satimg 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- satimg-0.3.0/.gitignore +168 -0
- satimg-0.3.0/LICENSE +21 -0
- satimg-0.3.0/PKG-INFO +178 -0
- satimg-0.3.0/README.md +147 -0
- satimg-0.3.0/pyproject.toml +66 -0
- satimg-0.3.0/src/satimg/__init__.py +65 -0
- satimg-0.3.0/src/satimg/connectors/__init__.py +46 -0
- satimg-0.3.0/src/satimg/connectors/_auth.py +78 -0
- satimg-0.3.0/src/satimg/connectors/_credentials.py +51 -0
- satimg-0.3.0/src/satimg/connectors/base.py +93 -0
- satimg-0.3.0/src/satimg/connectors/landsat.py +67 -0
- satimg-0.3.0/src/satimg/connectors/sentinel.py +81 -0
- satimg-0.3.0/src/satimg/deepzoom.py +76 -0
- satimg-0.3.0/src/satimg/geometry.py +181 -0
- satimg-0.3.0/src/satimg/landmask.py +28 -0
- satimg-0.3.0/src/satimg/prediction/__init__.py +14 -0
- satimg-0.3.0/src/satimg/prediction/detector.py +91 -0
- satimg-0.3.0/src/satimg/prediction/models.py +46 -0
- satimg-0.3.0/src/satimg/prediction/nms.py +148 -0
- satimg-0.3.0/src/satimg/prediction/types.py +36 -0
- satimg-0.3.0/src/satimg/product.py +142 -0
- satimg-0.3.0/src/satimg/products/__init__.py +7 -0
- satimg-0.3.0/src/satimg/products/landsat.py +86 -0
- satimg-0.3.0/src/satimg/products/sentinel1.py +107 -0
- satimg-0.3.0/src/satimg/products/sentinel2.py +95 -0
- satimg-0.3.0/src/satimg/raster.py +233 -0
- satimg-0.3.0/src/satimg/readers.py +36 -0
- satimg-0.3.0/src/satimg/registry.py +58 -0
- satimg-0.3.0/src/satimg/transform.py +73 -0
satimg-0.3.0/.gitignore
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
data/*
|
|
10
|
+
examples/*
|
|
11
|
+
# Distribution / packaging
|
|
12
|
+
.Python
|
|
13
|
+
build/
|
|
14
|
+
develop-eggs/
|
|
15
|
+
dist/
|
|
16
|
+
downloads/
|
|
17
|
+
eggs/
|
|
18
|
+
.eggs/
|
|
19
|
+
lib/
|
|
20
|
+
lib64/
|
|
21
|
+
parts/
|
|
22
|
+
sdist/
|
|
23
|
+
var/
|
|
24
|
+
wheels/
|
|
25
|
+
share/python-wheels/
|
|
26
|
+
*.egg-info/
|
|
27
|
+
.installed.cfg
|
|
28
|
+
*.egg
|
|
29
|
+
MANIFEST
|
|
30
|
+
|
|
31
|
+
# PyInstaller
|
|
32
|
+
# Usually these files are written by a python script from a template
|
|
33
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
34
|
+
*.manifest
|
|
35
|
+
*.spec
|
|
36
|
+
|
|
37
|
+
# Installer logs
|
|
38
|
+
pip-log.txt
|
|
39
|
+
pip-delete-this-directory.txt
|
|
40
|
+
|
|
41
|
+
# Unit test / coverage reports
|
|
42
|
+
htmlcov/
|
|
43
|
+
.tox/
|
|
44
|
+
.nox/
|
|
45
|
+
.coverage
|
|
46
|
+
.coverage.*
|
|
47
|
+
.cache
|
|
48
|
+
nosetests.xml
|
|
49
|
+
coverage.xml
|
|
50
|
+
*.cover
|
|
51
|
+
*.py,cover
|
|
52
|
+
.hypothesis/
|
|
53
|
+
.pytest_cache/
|
|
54
|
+
cover/
|
|
55
|
+
|
|
56
|
+
# Translations
|
|
57
|
+
*.mo
|
|
58
|
+
*.pot
|
|
59
|
+
|
|
60
|
+
# Django stuff:
|
|
61
|
+
*.log
|
|
62
|
+
local_settings.py
|
|
63
|
+
db.sqlite3
|
|
64
|
+
db.sqlite3-journal
|
|
65
|
+
|
|
66
|
+
# Flask stuff:
|
|
67
|
+
instance/
|
|
68
|
+
.webassets-cache
|
|
69
|
+
|
|
70
|
+
# Scrapy stuff:
|
|
71
|
+
.scrapy
|
|
72
|
+
|
|
73
|
+
# Sphinx documentation
|
|
74
|
+
docs/_build/
|
|
75
|
+
|
|
76
|
+
# PyBuilder
|
|
77
|
+
.pybuilder/
|
|
78
|
+
target/
|
|
79
|
+
|
|
80
|
+
# Jupyter Notebook
|
|
81
|
+
.ipynb_checkpoints
|
|
82
|
+
|
|
83
|
+
# IPython
|
|
84
|
+
profile_default/
|
|
85
|
+
ipython_config.py
|
|
86
|
+
|
|
87
|
+
# pyenv
|
|
88
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
89
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
90
|
+
# .python-version
|
|
91
|
+
|
|
92
|
+
# pipenv
|
|
93
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
94
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
95
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
96
|
+
# install all needed dependencies.
|
|
97
|
+
#Pipfile.lock
|
|
98
|
+
|
|
99
|
+
# poetry
|
|
100
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
101
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
102
|
+
# commonly ignored for libraries.
|
|
103
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
104
|
+
#poetry.lock
|
|
105
|
+
|
|
106
|
+
# pdm
|
|
107
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
108
|
+
#pdm.lock
|
|
109
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
110
|
+
# in version control.
|
|
111
|
+
# https://pdm.fming.dev/#use-with-ide
|
|
112
|
+
.pdm.toml
|
|
113
|
+
|
|
114
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
115
|
+
__pypackages__/
|
|
116
|
+
|
|
117
|
+
# Celery stuff
|
|
118
|
+
celerybeat-schedule
|
|
119
|
+
celerybeat.pid
|
|
120
|
+
|
|
121
|
+
# SageMath parsed files
|
|
122
|
+
*.sage.py
|
|
123
|
+
|
|
124
|
+
# Environments
|
|
125
|
+
.env
|
|
126
|
+
.venv
|
|
127
|
+
env/
|
|
128
|
+
venv/
|
|
129
|
+
ENV/
|
|
130
|
+
env.bak/
|
|
131
|
+
venv.bak/
|
|
132
|
+
|
|
133
|
+
# Spyder project settings
|
|
134
|
+
.spyderproject
|
|
135
|
+
.spyproject
|
|
136
|
+
|
|
137
|
+
# Rope project settings
|
|
138
|
+
.ropeproject
|
|
139
|
+
|
|
140
|
+
# mkdocs documentation
|
|
141
|
+
/site
|
|
142
|
+
|
|
143
|
+
# mypy
|
|
144
|
+
.mypy_cache/
|
|
145
|
+
.dmypy.json
|
|
146
|
+
dmypy.json
|
|
147
|
+
|
|
148
|
+
# Pyre type checker
|
|
149
|
+
.pyre/
|
|
150
|
+
|
|
151
|
+
# pytype static type analyzer
|
|
152
|
+
.pytype/
|
|
153
|
+
|
|
154
|
+
# Cython debug symbols
|
|
155
|
+
cython_debug/
|
|
156
|
+
|
|
157
|
+
# PyCharm
|
|
158
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
159
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
160
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
161
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
162
|
+
#.idea/
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
# macOS stores DS_Store files on remote file systems.
|
|
166
|
+
.DS_Store
|
|
167
|
+
/.idea/
|
|
168
|
+
/tests/**/tmp/
|
satimg-0.3.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 peachfuzz11
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
satimg-0.3.0/PKG-INFO
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: satimg
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: A uniform, tile-friendly wrapper over satellite imagery
|
|
5
|
+
Project-URL: Homepage, https://github.com/peachfuzz11/satimg
|
|
6
|
+
Project-URL: Repository, https://github.com/peachfuzz11/satimg
|
|
7
|
+
Project-URL: Issues, https://github.com/peachfuzz11/satimg/issues
|
|
8
|
+
Author-email: peachfuzz11 <pederh11@gmail.com>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: deep-zoom,geospatial,imagery,landsat,raster,remote-sensing,satellite,sentinel,tiling
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: GIS
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Image Recognition
|
|
20
|
+
Requires-Python: >=3.12
|
|
21
|
+
Requires-Dist: beautifulsoup4>=4.14.2
|
|
22
|
+
Requires-Dist: dask[array]>=2025.10.0
|
|
23
|
+
Requires-Dist: onnxruntime>=1.23.2
|
|
24
|
+
Requires-Dist: pillow>=12.0.0
|
|
25
|
+
Requires-Dist: pystac-client>=0.9.0
|
|
26
|
+
Requires-Dist: rasterio>=1.4.3
|
|
27
|
+
Requires-Dist: rioxarray>=0.19.0
|
|
28
|
+
Requires-Dist: roaring-landmask>=0.10.1
|
|
29
|
+
Requires-Dist: xarray>=2025.10.1
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# satimg
|
|
33
|
+
|
|
34
|
+
A uniform, tile-friendly wrapper over satellite imagery. Point it at a product
|
|
35
|
+
directory and you get the same interface regardless of sensor: three views on the
|
|
36
|
+
pixels and one clean way to walk them in windows without ever losing track of
|
|
37
|
+
where a window came from.
|
|
38
|
+
|
|
39
|
+
Supported products: Sentinel-1 GRD (IW / EW), Sentinel-2 L1C, Landsat C2 L1.
|
|
40
|
+
|
|
41
|
+
## Concepts
|
|
42
|
+
|
|
43
|
+
| Object | What it is |
|
|
44
|
+
| --- | --- |
|
|
45
|
+
| `Product` | A product directory. Exposes `.raw`, `.rgb`, `.gray`, `.patches(...)`, metadata. |
|
|
46
|
+
| `Raster` | A lazy `(band, y, x)` array. Reads nothing until you ask for values. |
|
|
47
|
+
| `Window` | An immutable pixel rectangle (`col`, `row`, `width`, `height`). Pure geometry. |
|
|
48
|
+
| `Grid` | Lays `Window`s over an image with a step and an edge policy. |
|
|
49
|
+
| `Patch` | A `Window` bound to the `Raster` it came from. `.array` (lazy) / `.values` (numpy) + geo helpers. |
|
|
50
|
+
|
|
51
|
+
### Three views on the pixels
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
import satimg
|
|
55
|
+
|
|
56
|
+
product = satimg.open("/data/S2A_MSIL1C_20220114T103401_..._T33UUB_....SAFE")
|
|
57
|
+
|
|
58
|
+
product.raw # every native band, merged onto one grid, native dtype -> Raster
|
|
59
|
+
product.rgb # 3-band uint8 true-colour visualisation -> Raster
|
|
60
|
+
product.gray # 1-band uint8 visualisation -> Raster
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
All three are lazy `Raster`s over the same grid, so a `Window` means the same
|
|
64
|
+
thing in each.
|
|
65
|
+
|
|
66
|
+
### Walking the image in patches
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
for patch in product.patches(512, overlap=64, kind="rgb"):
|
|
70
|
+
tile = patch.values # np.ndarray, (3, 512, 512), uint8
|
|
71
|
+
x0, y0 = patch.col, patch.row # exact offset in the full image
|
|
72
|
+
lat, lon = patch.center_latlon # where the patch sits on Earth
|
|
73
|
+
...
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
`for patch in product` is shorthand for `product.patches()` (raw bands,
|
|
77
|
+
512 px, no overlap).
|
|
78
|
+
|
|
79
|
+
`kind=` picks the view (`"raw"` / `"rgb"` / `"gray"`). `batch=n` yields lists of
|
|
80
|
+
`n` patches instead of one at a time.
|
|
81
|
+
|
|
82
|
+
### Edge handling
|
|
83
|
+
|
|
84
|
+
`product.patches(size, edge=...)` decides what happens at the right / bottom border:
|
|
85
|
+
|
|
86
|
+
| `edge` | behaviour | use for |
|
|
87
|
+
| --- | --- | --- |
|
|
88
|
+
| `"trim"` (default) | last row/col of patches is smaller — you get exactly the pixels that exist | analysis, lossless re-assembly |
|
|
89
|
+
| `"pad"` | every patch is exactly `size`, overhang zero-filled | batched model inference |
|
|
90
|
+
| `"skip"` | drop partial patches, keep only full interior tiles | training-set extraction |
|
|
91
|
+
|
|
92
|
+
Indices are always conserved: `patch.window` tells you where the tile belongs,
|
|
93
|
+
`patch.window.clip(product.width, product.height)` gives its valid region.
|
|
94
|
+
|
|
95
|
+
### Mapping results back
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
patch = next(product.patches(1024, kind="rgb"))
|
|
99
|
+
boxes = detect(patch.values) # boxes in patch pixels
|
|
100
|
+
boxes[:, [0, 2]] += patch.window.col # -> full-image pixels
|
|
101
|
+
boxes[:, [1, 3]] += patch.window.row
|
|
102
|
+
latlon = product.transformer.rowcol_to_latlon(boxes[:, [1, 0]])
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Working with a single window
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
from satimg import Window
|
|
109
|
+
|
|
110
|
+
win = Window(col=4096, row=2048, width=1024, height=1024)
|
|
111
|
+
chip = product.raw.read(win) # lazy xarray.DataArray, dims (band, y, x)
|
|
112
|
+
chip = product.raw.values(win) # numpy, zero-padded if the window overhangs
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Rasters compose
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
ndwi = product.raw.map(lambda d: (d.isel(band=2) - d.isel(band=7))
|
|
119
|
+
/ (d.isel(band=2) + d.isel(band=7)),
|
|
120
|
+
name="ndwi")
|
|
121
|
+
for patch in ndwi.patches(512):
|
|
122
|
+
...
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Downloading
|
|
126
|
+
|
|
127
|
+
`search` is anonymous; `download` needs a (free) account for the archive.
|
|
128
|
+
Pass credentials to the connector, or set environment variables
|
|
129
|
+
(`CDSE_USERNAME` / `CDSE_PASSWORD` for Copernicus, `USGS_USERNAME` /
|
|
130
|
+
`USGS_PASSWORD` / optional `USGS_TOKEN` for USGS).
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
from satimg import get_connector
|
|
134
|
+
|
|
135
|
+
connector = get_connector("sentinel-2-l1c") # search only
|
|
136
|
+
items = connector.search(geojson=aoi, start_datetime=start, stop_datetime=stop)
|
|
137
|
+
|
|
138
|
+
connector = get_connector("sentinel-2-l1c",
|
|
139
|
+
username="me@example.com", password="...")
|
|
140
|
+
connector.download(items[0], "/data/scene.zip")
|
|
141
|
+
|
|
142
|
+
with satimg.open_zip("/data/scene.zip") as product:
|
|
143
|
+
...
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Deep Zoom
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
from satimg.deepzoom import DeepZoom
|
|
150
|
+
|
|
151
|
+
DeepZoom(tile_size=512).build(product.rgb, "/tmp/scene") # -> /tmp/scene.dzi
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Adding a product
|
|
155
|
+
|
|
156
|
+
Subclass `Product`, implement `raw`, `_render_rgb`, and the metadata properties,
|
|
157
|
+
and register a filename pattern:
|
|
158
|
+
|
|
159
|
+
```python
|
|
160
|
+
from satimg.registry import register
|
|
161
|
+
|
|
162
|
+
@register(r"^MY_SENSOR_\d{8}.*$")
|
|
163
|
+
class MySensorProduct(Product):
|
|
164
|
+
...
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Importing `satimg.products` registers the built-ins.
|
|
168
|
+
|
|
169
|
+
## Development
|
|
170
|
+
|
|
171
|
+
```sh
|
|
172
|
+
uv sync
|
|
173
|
+
uv run pytest # fast unit tests + product integration tests
|
|
174
|
+
uv run pytest tests/test_geometry.py tests/test_raster.py # just the fast ones
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Integration tests run against minified scenes under `tests/data/` — real
|
|
178
|
+
georeferencing and metadata, zeroed pixels.
|
satimg-0.3.0/README.md
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# satimg
|
|
2
|
+
|
|
3
|
+
A uniform, tile-friendly wrapper over satellite imagery. Point it at a product
|
|
4
|
+
directory and you get the same interface regardless of sensor: three views on the
|
|
5
|
+
pixels and one clean way to walk them in windows without ever losing track of
|
|
6
|
+
where a window came from.
|
|
7
|
+
|
|
8
|
+
Supported products: Sentinel-1 GRD (IW / EW), Sentinel-2 L1C, Landsat C2 L1.
|
|
9
|
+
|
|
10
|
+
## Concepts
|
|
11
|
+
|
|
12
|
+
| Object | What it is |
|
|
13
|
+
| --- | --- |
|
|
14
|
+
| `Product` | A product directory. Exposes `.raw`, `.rgb`, `.gray`, `.patches(...)`, metadata. |
|
|
15
|
+
| `Raster` | A lazy `(band, y, x)` array. Reads nothing until you ask for values. |
|
|
16
|
+
| `Window` | An immutable pixel rectangle (`col`, `row`, `width`, `height`). Pure geometry. |
|
|
17
|
+
| `Grid` | Lays `Window`s over an image with a step and an edge policy. |
|
|
18
|
+
| `Patch` | A `Window` bound to the `Raster` it came from. `.array` (lazy) / `.values` (numpy) + geo helpers. |
|
|
19
|
+
|
|
20
|
+
### Three views on the pixels
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
import satimg
|
|
24
|
+
|
|
25
|
+
product = satimg.open("/data/S2A_MSIL1C_20220114T103401_..._T33UUB_....SAFE")
|
|
26
|
+
|
|
27
|
+
product.raw # every native band, merged onto one grid, native dtype -> Raster
|
|
28
|
+
product.rgb # 3-band uint8 true-colour visualisation -> Raster
|
|
29
|
+
product.gray # 1-band uint8 visualisation -> Raster
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
All three are lazy `Raster`s over the same grid, so a `Window` means the same
|
|
33
|
+
thing in each.
|
|
34
|
+
|
|
35
|
+
### Walking the image in patches
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
for patch in product.patches(512, overlap=64, kind="rgb"):
|
|
39
|
+
tile = patch.values # np.ndarray, (3, 512, 512), uint8
|
|
40
|
+
x0, y0 = patch.col, patch.row # exact offset in the full image
|
|
41
|
+
lat, lon = patch.center_latlon # where the patch sits on Earth
|
|
42
|
+
...
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
`for patch in product` is shorthand for `product.patches()` (raw bands,
|
|
46
|
+
512 px, no overlap).
|
|
47
|
+
|
|
48
|
+
`kind=` picks the view (`"raw"` / `"rgb"` / `"gray"`). `batch=n` yields lists of
|
|
49
|
+
`n` patches instead of one at a time.
|
|
50
|
+
|
|
51
|
+
### Edge handling
|
|
52
|
+
|
|
53
|
+
`product.patches(size, edge=...)` decides what happens at the right / bottom border:
|
|
54
|
+
|
|
55
|
+
| `edge` | behaviour | use for |
|
|
56
|
+
| --- | --- | --- |
|
|
57
|
+
| `"trim"` (default) | last row/col of patches is smaller — you get exactly the pixels that exist | analysis, lossless re-assembly |
|
|
58
|
+
| `"pad"` | every patch is exactly `size`, overhang zero-filled | batched model inference |
|
|
59
|
+
| `"skip"` | drop partial patches, keep only full interior tiles | training-set extraction |
|
|
60
|
+
|
|
61
|
+
Indices are always conserved: `patch.window` tells you where the tile belongs,
|
|
62
|
+
`patch.window.clip(product.width, product.height)` gives its valid region.
|
|
63
|
+
|
|
64
|
+
### Mapping results back
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
patch = next(product.patches(1024, kind="rgb"))
|
|
68
|
+
boxes = detect(patch.values) # boxes in patch pixels
|
|
69
|
+
boxes[:, [0, 2]] += patch.window.col # -> full-image pixels
|
|
70
|
+
boxes[:, [1, 3]] += patch.window.row
|
|
71
|
+
latlon = product.transformer.rowcol_to_latlon(boxes[:, [1, 0]])
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Working with a single window
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
from satimg import Window
|
|
78
|
+
|
|
79
|
+
win = Window(col=4096, row=2048, width=1024, height=1024)
|
|
80
|
+
chip = product.raw.read(win) # lazy xarray.DataArray, dims (band, y, x)
|
|
81
|
+
chip = product.raw.values(win) # numpy, zero-padded if the window overhangs
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Rasters compose
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
ndwi = product.raw.map(lambda d: (d.isel(band=2) - d.isel(band=7))
|
|
88
|
+
/ (d.isel(band=2) + d.isel(band=7)),
|
|
89
|
+
name="ndwi")
|
|
90
|
+
for patch in ndwi.patches(512):
|
|
91
|
+
...
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Downloading
|
|
95
|
+
|
|
96
|
+
`search` is anonymous; `download` needs a (free) account for the archive.
|
|
97
|
+
Pass credentials to the connector, or set environment variables
|
|
98
|
+
(`CDSE_USERNAME` / `CDSE_PASSWORD` for Copernicus, `USGS_USERNAME` /
|
|
99
|
+
`USGS_PASSWORD` / optional `USGS_TOKEN` for USGS).
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
from satimg import get_connector
|
|
103
|
+
|
|
104
|
+
connector = get_connector("sentinel-2-l1c") # search only
|
|
105
|
+
items = connector.search(geojson=aoi, start_datetime=start, stop_datetime=stop)
|
|
106
|
+
|
|
107
|
+
connector = get_connector("sentinel-2-l1c",
|
|
108
|
+
username="me@example.com", password="...")
|
|
109
|
+
connector.download(items[0], "/data/scene.zip")
|
|
110
|
+
|
|
111
|
+
with satimg.open_zip("/data/scene.zip") as product:
|
|
112
|
+
...
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Deep Zoom
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
from satimg.deepzoom import DeepZoom
|
|
119
|
+
|
|
120
|
+
DeepZoom(tile_size=512).build(product.rgb, "/tmp/scene") # -> /tmp/scene.dzi
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Adding a product
|
|
124
|
+
|
|
125
|
+
Subclass `Product`, implement `raw`, `_render_rgb`, and the metadata properties,
|
|
126
|
+
and register a filename pattern:
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
from satimg.registry import register
|
|
130
|
+
|
|
131
|
+
@register(r"^MY_SENSOR_\d{8}.*$")
|
|
132
|
+
class MySensorProduct(Product):
|
|
133
|
+
...
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Importing `satimg.products` registers the built-ins.
|
|
137
|
+
|
|
138
|
+
## Development
|
|
139
|
+
|
|
140
|
+
```sh
|
|
141
|
+
uv sync
|
|
142
|
+
uv run pytest # fast unit tests + product integration tests
|
|
143
|
+
uv run pytest tests/test_geometry.py tests/test_raster.py # just the fast ones
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Integration tests run against minified scenes under `tests/data/` — real
|
|
147
|
+
georeferencing and metadata, zeroed pixels.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "satimg"
|
|
7
|
+
version = "0.3.0"
|
|
8
|
+
description = "A uniform, tile-friendly wrapper over satellite imagery"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.12"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [{ name = "peachfuzz11", email = "pederh11@gmail.com" }]
|
|
14
|
+
keywords = [
|
|
15
|
+
"satellite",
|
|
16
|
+
"imagery",
|
|
17
|
+
"remote-sensing",
|
|
18
|
+
"sentinel",
|
|
19
|
+
"landsat",
|
|
20
|
+
"raster",
|
|
21
|
+
"geospatial",
|
|
22
|
+
"tiling",
|
|
23
|
+
"deep-zoom",
|
|
24
|
+
]
|
|
25
|
+
classifiers = [
|
|
26
|
+
"Development Status :: 3 - Alpha",
|
|
27
|
+
"Intended Audience :: Science/Research",
|
|
28
|
+
"Operating System :: OS Independent",
|
|
29
|
+
"Programming Language :: Python :: 3",
|
|
30
|
+
"Programming Language :: Python :: 3.12",
|
|
31
|
+
"Programming Language :: Python :: 3.13",
|
|
32
|
+
"Topic :: Scientific/Engineering :: GIS",
|
|
33
|
+
"Topic :: Scientific/Engineering :: Image Recognition",
|
|
34
|
+
]
|
|
35
|
+
dependencies = [
|
|
36
|
+
"beautifulsoup4>=4.14.2",
|
|
37
|
+
"dask[array]>=2025.10.0",
|
|
38
|
+
"onnxruntime>=1.23.2",
|
|
39
|
+
"pillow>=12.0.0",
|
|
40
|
+
"pystac-client>=0.9.0",
|
|
41
|
+
"rasterio>=1.4.3",
|
|
42
|
+
"rioxarray>=0.19.0",
|
|
43
|
+
"roaring-landmask>=0.10.1",
|
|
44
|
+
"xarray>=2025.10.1",
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
[project.urls]
|
|
48
|
+
Homepage = "https://github.com/peachfuzz11/satimg"
|
|
49
|
+
Repository = "https://github.com/peachfuzz11/satimg"
|
|
50
|
+
Issues = "https://github.com/peachfuzz11/satimg/issues"
|
|
51
|
+
|
|
52
|
+
[dependency-groups]
|
|
53
|
+
dev = [
|
|
54
|
+
"pytest>=8",
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
[tool.hatch.build.targets.wheel]
|
|
58
|
+
packages = ["src/satimg"]
|
|
59
|
+
|
|
60
|
+
[tool.hatch.build.targets.sdist]
|
|
61
|
+
include = ["src/satimg", "README.md", "LICENSE"]
|
|
62
|
+
|
|
63
|
+
[tool.pytest.ini_options]
|
|
64
|
+
testpaths = ["tests"]
|
|
65
|
+
python_files = ["test_*.py"]
|
|
66
|
+
addopts = "-ra"
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""satimg -- a uniform, tile-friendly wrapper over satellite imagery.
|
|
2
|
+
|
|
3
|
+
import satimg
|
|
4
|
+
|
|
5
|
+
product = satimg.open("/data/S2A_MSIL1C_....SAFE")
|
|
6
|
+
|
|
7
|
+
for patch in product.patches(512, overlap=64, kind="rgb"):
|
|
8
|
+
do_something(patch.values) # (band, y, x) uint8
|
|
9
|
+
print(patch.col, patch.row) # where it sits in the full image
|
|
10
|
+
print(patch.center_latlon) # where it sits on Earth
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import os
|
|
16
|
+
import tempfile
|
|
17
|
+
import zipfile
|
|
18
|
+
from contextlib import contextmanager
|
|
19
|
+
from importlib.metadata import PackageNotFoundError, version as _version
|
|
20
|
+
from typing import Iterator
|
|
21
|
+
|
|
22
|
+
try:
|
|
23
|
+
__version__ = _version("satimg")
|
|
24
|
+
except PackageNotFoundError: # running from a source tree without an install
|
|
25
|
+
__version__ = "0.0.0"
|
|
26
|
+
|
|
27
|
+
from satimg import products as _products # noqa: F401 (populates the registry)
|
|
28
|
+
from satimg.connectors import CredentialsError, get_connector
|
|
29
|
+
from satimg.geometry import Grid, Window
|
|
30
|
+
from satimg.product import Product
|
|
31
|
+
from satimg.raster import Patch, Raster
|
|
32
|
+
from satimg.registry import UnknownProductError, resolve
|
|
33
|
+
|
|
34
|
+
__all__ = [
|
|
35
|
+
"__version__",
|
|
36
|
+
"open",
|
|
37
|
+
"open_zip",
|
|
38
|
+
"get_connector",
|
|
39
|
+
"Product",
|
|
40
|
+
"Raster",
|
|
41
|
+
"Patch",
|
|
42
|
+
"Window",
|
|
43
|
+
"Grid",
|
|
44
|
+
"UnknownProductError",
|
|
45
|
+
"CredentialsError",
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def open(path: str) -> Product:
|
|
50
|
+
"""Open a product directory, returning the matching :class:`Product`."""
|
|
51
|
+
return resolve(path)(path)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@contextmanager
|
|
55
|
+
def open_zip(zip_path: str, dest: str | None = None) -> Iterator[Product]:
|
|
56
|
+
"""Extract a zipped product to a temp dir and yield it as a :class:`Product`.
|
|
57
|
+
|
|
58
|
+
The temp dir (under ``dest``, or the system default) is removed on exit.
|
|
59
|
+
"""
|
|
60
|
+
with tempfile.TemporaryDirectory(dir=dest) as tmp:
|
|
61
|
+
with zipfile.ZipFile(zip_path) as archive:
|
|
62
|
+
archive.extractall(tmp)
|
|
63
|
+
entries = [os.path.join(tmp, e) for e in os.listdir(tmp)]
|
|
64
|
+
root = entries[0] if len(entries) == 1 and os.path.isdir(entries[0]) else tmp
|
|
65
|
+
yield open(root)
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""Remote archive connectors, keyed by STAC collection name.
|
|
2
|
+
|
|
3
|
+
``search`` is anonymous; ``download`` needs an account -- pass ``username=`` /
|
|
4
|
+
``password=`` (and ``token=`` for USGS) or set the service's environment
|
|
5
|
+
variables (see :mod:`satimg.connectors._credentials`).
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from satimg.connectors._credentials import Credentials, CredentialsError
|
|
11
|
+
from satimg.connectors.base import Connector, STACConnector
|
|
12
|
+
from satimg.connectors.landsat import LandsatConnector
|
|
13
|
+
from satimg.connectors.sentinel import Sentinel1Connector, Sentinel2Connector
|
|
14
|
+
|
|
15
|
+
_CONNECTORS: dict[str, type[Connector]] = {
|
|
16
|
+
"sentinel-1-grd": Sentinel1Connector,
|
|
17
|
+
"sentinel-2-l1c": Sentinel2Connector,
|
|
18
|
+
"landsat-c2l1": LandsatConnector,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def get_connector(collection: str, **credentials) -> Connector:
|
|
23
|
+
"""Instantiate the connector for a STAC ``collection`` name.
|
|
24
|
+
|
|
25
|
+
Extra keyword arguments (``username``, ``password``, ``token``) are passed to
|
|
26
|
+
the connector's constructor.
|
|
27
|
+
"""
|
|
28
|
+
try:
|
|
29
|
+
cls = _CONNECTORS[collection]
|
|
30
|
+
except KeyError:
|
|
31
|
+
raise ValueError(
|
|
32
|
+
f"no connector for {collection!r}; known: {sorted(_CONNECTORS)}"
|
|
33
|
+
) from None
|
|
34
|
+
return cls(**credentials)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
__all__ = [
|
|
38
|
+
"Connector",
|
|
39
|
+
"STACConnector",
|
|
40
|
+
"Sentinel1Connector",
|
|
41
|
+
"Sentinel2Connector",
|
|
42
|
+
"LandsatConnector",
|
|
43
|
+
"Credentials",
|
|
44
|
+
"CredentialsError",
|
|
45
|
+
"get_connector",
|
|
46
|
+
]
|