openquake.commonlib package

calc module

class openquake.commonlib.calc.RuptureSerializer(datastore)[source]

Bases: object

Serialize event based ruptures on an HDF5 files. Populate the datasets ruptures and sids.

close()[source]

Save information about the rupture codes as attributes of the ‘ruptures’ dataset.

save(rup_array)[source]

Store the ruptures in array format.

openquake.commonlib.calc.compute_hazard_maps(curves, imls, poes)[source]

Given a set of hazard curve poes, interpolate a hazard map at the specified poe.

Parameters:
  • curves – 2D array of floats. Each row represents a curve, where the values in the row are the PoEs (Probabilities of Exceedance) corresponding to imls. Each curve corresponds to a geographical location.
  • imls – Intensity Measure Levels associated with these hazard curves. Type should be an array-like of floats.
  • poes – Value(s) on which to interpolate a hazard map from the input curves. Can be an array-like or scalar value (for a single PoE).
Returns:

An array of shape N x P, where N is the number of curves and P the number of poes.

openquake.commonlib.calc.convert_to_array(pmap, nsites, imtls, inner_idx=0)[source]

Convert the probability map into a composite array with header of the form PGA-0.1, PGA-0.2 …

Parameters:
  • pmap – probability map
  • nsites – total number of sites
  • imtls – a DictArray with IMT and levels
Returns:

a composite array of lenght nsites

openquake.commonlib.calc.make_hmap(pmap, imtls, poes, sid=None)[source]

Compute the hazard maps associated to the passed probability map.

Parameters:
  • pmap – hazard curves in the form of a ProbabilityMap
  • imtls – DictArray with M intensity measure types
  • poes – P PoEs where to compute the maps
  • sid – not None when pmap is actually a ProbabilityCurve
Returns:

a ProbabilityMap with size (N, M, P)

openquake.commonlib.calc.make_hmap_array(pmap, imtls, poes, nsites)[source]
Returns:a compound array of hazard maps of shape nsites
openquake.commonlib.calc.make_uhs(hmap, info)[source]

Make Uniform Hazard Spectra curves for each location.

Parameters:
  • hmap – array of shape (N, M, P)
  • info – a dictionary with keys poes, imtls, uhs_dt
Returns:

a composite array containing uniform hazard spectra

hazard_writers module

Classes for serializing various NRML XML artifacts.

class openquake.commonlib.hazard_writers.BaseCurveWriter(dest, **metadata)[source]

Bases: object

Base class for curve writers.

Parameters:
  • dest – File path (including filename) or file-like object for results to be saved to.
  • metadata

    The following keyword args are required:

    • investigation_time: Investigation time (in years) defined in the calculation which produced these results.

    The following are more or less optional (combinational rules noted below where applicable):

    • statistics: ‘mean’ or ‘quantile’
    • quantile_value: Only required if statistics = ‘quantile’.
    • smlt_path: String representing the logic tree path which produced these curves. Only required for non-statistical curves.
    • gsimlt_path: String represeting the GSIM logic tree path which produced these curves. Only required for non-statisical curves.
serialize(_data)[source]

Implement in subclasses.

class openquake.commonlib.hazard_writers.DisaggXMLWriter(dest, **metadata)[source]

Bases: object

Parameters:
  • dest – File path (including filename) or file-like object for XML results to be saved to.
  • metadata

    The following keyword args are required:

    • investigation_time: Investigation time (in years) defined in the calculation which produced these results.
    • imt: Intensity measure type used to compute these matrices.
    • lon, lat: Longitude and latitude associated with these results.

    The following attributes define dimension context for the result matrices:

    • mag_bin_edges: List of magnitude bin edges (floats)
    • dist_bin_edges: List of distance bin edges (floats)
    • lon_bin_edges: List of longitude bin edges (floats)
    • lat_bin_edges: List of latitude bin edges (floats)
    • eps_bin_edges: List of epsilon bin edges (floats)
    • tectonic_region_types: List of tectonic region types (strings)
    • smlt_path: String representing the logic tree path which produced these results. Only required for non-statistical results.
    • gsimlt_path: String represeting the GSIM logic tree path which produced these results. Only required for non-statistical results.

    The following are optional, depending on the imt:

    • sa_period
    • sa_damping
BIN_EDGE_ATTR_MAP = {'mag_bin_edges': 'magBinEdges', 'dist_bin_edges': 'distBinEdges', 'lon_bin_edges': 'lonBinEdges', 'lat_bin_edges': 'latBinEdges', 'eps_bin_edges': 'epsBinEdges', 'tectonic_region_types': 'tectonicRegionTypes'}

Maps metadata keywords to XML attribute names for bin edge information passed to the constructor.

DIM_LABEL_TO_BIN_EDGE_MAP = {'Mag': 'mag_bin_edges', 'Dist': 'dist_bin_edges', 'Lon': 'lon_bin_edges', 'Lat': 'lat_bin_edges', 'Eps': 'eps_bin_edges', 'TRT': 'tectonic_region_types'}
serialize(data)[source]
Parameters:data

A sequence of data where each datum has the following attributes:

  • matrix: N-dimensional numpy array containing the disaggregation histogram.
  • dim_labels: A list of strings which label the dimensions of a given histogram. For example, for a Magnitude-Distance-Epsilon histogram, we would expect dim_labels to be ['Mag', 'Dist', 'Eps'].
  • poe: The disaggregation Probability of Exceedance level for which these results were produced.
  • iml: Intensity measure level, interpolated from the source hazard curve at the given poe.
