コード例 #1
0
 def test_emdat_impact_yearlysum_no_futurewarning(self):
     """Ensure that no FutureWarning is issued"""
     with warnings.catch_warnings():
         # Make sure that FutureWarning will cause an error
         warnings.simplefilter("error", category=FutureWarning)
         im_d.emdat_impact_yearlysum(
             EMDAT_TEST_CSV,
             countries=["Bangladesh", "USA"],
             hazard="Flood",
             year_range=(2015, 2017),
             reference_year=None,
             imp_str="Total Affected",
         )
コード例 #2
0
def init_impact_data(hazard_type, 
                     region_ids,
                     year_range,
                     source_file,
                     reference_year,
                     impact_data_source='emdat',
                     yearly_impact=True):
    """ creates a dataframe containing the recorded impact data for one hazard 
    type and one area (countries, country or local split)
    Parameters:
            hazard_type: default = 'TC', type of hazard 'WS','FL' etc.
            region_ids: name the region_ids or country names 
            year_range (list): list containting start and end year. 
                    e.g. [1980, 2017]
            reference_year: impacts will be scaled to this year
            impact_data_source: default 'emdat', others maybe possible
    Optional Parameters:
            yearly_impact (boolean): if set True, impact is returned per year, 
                not per event
    Returns:
            df_out: DataFrame with recorded impact written to rows for each year
                or event.
    """
    if impact_data_source == 'emdat':
        if yearly_impact:
            em_data = emdat_impact_yearlysum(region_ids, hazard_type,
                                             emdat_file_csv=source_file, year_range=year_range,
                                             reference_year=reference_year)
        else:
            raise ValueError ('init_impact_data not yet implemented for yearly_impact = False.')
            em_data = emdat_impact_event()
    else:
        raise ValueError('init_impact_data not yet implemented for other impact_data_sources than emdat.')
    return em_data
コード例 #3
0
    def test_emdat_damage_yearlysum(self):
        """test emdat_impact_yearlysum yearly impact data extraction with scaling"""
        df = im_d.emdat_impact_yearlysum(EMDAT_TEST_CSV, countries=['Bangladesh', 'USA'],
                                         hazard='Flood', year_range=(2015, 2017),
                                         reference_year=2000)

        self.assertEqual(36, df.size)
        self.assertAlmostEqual(df.impact.max(), 15150000000.0)
        self.assertEqual(df.impact_scaled.min(), 10943000.0)
        self.assertEqual(df["year"][5], 2017)
        self.assertEqual(df["reference_year"].max(), 2000)
        self.assertIn('USA', list(df['ISO']))
        self.assertIn(50, list(df['region_id']))
コード例 #4
0
    def test_emdat_affected_yearlysum(self):
        """test emdat_impact_yearlysum yearly impact data extraction"""
        df = im_d.emdat_impact_yearlysum(EMDAT_TEST_CSV, countries=['Bangladesh', 'USA'],
                                         hazard='Flood', year_range=(2015, 2017),
                                         reference_year=None, imp_str="Total Affected")

        self.assertEqual(36, df.size)
        self.assertEqual(df["impact"][1], 91000)
        self.assertEqual(df.impact.sum(), 11517946)
        self.assertEqual(df["year"][5], 2017)

        self.assertIn('USA', list(df['ISO']))
        self.assertIn('BGD', list(df['ISO']))
コード例 #5
0
    def test_emdat_impact_yearlysum(self):
        """test emdat_impact_yearlysum yearly impact data extraction"""
        df = im_d.emdat_impact_yearlysum(['Bangladesh', 'USA'], 'Flood', \
                                             EMDAT_TEST_CSV, [2015, 2017], \
                                             imp_str = 'Total affected')
        self.assertEqual(36, df.size)
        self.assertEqual(df["impact"][1], 1900000)
        self.assertEqual(df.impact.sum(), 11517946)
        self.assertEqual(df["year"][5], 2017)

        self.assertIn('USA', list(df['ISO3']))
        self.assertIn('BGD', list(df['ISO3']))
        self.assertEqual(0, df['reference_year'].max())
コード例 #6
0
    def test_emdat_impact_yearlysum(self):
        """test emdat_impact_yearlysum yearly impact data extraction"""
        emdat_file_csv = os.path.join(DATA_FOLDER, \
                                    'emdat_testdata_BGD_USA_1970-2017.csv')
        df = im_d.emdat_impact_yearlysum(['Bangladesh', 'USA'], 'Flood', \
                                             emdat_file_csv, [2015, 2017], \
                                             imp_str = 'Total affected')
        self.assertEqual(36, df.size)
        self.assertEqual(df["impact"][1], 1900000)
        self.assertEqual(df.impact.sum(), 11517946)
        self.assertEqual(df["year"][5], 2017)

        self.assertIn('USA', list(df['ISO3']))
        self.assertIn('BGD', list(df['ISO3']))
        self.assertEqual(0, df['reference_year'].max())