示例#1
0
    def test_isimip_country_flood(self):
        rf = RiverFlood()
        rf.set_from_nc(dph_path=HAZ_DEMO_FLDDPH, frc_path=HAZ_DEMO_FLDFRC,
                       countries=['DEU'], ISINatIDGrid=True)
        self.assertEqual(rf.date[0], 730303)
        self.assertEqual(rf.event_id[0], 0)
        self.assertEqual(rf.event_name[0], '2000')
        self.assertEqual(rf.orig[0], False)
        self.assertAlmostEqual(rf.frequency[0], 1.)

        self.assertAlmostEqual(np.min(rf.centroids.lat), 47.312247000002785, 4)
        self.assertAlmostEqual(np.max(rf.centroids.lat), 55.0622346, 4)
        self.assertAlmostEqual(np.min(rf.centroids.lon), 5.895702599999964, 4)
        self.assertAlmostEqual(np.max(rf.centroids.lon), 15.020687999996682, 4)
        self.assertAlmostEqual(rf.centroids.lon[1000], 9.145697399999989, 4)
        self.assertAlmostEqual(rf.centroids.lat[1000], 47.89557939999999, 4)

        self.assertEqual(rf.intensity.shape, (1, 26878))
        self.assertAlmostEqual(np.min(rf.intensity), 0.0, 4)
        self.assertAlmostEqual(np.max(rf.intensity), 10.547529220581055, 4)
        self.assertEqual(np.argmin(rf.intensity), 0, 4)
        self.assertEqual(np.argmax(rf.intensity), 938, 4)

        self.assertEqual(rf.fraction.shape, (1, 26878))
        self.assertAlmostEqual(np.min(rf.fraction), 0.0, 4)
        self.assertAlmostEqual(np.max(rf.fraction), 0.9968000054359436, 4)
        self.assertEqual(np.argmin(rf.fraction), 0, 4)
        self.assertEqual(np.argmax(rf.fraction), 1052, 4)
        return
示例#2
0
    def test_isimip_reg_flood(self):
        rf = RiverFlood()
        rf.set_from_nc(dph_path=HAZ_DEMO_FLDDPH, frc_path=HAZ_DEMO_FLDFRC,
                       reg=['SWA'], ISINatIDGrid=True)

        self.assertEqual(rf.date[0], 730303)

        self.assertEqual(rf.event_id[0], 0)
        self.assertEqual(rf.event_name[0], '2000')
        self.assertEqual(rf.orig[0], False)
        self.assertAlmostEqual(rf.frequency[0], 1.)

        self.assertAlmostEqual(np.min(rf.centroids.lat), -0.687676199985944, 4)
        self.assertAlmostEqual(np.max(rf.centroids.lat), 38.43726119999998, 4)
        self.assertAlmostEqual(np.min(rf.centroids.lon), 60.52061519999998, 4)
        self.assertAlmostEqual(np.max(rf.centroids.lon), 101.14555019998537, 4)
        self.assertAlmostEqual(rf.centroids.lon[10000], 98.27055479999999, 4)
        self.assertAlmostEqual(rf.centroids.lat[10000], 11.478970999999987, 4)

        self.assertEqual(rf.intensity.shape, (1, 301181))
        self.assertAlmostEqual(np.min(rf.intensity), 0.0, 4)
        self.assertAlmostEqual(np.max(rf.intensity), 16.69780921936035, 4)
        self.assertEqual(np.argmin(rf.intensity), 0, 4)
        self.assertEqual(np.argmax(rf.intensity), 40613, 4)

        self.assertEqual(rf.fraction.shape, (1, 301181))
        self.assertAlmostEqual(np.min(rf.fraction), 0.0, 4)
        self.assertAlmostEqual(np.max(rf.fraction), 1.0, 4)
        self.assertEqual(np.argmin(rf.fraction), 0, 4)
        self.assertEqual(np.argmax(rf.fraction), 126135, 4)

        return
