Skip to content

Commit

Permalink
Revert rioxarray usage and unify to DEM and landmask loading
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexeyPechnikov committed Feb 25, 2024
1 parent 351e368 commit de11de6
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pygmtsar/pygmtsar/AWS.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def download_dem(self, geometry, filename=None, n_jobs=-1, product='1s', skip_ex
dem.plot.imshow()
"""
import xarray as xr
import rioxarray as rio
import geopandas as gpd
import numpy as np
from tqdm.auto import tqdm
Expand Down Expand Up @@ -53,7 +54,8 @@ def job_tile(product, lon, lat):
if response.status_code != 200:
return None
with io.BytesIO(response.content) as f:
tile = xr.open_dataarray(f, engine='rasterio')\
#tile = xr.open_dataarray(f, engine='rasterio')
tile = rio.open_rasterio(f, chunks=self.chunksize)\
.squeeze(drop=True)\
.rename({'y': 'lat', 'x': 'lon'})\
.drop_vars('spatial_ref')\
Expand All @@ -69,7 +71,7 @@ def job_tile(product, lon, lat):
tile_xarrays = joblib.Parallel(n_jobs=n_jobs)(joblib.delayed(job_tile)(product, x, y)\
for x in range(left, right + 1) for y in range(lower, upper + 1))

dem = xr.combine_by_coords([tile for tile in tile_xarrays if tile is not None])['band_data']
dem = xr.combine_by_coords([tile for tile in tile_xarrays if tile is not None])
bounds = self.get_bounds(geometry)
dem = dem.sel(lat=slice(bounds[1], bounds[3]), lon=slice(bounds[0], bounds[2]))

Expand Down

0 comments on commit de11de6

Please sign in to comment.