def hazard_maps(self, curves): """ Compute the hazard maps associated to the curves """ n, p = len(self.sitecol), len(self.oqparam.poes) maps = zero_maps((n, p), self.oqparam.imtls) for imt in curves.dtype.fields: maps[imt] = calc.compute_hazard_maps(curves[imt], self.oqparam.imtls[imt], self.oqparam.poes) return maps
def hazard_maps(self, curves): """ Compute the hazard maps associated to the curves """ maps = zero_maps( len(self.sitecol), self.oqparam.imtls, self.oqparam.poes) for imt in curves.dtype.fields: # build a matrix of size (N, P) data = calc.compute_hazard_maps( curves[imt], self.oqparam.imtls[imt], self.oqparam.poes) for poe, hmap in zip(self.oqparam.poes, data.T): maps['%s~%s' % (imt, poe)] = hmap return maps
def hazard_maps(self, curves): """ Compute the hazard maps associated to the curves """ maps = zero_maps( len(self.sitecol), self.oqparam.imtls, self.oqparam.poes) for imt in curves.dtype.fields: # build a matrix of size (N, P) data = calc.compute_hazard_maps( curves[imt], self.oqparam.imtls[imt], self.oqparam.poes) for poe, hmap in zip(self.oqparam.poes, data.T): maps['%s~%s' % (imt, poe)] = hmap return maps
def test_compute_hazard_map(self): curves = [ [0.8, 0.5, 0.1], [0.98, 0.15, 0.05], [0.6, 0.5, 0.4], [0.1, 0.01, 0.001], [0.8, 0.2, 0.1], ] imls = [0.005, 0.007, 0.0098] poe = 0.2 expected = [[0.00847798, 0.00664814, 0.0098, 0, 0.007]] actual = calc.compute_hazard_maps(curves, imls, poe) aaae(expected, actual.T)
def test_compute_hazard_map(self): curves = [ [0.8, 0.5, 0.1], [0.98, 0.15, 0.05], [0.6, 0.5, 0.4], [0.1, 0.01, 0.001], [0.8, 0.2, 0.1], ] imls = [0.005, 0.007, 0.0098] poe = 0.2 expected = [[0.00847798, 0.00664814, 0.0098, 0, 0.007]] actual = calc.compute_hazard_maps(curves, imls, poe) aaae(expected, actual.T)
def hazard_curves_to_hazard_map(hazard_curves, poes, monitor): """ Function to process a set of hazard curves into 1 hazard map for each PoE in ``poes``. Hazard map results are written directly to the database. :param hazard_curves: a list of :class:`hazard curves <openquake.engine.db.models.HazardCurve>` :param list poes: list of PoEs for which we want to iterpolate hazard maps :param monitor: monitor of the currently running job """ job = models.OqJob.objects.get(id=monitor.job_id) for hc in hazard_curves: hcd = list(models.HazardCurveData.objects.all_curves_simple( filter_args=dict(hazard_curve=hc.id), order_by='location' )) imt = hc.imt if imt == 'SA': # if it's SA, include the period using the standard notation imt = 'SA(%s)' % hc.sa_period # Gather all of the curves and compute the maps, for all PoEs curves = [_poes for _, _, _poes in hcd] hazard_maps = calc.compute_hazard_maps(curves, hc.imls, poes).T # Prepare the maps to be saved to the DB for i, poe in enumerate(poes): map_values = hazard_maps[i] lons = numpy.empty(map_values.shape) lats = numpy.empty(map_values.shape) for loc_idx, _ in enumerate(map_values): lons[loc_idx] = hcd[loc_idx][0] lats[loc_idx] = hcd[loc_idx][1] # Create 'Output' records for the map for this PoE if hc.statistics == 'mean': disp_name = _HAZ_MAP_DISP_NAME_MEAN_FMT % dict( poe=poe, imt=imt) elif hc.statistics == 'quantile': disp_name = _HAZ_MAP_DISP_NAME_QUANTILE_FMT % dict( poe=poe, imt=imt, quantile=hc.quantile) else: disp_name = _HAZ_MAP_DISP_NAME_FMT % dict( poe=poe, imt=imt, rlz=hc.lt_realization.id) output = job.get_or_create_output(disp_name, 'hazard_map') # Save the complete hazard map models.HazardMap.objects.create( output=output, lt_realization=hc.lt_realization, investigation_time=hc.investigation_time, imt=hc.imt, statistics=hc.statistics, quantile=hc.quantile, sa_period=hc.sa_period, sa_damping=hc.sa_damping, poe=poe, lons=lons.tolist(), lats=lats.tolist(), imls=map_values.tolist(), )