Metadata-Version: 2.4
Name: topocurve
Version: 0.1.2
Summary: A package for processing digital elevation models.
Home-page: https://github.com/tschermer02/topoCurve1
Author: Taylor Schermer, Joel Nash, Nate Klema
Author-email: tschermer@fortlewis.edu, jxnash@fortlewis.edu, ntklema@fortlewis.edu
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Requires-Python: >=3.6
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy<2
Requires-Dist: scipy
Requires-Dist: zarr<2.13
Requires-Dist: numcodecs<0.12
Requires-Dist: Pillow
Requires-Dist: photutils<2.0,>=1.8
Requires-Dist: tifffile<2024.8
Requires-Dist: geotiff
Requires-Dist: scikit-learn
Requires-Dist: rasterio
Requires-Dist: pyproj
Requires-Dist: matplotlib
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license-file
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

![TopoCurve Logo](./TC-removebg-preview.png)

# 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

- **Principal Contributor:** [Taylor Schermer](https://github.com/tschermer02)
- **Contributions:**  [Joel Nash](https://github.com/jxnash), [Nate Klema](https://github.com/ntklema), [Leif Karlstrom](https://github.com/leifkarlstrom)



<p><small>Project based on the <a target="_blank" href="https://drivendata.github.io/cookiecutter-data-science/">cookiecutter data science project template</a>. #cookiecutterdatascience</small></p>
```
