Skip to content

Commit

Permalink
Merge pull request #10061 from gem/max_params
Browse files Browse the repository at this point in the history
Small refactoring of the source classes
  • Loading branch information
micheles authored Oct 16, 2024
2 parents f1812dd + 63fe1ac commit cfda150
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
15 changes: 6 additions & 9 deletions openquake/hazardlib/source/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ class BaseSeismicSource(metaclass=abc.ABCMeta):
weight = 0.001 # set in contexts
esites = 0 # updated in estimate_weight
offset = 0 # set in fix_src_offset
trt_smr = -1 # set by the engine
num_ruptures = 0 # set by the engine
seed = None # set by the engine

@abc.abstractproperty
def MODIFICATIONS(self):
Expand All @@ -218,14 +221,6 @@ def serial(self, ses_seed):
"""
return zlib.crc32(self.source_id.encode('ascii'), ses_seed)

def __init__(self, source_id, name, tectonic_region_type):
self.source_id = source_id
self.name = name
self.tectonic_region_type = tectonic_region_type
self.trt_smr = -1 # set by the engine
self.num_ruptures = 0 # set by the engine
self.seed = None # set by the engine

def is_gridded(self):
"""
:returns: True if the source contains only gridded ruptures
Expand Down Expand Up @@ -394,7 +389,9 @@ class ParametricSeismicSource(BaseSeismicSource, metaclass=abc.ABCMeta):
def __init__(self, source_id, name, tectonic_region_type, mfd,
rupture_mesh_spacing, magnitude_scaling_relationship,
rupture_aspect_ratio, temporal_occurrence_model):
super().__init__(source_id, name, tectonic_region_type)
self.source_id = source_id
self.name = name
self.tectonic_region_type = tectonic_region_type

if rupture_mesh_spacing is not None and not rupture_mesh_spacing > 0:
raise ValueError('rupture mesh spacing must be positive')
Expand Down
4 changes: 3 additions & 1 deletion openquake/hazardlib/source/multi_fault.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ def __init__(self, source_id: str, name: str, tectonic_region_type: str,
self.rakes = F32(rakes)
self.infer_occur_rates = infer_occur_rates
self.investigation_time = investigation_time
super().__init__(source_id, name, tectonic_region_type)
self.source_id =source_id
self.name = name
self.tectonic_region_type = tectonic_region_type

@property
def occur_rates(self):
Expand Down
4 changes: 3 additions & 1 deletion openquake/hazardlib/source/non_parametric.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ class NonParametricSeismicSource(BaseSeismicSource):

def __init__(self, source_id, name, tectonic_region_type, data,
weights=None):
super().__init__(source_id, name, tectonic_region_type)
self.source_id = source_id
self.name = name
self.tectonic_region_type = tectonic_region_type
self.data = data
if weights is not None:
assert len(weights) == len(data), (len(weights), len(data))
Expand Down

0 comments on commit cfda150

Please sign in to comment.