示例#3
0
    def test_meta_centroids_flood(self):
        min_lat, max_lat, min_lon, max_lon = 45.7, 47.8, 7.5, 10.5
        cent = Centroids()
        cent.set_raster_from_pnt_bounds((min_lon, min_lat, max_lon, max_lat),
                                        res=0.05)
        rf_rast = RiverFlood()
        rf_rast.set_from_nc(dph_path=HAZ_DEMO_FLDDPH, frc_path=HAZ_DEMO_FLDFRC,
                            centroids=cent)
        self.assertEqual(rf_rast.centroids.shape, (43, 61))
        self.assertAlmostEqual(np.min(rf_rast.centroids.lat),
                               45.70000000000012, 4)
        self.assertAlmostEqual(np.max(rf_rast.centroids.lat), 47.8, 4)
        self.assertAlmostEqual(np.min(rf_rast.centroids.lon), 7.5, 4)
        self.assertAlmostEqual(np.max(rf_rast.centroids.lon),
                               10.49999999999999, 4)
        self.assertAlmostEqual(rf_rast.centroids.lon[90],
                               8.949999999999996, 4)
        self.assertAlmostEqual(rf_rast.centroids.lat[90], 47.75, 4)

        self.assertEqual(rf_rast.intensity.shape, (1, 2623))
        self.assertAlmostEqual(np.min(rf_rast.intensity), 0.0, 4)
        self.assertAlmostEqual(np.max(rf_rast.intensity), 5.8037286, 4)
        self.assertEqual(np.argmin(rf_rast.intensity), 0, 4)
        self.assertEqual(np.argmax(rf_rast.intensity), 55, 4)

        self.assertEqual(rf_rast.fraction.shape, (1, 2623))
        self.assertAlmostEqual(np.min(rf_rast.fraction), 0.0, 4)
        self.assertAlmostEqual(np.max(rf_rast.fraction), 0.4896, 4)
        self.assertEqual(np.argmin(rf_rast.fraction), 0, 4)
        self.assertEqual(np.argmax(rf_rast.fraction), 360, 4)
示例#4
0
    def test_wrong_iso3_fail(self):

        emptyFlood = RiverFlood()
        with self.assertRaises(KeyError):
            RiverFlood._select_exact_area(['OYY'])
        with self.assertRaises(AttributeError):
            emptyFlood.set_from_nc(years=[2600], dph_path=HAZ_DEMO_FLDDPH,
                                   frc_path=HAZ_DEMO_FLDFRC)
        with self.assertRaises(KeyError):
            emptyFlood.set_from_nc(reg=['OYY'], dph_path=HAZ_DEMO_FLDDPH,
                                   frc_path=HAZ_DEMO_FLDFRC, ISINatIDGrid=True)
示例#5
0
    def test_flooded_area(self):

        testRFset = RiverFlood()
        testRFset.set_from_nc(countries=['AFG'], dph_path=HAZ_DEMO_FLDDPH,
                              frc_path=HAZ_DEMO_FLDFRC, ISINatIDGrid=True)
        years = [2000, 2001, 2002]
        manipulated_dates = [730303, 730669, 731034]
        testRFaddset = []
        for i in range(len(years)):
            testRFaddset = RiverFlood()
            testRFaddset.set_from_nc(countries=['AFG'],
                                     dph_path=HAZ_DEMO_FLDDPH,
                                     frc_path=HAZ_DEMO_FLDFRC,
                                     ISINatIDGrid=True)
            testRFaddset.date = np.array([manipulated_dates[i]])
            if i == 0:
                testRFaddset.event_name = ['2000_2']
            else:
                testRFaddset.event_name = [str(years[i])]
            testRFset.append(testRFaddset)

        testRFset.set_flooded_area(save_centr=True)
        self.assertEqual(testRFset.units, 'm')

        self.assertEqual(testRFset.fla_event.shape[0], 4)
        self.assertEqual(testRFset.fla_annual.shape[0], 3)
        self.assertAlmostEqual(np.max(testRFset.fla_ev_centr[0]),
                               17200498.22927546, 3)
        self.assertEqual(np.argmax(testRFset.fla_ev_centr[0]),
                         32610)
        self.assertAlmostEqual(np.max(testRFset.fla_ev_centr[2]),
                               17200498.22927546, 3)
        self.assertEqual(np.argmax(testRFset.fla_ev_centr[2]),
                         32610)

        self.assertAlmostEqual(np.max(testRFset.fla_ann_centr[0]),
                               34400996.45855092, 3)
        self.assertEqual(np.argmax(testRFset.fla_ann_centr[0]),
                         32610)
        self.assertAlmostEqual(np.max(testRFset.fla_ann_centr[2]),
                               17200498.22927546, 3)
        self.assertEqual(np.argmax(testRFset.fla_ann_centr[2]),
                         32610)

        self.assertAlmostEqual(testRFset.fla_event[0],
                               6244242013.5826435, 3)
        self.assertAlmostEqual(testRFset.fla_annual[0],
                               12488484027.165287, 3)
        self.assertAlmostEqual(testRFset.fla_ann_av,
                               8325656018.110191, 3)
        self.assertAlmostEqual(testRFset.fla_ev_av,
                               6244242013.5826435, 3)
    def test_full_impact(self):
        """test full flood impact"""
        testRF = RiverFlood()
        testRF.set_from_nc(dph_path=HAZ_DEMO_FLDDPH, frc_path=HAZ_DEMO_FLDFRC,
                           countries=['CHE'])

        gdpa = GDP2Asset()
        gdpa.set_countries(countries=['CHE'], ref_year=2000, path=DEMO_GDP2ASSET)

        if_set = flood_imp_func_set()
        imp = Impact()
        imp.calc(gdpa, if_set, testRF)

        self.assertAlmostEqual(imp.at_event[0], 226839.72426476143)
        self.assertAlmostEqual(gdpa.gdf['if_RF'].iloc[0], 3.0)
