Skip to content

Commit e4c9363

Browse files
committed
better copernicus dem retrieval
1 parent 4e4b8f0 commit e4c9363

5 files changed

Lines changed: 2345 additions & 1047 deletions

File tree

cryogrid_pytools/analyze.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,15 @@ def calc_profile_props(ground_temperature_profile: xr.DataArray) -> xr.Dataset:
3131
assert "depth" in da.coords, "depth dimension is required"
3232
assert "time" in da.dims, "time dimension is required"
3333
assert da.max() < 100, "temperature should be in degrees Celsius"
34-
if 'gridcell' in da.dims:
35-
assert da.sizes['gridcell'] == 1, "You are passing multiple profiles (e.g., dim gridcell size > 1)"
36-
if 'level' in da.dims and 'depth' not in da.dims:
37-
da = da.swap_dims(level='depth')
34+
if "gridcell" in da.dims:
35+
assert da.sizes["gridcell"] == 1, (
36+
"You are passing multiple profiles (e.g., dim gridcell size > 1)"
37+
)
38+
if "level" in da.dims and "depth" not in da.dims:
39+
da = da.swap_dims(level="depth")
3840

3941
depth = da.depth
42+
depth_idx_just_below_surface = abs(depth - 0).argmin().item() + 1
4043

4144
bottom_thawing_mask = detect_bottom_thawing(da)
4245
# create annual version

cryogrid_pytools/data/from_planetary_computer.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,13 @@ def search_stac_items_planetary_computer(collection, bbox, **kwargs) -> list:
5151

5252

5353
@utils._decorator_dataarray_to_bbox
54-
def get_dem_copernicus30(
55-
bbox_WSEN: list, res: int = 30, epsg=32643, smoothing_iters=2, smoothing_size=3
54+
def get_dem_copernicus(
55+
bbox_WSEN: list,
56+
res: int = 30,
57+
epsg=32643,
58+
collection="cop-dem-glo-30",
59+
smoothing_iters=2,
60+
smoothing_size=3,
5661
) -> _xr.DataArray:
5762
"""
5863
Download DEM data from the STAC catalog (default is COP DEM Global 30m).
@@ -66,6 +71,9 @@ def get_dem_copernicus30(
6671
epsg : int, optional
6772
The EPSG code of the projection of the DEM data. Default is
6873
EPSG:32643 (UTM 43N) for the Pamir region.
74+
collection : str, optional
75+
The STAC collection to search for DEM data. Default is "cop-dem-glo-30".
76+
Also supports "cop-dem-glo-90" for 90m resolution.
6977
smoothing_iters : int, optional
7078
The number of iterations to apply the smoothing filter. Default is 2.
7179
Set to 0 to disable smoothing.
@@ -83,9 +91,9 @@ def get_dem_copernicus30(
8391
check_epsg(epsg)
8492

8593
_logger.info(
86-
f"Fetching COP DEM Global data from Planetary Computer (cop-dem-glo-30 @ {res:.2g})"
94+
f"Fetching COP DEM Global data from Planetary Computer ({collection} @ {res:.2g})"
8795
)
88-
items = search_stac_items_planetary_computer("cop-dem-glo-30", bbox_WSEN)
96+
items = search_stac_items_planetary_computer(collection, bbox_WSEN)
8997
da_dem = _stackstac.stack(
9098
items=items, bounds_latlon=bbox_WSEN, resolution=res, epsg=epsg
9199
)
@@ -96,7 +104,7 @@ def get_dem_copernicus30(
96104
.pipe(drop_coords_without_dim)
97105
.pipe(smooth_data, n_iters=smoothing_iters, kernel_size=smoothing_size)
98106
.rio.write_crs(f"EPSG:{epsg}")
99-
.rename("cop_dem_glo_30")
107+
.rename(collection)
100108
.assign_attrs(
101109
source=items[0].links[0].href, # collection URL
102110
bbox_request=bbox_WSEN,

demo.ipynb

Lines changed: 2320 additions & 1035 deletions
Large diffs are not rendered by default.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "cryogrid_pytools"
7-
version = "0.3.11"
7+
version = "0.3.12"
88
description = "Tools to read in CryoGrid MATLAB data to Python and create forcing data"
99
readme = "README.md"
1010
license = "MIT"

uv.lock

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)