Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 50 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,22 @@ This Python software package provides a comprehensive solution for handling grid

[Gregory H. Halverson](https://github.com/gregory-halverson-jpl) (they/them)<br>
[gregory.h.halverson@jpl.nasa.gov](mailto:gregory.h.halverson@jpl.nasa.gov)<br>
NASA Jet Propulsion Laboratory 329G
NASA Jet Propulsion Laboratory 321H

## Citing this Package

If you use `rasters` in your research or software pipelines, please cite it using the following BibTeX entry:

```bibtex
@software{halverson_rasters_2026,
author = {Halverson, Gregory H.},
title = {rasters: Object-Oriented Gridded and Swath Raster Processing Toolkit for Python},
year = {2026},
version = {1.21.0},
publisher = {GitHub},
url = {https://github.com/python-rasters/rasters}
}
```

The software addresses several challenges in the field. It makes swath remote sensing datasets more accessible and easier to work with. It also associates coordinate reference systems with vector geometries, simplifying transformations between projections.

Expand Down Expand Up @@ -37,7 +52,7 @@ This software improves over the rasterio package by encapsulating rasters as obj

This software solves the problem of swath remote sensing datasets being inaccessible and difficult to work with. This software solves the problem of vector geometries in python not having coordinate reference systems associated with them. The software is inspired by and intended to be a python equivalent for the raster package in R and the Rasters.jl package in Julia.

### Does your work relate to current or future NASA (include reimbursable) work that has value to the conduct of aeronautical and space activities?  If so, please explain:
### Does your work relate to current or future NASA (include reimbursable) work that has value to the conduct of aeronautical and space activities? If so, please explain:

This software package was developed as part of a research grant by the NASA Research Opportunities in Space and Earth Sciences (ROSES) program. This software was designed for use by the Ecosystem Spaceborne Thermal Radiometer Experiment on Space Station (ECOSTRESS) mission as a precursor for the Surface Biology and Geology (SBG) mission, but it may be useful generally for remote sensing and GIS projects in python.

Expand All @@ -63,7 +78,7 @@ This software is written entirely in python and intended to be distributed using

This software has been deployed for ECOSTRESS and ET-Toolbox.

### Please identify the customer(s) and sponsors(s) outside of your section that requested and are using your software. 
### Please identify the customer(s) and sponsors(s) outside of your section that requested and are using your software.

This package is being released according to the SPD-41 open-science requirements of NASA-funded ROSES projects.

Expand Down Expand Up @@ -417,9 +432,36 @@ masked_raster = raster.mask(mask)
# Fill masked values with another raster
filled = raster.fill(fill_raster)
```

## Changelog

### 1.1.0

The `KDTree` class can now save to file with the `.save` method and load from file with the `KDTree.load` class method.
## History

* **`v1.0.2` – `v1.2.0` (June – September 2024):** Launched as a single-file package (`rasters/rasters.py`) adapted from ECOSTRESS workflows at NASA JPL. Refactored vector geometry classes (`Point`, `MultiPoint`, `Polygon`, `MultiPolygon`) from Shapely inheritance to composition with explicit CRS tracking, added `msgpack` serialization (`KDTree.save()` and `KDTree.load()`), added `.wkt` representations, and switched swath point lookup to `scipy.spatial.cKDTree`.
* **`v1.3.0` – `v1.4.6` (September 2024 – February 2025):** Split the monolith into dedicated single-responsibility modules (`CRS.py`, `bbox.py`, `point.py`, `polygon.py`, `kdtree.py`, `raster.py`, `raster_grid.py`, `raster_geolocation.py`, etc.), dropped the deprecated `pygeos` dependency in favor of `shapely` 2.x, added point extraction via `Raster.open(..., geometry=Point)`, added grid shifting (`RasterGrid.shift_xy()`, `shift_distance()`), and resolved macOS `pykdtree` build issues (`pykdtree>=1.3.11`).
* **`v1.5.0` – `v1.16.1` (April – November 2025):** Added `linear_downscale()` and `bias_correct()`, configurable resampling in `mosaic()`, `MultiPoint` extraction in `Raster.open()`, `RasterGeolocation.window()` and `.subset()`, square-bracket geometry indexing (`grid[polygon]`, `geolocation[window]`), `GeoSeries` to `MultiPoint` wrapping, `Point.lat`/`Point.lon` properties, `RasterGrid` bounds properties (`xmin`, `xmax`, `ymin`, `ymax`), and multi-raster mosaicking/masking fixes.
* **`v1.17.0` – `v1.21.0` (January – November 2026):** Expanded module docstrings and documentation, added `BBox.boundary_latlon`, expanded CI test coverage across Python `3.11`–`3.14`, fixed `BBox` handling in `wrap_geometry()`, and resolved deprecation warnings under Shapely 2.2+ (`shapely.transform()`), `affine` 2.4+ (`@` matrix multiplication), and NumPy 2.0+ (`__array_wrap__`).

## Known Issues

The following known issues are tracked in the [GitHub issue tracker](https://github.com/python-rasters/rasters/issues) as of `v1.21.0`:

* **Vector & Geometry Edge Cases:**
* Calling `Polygon()` or `MultiPolygon()` with no arguments raises an `IndexError` instead of initializing an empty geometry ([#74](https://github.com/python-rasters/rasters/issues/74)).
* `RasterGeometry.point` returns a `ValueError` instance rather than raising it when the geometry is not a single cell ([#78](https://github.com/python-rasters/rasters/issues/78)).
* `BBox.round` truncates coordinates to whole integers without supporting an `ndigits` precision argument ([#85](https://github.com/python-rasters/rasters/issues/85)).
* `rasters/local_UTM_proj4_from_lat_lon.py` is an orphaned stub file with an empty function definition superseded by `rasters/local_UTM_proj4.py` ([#71](https://github.com/python-rasters/rasters/issues/71)).
* **Raster Indexing, Slicing & Grid Operations:**
* `Raster.__setitem__()` fails on slice and tuple-slice assignments (`raster[0:5] = 0`, `raster[0:5, 0:5] = 0`) ([#75](https://github.com/python-rasters/rasters/issues/75)).
* Single-dimension indexing (`raster[0]` or `raster[0:5]`) raises a `TypeError` in `Raster._key()` ([#76](https://github.com/python-rasters/rasters/issues/76)).
* `Raster._slice()` mutates array view shapes in-place (`result.shape = new_shape`), failing on non-contiguous slices ([#82](https://github.com/python-rasters/rasters/issues/82)).
* `RasterGrid.resolution()` raises a `TypeError` when passed a scalar `float` instead of a tuple ([#77](https://github.com/python-rasters/rasters/issues/77)).
* `Raster.origin` delegates to a nonexistent `self.geometry.origin` attribute ([#79](https://github.com/python-rasters/rasters/issues/79)).
* `Raster.rescale()` resizes the data array to the original `(self.rows, self.cols)` shape instead of the target `(geometry.rows, geometry.cols)` shape ([#83](https://github.com/python-rasters/rasters/issues/83)).
* **MultiRaster, Mosaicking & Reprojection:**
* `MultiRaster.contain()` / `MultiRaster.__init__()` nests `metadata` under a `"metadata"` key instead of unpacking it ([#80](https://github.com/python-rasters/rasters/issues/80)).
* `Raster.to_grid()` raises a `TypeError` on boolean rasters when `nodata` is `None` ([#81](https://github.com/python-rasters/rasters/issues/81)).
* `mosaic()` fails on generator/iterator inputs and evaluates `geometry.shape` before resolving default geometry from `images[0]` ([#84](https://github.com/python-rasters/rasters/issues/84)).
* **File I/O, Testing & Warnings:**
* `Raster.from_geotiff()` calls a nonexistent `cls.from_file()` method and rejects `.tiff` extensions due to operator precedence ([#72](https://github.com/python-rasters/rasters/issues/72)).
* `Raster.to_COG()` invokes `gdal_translate` via `os.system()` without checking exit status and uses naive `.replace(".tif", ".temp.tif")` path substitution ([#87](https://github.com/python-rasters/rasters/issues/87)).
* `RasterGeometry` uses `warnings.filterwarnings('ignore')` followed by `warnings.resetwarnings()` instead of `with warnings.catch_warnings()`, clearing external warning filters ([#86](https://github.com/python-rasters/rasters/issues/86)).
* `tests/test_write_geotiff.py` is currently an empty placeholder without GeoTIFF write tests ([#73](https://github.com/python-rasters/rasters/issues/73)).
141 changes: 114 additions & 27 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,45 +1,132 @@
# Python version for environment creation
PYTHON_VERSION ?= 3.14
# Define the package name, module name, environment name, and Python version
PACKAGE_NAME = rasters
MODULE_NAME = $(subst -,_,$(PACKAGE_NAME))
ENVIRONMENT_NAME = $(PACKAGE_NAME)
PYTHON_VERSION = $(if $(PYTHON),$(PYTHON),3.13)

.PHONY: clean test build twine-upload dist environment install uninstall reinstall test
# Allow passing extra flags via command line: make <target> ARGS="-k test_name"
ARGS ?=

clean:
# Include a Makefile.local to override things, if found
-include Makefile.local

.DEFAULT_GOAL := help

.PHONY: help clean test build wheel sdist twine-upload dist \
install uninstall reinstall environment remove-environment \
repomix generate-history show-issues

help: ## Show available targets
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-28s\033[0m %s\n", $$1, $$2}'

##@ Cleanup & Environment
clean: ## Remove build artifacts, caches, coverage files, and logs
rm -rf *.o *.out *.log
rm -rf build/
rm -rf dist/
rm -rf *.egg-info
rm -rf .pytest_cache
rm -rf htmlcov/ .coverage
rm -rf $(PACKAGE_NAME)-repomix.xml repomix-output.xml release_diffs.patch
find . -type d -name "__pycache__" -exec rm -rf {} +
find . -type f -name "*.py[co]" -delete

test:
pytest
environment: ## Create a new Conda/Mamba environment (override with PYTHON=3.12)
mamba create -y -n $(ENVIRONMENT_NAME) -c conda-forge python=$(PYTHON_VERSION) jupyter

build:
python -m build
remove-environment: ## Remove the Conda/Mamba environment
mamba env remove -y -n $(ENVIRONMENT_NAME)

twine-upload:
twine upload dist/*
install: ## Install the package in editable mode with development dependencies
pip install -e .[dev]

dist:
make clean
make build
make twine-upload
uninstall: ## Uninstall the package
pip uninstall -y $(PACKAGE_NAME)

environment:
mamba create -y -n rasters python=$(PYTHON_VERSION) jupyter
reinstall: ## Reinstall the package (uninstall and then install)
$(MAKE) uninstall
$(MAKE) install

remove-environment:
mamba env remove -y -n rasters
##@ Testing & Verification
test: ## Run Python unit tests using pytest
pytest -vv $(ARGS)

install:
pip install -e .[dev]
##@ Packaging & Release
wheel: ## Build the Python wheel
python -m build --wheel

sdist: ## Build the Python source distribution
python -m build --sdist

build: ## Build the Python wheel and source distribution
python -m build

twine-upload: ## Upload the built package to PyPI using Twine
twine upload dist/*

dist: ## Clean, build, and upload the package to PyPI
$(MAKE) clean
$(MAKE) build
$(MAKE) twine-upload

uninstall:
pip uninstall -y rasters
##@ Utilities
repomix: ## Pack repository context for LLM review
npx repomix -o $(PACKAGE_NAME)-repomix.xml --ignore "**/*.tif,**/*.tiff,**/*.png,**/*.jpg,**/*.jpeg,**/*.aux.xml,**/*.csv,**/*.pdf,**/*.svg,**/*.ipynb,*-repomix*.xml,repomix-output.xml,release_diffs.patch" --copy

reinstall:
make uninstall
make install
generate-history: ## Generate release commit history patch
fish -c ' \
git fetch --tags --quiet; \
set first_commit (git rev-list --max-parents=0 HEAD | head -n 1); \
set releases (gh release list --limit 1000 --json tagName,createdAt --jq "sort_by(.createdAt) | .[].tagName"); \
begin; \
echo "========================================"; \
echo "REPOSITORY RELEASE TIMELINE"; \
echo "========================================"; \
gh release list --limit 1000; \
echo ""; \
if test (count $$releases) -ge 1; \
set first_rel $$releases[1]; \
echo "========================================"; \
echo "INITIAL COMMIT ($$first_commit) -> FIRST RELEASE ($$first_rel)"; \
echo "========================================"; \
git log --reverse --stat -p $$first_rel -- "*.py" "pyproject.toml"; \
echo ""; \
end; \
if test (count $$releases) -ge 2; \
for i in (seq 2 (count $$releases)); \
set prev_idx (math $$i - 1); \
set prev $$releases[$$prev_idx]; \
set curr $$releases[$$i]; \
echo "========================================"; \
echo "RELEASE COMMIT HISTORY: $$prev -> $$curr"; \
echo "========================================"; \
git log --reverse --stat -p $$prev..$$curr -- "*.py" "pyproject.toml"; \
echo ""; \
end; \
end; \
if test (count $$releases) -ge 1; \
set latest_rel $$releases[-1]; \
echo "========================================"; \
echo "LATEST RELEASE ($$latest_rel) -> CURRENT WORKING TREE (HEAD + UNCOMMITTED)"; \
echo "========================================"; \
git log --reverse --stat -p $$latest_rel..HEAD -- "*.py" "pyproject.toml"; \
echo ""; \
git status -s -- "*.py" "pyproject.toml"; \
echo ""; \
git diff HEAD -- "*.py" "pyproject.toml"; \
else; \
echo "========================================"; \
echo "INITIAL COMMIT ($$first_commit) -> CURRENT WORKING TREE"; \
echo "========================================"; \
git log --reverse --stat -p -- "*.py" "pyproject.toml"; \
echo ""; \
git status -s -- "*.py" "pyproject.toml"; \
echo ""; \
git diff HEAD -- "*.py" "pyproject.toml"; \
end; \
end > release_diffs.patch; \
'

repomix:
npx repomix --ignore "**/*.tif,**/*.png,**/*.jpeg,**/*.aux.xml,**/*.ipynb"
show-issues: ## List open GitHub issues
gh issue list --state open --json number,title,body --template '{{range .}}## #{{.number}}: {{.title}}{{"\n\n"}}{{.body}}{{"\n\n---\n\n"}}{{end}}'
Loading
Loading