diff --git a/pyproject.toml b/pyproject.toml index aa2c2c7..12c1e47 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,7 +51,7 @@ dependencies = [ "python-dotenv>=0.5.1", "rasterio", "s3fs", - "seaborn", + "seaborn", "tqdm", "xarray" ] diff --git a/src/GOSTrocks/dataMisc.py b/src/GOSTrocks/dataMisc.py index 353e672..9f99cfe 100644 --- a/src/GOSTrocks/dataMisc.py +++ b/src/GOSTrocks/dataMisc.py @@ -60,7 +60,9 @@ def aws_search_ntl( :type verbose: bool, optional """ if unsigned: - s3client = boto3.client("s3", verify=False, config=Config(signature_version=UNSIGNED)) + s3client = boto3.client( + "s3", verify=False, config=Config(signature_version=UNSIGNED) + ) else: s3client = boto3.client("s3", verify=False) @@ -151,16 +153,22 @@ def get_fathom_vrts(return_df=False): return vrt_pd return all_vrts -def get_worldcover(df, download_folder, worldcover_vrt='WorldCover.vrt', - version='v200', - print_command=False, verbose=False): - """ Download ESA globcover from AWS (https://aws.amazon.com/marketplace/pp/prodview-7oorylcamixxc) + +def get_worldcover( + df, + download_folder, + worldcover_vrt="WorldCover.vrt", + version="v200", + print_command=False, + verbose=False, +): + """Download ESA globcover from AWS (https://aws.amazon.com/marketplace/pp/prodview-7oorylcamixxc) Parameters ---------- df : geopandas.GeoDataFrame Data frame used to select tiles to download; selects tiles based on the data frame unary_union - download_folder : string + download_folder : string path to folder to download tiles worldcover_vrt : str, optional name of the VRT file to create, by default 'WorldCover.vrt' @@ -172,23 +180,23 @@ def get_worldcover(df, download_folder, worldcover_vrt='WorldCover.vrt', verbose : bool, optional Print more updates during processing, by default False """ - - bucket='esa-worldcover' - esa_file_geojson = 'esa_worldcover_grid.geojson' - s3 = boto3.client('s3', verify=False, config=Config(signature_version=UNSIGNED)) + + bucket = "esa-worldcover" + esa_file_geojson = "esa_worldcover_grid.geojson" + s3 = boto3.client("s3", verify=False, config=Config(signature_version=UNSIGNED)) tiles_geojson = os.path.join(download_folder, esa_file_geojson) if not os.path.exists(tiles_geojson): s3.download_file(bucket, esa_file_geojson, tiles_geojson) tile_path = "{version}/2021/map/ESA_WorldCover_10m_2021_v200_{tile}_Map.tif" - + in_tiles = gpd.read_file(tiles_geojson) sel_tiles = in_tiles.loc[in_tiles.intersects(df.unary_union)] all_tiles = [] for idx, row in sel_tiles.iterrows(): - cur_tile_path = tile_path.format(tile=row['ll_tile'], version=version) + cur_tile_path = tile_path.format(tile=row["ll_tile"], version=version) cur_out = os.path.join(download_folder, f"WorldCover_{row['ll_tile']}.tif") all_tiles.append(cur_out) if not os.path.exists(cur_out): @@ -199,12 +207,11 @@ def get_worldcover(df, download_folder, worldcover_vrt='WorldCover.vrt', if not os.path.exists(cur_out): if verbose: print(f"Downloading {cur_tile_path} to {cur_out}") - s3.download_file(bucket,cur_tile_path, cur_out) + s3.download_file(bucket, cur_tile_path, cur_out) else: if verbose: print(f"File {cur_out} already exists") out_vrt = os.path.join(download_folder, worldcover_vrt) gdal.BuildVRT(out_vrt, all_tiles, options=gdal.BuildVRTOptions()) - - return(all_tiles) + return all_tiles diff --git a/src/GOSTrocks/infra/aggregator.py b/src/GOSTrocks/infra/aggregator.py index 9f580d6..ac65cac 100644 --- a/src/GOSTrocks/infra/aggregator.py +++ b/src/GOSTrocks/infra/aggregator.py @@ -1,6 +1,7 @@ """ The following module contains a number of functions to aggregate geospatial outputs into tables for InfraSAP analytics. """ + import geopandas as gpd import pandas as pd import rasterio as rio diff --git a/src/GOSTrocks/rasterMisc.py b/src/GOSTrocks/rasterMisc.py index f24c91f..66c98a7 100644 --- a/src/GOSTrocks/rasterMisc.py +++ b/src/GOSTrocks/rasterMisc.py @@ -126,7 +126,7 @@ def project_raster(srcRst, dstCrs, output_raster=""): dstCrs (int): crs to project to output_raster (string): file to write to, defaults to '', which writes nothing - """ + """ if dstCrs.__class__ == int: dstCrs = CRS.from_epsg(dstCrs)