Exemplo n.º 1
0
def _store_input_parameters(params, calc_mode, job_profile):
    """Store parameters in uiapi.oq_job_profile columns"""

    for name, param in PARAMS.items():
        if calc_mode in param.modes and param.default is not None:
            setattr(job_profile, param.column, param.default)

    for name, value in params.items():
        param = PARAMS[name]
        value = value.strip()

        if param.type in (models.BooleanField, models.NullBooleanField):
            value = value.lower() not in ('0', 'false')
        elif param.type == models.PolygonField:
            ewkt = shapes.polygon_ewkt_from_coords(value)
            value = GEOSGeometry(ewkt)
        elif param.type == models.MultiPointField:
            ewkt = shapes.multipoint_ewkt_from_coords(value)
            value = GEOSGeometry(ewkt)
        elif param.type == FloatArrayField:
            value = [float(v) for v in ARRAY_RE.split(value) if len(v)]
        elif param.type == CharArrayField:
            if param.to_db is not None:
                value = param.to_db(value)
            value = [str(v) for v in ARRAY_RE.split(value) if len(v)]
        elif param.to_db is not None:
            value = param.to_db(value)
        elif param.type == None:
            continue

        setattr(job_profile, param.column, value)

    if job_profile.imt != 'sa':
        job_profile.period = None
        job_profile.damping = None
Exemplo n.º 2
0
def _store_input_parameters(params, calc_mode, job_profile):
    """Store parameters in uiapi.oq_job_profile columns"""

    for name, param in PARAMS.items():
        if calc_mode in param.modes and param.default is not None:
            setattr(job_profile, param.column, param.default)

    for name, value in params.items():
        param = PARAMS[name]
        value = value.strip()

        if param.type in (models.BooleanField, models.NullBooleanField):
            value = value.lower() not in ('0', 'false')
        elif param.type == models.PolygonField:
            ewkt = shapes.polygon_ewkt_from_coords(value)
            value = GEOSGeometry(ewkt)
        elif param.type == models.MultiPointField:
            ewkt = shapes.multipoint_ewkt_from_coords(value)
            value = GEOSGeometry(ewkt)
        elif param.type == FloatArrayField:
            value = [float(v) for v in ARRAY_RE.split(value) if len(v)]
        elif param.type == CharArrayField:
            if param.to_db is not None:
                value = param.to_db(value)
            value = [str(v) for v in ARRAY_RE.split(value) if len(v)]
        elif param.to_db is not None:
            value = param.to_db(value)
        elif param.type == None:
            continue

        setattr(job_profile, param.column, value)

    if job_profile.imt != 'sa':
        job_profile.period = None
        job_profile.damping = None
Exemplo n.º 3
0
    def test_multipoint_ewkt(self):
        '''
        Test typical usage of
        :py:function:`openquake.shapes.multipoint_ewkt_from_coords`
        '''
        expected_ewkt = \
            'SRID=4326;MULTIPOINT((-122.0 38.113), (-122.114 38.113))'

        coords = '38.113, -122.0, 38.113, -122.114'

        actual_ewkt = shapes.multipoint_ewkt_from_coords(coords)

        self.assertEqual(expected_ewkt, actual_ewkt)
Exemplo n.º 4
0
    def test_multipoint_ewkt(self):
        '''
        Test typical usage of
        :py:function:`openquake.shapes.multipoint_ewkt_from_coords`
        '''
        expected_ewkt = \
            'SRID=4326;MULTIPOINT((-122.0 38.113), (-122.114 38.113))'

        coords = '38.113, -122.0, 38.113, -122.114'

        actual_ewkt = shapes.multipoint_ewkt_from_coords(coords)

        self.assertEqual(expected_ewkt, actual_ewkt)
Exemplo n.º 5
0
    def test_multipoint_ewkt_round_float(self):
        '''
        Test usage of
        :py:function:`openquake.shapes.multipoint_ewkt_from_coords` to ensure
        that high-precision coordinate values are rounded down a reasonable
        level of precision.
        '''
        expected_ewkt = \
            'SRID=4326;MULTIPOINT((-122.0 38.1130001), (-122.114 38.113))'

        coords = '38.11300006, -122.00000001, 38.113, -122.114'

        actual_ewkt = shapes.multipoint_ewkt_from_coords(coords)

        self.assertEqual(expected_ewkt, actual_ewkt)
Exemplo n.º 6
0
    def test_multipoint_ewkt_round_float(self):
        '''
        Test usage of
        :py:function:`openquake.shapes.multipoint_ewkt_from_coords` to ensure
        that high-precision coordinate values are rounded down a reasonable
        level of precision.
        '''
        expected_ewkt = \
            'SRID=4326;MULTIPOINT((-122.0 38.1130001), (-122.114 38.113))'

        coords = '38.11300006, -122.00000001, 38.113, -122.114'

        actual_ewkt = shapes.multipoint_ewkt_from_coords(coords)

        self.assertEqual(expected_ewkt, actual_ewkt)
Exemplo n.º 7
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