Esempio 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 == fields.FloatArrayField:
            value = [float(v) for v in ARRAY_RE.split(value) if len(v)]
        elif param.type == fields.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
Esempio n. 2
0
    def test_polygon_ewkt(self):
        '''
        Test typical usage of
        :py:function:`openquake.engine.shapes.polygon_ewkt_from_coords`
        '''
        # Note that the first & last coord are the same to form a closed loop.
        expected_ewkt = (
            'SRID=4326;POLYGON((-122.0 38.113, -122.114 38.113, '
            '-122.57 38.111, -122.0 38.113))')

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

        actual_ewkt = shapes.polygon_ewkt_from_coords(coords)

        self.assertEqual(expected_ewkt, actual_ewkt)
Esempio n. 3
0
    def test_polygon_ewkt_round_float(self):
        '''
        Test usage of
        :py:function:`openquake.engine.shapes.polygon_ewkt_from_coords` to
        ensure that high-precision coordinate values are rounded down a
        reasonable level of precision.
        '''
        # Note that the first & last coord are the same to form a closed loop.
        expected_ewkt = (
            'SRID=4326;POLYGON((-122.0 38.113, -122.114 38.113, '
            '-122.57 38.1110001, -122.0 38.113))')

        coords = \
            '38.113, -122.00000001, 38.113, -122.114, 38.11100006, -122.57'

        actual_ewkt = shapes.polygon_ewkt_from_coords(coords)

        self.assertEqual(expected_ewkt, actual_ewkt)