diff --git a/tests/test_LandCover.py b/tests/test_LandCover.py index 99644ae..baa43c7 100644 --- a/tests/test_LandCover.py +++ b/tests/test_LandCover.py @@ -4,29 +4,28 @@ from cropmaps.sts import sentimeseries import rasterio -for directory, _, _ in os.walk("./data"): +for directory, _, _ in os.walk(os.path.join(os.path.dirname(__file__), "data")): for file in os.listdir(directory): if file.endswith(".tif"): os.remove(os.path.join(directory, file)) if file.endswith(".tif.aux.xml"): os.remove(os.path.join(directory, file)) +if not os.path.exists(os.path.join(os.path.dirname(__file__), "data/eodata_local")): + os.makedirs(os.path.join(os.path.dirname(__file__), "data/eodata_local")) -if not os.path.exists("./data/eodata_local"): - os.makedirs("./data/eodata_local") - -landcover_data = "./data/LandCover" +landcover_data = os.path.join(os.path.dirname(__file__), "data/LandCover") search_params = [(landcover_data, None, "LC_mosaic.tif", do_not_raise()), (None, None, "LC_mosaic.tif", pytest.raises(TypeError)), - (landcover_data, "./data/AOI/AOI.geojson", "LC_mosaic.tif", do_not_raise()), + (landcover_data, os.path.join(os.path.dirname(__file__), "data/AOI/AOI.geojson"), "LC_mosaic.tif", do_not_raise()), ] @pytest.mark.parametrize("store, aoi, outname, exception", search_params) def test_LandCover(store, aoi, outname, exception): with exception: eodata = sentimeseries("S2-timeseries") - eodata.find("./data/eodata") + eodata.find(os.path.join(os.path.dirname(__file__), "data/eodata")) landcover_image = eodata.LandCover(store, aoi, outname) src = rasterio.open(landcover_image) assert src.meta["dtype"] == "uint8" diff --git a/tests/test_apply_SCL.py b/tests/test_apply_SCL.py index dc2f72f..c4627d5 100644 --- a/tests/test_apply_SCL.py +++ b/tests/test_apply_SCL.py @@ -5,35 +5,34 @@ from cropmaps.exceptions import BandNotFound import rasterio -for directory, _, _ in os.walk("./data"): +for directory, _, _ in os.walk(os.path.join(os.path.dirname(__file__), "data")): for file in os.listdir(directory): if file.endswith(".tif"): os.remove(os.path.join(directory, file)) if file.endswith(".tif.aux.xml"): os.remove(os.path.join(directory, file)) +if not os.path.exists(os.path.join(os.path.dirname(__file__), "data/eodata_local")): + os.makedirs(os.path.join(os.path.dirname(__file__), "data/eodata_local")) -if not os.path.exists("./data/eodata_local"): - os.makedirs("./data/eodata_local") - -search_params = [(None, "NDWI", "./data/eodata_local", "AOI", None, do_not_raise()), - (None, "NDBI", "./data/eodata_local", "AOI", None, do_not_raise()), - (None, "NDVI", "./data/eodata_local", "AOI", None, do_not_raise()), - (None, None, "./data/eodata_local", "AOI", None, do_not_raise()), +search_params = [(None, "NDWI", os.path.join(os.path.dirname(__file__), "data/eodata_local"), "AOI", None, do_not_raise()), + (None, "NDBI", os.path.join(os.path.dirname(__file__), "data/eodata_local"), "AOI", None, do_not_raise()), + (None, "NDVI", os.path.join(os.path.dirname(__file__), "data/eodata_local"), "AOI", None, do_not_raise()), + (None, None, os.path.join(os.path.dirname(__file__), "data/eodata_local"), "AOI", None, do_not_raise()), (None, None, None, None, None, do_not_raise()), ("./data/eodata/Sentinel-2/L2A/2018/06/27/S2A_MSIL2A_20180627T104021_N0208_R008_T31TEJ_20180627T143337.SAFE/GRANULE/L2A_T31TEJ_A015735_20180627T104837/IMG_DATA/T31TEJ_20180627T104021_B04_10m.jp2", None, None, None, None, pytest.raises(TypeError)), - (None, "NDBI", "./data/eodata_local", "AOI", "highest", pytest.raises(BandNotFound)), + (None, "NDBI", os.path.join(os.path.dirname(__file__), "/data/eodata_local"), "AOI", "highest", pytest.raises(BandNotFound)), ] @pytest.mark.parametrize("image, band, store, subregion, resolution, exception", search_params) def test_apply_SCL(image, band, store, subregion, resolution, exception): with exception: eodata = sentimeseries("S2-timeseries") - eodata.find("./data/eodata") - eodata.clipbyMask("./data/AOI/AOI.geojson", store = "./data/eodata_local") - eodata.getVI("NDVI", store = "./data/eodata_local", subregion = "AOI") # Subregion is the name of the mask shapefile - eodata.getVI("NDWI", store = "./data/eodata_local", subregion = "AOI") # This is in 10m - eodata.getVI("NDBI", store = "./data/eodata_local", subregion = "AOI") # This is in 20m + eodata.find(os.path.join(os.path.dirname(__file__), "data/eodata")) + eodata.clipbyMask(os.path.join(os.path.dirname(__file__), "data/AOI/AOI.geojson"), store = os.path.join(os.path.dirname(__file__), "data/eodata_local")) + eodata.getVI("NDVI", store = os.path.join(os.path.dirname(__file__), "data/eodata_local"), subregion = "AOI") # Subregion is the name of the mask shapefile + eodata.getVI("NDWI", store = os.path.join(os.path.dirname(__file__), "data/eodata_local"), subregion = "AOI") # This is in 10m + eodata.getVI("NDBI", store = os.path.join(os.path.dirname(__file__), "data/eodata_local"), subregion = "AOI") # This is in 20m eodata.apply_SCL(image, band, store, subregion, resolution) if subregion is None: diff --git a/tests/test_burn.py b/tests/test_burn.py index eaa06f9..cf069bb 100644 --- a/tests/test_burn.py +++ b/tests/test_burn.py @@ -6,27 +6,26 @@ from cropmaps.sts import sentimeseries from cropmaps.prepare_vector import burn -for directory, _, _ in os.walk("./data"): +for directory, _, _ in os.walk(os.path.join(os.path.dirname(__file__), "data")): for file in os.listdir(directory): if file.endswith(".tif"): os.remove(os.path.join(directory, file)) if file.endswith(".tif.aux.xml"): os.remove(os.path.join(directory, file)) +if not os.path.exists(os.path.join(os.path.dirname(__file__), "data/eodata_local")): + os.makedirs(os.path.join(os.path.dirname(__file__), "data/eodata_local")) -if not os.path.exists("./data/eodata_local"): - os.makedirs("./data/eodata_local") - -search_params = [("./data/reference_data/france_data_2018.shp", "EC_hcat_n", None, True, None, "gt.tif", do_not_raise()), +search_params = [(os.path.join(os.path.dirname(__file__), "data/reference_data/france_data_2018.shp"), "EC_hcat_n", None, True, None, "gt.tif", do_not_raise()), ] @pytest.mark.parametrize("shapefile, classes, classes_id, save_nomenclature, save_to, outfname, exception", search_params) def test_burn(shapefile, classes, classes_id, save_nomenclature, save_to, outfname, exception): with exception: eodata = sentimeseries("S2-timeseries") - eodata.find("./data/eodata") + eodata.find(os.path.join(os.path.dirname(__file__), "data/eodata")) # To AOI - eodata.clipbyMask("./data/AOI/AOI.geojson", store = "./data/eodata_local") + eodata.clipbyMask(os.path.join(os.path.dirname(__file__), "data/AOI/AOI.geojson"), store = os.path.join(os.path.dirname(__file__), "data/eodata_local")) base = eodata.data[0].B04["10"]["AOI"] metadata = rasterio.open(base).meta.copy() diff --git a/tests/test_clipper.py b/tests/test_clipper.py index 82b6b71..ad4db43 100644 --- a/tests/test_clipper.py +++ b/tests/test_clipper.py @@ -4,35 +4,34 @@ from contextlib import suppress as do_not_raise from cropmaps.sts import sentimeseries -for directory, _, _ in os.walk("./data"): +for directory, _, _ in os.walk(os.path.join(os.path.dirname(__file__), "data")): for file in os.listdir(directory): if file.endswith(".tif"): os.remove(os.path.join(directory, file)) if file.endswith(".tif.aux.xml"): os.remove(os.path.join(directory, file)) - -if not os.path.exists("./data/eodata_local"): - os.makedirs("./data/eodata_local") +if not os.path.exists(os.path.join(os.path.dirname(__file__), "data/eodata_local")): + os.makedirs(os.path.join(os.path.dirname(__file__), "data/eodata_local")) eodata = sentimeseries("S2-timeseries") -eodata.find("./data/eodata") +eodata.find(os.path.join(os.path.dirname(__file__), "data/eodata")) image = eodata.data[0] -search_params = [("./data/AOI/AOI.geojson", False, "B08", False, None, None, "./data/eodata_local", True, do_not_raise()), - ("./data/AOI/AOI.geojson", False, "B08", False, None, None, None, True, do_not_raise()), - ("./data/AOI/AOI.geojson", False, "B8A", True, None, None, None, True, do_not_raise()), - ("./data/AOI/AOI.geojson", True, "B8A", True, None, None, None, True, do_not_raise()), - ("./data/AOI/AOI.geojson", False, None, True, None, None, None, True, do_not_raise()), - ("./data/AOI/AOI.geojson", False, "B8A", False, None, None, None, True, do_not_raise()), - ("./data/AOI/AOI.geojson", False, None, True, None, None, "./data/eodata_local", True, do_not_raise()), +search_params = [(os.path.join(os.path.dirname(__file__), "data/AOI/AOI.geojson"), False, "B08", False, None, None, os.path.join(os.path.dirname(__file__), "data/eodata_local"), True, do_not_raise()), + (os.path.join(os.path.dirname(__file__), "data/AOI/AOI.geojson"), False, "B08", False, None, None, None, True, do_not_raise()), + (os.path.join(os.path.dirname(__file__), "data/AOI/AOI.geojson"), False, "B8A", True, None, None, None, True, do_not_raise()), + (os.path.join(os.path.dirname(__file__), "data/AOI/AOI.geojson"), True, "B8A", True, None, None, None, True, do_not_raise()), + (os.path.join(os.path.dirname(__file__), "data/AOI/AOI.geojson"), False, None, True, None, None, None, True, do_not_raise()), + (os.path.join(os.path.dirname(__file__), "data/AOI/AOI.geojson"), False, "B8A", False, None, None, None, True, do_not_raise()), + (os.path.join(os.path.dirname(__file__), "data/AOI/AOI.geojson"), False, None, True, None, None, os.path.join(os.path.dirname(__file__), "data/eodata_local"), True, do_not_raise()), ] @pytest.mark.parametrize("shapefile, series, band, resize, method, new, store, force_update, exception", search_params) def test_clip_by_mask(shapefile, series, band, resize, method, new, store, force_update, exception): with exception: eodata = sentimeseries("S2-timeseries") - eodata.find("./data/eodata") + eodata.find(os.path.join(os.path.dirname(__file__), "data/eodata")) if series: eodata.clipbyMask(shapefile, None, band, resize, method, new, store, force_update) for im in eodata.data: diff --git a/tests/test_find.py b/tests/test_find.py index 5b98a8f..3875706 100644 --- a/tests/test_find.py +++ b/tests/test_find.py @@ -4,13 +4,13 @@ from cropmaps.sts import sentimeseries from cropmaps.exceptions import NoDataError -if not os.path.exists("./data/eodata_local"): - os.makedirs("./data/eodata_local") +if not os.path.exists(os.path.join(os.path.dirname(__file__), "data/eodata_local")): + os.makedirs(os.path.join(os.path.dirname(__file__), "data/eodata_local")) # Test cropmaps.sts.sentimeseries.find() -search_params = [("./data/eodata", "L2A", do_not_raise()), - ("./data/eodata", "L1C", pytest.raises(NoDataError)) +search_params = [(os.path.join(os.path.dirname(__file__), "data/eodata"), "L2A", do_not_raise()), + (os.path.join(os.path.dirname(__file__), "data/eodata"), "L1C", pytest.raises(NoDataError)) ] @pytest.mark.parametrize("search, level, exception", search_params) @@ -45,14 +45,14 @@ def local_DIAS_path_creator(image): # Get data eodata = sentimeseries("S2-timeseries") -eodata.find("./data/eodata") +eodata.find(os.path.join(os.path.dirname(__file__), "data/eodata")) eodata.sort_images(date=True) creodias_paths = [] for image in eodata.data: src = os.path.join(image.path, image.name) DIAS_path = local_DIAS_path_creator(image) - creodias_paths.append(os.path.join("./data/eodata", DIAS_path, image.name)) + creodias_paths.append(os.path.join(os.path.dirname(__file__), "data/eodata", DIAS_path, image.name)) search_params = [(creodias_paths, do_not_raise()), ([], pytest.raises(NoDataError)) diff --git a/tests/test_generate_cube.py b/tests/test_generate_cube.py index 810687f..48ab1bc 100644 --- a/tests/test_generate_cube.py +++ b/tests/test_generate_cube.py @@ -4,15 +4,15 @@ from cropmaps.sts import sentimeseries from cropmaps.cube import generate_cube_paths -for directory, _, _ in os.walk("./data"): +for directory, _, _ in os.walk(os.path.join(os.path.dirname(__file__), "data")): for file in os.listdir(directory): if file.endswith(".tif"): os.remove(os.path.join(directory, file)) if file.endswith(".tif.aux.xml"): os.remove(os.path.join(directory, file)) -if not os.path.exists("./data/eodata_local"): - os.makedirs("./data/eodata_local") +if not os.path.exists(os.path.join(os.path.dirname(__file__), "data/eodata_local")): + os.makedirs(os.path.join(os.path.dirname(__file__), "data/eodata_local")) search_params = [("AOI", do_not_raise()), (None, do_not_raise()), @@ -24,29 +24,29 @@ def test_generate_cube_paths(mask, exception): bands = ["B02", "B03", "B04", "B05", "B06", "B07", "B08", "B8A", "B11", "B12", "NDVI", "NDBI", "NDWI"] eodata = sentimeseries("S2-timeseries") - eodata.find("./data/eodata") + eodata.find(os.path.join(os.path.dirname(__file__), "data/eodata")) # To AOI - eodata.clipbyMask("./data/AOI/AOI.geojson", store = "./data/eodata_local") - eodata.clipbyMask("./data/AOI/AOI.geojson", store = "./data/eodata_local", resize = True) - eodata.getVI("NDVI", store = "./data/eodata_local", subregion = "AOI") # Subregion is the name of the mask shapefile - eodata.getVI("NDWI", store = "./data/eodata_local", subregion = "AOI") - eodata.getVI("NDBI", store = "./data/eodata_local", subregion = "AOI") # This is in 20m - eodata.upsample(store = "./data/eodata_local", band = "NDBI", subregion = "AOI", new = "AOI_10_Upsampled") # Transforming to 10m - eodata.apply_SCL(store = "./data/eodata_local", resolution="highest", subregion="AOI") # This performs only the default bands - eodata.apply_SCL(store = "./data/eodata_local", band = "NDVI", resolution="highest", subregion="AOI") - eodata.apply_SCL(store = "./data/eodata_local", band = "NDWI", resolution="highest", subregion="AOI") - eodata.apply_SCL(store = "./data/eodata_local", band = "NDBI", resolution="highest", subregion="AOI") + eodata.clipbyMask(os.path.join(os.path.dirname(__file__), "data/AOI/AOI.geojson"), store = os.path.join(os.path.dirname(__file__), "data/eodata_local")) + eodata.clipbyMask(os.path.join(os.path.dirname(__file__), "data/AOI/AOI.geojson"), store = os.path.join(os.path.dirname(__file__), "data/eodata_local"), resize = True) + eodata.getVI("NDVI", store = os.path.join(os.path.dirname(__file__), "data/eodata_local"), subregion = "AOI") # Subregion is the name of the mask shapefile + eodata.getVI("NDWI", store = os.path.join(os.path.dirname(__file__), "data/eodata_local"), subregion = "AOI") + eodata.getVI("NDBI", store = os.path.join(os.path.dirname(__file__), "data/eodata_local"), subregion = "AOI") # This is in 20m + eodata.upsample(store = os.path.join(os.path.dirname(__file__), "data/eodata_local"), band = "NDBI", subregion = "AOI", new = "AOI_10_Upsampled") # Transforming to 10m + eodata.apply_SCL(store = os.path.join(os.path.dirname(__file__), "data/eodata_local"), resolution="highest", subregion="AOI") # This performs only the default bands + eodata.apply_SCL(store = os.path.join(os.path.dirname(__file__), "data/eodata_local"), band = "NDVI", resolution="highest", subregion="AOI") + eodata.apply_SCL(store = os.path.join(os.path.dirname(__file__), "data/eodata_local"), band = "NDWI", resolution="highest", subregion="AOI") + eodata.apply_SCL(store = os.path.join(os.path.dirname(__file__), "data/eodata_local"), band = "NDBI", resolution="highest", subregion="AOI") # To raw - eodata.upsample(store = "./data/eodata_local") # Transforming all 20m bands to 10m - eodata.getVI("NDVI", store = "./data/eodata_local") # Subregion is the name of the mask shapefile - eodata.getVI("NDWI", store = "./data/eodata_local") - eodata.getVI("NDBI", store = "./data/eodata_local") # This is in 20m - eodata.upsample(store = "./data/eodata_local", band = "NDBI") # Transforming to 10m - eodata.apply_SCL(store = "./data/eodata_local", resolution="highest") # This performs only the default bands - eodata.apply_SCL(store = "./data/eodata_local", band = "NDVI", resolution="highest") - eodata.apply_SCL(store = "./data/eodata_local", band = "NDWI", resolution="highest") - eodata.apply_SCL(store = "./data/eodata_local", band = "NDBI", resolution="highest") + eodata.upsample(store = os.path.join(os.path.dirname(__file__), "data/eodata_local")) # Transforming all 20m bands to 10m + eodata.getVI("NDVI", store = os.path.join(os.path.dirname(__file__), "data/eodata_local")) # Subregion is the name of the mask shapefile + eodata.getVI("NDWI", store = os.path.join(os.path.dirname(__file__), "data/eodata_local")) + eodata.getVI("NDBI", store = os.path.join(os.path.dirname(__file__), "data/eodata_local")) # This is in 20m + eodata.upsample(store = os.path.join(os.path.dirname(__file__), "data/eodata_local"), band = "NDBI") # Transforming to 10m + eodata.apply_SCL(store = os.path.join(os.path.dirname(__file__), "data/eodata_local"), resolution="highest") # This performs only the default bands + eodata.apply_SCL(store = os.path.join(os.path.dirname(__file__), "data/eodata_local"), band = "NDVI", resolution="highest") + eodata.apply_SCL(store = os.path.join(os.path.dirname(__file__), "data/eodata_local"), band = "NDWI", resolution="highest") + eodata.apply_SCL(store = os.path.join(os.path.dirname(__file__), "data/eodata_local"), band = "NDBI", resolution="highest") paths = generate_cube_paths(eodata, bands, mask) assert isinstance(paths, list) assert len(paths) == len(bands)*eodata.total \ No newline at end of file diff --git a/tests/test_getVI.py b/tests/test_getVI.py index dfa3fcc..c118ad0 100644 --- a/tests/test_getVI.py +++ b/tests/test_getVI.py @@ -4,23 +4,22 @@ from cropmaps.sts import sentimeseries import rasterio -for directory, _, _ in os.walk("./data"): +for directory, _, _ in os.walk(os.path.join(os.path.dirname(__file__), "data")): for file in os.listdir(directory): if file.endswith(".tif"): os.remove(os.path.join(directory, file)) if file.endswith(".tif.aux.xml"): os.remove(os.path.join(directory, file)) +if not os.path.exists(os.path.join(os.path.dirname(__file__), "data/eodata_local")): + os.makedirs(os.path.join(os.path.dirname(__file__), "data/eodata_local")) -if not os.path.exists("./data/eodata_local"): - os.makedirs("./data/eodata_local") - -search_params = [("NDVI", "./data/eodata_local", None, "AOI", False, do_not_raise()), - ("NDWI", "./data/eodata_local", None, "AOI", False, do_not_raise()), - ("NDBI", "./data/eodata_local", None, "AOI", False, do_not_raise()), - ("NDVI", "./data/eodata_local", None, None, False, do_not_raise()), - ("NDWI", "./data/eodata_local", None, None, False, do_not_raise()), - ("NDBI", "./data/eodata_local", None, None, False, do_not_raise()), +search_params = [("NDVI", os.path.join(os.path.dirname(__file__), "data/eodata_local"), None, "AOI", False, do_not_raise()), + ("NDWI", os.path.join(os.path.dirname(__file__), "data/eodata_local"), None, "AOI", False, do_not_raise()), + ("NDBI", os.path.join(os.path.dirname(__file__), "data/eodata_local"), None, "AOI", False, do_not_raise()), + ("NDVI", os.path.join(os.path.dirname(__file__), "data/eodata_local"), None, None, False, do_not_raise()), + ("NDWI", os.path.join(os.path.dirname(__file__), "data/eodata_local"), None, None, False, do_not_raise()), + ("NDBI", os.path.join(os.path.dirname(__file__), "data/eodata_local"), None, None, False, do_not_raise()), ("NDVI", None, None, None, False, do_not_raise()), ("NDWI", None, None, None, False, do_not_raise()), ("NDBI", None, None, None, False, do_not_raise()), @@ -33,9 +32,9 @@ def test_getVI(index, store, image, subregion, verbose, exception): with exception: eodata = sentimeseries("S2-timeseries") - eodata.find("./data/eodata") - eodata.clipbyMask("./data/AOI/AOI.geojson", store = "./data/eodata_local") - eodata.clipbyMask("./data/AOI/AOI.geojson") + eodata.find(os.path.join(os.path.dirname(__file__), "data/eodata")) + eodata.clipbyMask(os.path.join(os.path.dirname(__file__), "data/AOI/AOI.geojson"), store = os.path.join(os.path.dirname(__file__), "data/eodata_local")) + eodata.clipbyMask(os.path.join(os.path.dirname(__file__), "data/AOI/AOI.geojson")) eodata.getVI(index, store, image, subregion, verbose) if subregion is None: level = "raw" diff --git a/tests/test_make_cube.py b/tests/test_make_cube.py index 5ef0ffb..b2f29ab 100644 --- a/tests/test_make_cube.py +++ b/tests/test_make_cube.py @@ -6,18 +6,17 @@ from cropmaps.sts import sentimeseries from cropmaps.cube import generate_cube_paths, make_cube -for directory, _, _ in os.walk("./data"): +for directory, _, _ in os.walk(os.path.join(os.path.dirname(__file__), "data")): for file in os.listdir(directory): if file.endswith(".tif"): os.remove(os.path.join(directory, file)) if file.endswith(".tif.aux.xml"): os.remove(os.path.join(directory, file)) +if not os.path.exists(os.path.join(os.path.dirname(__file__), "data/eodata_local")): + os.makedirs(os.path.join(os.path.dirname(__file__), "data/eodata_local")) -if not os.path.exists("./data/eodata_local"): - os.makedirs("./data/eodata_local") - -search_params = [("./data/eodata_local/hypercube", "cube.tif", np.float32, -9999, True, True, 0.0001, 0., True, False, do_not_raise()), +search_params = [(os.path.join(os.path.dirname(__file__), "data/eodata_local/hypercube"), "cube.tif", np.float32, -9999, True, True, 0.0001, 0., True, False, do_not_raise()), ] @pytest.mark.parametrize("searchPath, newFilename, dtype, nodata, gap_fill, harmonize, alpha, beta, force_new, compress, exception", search_params) @@ -27,18 +26,18 @@ def test_make_cube(searchPath, newFilename, dtype, nodata, gap_fill, harmonize, with exception: eodata = sentimeseries("S2-timeseries") - eodata.find("./data/eodata") + eodata.find(os.path.join(os.path.dirname(__file__), "data/eodata")) # To AOI - eodata.clipbyMask("./data/AOI/AOI.geojson", store = "./data/eodata_local") - eodata.clipbyMask("./data/AOI/AOI.geojson", store = "./data/eodata_local", resize = True) - eodata.getVI("NDVI", store = "./data/eodata_local", subregion = "AOI") # Subregion is the name of the mask shapefile - eodata.getVI("NDWI", store = "./data/eodata_local", subregion = "AOI") - eodata.getVI("NDBI", store = "./data/eodata_local", subregion = "AOI") # This is in 20m - eodata.upsample(store = "./data/eodata_local", band = "NDBI", subregion = "AOI", new = "AOI_10_Upsampled") # Transforming to 10m - eodata.apply_SCL(store = "./data/eodata_local", resolution="highest", subregion="AOI") # This performs only the default bands - eodata.apply_SCL(store = "./data/eodata_local", band = "NDVI", resolution="highest", subregion="AOI") - eodata.apply_SCL(store = "./data/eodata_local", band = "NDWI", resolution="highest", subregion="AOI") - eodata.apply_SCL(store = "./data/eodata_local", band = "NDBI", resolution="highest", subregion="AOI") + eodata.clipbyMask(os.path.join(os.path.dirname(__file__), "data/AOI/AOI.geojson"), store = os.path.join(os.path.dirname(__file__), "data/eodata_local")) + eodata.clipbyMask(os.path.join(os.path.dirname(__file__), "data/AOI/AOI.geojson"), store = os.path.join(os.path.dirname(__file__), "data/eodata_local"), resize = True) + eodata.getVI("NDVI", store = os.path.join(os.path.dirname(__file__), "data/eodata_local"), subregion = "AOI") # Subregion is the name of the mask shapefile + eodata.getVI("NDWI", store = os.path.join(os.path.dirname(__file__), "data/eodata_local"), subregion = "AOI") + eodata.getVI("NDBI", store = os.path.join(os.path.dirname(__file__), "data/eodata_local"), subregion = "AOI") # This is in 20m + eodata.upsample(store = os.path.join(os.path.dirname(__file__), "data/eodata_local"), band = "NDBI", subregion = "AOI", new = "AOI_10_Upsampled") # Transforming to 10m + eodata.apply_SCL(store = os.path.join(os.path.dirname(__file__), "data/eodata_local"), resolution="highest", subregion="AOI") # This performs only the default bands + eodata.apply_SCL(store = os.path.join(os.path.dirname(__file__), "data/eodata_local"), band = "NDVI", resolution="highest", subregion="AOI") + eodata.apply_SCL(store = os.path.join(os.path.dirname(__file__), "data/eodata_local"), band = "NDWI", resolution="highest", subregion="AOI") + eodata.apply_SCL(store = os.path.join(os.path.dirname(__file__), "data/eodata_local"), band = "NDBI", resolution="highest", subregion="AOI") bands = ["B02", "B03", "B04", "B05", "B06", "B07", "B08", "B8A", "B11", "B12", "NDVI", "NDBI", "NDWI"] paths = generate_cube_paths(eodata, bands, mask = "AOI") diff --git a/tests/test_remove_orbit.py b/tests/test_remove_orbit.py index f0c20e7..48cb4c0 100644 --- a/tests/test_remove_orbit.py +++ b/tests/test_remove_orbit.py @@ -3,16 +3,15 @@ from contextlib import suppress as do_not_raise from cropmaps.sts import sentimeseries -for directory, _, _ in os.walk("./data"): +for directory, _, _ in os.walk(os.path.join(os.path.dirname(__file__), "data")): for file in os.listdir(directory): if file.endswith(".tif"): os.remove(os.path.join(directory, file)) if file.endswith(".tif.aux.xml"): os.remove(os.path.join(directory, file)) - -if not os.path.exists("./data/eodata_local"): - os.makedirs("./data/eodata_local") +if not os.path.exists(os.path.join(os.path.dirname(__file__), "data/eodata_local")): + os.makedirs(os.path.join(os.path.dirname(__file__), "data/eodata_local")) search_params = [("8", 0, do_not_raise()), (None, 10, pytest.raises(TypeError)), @@ -23,6 +22,6 @@ def test_remove_orbit(orbit, total, exception): with exception: eodata = sentimeseries("S2-timeseries") - eodata.find("./data/eodata") + eodata.find(os.path.join(os.path.dirname(__file__), "data/eodata")) eodata.remove_orbit(orbit) assert eodata.total == total diff --git a/tests/test_sort_remove_etc.py b/tests/test_sort_remove_etc.py index 5544b7f..c49b3e1 100644 --- a/tests/test_sort_remove_etc.py +++ b/tests/test_sort_remove_etc.py @@ -4,15 +4,22 @@ from cropmaps.exceptions import MinMaxCloudBoundError, MinMaxDateError import os -if not os.path.exists("./data/eodata_local"): - os.makedirs("./data/eodata_local") +for directory, _, _ in os.walk(os.path.join(os.path.dirname(__file__), "data")): + for file in os.listdir(directory): + if file.endswith(".tif"): + os.remove(os.path.join(directory, file)) + if file.endswith(".tif.aux.xml"): + os.remove(os.path.join(directory, file)) + +if not os.path.exists(os.path.join(os.path.dirname(__file__), "data/eodata_local")): + os.makedirs(os.path.join(os.path.dirname(__file__), "data/eodata_local")) # Test cropmaps.ts.remove_cloudy() -search_params = [("./data/eodata", 5, 0, do_not_raise()), - ("./data/eodata", "5", 0, pytest.raises(TypeError)), - ("./data/eodata", 5, "0", pytest.raises(TypeError)), - ("./data/eodata", 0, 5, pytest.raises(MinMaxCloudBoundError)), +search_params = [(os.path.join(os.path.dirname(__file__), "data/eodata"), 5, 0, do_not_raise()), + (os.path.join(os.path.dirname(__file__), "data/eodata"), "5", 0, pytest.raises(TypeError)), + (os.path.join(os.path.dirname(__file__), "data/eodata"), 5, "0", pytest.raises(TypeError)), + (os.path.join(os.path.dirname(__file__), "data/eodata"), 0, 5, pytest.raises(MinMaxCloudBoundError)), ] @pytest.mark.parametrize("search, max_cloud, min_cloud, exception", search_params) @@ -28,10 +35,10 @@ def test_remove_cloudy(search, max_cloud, min_cloud, exception): # Test cropmaps.ts.keep_timerange() -search_params = [("./data/eodata", "104100", "104400", do_not_raise()), - ("./data/eodata", 104100, "104400", pytest.raises(TypeError)), - ("./data/eodata", "104100", 104400, pytest.raises(TypeError)), - ("./data/eodata", "104400", "104100", pytest.raises(ValueError)) +search_params = [(os.path.join(os.path.dirname(__file__), "data/eodata"), "104100", "104400", do_not_raise()), + (os.path.join(os.path.dirname(__file__), "data/eodata"), 104100, "104400", pytest.raises(TypeError)), + (os.path.join(os.path.dirname(__file__), "data/eodata"), "104100", 104400, pytest.raises(TypeError)), + (os.path.join(os.path.dirname(__file__), "data/eodata"), "104400", "104100", pytest.raises(ValueError)) ] @pytest.mark.parametrize("search, start_time, end_time, exception", search_params) @@ -46,14 +53,14 @@ def test_keep_timerange(search, start_time, end_time, exception): # Test cropmaps.ts.remove_date() -search_params = [("./data/eodata", "23012017", do_not_raise()), - ("./data/eodata", "23012018", do_not_raise()), - ("./data/eodata", "230120188", pytest.raises(ValueError)), - ("./data/eodata", ["23012018", "28012018"], do_not_raise()), - ("./data/eodata", ["23012018", "28012018","28012017"], do_not_raise()), - ("./data/eodata", ["23012018", "28012018","280120177"], pytest.raises(ValueError)), - ("./data/eodata", 23012018, pytest.raises(TypeError)), - ("./data/eodata", [23012018], pytest.raises(TypeError)) +search_params = [(os.path.join(os.path.dirname(__file__), "data/eodata"), "23012017", do_not_raise()), + (os.path.join(os.path.dirname(__file__), "data/eodata"), "23012018", do_not_raise()), + (os.path.join(os.path.dirname(__file__), "data/eodata"), "230120188", pytest.raises(ValueError)), + (os.path.join(os.path.dirname(__file__), "data/eodata"), ["23012018", "28012018"], do_not_raise()), + (os.path.join(os.path.dirname(__file__), "data/eodata"), ["23012018", "28012018","28012017"], do_not_raise()), + (os.path.join(os.path.dirname(__file__), "data/eodata"), ["23012018", "28012018","280120177"], pytest.raises(ValueError)), + (os.path.join(os.path.dirname(__file__), "data/eodata"), 23012018, pytest.raises(TypeError)), + (os.path.join(os.path.dirname(__file__), "data/eodata"), [23012018], pytest.raises(TypeError)) ] @pytest.mark.parametrize("search, date, exception", search_params) @@ -68,12 +75,12 @@ def test_keep_timerange(search, date, exception): # Test cropmaps.ts.filter_dates() -search_params = [("./data/eodata", 23012017, None, pytest.raises(TypeError)), - ("./data/eodata", "231020181", None, pytest.raises(ValueError)), - ("./data/eodata", "01102018", None, do_not_raise()), - ("./data/eodata", "01102018", 23012017, pytest.raises(TypeError)), - ("./data/eodata", "01102018", "230120171", pytest.raises(ValueError)), - ("./data/eodata", "01102018", "01042018", do_not_raise()), +search_params = [(os.path.join(os.path.dirname(__file__), "data/eodata"), 23012017, None, pytest.raises(TypeError)), + (os.path.join(os.path.dirname(__file__), "data/eodata"), "231020181", None, pytest.raises(ValueError)), + (os.path.join(os.path.dirname(__file__), "data/eodata"), "01102018", None, do_not_raise()), + (os.path.join(os.path.dirname(__file__), "data/eodata"), "01102018", 23012017, pytest.raises(TypeError)), + (os.path.join(os.path.dirname(__file__), "data/eodata"), "01102018", "230120171", pytest.raises(ValueError)), + (os.path.join(os.path.dirname(__file__), "data/eodata"), "01102018", "01042018", do_not_raise()), ] @pytest.mark.parametrize("search, max_date, min_date, exception", search_params) @@ -88,11 +95,11 @@ def test_filter_dates(search, max_date, min_date, exception): # Test cropmaps.ts.sort_images() -search_params = [("./data/eodata", "True", True, pytest.raises(TypeError)), - ("./data/eodata", True, "True", pytest.raises(TypeError)), - ("./data/eodata", False, False, do_not_raise()), - ("./data/eodata", True, False, do_not_raise()), - ("./data/eodata", False, True, do_not_raise()), +search_params = [(os.path.join(os.path.dirname(__file__), "data/eodata"), "True", True, pytest.raises(TypeError)), + (os.path.join(os.path.dirname(__file__), "data/eodata"), True, "True", pytest.raises(TypeError)), + (os.path.join(os.path.dirname(__file__), "data/eodata"), False, False, do_not_raise()), + (os.path.join(os.path.dirname(__file__), "data/eodata"), True, False, do_not_raise()), + (os.path.join(os.path.dirname(__file__), "data/eodata"), False, True, do_not_raise()), ] @pytest.mark.parametrize("search, cloud_coverage, date, exception", search_params) diff --git a/tests/test_upsample.py b/tests/test_upsample.py index 360055a..60577db 100644 --- a/tests/test_upsample.py +++ b/tests/test_upsample.py @@ -4,22 +4,21 @@ from cropmaps.sts import sentimeseries import rasterio -for directory, _, _ in os.walk("./data"): +for directory, _, _ in os.walk(os.path.join(os.path.dirname(__file__), "data")): for file in os.listdir(directory): if file.endswith(".tif"): os.remove(os.path.join(directory, file)) if file.endswith(".tif.aux.xml"): os.remove(os.path.join(directory, file)) +if not os.path.exists(os.path.join(os.path.dirname(__file__), "data/eodata_local")): + os.makedirs(os.path.join(os.path.dirname(__file__), "data/eodata_local")) -if not os.path.exists("./data/eodata_local"): - os.makedirs("./data/eodata_local") - -search_params = [(True, "NDBI", None, None, "./data/eodata_local", "AOI", do_not_raise()), - (True, "NDVI", None, None, "./data/eodata_local", "AOI", do_not_raise()), +search_params = [(True, "NDBI", None, None, os.path.join(os.path.dirname(__file__), "data/eodata_local"), "AOI", do_not_raise()), + (True, "NDVI", None, None, os.path.join(os.path.dirname(__file__), "data/eodata_local"), "AOI", do_not_raise()), (True, "SCL", None, None, None, None, do_not_raise()), - (False, "B07", None, None, "./data/eodata_local", "AOI", do_not_raise()), - (False, None, None, None, "./data/eodata_local", "AOI", do_not_raise()), + (False, "B07", None, None, os.path.join(os.path.dirname(__file__), "data/eodata_local"), "AOI", do_not_raise()), + (False, None, None, None, os.path.join(os.path.dirname(__file__), "data/eodata_local"), "AOI", do_not_raise()), (False, None, None, None, None, None, do_not_raise()), ] @@ -27,11 +26,11 @@ def test_upsample(series, band, method, new, store, subregion, exception): with exception: eodata = sentimeseries("S2-timeseries") - eodata.find("./data/eodata") - eodata.clipbyMask("./data/AOI/AOI.geojson", store = "./data/eodata_local") - eodata.clipbyMask("./data/AOI/AOI.geojson") - eodata.getVI("NDVI", store = "./data/eodata_local", subregion = "AOI") # Subregion is the name of the mask shapefile - eodata.getVI("NDBI", store = "./data/eodata_local", subregion = "AOI") # This is in 20m + eodata.find(os.path.join(os.path.dirname(__file__), "data/eodata")) + eodata.clipbyMask(os.path.join(os.path.dirname(__file__), "data/AOI/AOI.geojson"), store = os.path.join(os.path.dirname(__file__), "data/eodata_local")) + eodata.clipbyMask(os.path.join(os.path.dirname(__file__), "data/AOI/AOI.geojson")) + eodata.getVI("NDVI", store = os.path.join(os.path.dirname(__file__), "data/eodata_local"), subregion = "AOI") # Subregion is the name of the mask shapefile + eodata.getVI("NDBI", store = os.path.join(os.path.dirname(__file__), "data/eodata_local"), subregion = "AOI") # This is in 20m if series: eodata.upsample(None, band, method, new, store, subregion) else: