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. point1 = hazardlib_geo.Point(-0.0000001, 0) point2 = hazardlib_geo.Point(0.0000001, 0) res1 = models.get_closest_site_model_data(self.site_model_inp, point1) res2 = models.get_closest_site_model_data(self.site_model_inp, point2) self.assertEqual(sm1, res1) self.assertEqual(sm2, res2)
def test_get_closest_site_model_data_no_data(self): # We haven't yet linked any site model data to this input, so we # expect a result of `None`. self.assertIsNone(models.get_closest_site_model_data( self.site_model_inp, hazardlib_geo.Point(0, 0)) )