Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Dec 2, 2024
1 parent 551469a commit deb8cd8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ dependencies = [
"python-dotenv>=0.5.1",
"rasterio",
"s3fs",
"seaborn",
"seaborn",
"tqdm",
"xarray"
]
Expand Down
37 changes: 22 additions & 15 deletions src/GOSTrocks/dataMisc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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'
Expand All @@ -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):
Expand All @@ -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
1 change: 1 addition & 0 deletions src/GOSTrocks/infra/aggregator.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/GOSTrocks/rasterMisc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit deb8cd8

Please sign in to comment.