Skip to main content

Dask aware lightweight DEM utilities for Xarray

Project description

xCorduroy - Dask aware lightweight DEM utilities for Xarray

xcorduroy is a lightweight [dask, numpy, xarray and xproj] Xarray accessor for library for calculating hillshade, slope angle and aspects from DEMs.

** Warning: experimental**

Usage

Installation

uv add "xcorduroy @ git+https://github.com/norlandrhagen/corduroy"
# or 
pip install "git+https://github.com/norlandrhagen/corduroy"

Notebooks

An example notebook can be found in notebooks/DEM_example.ipynb

Example

import xarray as xr
import xcorduroy # This is needed for the .dem accessor
import xproj # This is needed for the .proj accessor

# Load a 2D Raster DEM
ds = xr.open_dataset("DEM.zarr", engine="zarr", chunks="auto")

# Make sure you have a crs registered
ds = ds.proj.assign_crs("EPSG:4326")

# Calculate hillshade. Note you can use the `dem` accessor.
hillshade = ds['dem'].dem.hillshade()
slope = ds['dem'].dem.slope()
aspect = ds['dem'].dem.aspect()


# Plotting
fig, axes = plt.subplots(2, 2, figsize=(12, 10), sharex=True, sharey=True)

ds['dem'].plot(ax=axes[0, 0], cmap='terrain', add_colorbar=True)
axes[0, 0].set_title("Input DEM")

slope.plot(ax=axes[0, 1], cmap='magma')
axes[0, 1].set_title("Slope")

aspect.plot(ax=axes[1, 0], cmap='twilight')
axes[1, 0].set_title("Aspect")

hillshade.plot(ax=axes[1, 1], cmap='gray')
axes[1, 1].set_title("Hillshade")

plt.tight_layout()

Methods

The three current methods implemented are .hillshade(), .slope() and .aspect(). The hillshade method is based off of the Horn, 1981 method. Details can be found in src/corduroy/DEM.py. They are inspired by similar methods in xdem and xarray-spatial. If you are looking for well-validated functions for scientific analysis, check out either of them. This library is a limited scope lightweight take on some of the methods, not a replacement.

Development

This project uses uv for dependency management, pytest and hypothesis for testing, ty for type-checking and ruff for linting.

Sync development environment

uv sync --all-extras

Run type checking

uv run ty check 

Run linter

uv run pre-commit run all-files

Run tests

uv run pytest tests/

What's in the name

Corduroy is a textured snow surface left by groomers that forms regular peaks and valleys.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xcorduroy-0.0.1.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xcorduroy-0.0.1-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file xcorduroy-0.0.1.tar.gz.

File metadata

  • Download URL: xcorduroy-0.0.1.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for xcorduroy-0.0.1.tar.gz
Algorithm Hash digest
SHA256 e6641b04b614bca5d9d0dde21f89ee620522a71e2f8f612ac71215a2f24c09f6
MD5 c9f13feffe4028e30fa38fee6f08e9b9
BLAKE2b-256 897d126b99b0a74045d90418e35fcbd5dc35a41b259b067fbe71b3da4e4a6e2e

See more details on using hashes here.

File details

Details for the file xcorduroy-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: xcorduroy-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for xcorduroy-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7aa362edf3d748085e4c4b5db59041d3dee67948b2677254d2d83ee0abb5567c
MD5 503c3397ce03e734191214b2d1424099
BLAKE2b-256 660168acc6098065a16b3f738449a433706251a9e235bb5af70317d06344369c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page