A Python package for satellite image processing with fluent interface
Project description
satfarm
A Python package for satellite image processing with a fluent interface, built on top of rasterio and xarray.
🌟 Features
- Raster data I/O: Support for GeoTIFF, PNG, and other common formats
- Coordinate reference system: Transformation and resampling capabilities
- Band operations: Spectral index calculations and band manipulations
- Image rendering: Visualization with customizable color maps
- Geometric operations: Clipping, shrinking, and spatial transformations
- Fluent interface: Chain operations together for readable, maintainable code
📦 Installation
pip install satfarm
Development Installation
git clone https://github.com/yourusername/satfarm.git
cd satfarm
pip install -e ".[dev]"
🚀 Quick Start
from satfarm import SatImage
import numpy as np
# Basic usage
processor = SatImage()
# Load and process satellite imagery
result = (processor
.read_tif("path/to/satellite_image.tif")
.change_pixel_dtype("float32")
.change_nodata(new_nodata=np.nan, old_nodata=0)
.reproject("EPSG:4326")
.shrink(distance=30)
.set_band_alias(["red", "green", "blue", "nir"])
.to_tif("processed_image.tif")
)
print(result)
📖 Examples
Spectral Index Calculation
from satfarm import SatImage
# Load image and set band aliases
simage = (SatImage()
.read_tif("multispectral_image.tif")
.set_band_alias(["blue", "green", "red", "nir"])
)
# Calculate vegetation indices
equations = {
"NDVI": "(B[4] - B[3]) / (B[4] + B[3])",
"NDRE": "(B[4] - B[2]) / (B[4] + B[2])",
"SAVI": "1.5 * (B[4] - B[3]) / (B[4] + B[3] + 0.5)"
}
# Process multiple indices
index_images = list(simage.calculate_index(equations))
for idx_img in index_images:
print(f"Index: {idx_img.get_band_alias()}")
stats = idx_img.calculate_band_stats()
print(f"Statistics: {stats}")
Image Rendering and Visualization
# Render index with custom colormap
rendered = (index_images[0] # NDVI
.render_index(vmin=0, vmax=1, cmap="viridis")
.rescale(0.5) # Reduce resolution by 50%
.to_png("ndvi_visualization.png")
)
Image Merging and Analysis
# Merge multiple index images
merged = SatImage().merge(index_images)
# Get image boundary
boundary = merged.get_boundary()
# Calculate comprehensive statistics
stats = merged.calculate_band_stats()
🏗️ API Reference
Core Class
SatImage
The main class providing a fluent interface for satellite image processing.
Key Methods:
-
I/O Operations
read_tif(path): Load GeoTIFF filesto_tif(path): Save as GeoTIFFto_png(path): Save as PNG
-
Data Manipulation
change_pixel_dtype(dtype): Convert pixel data typechange_nodata(new_nodata, old_nodata): Update nodata valuesreproject(crs): Reproject to different coordinate systemrescale(factor): Resize image by scaling factorshrink(distance): Reduce image extent by specified distance
-
Band Operations
set_band_alias(aliases): Assign names to bandsextract_band(bands): Select specific bandsapply_scale_factor(factors): Apply scaling factors to bandscalculate_index(equations): Compute spectral indices
-
Analysis
calculate_band_stats(): Compute statistical metricsget_boundary(): Extract image boundary geometry
-
Visualization
render_index(vmin, vmax, cmap): Render with color mapping
-
Utilities
copy(): Create deep copymerge(images): Combine multiple imagesis_empty(): Check if image data exists
🔧 Dependencies
- numpy (>=1.21.0): Numerical computing
- rioxarray (>=0.13.0): Rasterio integration with xarray
- geopandas (>=0.12.0): Geospatial data handling
- Pillow (>=9.0.0): Image processing
- matplotlib (>=3.5.0): Plotting and visualization
- typeguard (>=4.0.0): Runtime type checking
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the project
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
- Built on top of the excellent rasterio and xarray libraries
- Inspired by modern geospatial processing workflows
- Thanks to the open source geospatial community
📞 Support
If you encounter any issues or have questions, please open an issue on GitHub.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file satfarm-0.1.3.tar.gz.
File metadata
- Download URL: satfarm-0.1.3.tar.gz
- Upload date:
- Size: 18.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0bf90c20c6a1207cdea2f918f147a0d8b3df6dd36d3642ad45aa61364a3f561c
|
|
| MD5 |
a4e26ac67d3ae7298b4f8470d4c4c94d
|
|
| BLAKE2b-256 |
9b14e28bb25244e3361b36cd5c9c50c1d923c36c9ed51e8041980b8abf488d7b
|
File details
Details for the file satfarm-0.1.3-py3-none-any.whl.
File metadata
- Download URL: satfarm-0.1.3-py3-none-any.whl
- Upload date:
- Size: 23.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1127687b625daf74d1b9a0c5980c0d06e308f695115aa9d6ec967c9f97bd5223
|
|
| MD5 |
53acb54d0837f901f76fe79346ab8289
|
|
| BLAKE2b-256 |
317c9b0b40e0af1ff70deecc947898085e8cef9f55387ea628bdec9aa1dbd162
|