Database Models

Model representations of the OpenQuake DB tables.

class openquake.engine.db.models.AggregateLoss(id, output, insured, mean, std_dev, loss_type)[source]

Bases: django.db.models.base.Model

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception AggregateLoss.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

AggregateLoss.assertAlmostEqual(data)[source]
AggregateLoss.data_hash

A db-sequence independent tuple that identifies this output

AggregateLoss.get_loss_type_display(*moreargs, **morekwargs)
AggregateLoss.objects = <django.db.models.manager.Manager object>
AggregateLoss.output
AggregateLoss.output_hash
Returns:a (db-sequence independent) tuple that identifies this output among which the ones created in the same calculation
AggregateLoss.to_csv_str()[source]

Convert AggregateLoss into a CSV string

class openquake.engine.db.models.AggregateLossCurveData(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Holds the probabilities of exceedance for the whole exposure model

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception AggregateLossCurveData.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

AggregateLossCurveData.assertAlmostEqual(data)[source]
AggregateLossCurveData.data_hash

A db-sequence independent tuple that identifies this output

AggregateLossCurveData.loss_curve
AggregateLossCurveData.objects = <django.db.models.manager.Manager object>
AggregateLossCurveData.to_csv_str(label)[source]

Convert AggregateLossCurveData into a CSV string.

Parameters:label (str) – an identifier for the curve (for instance the cost type)
class openquake.engine.db.models.AssetManager[source]

Bases: django.contrib.gis.db.models.manager.GeoManager

Asset manager

get_asset_chunk(exposure_model, time_event, assocs)[source]
Parameters:assocs – a list of openquake.engine.db.models.AssetSite objects
Returns:a list of instances of openquake.engine.db.models.ExposureData (ordered by location) associated with the openquake.engine.db.models.ExposureModel associated with rc.

It also add an annotation to each ExposureData object to provide the occupants value for the risk calculation given in input and the cost for each cost type considered in rc

taxonomies_contained_in(exposure_model_id, region_constraint)[source]
Parameters:
  • exposure_model_id – ID of an ExposureModel
  • region_constraint – A string describing a region in WKT format
Returns:

A dictionary which map each taxonomy associated with exposure_model and contained in region_constraint with the number of assets.

class openquake.engine.db.models.AssetSite(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Contains the association exposure_data_id -> site_id, as generated by the current risk job.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception AssetSite.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

AssetSite.asset
AssetSite.epsilon_set
AssetSite.job
AssetSite.objects = <django.db.models.manager.Manager object>
AssetSite.site
class openquake.engine.db.models.AssocLtRlzTrtModel(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Associations between logic tree realizations and TrtModels. Fixed a realization and a TRT, the gsim is unique.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception AssocLtRlzTrtModel.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

AssocLtRlzTrtModel.objects = <django.db.models.manager.Manager object>
AssocLtRlzTrtModel.rlz
AssocLtRlzTrtModel.trt_model
class openquake.engine.db.models.BCRDistribution(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Holds metadata for the benefit-cost ratio distribution

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception BCRDistribution.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

BCRDistribution.bcrdistributiondata_set
BCRDistribution.get_loss_type_display(*moreargs, **morekwargs)
BCRDistribution.hazard_output
BCRDistribution.objects = <django.db.models.manager.Manager object>
BCRDistribution.output
BCRDistribution.output_hash
Returns:a (db-sequence independent) tuple that identifies this output among which the ones created in the same calculation
class openquake.engine.db.models.BCRDistributionData(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Holds the actual data for the benefit-cost ratio distribution

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception BCRDistributionData.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

BCRDistributionData.assertAlmostEqual(data)[source]
BCRDistributionData.bcr_distribution
BCRDistributionData.data_hash

A db-sequence independent tuple that identifies this output

BCRDistributionData.location
BCRDistributionData.objects = <django.db.models.manager.Manager object>
class openquake.engine.db.models.Cost(id, exposure_data, cost_type, converted_cost, converted_retrofitted_cost, deductible_absolute, insurance_limit_absolute)[source]

Bases: django.db.models.base.Model

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception Cost.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

Cost.cost_type
Cost.exposure_data
Cost.objects = <django.db.models.manager.Manager object>
class openquake.engine.db.models.CostType(id, exposure_model, name, conversion, unit, retrofitted_conversion, retrofitted_unit)[source]

Bases: django.db.models.base.Model

CONVERSION_CHOICES = ((u'aggregated', u'Aggregated economic value'), (u'per_area', u'Per area economic value'), (u'per_asset', u'Per asset economic value'))
COST_TYPE_CHOICES = (('structuralCost', 'structuralCost'), ('retrofittedStructuralCost', 'retrofittedStructuralCost'), ('nonStructuralCost', 'nonStructuralCost'), ('contentsCost', 'contentsCost'), ('businessInterruptionCost', 'businessInterruptionCost'))
exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception CostType.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

CostType.cost_set
CostType.exposure_model
CostType.get_conversion_display(*moreargs, **morekwargs)
CostType.get_name_display(*moreargs, **morekwargs)
CostType.get_retrofitted_conversion_display(*moreargs, **morekwargs)
CostType.objects = <django.db.models.manager.Manager object>
openquake.engine.db.models.DEFAULT_SRID = 4326

System Reference ID used for geometry objects

class openquake.engine.db.models.Damage(*args, **kwargs)[source]

Bases: django.db.models.base.Model

The damage curve corresponding to a given hazard output.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception Damage.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

Damage.damagedata_set
Damage.get_statistics_display(*moreargs, **morekwargs)
Damage.hazard_output
Damage.loss_type
Damage.objects = <django.db.models.manager.Manager object>
Damage.output
Damage.risk_calculation
class openquake.engine.db.models.DamageData(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Holds the actual damage fractions for an entire calculation. There should be N records per realization per damage state, where N is the number of assets.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception DamageData.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

DamageData.damage
DamageData.dmg_state
DamageData.exposure_data
DamageData.objects = <django.db.models.manager.Manager object>
class openquake.engine.db.models.DisaggResult(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Storage for disaggregation historgrams. Each histogram is stored in matrix as a 6-dimensional numpy array (pickled). The dimensions of the matrix are as follows, in order:

  • magnitude
  • distance
  • longitude
  • latitude
  • epsilon
  • tectonic region type

Bin edges are defined for all of these dimensions (except tectonic region type) as:

  • mag_bin_edges
  • dist_bin_edges
  • lat_bin_edges
  • lon_bin_edges
  • eps_bin_edges

The size of the tectonic region type (TRT) dimension is simply determined by the length of trts.

Additional metadata for the disaggregation histogram is stored, including location (POINT geometry), disaggregation PoE (Probability of Exceedance) and the corresponding IML (Intensity Measure Level) extracted from the hazard curve, logic tree path information, and investigation time.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception DisaggResult.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

DisaggResult.get_imt_display(*moreargs, **morekwargs)
DisaggResult.location
DisaggResult.lt_realization
DisaggResult.matrix

A placeholder class that provides a way to set the attribute on the model.

DisaggResult.objects = <django.db.models.manager.Manager object>
DisaggResult.output
class openquake.engine.db.models.DmgDistPerAsset(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Holds the actual data for damage distributions per asset.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception DmgDistPerAsset.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

DmgDistPerAsset.assertAlmostEqual(data)[source]
DmgDistPerAsset.data_hash

A db-sequence independent tuple that identifies this output

DmgDistPerAsset.dmg_state
DmgDistPerAsset.exposure_data
DmgDistPerAsset.objects = <django.db.models.manager.Manager object>
DmgDistPerAsset.output
DmgDistPerAsset.output_hash
Returns:a (db-sequence independent) tuple that identifies this output among which the ones created in the same calculation
class openquake.engine.db.models.DmgDistPerTaxonomy(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Holds the actual data for damage distributions per taxonomy.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception DmgDistPerTaxonomy.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

DmgDistPerTaxonomy.assertAlmostEqual(data)[source]
DmgDistPerTaxonomy.data_hash

A db-sequence independent tuple that identifies this output

DmgDistPerTaxonomy.dmg_state
DmgDistPerTaxonomy.objects = <django.db.models.manager.Manager object>
DmgDistPerTaxonomy.output
DmgDistPerTaxonomy.output_hash
Returns:a (db-sequence independent) tuple that identifies this output among which the ones created in the same calculation
class openquake.engine.db.models.DmgDistTotal(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Holds the actual ‘total damage distribution’ values for for an entire calculation. There should be one record per calculation per damage state.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception DmgDistTotal.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

DmgDistTotal.assertAlmostEqual(data)[source]
DmgDistTotal.data_hash

A db-sequence independent tuple that identifies this output

DmgDistTotal.dmg_state
DmgDistTotal.objects = <django.db.models.manager.Manager object>
DmgDistTotal.output
DmgDistTotal.output_hash
Returns:a (db-sequence independent) tuple that identifies this output among which the ones created in the same calculation
class openquake.engine.db.models.DmgState(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Holds the damage_states associated to a given output

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception DmgState.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

DmgState.damagedata_set
DmgState.dmgdistperasset_set
DmgState.dmgdistpertaxonomy_set
DmgState.dmgdisttotal_set
DmgState.objects = <django.db.models.manager.Manager object>
DmgState.risk_calculation
class openquake.engine.db.models.Epsilon(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Contains the association (asset_site, ses_collection) -> epsilons, as generated by the current risk job for event based and scenario computations.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception Epsilon.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

Epsilon.asset_site
Epsilon.objects = <django.db.models.manager.Manager object>
classmethod Epsilon.saveall(asset_sites, epsilon_matrix)[source]

Insert the epsilons for each asset_sites association.

Parameters:
  • asset_sites – a list of openquake.engine.db.models.AssetSite instances
  • epsilon_matrix – a numpy matrix with NxE elements, where N is the number of assets and E the number of ruptures
class openquake.engine.db.models.EventLoss(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Holds the aggregate loss we have for each rupture

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception EventLoss.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

EventLoss.eventlossasset_set
EventLoss.eventlossdata_set
EventLoss.get_loss_type_display(*moreargs, **morekwargs)
EventLoss.hazard_output
EventLoss.objects = <django.db.models.manager.Manager object>
EventLoss.output

Foreign key to an openquake.engine.db.models.Output object with output_type == event_loss

EventLoss.output_hash
Returns:a (db-sequence independent) tuple that identifies this output among which the ones created in the same calculation
EventLoss.to_csv_str()[source]

Convert EventLoss into a CSV with fields rupture_tag, aggregate_loss

class openquake.engine.db.models.EventLossAsset(id, event_loss, rupture, asset, loss)[source]

Bases: django.db.models.base.Model

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception EventLossAsset.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

EventLossAsset.assertAlmostEqual(data)[source]
EventLossAsset.asset
EventLossAsset.data_hash

A db-sequence independent tuple that identifies this output

EventLossAsset.event_loss
EventLossAsset.objects = <django.db.models.manager.Manager object>
EventLossAsset.rupture
EventLossAsset.to_csv_str()[source]

Convert EventLossAsset into a CSV string

class openquake.engine.db.models.EventLossData(id, event_loss, rupture, aggregate_loss)[source]

Bases: django.db.models.base.Model

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception EventLossData.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

EventLossData.assertAlmostEqual(data)[source]
EventLossData.data_hash

A db-sequence independent tuple that identifies this output

EventLossData.event_loss
EventLossData.objects = <django.db.models.manager.Manager object>
EventLossData.rupture
EventLossData.to_csv_str()[source]

Convert EventLossData into a CSV string

class openquake.engine.db.models.ExposureData(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Per-asset risk exposure data

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception ExposureData.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

ExposureData.NO_RETROFITTING_COST = 'no retrofitting cost'
ExposureData.assetsite_set
ExposureData.cost_set
ExposureData.damagedata_set
ExposureData.deductible(loss_type)[source]

Extract the deductible limit of the asset for the given loss_type. See the method value for details.

ExposureData.dmgdistperasset_set
ExposureData.eventlossasset_set
ExposureData.exposure_model
ExposureData.insurance_limit(loss_type)[source]

Extract the insurance limit of the asset for the given loss_type. See the method value for details.

ExposureData.number

An alias for number_of_units

ExposureData.objects = <openquake.engine.db.models.AssetManager object>
ExposureData.occupancy_set
static ExposureData.per_asset_value(cost, cost_type, area, area_type, number_of_units, category)[source]

Return per-asset value for the given exposure data set.

Calculate per asset value by considering the given exposure data as follows:

case 1: cost type: aggregated:
cost = economic value
case 2: cost type: per asset:
cost * number (of assets) = economic value
case 3: cost type: per area and area type: aggregated:
cost * area = economic value
case 4: cost type: per area and area type: per asset:
cost * area * number = economic value

The same “formula” applies to contenst/retrofitting cost analogously.

Returns:The per-asset value as a float.
Raises:ValueError in case of a malformed (risk exposure data) input.
ExposureData.retrofitted(loss_type)[source]

Extract the retrofitted cost of the asset for the given loss_type. See the method value for details.

ExposureData.site
ExposureData.value(loss_type)[source]

Extract the value of the asset for the given loss_type. Although the Django Model definition does not have a value for each loss type, we rely on the fact that an annotation on the asset named loss_type is present.

class openquake.engine.db.models.ExposureModel(*args, **kwargs)[source]

Bases: django.db.models.base.Model

A risk exposure model

AREA_CHOICES = ((u'aggregated', u'Aggregated area value'), (u'per_asset', u'Per asset area value'))
exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception ExposureModel.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

ExposureModel.costtype_set
ExposureModel.exposuredata_set
ExposureModel.get_area_type_display(*moreargs, **morekwargs)
ExposureModel.has_insurance_bounds()[source]
ExposureModel.has_retrofitted_costs()[source]
ExposureModel.has_time_event(time_event)[source]
ExposureModel.job
ExposureModel.objects = <django.db.models.manager.Manager object>
ExposureModel.supports_loss_type(loss_type)[source]
Returns:True if the exposure contains the asset data needed for computing losses for loss_type
ExposureModel.taxonomies_in(region_constraint)[source]
Parameters:region_constraint (str) – polygon in wkt format the assets must be contained into
Returns:A dictionary mapping each taxonomy with the number of assets contained in region_constraint
ExposureModel.unit(loss_type)[source]
class openquake.engine.db.models.Gmf(*args, **kwargs)[source]

Bases: django.db.models.base.Model

A collection of ground motion field (GMF) sets for a given logic tree realization.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception Gmf.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

Gmf.check_export_size()[source]

Raise an error if the number of rows to export is bigger that the configuration parameter max_rows_export_gmfs.

Gmf.gmfdata_set
Gmf.gmfsets(ses_coll, gmf_dict)[source]
Parameters:
  • ses_coll – a SESCollection instance
  • gmf_dict
    a dictionary (imt, sa_period, sa_damping, rupture_tag)
    -> [(x, y, gmv), ...]
Returns:

a list of openquake.engine.db.models.GmfSet instances

Gmf.lt_realization
Gmf.objects = <django.db.models.manager.Manager object>
Gmf.output
class openquake.engine.db.models.GmfData(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Ground Motion Field: A collection of ground motion values and their respective geographical locations.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception GmfData.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

GmfData.get_imt_display(*moreargs, **morekwargs)
GmfData.gmf
GmfData.objects = <django.contrib.gis.db.models.manager.GeoManager object>
GmfData.site
class openquake.engine.db.models.GmfSet(ses, gmfset)[source]

Bases: object

Small wrapper around the list of Gmf objects associated to the given SES.

class openquake.engine.db.models.HazardCurve(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Hazard Curve header information

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception HazardCurve.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

HazardCurve.STAT_CHOICES = ((u'mean', u'Mean'), (u'quantile', u'Quantile'))
HazardCurve.get_imt_display(*moreargs, **morekwargs)
HazardCurve.get_statistics_display(*moreargs, **morekwargs)
HazardCurve.hazardcurvedata_set
HazardCurve.imt_long
Returns:a string representing the imt associated with the

curve (if any) in the long form, e.g. SA(0.01)

HazardCurve.lt_realization
HazardCurve.objects = <django.db.models.manager.Manager object>
HazardCurve.output
class openquake.engine.db.models.HazardCurveData(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Hazard Curve data

Contains an list of PoE (Probability of Exceedance) values and the geographical point associated with the curve

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception HazardCurveData.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

HazardCurveData.hazard_curve
HazardCurveData.location
HazardCurveData.objects = <openquake.engine.db.models.HazardCurveDataManager object>
class openquake.engine.db.models.HazardCurveDataManager[source]

Bases: django.contrib.gis.db.models.manager.GeoManager

Manager class to filter and create HazardCurveData objects

all_curves_for_imt(job, imt, sa_period, sa_damping)[source]

Helper function for creating a django.db.models.query.QuerySet for selecting all curves from all realizations for a given job_id and imt.

Parameters:
  • job – An openquake.engine.db.models.OqJob instance.
  • imt (str) – Intensity measure type.
  • sa_period – Spectral Acceleration period value. Only relevant if the imt is “SA”.
  • sa_damping – Spectrail Acceleration damping value. Only relevant if the imt is “SA”.
all_curves_simple(filter_args=None, order_by='id')[source]

Get all HazardCurveData records matching filter_args and return the results in a simple, lean format: a sequence of (x, y, poes) triples, where x and y are longitude and latitude of the location.

For querying large sets of hazard curve data, this is a rather lean and efficient method for getting the results.

Parameters:
  • filter_args (dict) – Optional. Dictionary of filter arguments to apply to the query.
  • order_by (str) – Defaults to the primary key (‘id’). Field by which to order results. Currently, only one ORDER BY field is supported.
class openquake.engine.db.models.HazardMap(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Hazard Map header (information which pertains to entire map)

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception HazardMap.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

HazardMap.get_imt_display(*moreargs, **morekwargs)
HazardMap.get_statistics_display(*moreargs, **morekwargs)
HazardMap.lt_realization
HazardMap.objects = <django.db.models.manager.Manager object>
HazardMap.output
class openquake.engine.db.models.HazardSite(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Contains pre-computed site parameter matrices. lons and lats represent the calculation sites of interest. The associated site parameters are from the closest point in a site model in relation to each calculation point of interest.

Used only if a calculation defines a site model (otherwise, reference parameters are use for all points of interest).

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception HazardSite.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

HazardSite.assetsite_set
HazardSite.gmfdata_set
HazardSite.hazard_calculation
HazardSite.objects = <django.db.models.manager.Manager object>
class openquake.engine.db.models.Imt(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Table with the Intensity Measure Types

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception Imt.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

classmethod Imt.get(imt_str)[source]
Parameters:imt_str – a string specifying the IMT
Returns:a openquake.engine.db.models.Imt instance
Imt.get_im_type_display(*moreargs, **morekwargs)
Imt.imttaxonomy_set
Imt.objects = <django.db.models.manager.Manager object>
classmethod Imt.save_new(hazardlib_imts)[source]

Save the intensity measure types not already stored in the database.

Parameters:hazardlib_imts – a list of hazardlib IMT tuples
Imt.stored_imts = None
class openquake.engine.db.models.ImtTaxonomy(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Table with the associations IMT, taxonomy, as extracted from the risk models.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception ImtTaxonomy.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

ImtTaxonomy.imt
ImtTaxonomy.job
ImtTaxonomy.objects = <django.db.models.manager.Manager object>
class openquake.engine.db.models.JobInfo(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Store information about a job.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception JobInfo.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

JobInfo.objects = <django.db.models.manager.Manager object>
JobInfo.oq_job
JobInfo.parent_job
class openquake.engine.db.models.JobParam(*args, **kwargs)[source]

Bases: django.db.models.base.Model

The parameters of a job

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception JobParam.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

JobParam.job
JobParam.objects = <django.db.models.manager.Manager object>
JobParam.value

A placeholder class that provides a way to set the attribute on the model.

class openquake.engine.db.models.JobStats(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Capture various statistics about a job.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception JobStats.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

JobStats.get_next_by_start_time(*moreargs, **morekwargs)
JobStats.get_next_by_stop_time(*moreargs, **morekwargs)
JobStats.get_previous_by_start_time(*moreargs, **morekwargs)
JobStats.get_previous_by_stop_time(*moreargs, **morekwargs)
JobStats.objects = <django.db.models.manager.Manager object>
JobStats.oq_job
openquake.engine.db.models.LOSS_TYPES = ['structural', 'nonstructural', 'fatalities', 'contents']

Kind of supported type of loss outputs

class openquake.engine.db.models.Log(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Log table for calculations

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception Log.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

Log.get_level_display(*moreargs, **morekwargs)
Log.get_next_by_timestamp(*moreargs, **morekwargs)
Log.get_previous_by_timestamp(*moreargs, **morekwargs)
Log.job
Log.objects = <django.db.models.manager.Manager object>
class openquake.engine.db.models.LossCurve(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Holds the parameters common to a set of loss curves

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception LossCurve.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

LossCurve.aggregatelosscurvedata
LossCurve.get_loss_type_display(*moreargs, **morekwargs)
LossCurve.get_statistics_display(*moreargs, **morekwargs)
LossCurve.hazard_output
LossCurve.losscurvedata_set
LossCurve.objects = <django.db.models.manager.Manager object>
LossCurve.output
LossCurve.output_hash
Returns:a (db-sequence independent) tuple that identifies this output among which the ones created in the same calculation
LossCurve.to_csv_str()[source]

Convert LossCurve into a CSV string

class openquake.engine.db.models.LossCurveData(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Holds the probabilities of exceedance for a given loss curve

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception LossCurveData.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

LossCurveData.assertAlmostEqual(data)[source]
LossCurveData.average_loss
LossCurveData.data_hash

A db-sequence independent tuple that identifies this output

LossCurveData.location
LossCurveData.loss_curve
LossCurveData.losses
LossCurveData.objects = <django.db.models.manager.Manager object>
LossCurveData.stddev_loss
LossCurveData.to_csv_str(label)[source]

Convert LossCurveData into a CSV string.

Parameters:label (str) – an identifier for the curve (for instance the asset_ref)
class openquake.engine.db.models.LossFraction(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Holds metadata for loss fraction data

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception LossFraction.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

LossFraction.display_value(value, oq)[source]

Converts value in a form that is best suited to be displayed.

Parameters:oq – An OqParam object used to get the bin width
Returns:value if the attribute variable is equal to taxonomy. if the attribute variable is equal to magnitude-distance, then it extracts two integers (comma separated) from value and convert them into ranges encoded back as csv.
LossFraction.get_loss_type_display(*moreargs, **morekwargs)
LossFraction.get_statistics_display(*moreargs, **morekwargs)
LossFraction.get_variable_display(*moreargs, **morekwargs)
LossFraction.hazard_output
LossFraction.items()[source]

Yields tuples with two elements. The first one is a location (described by a lon/lat tuple), the second one is a dictionary modeling the disaggregation of the losses on such location. In this dictionary, each key is a value of variable, and each corresponding value is a tuple holding the absolute losses and the fraction of losses occurring in that location.

LossFraction.lossfractiondata_set
LossFraction.objects = <django.db.models.manager.Manager object>
LossFraction.output
LossFraction.output_hash
Returns:a (db-sequence independent) tuple that identifies this output among which the ones created in the same calculation
LossFraction.to_array()[source]
Returns:the loss fractions as numpy array
NOTE:(not memory efficient)
LossFraction.total_fractions()[source]
Returns:a dictionary mapping values of variable (e.g. a

taxonomy) to tuples yielding the associated absolute losses (e.g. the absolute losses for assets of a taxonomy) and the percentage (expressed in decimal format) over the total losses

class openquake.engine.db.models.LossFractionData(id, loss_fraction, location, value, absolute_loss)[source]

Bases: django.db.models.base.Model

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception LossFractionData.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

LossFractionData.assertAlmostEqual(data)[source]
LossFractionData.data_hash

A db-sequence independent tuple that identifies this output

LossFractionData.location
LossFractionData.loss_fraction
LossFractionData.objects = <django.db.models.manager.Manager object>
LossFractionData.to_csv_str()[source]

Convert LossFractionData into a CSV string

class openquake.engine.db.models.LossMap(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Holds metadata for loss maps

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception LossMap.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

LossMap.get_loss_type_display(*moreargs, **morekwargs)
LossMap.get_statistics_display(*moreargs, **morekwargs)
LossMap.hazard_output
LossMap.lossmapdata_set
LossMap.objects = <django.db.models.manager.Manager object>
LossMap.output
LossMap.output_hash
Returns:a (db-sequence independent) tuple that identifies this output among which the ones created in the same calculation
class openquake.engine.db.models.LossMapData(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Holds an asset, its position and a value plus (for non-scenario maps) the standard deviation for its loss

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception LossMapData.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

LossMapData.assertAlmostEqual(data)[source]
LossMapData.data_hash

A db-sequence independent tuple that identifies this output

LossMapData.location
LossMapData.loss_map
LossMapData.objects = <django.db.models.manager.Manager object>
class openquake.engine.db.models.LtRealization(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Identify a logic tree branch.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception LtRealization.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

LtRealization.assocltrlztrtmodel_set
LtRealization.disaggresult_set
LtRealization.get_gsim_instances()[source]

Return the GSIM instances associated to the current realization by looking at the association table.

LtRealization.gmf_set
LtRealization.hazardcurve_set
LtRealization.hazardmap_set
LtRealization.lt_model
LtRealization.objects = <django.db.models.manager.Manager object>
LtRealization.sm_lt_path

The source model logic tree path extracted from the underlying source model

LtRealization.uhs_set
class openquake.engine.db.models.LtSourceModel(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Identify a logic tree source model.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception LtSourceModel.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

LtSourceModel.get_num_sources()[source]

Return the number of sources in the model.

LtSourceModel.get_tectonic_region_types()[source]

Return the tectonic region types in the model, ordered by number of sources.

LtSourceModel.hazard_calculation
LtSourceModel.ltrealization_set
LtSourceModel.make_gsim_lt(trts=())[source]

Helper to instantiate a GsimLogicTree object from the logic tree file.

LtSourceModel.objects = <django.db.models.manager.Manager object>
LtSourceModel.trtmodel_set
openquake.engine.db.models.MAX_SINT_32 = 2147483647

Maximum value for a seed number

openquake.engine.db.models.MIN_SINT_32 = -2147483648

Minimum value for a seed number

exception openquake.engine.db.models.MissingParameter[source]

Bases: exceptions.KeyError

Raised by OqJob.get_param when a parameter is missing in the database

class openquake.engine.db.models.Occupancy(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Asset occupancy data

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception Occupancy.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

Occupancy.exposure_data
Occupancy.objects = <django.db.models.manager.Manager object>
class openquake.engine.db.models.OqJob(*args, **kwargs)[source]

Bases: django.db.models.base.Model

An OpenQuake engine run started by the user

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

OqJob.LOG_LEVEL_CHOICES = ((u'debug', u'Debug'), (u'info', u'Info'), (u'progress', u'Progress'), (u'warn', u'Warn'), (u'error', u'Error'), (u'critical', u'Critical'))
exception OqJob.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

OqJob.STATUS_CHOICES = ((u'created', u'Created'), (u'pre_executing', u'Pre-Executing'), (u'executing', u'Executing'), (u'post_executing', u'Post-Executing'), (u'post_processing', u'Post-Processing'), (u'export', u'Exporting results'), (u'clean_up', u'Cleaning up'), (u'complete', u'Complete'))
OqJob.assetsite_set
OqJob.damage_set
OqJob.dmgstate_set
OqJob.exposure_model

Return the right exposure model by following rules in order:

  1. if the preloaded_exposure_model_id is set in job_risk.ini, use it
  2. if an exposure_file is defined in job_risk.ini, use it
  3. if an exposure was used in the hazard job, use it
  4. if no exposure is found, return None
OqJob.exposuremodel
OqJob.get_log_level_display(*moreargs, **morekwargs)
OqJob.get_next_by_last_update(*moreargs, **morekwargs)
OqJob.get_oqparam()[source]

Return an OqParam object as read from the database

OqJob.get_or_create_output(display_name, output_type)[source]
Parameters:
  • disp_name – display name of the output
  • output_type – the output type
Returns:

an Output instance

OqJob.get_param(name, missing=<object object>)[source]

job.get_param(name) returns the value of the requested parameter or raise a MissingParameter exception if the parameter does not exist in the database.

job.get_param(name, missing) returns the value of the requested parameter or the missing value if the parameter does not exist in the database.

Parameters:
  • name – the name of the parameter
  • missing – value returned if the parameter is missing

NB: since job_param.value is NOT NULL, .get_param(name) can return None only if the parameter is missing.

OqJob.get_previous_by_last_update(*moreargs, **morekwargs)
OqJob.get_status_display(*moreargs, **morekwargs)
OqJob.hazard_calculation
OqJob.hazardsite_set
OqJob.imttaxonomy_set
OqJob.job_type

‘hazard’ or ‘risk’

OqJob.jobinfo
OqJob.jobinfo_set
OqJob.jobparam_set
OqJob.jobstats
OqJob.log_set
OqJob.ltsourcemodel_set
OqJob.objects = <django.db.models.manager.Manager object>
OqJob.oqjob_set
OqJob.output_set
OqJob.performance_set
OqJob.risk_calculation()[source]
OqJob.save_hazard_sites()[source]

Populate the table HazardSite by inferring the points from the sites, region, or exposure.

OqJob.save_params(params)[source]

Save on the database table job_params the given parameters.

Parameters:
  • job – an OqJob instance
  • params – a dictionary {name: string} of parameters
class openquake.engine.db.models.Output(*args, **kwargs)[source]

Bases: django.db.models.base.Model

A single artifact which is a result of an OpenQuake job. The data may reside in a file or in the database.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

Output.HAZARD_OUTPUT_TYPE_CHOICES = ((u'disagg_matrix', u'Disaggregation Matrix'), (u'gmf', u'Ground Motion Field'), (u'gmf_scenario', u'Ground Motion Field'), (u'hazard_curve', u'Hazard Curve'), (u'hazard_curve_multi', u'Hazard Curve (multiple imts)'), (u'hazard_map', u'Hazard Map'), (u'ses', u'Stochastic Event Set'), (u'uh_spectra', u'Uniform Hazard Spectra'))
Output.HazardMetadata

Metadata of hazard outputs used by risk calculation. See hazard_metadata property for more details

alias of hazard_metadata

Output.LogicTreePath

Hold the full paths in the model trees of ground shaking intensity models and of source models, respectively.

alias of logic_tree_path

exception Output.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

Output.RISK_OUTPUT_TYPE_CHOICES = ((u'agg_loss_curve', u'Aggregate Loss Curve'), (u'aggregate_loss', u'Aggregate Losses'), (u'bcr_distribution', u'Benefit-cost ratio distribution'), (u'collapse_map', u'Collapse Map Distribution'), (u'dmg_dist_per_asset', u'Damage Distribution Per Asset'), (u'dmg_dist_per_taxonomy', u'Damage Distribution Per Taxonomy'), (u'dmg_dist_total', u'Total Damage Distribution'), (u'event_loss', u'Event Loss Table'), (u'event_loss_asset', u'Event Loss Asset'), (u'loss_curve', u'Loss Curve'), (u'event_loss_curve', u'Loss Curve'), (u'loss_fraction', u'Loss fractions'), (u'loss_map', u'Loss Map'), (u'dmg_per_asset', 'Damage Per Asset'))
Output.StatisticalParams

Hold the statistical params (statistics, quantile).

alias of statistical_params

Output.aggregate_loss
Output.bcr_distribution
Output.damage
Output.damages
Output.disagg_matrix
Output.event_loss
Output.get_next_by_last_update(*moreargs, **morekwargs)
Output.get_output_type_display(*moreargs, **morekwargs)
Output.get_previous_by_last_update(*moreargs, **morekwargs)
Output.gmf
Output.hazard_curve
Output.hazard_map
Output.hazard_metadata

Given an Output produced by a risk calculation it returns the corresponding hazard metadata.

Returns:A namedtuple with the following attributes:
* investigation_time: the hazard investigation time (float)
* statistics: the kind of hazard statistics (None, "mean" or
  "quantile")
* quantile: quantile value (when `statistics` is "quantile")
* sm_path: a list representing the source model path
* gsim_path: a list representing the gsim logic tree path
Output.is_hazard_curve()[source]
Output.loss_curve
Output.loss_fraction
Output.loss_map
Output.lt_realization_paths
Returns:an instance of LogicTreePath the output is

associated with. When the output is not associated with any logic tree branch then it returns a LogicTreePath namedtuple with a couple of None.

Output.objects = <openquake.engine.db.models.OutputManager object>
Output.oq_job
Output.output_container
Returns:the output container associated with this output
Output.risk_bcr_distribution
Output.risk_event_loss_tables
Output.risk_loss_curves
Output.risk_loss_fractions
Output.risk_loss_maps
Output.ses
Output.statistical_params
Returns:an instance of StatisticalParams the output is

associated with

Output.uh_spectra
class openquake.engine.db.models.OutputManager[source]

Bases: django.db.models.manager.Manager

Manager class to filter and create Output objects

create_output(job, display_name, output_type)[source]

Create an output for the given job, display_name and output_type (default to hazard_curve)

class openquake.engine.db.models.Performance(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Contains performance information about the operations performed by a task launched by a job.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception Performance.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

Performance.get_next_by_start_time(*moreargs, **morekwargs)
Performance.get_previous_by_start_time(*moreargs, **morekwargs)
Performance.objects = <django.db.models.manager.Manager object>
Performance.oq_job
class openquake.engine.db.models.ProbabilisticRupture(*args, **kwargs)[source]

Bases: django.db.models.base.Model

A rupture as part of a Stochastic Event Set Collection.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception ProbabilisticRupture.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

ProbabilisticRupture.bottom_left_corner
ProbabilisticRupture.bottom_right_corner
classmethod ProbabilisticRupture.create(rupture, ses_collection, site_indices=None)[source]

Create a ProbabilisticRupture row on the database.

Parameters:
  • rupture – a hazardlib rupture
  • ses_collection – a Stochastic Event Set Collection object
  • site_indices – an array of indices for the site_collection
ProbabilisticRupture.depths
ProbabilisticRupture.dip
ProbabilisticRupture.geom

Extract the triple (lons, lats, depths) from the surface geometry (cached).

ProbabilisticRupture.hypocenter

Convert the 3D array into a hazardlib point

ProbabilisticRupture.lats
ProbabilisticRupture.lons
ProbabilisticRupture.mag
ProbabilisticRupture.objects = <django.db.models.manager.Manager object>
ProbabilisticRupture.ses_collection
ProbabilisticRupture.sesrupture_set
ProbabilisticRupture.strike
ProbabilisticRupture.surface

A placeholder class that provides a way to set the attribute on the model.

ProbabilisticRupture.tectonic_region_type

The TRT associated to the underlying trt_model

ProbabilisticRupture.top_left_corner
ProbabilisticRupture.top_right_corner
openquake.engine.db.models.RISK_ATOL = 0.01

absolute tolerance to consider two risk outputs (almost) equal

openquake.engine.db.models.RISK_RTOL = 0.05

relative tolerance to consider two risk outputs (almost) equal

class openquake.engine.db.models.SES(ses_collection, ordinal=1)[source]

Bases: object

Stochastic Event Set: A container for 1 or more ruptures associated with a specific investigation time span.

class openquake.engine.db.models.SESCollection(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Stochastic Event Set Collection: A container for 1 or more Stochastic Event Sets for a given logic tree realization.

See also SES and SESRupture.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception SESCollection.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

classmethod SESCollection.create(output)[source]

Create an LtSourceModel, a TrtModel and a SESCollection associated to it and to the given output.

Parameters:output – an output of type GMF
SESCollection.get_ruptures()[source]

Return the SESRuptures associated to self

SESCollection.objects = <django.db.models.manager.Manager object>
SESCollection.output
SESCollection.probabilisticrupture_set
SESCollection.sm_lt_path

The source model logic tree path corresponding to the collection

SESCollection.trt_model
class openquake.engine.db.models.SESRupture(*args, **kwargs)[source]

Bases: django.db.models.base.Model

A rupture as part of a Stochastic Event Set.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception SESRupture.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

SESRupture.eventlossasset_set
SESRupture.eventlossdata_set
SESRupture.hypocenter

The hypocenter of the underlying rupture

SESRupture.objects = <django.db.models.manager.Manager object>
SESRupture.rupture
SESRupture.surface

The surface of the underlying rupture

openquake.engine.db.models.STAT_CHOICES = ((u'mean', u'Mean'), (u'quantile', u'Quantile'))

Kind of supported curve statistics

class openquake.engine.db.models.SourceInfo(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Source specific infos

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception SourceInfo.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

SourceInfo.objects = <django.db.models.manager.Manager object>
SourceInfo.trt_model
class openquake.engine.db.models.TrtModel(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Source submodel containing sources of the same tectonic region type.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception TrtModel.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

TrtModel.assocltrlztrtmodel_set
TrtModel.get_gsim_instances()[source]

Return the GSIM instances associated to the current TrtModel

TrtModel.get_realizations(gsim_name)[source]

Return the realizations associated to the current TrtModel and the given GSIM.

Parameters:gsim_name (str) – name of a GSIM class
TrtModel.get_rlzs_by_gsim()[source]

Return the realizations associated to the current TrtModel as an ordered dictionary {gsim_name: [rlz, ...]}

TrtModel.lt_model
TrtModel.objects = <django.db.models.manager.Manager object>
TrtModel.samples

How many times the TrtModel was sampled (it may be different from 1 only when sampling is enabled).

TrtModel.sescollection_set
TrtModel.sourceinfo_set
class openquake.engine.db.models.UHS(*args, **kwargs)[source]

Bases: django.db.models.base.Model

UHS/Uniform Hazard Spectra: * “Uniform” meaning “the same PoE” * “Spectrum” because it covers a range/band of periods/frequencies

Records in this table contain metadata for a collection of UHS data.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception UHS.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

UHS.STAT_CHOICES = ((u'mean', u'Mean'), (u'quantile', u'Quantile'))
UHS.get_statistics_display(*moreargs, **morekwargs)
UHS.lt_realization
UHS.objects = <django.db.models.manager.Manager object>
UHS.output
UHS.uhsdata_set
class openquake.engine.db.models.UHSData(*args, **kwargs)[source]

Bases: django.db.models.base.Model

UHS curve for a given location.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception UHSData.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

UHSData.location
UHSData.objects = <django.db.models.manager.Manager object>
UHSData.uhs
openquake.engine.db.models.build_curves(rlz, curves_by_trt_model_gsim)[source]

Build on the fly the hazard curves for the current realization by looking at the associations stored in the database table hzrdr.assoc_lt_rlz_trt_model.

openquake.engine.db.models.extract_from(objlist, attr)[source]

Extract an attribute from a list of Django objects, by scanning them in order until a not None attribute is found. If nothing is found, or if an exception ObjectDoesNotExist is raised, return None.

Parameters:
  • objlist – the list of Django objects
  • attr (str) – the name of the attribute to look for
openquake.engine.db.models.extract_ses_ordinal(tag)[source]

Extract the SES ordinal from a tag. For instance

>>> extract_ses_ordinal('col=01|ses=0002|src=A|rup=001-17')
2
openquake.engine.db.models.get_correl_model(job)[source]

Helper function for constructing the appropriate correlation model.

Returns:A correlation object. See openquake.hazardlib.correlation for more info.
openquake.engine.db.models.get_geom(surface, is_from_fault_source, is_multi_surface)[source]

The following fields can be interpreted different ways, depending on the value of is_from_fault_source. If is_from_fault_source is True, each of these fields should contain a 2D numpy array (all of the same shape). Each triple of (lon, lat, depth) for a given index represents the node of a rectangular mesh. If is_from_fault_source is False, each of these fields should contain a sequence (tuple, list, or numpy array, for example) of 4 values. In order, the triples of (lon, lat, depth) represent top left, top right, bottom left, and bottom right corners of the the rupture’s planar surface. Update: There is now a third case. If the rupture originated from a characteristic fault source with a multi-planar-surface geometry, lons, lats, and depths will contain one or more sets of 4 points, similar to how planar surface geometry is stored (see above).

Parameters:rupture – an instance of :class:

openquake.hazardlib.source.rupture.BaseProbabilisticRupture

Parameters:
  • is_from_fault_source – a boolean
  • is_multi_surface – a boolean
openquake.engine.db.models.get_gmvs_per_site(output, imt)[source]

Iterator for walking through all GmfData objects associated to a given output. Notice that values for the same site are displayed together and ordered according to the rupture ids, so that it is possible to get consistent outputs in the test cases.

Parameters:
Returns:

a list of ground motion values per each site

openquake.engine.db.models.getcursor(route)[source]

Return a cursor from a Django route

openquake.engine.db.models.loss_curve_almost_equal(curve, expected_curve)[source]
openquake.engine.db.models.make_absolute(limit, value, is_absolute=None)[source]
Returns:limit if is_absolute is True or limit is None, else limit * value
openquake.engine.db.models.oqparam(job_id)[source]
Parameters:job_id – ID of openquake.engine.db.models.OqJob
Returns:instance of openquake.commonlib.oqvalidation.OqParam
openquake.engine.db.models.order_by_location(queryset)[source]

Utility function to order a queryset by location. This works even if the location is of Geography object (a simple order_by(‘location’) only works for Geometry objects).

openquake.engine.db.models.queryset_iter(queryset, chunk_size)[source]

Given a QuerySet, split it into smaller queries and yield the result of each.

Parameters:
  • queryset – A django.db.models.query.QuerySet to iterate over, in chunks of chunk_size.
  • chunksize (int) – Chunk size for iteration over query results. For an unexecuted QuerySet, this will result in splitting a (potentially large) query into smaller queries.
openquake.engine.db.models.risk_almost_equal(o1, o2, key=<function <lambda>>, rtol=0.05, atol=0.01)[source]
openquake.engine.db.models.save_sites(job, coords)[source]

Save all the given sites on the hzrdi.hazard_site table, in lon-lat order

Parameters:coords – a sequence of coordinates
Returns:a mesh and the ids of the inserted HazardSite instances

NB: the coordinate list can contain duplicates; they will be removed