def test_emdat_df_2020_load(self): """load selected sub sample from CSV, return DataFrame here: from 2020 EM-DAT version to 2020 target_version""" df = im_d.clean_emdat_df(EMDAT_2020_CSV_DEMO, countries=['THA', 'Viet Nam'], hazard='TC', year_range=[2005, 2008], target_version=2020) self.assertIn('ISO', df.columns) self.assertIn('Year', df.columns) iso3 = list(df.ISO.unique()) years = np.arange(df.Year.min(), df.Year.max() + 1) self.assertIn('THA', iso3) self.assertIn('VNM', iso3) self.assertNotIn('USA', iso3) self.assertNotIn('TWN', iso3) self.assertEqual(4, len(years)) self.assertEqual(2008, years[-1]) self.assertEqual(2006, years[1]) self.assertEqual(43, df.columns.size) self.assertEqual(688, df.size) self.assertEqual(624000, df["Total Damages ('000 US$)"].max()) self.assertIn('Tropical cyclone', list(df['Disaster Subtype'])) self.assertFalse(False in list( df['Disaster Subtype'] == 'Tropical cyclone')) self.assertFalse('Flood' in list(df['Disaster Subtype']))
def test_emdat_to_impact_2020format(self): """test import TC EM-DAT to Impact() from new 2020 EMDAT format CSV""" df1 = im_d.clean_emdat_df(EMDAT_2020_CSV_DEMO, hazard='TC', countries='PHL', year_range=(2013, 2013)) df2 = im_d.emdat_impact_event(EMDAT_2020_CSV_DEMO, countries='PHL', hazard='TC', year_range=(2013, 2013), reference_year=None, imp_str='Total Affected') impact_emdat, _countries = im_d.emdat_to_impact( EMDAT_2020_CSV_DEMO, 'TC', countries='PHL', year_range=(2013, 2013), imp_str="Total Affected") # compare number of entries for all steps: self.assertEqual(len(df1.index), len(df2.index)) self.assertEqual(impact_emdat.event_id.size, len(df1.index)) # TC events in EM-DAT in the Philipppines, 2013: self.assertEqual(8, impact_emdat.event_id.size) # People affected by TC events in the Philippines in 2013 (AAI): self.assertAlmostEqual(17944571., impact_emdat.aai_agg, places=0) # People affected by Typhoon Hayian in the Philippines: self.assertAlmostEqual(1.610687e+07, impact_emdat.at_event[4], places=0)
def test_emdat_df_2018_to_2020_load(self): """load selected sub sample from CSV, return DataFrame here: from 2018 EM-DAT version to 2020 target_version""" df = im_d.clean_emdat_df(EMDAT_TEST_CSV, countries=['USA'], hazard='TC', year_range=[2000, 2017], target_version=2020) self.assertIn('ISO', df.columns) self.assertIn('Year', df.columns) iso3 = list(df.ISO.unique()) years = np.arange(df.Year.min(), df.Year.max() + 1) self.assertListEqual(['USA'], iso3) self.assertEqual(18, len(years)) self.assertEqual(2017, years[-1]) self.assertEqual(2010, years[10]) self.assertEqual(1634, df.size) self.assertEqual(60000000, df["Insured Damages ('000 US$)"].max()) self.assertIn('Tropical cyclone', list(df['Disaster Subtype'])) self.assertFalse(False in list(df['Disaster Subtype'] == 'Tropical cyclone')) self.assertFalse('Flood' in list(df['Disaster Subtype']))
def test_clean_emdat_df_2018_load(self): """load selected sub sample from CSV, return DataFrame. here: from 2018 EM-DAT version to 2018 target_version""" df = im_d.clean_emdat_df(EMDAT_TEST_CSV, countries=['Bangladesh'], hazard='TC', year_range=[2000, 2017], target_version=2018) self.assertIn('ISO', df.columns) self.assertIn('Year', df.columns) iso3 = list(df.ISO.unique()) years = np.arange(df.Year.min(), df.Year.max() + 1) self.assertListEqual(['BGD'], iso3) self.assertEqual(18, len(years)) self.assertEqual(2017, years[-1]) self.assertEqual(2010, years[10]) self.assertEqual(450, df.size) self.assertEqual(8978541, df['Total affected'].max()) self.assertIn('Tropical cyclone', list(df['Disaster subtype'])) self.assertFalse(False in list(df['Disaster subtype'] == 'Tropical cyclone')) self.assertFalse('Flood' in list(df['Disaster subtype']))