Database Models

Model representations of the OpenQuake DB tables.

openquake.server.db.models.DEFAULT_SRID = 4326

System Reference ID used for geometry objects

class openquake.server.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.server.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.server.db.models.LOSS_TYPES = ['structural', 'nonstructural', 'fatalities', 'contents']

Kind of supported type of loss outputs

class openquake.server.db.models.LiteralField(verbose_name=None, name=None, primary_key=False, max_length=None, unique=False, blank=False, null=False, db_index=False, rel=None, default=<class django.db.models.fields.NOT_PROVIDED>, editable=True, serialize=True, unique_for_date=None, unique_for_month=None, unique_for_year=None, choices=None, help_text=u'', db_column=None, db_tablespace=None, auto_created=False, validators=[], error_messages=None)[source]

Bases: django.db.models.fields.Field

Convert from Postgres TEXT to Python objects and viceversa by using ast.literal_eval and repr.

contribute_to_class(cls, name, **kwargs)
db_type(connection=None)[source]
get_prep_value(value)[source]
to_python(value)[source]
class openquake.server.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>
openquake.server.db.models.MAX_SINT_32 = 2147483647

Maximum value for a seed number

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

Minimum value for a seed number

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

Bases: exceptions.KeyError

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

class openquake.server.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.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.job_type

‘hazard’ or ‘risk’

OqJob.jobparam_set
OqJob.jobstats
OqJob.log_set
OqJob.objects = <django.db.models.manager.Manager object>
OqJob.oqjob_set
OqJob.output_set
OqJob.performance_set
OqJob.risk_calculation()[source]
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.server.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.get_next_by_last_update(*moreargs, **morekwargs)
Output.get_output_type_display(*moreargs, **morekwargs)
Output.get_previous_by_last_update(*moreargs, **morekwargs)
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.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.server.db.models.OutputManager object>
Output.oq_job
Output.output_container
Returns:the output container associated with this output
Output.statistical_params
Returns:an instance of StatisticalParams the output is

associated with

class openquake.server.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.server.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
openquake.server.db.models.RISK_ATOL = 0.01

absolute tolerance to consider two risk outputs (almost) equal

openquake.server.db.models.RISK_RTOL = 0.05

relative tolerance to consider two risk outputs (almost) equal

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

Kind of supported curve statistics

openquake.server.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.server.db.models.getcursor(route)[source]

Return a cursor from a Django route

openquake.server.db.models.oqparam(job_id)[source]
Parameters:job_id – ID of openquake.server.db.models.OqJob
Returns:instance of openquake.commonlib.oqvalidation.OqParam