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
def test_multipoint_ewkt(self): ''' Test typical usage of :py:function:`openquake.engine.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)
def test_multipoint_ewkt_round_float(self): ''' Test usage of :py:function:`openquake.engine.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)