class openquake.commonlib.hazard_writers.HazardCurveXMLWriter(dest, **metadata)[source]

Bases: openquake.commonlib.hazard_writers.BaseCurveWriter

Hazard Curve XML writer. See BaseCurveWriter for a list of general constructor inputs.

The following additional metadata params are required:
  • imt: Intensity measure type used to compute these hazard curves.
  • imls: Intensity measure levels, which represent the x-axis values of each curve.
The following parameters are optional:
  • sa_period: Only used with imt = ‘SA’.
  • sa_damping: Only used with imt = ‘SA’.
add_hazard_curves(root, metadata, data)[source]

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.

serialize(data)[source]

Write a sequence of hazard curves to the specified file.

Parameters:data

Iterable of hazard curve data. Each datum must be an object with the following attributes:

  • poes: A list of probability of exceedence values (floats).
  • location: An object representing the location of the curve; must have x and y to represent lon and lat, respectively.
class openquake.commonlib.hazard_writers.HazardMapWriter(dest, **metadata)[source]

Bases: object

Parameters:
  • dest – File path (including filename) or a file-like object for results to be saved to.
  • metadata

    The following keyword args are required:

    • investigation_time: Investigation time (in years) defined in the calculation which produced these results.
    • imt: Intensity measure type used to compute these hazard curves.
    • poe: The Probability of Exceedance level for which this hazard map was produced.

    The following are more or less optional (combinational rules noted below where applicable):

    • statistics: ‘mean’ or ‘quantile’
    • quantile_value: Only required if statistics = ‘quantile’.
    • smlt_path: String representing the logic tree path which produced these curves. Only required for non-statistical curves.
    • gsimlt_path: String represeting the GSIM logic tree path which produced these curves. Only required for non-statisical curves.
    • sa_period: Only used with imt = ‘SA’.
    • sa_damping: Only used with imt = ‘SA’.
serialize(data)[source]

Write a sequence of hazard map data to the specified file.

Parameters:data – Iterable of hazard map data. Each datum should be a triple of (lon, lat, iml) values.
class openquake.commonlib.hazard_writers.HazardMapXMLWriter(dest, **metadata)[source]

Bases: openquake.commonlib.hazard_writers.HazardMapWriter

NRML/XML implementation of a HazardMapWriter.

See HazardMapWriter for information about constructor parameters.

serialize(data)[source]

Serialize hazard map data to XML.

See HazardMapWriter.serialize() for details about the expected input.

class openquake.commonlib.hazard_writers.SESXMLWriter(dest)[source]

Bases: object

Parameters:
  • dest – File path (including filename) or a file-like object for XML results to be saved to.
  • sm_lt_path (str) – Source model logic tree branch identifier of the logic tree realization which produced this collection of stochastic event sets.
  • gsim_lt_path – GSIM logic tree branch identifier of the logic tree realization which produced this collection of stochastic event sets.
serialize(data, investigation_time)[source]

Serialize a collection of stochastic event sets to XML.

Parameters:
  • data

    A dictionary grp_id -> list of openquake.commonlib.calc.Rupture objects. Each Rupture should have the following attributes:

    • rupid
    • events_by_ses
    • magnitude
    • strike
    • dip
    • rake
    • tectonic_region_type
    • is_from_fault_source (a bool)
    • is_multi_surface (a bool)
    • lons
    • lats
    • depths

    If is_from_fault_source is True, the rupture originated from a simple or complex fault sources. In this case, lons, lats, and depths should all be 2D arrays (of uniform shape). These coordinate triples represent nodes of the rupture mesh.

    If is_from_fault_source is False, the rupture originated from a point or area source. In this case, the rupture is represented by a quadrilateral planar surface. This planar surface is defined by 3D vertices. In this case, the rupture should have the following attributes:

    • top_left_corner
    • top_right_corner
    • bottom_right_corner
    • bottom_left_corner

    Each of these should be a triple of lon, lat, depth.

    If is_multi_surface is True, the rupture originated from a multi-surface source. In this case, lons, lats, and depths should have uniform length. The length should be a multiple of 4, where each segment of 4 represents the corner points of a planar surface in the following order:

    • top left
    • top right
    • bottom left
    • bottom right

    Each of these should be a triple of lon, lat, depth.

  • investigation_time – Investigation time parameter specified in the job.ini
class openquake.commonlib.hazard_writers.UHSXMLWriter(dest, **metadata)[source]

Bases: openquake.commonlib.hazard_writers.BaseCurveWriter

UHS curve XML writer. See BaseCurveWriter for a list of general constructor inputs.

The following additional metadata params are required:
  • poe: Probability of exceedance for which a given set of UHS have been
    computed
  • periods: A list of SA (Spectral Acceleration) period values, sorted
    ascending order
serialize(data)[source]

Write a sequence of uniform hazard spectra to the specified file.

Parameters:data

Iterable of UHS data. Each datum must be an object with the following attributes:

  • imls: A sequence of Intensity Measure Levels
  • location: An object representing the location of the curve; must have x and y to represent lon and lat, respectively.
openquake.commonlib.hazard_writers.gen_gmfs(gmf_set)[source]

Generate GMF nodes from a gmf_set :param gmf_set: a sequence of GMF objects with attributes imt, sa_period, sa_damping, event_id and containing a list of GMF nodes with attributes gmv and location. The nodes are sorted by lon/lat.

openquake.commonlib.hazard_writers.rupture_to_element(rup, parent=None)[source]