示例#7
0
    def test_flooded_area(self):

        testRFset = RiverFlood()
        testRFset.set_from_nc(countries=['DEU', 'CHE'],
                              dph_path=HAZ_DEMO_FLDDPH,
                              frc_path=HAZ_DEMO_FLDFRC,
                              ISINatIDGrid=True)
        years = [2000, 2001, 2002]
        manipulated_dates = [730303, 730669, 731034]
        testRFaddset = []
        for i in range(len(years)):
            testRFaddset = RiverFlood()
            testRFaddset.set_from_nc(countries=['DEU', 'CHE'],
                                     dph_path=HAZ_DEMO_FLDDPH,
                                     frc_path=HAZ_DEMO_FLDFRC,
                                     ISINatIDGrid=True)
            testRFaddset.date = np.array([manipulated_dates[i]])
            if i == 0:
                testRFaddset.event_name = ['2000_2']
            else:
                testRFaddset.event_name = [str(years[i])]
            testRFset.append(testRFaddset)

        testRFset.set_flooded_area(save_centr=True)
        self.assertEqual(testRFset.units, 'm')

        self.assertEqual(testRFset.fla_event.shape[0], 4)
        self.assertEqual(testRFset.fla_annual.shape[0], 3)
        self.assertAlmostEqual(np.max(testRFset.fla_ev_centr[0]),
                               14388131.402572632, 3)
        self.assertEqual(np.argmax(testRFset.fla_ev_centr[0]), 3812)
        self.assertAlmostEqual(np.max(testRFset.fla_ev_centr[2]),
                               14388131.402572632, 3)
        self.assertEqual(np.argmax(testRFset.fla_ev_centr[2]), 3812)

        self.assertAlmostEqual(np.max(testRFset.fla_ann_centr[0]),
                               28776262.805145264, 3)
        self.assertEqual(np.argmax(testRFset.fla_ann_centr[0]), 3812)
        self.assertAlmostEqual(np.max(testRFset.fla_ann_centr[2]),
                               14388131.402572632, 3)
        self.assertEqual(np.argmax(testRFset.fla_ann_centr[2]), 3812)

        self.assertAlmostEqual(testRFset.fla_event[0], 2463979258.8144045, 3)
        self.assertAlmostEqual(testRFset.fla_annual[0], 4927958517.628809, 3)
        self.assertAlmostEqual(testRFset.fla_ann_av, 3285305678.419206, 3)
        self.assertAlmostEqual(testRFset.fla_ev_av, 2463979258.8144045, 3)
