Source code for openquake.hmtk.strain.geodetic_strain

# -*- coding: utf-8 -*-
# vim: tabstop=4 shiftwidth=4 softtabstop=4

# Copyright (C) 2010-2023 GEM Foundation, G. Weatherill, M. Pagani,
# D. Monelli.
# The Hazard Modeller's Toolkit 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.
# You should have received a copy of the GNU Affero General Public License
# along with OpenQuake. If not, see <>
# The software Hazard Modeller's Toolkit (openquake.hmtk) provided herein
# is released as a prototype implementation on behalf of
# scientists and engineers working within the GEM Foundation (Global
# Earthquake Model).
# It is distributed for the purpose of open collaboration and in the
# hope that it will be useful to the scientific, engineering, disaster
# risk and software design communities.
# The software is NOT distributed as part of GEM's OpenQuake suite
# ( and must be considered as a
# separate entity. The software provided herein is designed and implemented
# by scientific staff. It is not developed to the design standards, nor
# subject to same level of critical review by professional software
# developers, as GEM's OpenQuake software suite.
# Feedback and contribution to the software is welcome, and can be
# directed to the hazard scientific staff of the GEM Model Facility
# (
# The Hazard Modeller's Toolkit (openquake.hmtk) is therefore distributed
# 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.
# The GEM Foundation, and the authors of the software, assume no
# liability for use of the software.

:class:`openquake.hmtk.strain.geodectic_strain.GeodeticStain` is a
core class for storage and implementation of a geodetic strain rate
import numpy as np
from copy import deepcopy

DATA_VARIABLES = ['longitude', 'latitude', 'exx', 'eyy', 'exy']

[docs]class GeodeticStrain(object): ''' :class:`openquake.hmtk.strain.geodetic_strain.GeodeticStrain` describes the geodetic strain model :param dict data: Strain data in the form of a dictionary where is vector of attributes is stored under the correponding dictionary key (i.e. - longitude - Longitude of point - latitude - Latitiude of point - exx - xx-component of strain tensor - eyy - yy-component of strain tensor - exy - xy-component of strain tensor :param numpy.ndarray seismicity_rate: Seismicity rate at each point associated with the strain model :param numpy.ndarray target_magnitudes: Magnitudes for the corresponding activity rates :param list data_variables: List of strain data attributes in the current class ''' def __init__(self): '''Instantiates''' = None self.regions = None self.seismicity_rate = None self.regionalisation = None self.target_magnitudes = None self.data_variables = []
[docs] def get_secondary_strain_data(self, strain_data=None): ''' Calculate the following and add to data dictionary: 1) 2nd invarient of strain 2) Dilatation rate 3) e1h and e2h 4) err :param dict strain_data: Strain data dictionary (as described) - will overwrite current data if input ''' if strain_data: = strain_data if not isinstance(, dict): raise ValueError('Strain data not input or incorrectly formatted') # Check to ensure essential attributes are in data dictionary for essential_key in DATA_VARIABLES: if essential_key not in print( raise ValueError('Essential strain information %s missing!' % essential_key) self.data_variables = deepcopy(DATA_VARIABLES) # Second Invarient['2nd_inv'] = np.sqrt( (['exx'] ** 2.) + (['eyy'] ** 2.) + 2.0 * (['exy'] ** 2.)) # Dilatation['dilatation'] =['exx'] +['eyy'] # err['err'] = -1. *['dilatation'] center_normal_rate = (['exx'] +['eyy']) / 2. radius_rate = np.sqrt((['exx'] - center_normal_rate) ** 2. + (['exy'] ** 2.)) # e1h and e2h['e1h'] = center_normal_rate - radius_rate['e2h'] = center_normal_rate + radius_rate['area'] = np.zeros(self.get_number_observations()) self.data_variables.extend(['2nd_inv', 'dilatation', 'err', 'e1h', 'e2h'])
[docs] def get_number_observations(self): ''' Returns the number of observations in the data file ''' if isinstance(, dict) and ('exx' in return len(['exx']) else: return 0