From 75dc7d05a63cc54e7066947ca2cdcc6f03f88b95 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 13 Jan 2025 19:55:04 +0000 Subject: [PATCH 1/2] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/pre-commit/pre-commit-hooks: v4.5.0 → v5.0.0](https://github.com/pre-commit/pre-commit-hooks/compare/v4.5.0...v5.0.0) - [github.com/igorshubovych/markdownlint-cli: v0.39.0 → v0.43.0](https://github.com/igorshubovych/markdownlint-cli/compare/v0.39.0...v0.43.0) - [github.com/codespell-project/codespell: v2.2.6 → v2.3.0](https://github.com/codespell-project/codespell/compare/v2.2.6...v2.3.0) - [github.com/astral-sh/ruff-pre-commit: v0.2.1 → v0.9.1](https://github.com/astral-sh/ruff-pre-commit/compare/v0.2.1...v0.9.1) --- .pre-commit-config.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fb7607e..eb235bb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ # See https://pre-commit.com/hooks.html for more hooks repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v5.0.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -14,7 +14,7 @@ repos: args: [--allow-missing-credentials] - id: detect-private-key - repo: https://github.com/igorshubovych/markdownlint-cli - rev: v0.39.0 + rev: v0.43.0 hooks: - id: markdownlint name: Markdownlint @@ -24,14 +24,14 @@ repos: "--disable=MD033", # no-inline-html ] - repo: https://github.com/codespell-project/codespell - rev: v2.2.6 + rev: v2.3.0 hooks: - id: codespell name: codespell description: Checks for common misspellings in text files additional_dependencies: [tomli] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.2.1 + rev: v0.9.1 hooks: - id: ruff types_or: [python, pyi, jupyter] From 364944f4df143b8f14f060d942d765637f5c804c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 13 Jan 2025 19:55:25 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- notebooks/ZON_DECAT_NTL_from_AWS.ipynb | 2 +- pyproject.toml | 2 +- src/GOSTrocks/dataMisc.py | 37 +++++++++++++++----------- src/GOSTrocks/infra/aggregator.py | 1 + src/GOSTrocks/rasterMisc.py | 2 +- 5 files changed, 26 insertions(+), 18 deletions(-) diff --git a/notebooks/ZON_DECAT_NTL_from_AWS.ipynb b/notebooks/ZON_DECAT_NTL_from_AWS.ipynb index 21ea0e2..af61374 100644 --- a/notebooks/ZON_DECAT_NTL_from_AWS.ipynb +++ b/notebooks/ZON_DECAT_NTL_from_AWS.ipynb @@ -412,7 +412,7 @@ "inD = inD.to_crs(\"epsg:4326\")\n", "\n", "for cur_tif in ntl_files:\n", - " file = f'{cur_tif.split(\"/\")[-1]}.tif'\n", + " file = f\"{cur_tif.split('/')[-1]}.tif\"\n", " out_file = os.path.join(os.path.join(viirs_folder, \"%s\" % file))\n", " curR = rasterio.open(cur_tif)\n", " if not os.path.exists(out_file):\n", 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)