示例#8
0
    def test_NATearth_country_flood(self):
        rf = RiverFlood()
        rf.set_from_nc(dph_path=HAZ_DEMO_FLDDPH, frc_path=HAZ_DEMO_FLDFRC,
                       countries=['DEU'])

        self.assertEqual(rf.date[0], 730303)
        self.assertEqual(rf.event_id[0], 0)
        self.assertEqual(rf.event_name[0], '2000')
        self.assertEqual(rf.orig[0], False)
        self.assertAlmostEqual(rf.frequency[0], 1.)

        self.assertAlmostEqual(np.min(rf.intensity), 0.0, 4)
        self.assertAlmostEqual(np.max(rf.intensity), 10.547529, 4)
        self.assertEqual(np.argmin(rf.intensity), 0, 4)
        self.assertEqual(np.argmax(rf.intensity), 38380, 4)

        self.assertAlmostEqual(np.min(rf.fraction), 0.0, 4)
        self.assertAlmostEqual(np.max(rf.fraction), 0.9968000054359436, 4)
        self.assertEqual(np.argmin(rf.fraction), 0, 4)
        self.assertEqual(np.argmax(rf.fraction), 38143, 4)
示例#9
0
    def test_global_flood(self):
        rf = RiverFlood()
        rf.set_from_nc(dph_path=HAZ_DEMO_FLDDPH, frc_path=HAZ_DEMO_FLDFRC)

        self.assertEqual(rf.date[0], 730303)
        self.assertEqual(rf.event_id[0], 0)
        self.assertEqual(rf.event_name[0], '2000')
        self.assertEqual(rf.orig[0], False)
        self.assertAlmostEqual(rf.frequency[0], 1.)

        self.assertEqual(rf.intensity.shape, (1, 37324800))
        self.assertAlmostEqual(np.min(rf.intensity), 0.0, 4)
        self.assertAlmostEqual(np.max(rf.intensity), 19.276295, 4)
        self.assertEqual(np.argmin(rf.intensity), 0, 4)
        self.assertEqual(np.argmax(rf.intensity), 26190437, 4)

        self.assertEqual(rf.fraction.shape, (1, 37324800))
        self.assertAlmostEqual(np.min(rf.fraction), 0.0, 4)
        self.assertAlmostEqual(np.max(rf.fraction), 1.0, 4)
        self.assertEqual(np.argmin(rf.fraction), 0, 4)
        self.assertEqual(np.argmax(rf.fraction), 3341440, 4)
示例#10
0
    def test_centroids_flood(self):

        # this is going to go through the meta part
        rand_centroids = Centroids()
        lat = np.arange(47, 56, 0.2)
        lon = np.arange(5, 15, 0.2)
        lon, lat = np.meshgrid(lon, lat)
        rand_centroids.set_lat_lon(lat.flatten(), lon.flatten())
        rf = RiverFlood()
        rf.set_from_nc(dph_path=HAZ_DEMO_FLDDPH,
                       frc_path=HAZ_DEMO_FLDFRC,
                       centroids=rand_centroids,
                       ISINatIDGrid=False)

        self.assertEqual(rf.date[0], 730303)
        self.assertEqual(rf.event_id[0], 0)
        self.assertEqual(rf.event_name[0], '2000')
        self.assertEqual(rf.orig[0], False)
        self.assertAlmostEqual(rf.frequency[0], 1.)

        self.assertEqual(rf.centroids.shape, (45, 50))
        self.assertAlmostEqual(np.min(rf.centroids.lat), 47.0, 4)
        self.assertAlmostEqual(np.max(rf.centroids.lat), 55.8, 4)
        self.assertAlmostEqual(np.min(rf.centroids.lon), 5.0, 4)
        self.assertAlmostEqual(np.max(rf.centroids.lon), 14.8, 4)
        self.assertAlmostEqual(rf.centroids.lon[90], 13.0, 4)
        self.assertAlmostEqual(rf.centroids.lat[90], 47.2, 4)

        self.assertEqual(rf.intensity.shape, (1, 2250))
        self.assertAlmostEqual(np.min(rf.intensity), 0.0, 4)
        self.assertAlmostEqual(np.max(rf.intensity), 8.921593, 4)
        self.assertEqual(np.argmin(rf.intensity), 0, 4)
        self.assertEqual(np.argmax(rf.intensity), 191, 4)

        self.assertEqual(rf.fraction.shape, (1, 2250))
        self.assertAlmostEqual(np.min(rf.fraction), 0.0, 4)
        self.assertAlmostEqual(np.max(rf.fraction), 0.92, 4)
        self.assertEqual(np.argmin(rf.fraction), 0, 4)
        self.assertEqual(np.argmax(rf.fraction), 1438, 4)
