def test_centroids_pass(self):
     """ Test _centroids_creation """
     bf = BushFire()
     firms = bf._clean_firms_csv(TEST_FIRMS)
     centroids = bf._centroids_creation(firms, 0.375 / ONE_LAT_KM, 1 / 2)
     self.assertEqual(centroids.meta['width'], 144)
     self.assertEqual(centroids.meta['height'], 138)
     self.assertEqual(centroids.meta['crs']['init'], 'epsg:4326')
     self.assertAlmostEqual(centroids.meta['transform'][0],
                            0.006749460043196544)
     self.assertAlmostEqual(centroids.meta['transform'][1], 0.0)
     self.assertTrue(
         centroids.meta['transform'][2] <= firms.longitude.min())
     self.assertAlmostEqual(centroids.meta['transform'][3], 0.0)
     self.assertAlmostEqual(centroids.meta['transform'][4],
                            -centroids.meta['transform'][0])
     self.assertTrue(centroids.meta['transform'][5] >= firms.latitude.max())
     self.assertTrue(firms.latitude.max() <= centroids.total_bounds[3])
     self.assertTrue(firms.latitude.min() >= centroids.total_bounds[1])
     self.assertTrue(firms.longitude.max() <= centroids.total_bounds[2])
     self.assertTrue(firms.longitude.min() >= centroids.total_bounds[0])
     self.assertTrue(centroids.lat.size)
     self.assertTrue(centroids.area_pixel.size)
     self.assertTrue(centroids.on_land.size)
    def test_hist_event_one_pass(self):
        bf = BushFire()
        firms = {
            'latitude': [
                -38.104, -38.104, -38.104, -38.104, -38.104, -38.093, -38.095,
                -37.433, -37.421, -37.423, -37.45, -38.104, -38.104, -38.104,
                -38.095, -37.45, -38.045, -38.047, -38.036, -37.983, -37.978,
                -37.979, -37.981, -37.45, -37.431, -37.421, -37.423, -38.104
            ],
            'longitude': [
                146.388, 146.388, 146.388, 146.388, 146.388, 146.397, 146.386,
                142.43, 142.442, 142.428, 145.361, 146.388, 146.388, 146.388,
                146.397, 145.361, 146.416, 146.404, 146.413, 146.33, 146.311,
                146.299, 146.288, 145.361, 142.445, 142.442, 142.428, 146.388
            ],
            'brightness': [
                400, 10, 316.5, 150, 500, 312.6, 312.7, 324.4, 373.6, 359.6,
                312.9, 100, 400, 500, 300, 250, 100, 150, 300, 400, 250, 300,
                332, 450, 200, 150, 400, 100
            ],
            'acq_date': [
                '2008-03-08', '2008-03-08', '2006-01-24', '2006-01-24',
                '2006-01-24', '2006-01-24', '2006-01-24', '2006-01-24',
                '2006-01-24', '2006-01-24', '2006-01-24', '2006-01-25',
                '2006-01-25', '2006-01-28', '2006-01-28', '2006-01-30',
                '2006-03-06', '2006-03-06', '2006-03-06', '2006-03-06',
                '2007-01-24', '2007-01-24', '2007-01-24', '2007-01-24',
                '2007-01-24', '2008-03-08', '2008-03-08', '2008-03-08'
            ]
        }

        firms, description = TestReaderDF._read_firms_synth(firms)

        self.assertEqual(firms['latitude'][0], -38.104)
        self.assertEqual(firms['longitude'][0], 146.388)
        self.assertEqual(firms['latitude'].iloc[-1], -38.104)
        self.assertEqual(firms['longitude'].iloc[-1], 146.388)
        self.assertFalse(firms['datenum'][0] == firms['datenum'][9])

        firms = bf._firms_cons_days(firms)

        self.assertEqual(firms['cons_id'][0], 0)
        self.assertEqual(firms['cons_id'][7], 0)
        self.assertEqual(firms['cons_id'][8], 0)
        self.assertEqual(firms['cons_id'][9], 0)
        self.assertEqual(firms['cons_id'][10], 0)
        self.assertEqual(firms['cons_id'][11], 1)
        self.assertEqual(firms['cons_id'][13], 1)
        self.assertEqual(firms['cons_id'][15], 2)
        self.assertEqual(firms['cons_id'][21], 3)
        self.assertEqual(firms['cons_id'][26], 4)

        centroids, res_data = bf._centroids_creation(firms, 1)

        firms = bf._firms_clustering(firms, res_data)

        self.assertEqual(max((firms['clus_id'][:10]).values), 2)
        self.assertEqual(max((firms['clus_id'][11:13]).values), 0)

        firms = bf._firms_event(firms)

        self.assertEqual(max((firms['event_id'][:10]).values), 3)
        self.assertEqual(firms['event_id'][11], 4)
        self.assertEqual(firms['event_id'][12], 4)
        self.assertEqual(firms['event_id'][13], 5)

        # add brightness matrix
        bf._calc_brightness(firms, centroids)

        self.assertEqual(bf.intensity[0, 1172], 500)
        self.assertEqual(bf.intensity[0, 4714], 312.7)
        self.assertEqual(bf.intensity[0, 4717], 312.6)
        self.assertEqual(bf.intensity[1, 227620], 312.9)
        self.assertEqual(bf.intensity[2, 232658], 324.4)
        self.assertEqual(bf.intensity[2, 236200], 359.6)
        self.assertEqual(bf.intensity[2, 237385], 373.6)
        self.assertEqual(bf.intensity[3, 1172], 500)
        self.assertEqual(bf.intensity[3, 4717], 300)
        self.assertEqual(bf.intensity[4, 227620], 250)

        # add probabilistic event
        ev_id = 1
        bf._random_bushfire_one_event(ev_id, 1)