Convert a rupture object into an Element object.

Parameters:
  • rup – must have attributes .rupid, .events_by_ses and .seed
  • parent – parent of the returned element, or None
openquake.commonlib.hazard_writers.sub_elems(elem, rup, *names)[source]

logictree module

Logic tree parser, verifier and processor. See specs at https://blueprints.launchpad.net/openquake-old/+spec/openquake-logic-tree-module

A logic tree object must be iterable and yielding realizations, i.e. objects with attributes value, weight, lt_path and ordinal.

class openquake.commonlib.logictree.BranchTuple(trt, id, gsim, weight, effective)

Bases: tuple

effective

Alias for field number 4

gsim

Alias for field number 2

id

Alias for field number 1

trt

Alias for field number 0

weight

Alias for field number 3

class openquake.commonlib.logictree.FullLogicTree(source_model_lt, gsim_lt)[source]

Bases: object

The full logic tree as composition of

Parameters:
classmethod fake(gsimlt=None)[source]
Returns:a fake FullLogicTree instance with the given gsim logic tree object; if None, builds automatically a fake gsim logic tree
get_grp_id(trt, eri)[source]
Returns:grp_id
get_gsims_by_trt()[source]
Returns:a dictionary trt -> sorted gsims
get_num_rlzs(sm_rlz=None)[source]
Parameters:sm_rlz – a Realization instance (or None)
Returns:the number of realizations per source model (or all)
get_realizations()[source]
Returns:the complete list of LtRealizations
get_rlzs(eri)[source]
Returns:a list of LtRealization objects
get_rlzs_by_grp()[source]
Returns:a dictionary grp_id -> [rlzis, …]
get_rlzs_by_gsim(grp_id)[source]
Returns:a dictionary gsim -> rlzs
get_rlzs_by_gsim_grp()[source]
Returns:a dictionary grp_id -> gsim -> rlzs
get_samples_by_grp()[source]
Returns:a dictionary grp_id -> source_model.samples
get_sm_by_grp()[source]
Returns:a dictionary grp_id -> sm_id
get_trti_eri(grp_id)[source]
Returns:(trti, eri)
grp_ids(eri)[source]
Parameters:eri – effective realization index
Returns:array of T group IDs, being T the number of TRTs
gsim_by_trt(rlz)[source]
Returns:a dictionary trt->gsim for the given realization
init()[source]
num_samples
Returns:the source_model_lt num_samples parameter
rlzs
Returns:an array of realizations
seed
Returns:the source_model_lt seed
trt_by_grp
Returns:a dictionary grp_id -> trt
class openquake.commonlib.logictree.GsimLogicTree(fname, tectonic_region_types=['*'], ltnode=None)[source]

Bases: object

A GsimLogicTree instance is an iterable yielding Realization tuples with attributes value, weight and lt_path, where value is a dictionary {trt: gsim}, weight is a number in the interval 0..1 and lt_path is a tuple with the branch ids of the given realization.

Parameters:
  • fname (str) – full path of the gsim_logic_tree file
  • tectonic_region_types – a sequence of distinct tectonic region types
  • ltnode – usually None, but it can also be a openquake.hazardlib.nrml.Node object describing the GSIM logic tree XML file, to avoid reparsing it
check_imts(imts)[source]

Make sure the IMTs are recognized by all GSIMs in the logic tree

collapse(branchset_ids)[source]

Collapse the GsimLogicTree by using AgvGMPE instances if needed

Parameters:branchset_ids – branchset ids to collapse
Returns:a collapse GsimLogicTree instance
classmethod from_(gsim)[source]

Generate a trivial GsimLogicTree from a single GSIM instance.

get_gsims(trt)[source]
Parameters:trt – tectonic region type
Returns:sorted list of available GSIMs for that trt
get_num_branches()[source]

Return the number of effective branches for tectonic region type, as a dictionary.

get_num_paths()[source]

Return the effective number of paths in the tree.

reduce(trts)[source]

Reduce the GsimLogicTree.

Parameters:trts – a subset of tectonic region types
Returns:a reduced GsimLogicTree instance
req_site_params
sample(n, seed)[source]
Parameters:
  • n – number of samples
  • seed – random seed
Returns:

n Realization objects

class openquake.commonlib.logictree.ImtWeight(branch, fname)[source]

Bases: object

A composite weight by IMTs extracted from the gsim_logic_tree_file

is_one()[source]

Check that all the inner weights are 1 up to the precision

class openquake.commonlib.logictree.Info(smpaths, applytosources)

Bases: tuple

applytosources

Alias for field number 1

smpaths

Alias for field number 0

exception openquake.commonlib.logictree.InvalidLogicTree[source]

Bases: Exception

class openquake.commonlib.logictree.LtRealization(ordinal, sm_lt_path, gsim_rlz, weight)[source]

Bases: object

Composite realization build on top of a source model realization and a GSIM realization.

gsim_lt_path
pid

An unique identifier for effective realizations

class openquake.commonlib.logictree.Realization(value, weight, ordinal, lt_path, samples, offset=0)[source]

Bases: object

Generic Realization object with attributes value, weight, ordinal, lt_path, samples and optionally offset.

name

Compact representation for the names

pid
class openquake.commonlib.logictree.SourceModelLogicTree(filename, seed=0, num_samples=0)[source]

Bases: object

Source model logic tree parser.

