shakelib.rupture.factory¶
-
shakelib.rupture.factory.
get_rupture
(origin, file=None, mesh_dx=0.5)[source]¶ This is a module-level function to read in a rupture file. This allows for the ShakeMap 3 text file specification or the ShakeMap 4 JSON rupture format. The ShakeMap 3 (“.txt” extension) only supports QuadRupture style rupture representation and so this method will always return a QuadRupture instance. The ShakeMap 4 JSON format supports QuadRupture and EdgeRupture represenations and so this method detects the rupture class and returns the appropriate Rupture subclass instance.
If file is None (default) then it returns a PointRupture.
Parameters: - origin (Origin) – A ShakeMap origin instance; required because hypocentral/epicentral distances are computed from the Rupture class.
- file (srt) – Path to rupture file (optional).
- mesh_dx (float) – Target spacing (in km) for rupture discretization; default is 0.5 km and it is only used if the rupture file is an EdgeRupture.
Returns: Rupture subclass instance.
-
shakelib.rupture.factory.
rupture_from_dict_and_origin
(d, origin, mesh_dx=0.5)[source]¶ Method returns either a QuadRupture or EdgeRupture object based on a GeoJSON dictionary and an origin. Note that this is very similar to
rupture_from_dict()
, except that method is for constructing the rupture objects from a dict that already contains the origin info in the metadata field (e.g., from a dict from a Shakemap container), while this method is for construction of the rupture objects from a GeoJSON dict that does not yet include that information (e.g., from a dict that is read in to initially create the shakemap container, along with an Origin that is derived from event.xml).See also
Parameters: - d (dict) – Rupture GeoJSON dictionary.
- origin (Origin) – A ShakeMap origin object.
- mesh_dx (float) – Target spacing (in km) for rupture discretization; default is 0.5 km and it is only used if the rupture file is an EdgeRupture.
Returns: a Rupture subclass.
-
shakelib.rupture.factory.
rupture_from_dict
(d)[source]¶ Method returns either a Rupture subclass (QuadRupture, EdgeRupture, or PointRupture) object based on a GeoJSON dictionary.
See also
Parameters: d (dict) – Rupture GeoJSON dictionary, which must contain origin information in the ‘metadata’ field. Returns: a Rupture subclass.
-
shakelib.rupture.factory.
text_to_json
(file)[source]¶ Read in old ShakeMap 3 textfile rupture format and convert to GeoJSON.
Parameters: rupturefile (srt) – Path to rupture file OR file-like object in GMT psxy format, where:
- Rupture vertices are space separated lat, lon, depth triplets on a single line.
- Rupture groups are separated by lines containing “>”
- Rupture groups must be closed.
- Verticies within a rupture group must start along the top edge and move in the strike direction then move to the bottom edge and move back in the opposite direction.
Returns: GeoJSON rupture dictionary. Return type: dict
-
shakelib.rupture.factory.
validate_json
(d)[source]¶ Check that the JSON format is acceptable. This is only for requirements that are common to both QuadRupture and EdgeRupture.
Parameters: d (dict) – Rupture JSON dictionary.
-
shakelib.rupture.factory.
is_quadrupture_class
(d)[source]¶ Check if JSON file fulfills QuadRupture class criteria:
- Are top and bottom edges horizontal?
- Are the four points in each quad coplanar?
Parameters: d (dict) – Rupture JSON dictionary. Returns: Can the rupture be represented in the QuadRupture class? Return type: bool