def compute_disagg_matrix(job_id, site, poe, result_dir): """ Compute a complete 5D Disaggregation matrix. This task leans heavily on the DisaggregationCalculator (in the OpenQuake Java lib) to handle this computation. The 5D matrix returned from the java calculator will be saved to a file in HDF5 format. :param job_id: id of the job record in the KVS :type job_id: `str` :param site: a single site of interest :type site: :class:`openquake.shapes.Site` instance` :param poe: Probability of Exceedence :type poe: `float` :param result_dir: location for the Java code to write the matrix in an HDF5 file (in a distributed environment, this should be the path of a mounted NFS) :returns: 2-tuple of (ground_motion_value, path_to_h5_matrix_file) """ the_job = job.Job.from_kvs(job_id) lat_bin_lims = the_job[job_cfg.LAT_BIN_LIMITS] lon_bin_lims = the_job[job_cfg.LON_BIN_LIMITS] mag_bin_lims = the_job[job_cfg.MAG_BIN_LIMITS] eps_bin_lims = the_job[job_cfg.EPS_BIN_LIMITS] jd = list_to_jdouble_array disagg_calc = java.jclass('DisaggregationCalculator')( jd(lat_bin_lims), jd(lon_bin_lims), jd(mag_bin_lims), jd(eps_bin_lims)) cache = java.jclass('KVS')( config.get('kvs', 'host'), int(config.get('kvs', 'port'))) erf = generate_erf(job_id, cache) gmpe_map = generate_gmpe_map(job_id, cache) set_gmpe_params(gmpe_map, the_job.params) imls = get_iml_list(the_job['INTENSITY_MEASURE_LEVELS'], the_job['INTENSITY_MEASURE_TYPE']) vs30_type = the_job['VS30_TYPE'] vs30_value = the_job['REFERENCE_VS30_VALUE'] depth_to_1pt0 = the_job['DEPTHTO1PT0KMPERSEC'] depth_to_2pt5 = the_job['REFERENCE_DEPTH_TO_2PT5KM_PER_SEC_PARAM'] matrix_result = disagg_calc.computeMatrix( site.latitude, site.longitude, erf, gmpe_map, poe, imls, vs30_type, vs30_value, depth_to_1pt0, depth_to_2pt5) matrix_path = save_5d_matrix_to_h5(result_dir, numpy.array(matrix_result.getMatrix())) return (matrix_result.getGMV(), matrix_path)
def compute_uhs(the_job, site): """Given a `Job` and a site of interest, compute UHS. The Java `UHSCalculator` is called to do perform the core computation. :param the_job: :class:`openquake.job.Job` instance. :param site: :class:`openquake.shapes.Site` instance. :returns: An `ArrayList` (Java object) of `UHSResult` objects, one per PoE. """ periods = list_to_jdouble_array(the_job['UHS_PERIODS']) poes = list_to_jdouble_array(the_job['POES']) imls = get_iml_list(the_job['INTENSITY_MEASURE_LEVELS'], the_job['INTENSITY_MEASURE_TYPE']) max_distance = the_job['MAXIMUM_DISTANCE'] cache = java.jclass('KVS')( config.get('kvs', 'host'), int(config.get('kvs', 'port'))) erf = generate_erf(the_job.job_id, cache) gmpe_map = generate_gmpe_map(the_job.job_id, cache) set_gmpe_params(gmpe_map, the_job.params) uhs_calc = java.jclass('UHSCalculator')(periods, poes, imls, erf, gmpe_map, max_distance) uhs_results = uhs_calc.computeUHS( site.latitude, site.longitude, the_job['VS30_TYPE'], the_job['REFERENCE_VS30_VALUE'], the_job['DEPTHTO1PT0KMPERSEC'], the_job['REFERENCE_DEPTH_TO_2PT5KM_PER_SEC_PARAM']) return uhs_results