Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix too many open files #13 #14

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ dependencies:
- numpy
- shapely
- pyarrow
- fiona
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ description = "Conveniently search, download, and preprocess ArcticDEM and REMA
keywords = [ "geospatial", "elevation", "arcticdem", "rema", "dem",]
classifiers = [ "Intended Audience :: Science/Research", "Programming Language :: Python :: 3", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Topic :: Scientific/Engineering", "Topic :: Scientific/Engineering :: GIS", "Topic :: Scientific/Engineering :: Image Processing",]
requires-python = ">=3.9"
dependencies = ["rioxarray", "rasterio", "geopandas", "pandas", "shapely", "numpy", "GDAL", "opencv-python", "scipy", "numba", "pyarrow",] # GDAL
dependencies = ["rioxarray", "rasterio", "geopandas", "pandas", "shapely", "numpy", "GDAL", "opencv-python", "scipy", "numba", "pyarrow", "fiona"] # GDAL

[[project.authors]]
name = "Tom Chudley"
Expand Down
27 changes: 15 additions & 12 deletions src/pdemtools/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,20 +313,22 @@ def mosaic(
)

# Load tiles that intersect with AOI
tiles = gpd.read_file(
_get_index_fpath(dataset, version=version), layer=layer, bbox=bounds
)
index_fpath = _get_index_fpath(dataset, version=version)
with open(index_fpath, "rb") as file:
tiles = gpd.read_file(index_fpath, layer=layer, bbox=bounds, engine='fiona')

if len(tiles) < 1:
raise ValueError(
"No {dataset} mosaic tiles found to intersect with bounds {aoi}"
)
if len(tiles) < 1:
raise ValueError(
"No {dataset} mosaic tiles found to intersect with bounds {aoi}"
)

# get aws filepaths from the tiles dataframe
fpaths = []
for _, row in tiles.iterrows():
fpath = _aws_link(row, dataset=dataset, version=version, resolution=resolution)
fpaths.append(fpath)

# get aws filepaths from the tiles dataframe
fpaths = []
for _, row in tiles.iterrows():
fpath = _aws_link(row, dataset=dataset, version=version, resolution=resolution)
fpaths.append(fpath)
tiles = None # release tiles object

# remove duplicates in 10m and 32m (which load supertiles, not tiles)
fpaths = list(set(fpaths))
Expand All @@ -349,6 +351,7 @@ def mosaic(
# Filter -9999.0 values to np.nan
dem = dem.where(dem > -9999.0)

dems = None # release dem objects for memory management
return dem


Expand Down
Loading