示例#1
0
    def test_from_footprints(self):
        """Test from_footprints constructor, using one small test files"""
        storms = StormEurope.from_footprints(WS_DEMO_NC[0], description='test_description')

        self.assertEqual(storms.tag.haz_type, 'WS')
        self.assertEqual(storms.units, 'm/s')
        self.assertEqual(storms.event_id.size, 1)
        self.assertEqual(storms.date.size, 1)
        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, (1, 9944))
        self.assertEqual(storms.fraction.shape, (1, 9944))
        self.assertEqual(storms.frequency[0], 1.0)


        """Test from_footprints constructor, using two small test files"""
        storms = StormEurope.from_footprints(WS_DEMO_NC, 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))
示例#2
0
    def test_read_with_ref(self):
        """Test from_footprints while passing in a reference raster."""
        storms = StormEurope.from_footprints(WS_DEMO_NC, ref_raster=WS_DEMO_NC[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))
示例#3
0
    def test_read_with_cent(self):
        """Test from_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.from_excel(
            DATA_DIR.joinpath('fp_centroids-test.xls'),
            var_names=var_names
            )
        storms = StormEurope.from_footprints(WS_DEMO_NC, centroids=test_centroids)

        self.assertEqual(storms.intensity.shape, (2, 9944))
        self.assertEqual(
            np.count_nonzero(
                ~np.isnan(storms.centroids.region_id)
            ),
            6401
        )
示例#4
0
    def test_generate_prob_storms(self):
        """Test the probabilistic storm generator; calls _hist2prob as well as
        Centroids.set_region_id()"""
        storms = StormEurope.from_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)
示例#5
0
    def test_set_ssi(self):
        """Test set_ssi with both dawkins and wisc_gust methodology."""
        storms = StormEurope.from_footprints(WS_DEMO_NC)

        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)
        )
 def test_Forecast_init_raise(self):
     """Test calc and propety functions from the Forecast class"""
     #hazard with several event dates
     storms = StormEurope.from_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)