def test_flooded_area(self):
        dph_path = HAZ_DEMO_FLDDPH
        frc_path = HAZ_DEMO_FLDFRC

        testRFset = RiverFlood()
        testRFset.set_from_nc(countries=['AFG'],
                              dph_path=dph_path,
                              frc_path=frc_path)
        years = [2000, 2001, 2002]
        manipulated_dates = [730303, 730669, 731034]
        for i in range(len(years)):
            testRFaddset = RiverFlood()
            testRFaddset.set_from_nc(countries=['AFG'])
            testRFaddset.date = [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()
        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)
        self.assertEqual(np.argmax(testRFset.fla_ev_centr[0]), 32610)
        self.assertAlmostEqual(np.max(testRFset.fla_ev_centr[2]),
                               17200498.22927546)
        self.assertEqual(np.argmax(testRFset.fla_ev_centr[2]), 32610)

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

        self.assertAlmostEqual(testRFset.fla_event[0], 6244242013.5826435, 4)
        self.assertAlmostEqual(testRFset.fla_annual[0], 12488484027.165287, 3)
        self.assertAlmostEqual(testRFset.fla_ann_av, 8325656018.110191, 4)
        self.assertAlmostEqual(testRFset.fla_ev_av, 6244242013.5826435, 4)
Exemple #2
0
    def test_flooded_area(self):
        testRFArea = RiverFlood()
        dph_path = HAZ_DEMO_FLDDPH
        frc_path = HAZ_DEMO_FLDFRC
        testRFArea.set_from_nc(countries=['AUT'], dph_path=dph_path,
                               frc_path=frc_path)
        self.assertEqual(testRFArea.centroids.lat.shape[0], 5782)
        self.assertAlmostEqual(np.max(testRFArea.centroids.lon),
                               17.104017999999968)
        self.assertAlmostEqual(np.min(testRFArea.centroids.lon),
                               9.562363399999981)
        self.assertAlmostEqual(np.max(testRFArea.centroids.lat),
                               48.978911)
        self.assertAlmostEqual(np.min(testRFArea.centroids.lat),
                               46.39558179999999)
        self.assertEqual(testRFArea.orig[0], 1)
        self.assertAlmostEqual(np.max(testRFArea.intensity),
                               9.613386154174805)
        self.assertEqual(np.argmax(testRFArea.intensity), 2786)
        self.assertAlmostEqual(np.max(testRFArea.fraction),
                               0.5103999972343445)
        self.assertEqual(np.argmax(testRFArea.fraction), 3391)

        testRFArea.set_flooded_area()
        self.assertAlmostEqual(np.max(testRFArea.fla_ev_centr),
                               7396511.421906647)
        self.assertEqual(np.argmax(testRFArea.fla_ev_centr), 3391)
        self.assertAlmostEqual(np.max(testRFArea.fla_ann_centr),
                               7396511.421906647)
        self.assertEqual(np.argmax(testRFArea.fla_ann_centr),
                         3391)

        self.assertAlmostEqual(testRFArea.fla_event[0],
                               229956891.5531019, 5)
        self.assertAlmostEqual(testRFArea.fla_annual[0],
                               229956891.5531019, 5)

        testRFset = RiverFlood()
        testRFset.set_from_nc(countries=['AFG'])
        years = [2000, 2001, 2002]
        manipulated_dates = [730303, 730669, 731034]
        for i in range(len(years)):
            testRFaddset = RiverFlood()
            testRFaddset.set_from_nc(countries=['AFG'])
            testRFaddset.date = [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()

        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)
        self.assertEqual(np.argmax(testRFset.fla_ev_centr[0]),
                         32610)
        self.assertAlmostEqual(np.max(testRFset.fla_ev_centr[2]),
                               17200498.22927546)
        self.assertEqual(np.argmax(testRFset.fla_ev_centr[2]),
                         32610)

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

        self.assertAlmostEqual(testRFset.fla_event[0],
                               6244242013.5826435, 4)
        self.assertAlmostEqual(testRFset.fla_annual[0],
                               12488484027.165287, 3)
        self.assertAlmostEqual(testRFset.fla_ann_av,
                               8325656018.110191, 4)
        self.assertAlmostEqual(testRFset.fla_ev_av,
                               6244242013.5826435, 4)