示例#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
示例#2
0
def prepare_job(user_name="openquake"):
    """Create job for the given user, return it."""
    # See if the current user exists
    # If not, create a record for them
    owner = prepare_user(user_name)
    job = OqJob(owner=owner)
    job.save()
    return job
示例#3
0
def prepare_job(user_name="openquake"):
    """Create job for the given user, return it."""
    # See if the current user exists
    # If not, create a record for them
    owner = prepare_user(user_name)
    job = OqJob(owner=owner)
    job.save()
    return job
示例#4
0
def _job_from_file(config_file, output_type, owner_username='******',
                   force_inputs=False):
    """
    Create a job from external configuration files.

    NOTE: This function is deprecated. Please use
    :function:`openquake.engine.import_job_profile`.

    :param config_file:
        The external configuration file path
    :param output_type:
        Where to store results:
        * 'db' database
        * 'xml' XML files *plus* database
    :param owner_username:
        oq_user.user_name which defines the owner of all DB artifacts created
        by this function.
    :param bool force_inputs: If `True` the model input files will be parsed
        and the resulting content written to the database no matter what.
    """

    # output_type can be set, in addition to 'db' and 'xml', also to
    # 'xml_without_db', which has the effect of serializing only to xml
    # without requiring a database at all.
    # This allows to run tests without requiring a database.
    # This is not documented in the public interface because it is
    # essentially a detail of our current tests and ci infrastructure.
    assert output_type in ('db', 'xml')

    params, sections = _parse_config_file(config_file)
    params, sections = _prepare_config_parameters(params, sections)

    validator = jobconf.default_validators(sections, params)
    is_valid, errors = validator.is_valid()

    if not is_valid:
        raise jobconf.ValidationException(errors)

    owner = OqUser.objects.get(user_name=owner_username)
    # openquake-server creates the job record in advance and stores
    # the calculation id in the config file
    job_id = params.get('OPENQUAKE_JOB_ID')
    if not job_id:
        # create the database record for this job
        job = OqJob(owner=owner, path=None)
        job.save()
        job_id = job.id
    else:
        job = OqJob.objects.get(job_id)

    job_profile = _prepare_job(params, sections, owner_username, job,
                               force_inputs)

    if output_type == 'db':
        serialize_results_to = ['db']
    else:
        serialize_results_to = ['db', 'xml']

    base_path = params['BASE_PATH']

    job_ctxt = JobContext(
        params, job_id, sections=sections, base_path=base_path,
        serialize_results_to=serialize_results_to, oq_job=job,
        oq_job_profile=job_profile)
    job_ctxt.to_kvs()

    return job_ctxt
示例#5
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
示例#6
0
def _job_from_file(config_file,
                   output_type,
                   owner_username='******',
                   force_inputs=False):
    """
    Create a job from external configuration files.

    NOTE: This function is deprecated. Please use
    :function:`openquake.engine.import_job_profile`.

    :param config_file:
        The external configuration file path
    :param output_type:
        Where to store results:
        * 'db' database
        * 'xml' XML files *plus* database
    :param owner_username:
        oq_user.user_name which defines the owner of all DB artifacts created
        by this function.
    :param bool force_inputs: If `True` the model input files will be parsed
        and the resulting content written to the database no matter what.
    """

    # output_type can be set, in addition to 'db' and 'xml', also to
    # 'xml_without_db', which has the effect of serializing only to xml
    # without requiring a database at all.
    # This allows to run tests without requiring a database.
    # This is not documented in the public interface because it is
    # essentially a detail of our current tests and ci infrastructure.
    assert output_type in ('db', 'xml')

    params, sections = _parse_config_file(config_file)
    params, sections = _prepare_config_parameters(params, sections)

    validator = jobconf.default_validators(sections, params)
    is_valid, errors = validator.is_valid()

    if not is_valid:
        raise jobconf.ValidationException(errors)

    owner = OqUser.objects.get(user_name=owner_username)
    # openquake-server creates the job record in advance and stores
    # the calculation id in the config file
    job_id = params.get('OPENQUAKE_JOB_ID')
    if not job_id:
        # create the database record for this job
        job = OqJob(owner=owner, path=None)
        job.save()
        job_id = job.id
    else:
        job = OqJob.objects.get(job_id)

    job_profile = _prepare_job(params, sections, owner_username, job,
                               force_inputs)

    if output_type == 'db':
        serialize_results_to = ['db']
    else:
        serialize_results_to = ['db', 'xml']

    base_path = params['BASE_PATH']

    job_ctxt = JobContext(params,
                          job_id,
                          sections=sections,
                          base_path=base_path,
                          serialize_results_to=serialize_results_to,
                          oq_job=job,
                          oq_job_profile=job_profile)
    job_ctxt.to_kvs()

    return job_ctxt