# Copyright (C) 2010-2025 GEM Foundation.## NRML is free software: you can redistribute it and/or modify it# under the terms of the GNU Affero General Public License as published# by the Free Software Foundation, either version 3 of the License, or# (at your option) any later version.## NRML is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU Affero General Public License# along with NRML. If not, see <http://www.gnu.org/licenses/>."""Simple objects models to represent elements of NRML artifacts. These modelsare intended to be produced by NRML XML parsers and consumed by NRML XMLserializers."""fromcollectionsimportnamedtuple
[docs]classSourceModel(object):"""Simple container for source objects, plus metadata. :param str name: Name of the source model. :param sources: Iterable of seismic source objects (:class:`PointSource`, :class:`AreaSource`, :class:`SimpleFaultSource`, :class:`ComplexFaultSource`). """def__init__(self,name=None,sources=None):self.name=nameself.sources=sourcesdef__iter__(self):returniter(self.sources)
[docs]classSeismicSource(object):""" General base class for seismic sources. """def__init__(self,id=None,name=None,trt=None):self.id=idself.name=nameself.trt=trt@propertydefattrib(self):""" General XML element attributes for a seismic source, as a dict. """returndict([("id",str(self.id)),("name",str(self.name)),("tectonicRegion",str(self.trt)),])
[docs]classPointSource(SeismicSource):"""Basic object representation of a Point Source. :param str id: Source identifier, unique within a given model. :param str name: Human-readable name for the source. :param str trt: Tectonic Region Type. :param geometry: :class:`PointGeometry` instance. :param str mag_scale_rel: Magnitude Scaling Relationship. :param float rupt_aspect_ratio: Rupture Aspect Ratio. :param mfd: Magnitude Frequency Distribution. An instance of :class:`IncrementalMFD` or :class:`TGRMFD`. :param list nodal_plane_dist: `list` of :class:`NodalPlane` objects which make up a Nodal Plane Distribution. :param list hypo_depth_dist: `list` of :class:`HypocentralDepth` instances which make up a Hypocentral Depth Distribution. """def__init__(self,id=None,name=None,trt=None,geometry=None,mag_scale_rel=None,rupt_aspect_ratio=None,mfd=None,nodal_plane_dist=None,hypo_depth_dist=None,):super(PointSource,self).__init__(id=id,name=name,trt=trt)self.geometry=geometryself.mag_scale_rel=mag_scale_relself.rupt_aspect_ratio=rupt_aspect_ratioself.mfd=mfdself.nodal_plane_dist=nodal_plane_distself.hypo_depth_dist=hypo_depth_dist
[docs]classPointGeometry(object):"""Basic object representation of a geometry for a :class:`PointSource`. :param str wkt: WKT representing the point geometry (a POINT). :param float upper_seismo_depth: Upper seismogenic depth. :param float lower_seismo_depth: Lower siesmogenic depth. """def__init__(self,wkt=None,upper_seismo_depth=None,lower_seismo_depth=None):self.wkt=wktself.upper_seismo_depth=upper_seismo_depthself.lower_seismo_depth=lower_seismo_depth
[docs]classAreaSource(PointSource):"""Basic object representation of an Area Source. :param str id: Source identifier, unique within a given model. :param str name: Human-readable name for the source. :param str trt: Tectonic Region Type. :param geometry: :class:`AreaGeometry` instance. :param str mag_scale_rel: Magnitude Scaling Relationship. :param float rupt_aspect_ratio: Rupture Aspect Ratio. :param mfd: Magnitude Frequency Distribution. An instance of :class:`IncrementalMFD` or :class:`TGRMFD`. :param list nodal_plane_dist: `list` of :class:`NodalPlane` objects which make up a Nodal Plane Distribution. :param list hypo_depth_dist: `list` of :class:`HypocentralDepth` instances which make up a Hypocentral Depth Distribution. """
[docs]classAreaGeometry(PointGeometry):"""Basic object representation of a geometry for a :class:`PointSource`. :param str wkt: WKT representing the area geometry (a POLYGON). :param float upper_seismo_depth: Upper seismogenic depth. :param float lower_seismo_depth: Lower siesmogenic depth. """
[docs]classSimpleFaultSource(SeismicSource):"""Basic object representation of a Simple Fault Source. :param str id: Source identifier, unique within a given model. :param str name: Human-readable name for the source. :param str trt: Tectonic Region Type. :param geometry: :class:`SimpleFaultGeometry` object. :param str mag_scale_rel: Magnitude Scaling Relationship. :param float rupt_aspect_ratio: Rupture Aspect Ratio. :param mfd: Magnitude Frequency Distribution. An instance of :class:`IncrementalMFD` or :class:`TGRMFD`. :param float rake: Rake angle. """def__init__(self,id=None,name=None,trt=None,geometry=None,mag_scale_rel=None,rupt_aspect_ratio=None,mfd=None,rake=None,):super(SimpleFaultSource,self).__init__(id=id,name=name,trt=trt)self.geometry=geometryself.mag_scale_rel=mag_scale_relself.rupt_aspect_ratio=rupt_aspect_ratioself.mfd=mfdself.rake=rake
[docs]classSimpleFaultGeometry(object):"""Basic object representation of a geometry for a :class:`SimpleFaultSource`. :param str wkt: WKT representing the fault trace of a simple fault (a LINESTRING). :param float upper_seismo_depth: Upper seismogenic depth. :param float lower_seismo_depth: Lower siesmogenic depth. """def__init__(self,id=None,name=None,wkt=None,dip=None,upper_seismo_depth=None,lower_seismo_depth=None,):self.wkt=wktself.dip=dipself.upper_seismo_depth=upper_seismo_depthself.lower_seismo_depth=lower_seismo_depth# a string representation useful for tests and debuggingdef__str__(self):return"""SimpleFaultGeometry(wkt=%(wkt)s,dip=%(dip)s,upper_seismo_depth=%(upper_seismo_depth)s,lower_seismo_depth=%(lower_seismo_depth)s)"""%vars(self)
[docs]classComplexFaultSource(SimpleFaultSource):"""Basic object representation of a Complex Fault Source. :param str id: Source identifier, unique within a given model. :param str name: Human-readable name for the source. :param str trt: Tectonic Region Type. :param geometry: :class:`ComplexFaultGeometry` object. :param str mag_scale_rel: Magnitude Scaling Relationship. :param float rupt_aspect_ratio: Rupture Aspect Ratio. :param mfd: Magnitude Frequency Distribution. An instance of :class:`IncrementalMFD` or :class:`TGRMFD`. :param float rake: Rake angle. """
[docs]classComplexFaultGeometry(object):"""Basic object representation of a geometry for a :class:`ComplexFaultSource`. :param str top_edge_wkt: WKT representing the fault top edge (a LINESTRING). :param str bottom_edge_wkt: WKT representing the fault bottom edge (a LINESTRING). :param list int_edges: Intermediate fault edges, between the top edge and bottom edge. A `list` of `str` objects representing the WKT for each intermediate fault edge (each is a LINESTRING). This parameter is optional. """def__init__(self,top_edge_wkt=None,bottom_edge_wkt=None,int_edges=None):self.top_edge_wkt=top_edge_wktself.bottom_edge_wkt=bottom_edge_wktself.int_edges=int_edgesifint_edgesisnotNoneelse[]# a string representation useful for tests and debuggingdef__str__(self):return"""ComplexFaultGeometry(top_edge_wkt=%(top_edge_wkt)s,bottom_edge_wkt=%(bottom_edge_wkt)s,int_edges=%(int_edges)s"""%vars(self)
[docs]classIncrementalMFD(object):"""Basic object representation of an Incremental Magnitude Frequency Distribtion. :param float min_mag: The lowest possible magnitude for this MFD. :param float bin_width: Width of a single histogram bin. :param list occur_rates: `list` of occurrence rates (float values). """def__init__(self,min_mag=None,bin_width=None,occur_rates=None):self.min_mag=min_magself.bin_width=bin_widthself.occur_rates=occur_rates@propertydefattrib(self):""" A dict of XML element attributes for this MFD. """returndict([("minMag",str(self.min_mag)),("binWidth",str(self.bin_width)),])
[docs]classTGRMFD(object):"""Basic object representation of a Truncated Gutenberg-Richter Magnitude Frequency Distribution. :param float a_val: 10 ** a_val is the number of of earthquakes per year with magnitude greater than or equal to 0. :param float b_val: Decay rate of the exponential distribution. :param float min_mag: The lowest possible magnitude for this MFD. :param float max_mag: The highest possible magnitude for this MFD. """def__init__(self,a_val=None,b_val=None,min_mag=None,max_mag=None):self.a_val=a_valself.b_val=b_valself.min_mag=min_magself.max_mag=max_mag@propertydefattrib(self):""" An dict of XML element attributes for this MFD. """returndict([("aValue",str(self.a_val)),("bValue",str(self.b_val)),("minMag",str(self.min_mag)),("maxMag",str(self.max_mag)),])
[docs]classNodalPlane(object):"""Basic object representation of a single node in a Nodal Plane Distribution. :param probability: Probability for this node in a Nodal Plane Distribution, as a float. :param float strike: Strike angle. :param float dip: Dip angle. :param float rake: Rake angle. """def__init__(self,probability=None,strike=None,dip=None,rake=None):self.probability=probabilityself.strike=strikeself.dip=dipself.rake=rake@propertydefattrib(self):""" A dict of XML element attributes for this NodalPlane. """returndict([("probability",str(self.probability)),("strike",str(self.strike)),("dip",str(self.dip)),("rake",str(self.rake)),])
[docs]classHypocentralDepth(object):"""Basic object representation of a single node in a Hypocentral Depth Distribution. :param probability: Probability for this node in a Hypocentral Depth Distribution, as a float. :param float depth: Depth (in km). """def__init__(self,probability=None,depth=None):self.probability=probabilityself.depth=depth@propertydefattrib(self):""" An dict of XML element attribute for this HypocentralDepth. """returndict([("probability",str(self.probability)),("depth",str(self.depth)),])
[docs]classSiteModel(object):"""Basic object representation of a single node in a model of site-specific parameters. :param float vs30: Average shear wave velocity for top 30 m. Units m/s. :param str vs30_type: 'measured' or 'inferred'. Identifies if vs30 value has been measured or inferred. :param float z1pt0: Depth to shear wave velocity of 1.0 km/s. Units m. :param float z2pt5: Depth to shear wave velocity of 2.5 km/s. Units km. :param wkt: Well-known text (POINT) represeting the location of these parameters. """def__init__(self,vs30=None,vs30_type=None,z1pt0=None,z2pt5=None,wkt=None):self.vs30=vs30self.vs30_type=vs30_typeself.z1pt0=z1pt0self.z2pt5=z2pt5self.wkt=wkt
[docs]classSimpleFaultRuptureModel(object):"""Basic object representation of a Simple Fault Rupture. :param str id: Rupture identifier, unique within a given model. :param float magnitude: Magnitude. :param float rake: Rake angle. :param list hypocenter: Floats representing lon, lat and depth. :param geometry: :class:`SimpleFaultGeometry` object. """def__init__(self,id=None,magnitude=None,rake=None,hypocenter=None,geometry=None,):self.id=idself.magnitude=magnitudeself.rake=rakeself.hypocenter=hypocenterself.geometry=geometry
[docs]classComplexFaultRuptureModel(SimpleFaultRuptureModel):"""Basic object representation of a Complex Fault Rupture. :param str id: Rupture identifier, unique within a given model. :param float magnitude: Magnitude. :param float rake: Rake angle. :param list hypocenter: Floats representing lon, lat and depth. :param geometry: :class:`ComplexFaultGeometry` object. """
[docs]classCharacteristicSource(SeismicSource):""" Basic object representation of a characteristic fault source. :param str id: Source identifier, unique within a given model. :param str name: Human-readable name for the source. :param str trt: Tectonic Region Type. :param mfd: Magnitude Frequency Distribution. An instance of :class:`IncrementalMFD` or :class:`TGRMFD`. :param float rake: Rake angle. :param surface: A :class:`SimpleFaultGeometry`, :class:`ComplexFaultGeometry`, or a list of :class:`PlanarSurface` objects. """def__init__(self,id=None,name=None,trt=None,mfd=None,rake=None,surface=None):super(CharacteristicSource,self).__init__(id=id,name=name,trt=trt)self.mfd=mfdself.rake=rakeself.surface=surface
[docs]classPlanarSurface(object):""" :param strike: Strike angle. :param dip: Dip angle. :param top_left,top_right,bottom_left,bottom_right: Corner points of the planar surface, represented by :class:`Point` objects. """def__init__(self,strike=None,dip=None,top_left=None,top_right=None,bottom_left=None,bottom_right=None,):self.strike=strikeself.dip=dipself.top_left=top_leftself.top_right=top_rightself.bottom_left=bottom_leftself.bottom_right=bottom_right
[docs]classPoint(object):""" A simple representation of longitude, latitude, and depth. :param longitude: Longitude :param latitude: Latitude :param depth: Depth """def__init__(self,longitude=None,latitude=None,depth=None):self.longitude=longitudeself.latitude=latitudeself.depth=depth
[docs]classHazardCurveModel(object):""" Simple container for hazard curve objects. The accepted arguments are:: * investigation_time * imt * imls * statistics * quantile_value * sa_period * sa_damping * data_iter (optional), an iterable returning pairs with the form (poes_array, location). """def__init__(self,**metadata):self._data_iter=metadata.pop("data_iter",())self.metadata=metadatavars(self).update(metadata)def__iter__(self):returnself._data_iter