示例#11
0
    def test_NATearth_reg_flood(self):
        rf = RiverFlood()
        rf.set_from_nc(dph_path=HAZ_DEMO_FLDDPH, frc_path=HAZ_DEMO_FLDFRC,
                       reg=['SWA'])

        self.assertEqual(rf.date[0], 730303)
        self.assertEqual(rf.event_id[0], 0)
        self.assertEqual(rf.event_name[0], '2000')
        self.assertEqual(rf.orig[0], False)
        self.assertAlmostEqual(rf.frequency[0], 1.00, 1)

        self.assertEqual(rf.centroids.shape, (941, 978))

        self.assertEqual(rf.intensity.shape, (1, 920298))
        self.assertAlmostEqual(np.min(rf.intensity), 0.0, 4)
        self.assertAlmostEqual(np.max(rf.intensity), 16.69781, 4)
        self.assertEqual(np.argmin(rf.intensity), 0, 4)
        self.assertEqual(np.argmax(rf.intensity), 480702, 4)

        self.assertEqual(rf.fraction.shape, (1, 920298))
        self.assertAlmostEqual(np.min(rf.fraction), 0.0, 4)
        self.assertAlmostEqual(np.max(rf.fraction), 1.0, 4)
        self.assertEqual(np.argmin(rf.fraction), 0, 4)
        self.assertEqual(np.argmax(rf.fraction), 31487, 4)
示例#12
0
        frc_path= flood_dir + '{}/{}/area_150arcsec_annual_max_protection-flopros-{}.nc'\
            .format(args.CL_model, args.RF_model, PROT_STD[pro_std])

        if not os.path.exists(dph_path):
            print('{} path not found'.format(dph_path))
            break
        if not os.path.exists(frc_path):
            print('{} path not found'.format(frc_path))
            break

        # set flood hazard
        rf = RiverFlood()

        rf.set_from_nc(dph_path=dph_path,
                       frc_path=frc_path,
                       countries=country,
                       years=years,
                       ISINatIDGrid=True)
        # set flood hazard for subregions
        rf_pos = copy.copy(rf)
        rf_pos.exclude_trends(dis_path, 'pos')

        rf_neg = copy.copy(rf)
        rf_neg.exclude_trends(dis_path, 'neg')

        rf.set_flooded_area(save_centr=True)
        rf.set_flood_volume()
        rf_pos.set_flooded_area(save_centr=True)
        rf_neg.set_flooded_area(save_centr=True)
        rf_pos.set_flood_volume()
        rf_neg.set_flood_volume()
示例#13
0
natcat=pd.read_excel('/home/insauer/projects/Attribution/Floods/Paper_NC_Review_Data/Input_PPP_conversion/1980-2016_Masterdatei_NatCat_worldwide_no-pw_2005conversions_PPP.xlsx', index_col=0)

trend_path = '/home/insauer/projects/RiverDischarge/Data/basin_trends_geo.nc'

#trend_path = '/home/insauer/projects/Attribution/Floods/Paper_NC_20_06_Data/Input_Damage_Assessment/TrendsMedianDischarge_MK.nc'

natcat_assigned = pd.DataFrame(columns = ['Country', 'Year', 'pos_risk', 'neg_risk', 'unclear'])

for iso in isos:
    print(iso)
    if iso =='GIB' or iso == 'MCO':
        continue
    
    dis_pos = RiverFlood()
    dis_pos.set_from_nc(dph_path=dph_path, frc_path=frc_path, countries=[iso], ISINatIDGrid=True)
    dis_neg = copy.copy(dis_pos)
    dis_pos.get_dis_mask(trend_path, 'pos')
    dis_neg.get_dis_mask(trend_path, 'neg')

    # dis_pos = FloodTrend()
    # dis_pos.set_from_nc(dph_path=trend_path, countries=[iso])
    # dis_neg = copy.copy(dis_pos)
    # dis_pos.get_dis_mask(dis = 'pos')
    # dis_neg.get_dis_mask(dis = 'neg')
    
    natcat_cnt_all = natcat[(natcat['Country ISO3']==iso) &
                        (natcat['Subevent']=='gf:General flood')]
    
    years = list(set(natcat_cnt_all['Year']))