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

    Returns the newly created job object.
    """
    session = get_db_session("reslt", "writer")

    # TODO specify the owner as a command line parameter
    owner = session.query(OqUser).filter(OqUser.user_name == 'openquake').one()
    oqp = OqParams(upload=None)
    job = OqJob(owner=owner, path=None, oq_params=oqp,
                job_type=CALCULATION_MODE[params['CALCULATION_MODE']])

    # fill-in parameters
    oqp.job_type = job.job_type
    oqp.region_grid_spacing = float(params['REGION_GRID_SPACING'])
    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))

    if oqp.job_type != 'classical':
        oqp.gm_correlated = (
            params['GROUND_MOTION_CORRELATION'].lower() != 'false')
    else:
        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 != 'deterministic':
        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'])

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

    # config lat/lon -> postgis -> lon/lat
    coords = [float(v) for v in
                  params['REGION_VERTEX'].split(",")]
    vertices = ["%f %f" % (coords[i + 1], coords[i])
                    for i in xrange(0, len(coords), 2)]
    region = "SRID=4326;POLYGON((%s, %s))" % (", ".join(vertices), vertices[0])
    oqp.region = ga.WKTSpatialElement(region)

    session.add(oqp)
    session.add(job)
    session.commit()

    return job
Exemplo n.º 2
0
    def setup_classic_job(self, create_job_path=True, upload_id=None):
        """Create a classic job with associated upload and inputs.

        :param integer upload_id: if set use upload record with given db key.
        :param bool create_job_path: if set the path for the job will be
            created and captured in the job record
        :returns: a :py:class:`db.alchemy.models.OqJob` instance
        """
        session = get_db_session("uiapi", "writer")
        upload = self.setup_upload(upload_id)
        oqp = OqParams()
        oqp.job_type = "classical"
        oqp.upload = upload
        oqp.region_grid_spacing = 0.01
        oqp.min_magnitude = 5.0
        oqp.investigation_time = 50.0
        oqp.component = "gmroti50"
        oqp.imt = "pga"
        oqp.truncation_type = "twosided"
        oqp.truncation_level = 3
        oqp.reference_vs30_value = 760
        oqp.imls = self.IMLS
        oqp.poes = [0.01, 0.10]
        oqp.realizations = 1
        oqp.region = (
            "POLYGON((-81.3 37.2, -80.63 38.04, -80.02 37.49, -81.3 37.2))")
        session.add(oqp)
        job = OqJob(oq_params=oqp, owner=upload.owner, job_type="classical")
        session.add(job)
        session.commit()
        if create_job_path:
            job.path = os.path.join(upload.path, str(job.id))
            session.add(job)
            session.commit()
            os.mkdir(job.path)
            os.chmod(job.path, 0777)
        return job