Пример #1
0
def compute_uhs(the_job, site):
    """Given a `JobContext` and a site of interest, compute UHS. The Java
    `UHSCalculator` is called to do perform the core computation.

    :param the_job:
        :class:`openquake.engine.JobContext` 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
Пример #2
0
def compute_disagg_matrix(calc_proxy, 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 calc_proxy:
        A :class:`openquake.engine.CalculationProxy` which holds all of the
        data we need to run this computation.
    :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)
    """
    lat_bin_lims = calc_proxy[job_cfg.LAT_BIN_LIMITS]
    lon_bin_lims = calc_proxy[job_cfg.LON_BIN_LIMITS]
    mag_bin_lims = calc_proxy[job_cfg.MAG_BIN_LIMITS]
    eps_bin_lims = calc_proxy[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(calc_proxy.job_id, cache)
    gmpe_map = generate_gmpe_map(calc_proxy.job_id, cache)
    set_gmpe_params(gmpe_map, calc_proxy.params)

    imls = get_iml_list(calc_proxy['INTENSITY_MEASURE_LEVELS'],
                        calc_proxy['INTENSITY_MEASURE_TYPE'])
    vs30_type = calc_proxy['VS30_TYPE']
    vs30_value = calc_proxy['REFERENCE_VS30_VALUE']
    depth_to_1pt0 = calc_proxy['DEPTHTO1PT0KMPERSEC']
    depth_to_2pt5 = calc_proxy['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)
Пример #3
0
def compute_uhs(the_job, site):
    """Given a `JobContext` and a site of interest, compute UHS. The Java
    `UHSCalculator` is called to do perform the core computation.

    :param the_job:
        :class:`openquake.engine.JobContext` 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 = general.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 = general.generate_erf(the_job.job_id, cache)
    gmpe_map = general.generate_gmpe_map(the_job.job_id, cache)
    general.set_gmpe_params(gmpe_map, the_job.params)

    uhs_calc = java.jclass('UHSCalculator')(periods, poes, imls, erf, gmpe_map,
                                            max_distance)

    site_model = general.get_site_model(the_job.oq_job.id)

    if site_model is not None:
        sm_data = general.get_closest_site_model_data(site_model, site)
        vs30_type = sm_data.vs30_type.capitalize()
        vs30 = sm_data.vs30
        z1pt0 = sm_data.z1pt0
        z2pt5 = sm_data.z2pt5
    else:
        jp = the_job.oq_job_profile

        vs30_type = jp.vs30_type.capitalize()
        vs30 = jp.reference_vs30_value
        z1pt0 = jp.depth_to_1pt_0km_per_sec
        z2pt5 = jp.reference_depth_to_2pt5km_per_sec_param

    uhs_results = _compute_uhs(
        uhs_calc, site.latitude, site.longitude, vs30_type, vs30, z1pt0, z2pt5
    )

    return uhs_results
Пример #4
0
def compute_uhs(the_job, site):
    """Given a `CalculationProxy` and a site of interest, compute UHS. The Java
    `UHSCalculator` is called to do perform the core computation.

    :param the_job:
        :class:`openquake.engine.CalculationProxy` 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
Пример #5
0
def compute_disagg_matrix(job_ctxt, 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_ctxt:
        A :class:`openquake.engine.JobContext` which holds all of the
        data we need to run this computation.
    :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)
    """
    lat_bin_lims = job_ctxt[job_cfg.LAT_BIN_LIMITS]
    lon_bin_lims = job_ctxt[job_cfg.LON_BIN_LIMITS]
    mag_bin_lims = job_ctxt[job_cfg.MAG_BIN_LIMITS]
    eps_bin_lims = job_ctxt[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 = general.generate_erf(job_ctxt.job_id, cache)
    gmpe_map = general.generate_gmpe_map(job_ctxt.job_id, cache)
    general.set_gmpe_params(gmpe_map, job_ctxt.params)

    imls = general.get_iml_list(job_ctxt['INTENSITY_MEASURE_LEVELS'],
                                job_ctxt['INTENSITY_MEASURE_TYPE'])

    site_model = general.get_site_model(job_ctxt.oq_job.id)

    if site_model is not None:
        sm_data = general.get_closest_site_model_data(site_model, site)
        vs30_type = sm_data.vs30_type.capitalize()
        vs30 = sm_data.vs30
        z1pt0 = sm_data.z1pt0
        z2pt5 = sm_data.z2pt5
    else:
        jp = job_ctxt.oq_job_profile

        vs30_type = jp.vs30_type.capitalize()
        vs30 = jp.reference_vs30_value
        z1pt0 = jp.depth_to_1pt_0km_per_sec
        z2pt5 = jp.reference_depth_to_2pt5km_per_sec_param

    matrix_result = _compute_matrix(disagg_calc, site.latitude, site.longitude,
                                    erf, gmpe_map, poe, imls, vs30_type, vs30,
                                    z1pt0, z2pt5)

    matrix_path = save_5d_matrix_to_h5(result_dir,
                                       numpy.array(matrix_result.getMatrix()))

    return (matrix_result.getGMV(), matrix_path)
Пример #6
0
def compute_disagg_matrix(job_ctxt, 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_ctxt:
        A :class:`openquake.engine.JobContext` which holds all of the
        data we need to run this computation.
    :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)
    """
    lat_bin_lims = job_ctxt[job_cfg.LAT_BIN_LIMITS]
    lon_bin_lims = job_ctxt[job_cfg.LON_BIN_LIMITS]
    mag_bin_lims = job_ctxt[job_cfg.MAG_BIN_LIMITS]
    eps_bin_lims = job_ctxt[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 = general.generate_erf(job_ctxt.job_id, cache)
    gmpe_map = general.generate_gmpe_map(job_ctxt.job_id, cache)
    general.set_gmpe_params(gmpe_map, job_ctxt.params)

    imls = general.get_iml_list(job_ctxt['INTENSITY_MEASURE_LEVELS'],
                                job_ctxt['INTENSITY_MEASURE_TYPE'])

    site_model = general.get_site_model(job_ctxt.oq_job.id)

    if site_model is not None:
        sm_data = general.get_closest_site_model_data(site_model, site)
        vs30_type = sm_data.vs30_type.capitalize()
        vs30 = sm_data.vs30
        z1pt0 = sm_data.z1pt0
        z2pt5 = sm_data.z2pt5
    else:
        jp = job_ctxt.oq_job_profile

        vs30_type = jp.vs30_type.capitalize()
        vs30 = jp.reference_vs30_value
        z1pt0 = jp.depth_to_1pt_0km_per_sec
        z2pt5 = jp.reference_depth_to_2pt5km_per_sec_param

    matrix_result = _compute_matrix(
        disagg_calc, site.latitude, site.longitude, erf, gmpe_map, poe, imls,
        vs30_type, vs30, z1pt0, z2pt5)

    matrix_path = save_5d_matrix_to_h5(result_dir,
                                       numpy.array(matrix_result.getMatrix()))

    return (matrix_result.getGMV(), matrix_path)