Skip to main content

A package for processing digital elevation models.

Project description

TopoCurve Logo

TopoCurve

TopoCurve is a Python library for processing digital elevation models (DEM) stored in GeoTIFF format. This library provides functionalities to extract metadata, calculate principal curvatures and curvature features, as well as plot elevation values. It also includes spectral filtering capabilities for advanced DEM processing.

Installation via pip install

To install TopoCurve, simply pip install:

pip install topocurve

Installation via Git

To install TopoCurve, simply clone the repository and install the dependencies listed in requirements.txt:

git clone https://github.com/username/topo_curve.git
cd topo_curve
pip install -r requirements.txt

Usage & Example from pip install

!pip install topocurve

from topocurve import TopoCurve, SpectralFiltering

# Define the path to the TIFF file
tiff_file = 'path/to/tif'

# Instantiate TopoCurve object
dem = TopoCurve(tiff_file)

# Instantiate SpectralFiltering object
spectral_filter = SpectralFiltering(tiff_file)

# Apply FFT filtering with a lowpass filter at 150-200
dx, dy, ZFilt = spectral_filter.FFT([150, 200], 'lowpass', 0.5)

# Compute curvature attributes
K1, K2, KM, KG, SMAP, SDist, CMAP = dem.CurveCalc(ZFilt1, dx, dy, 0)

# Plot the filtered elevation values
dem.plot(ZFilt,
          title="Filtered DEM (150–500 m)",
          cmap="terrain",
          cbar_label="Elevation (m)",
          filename="filtered_dem_1.png",
          tiff_file=tiff_file)

Usage & Example from git

import os, sys
sys.path.append(os.path.abspath(".."))

from topocurve.TopoCurve import TopoCurve
from topocurve.SpectralFiltering import SpectralFiltering

# Define the path to the TIFF file
tiff_file = 'path/to/tif'

# Instantiate TopoCurve object
dem = TopoCurve(tiff_file)

# Instantiate SpectralFiltering object
spectral_filter = SpectralFiltering(tiff_file)

# Apply FFT filtering with a lowpass filter at 150-200
dx, dy, ZFilt = spectral_filter.FFT([150, 200], 'lowpass', 0.5)

# Compute curvature attributes
K1, K2, KM, KG, SMAP, SDist, CMAP = dem.CurveCalc(ZFilt1, dx, dy, 0)

# Plot the filtered elevation values
dem.plot(ZFilt,
          title="Filtered DEM (150–500 m)",
          cmap="terrain",
          cbar_label="Elevation (m)",
          filename="filtered_dem_1.png",
          tiff_file=tiff_file)

API Documentation

TopoCurve Class

TopoCurve(tiff_file)

Initialize the TopoCurve object with a GeoTIFF file.

  • Parameters:
    • tiff_file (str): Path to the GeoTIFF file.
  • Loads:
    • Elevation array (z_array)
    • DEM dimensions (dimx, dimy)
    • Pixel scale and tiepoints
    • Projected CRS information
    • Ensures uniform grid spacing

CurveCalc(ZFilt, dx, dy, kt)

Compute curvature attributes and the full SMAP classification.

  • Parameters:

    • ZFilt (numpy.ndarray): Filtered DEM surface.
    • dx (float): Grid spacing in x-direction.
    • dy (float): Grid spacing in y-direction.
    • kt (float): Curvature threshold/tolerance.
  • Returns:

    • K1 — minimum principal curvature
    • K2 — maximum principal curvature
    • KM — mean curvature
    • KG — Gaussian curvature
    • SMAP — classification map
    • SDist — distribution statistics
    • CMAP — dictionary of curvatures

get_latlon_extent(tiff_file)

Extract the geographic bounds for plotting.

  • Parameters:

    • tiff_file (str): Path to the DEM GeoTIFF.
  • Returns:

    • [lon_min, lon_max, lat_min, lat_max]

plot(array, title, cmap, cbar_label, filename, tiff_file, output_dir)

Generic plotting function for DEMs, filtered DEMs, and curvature fields.

  • Parameters:
    • array (numpy.ndarray): Data to plot.
    • title (str): Plot title.
    • cmap (str): Colormap name.
    • cbar_label (str): Colorbar label.
    • filename (str): Output filename.
    • tiff_file (str): GeoTIFF used for extent.
    • output_dir (str): Save directory.

plot_smap(SMAP, tiff_file, title, output_dir)