Parameters:filename – Full pathname of logic tree file
Raises:LogicTreeError – If logic tree file has a logic error, which can not be prevented by xml schema rules (like referencing sources with missing id).
FILTERS = ('applyToTectonicRegionType', 'applyToSources', 'applyToSourceType')
apply_branchset(apply_to_branches, lineno, branchset)[source]

See superclass’ method for description and signature specification.

Parses branchset node’s attribute @applyToBranches to apply following branchests to preceding branches selectively. Branching level can have more than one branchset exactly for this: different branchsets can apply to different open ends.

Checks that branchset tries to be applied only to branches on previous branching level which do not have a child branchset yet.

bset_values(sm_rlz)[source]
Parameters:sm_rlz – an effective realization
Returns:a list of B - 1 pairs (branchset, value)
collapse(branchset_ids)[source]

Set the attribute .collapsed on the given branchsets

collect_source_model_data(branch_id, source_model)[source]

Parse source model file and collect information about source ids, source types and tectonic region types available in it. That information is used then for validate_filters() and validate_uncertainty_value().

classmethod fake()[source]
Returns:a fake SourceModelLogicTree with a single branch
on_each_source

True if there is an applyToSources for each source.

parse_branches(branchset_node, branchset)[source]

Create and attach branches at branchset_node to branchset.

Parameters:
  • branchset_node – Same as for parse_branchset().
  • branchset – An instance of BranchSet.

Checks that each branch has valid value, unique id and that all branches have total weight of 1.0.

Returns:None, all branches are attached to provided branchset.
parse_branchset(branchset_node, depth)[source]
Parameters:
  • node (branchset) – etree.Element object with tag “logicTreeBranchSet”.
  • depth – The sequential number of this branching level, based on 0.

Enumerates children branchsets and call parse_branchset(), validate_branchset(), parse_branches() and finally apply_branchset() for each.

Keeps track of “open ends” – the set of branches that don’t have any child branchset on this step of execution. After processing of every branchset only those branches that are listed in it can have child branchsets (if there is one on the next level).

parse_filters(branchset_node, uncertainty_type, filters)[source]

See superclass’ method for description and signature specification.

Converts “applyToSources” filter value by just splitting it to a list.

parse_tree(tree_node)[source]

Parse the whole tree and point root_branchset attribute to the tree’s root.

validate_branchset(branchset_node, depth, branchset)[source]

See superclass’ method for description and signature specification.

Checks that the following conditions are met:

  • First branching level must contain exactly one branchset, which must be of type “sourceModel”.
  • All other branchsets must not be of type “sourceModel” or “gmpeModel”.
validate_filters(branchset_node, uncertainty_type, filters)[source]

See superclass’ method for description and signature specification.

Checks that the following conditions are met:

  • “sourceModel” uncertainties can not have filters.
  • Absolute uncertainties must have only one filter – “applyToSources”, with only one source id.
  • All other uncertainty types can have either no or one filter.
  • Filter “applyToSources” must mention only source ids that exist in source models.
  • Filter “applyToTectonicRegionType” must mention only tectonic region types that exist in source models.
  • Filter “applyToSourceType” must mention only source types that exist in source models.
openquake.commonlib.logictree.capitalize(words)[source]

Capitalize words separated by spaces.

openquake.commonlib.logictree.collect_info(smlt)[source]

Given a path to a source model logic tree, collect all of the path names to the source models it contains and build 1. a dictionary source model branch ID -> paths 2. a dictionary source model branch ID -> source IDs in applyToSources

Parameters:smlt – source model logic tree file
Returns:an Info namedtupled containing the two dictionaries
openquake.commonlib.logictree.get_effective_rlzs[source]

Group together realizations with the same path and yield the first representative of each group.

openquake.commonlib.logictree.get_field(data, field, default)[source]
Parameters:data – a record with a field field, possibily missing
openquake.commonlib.logictree.read_source_groups(fname)[source]
Parameters:fname – a path to a source model XML file
Returns:a list of SourceGroup objects containing source nodes
openquake.commonlib.logictree.taxonomy_mapping(filename, taxonomies)[source]
Parameters:
  • filename – path to the CSV file containing the taxonomy associations
  • taxonomies – an array taxonomy string -> taxonomy index
Returns:

(array, [[(taxonomy, weight), …], …])

openquake.commonlib.logictree.unique(objects, key=None)[source]

Raise a ValueError if there is a duplicated object, otherwise returns the objects as they are.

logs module

Set up some system-wide loggers

class openquake.commonlib.logs.LogDatabaseHandler(job_id)[source]

Bases: logging.Handler

Log stream handler

emit(record)[source]
class openquake.commonlib.logs.LogFileHandler(job_id, log_file)[source]

Bases: logging.FileHandler

Log file handler

emit(record)[source]
class openquake.commonlib.logs.LogStreamHandler(job_id)[source]

Bases: logging.StreamHandler

Log stream handler

emit(record)[source]
openquake.commonlib.logs.dbcmd(action, *args)[source]

A dispatcher to the database server.

Parameters:
  • action (string) – database action to perform
  • args (tuple) – arguments
openquake.commonlib.logs.handle(job_id, log_level='info', log_file=None)[source]

Context manager adding and removing log handlers.

Parameters:
  • job_id – ID of the current job
  • log_level – one of debug, info, warn, error, critical
  • log_file – log file path (if None, logs on stdout only)
openquake.commonlib.logs.init(calc_id='nojob', level=20)[source]
  1. initialize the root logger (if not already initialized)
  2. set the format of the root handlers (if any)
  3. return a new calculation ID candidate if calc_id is ‘job’ or ‘nojob’ (with ‘nojob’ the calculation ID is not stored in the database)
