コード例 #1
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)
コード例 #2
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)