def test_read_with_cent(self): """ Test read_footprints while passing in a Centroids object """ 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)
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.51114627e+09, 6.44053524e+08]) self.assertTrue(np.allclose(storms.ssi, ssi_dawg)) storms.set_ssi(method='wisc_gust') ssi_gusty = np.asarray([1.48558417e+09, 6.13437760e+08]) self.assertTrue(np.allclose(storms.ssi, ssi_gusty)) storms.set_ssi(threshold=20, on_land=False) ssi_special = np.asarray([3.09951236e+09, 1.29563312e+09]) self.assertTrue(np.allclose(storms.ssi, ssi_special))
def test_centroids_from_nc(self): """ Test if centroids can be constructed correctly """ cent = StormEurope._centroids_from_nc(TEST_NCS[0]) self.assertTrue(isinstance(cent, Centroids)) self.assertTrue(isinstance(cent.coord, np.ndarray)) self.assertEqual(cent.size, 9944) self.assertEqual(cent.coord.shape[0], cent.id.shape[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)
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))
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))
from climada.hazard import StormEurope # All these variables need to be defined correctly for the code to work. # The strings in these variables should point to existing folders on your computer. project_folder = 'C:\\Users\\ThomasRoosli\\Documents\\PhD\\WISC_phd\\paper GVZ\\jupyter' file_identifier = '_v01' # this string is added to all files written by this code wisc_hist_filename = os.path.join(project_folder, 'WISC_hist' + file_identifier + '.hdf5') wisc_prob_filename = os.path.join(project_folder, 'WISC_prob_CH' + file_identifier + '.hdf5') ### tryout GEV with 5 year maxima wisc_hist = StormEurope() wisc_hist.read_hdf5(wisc_hist_filename) #get 5 year maxima block_size_years = 5 quinquenniums = np.arange(0, 80, block_size_years) + 1940 ssi_5y_maxima = np.zeros_like(quinquenniums[:-1], dtype=float) for ind_i, start_year_i in enumerate(quinquenniums[:-1]): start_i = datetime.datetime(start_year_i, 1, 1).toordinal() end_i = datetime.datetime(quinquenniums[ind_i + 1], 1, 1).toordinal() selection_i = (wisc_hist.date >= start_i) & (wisc_hist.date < end_i) ssi_5y_maxima[ind_i] = wisc_hist.ssi[selection_i].max() #params_first = using R script params_final_gev = scipy.stats.genextreme.fit(ssi_5y_maxima, -0.1154771, loc=21360556255,