openquake.commonlib.logs.touch_log_file(log_file)[source]

If a log file destination is specified, attempt to open the file in ‘append’ mode (‘a’). If the specified file is not writable, an IOError will be raised.

oqvalidation module

class openquake.commonlib.oqvalidation.OqParam(**names_vals)[source]

Bases: openquake.hazardlib.valid.ParamSet

KNOWN_INPUTS = {'taxonomy_mapping', 'structural_vulnerability_retrofitted', 'occupants_vulnerability', 'exposure', 'reqv', 'source_model', 'business_interruption_vulnerability', 'multi_peril', 'gmfs', 'insurance', 'job_ini', 'site_model', 'sites', 'source_model_logic_tree', 'nonstructural_consequence', 'structural_consequence', 'rupture_model', 'business_interruption_consequence', 'input_zip', 'contents_vulnerability', 'shakemap', 'gsim_logic_tree', 'fragility', 'contents_consequence', 'hazard_curves', 'contents_fragility', 'structural_vulnerability', 'nonstructural_fragility', 'nonstructural_vulnerability', 'business_interruption_fragility', 'consequence', 'amplification', 'structural_fragility'}
aggregate_by

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
all_cost_types

Return the cost types of the computation (including occupants if it is there) in order.

approx_ddd

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
area_source_discretization

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
ash_wet_amplification_factor

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
asset_correlation

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
asset_hazard_distance

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
asset_life_expectancy

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
asset_loss_table

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
assets_per_site_limit

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
avg_losses

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
base_path

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
calculation_mode

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
check_gsims(gsims)[source]
Parameters:gsims – a sequence of GSIM instances
check_missing(param, action)[source]

Make sure the given parameter is missing in the job.ini file

check_source_model()[source]
check_uniform_hazard_spectra()[source]
collapse_gsim_logic_tree

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
collapse_level

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
collapse_threshold

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
compare_with_classical

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
complex_fault_mesh_spacing

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
concurrent_tasks

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
conditional_loss_poes

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
continuous_fragility_discretization

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
coordinate_bin_width

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
correl_model

Return a correlation object. See openquake.hazardlib.correlation for more info.

cross_correlation

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
description

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
disagg_by_src

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
disagg_outputs

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
discard_assets

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
discard_trts

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
distance_bin_width

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
ebrisk_maxsize

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
export_dir

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
export_multi_curves

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
exports

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
filter_distance

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
get_kinds(kind, R)[source]

Yield ‘rlz-000’, ‘rlz-001’, …’, ‘mean’, ‘quantile-0.1’, …

get_reqv()[source]
Returns:an instance of class:RjbEquivalent if reqv_hdf5 is set
gmf_data_dt()[source]
Returns:a composite data type for the GMFs
ground_motion_correlation_model

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
ground_motion_correlation_params

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
ground_motion_fields

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
gsim

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
hazard_calculation_id

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
hazard_curves_from_gmfs

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
hazard_maps

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
hazard_output_id

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
hazard_precomputed()[source]
Returns:True if the hazard is precomputed
hazard_stats()[source]

Return a dictionary stat_name -> stat_func

hmap_dt()[source]
Returns:a composite dtype (imt, poe)
hypocenter

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
ignore_covs

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
ignore_missing_costs

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
iml_disagg

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
imt_dt(dtype=<class 'numpy.float64'>)[source]
Returns:a numpy dtype {imt: float}
imt_periods()[source]
Returns:the IMTs with a period, as objects
imtls

Returns a DictArray with the risk intensity measure types and levels, if given, or the hazard ones.

individual_curves

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
input_dir
Returns:absolute path to where the job.ini is
inputs

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
intensity_measure_types

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
intensity_measure_types_and_levels

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
interest_rate

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
investigation_time

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
is_event_based()[source]

The calculation mode is event_based, event_based_risk or ebrisk

is_ucerf()[source]
Returns:True for UCERF calculations, False otherwise
is_valid_complex_fault_mesh_spacing()[source]

The complex_fault_mesh_spacing parameter can be None only if rupture_mesh_spacing is set. In that case it is identified with it.

is_valid_export_dir()[source]

export_dir={export_dir} must refer to a directory, and the user must have the permission to write on it.

is_valid_geometry()[source]

It is possible to infer the geometry only if exactly one of sites, sites_csv, hazard_curves_csv, region is set. You did set more than one, or nothing.

is_valid_intensity_measure_levels()[source]

In order to compute hazard curves, intensity_measure_types_and_levels must be set or extracted from the risk models.

is_valid_intensity_measure_types()[source]

If the IMTs and levels are extracted from the risk models, they must not be set directly. Moreover, if intensity_measure_types_and_levels is set directly, intensity_measure_types must not be set.

is_valid_maximum_distance()[source]

Invalid maximum_distance={maximum_distance}: {error}

is_valid_poes()[source]

When computing hazard maps and/or uniform hazard spectra, the poes list must be non-empty.

is_valid_shakemap()[source]

hazard_calculation_id must be set if shakemap_id is set

is_valid_sites_disagg()[source]

The option sites_disagg (when given) requires specific_assets to be set.

is_valid_specific_assets()[source]

Read the special assets from the parameters specific_assets or specific_assets_csv, if present. You cannot have both. The concept is meaninful only for risk calculators.

is_valid_truncation_level()[source]

