idx
int64
0
63k
question
stringlengths
61
4.03k
target
stringlengths
6
1.23k
44,100
def hmcorrelation ( sites_or_distances , imt , uncertainty_multiplier = 0 ) : if hasattr ( sites_or_distances , 'mesh' ) : distances = sites_or_distances . mesh . get_distance_matrix ( ) else : distances = sites_or_distances period = imt . period if period < 1.37 : Med_b = 4.231 * period * period - 5.180 * period + 13....
Returns the Heresi - Miranda correlation model .
44,101
def get_lower_triangle_correlation_matrix ( self , sites , imt ) : return numpy . linalg . cholesky ( self . _get_correlation_matrix ( sites , imt ) )
Get lower - triangle matrix as a result of Cholesky - decomposition of correlation matrix .
44,102
def start_ebrisk ( rupgetter , srcfilter , param , monitor ) : with monitor ( 'weighting ruptures' ) : rupgetter . set_weights ( srcfilter , param [ 'num_taxonomies' ] ) if rupgetter . weights . sum ( ) <= param [ 'maxweight' ] : yield ebrisk ( rupgetter , srcfilter , param , monitor ) else : for rgetter in rupgetter ....
Launcher for ebrisk tasks
44,103
def get_min_max_mag ( self ) : "Return the minimum and maximum magnitudes" mag , num_bins = self . _get_min_mag_and_num_bins ( ) return mag , mag + self . bin_width * ( num_bins - 1 )
Return the minimum and maximum magnitudes
44,104
def _get_rate ( self , mag ) : mag_lo = mag - self . bin_width / 2.0 mag_hi = mag + self . bin_width / 2.0 if mag >= self . min_mag and mag < self . char_mag - DELTA_CHAR / 2 : return ( 10 ** ( self . a_val - self . b_val * mag_lo ) - 10 ** ( self . a_val - self . b_val * mag_hi ) ) else : return ( self . char_rate / D...
Calculate and return the annual occurrence rate for a specific bin .
44,105
def _get_min_mag_and_num_bins ( self ) : min_mag = round ( self . min_mag / self . bin_width ) * self . bin_width max_mag = ( round ( ( self . char_mag + DELTA_CHAR / 2 ) / self . bin_width ) * self . bin_width ) min_mag += self . bin_width / 2.0 max_mag -= self . bin_width / 2.0 num_bins = int ( round ( ( max_mag - mi...
Estimate the number of bins in the histogram and return it along with the first bin center value .
44,106
def get_annual_occurrence_rates ( self ) : mag , num_bins = self . _get_min_mag_and_num_bins ( ) rates = [ ] for i in range ( num_bins ) : rate = self . _get_rate ( mag ) rates . append ( ( mag , rate ) ) mag += self . bin_width return rates
Calculate and return the annual occurrence rates histogram .
44,107
def create_geometry ( self , input_geometry , upper_depth , lower_depth ) : self . _check_seismogenic_depths ( upper_depth , lower_depth ) if not isinstance ( input_geometry , Polygon ) : if not isinstance ( input_geometry , np . ndarray ) : raise ValueError ( 'Unrecognised or unsupported geometry ' 'definition' ) if n...
If geometry is defined as a numpy array then create instance of nhlib . geo . polygon . Polygon class otherwise if already instance of class accept class
44,108
def select_catalogue ( self , selector , distance = None ) : if selector . catalogue . get_number_events ( ) < 1 : raise ValueError ( 'No events found in catalogue!' ) self . catalogue = selector . within_polygon ( self . geometry , distance , upper_depth = self . upper_depth , lower_depth = self . lower_depth ) if sel...
Selects the catalogue of earthquakes attributable to the source
44,109
def new ( self , operation = 'no operation' , ** kw ) : self_vars = vars ( self ) . copy ( ) del self_vars [ 'operation' ] del self_vars [ 'children' ] del self_vars [ 'counts' ] del self_vars [ '_flush' ] new = self . __class__ ( operation ) vars ( new ) . update ( self_vars ) vars ( new ) . update ( kw ) return new
Return a copy of the monitor usable for a different operation .
44,110
def from_shakemap ( cls , shakemap_array ) : self = object . __new__ ( cls ) self . complete = self n = len ( shakemap_array ) dtype = numpy . dtype ( [ ( p , site_param_dt [ p ] ) for p in 'sids lon lat depth vs30' . split ( ) ] ) self . array = arr = numpy . zeros ( n , dtype ) arr [ 'sids' ] = numpy . arange ( n , d...
Build a site collection from a shakemap array
44,111
def from_points ( cls , lons , lats , depths = None , sitemodel = None , req_site_params = ( ) ) : assert len ( lons ) < U32LIMIT , len ( lons ) if depths is None : depths = numpy . zeros ( len ( lons ) ) assert len ( lons ) == len ( lats ) == len ( depths ) , ( len ( lons ) , len ( lats ) , len ( depths ) ) self = obj...
Build the site collection from
44,112
def make_complete ( self ) : self . array [ 'sids' ] = numpy . arange ( len ( self ) , dtype = numpy . uint32 ) self . complete = self
Turns the site collection into a complete one if needed
44,113
def filter ( self , mask ) : assert len ( mask ) == len ( self ) , ( len ( mask ) , len ( self ) ) if mask . all ( ) : return self if not mask . any ( ) : return None indices , = mask . nonzero ( ) return self . filtered ( indices )
Create a SiteCollection with only a subset of sites .
44,114
def point_at ( self , horizontal_distance , vertical_increment , azimuth ) : lon , lat = geodetic . point_at ( self . longitude , self . latitude , azimuth , horizontal_distance ) return Point ( lon , lat , self . depth + vertical_increment )
Compute the point with given horizontal vertical distances and azimuth from this point .
44,115
def equally_spaced_points ( self , point , distance ) : lons , lats , depths = geodetic . intervals_between ( self . longitude , self . latitude , self . depth , point . longitude , point . latitude , point . depth , distance ) return [ Point ( lons [ i ] , lats [ i ] , depths [ i ] ) for i in range ( len ( lons ) ) ]
Compute the set of points equally spaced between this point and the given point .
44,116
def to_polygon ( self , radius ) : assert radius > 0 from openquake . hazardlib . geo . polygon import Polygon proj = geo_utils . OrthographicProjection ( self . longitude , self . longitude , self . latitude , self . latitude ) point = shapely . geometry . Point ( * proj ( self . longitude , self . latitude ) ) return...
Create a circular polygon with specified radius centered in the point .
44,117
def closer_than ( self , mesh , radius ) : dists = geodetic . distance ( self . longitude , self . latitude , self . depth , mesh . lons , mesh . lats , 0 if mesh . depths is None else mesh . depths ) return dists <= radius
Check for proximity of points in the mesh .
44,118
def print_csm_info ( fname ) : oqparam = readinput . get_oqparam ( fname ) csm = readinput . get_composite_source_model ( oqparam , in_memory = False ) print ( csm . info ) print ( 'See http://docs.openquake.org/oq-engine/stable/' 'effective-realizations.html for an explanation' ) rlzs_assoc = csm . info . get_rlzs_ass...
Parse the composite source model without instantiating the sources and prints information about its composition and the full logic tree
44,119
def do_build_reports ( directory ) : for cwd , dirs , files in os . walk ( directory ) : for f in sorted ( files ) : if f in ( 'job.ini' , 'job_h.ini' , 'job_haz.ini' , 'job_hazard.ini' ) : job_ini = os . path . join ( cwd , f ) logging . info ( job_ini ) try : reportwriter . build_report ( job_ini , cwd ) except Excep...
Walk the directory and builds pre - calculation reports for all the job . ini files found .
44,120
def info ( calculators , gsims , views , exports , extracts , parameters , report , input_file = '' ) : if calculators : for calc in sorted ( base . calculators ) : print ( calc ) if gsims : for gs in gsim . get_available_gsims ( ) : print ( gs ) if views : for name in sorted ( view ) : print ( name ) if exports : dic ...
Give information . You can pass the name of an available calculator a job . ini file or a zip archive with the input files .
44,121
def classical_split_filter ( srcs , srcfilter , gsims , params , monitor ) : ss = int ( os . environ . get ( 'OQ_SAMPLE_SOURCES' , 0 ) ) if ss : splits , stime = split_sources ( srcs ) srcs = readinput . random_filtered_sources ( splits , srcfilter , ss ) yield classical ( srcs , srcfilter , gsims , params , monitor ) ...
Split the given sources filter the subsources and the compute the PoEs . Yield back subtasks if the split sources contain more than maxweight ruptures .
44,122
def get_azimuth_plunge ( vect , degrees = True ) : if vect [ 0 ] > 0 : vect = - 1. * np . copy ( vect ) vect_hor = sqrt ( vect [ 1 ] ** 2. + vect [ 2 ] ** 2. ) plunge = atan2 ( - vect [ 0 ] , vect_hor ) azimuth = atan2 ( vect [ 2 ] , - vect [ 1 ] ) if degrees : icr = 180. / pi return icr * azimuth % 360. , icr * plunge...
For a given vector in USE format retrieve the azimuth and plunge
44,123
def use_to_ned ( tensor ) : return np . array ( ROT_NED_USE . T * np . matrix ( tensor ) * ROT_NED_USE )
Converts a tensor in USE coordinate sytem to NED
44,124
def ned_to_use ( tensor ) : return np . array ( ROT_NED_USE * np . matrix ( tensor ) * ROT_NED_USE . T )
Converts a tensor in NED coordinate sytem to USE
44,125
def get_mean_and_stddevs ( self , sites , rup , dists , imt , stddev_types ) : mean , stddevs = super ( ) . get_mean_and_stddevs ( sites , rup , dists , imt , stddev_types ) if imt == PGA ( ) : freq = 50.0 elif imt == PGV ( ) : freq = 2.0 else : freq = 1. / imt . period x1 = np . min ( [ - 0.18 + 0.17 * np . log10 ( fr...
Using a frequency dependent correction for the mean ground motion . Standard deviation is fixed .
44,126
def get_rlz ( self , rlzstr ) : r mo = re . match ( r'rlz-(\d+)' , rlzstr ) if not mo : return return self . realizations [ int ( mo . group ( 1 ) ) ]
r Get a Realization instance for a string of the form rlz - \ d +
44,127
def export ( datastore_key , calc_id = - 1 , exports = 'csv' , export_dir = '.' ) : dstore = util . read ( calc_id ) parent_id = dstore [ 'oqparam' ] . hazard_calculation_id if parent_id : dstore . parent = util . read ( parent_id ) dstore . export_dir = export_dir with performance . Monitor ( 'export' , measuremem = T...
Export an output from the datastore .
44,128
def convert_UCERFSource ( self , node ) : dirname = os . path . dirname ( self . fname ) source_file = os . path . join ( dirname , node [ "filename" ] ) if "startDate" in node . attrib and "investigationTime" in node . attrib : inv_time = float ( node [ "investigationTime" ] ) if inv_time != self . investigation_time ...
Converts the Ucerf Source node into an SES Control object
44,129
def build_idx_set ( branch_id , start_date ) : code_set = branch_id . split ( "/" ) code_set . insert ( 3 , "Rates" ) idx_set = { "sec" : "/" . join ( [ code_set [ 0 ] , code_set [ 1 ] , "Sections" ] ) , "mag" : "/" . join ( [ code_set [ 0 ] , code_set [ 1 ] , code_set [ 2 ] , "Magnitude" ] ) } idx_set [ "rate" ] = "/"...
Builds a dictionary of keys based on the branch code
44,130
def get_rupture_surface ( mag , nodal_plane , hypocenter , msr , rupture_aspect_ratio , upper_seismogenic_depth , lower_seismogenic_depth , mesh_spacing = 1.0 ) : assert ( upper_seismogenic_depth <= hypocenter . depth and lower_seismogenic_depth >= hypocenter . depth ) rdip = math . radians ( nodal_plane . dip ) azimut...
Create and return rupture surface object with given properties .
44,131
def get_ridx ( self , iloc ) : with h5py . File ( self . source_file , "r" ) as hdf5 : return hdf5 [ self . idx_set [ "geol" ] + "/RuptureIndex" ] [ iloc ]
List of rupture indices for the given iloc
44,132
def get_background_sids ( self , src_filter ) : branch_key = self . idx_set [ "grid_key" ] idist = src_filter . integration_distance ( DEFAULT_TRT ) with h5py . File ( self . source_file , 'r' ) as hdf5 : bg_locations = hdf5 [ "Grid/Locations" ] . value distances = min_geodetic_distance ( src_filter . sitecol . xyz , (...
We can apply the filtering of the background sites as a pre - processing step - this is done here rather than in the sampling of the ruptures themselves
44,133
def iter_ruptures ( self ) : assert self . orig , '%s is not fully initialized' % self for ridx in range ( self . start , self . stop ) : if self . orig . rate [ ridx ] : rup = self . get_ucerf_rupture ( ridx , self . src_filter ) if rup : yield rup
Yield ruptures for the current set of indices
44,134
def get_background_sources ( self , src_filter , sample_factor = None ) : background_sids = self . get_background_sids ( src_filter ) if sample_factor is not None : background_sids = random_filter ( background_sids , sample_factor , seed = 42 ) with h5py . File ( self . source_file , "r" ) as hdf5 : grid_loc = "/" . jo...
Turn the background model of a given branch into a set of point sources
44,135
def split ( src , chunksize = MINWEIGHT ) : for i , block in enumerate ( block_splitter ( src . iter_ruptures ( ) , chunksize , key = operator . attrgetter ( 'mag' ) ) ) : rup = block [ 0 ] source_id = '%s:%d' % ( src . source_id , i ) amfd = mfd . ArbitraryMFD ( [ rup . mag ] , [ rup . mag_occ_rate ] ) rcs = RuptureCo...
Split a complex fault source in chunks
44,136
def get_bounding_box ( self , maxdist ) : locations = [ rup . hypocenter for rup in self . ruptures ] return get_bounding_box ( locations , maxdist )
Bounding box containing all the hypocenters enlarged by the maximum distance
44,137
def show_attrs ( key , calc_id = - 1 ) : ds = util . read ( calc_id ) try : attrs = h5py . File . __getitem__ ( ds . hdf5 , key ) . attrs except KeyError : print ( '%r is not in %s' % ( key , ds ) ) else : if len ( attrs ) == 0 : print ( '%s has no attributes' % key ) for name , value in attrs . items ( ) : print ( nam...
Show the attributes of a HDF5 dataset in the datastore .
44,138
def compare_mean_curves ( calc_ref , calc , nsigma = 3 ) : dstore_ref = datastore . read ( calc_ref ) dstore = datastore . read ( calc ) imtls = dstore_ref [ 'oqparam' ] . imtls if dstore [ 'oqparam' ] . imtls != imtls : raise RuntimeError ( 'The IMTs and levels are different between ' 'calculation %d and %d' % ( calc_...
Compare the hazard curves coming from two different calculations .
44,139
def _get_stddevs ( self , sites , rup , C , stddev_types , ln_y_ref , exp1 , exp2 ) : ret = [ ] for stddev_type in stddev_types : assert stddev_type in self . DEFINED_FOR_STANDARD_DEVIATION_TYPES if stddev_type == const . StdDev . TOTAL : ret . append ( 0.65 * np . ones_like ( sites . vs30 ) ) return ret
Returns the standard deviation which is fixed at 0 . 65 for every site
44,140
def build_imls ( ff , continuous_fragility_discretization , steps_per_interval = 0 ) : if ff . format == 'discrete' : imls = ff . imls if ff . nodamage and ff . nodamage < imls [ 0 ] : imls = [ ff . nodamage ] + imls if steps_per_interval > 1 : gen_imls = fine_graining ( imls , steps_per_interval ) else : gen_imls = im...
Build intensity measure levels from a fragility function . If the function is continuous they are produced simply as a linear space between minIML and maxIML . If the function is discrete they are generated with a complex logic depending on the noDamageLimit and the parameter steps per interval .
44,141
def insured_loss_curve ( curve , deductible , insured_limit ) : losses , poes = curve [ : , curve [ 0 ] <= insured_limit ] limit_poe = interpolate . interp1d ( * curve , bounds_error = False , fill_value = 1 ) ( deductible ) return numpy . array ( [ losses , numpy . piecewise ( poes , [ poes > limit_poe ] , [ limit_poe...
Compute an insured loss ratio curve given a loss ratio curve
44,142
def bcr ( eal_original , eal_retrofitted , interest_rate , asset_life_expectancy , asset_value , retrofitting_cost ) : return ( ( eal_original - eal_retrofitted ) * asset_value * ( 1 - numpy . exp ( - interest_rate * asset_life_expectancy ) ) / ( interest_rate * retrofitting_cost ) )
Compute the Benefit - Cost Ratio .
44,143
def pairwise_mean ( values ) : "Averages between a value and the next value in a sequence" return numpy . array ( [ numpy . mean ( pair ) for pair in pairwise ( values ) ] )
Averages between a value and the next value in a sequence
44,144
def pairwise_diff ( values ) : "Differences between a value and the next value in a sequence" return numpy . array ( [ x - y for x , y in pairwise ( values ) ] )
Differences between a value and the next value in a sequence
44,145
def mean_std ( fractions ) : n = fractions . shape [ 0 ] if n == 1 : return fractions [ 0 ] , numpy . ones_like ( fractions [ 0 ] ) * numpy . nan return numpy . mean ( fractions , axis = 0 ) , numpy . std ( fractions , axis = 0 , ddof = 1 )
Given an N x M matrix returns mean and std computed on the rows i . e . two M - dimensional vectors .
44,146
def broadcast ( func , composite_array , * args ) : dic = { } dtypes = [ ] for name in composite_array . dtype . names : dic [ name ] = func ( composite_array [ name ] , * args ) dtypes . append ( ( name , dic [ name ] . dtype ) ) res = numpy . zeros ( dic [ name ] . shape , numpy . dtype ( dtypes ) ) for name in dic :...
Broadcast an array function over a composite array
44,147
def average_loss ( lc ) : losses , poes = ( lc [ 'loss' ] , lc [ 'poe' ] ) if lc . dtype . names else lc return - pairwise_diff ( losses ) @ pairwise_mean ( poes )
Given a loss curve array with poe and loss fields computes the average loss on a period of time .
44,148
def normalize_curves_eb ( curves ) : non_zero_curves = [ ( losses , poes ) for losses , poes in curves if losses [ - 1 ] > 0 ] if not non_zero_curves : return curves [ 0 ] [ 0 ] , numpy . array ( [ poes for _losses , poes in curves ] ) else : max_losses = [ losses [ - 1 ] for losses , _poes in non_zero_curves ] referen...
A more sophisticated version of normalize_curves used in the event based calculator .
44,149
def sample ( self , means , covs , idxs , epsilons = None ) : if epsilons is None : return means self . set_distribution ( epsilons ) res = self . distribution . sample ( means , covs , means * covs , idxs ) return res
Sample the epsilons and apply the corrections to the means . This method is called only if there are nonzero covs .
44,150
def mean_loss_ratios_with_steps ( self , steps ) : loss_ratios = self . mean_loss_ratios if min ( loss_ratios ) > 0.0 : loss_ratios = numpy . concatenate ( [ [ 0.0 ] , loss_ratios ] ) if max ( loss_ratios ) < 1.0 : loss_ratios = numpy . concatenate ( [ loss_ratios , [ 1.0 ] ] ) return fine_graining ( loss_ratios , step...
Split the mean loss ratios producing a new set of loss ratios . The new set of loss ratios always includes 0 . 0 and 1 . 0
44,151
def sample ( self , probs , _covs , idxs , epsilons ) : self . set_distribution ( epsilons ) return self . distribution . sample ( self . loss_ratios , probs )
Sample the . loss_ratios with the given probabilities .
44,152
def build ( self , continuous_fragility_discretization , steps_per_interval ) : newfm = copy . copy ( self ) for key , ffl in self . items ( ) : newfm [ key ] = ffl . build ( self . limitStates , continuous_fragility_discretization , steps_per_interval ) return newfm
Return a new FragilityModel instance in which the values have been replaced with FragilityFunctionList instances .
44,153
def compute_gmfs ( rupgetter , srcfilter , param , monitor ) : getter = GmfGetter ( rupgetter , srcfilter , param [ 'oqparam' ] ) with monitor ( 'getting ruptures' ) : getter . init ( ) return getter . compute_gmfs_curves ( monitor )
Compute GMFs and optionally hazard curves
44,154
def _get_minmax_edges ( self , edge ) : if isinstance ( edge , Line ) : depth_vals = np . array ( [ node . depth for node in edge . points ] ) else : depth_vals = edge [ : , 2 ] temp_upper_depth = np . min ( depth_vals ) if not self . upper_depth : self . upper_depth = temp_upper_depth else : if temp_upper_depth < self...
Updates the upper and lower depths based on the input edges
44,155
def _get_magnitude_term ( self , C , mag ) : if mag >= self . CONSTS [ "Mh" ] : return C [ "e1" ] + C [ "b3" ] * ( mag - self . CONSTS [ "Mh" ] ) else : return C [ "e1" ] + ( C [ "b1" ] * ( mag - self . CONSTS [ "Mh" ] ) ) + ( C [ "b2" ] * ( mag - self . CONSTS [ "Mh" ] ) ** 2. )
Returns the magnitude scaling term - equation 3
44,156
def _get_distance_term ( self , C , rjb , mag ) : c_3 = self . _get_anelastic_coeff ( C ) rval = np . sqrt ( rjb ** 2. + C [ "h" ] ** 2. ) return ( C [ "c1" ] + C [ "c2" ] * ( mag - self . CONSTS [ "Mref" ] ) ) * np . log ( rval / self . CONSTS [ "Rref" ] ) + c_3 * ( rval - self . CONSTS [ "Rref" ] )
Returns the general distance scaling term - equation 2
44,157
def _get_site_term ( self , C , vs30 ) : dg1 , dg2 = self . _get_regional_site_term ( C ) return ( C [ "g1" ] + dg1 ) + ( C [ "g2" ] + dg2 ) * np . log ( vs30 )
Returns only a linear site amplification term
44,158
def _get_stddevs ( self , C , stddev_types , num_sites ) : assert all ( stddev_type in self . DEFINED_FOR_STANDARD_DEVIATION_TYPES for stddev_type in stddev_types ) stddevs = [ np . zeros ( num_sites ) + C [ 'SigmaTot' ] for _ in stddev_types ] return stddevs
Return standard deviations as defined in tables below
44,159
def _compute_mean ( self , C , mag , rrup , hypo_depth , delta_R , delta_S , delta_V , delta_I , vs30 ) : mean = ( C [ 'A1' ] + ( C [ 'A2' ] + C [ 'A2R' ] * delta_R + C [ 'A2V' ] * delta_V ) * mag + ( C [ 'A3' ] + C [ 'A3S' ] * delta_S + C [ 'A3V' ] * delta_V ) * np . log10 ( np . power ( ( rrup ** 3 + C [ 'd' ] ** 3 )...
Compute MMI Intensity Value as per Equation in Table 5 and Table 7 pag 198 .
44,160
def _get_stddevs ( self , C , stddev_types , num_sites ) : sigma_inter = C [ 'tau' ] + np . zeros ( num_sites ) sigma_intra = C [ 'sigma' ] + np . zeros ( num_sites ) std = [ ] for stddev_type in stddev_types : if stddev_type == const . StdDev . TOTAL : std += [ np . sqrt ( sigma_intra ** 2 + sigma_inter ** 2 ) ] elif ...
Return total standard deviation as described in paragraph 5 . 2 pag 200 .
44,161
def plot_assets ( calc_id = - 1 , site_model = False ) : import matplotlib . pyplot as p from openquake . hmtk . plotting . patch import PolygonPatch dstore = util . read ( calc_id ) try : region = dstore [ 'oqparam' ] . region except KeyError : region = None sitecol = dstore [ 'sitecol' ] try : assetcol = dstore [ 'as...
Plot the sites and the assets
44,162
def _get_adjustment ( mag , year , mmin , completeness_year , t_f , mag_inc = 0.1 ) : if len ( completeness_year ) == 1 : if ( mag >= mmin ) and ( year >= completeness_year [ 0 ] ) : return 1.0 else : return False kval = int ( ( ( mag - mmin ) / mag_inc ) ) + 1 if ( kval >= 1 ) and ( year >= completeness_year [ kval - ...
If the magnitude is greater than the minimum in the completeness table and the year is greater than the corresponding completeness year then return the Weichert factor
44,163
def get_catalogue_bounding_polygon ( catalogue ) : upper_lon = np . max ( catalogue . data [ 'longitude' ] ) upper_lat = np . max ( catalogue . data [ 'latitude' ] ) lower_lon = np . min ( catalogue . data [ 'longitude' ] ) lower_lat = np . min ( catalogue . data [ 'latitude' ] ) return Polygon ( [ Point ( lower_lon , ...
Returns a polygon containing the bounding box of the catalogue
44,164
def make_from_catalogue ( cls , catalogue , spacing , dilate ) : new = cls ( ) cat_bbox = get_catalogue_bounding_polygon ( catalogue ) if dilate > 0 : cat_bbox = cat_bbox . dilate ( dilate ) new . update ( { 'xmin' : np . min ( cat_bbox . lons ) , 'xmax' : np . max ( cat_bbox . lons ) , 'xspc' : spacing , 'ymin' : np ....
Defines the grid on the basis of the catalogue
44,165
def write_to_csv ( self , filename ) : fid = open ( filename , 'wt' ) header_info = [ 'Longitude' , 'Latitude' , 'Depth' , 'Observed Count' , 'Smoothed Rate' , 'b-value' ] writer = csv . DictWriter ( fid , fieldnames = header_info ) headers = dict ( ( name0 , name0 ) for name0 in header_info ) writer . writerow ( heade...
Exports to simple csv
44,166
def _validate_hazard_metadata ( md ) : if ( md . get ( 'statistics' ) is not None and ( md . get ( 'smlt_path' ) is not None or md . get ( 'gsimlt_path' ) is not None ) ) : raise ValueError ( 'Cannot specify both `statistics` and logic tree ' 'paths' ) if md . get ( 'statistics' ) is not None : if md . get ( 'statistic...
Validate metadata dict of attributes which are more or less the same for hazard curves hazard maps and disaggregation histograms .
44,167
def _set_metadata ( element , metadata , attr_map , transform = str ) : for kw , attr in attr_map . items ( ) : value = metadata . get ( kw ) if value is not None : element . set ( attr , transform ( value ) )
Set metadata attributes on a given element .
44,168
def serialize ( self , data ) : with open ( self . dest , 'wb' ) as fh : root = et . Element ( 'nrml' ) self . add_hazard_curves ( root , self . metadata , data ) nrml . write ( list ( root ) , fh )
Write a sequence of hazard curves to the specified file .
44,169
def add_hazard_curves ( self , root , metadata , data ) : hazard_curves = et . SubElement ( root , 'hazardCurves' ) _set_metadata ( hazard_curves , metadata , _ATTR_MAP ) imls_elem = et . SubElement ( hazard_curves , 'IMLs' ) imls_elem . text = ' ' . join ( map ( scientificformat , metadata [ 'imls' ] ) ) gml_ns = nrml...
Add hazard curves stored into data as child of the root element with metadata . See the documentation of the method serialize and the constructor for a description of data and metadata respectively .
44,170
def serialize ( self , data , fmt = '%10.7E' ) : gmf_set_nodes = [ ] for gmf_set in data : gmf_set_node = Node ( 'gmfSet' ) if gmf_set . investigation_time : gmf_set_node [ 'investigationTime' ] = str ( gmf_set . investigation_time ) gmf_set_node [ 'stochasticEventSetId' ] = str ( gmf_set . stochastic_event_set_id ) gm...
Serialize a collection of ground motion fields to XML .
44,171
def serialize ( self , data , investigation_time ) : with open ( self . dest , 'wb' ) as fh : root = et . Element ( 'nrml' ) ses_container = et . SubElement ( root , 'ruptureCollection' ) ses_container . set ( 'investigationTime' , str ( investigation_time ) ) for grp_id in sorted ( data ) : attrs = dict ( id = grp_id ...
Serialize a collection of stochastic event sets to XML .
44,172
def serialize ( self , data ) : with open ( self . dest , 'wb' ) as fh : root = et . Element ( 'nrml' ) hazard_map = et . SubElement ( root , 'hazardMap' ) _set_metadata ( hazard_map , self . metadata , _ATTR_MAP ) for lon , lat , iml in data : node = et . SubElement ( hazard_map , 'node' ) node . set ( 'lon' , str ( l...
Serialize hazard map data to XML .
44,173
def serialize ( self , data ) : gml_ns = nrml . SERIALIZE_NS_MAP [ 'gml' ] with open ( self . dest , 'wb' ) as fh : root = et . Element ( 'nrml' ) uh_spectra = et . SubElement ( root , 'uniformHazardSpectra' ) _set_metadata ( uh_spectra , self . metadata , _ATTR_MAP ) periods_elem = et . SubElement ( uh_spectra , 'peri...
Write a sequence of uniform hazard spectra to the specified file .
44,174
def check_config ( config , data ) : essential_keys = [ 'input_mmin' , 'b-value' , 'sigma-b' ] for key in essential_keys : if not key in config . keys ( ) : raise ValueError ( 'For KijkoSellevolBayes the key %s needs to ' 'be set in the configuation' % key ) if 'tolerance' not in config . keys ( ) or not config [ 'tole...
Check config file inputs
44,175
def _compute_mean ( self , C , mag , rjb ) : ffc = self . _compute_finite_fault_correction ( mag ) d = np . sqrt ( rjb ** 2 + ( C [ 'c7' ] ** 2 ) * ( ffc ** 2 ) ) mean = ( C [ 'c1' ] + C [ 'c2' ] * ( mag - 6. ) + C [ 'c3' ] * ( ( mag - 6. ) ** 2 ) - C [ 'c4' ] * np . log ( d ) - C [ 'c6' ] * d ) factor = np . log ( rjb...
Compute ground motion mean value .
44,176
def _compute_finite_fault_correction ( self , mag ) : mw_j96 = mblg_to_mw_johnston_96 ( mag ) mw_ab87 = mblg_to_mw_atkinson_boore_87 ( mag ) t1 = np . exp ( - 1.25 + 0.227 * mw_j96 ) t2 = np . exp ( - 1.25 + 0.227 * mw_ab87 ) return np . sqrt ( t1 * t2 )
Compute finite fault correction term as geometric mean of correction terms obtained from Mw values calculated with Johnston 1996 and Atkinson and Boore 1987 conversion equations .
44,177
def get_vulnerability_functions_04 ( fname ) : categories = dict ( assetCategory = set ( ) , lossCategory = set ( ) , vulnerabilitySetID = set ( ) ) imts = set ( ) taxonomies = set ( ) vf_dict = { } for vset in nrml . read ( fname ) . vulnerabilityModel : categories [ 'assetCategory' ] . add ( vset [ 'assetCategory' ] ...
Parse the vulnerability model in NRML 0 . 4 format .
44,178
def upgrade_file ( path , multipoint ) : node0 = nrml . read ( path , chatty = False ) [ 0 ] shutil . copy ( path , path + '.bak' ) tag = striptag ( node0 . tag ) gml = True if tag == 'vulnerabilityModel' : vf_dict , cat_dict = get_vulnerability_functions_04 ( path ) node0 = Node ( 'vulnerabilityModel' , cat_dict , nod...
Upgrade to the latest NRML version
44,179
def _compute_term_3 ( self , C , rrup , mag ) : return ( C [ 'a3' ] * np . log10 ( rrup + C [ 'a4' ] * np . power ( 10 , C [ 'a5' ] * mag ) ) )
This computes the third term in equation 2 page 2 .
44,180
def mag_scale_rel_to_hazardlib ( mag_scale_rel , use_default = False ) : if isinstance ( mag_scale_rel , BaseMSR ) : return mag_scale_rel elif isinstance ( mag_scale_rel , str ) : if not mag_scale_rel in SCALE_RELS . keys ( ) : raise ValueError ( 'Magnitude scaling relation %s not supported!' % mag_scale_rel ) else : r...
Returns the magnitude scaling relation in a format readable by openquake . hazardlib
44,181
def npd_to_pmf ( nodal_plane_dist , use_default = False ) : if isinstance ( nodal_plane_dist , PMF ) : return nodal_plane_dist else : if use_default : return PMF ( [ ( 1.0 , NodalPlane ( 0.0 , 90.0 , 0.0 ) ) ] ) else : raise ValueError ( 'Nodal Plane distribution not defined' )
Returns the nodal plane distribution as an instance of the PMF class
44,182
def run_job ( job_ini , log_level = 'info' , log_file = None , exports = '' , username = getpass . getuser ( ) , ** kw ) : job_id = logs . init ( 'job' , getattr ( logging , log_level . upper ( ) ) ) with logs . handle ( job_id , log_level , log_file ) : job_ini = os . path . abspath ( job_ini ) oqparam = eng . job_fro...
Run a job using the specified config file and other options .
44,183
def run_tile ( job_ini , sites_slice ) : return run_job ( job_ini , sites_slice = ( sites_slice . start , sites_slice . stop ) )
Used in tiling calculations
44,184
def del_calculation ( job_id , confirmed = False ) : if logs . dbcmd ( 'get_job' , job_id ) is None : print ( 'There is no job %d' % job_id ) return if confirmed or confirm ( 'Are you sure you want to (abort and) delete this calculation and ' 'all associated outputs?\nThis action cannot be undone. (y/n): ' ) : try : ab...
Delete a calculation and all associated outputs .
44,185
def smart_run ( job_ini , oqparam , log_level , log_file , exports , reuse_hazard ) : haz_checksum = readinput . get_checksum32 ( oqparam , hazard = True ) job = logs . dbcmd ( 'get_job_from_checksum' , haz_checksum ) reuse = reuse_hazard and job and os . path . exists ( job . ds_calc_dir + '.hdf5' ) ebr = ( oqparam . ...
Run calculations by storing their hazard checksum and reusing previous calculations if requested .
44,186
def _get_stddevs ( self , C , sites , pga1100 , sigma_pga , stddev_types ) : std_intra = self . _compute_intra_event_std ( C , sites . vs30 , pga1100 , sigma_pga ) std_inter = C [ 't_lny' ] * np . ones_like ( sites . vs30 ) stddevs = [ ] for stddev_type in stddev_types : assert stddev_type in self . DEFINED_FOR_STANDAR...
Returns the standard deviations as described in the ALEATORY UNCERTAINTY MODEL section of the paper . Equations 13 to 19 pages 147 to 151
44,187
def _compute_intra_event_std ( self , C , vs30 , pga1100 , sigma_pga ) : sig_lnyb = np . sqrt ( C [ 's_lny' ] ** 2. - C [ 's_lnAF' ] ** 2. ) sig_lnab = np . sqrt ( sigma_pga ** 2. - C [ 's_lnAF' ] ** 2. ) alpha = self . _compute_intra_event_alpha ( C , vs30 , pga1100 ) return np . sqrt ( ( sig_lnyb ** 2. ) + ( C [ 's_l...
Returns the intra - event standard deviation at the site as defined in equation 15 page 147
44,188
def _compute_intra_event_alpha ( self , C , vs30 , pga1100 ) : alpha = np . zeros_like ( vs30 , dtype = float ) idx = vs30 < C [ 'k1' ] if np . any ( idx ) : temp1 = ( pga1100 [ idx ] + C [ 'c' ] * ( vs30 [ idx ] / C [ 'k1' ] ) ** C [ 'n' ] ) ** - 1. temp1 = temp1 - ( ( pga1100 [ idx ] + C [ 'c' ] ) ** - 1. ) alpha [ i...
Returns the linearised functional relationship between fsite and pga1100 determined from the partial derivative defined on equation 17 on page 148
44,189
def _get_total_sigma ( self , C , std_intra , std_inter ) : return np . sqrt ( std_intra ** 2. + std_inter ** 2. + C [ 'c_lny' ] ** 2. )
Returns the total sigma term for the arbitrary horizontal component of ground motion defined by equation 18 page 150
44,190
def generate_event_set ( ucerf , background_sids , src_filter , ses_idx , seed ) : serial = seed + ses_idx * TWO16 with h5py . File ( ucerf . source_file , 'r' ) as hdf5 : occurrences = ucerf . tom . sample_number_of_occurrences ( ucerf . rate , seed ) indices , = numpy . where ( occurrences ) logging . debug ( 'Consid...
Generates the event set corresponding to a particular branch
44,191
def sample_background_model ( hdf5 , branch_key , tom , seed , filter_idx , min_mag , npd , hdd , upper_seismogenic_depth , lower_seismogenic_depth , msr = WC1994 ( ) , aspect = 1.5 , trt = DEFAULT_TRT ) : bg_magnitudes = hdf5 [ "/" . join ( [ "Grid" , branch_key , "Magnitude" ] ) ] . value mag_idx = bg_magnitudes >= m...
Generates a rupture set from a sample of the background model
44,192
def get_median_area ( self , mag , rake ) : assert rake is None or - 180 <= rake <= 180 if rake is None : return 10.0 ** ( - 3.49 + 0.91 * mag ) elif ( - 45 <= rake <= 45 ) or ( rake >= 135 ) or ( rake <= - 135 ) : return 10.0 ** ( - 3.42 + 0.90 * mag ) elif rake > 0 : return 10.0 ** ( - 3.99 + 0.98 * mag ) else : retu...
The values are a function of both magnitude and rake .
44,193
def get_std_dev_area ( self , mag , rake ) : assert rake is None or - 180 <= rake <= 180 if rake is None : return 0.24 elif ( - 45 <= rake <= 45 ) or ( rake >= 135 ) or ( rake <= - 135 ) : return 0.22 elif rake > 0 : return 0.26 else : return 0.22
Standard deviation for WC1994 . Magnitude is ignored .
44,194
def get_std_dev_mag ( self , rake ) : assert rake is None or - 180 <= rake <= 180 if rake is None : return 0.24 elif ( - 45 <= rake <= 45 ) or ( rake >= 135 ) or ( rake <= - 135 ) : return 0.23 elif rake > 0 : return 0.25 else : return 0.25
Standard deviation on the magnitude for the WC1994 area relation .
44,195
def set_parameters ( self ) : for key in dir ( self ) : if key . startswith ( 'REQUIRES_' ) : setattr ( self , key , getattr ( self . gmpe , key ) ) if key . startswith ( 'DEFINED_' ) : if not key . endswith ( 'FOR_INTENSITY_MEASURE_TYPES' ) : setattr ( self , key , getattr ( self . gmpe , key ) )
Combines the parameters of the GMPE provided at the construction level with the ones assigned to the average GMPE .
44,196
def from_points_list ( cls , points ) : lons = numpy . zeros ( len ( points ) , dtype = float ) lats = lons . copy ( ) depths = lons . copy ( ) for i in range ( len ( points ) ) : lons [ i ] = points [ i ] . longitude lats [ i ] = points [ i ] . latitude depths [ i ] = points [ i ] . depth if not depths . any ( ) : dep...
Create a mesh object from a collection of points .
44,197
def get_min_distance ( self , mesh ) : return cdist ( self . xyz , mesh . xyz ) . min ( axis = 0 )
Compute and return the minimum distance from the mesh to each point in another mesh .
44,198
def get_closest_points ( self , mesh ) : min_idx = cdist ( self . xyz , mesh . xyz ) . argmin ( axis = 0 ) if hasattr ( mesh , 'shape' ) : min_idx = min_idx . reshape ( mesh . shape ) lons = self . lons . take ( min_idx ) lats = self . lats . take ( min_idx ) deps = self . depths . take ( min_idx ) return Mesh ( lons ,...
Find closest point of this mesh for each point in the other mesh
44,199
def get_distance_matrix ( self ) : assert self . lons . ndim == 1 distances = geodetic . geodetic_distance ( self . lons . reshape ( self . lons . shape + ( 1 , ) ) , self . lats . reshape ( self . lats . shape + ( 1 , ) ) , self . lons , self . lats ) return numpy . matrix ( distances , copy = False )
Compute and return distances between each pairs of points in the mesh .