Beispiel #3
0
    def test_random_brightness_one_pass(self):
        bf = BushFire()
        firms, description = bf._read_firms_csv(TEST_FIRMS)

        firms = bf._clean_firms_csv(firms)

        self.assertEqual(firms['latitude'][0], 36.46245)
        self.assertEqual(firms['longitude'][0], -121.8989)
        self.assertEqual(firms['latitude'].iloc[-1], 36.17266)
        self.assertEqual(firms['longitude'].iloc[-1], -121.61211000000002)

        centroids, res_data = bf._centroids_creation(firms, 1)
        firms = bf._firms_cons_days(firms)

        self.assertEqual(firms['cons_id'][9320], 0)
        self.assertEqual(firms['cons_id'][9321], 1)

        firms = bf._firms_clustering(firms, res_data)

        self.assertEqual(firms['clus_id'][1621], 0)
        self.assertEqual(firms['clus_id'][1622], 1)
        self.assertEqual(firms['clus_id'][1623], 2)

        firms = bf._firms_event(firms)

        self.assertEqual(firms['event_id'][1621], 1)
        self.assertEqual(firms['event_id'][1622], 2)
        self.assertEqual(firms['event_id'][1623], 3)
        self.assertEqual(firms['event_id'][9319], 3)
        self.assertEqual(firms['event_id'][9320], 4)

        bf._calc_brightness(firms, centroids)
        bf.check()

        self.assertEqual(bf.tag.haz_type, 'BF')
        self.assertEqual(bf.tag.description, '')
        self.assertEqual(bf.units, 'K')
        self.assertEqual(bf.centroids.size, 78090)
        self.assertEqual(bf.event_id.size, 5)
        self.assertEqual(bf.event_id[0], 1)
        self.assertEqual(bf.event_name, ['1.0', '2.0', '3.0', '4.0', '5.0'])
        self.assertTrue(np.array_equal(bf.frequency, np.array([1, 1, 1, 1, 1])))
        self.assertTrue(isinstance(bf.intensity, sparse.csr_matrix))
        self.assertTrue(isinstance(bf.fraction, sparse.csr_matrix))
        self.assertEqual(bf.intensity.shape, (5, 78090))
        self.assertEqual(bf.fraction.shape, (5, 78090))

        bf._area_one_year(2016)

        ev_id = 3
        area_hull_one_event = bf._hull_burned_area(ev_id)

        self.assertAlmostEqual(area_hull_one_event, 60421, delta = 500)

        prob_event = bf._random_bushfire_one_event(ev_id, 1)
        prob_event.check()

        self.assertEqual(prob_event.tag.haz_type, 'BF')
        self.assertEqual(prob_event.tag.description, '')
        self.assertEqual(prob_event.units, 'K')
        self.assertEqual(prob_event.centroids.size, 78090)
        self.assertEqual(prob_event.event_id.size, 1)
        self.assertEqual(prob_event.event_id[0], 1)
        self.assertEqual(prob_event.event_name, ['3_gen1'])
        self.assertTrue(np.array_equal(prob_event.frequency, np.array([1])))
        self.assertTrue(isinstance(prob_event.intensity, sparse.csr_matrix))
        self.assertTrue(isinstance(prob_event.fraction, sparse.csr_matrix))
        self.assertEqual(prob_event.intensity.shape, (1, 78090))
        self.assertEqual(prob_event.fraction.shape, (1, 78090))

        self.assertAlmostEqual(prob_event.intensity.nonzero()[0].size, 3928, delta = 10)

        self.assertAlmostEqual(bf.intensity[ev_id - 1].data.mean(),prob_event.intensity[0].data.mean(), delta = 2)
        self.assertAlmostEqual(bf.intensity[ev_id - 1].data.std(), prob_event.intensity[0].data.std(), delta = 2)