In presence of a correlation model the truncation level must be nonzero

is_valid_truncation_level_disaggregation()[source]

Truncation level must be set for disaggregation calculations

job_type

‘hazard’ or ‘risk’

loss_dt(dtype=<class 'numpy.float32'>)[source]
Returns:a composite dtype based on the loss types including occupants
loss_dt_list(dtype=<class 'numpy.float32'>)[source]
Returns:a data type list [(loss_name, dtype), …]
loss_maps_dt(dtype=<class 'numpy.float32'>)[source]

Return a composite data type for loss maps

loss_names

Loss types plus insured types, if any

lrem_steps_per_interval

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
lti

Dictionary extended_loss_type -> extended_loss_type index

mag_bin_width

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
master_seed

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
max

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
max_data_transfer

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
max_potential_gmfs

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
max_potential_paths

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
max_sites_disagg

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
max_sites_per_gmf

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
max_weight

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
maximum_distance

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
mean

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
mean_hazard_curves

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
min_iml
Returns:a numpy array of intensities, one per IMT
min_weight

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
minimum_asset_loss

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
minimum_intensity

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
minimum_magnitude

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
modal_damage_state

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
no_imls()[source]

Return True if there are no intensity measure levels

num_cores

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
num_epsilon_bins

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
num_rlzs_disagg

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
number_of_ground_motion_fields

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
number_of_logic_tree_samples

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
poes

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
poes_disagg

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
point_rupture_bins

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
pointsource_distance

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
quantile_hazard_curves

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
quantiles

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
random_seed

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
reference_backarc

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
reference_depth_to_1pt0km_per_sec

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
reference_depth_to_2pt5km_per_sec

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
reference_siteclass

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
reference_vs30_type

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
reference_vs30_value

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
region

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
region_grid_spacing

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
return_periods

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
risk_files
risk_imtls

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
risk_investigation_time

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
rlz_index

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
rupture_mesh_spacing

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
ruptures_per_block

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
save_disk_space

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
ses_per_logic_tree_path

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
ses_ratio

The ratio

risk_investigation_time / investigation_time / ses_per_logic_tree_path

ses_seed

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
set_risk_imtls(risk_models)[source]
Parameters:risk_models – a dictionary taxonomy -> loss_type -> risk_function

Set the attribute risk_imtls.

shakemap_id

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
shift_hypo

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
site_effects

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
siteparam = {'vs30measured': 'reference_vs30_type', 'vs30': 'reference_vs30_value', 'z1pt0': 'reference_depth_to_1pt0km_per_sec', 'z2pt5': 'reference_depth_to_2pt5km_per_sec', 'siteclass': 'reference_siteclass', 'backarc': 'reference_backarc'}
sites

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
sites_disagg

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
sites_slice

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
sm_lt_path

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
soil_intensities

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
source_id

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
spatial_correlation

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
specific_assets

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
split_sources

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
std

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
steps_per_interval

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
taxonomies_from_model

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
time_event

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
truncation_level

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
tses

Return the total time as investigation_time * ses_per_logic_tree_path * (number_of_logic_tree_samples or 1)

uhs_dt()[source]
Returns:a composity dtype (poe, imt)
uniform_hazard_spectra

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
vs30_tolerance

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
width_of_mfd_bin

A descriptor for validated parameters with a default, to be used as attributes in ParamSet objects.

Parameters:
  • validator – the validator
  • default – the default value
openquake.commonlib.oqvalidation.check_same_levels(imtls)[source]
Parameters:imtls – a dictionary (or dict-like) imt -> imls
Returns:the periods and the levels
Raises:a ValueError if the levels are not the same across all IMTs

readinput module

exception openquake.commonlib.readinput.DuplicatedPoint[source]

Bases: Exception

Raised when reading a CSV file with duplicated (lon, lat) pairs

class openquake.commonlib.readinput.Site(sid, lon, lat)

Bases: tuple

lat

Alias for field number 2

lon

Alias for field number 1

sid

Alias for field number 0

openquake.commonlib.readinput.collect_files(dirpath, cond=<function <lambda>>)[source]

Recursively collect the files contained inside dirpath.

Parameters:
  • dirpath – path to a readable directory
  • cond – condition on the path to collect the file
openquake.commonlib.readinput.extract_from_zip(path, candidates)[source]

Given a zip archive and a function to detect the presence of a given filename, unzip the archive into a temporary directory and return the full path of the file. Raise an IOError if the file cannot be found within the archive.

Parameters:
  • path – pathname of the archive
  • candidates – list of names to search for
openquake.commonlib.readinput.get_amplification(oqparam)[source]
Returns:a composite array (amplification, param, imt0, imt1, …)
openquake.commonlib.readinput.get_checksum32(oqparam, hazard=False)[source]

Build an unsigned 32 bit integer from the input files of a calculation.

Parameters:
  • oqparam – an OqParam instance
  • hazard – if True, consider only the hazard files
Returns:

the checkume

openquake.commonlib.readinput.get_composite_source_model(oqparam, full_lt=None, h5=None)[source]

Parse the XML and build a complete composite source model in memory.

Parameters:
openquake.commonlib.readinput.get_crmodel(oqparam)[source]
Return a openquake.risklib.riskinput.CompositeRiskModel instance
Parameters:oqparam – an openquake.commonlib.oqvalidation.OqParam instance
openquake.commonlib.readinput.get_csv_header(fname, sep=', ')[source]
Parameters:
  • fname – a CSV file
  • sep – the separator (default comma)
