コード例 #1
0
ファイル: helpers.py プロジェクト: favalex/openquake-server
    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:`geonode.mtapi.models.OqJob` instance
        """
        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 = [
            0.005,
            0.007,
            0.0098,
            0.0137,
            0.0192,
            0.0269,
            0.0376,
            0.0527,
            0.0738,
            0.103,
            0.145,
            0.203,
            0.284,
            0.397,
            0.556,
            0.778,
        ]
        oqp.poes = [0.01, 0.10]
        oqp.realizations = 1
        from django.contrib.gis import geos

        oqp.region = geos.Polygon(((-122.2, 38.0), (-121.7, 38.0), (-121.7, 37.5), (-122.2, 37.5), (-122.2, 38.0)))
        oqp.save()
        job = OqJob(oq_params=oqp, owner=upload.owner, job_type="classical")
        job.save()
        if create_job_path:
            job.path = os.path.join(upload.path, str(job.id))
            os.mkdir(job.path)
            os.chmod(job.path, 0777)
            job.save()
        return job
コード例 #2
0
ファイル: helpers.py プロジェクト: gem/openquake-server
    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:`geonode.mtapi.models.OqJob` instance
        """
        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 = [
            0.005, 0.007, 0.0098, 0.0137, 0.0192, 0.0269, 0.0376, 0.0527,
            0.0738, 0.103, 0.145, 0.203, 0.284, 0.397, 0.556, 0.778
        ]
        oqp.poes = [0.01, 0.10]
        oqp.realizations = 1
        from django.contrib.gis import geos
        oqp.region = geos.Polygon(
            ((-122.2, 38.0), (-121.7, 38.0), (-121.7, 37.5), (-122.2, 37.5),
             (-122.2, 38.0)))
        oqp.save()
        job = OqJob(oq_params=oqp, owner=upload.owner, job_type="classical")
        job.save()
        if create_job_path:
            job.path = os.path.join(upload.path, str(job.id))
            os.mkdir(job.path)
            os.chmod(job.path, 0777)
            job.save()
        return job
コード例 #3
0
ファイル: views.py プロジェクト: gem/openquake-server
def prepare_job(params):
    """Create a job with the associated upload and the given parameters.

    :param dict params: the parameters will look as follows:
        {"model":"openquake.calculationparams",
         "upload": 23,
         "fields":
             {"job_type": "classical",
              "region_grid_spacing": 0.1,
              "min_magnitude": 5,
              "investigation_time": 50,
              "component": "average",
              "imt": "pga",
              "period": 1,
              "truncation_type": "none",
              "truncation_level": 3,
              "reference_v30_value": 800,
              "imls": [0.2,0.02,0.01],
              "poes": [0.2,0.02,0.01],
              "realizations": 6,
              "histories": 1,
              "gm_correlated": False,
              "region":"POLYGON((
                 16.460737205888 41.257786872643,
                 16.460898138429 41.257786872643,
                 16.460898138429 41.257923984376,
                 16.460737205888 41.257923984376,
                 16.460737205888 41.257786872643))"}}

        Please see the "hazard_risk_calc" section of
        https://github.com/gem/openquake/wiki/demo-client-API for details on
        the parameters.

    :returns: a :py:class:`geonode.mtapi.models.OqJob` instance
    """
    print "> prepare_job"

    upload = params.get("upload")
    if not upload:
        print "No upload database key supplied"

    upload = Upload.objects.get(id=upload)
    if not upload:
        print "No upload record found"
    else:
        print upload

    oqp = OqParams(upload=upload)
    trans_tab = dict(reference_v30_value="reference_vs30_value")
    value_trans_tab = {
        "truncation_type": {
            "1-sided": "onesided",
            "2-sided": "twosided"}}
    param_names = (
        "job_type", "region_grid_spacing", "min_magnitude",
        "investigation_time", "component", "imt", "period", "truncation_type",
        "truncation_level", "reference_v30_value", "imls", "poes",
        "realizations", "histories", "gm_correlated")

    ignore = dict(
        classical=set(["period", "histories", "gm_correlated"]),
        deterministic=set(), event_based=set())

    job_type = params["fields"]["job_type"]
    assert job_type in ("classical", "deterministic", "event_based"), \
        "invalid job type: '%s'" % job_type

    for param_name in param_names:
        if param_name == "region" or param_name in ignore[job_type]:
            continue
        # Take care of differences in property names.
        property_name = trans_tab.get(param_name, param_name)
        value = params["fields"].get(param_name)
        if value:
            # Is there a need to translate the value?
            trans = value_trans_tab.get(property_name)
            if trans:
                value = trans.get(value, value)
            setattr(oqp, property_name, value)

    region = params["fields"].get("region")

    if region:
        oqp.region = GEOSGeometry(region)

    oqp.save()
    print oqp

    job = OqJob(oq_params=oqp, owner=upload.owner,
                job_type=params["fields"]["job_type"])
    job.save()
    print job

    print "< prepare_job"
    return job