예제 #1
0
    def test_read_with_cent(self):
        """ Test read_footprints while passing in a Centroids object """
        var_names = copy.deepcopy(DEF_VAR_EXCEL)
        var_names['sheet_name'] = 'fp_centroids-test'
        var_names['col_name']['region_id'] = 'iso_n3'
        test_centroids = Centroids()
        test_centroids.read_excel(os.path.join(DATA_DIR,
                                               'fp_centroids-test.xls'),
                                  var_names=var_names)
        storms = StormEurope()
        storms.read_footprints(TEST_NCS, centroids=test_centroids)

        self.assertEqual(storms.intensity.shape, (2, 9944))
        self.assertEqual(
            np.count_nonzero(~np.isnan(storms.centroids.region_id)), 6401)
예제 #2
0
    def test_set_ssi(self):
        """ Test set_ssi with both dawkins and wisc_gust methodology. """
        storms = StormEurope()
        storms.read_footprints(TEST_NCS)

        storms.set_ssi(method='dawkins')
        ssi_dawg = np.asarray([1.44573572e+09, 6.16173724e+08])
        self.assertTrue(np.allclose(storms.ssi, ssi_dawg))

        storms.set_ssi(method='wisc_gust')
        ssi_gusty = np.asarray([1.42124571e+09, 5.86870673e+08])
        self.assertTrue(np.allclose(storms.ssi, ssi_gusty))

        storms.set_ssi(threshold=20, on_land=False)
        ssi_special = np.asarray([2.96582030e+09, 1.23980294e+09])
        self.assertTrue(np.allclose(storms.ssi, ssi_special))
예제 #3
0
    def test_generate_prob_storms(self):
        """ Test the probabilistic storm generator; calls _hist2prob as well as
        Centroids.set_region_id() """
        storms = StormEurope()
        storms.read_footprints(TEST_NCS)
        storms_prob = storms.generate_prob_storms()

        self.assertEqual(
            np.count_nonzero(storms.centroids.region_id), 6190
            # here, we don't rasterise; we check if the centroids lie in a
            # polygon. that is to say, it's not the majority of a raster pixel,
            # but the centroid's location that is decisive
        )
        self.assertEqual(storms_prob.size, 60)
        self.assertEqual(np.count_nonzero(storms_prob.orig), 2)
        self.assertEqual(storms_prob.centroids.size, 3054)
        self.assertIsInstance(storms_prob.intensity, sparse.csr.csr_matrix)
예제 #4
0
    def test_read_with_ref(self):
        """ Test read_footprints while passing in a reference raster. """
        storms = StormEurope()
        storms.read_footprints(TEST_NCS, ref_raster=TEST_NCS[1])

        self.assertEqual(storms.tag.haz_type, 'WS')
        self.assertEqual(storms.units, 'm/s')
        self.assertEqual(storms.event_id.size, 2)
        self.assertEqual(storms.date.size, 2)
        self.assertEqual(dt.datetime.fromordinal(storms.date[0]).year, 1999)
        self.assertEqual(dt.datetime.fromordinal(storms.date[0]).month, 12)
        self.assertEqual(dt.datetime.fromordinal(storms.date[0]).day, 26)
        self.assertEqual(storms.event_id[0], 1)
        self.assertEqual(storms.event_name[0], 'Lothar')
        self.assertTrue(isinstance(storms.intensity, sparse.csr.csr_matrix))
        self.assertTrue(isinstance(storms.fraction, sparse.csr.csr_matrix))
        self.assertEqual(storms.intensity.shape, (2, 9944))
        self.assertEqual(storms.fraction.shape, (2, 9944))
예제 #5
0
    def test_read_footprints(self):
        """ Test read_footprints function, using two small test files"""
        storms = StormEurope()
        storms.read_footprints(TEST_NCS, description='test_description')

        self.assertEqual(storms.tag.haz_type, 'WS')
        self.assertEqual(storms.units, 'm/s')
        self.assertEqual(storms.event_id.size, 2)
        self.assertEqual(storms.date.size, 2)
        self.assertEqual(dt.datetime.fromordinal(storms.date[0]).year, 1999)
        self.assertEqual(dt.datetime.fromordinal(storms.date[0]).month, 12)
        self.assertEqual(dt.datetime.fromordinal(storms.date[0]).day, 26)
        self.assertEqual(storms.event_id[0], 1)
        self.assertEqual(storms.event_name[0], 'Lothar')
        self.assertIsInstance(storms.intensity, sparse.csr.csr_matrix)
        self.assertIsInstance(storms.fraction, sparse.csr.csr_matrix)
        self.assertEqual(storms.intensity.shape, (2, 9944))
        self.assertEqual(storms.fraction.shape, (2, 9944))
예제 #6
0
    def test_generate_prob_storms(self):
        """Test the probabilistic storm generator; calls _hist2prob as well as
        Centroids.set_region_id()"""
        storms = StormEurope()
        storms.read_footprints(WS_DEMO_NC)
        storms_prob = storms.generate_prob_storms()

        self.assertEqual(
            np.count_nonzero(storms.centroids.region_id), 6402
            # here, we don't rasterise; we check if the centroids lie in a
            # polygon. that is to say, it's not the majority of a raster pixel,
            # but the centroid's location that is decisive
        )
        self.assertEqual(storms_prob.size, 60)
        self.assertTrue(
            np.allclose((1 / storms_prob.frequency).astype(int), 330))
        self.assertAlmostEqual(storms.frequency.sum(),
                               storms_prob.frequency.sum())
        self.assertEqual(np.count_nonzero(storms_prob.orig), 2)
        self.assertEqual(storms_prob.centroids.size, 3054)
        self.assertIsInstance(storms_prob.intensity, sparse.csr.csr_matrix)
예제 #7
0
 def test_Forecast_init_raise(self):
     """Test calc and propety functions from the Forecast class"""
     #hazard with several event dates
     storms = StormEurope()
     storms.read_footprints(WS_DEMO_NC, description='test_description')
     #exposure
     data = {}
     data['latitude'] = np.array([1, 2, 3])
     data['longitude'] = np.array([1, 2, 3])
     data['value'] = np.ones_like(data['latitude']) * 100000
     data['deductible'] = np.zeros_like(data['latitude'])
     data[INDICATOR_IMPF + 'WS'] = np.ones_like(data['latitude'])
     data['region_id'] = np.ones_like(data['latitude'], dtype=int) * 756
     expo = Exposures(gpd.GeoDataFrame(data=data))
     #vulnerability
     #generate vulnerability
     impact_function_set = ImpactFuncSet()
     #create and calculate Forecast
     with self.assertRaises(ValueError):
         Forecast({dt.datetime(2018, 1, 1): storms}, expo,
                  impact_function_set)