Returns:

the first line of fname

openquake.commonlib.readinput.get_exposure(oqparam)[source]

Read the full exposure in memory and build a list of openquake.risklib.asset.Asset instances.

Parameters:oqparam – an openquake.commonlib.oqvalidation.OqParam instance
Returns:an Exposure instance or a compatible AssetCollection
openquake.commonlib.readinput.get_full_lt(oqparam)[source]
Parameters:oqparam – an openquake.commonlib.oqvalidation.OqParam instance
Returns:a openquake.commonlib.logictree.FullLogicTree instance
openquake.commonlib.readinput.get_gsim_lt(oqparam, trts=('*', ))[source]
Parameters:
Returns:

a GsimLogicTree instance obtained by filtering on the provided tectonic region types.

openquake.commonlib.readinput.get_gsims(oqparam)[source]

Return an ordered list of GSIM instances from the gsim name in the configuration file or from the gsim logic tree file.

Parameters:oqparam – an openquake.commonlib.oqvalidation.OqParam instance
openquake.commonlib.readinput.get_imts(oqparam)[source]

Return a sorted list of IMTs as hazardlib objects

openquake.commonlib.readinput.get_input_files(oqparam, hazard=False)[source]
Parameters:
  • oqparam – an OqParam instance
  • hazard – if True, consider only the hazard files
Returns:

input path names in a specific order

openquake.commonlib.readinput.get_mesh(oqparam)[source]

Extract the mesh of points to compute from the sites, the sites_csv, the region, the site model, the exposure in this order.

Parameters:oqparam – an openquake.commonlib.oqvalidation.OqParam instance
openquake.commonlib.readinput.get_oqparam(job_ini, pkg=None, calculators=None, hc_id=None, validate=1, **kw)[source]

Parse a dictionary of parameters from an INI-style config file.

Parameters:
  • job_ini – Path to configuration file/archive or dictionary of parameters
  • pkg – Python package where to find the configuration file (optional)
  • calculators – Sequence of calculator names (optional) used to restrict the valid choices for calculation_mode
  • hc_id – Not None only when called from a post calculation
  • validate – Flag. By default it is true and the parameters are validated
  • kw – String-valued keyword arguments used to override the job.ini parameters
Returns:

An openquake.commonlib.oqvalidation.OqParam instance containing the validate and casted parameters/values parsed from the job.ini file as well as a subdictionary ‘inputs’ containing absolute paths to all of the files referenced in the job.ini, keyed by the parameter name.

openquake.commonlib.readinput.get_params(job_inis, **kw)[source]

Parse one or more INI-style config files.

Parameters:
  • job_inis – List of configuration files (or list containing a single zip archive)
  • kw – Optionally override some parameters
Returns:

A dictionary of parameters

openquake.commonlib.readinput.get_pmap_from_csv(oqparam, fnames)[source]
Parameters:
Returns:

the site mesh and the hazard curves read by the .csv files

openquake.commonlib.readinput.get_rupture(oqparam)[source]

Read the rupture_model file and by filter the site collection

Parameters:oqparam – an openquake.commonlib.oqvalidation.OqParam instance
Returns:an hazardlib rupture
openquake.commonlib.readinput.get_site_collection(oqparam)[source]

Returns a SiteCollection instance by looking at the points and the site model defined by the configuration parameters.

Parameters:oqparam – an openquake.commonlib.oqvalidation.OqParam instance
openquake.commonlib.readinput.get_site_model(oqparam)[source]

Convert the NRML file into an array of site parameters.

Parameters:oqparam – an openquake.commonlib.oqvalidation.OqParam instance
Returns:an array with fields lon, lat, vs30, …
openquake.commonlib.readinput.get_sitecol_assetcol(oqparam, haz_sitecol=None, cost_types=())[source]
Parameters:
  • oqparam – calculation parameters
  • haz_sitecol – the hazard site collection
  • cost_types – the expected cost types
Returns:

(site collection, asset collection, discarded)

openquake.commonlib.readinput.get_source_model_lt(oqparam)[source]
Parameters:oqparam – an openquake.commonlib.oqvalidation.OqParam instance
Returns:a openquake.commonlib.logictree.SourceModelLogicTree instance
openquake.commonlib.readinput.levels_from(header)[source]
openquake.commonlib.readinput.normalize(key, fnames, base_path)[source]
openquake.commonlib.readinput.reduce_sm(paths, source_ids)[source]
openquake.commonlib.readinput.reduce_source_model(smlt_file, source_ids, remove=True)[source]

Extract sources from the composite source model.

Parameters:
  • smlt_file – path to a source model logic tree file
  • source_ids – dictionary source_id -> records (src_id, code)
  • remove – if True, remove sm.xml files containing no sources
Returns:

the number of sources satisfying the filter vs the total

openquake.commonlib.readinput.unzip_rename(zpath, name)[source]
Parameters:
  • zpath – full path to a .zip archive
  • name – exposure.xml or ssmLT.xml
Returns:

path to an .xml file with the same name of the archive

source module

util module

openquake.commonlib.util.closest_to_ref(arrays, ref, cutoff=1e-12)[source]
Parameters:
  • arrays – a sequence of arrays
  • ref – the reference array
Returns:

a list of indices ordered by closeness

openquake.commonlib.util.compose_arrays(a1, a2, firstfield='etag')[source]

Compose composite arrays by generating an extended datatype containing all the fields. The two arrays must have the same length.

