Example #1
0
def prepare_job(params):
    """
    Create a new OqJob and fill in the related OpParams entry.

    Returns the newly created job object.
    """
    # TODO specify the owner as a command line parameter
    owner = OqUser.objects.get(user_name='openquake')

    input_set = InputSet(upload=None, owner=owner)
    input_set.save()

    job_type = CALCULATION_MODE[params['CALCULATION_MODE']]
    job = OqJob(owner=owner, path=None, job_type=job_type)

    oqp = OqParams(input_set=input_set)
    oqp.job_type = job_type

    _insert_input_files(params, input_set)
    _store_input_parameters(params, job_type, oqp)

    oqp.save()

    job.oq_params = oqp
    job.save()

    # Reset all progress indication counters for the job at hand.
    stats.delete_job_counters(job.id)

    return job
Example #2
0
def prepare_job(params):
    """
    Create a new OqJob and fill in the related OpParams entry.

    Returns the newly created job object.
    """
    oqp = OqParams(upload=None)

    # fill in parameters
    if 'SITES' in params:
        if 'REGION_VERTEX' in params and 'REGION_GRID_SPACING' in params:
            raise RuntimeError(
                "Job config contains both sites and region of interest.")

        ewkt = shapes.multipoint_ewkt_from_coords(params['SITES'])
        sites = GEOSGeometry(ewkt)
        oqp.sites = sites

    elif 'REGION_VERTEX' in params and 'REGION_GRID_SPACING' in params:
        oqp.region_grid_spacing = float(params['REGION_GRID_SPACING'])

        ewkt = shapes.polygon_ewkt_from_coords(params['REGION_VERTEX'])
        region = GEOSGeometry(ewkt)
        oqp.region = region

    else:
        raise RuntimeError(
            "Job config contains neither sites nor region of interest.")

    # TODO specify the owner as a command line parameter
    owner = OqUser.objects.get(user_name='openquake')

    job = OqJob(
        owner=owner, path=None,
        job_type=CALCULATION_MODE[params['CALCULATION_MODE']])

    oqp.job_type = job.job_type

    # fill-in parameters
    oqp.component = ENUM_MAP[params['COMPONENT']]
    oqp.imt = ENUM_MAP[params['INTENSITY_MEASURE_TYPE']]
    oqp.truncation_type = ENUM_MAP[params['GMPE_TRUNCATION_TYPE']]
    oqp.truncation_level = float(params['TRUNCATION_LEVEL'])
    oqp.reference_vs30_value = float(params['REFERENCE_VS30_VALUE'])

    if oqp.imt == 'sa':
        oqp.period = float(params.get('PERIOD', 0.0))
        oqp.damping = float(params.get('DAMPING', 0.0))

    if oqp.job_type == 'classical':
        oqp.imls = [float(v) for v in
                        params['INTENSITY_MEASURE_LEVELS'].split(",")]
        oqp.poes = [float(v) for v in
                        params['POES_HAZARD_MAPS'].split(" ")]

    if oqp.job_type in ('deterministic', 'event_based'):
        oqp.gm_correlated = (
            params['GROUND_MOTION_CORRELATION'].lower() != 'false')

    if oqp.job_type in  ('classical', 'event_based'):
        oqp.investigation_time = float(params.get('INVESTIGATION_TIME', 0.0))
        oqp.min_magnitude = float(params.get('MINIMUM_MAGNITUDE', 0.0))
        oqp.realizations = int(params['NUMBER_OF_LOGIC_TREE_SAMPLES'])
    else:
        oqp.gmf_calculation_number = int(
            params['NUMBER_OF_GROUND_MOTION_FIELDS_CALCULATIONS'])
        oqp.rupture_surface_discretization = float(
            params['RUPTURE_SURFACE_DISCRETIZATION'])

    if oqp.job_type == 'event_based':
        oqp.histories = int(params['NUMBER_OF_SEISMICITY_HISTORIES'])

    oqp.save()
    job.oq_params = oqp
    job.save()

    return job