def test_get_raster_meta(self):
     empty_LS = Landslide()
     pixel_width, pixel_height = empty_LS._get_raster_meta(
         path_sourcefile=os.path.join(LS_FILE_DIR,
                                      'ls_pr_NGI_UNEP/ls_pr.tif'),
         window_array=[865, 840, 120, 120])
     self.assertTrue(math.isclose(pixel_width, -0.00833, rel_tol=1e-03))
     self.assertTrue(math.isclose(pixel_height, 0.00833, rel_tol=1e-03))
 def test_set_ls_model_hist(self):
     """ Test the function set_LS_model for model 0 (historic hazard set)"""
     LS_hist = Landslide()
     LS_hist.set_ls_model_hist(bbox=[48, 10, 45, 7], \
                  path_sourcefile=os.path.join(DATA_DIR_TEST, 'nasa_global_landslide_catalog_point.shp'), check_plots=0)
     self.assertEqual(LS_hist.size, 49)
     self.assertEqual(LS_hist.tag.haz_type, 'LS')
     self.assertEqual(min(LS_hist.intensity.data), 1)
     self.assertEqual(max(LS_hist.intensity.data), 1)
 def test_get_window_from_coords(self):
     empty_LS = Landslide()
     window_array = empty_LS._get_window_from_coords(
         path_sourcefile=os.path.join(LS_FILE_DIR,
                                      'ls_pr_NGI_UNEP/ls_pr.tif'),
         bbox=[47, 8, 46, 7])
     self.assertEqual(window_array[0], 22440)
     self.assertEqual(window_array[1], 5159)
     self.assertEqual(window_array[2], 120)
     self.assertEqual(window_array[3], 120)
 def test_get_hist_events(self):
     empty_LS = Landslide()
     bbox = [48, 23, 40, 20]
     COOLR_path = os.path.join(DATA_DIR_TEST,
                               'nasa_global_landslide_catalog_point.shp')
     LS_catalogue_part = empty_LS._get_hist_events(bbox, COOLR_path)
     self.assertTrue(max(LS_catalogue_part.latitude) <= bbox[0])
     self.assertTrue(min(LS_catalogue_part.latitude) >= bbox[2])
     self.assertTrue(max(LS_catalogue_part.longitude) <= bbox[1])
     self.assertTrue(min(LS_catalogue_part.longitude) >= bbox[3])
    def test_set_ls_model_prob(self):
        """ Test the function set_LS_model for model versio UNEP_NGI, with and without neighbours"""
        LS_prob = Landslide()
        LS_prob.set_ls_model_prob(ls_model="UNEP_NGI", n_years=500, bbox=[48, 10, 45, 7], \
                     incl_neighbour=False, check_plots=0)
        self.assertEqual(LS_prob.tag.haz_type, 'LS')
        self.assertEqual(LS_prob.intensity_prob.shape, (1, 129600))
        self.assertEqual(max(LS_prob.intensity.data), 1)
        self.assertEqual(min(LS_prob.intensity.data), 0)
        self.assertEqual(LS_prob.intensity.shape, (1, 129600))
        self.assertAlmostEqual(max(LS_prob.intensity_prob.data),
                               8.999999999e-05)
        self.assertEqual(min(LS_prob.intensity_prob.data), 5e-07)
        self.assertEqual(LS_prob.centroids.size, 129600)

        LS_prob_nb = Landslide()
        LS_prob_nb.set_ls_model_prob(ls_model="UNEP_NGI", n_years=500, bbox=[48, 10, 45, 7], \
                     incl_neighbour=True, check_plots=0)
        self.assertEqual(LS_prob_nb.tag.haz_type, 'LS')
        self.assertEqual(LS_prob_nb.intensity_prob.shape, (1, 129600))
        self.assertEqual(max(LS_prob_nb.intensity.data), 1)
        self.assertEqual(min(LS_prob_nb.intensity.data), 0)
        self.assertEqual(LS_prob_nb.intensity.shape, (1, 129600))
        self.assertAlmostEqual(max(LS_prob_nb.intensity_prob.data),
                               8.999999999e-05)
        self.assertEqual(min(LS_prob_nb.intensity_prob.data), 5e-07)
        self.assertEqual(LS_prob_nb.centroids.size, 129600)

        self.assertTrue(
            sum(LS_prob.intensity.data) < sum(LS_prob_nb.intensity.data))
 def test_intensity_prob_to_binom(self):
     empty_LS = Landslide()
     window_array = empty_LS._get_window_from_coords(
         path_sourcefile=os.path.join(
             DATA_DIR_TEST, 'test_global_landslide_nowcast_20190501.tif'),
         bbox=[47, 23, 46, 22])
     empty_LS.set_raster([
         os.path.join(DATA_DIR_TEST,
                      'test_global_landslide_nowcast_20190501.tif')
     ],
                         window=Window(window_array[0], window_array[1],
                                       window_array[3], window_array[2]))
     empty_LS._intensity_cat_to_prob(max_prob=0.0001)
     empty_LS._intensity_prob_to_binom(100)
     self.assertTrue(max(empty_LS.intensity_prob.data) == 0.0001)
     self.assertTrue(min(empty_LS.intensity_prob.data) == 0)
     self.assertTrue(max(empty_LS.intensity.data) == 1)
     self.assertTrue(min(empty_LS.intensity.data) == 0)