openquake.commonlib.util.get_assets(dstore)[source]
Parameters:dstore – a datastore with keys ‘assetcol’
Returns:an array of records (id, tag1, …, tagN, lon, lat)
openquake.commonlib.util.log(array, cutoff)[source]

Compute the logarithm of an array with a cutoff on the small values

openquake.commonlib.util.max_rel_diff(curve_ref, curve, min_value=0.01)[source]

Compute the maximum relative difference between two curves. Only values greather or equal than the min_value are considered.

>>> curve_ref = [0.01, 0.02, 0.03, 0.05, 1.0]
>>> curve = [0.011, 0.021, 0.031, 0.051, 1.0]
>>> round(max_rel_diff(curve_ref, curve), 2)
0.1
openquake.commonlib.util.max_rel_diff_index(curve_ref, curve, min_value=0.01)[source]

Compute the maximum relative difference between two sets of curves. Only values greather or equal than the min_value are considered. Return both the maximum difference and its location (array index).

>>> curve_refs = [[0.01, 0.02, 0.03, 0.05], [0.01, 0.02, 0.04, 0.06]]
>>> curves = [[0.011, 0.021, 0.031, 0.051], [0.012, 0.022, 0.032, 0.051]]
>>> max_rel_diff_index(curve_refs, curves)
(0.2, 1)
openquake.commonlib.util.read(calc_id, username=None)[source]
Parameters:
  • calc_id – a calculation ID
  • username – if given, restrict the search to the user’s calculations
Returns:

the associated DataStore instance

openquake.commonlib.util.rmsep(array_ref, array, min_value=0)[source]

Root Mean Square Error Percentage for two arrays.

Parameters:
  • array_ref – reference array
  • array – another array
  • min_value – compare only the elements larger than min_value
Returns:

the relative distance between the arrays

>>> curve_ref = numpy.array([[0.01, 0.02, 0.03, 0.05],
... [0.01, 0.02, 0.04, 0.06]])
>>> curve = numpy.array([[0.011, 0.021, 0.031, 0.051],
... [0.012, 0.022, 0.032, 0.051]])
>>> str(round(rmsep(curve_ref, curve, .01), 5))
'0.11292'
openquake.commonlib.util.shared_dir_on()[source]
Returns:True if a shared_dir has been set in openquake.cfg, else False

writers module

class openquake.commonlib.writers.CsvWriter(sep=', ', fmt='%12.8E')[source]

Bases: object

Class used in the exporters to save a bunch of CSV files

getsaved()[source]

Returns the list of files saved by this CsvWriter

save(data, fname, header=None, comment=None, renamedict=None)[source]

Save data on fname.

Parameters:
  • data – numpy array or list of lists
  • fname – path name
  • header – header to use
  • comment – optional dictionary to be converted in a comment
  • renamedict – a dictionary for renaming the columns
save_block(data, dest)[source]

Save data on dest, which is file open in ‘a’ mode

openquake.commonlib.writers.build_header(dtype)[source]

Convert a numpy nested dtype into a list of strings suitable as header of csv file.

>>> imt_dt = numpy.dtype([('PGA', numpy.float32, 3),
...                       ('PGV', numpy.float32, 4)])
>>> build_header(imt_dt)
['PGA:3', 'PGV:4']
>>> gmf_dt = numpy.dtype([('A', imt_dt), ('B', imt_dt),
...                       ('idx', numpy.uint32)])
>>> build_header(gmf_dt)
['A~PGA:3', 'A~PGV:4', 'B~PGA:3', 'B~PGV:4', 'idx']
openquake.commonlib.writers.castable_to_int(s)[source]

Return True if the string s can be interpreted as an integer

openquake.commonlib.writers.extract_from(data, fields)[source]

Extract data from numpy arrays with nested records.

>>> imt_dt = numpy.dtype([('PGA', float, 3), ('PGV', float, 4)])
>>> a = numpy.array([([1, 2, 3], [4, 5, 6, 7])], imt_dt)
>>> extract_from(a, ['PGA'])
array([[1., 2., 3.]])
>>> gmf_dt = numpy.dtype([('A', imt_dt), ('B', imt_dt),
...                       ('idx', numpy.uint32)])
>>> b = numpy.array([(([1, 2, 3], [4, 5, 6, 7]),
...                  ([1, 2, 4], [3, 5, 6, 7]), 8)], gmf_dt)
>>> extract_from(b, ['idx'])
array([8], dtype=uint32)
>>> extract_from(b, ['B', 'PGV'])
array([[3., 5., 6., 7.]])
openquake.commonlib.writers.parse_header(header)[source]

Convert a list of the form [‘fieldname:fieldtype:fieldsize’,…] into a numpy composite dtype. The parser understands headers generated by openquake.commonlib.writers.build_header(). Here is an example:

>>> parse_header(['PGA:float32', 'PGV', 'avg:float32:2'])
(['PGA', 'PGV', 'avg'], dtype([('PGA', '<f4'), ('PGV', '<f4'), ('avg', '<f4', (2,))]))
Params header:a list of type descriptions
Returns:column names and the corresponding composite dtype
openquake.commonlib.writers.write_csv(dest, data, sep=', ', fmt='%.6E', header=None, comment=None, renamedict=None)[source]
Parameters:
  • dest – None, file, filename or io.BytesIO instance
  • data – array to save
  • sep – separator to use (default comma)
  • fmt – formatting string (default ‘%12.8E’)
  • header – optional list with the names of the columns to display
  • comment – optional comment dictionary