def store_site_model(input_mdl, source): """Invoke site model parser and save the site-specified parameter data to the database. :param input_mdl: The `uiapi.input` record which the new `hzrdi.site_model` records reference. This `input` record acts as a container for the site model data. :param source: Filename or file-like object containing the site model XML data. :returns: `list` of :class:`openquake.db.models.SiteModel` objects. These represent to newly-inserted `hzrdi.site_model` records. .""" parser = nrml_parsers.SiteModelParser(source) sm_data = [] for node in parser.parse(): sm = models.SiteModel() sm.vs30 = node.vs30 sm.vs30_type = node.vs30_type sm.z1pt0 = node.z1pt0 sm.z2pt5 = node.z2pt5 sm.location = node.wkt sm.input = input_mdl sm.save() sm_data.append(sm) return sm_data
def setUpClass(cls): # This site model has five points, arranged in an X-shaped pattern: # # a.....b # ....... # ...c... # ....... # d.....e cls.site_model_nodes = [ models.SiteModel(location='POINT(-10 10)'), models.SiteModel(location='POINT(10 10)'), models.SiteModel(location='POINT(0 0)'), models.SiteModel(location='POINT(-10 -10)'), models.SiteModel(location='POINT(10 -10)'), ]
def test_get_closest_site_model_data(self): # This test scenario is the following: # Site model data nodes arranged 2 degrees apart (longitudinally) along # the same parallel (indicated below by 'd' characters). # # The sites of interest are located at (-0.0000001, 0) and # (0.0000001, 0) (from left to right). # Sites of interest are indicated by 's' characters. # # To illustrate, a super high-tech nethack-style diagram: # # -1.........0.........1 V ← oh no, a vampire! # d s s d sm1 = models.SiteModel(input=self.site_model_inp, vs30_type='measured', vs30=0.0000001, z1pt0=0.0000001, z2pt5=0.0000001, location='POINT(-1 0)') sm1.save() sm2 = models.SiteModel(input=self.site_model_inp, vs30_type='inferred', vs30=0.0000002, z1pt0=0.0000002, z2pt5=0.0000002, location='POINT(1 0)') sm2.save() # NOTE(larsbutler): I tried testing the site (0, 0), but the result # actually alternated between the the two site model nodes on each test # run. It's very strange indeed. It must be a PostGIS thing. # (Or we can blame the vampire.) # # Thus, I decided to not include this in my test case, since it caused # the test to intermittently fail. site1 = shapes.Site(-0.0000001, 0) site2 = shapes.Site(0.0000001, 0) res1 = general.get_closest_site_model_data(self.site_model_inp, site1) res2 = general.get_closest_site_model_data(self.site_model_inp, site2) self.assertEqual(sm1, res1) self.assertEqual(sm2, res2)
def test_set_java_site_parameters(self): jsite = shapes.Site(0, 0).to_java() sm_data = models.SiteModel(vs30=800.0, vs30_type='measured', z1pt0=10.0, z2pt5=15.0) general.set_java_site_parameters(jsite, sm_data) self.assertEqual(800.0, jsite.getParameter('Vs30').getValue().value) self.assertEqual('measured', jsite.getParameter('Vs30 Type').getValue()) self.assertEqual( 10.0, jsite.getParameter('Depth 1.0 km/sec').getValue().value) self.assertEqual( 15.0, jsite.getParameter('Depth 2.5 km/sec').getValue().value)