Example #7
0
    def test_set_ls_hist(self):
        """ Test function set_ls_hist()"""
        LS_hist = Landslide()
        LS_hist.set_ls_hist(bbox=(20, 40, 23, 46), input_gdf=LS_HIST_FILE)
        self.assertEqual(LS_hist.size, 272)
        self.assertEqual(LS_hist.tag.haz_type, 'LS')
        self.assertEqual(np.unique(LS_hist.intensity.data), np.array([1]))
        self.assertEqual(np.unique(LS_hist.fraction.data), np.array([1]))
        self.assertTrue((LS_hist.frequency.data <= 1).all())

        input_gdf = gpd.read_file(LS_HIST_FILE)
        LS_hist = Landslide()
        LS_hist.set_ls_hist(bbox=(20, 40, 23, 46), input_gdf=input_gdf)
        self.assertEqual(LS_hist.size, 272)
        self.assertEqual(LS_hist.tag.haz_type, 'LS')
        self.assertEqual(np.unique(LS_hist.intensity.data), np.array([1]))
        self.assertEqual(np.unique(LS_hist.fraction.data), np.array([1]))
        self.assertTrue((LS_hist.frequency.data <= 1).all())
 def test_intensity_binom_to_range(self):
     empty_LS = Landslide()
     window_array = empty_LS._get_window_from_coords(
         path_sourcefile=os.path.join(
             DATA_DIR_TEST, 'test_global_landslide_nowcast_20190501.tif'),
         bbox=[47, 23, 46, 22])
     empty_LS.set_raster([
         os.path.join(DATA_DIR_TEST,
                      'test_global_landslide_nowcast_20190501.tif')
     ],
                         window=Window(window_array[0], window_array[1],
                                       window_array[3], window_array[2]))
     empty_LS._intensity_cat_to_prob(max_prob=0.0001)
     empty_LS._intensity_prob_to_binom(100)
     empty_LS.check()
     empty_LS.centroids.set_meta_to_lat_lon()
     empty_LS.centroids.set_geometry_points()
     empty_LS._intensity_binom_to_range(max_dist=1000)
     self.assertTrue(
         len(empty_LS.intensity.data[(empty_LS.intensity.data > 0)
                                     & (empty_LS.intensity.data < 1)]) > 0)
Example #9
0
    def test_set_ls_prob(self):
        """ Test the function set_ls_prob()"""
        LS_prob = Landslide()
        n_years = 1000
        LS_prob.set_ls_prob(bbox=(8, 45, 11, 46),
                            path_sourcefile=LS_PROB_FILE,
                            n_years=n_years,
                            dist='binom')

        self.assertEqual(LS_prob.tag.haz_type, 'LS')
        self.assertEqual(LS_prob.intensity.shape, (1, 43200))
        self.assertEqual(LS_prob.fraction.shape, (1, 43200))
        self.assertTrue(max(LS_prob.intensity.data) <= 1)
        self.assertEqual(min(LS_prob.intensity.data), 0)
        self.assertTrue(max(LS_prob.fraction.data) <= n_years)
        self.assertEqual(min(LS_prob.fraction.data), 0)
        self.assertEqual(LS_prob.frequency.shape, (1, 43200))
        self.assertEqual(min(LS_prob.frequency.data), 0)
        self.assertTrue(max(LS_prob.frequency.data) <= 1 / n_years)
        self.assertEqual(LS_prob.centroids.crs.to_epsg(), 4326)
        self.assertTrue(LS_prob.centroids.coord.max() <= 46)
        self.assertTrue(LS_prob.centroids.coord.min() >= 8)

        LS_prob = Landslide()
        n_years = 300
        LS_prob.set_ls_prob(bbox=(8, 45, 11, 46),
                            path_sourcefile=LS_PROB_FILE,
                            dist='poisson',
                            n_years=n_years)
        self.assertEqual(LS_prob.tag.haz_type, 'LS')
        self.assertEqual(LS_prob.intensity.shape, (1, 43200))
        self.assertEqual(LS_prob.fraction.shape, (1, 43200))
        self.assertTrue(max(LS_prob.intensity.data) <= 1)
        self.assertEqual(min(LS_prob.intensity.data), 0)
        self.assertTrue(max(LS_prob.fraction.data) <= n_years)
        self.assertEqual(min(LS_prob.fraction.data), 0)
        self.assertEqual(LS_prob.frequency.shape, (1, 43200))
        self.assertEqual(min(LS_prob.frequency.data), 0)
        self.assertTrue(max(LS_prob.frequency.data) <= 1 / n_years)
        self.assertEqual(LS_prob.centroids.crs.to_epsg(), 4326)
        self.assertTrue(LS_prob.centroids.coord.max() <= 46)
        self.assertTrue(LS_prob.centroids.coord.min() >= 8)

        LS_prob = Landslide()
        corr_fact = 1.8 * 10e6
        LS_prob.set_ls_prob(bbox=(8, 45, 11, 46),
                            path_sourcefile=LS_PROB_FILE,
                            dist='poisson',
                            corr_fact=corr_fact)
        self.assertEqual(LS_prob.tag.haz_type, 'LS')
        self.assertEqual(LS_prob.intensity.shape, (1, 43200))
        self.assertEqual(LS_prob.fraction.shape, (1, 43200))
        self.assertTrue(max(LS_prob.intensity.data) <= 1)
        self.assertEqual(min(LS_prob.intensity.data), 0)
        self.assertTrue(max(LS_prob.fraction.data) <= n_years)
        self.assertEqual(min(LS_prob.fraction.data), 0)
        self.assertEqual(LS_prob.frequency.shape, (1, 43200))
        self.assertEqual(min(LS_prob.frequency.data), 0)
        self.assertTrue(max(LS_prob.frequency.data) <= 1 / n_years)
        self.assertEqual(LS_prob.centroids.crs.to_epsg(), 4326)
        self.assertTrue(LS_prob.centroids.coord.max() <= 46)
        self.assertTrue(LS_prob.centroids.coord.min() >= 8)