Plot the SMAP classification using hillshade + color overlays.

  • Parameters:

    • SMAP (numpy.ndarray): Classification map.
    • tiff_file (str): GeoTIFF used for extent.
    • title (str): Plot title.
    • output_dir (str): Save directory.
  • Produces:

    • Hillshade grayscale base
    • SMAP overlay with transparency
    • Full legend for all 7 classes
    • Saves as smap.png

Spectral Filtering Class

SpectralFiltering(tiff_file)

Initialize the SpectralFiltering object with a GeoTIFF file.

  • Parameters:
    • tiff_file (str): Path to the GeoTIFF file.

detrend()

Detrend the elevation values using least squares plane fitting.

  • Returns:
    • Z_detrended (numpy.ndarray): Detrended elevation values.
    • plane (numpy.ndarray): Trend component of the elevation values.

mirror_dem()

Mirror the elevation values.

  • Returns:
    • mirrored_array (numpy.ndarray): Mirrored elevation values.

tukeyWindow(alphaIn)

Apply a Tukey window to the elevation values.

  • Arguments:

    • alphaIn (float): Parameter controlling the shape of the Tukey window.
  • Returns:

    • tukey_array (numpy.ndarray): Elevation values after applying the Tukey window.

padding(alphaIn)

Pad the elevation values.

  • Arguments:

    • alphaIn (float): Parameter controlling the shape of the Tukey window.
  • Returns:

    • padded_window_array (numpy.ndarray): Padded elevation values.

FFT(filter, filterType, alphaIn)

Apply FFT filtering to the elevation values.

  • Arguments:

    • filter (float): Filter parameter.
    • filterType (str): Type of filter ('lowpass' or 'highpass').
    • alphaIn (float): Parameter controlling the shape of the Tukey window.
  • Returns:

    • dx (float): Grid spacing in the x direction.
    • dy (float): Grid spacing in the y direction.
    • ZFilt (numpy.ndarray): Filtered elevation values.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project Organization

├── LICENSE
├── Makefile
├── README.md
├── TC-removebg-preview.png         # Project logo

├── docs/                           # Sphinx documentation
│   ├── Makefile
│   ├── commands.rst
│   ├── conf.py
│   ├── getting-started.rst
│   ├── index.rst
│   └── make.bat

├── references/                     # Background sources, DEMs, papers
│   ├── DEM_files/                  # Sample DEM test datasets
│   ├── paper.md                    # Project report / research notes
│   └── .gitkeep

├── reports/                        # Generated results
│   ├── figures/                    # Auto-saved plots from TopoCurve
│   └── .gitkeep

├── requirements.txt
├── setup.py
├── test_environment.py
├── tox.ini

├── src/                            # All Python source code
│   ├── __init__.py
│   ├── test.py                     # Basic tests
│   │
│   ├── topocurve/                  # Core TopoCurve library (importable)
│   │   ├── __init__.py
│   │   ├── TopoCurve.py            # DEM loading, curvature, SMAP, plotting
│   │   └── SpectralFiltering.py    # FFT low/high/bandpass filtering tools
│   │
│   ├── test_scripts/               # Example notebooks + reproducible demos
│   │   ├── example.ipynb
│   │   ├── example_sphere.ipynb
│   │   └── Reversibility_Test.py
│   │
│   └── code_play.py                # Sandbox for experimentation

└── .env                            # Local virtual environment (ignored)
        

Credits

Project based on the cookiecutter data science project template. #cookiecutterdatascience

```

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

topocurve-0.1.2.tar.gz (13.9 kB view details)

Uploaded Source

Built Distribution

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

topocurve-0.1.2-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file topocurve-0.1.2.tar.gz.

File metadata

  • Download URL: topocurve-0.1.2.tar.gz
  • Upload date:
  • Size: 13.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.1

File hashes

Hashes for topocurve-0.1.2.tar.gz
Algorithm Hash digest
SHA256 a676ee7134d279c95efb5c11eacff45c63913fdffc3c7c01dda4bdd6efb1de5d
MD5 9561128a6169324072e005e828e347f6
BLAKE2b-256 c72f82eb1044a2d916410222b2ea4b4a7ce04592675c78e4702859e6bfe7dca6

See more details on using hashes here.

File details

Details for the file topocurve-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: topocurve-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.1

File hashes

Hashes for topocurve-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d3342b6ef67e2fc4b97945c087755cb4a64628b2b72c480d730698f5b3fe3aea
MD5 2e6ed22290aa8950e23c2b6f992aeabd
BLAKE2b-256 9a1e565e4865427f6504b8166773f550c567fcafa50f184c4669dfc6ef993020

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