pygndc 1.0.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.
- pygndc-1.0.0/LICENSE +21 -0
- pygndc-1.0.0/PKG-INFO +247 -0
- pygndc-1.0.0/README.md +197 -0
- pygndc-1.0.0/pygndc/__init__.py +92 -0
- pygndc-1.0.0/pygndc/__main__.py +202 -0
- pygndc-1.0.0/pygndc/_version.py +11 -0
- pygndc-1.0.0/pygndc/analysis/__init__.py +24 -0
- pygndc-1.0.0/pygndc/analysis/vegetation.py +160 -0
- pygndc-1.0.0/pygndc/dataset/__init__.py +9 -0
- pygndc-1.0.0/pygndc/dataset/dataset.py +684 -0
- pygndc-1.0.0/pygndc/exceptions.py +48 -0
- pygndc-1.0.0/pygndc/interop/__init__.py +19 -0
- pygndc-1.0.0/pygndc/interop/interop.py +209 -0
- pygndc-1.0.0/pygndc/models/GNDCNetwork.py +228 -0
- pygndc-1.0.0/pygndc/models/GNDCNetworkTorch.py +459 -0
- pygndc-1.0.0/pygndc/models/__init__.py +5 -0
- pygndc-1.0.0/pygndc/reader/__init__.py +9 -0
- pygndc-1.0.0/pygndc/reader/reader.py +1154 -0
- pygndc-1.0.0/pygndc/utils/__init__.py +20 -0
- pygndc-1.0.0/pygndc/utils/compression.py +19 -0
- pygndc-1.0.0/pygndc/utils/config_utils.py +101 -0
- pygndc-1.0.0/pygndc/utils/date_utils.py +94 -0
- pygndc-1.0.0/pygndc/utils/math_utils.py +156 -0
- pygndc-1.0.0/pygndc/viewer/__init__.py +9 -0
- pygndc-1.0.0/pygndc/viewer/interactive.py +1867 -0
- pygndc-1.0.0/pygndc.egg-info/PKG-INFO +247 -0
- pygndc-1.0.0/pygndc.egg-info/SOURCES.txt +31 -0
- pygndc-1.0.0/pygndc.egg-info/dependency_links.txt +1 -0
- pygndc-1.0.0/pygndc.egg-info/entry_points.txt +2 -0
- pygndc-1.0.0/pygndc.egg-info/requires.txt +30 -0
- pygndc-1.0.0/pygndc.egg-info/top_level.txt +1 -0
- pygndc-1.0.0/pyproject.toml +83 -0
- pygndc-1.0.0/setup.cfg +4 -0
pygndc-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 jianboqi
|
|
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.
|
pygndc-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pygndc
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Geographic Neural Data Cube - Read and analyze .gndc compressed geospatial time-series data
|
|
5
|
+
Author-email: Jianbo Qi <jianboqi@126.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://geondc.org
|
|
8
|
+
Project-URL: Repository, https://github.com/jianboqi/pygndc
|
|
9
|
+
Project-URL: Issues, https://github.com/jianboqi/pygndc/issues
|
|
10
|
+
Keywords: geospatial,satellite,remote-sensing,neural-networks,compression
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: GIS
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: torch>=2.0.0
|
|
24
|
+
Requires-Dist: rasterio>=1.3.0
|
|
25
|
+
Requires-Dist: numpy>=1.21.0
|
|
26
|
+
Requires-Dist: pyyaml>=6.0
|
|
27
|
+
Requires-Dist: tqdm>=4.65.0
|
|
28
|
+
Requires-Dist: pydantic>=2.0.0
|
|
29
|
+
Requires-Dist: zstandard>=0.21.0
|
|
30
|
+
Requires-Dist: matplotlib>=3.5.0
|
|
31
|
+
Requires-Dist: pillow>=9.0.0
|
|
32
|
+
Provides-Extra: xarray
|
|
33
|
+
Requires-Dist: xarray>=2022.0; extra == "xarray"
|
|
34
|
+
Provides-Extra: geo
|
|
35
|
+
Requires-Dist: geopandas>=0.12.0; extra == "geo"
|
|
36
|
+
Requires-Dist: shapely>=2.0.0; extra == "geo"
|
|
37
|
+
Provides-Extra: all
|
|
38
|
+
Requires-Dist: xarray>=2022.0; extra == "all"
|
|
39
|
+
Requires-Dist: geopandas>=0.12.0; extra == "all"
|
|
40
|
+
Requires-Dist: shapely>=2.0.0; extra == "all"
|
|
41
|
+
Requires-Dist: scipy>=1.9.0; extra == "all"
|
|
42
|
+
Provides-Extra: dev
|
|
43
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
44
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
45
|
+
Requires-Dist: black>=23.0.0; extra == "dev"
|
|
46
|
+
Requires-Dist: ruff>=0.1.0; extra == "dev"
|
|
47
|
+
Requires-Dist: mypy>=1.0.0; extra == "dev"
|
|
48
|
+
Requires-Dist: twine>=4.0.0; extra == "dev"
|
|
49
|
+
Dynamic: license-file
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
# pygndc
|
|
53
|
+
|
|
54
|
+
**Geographic Neural Data Cube** - A Python SDK for reading and analyzing `.gndc` compressed geospatial time-series data.
|
|
55
|
+
|
|
56
|
+
<img width="286" height="320" alt="GeoNDC" src="https://github.com/user-attachments/assets/6c526878-93bc-4b70-bc99-cbb99193931a" />
|
|
57
|
+
|
|
58
|
+
## What is GeoNDC?
|
|
59
|
+
|
|
60
|
+
GeoNDC is a neural network-based compression format for multi-dimensional geospatial raster data. A single `.gndc` file stores 4D spatiotemporal data (Time x Height x Width x Bands) with up to **300:1 compression ratios**.
|
|
61
|
+
|
|
62
|
+
Key capabilities:
|
|
63
|
+
|
|
64
|
+
- **Arbitrary time reconstruction** - reconstruct data at any time point, not just original observation times
|
|
65
|
+
- **Fast random access** - query any pixel at any timestamp instantly
|
|
66
|
+
- **Analytic gradients** - compute spatial/temporal derivatives directly from the neural network
|
|
67
|
+
- **Multi-sensor support** - Sentinel-2, Landsat, MODIS, HiGLASS, and more
|
|
68
|
+
|
|
69
|
+
## Online Viewer & Data
|
|
70
|
+
|
|
71
|
+
- **Web Viewer**: Browse `.gndc` files directly in the browser via WebGPU at [geondc.org/viewer](https://www.geondc.org/viewer/) — no installation required, GPU-accelerated, runs entirely client-side.
|
|
72
|
+
- **Sample Data**: Download `.gndc` datasets from [Hugging Face](https://huggingface.co/datasets/geondc/geondc-data).
|
|
73
|
+
|
|
74
|
+
## Installation
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
pip install pygndc
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Or from source:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
git clone https://github.com/jianboqi/pygndc.git
|
|
84
|
+
cd pygndc
|
|
85
|
+
pip install .
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### GPU support (recommended)
|
|
89
|
+
|
|
90
|
+
`pip install pygndc` installs CPU-only PyTorch by default. For GPU acceleration, install CUDA-enabled PyTorch **first**:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
# Example for CUDA 12.1 (check https://pytorch.org for your CUDA version)
|
|
94
|
+
pip install torch --index-url https://download.pytorch.org/whl/cu121
|
|
95
|
+
|
|
96
|
+
# Then install pygndc
|
|
97
|
+
pip install pygndc
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### tiny-cuda-nn (fastest)
|
|
101
|
+
|
|
102
|
+
For best performance, install [tiny-cuda-nn](https://github.com/NVlabs/tiny-cuda-nn). This provides the optimized TCNN backend with significantly faster inference and lower memory usage.
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
pip install git+https://github.com/NVlabs/tiny-cuda-nn/#subdirectory=bindings/torch
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
> **Note**: tiny-cuda-nn requires an NVIDIA GPU with CUDA support and a C++ compiler. If you cannot install it, pygndc will automatically fall back to pure PyTorch (`torch_gpu` or `torch_cpu`).
|
|
109
|
+
|
|
110
|
+
### Optional dependencies
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
pip install pygndc[all] # xarray + geopandas + scipy
|
|
114
|
+
pip install pygndc[xarray] # xarray support
|
|
115
|
+
pip install pygndc[geo] # geopandas + shapely
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Inference modes
|
|
119
|
+
|
|
120
|
+
pygndc uses a single `mode` parameter to control both the backend and device:
|
|
121
|
+
|
|
122
|
+
| Mode | Backend | Device | Description |
|
|
123
|
+
|------|---------|--------|-------------|
|
|
124
|
+
| `auto` | auto-detect | auto-detect | **Default.** Best available mode |
|
|
125
|
+
| `tcnn_cuda` | tiny-cuda-nn | GPU | Fastest. Requires tinycudann + CUDA |
|
|
126
|
+
| `torch_gpu` | PyTorch | GPU | No extra dependencies, requires CUDA |
|
|
127
|
+
| `torch_cpu` | PyTorch | CPU | Works everywhere, slowest |
|
|
128
|
+
|
|
129
|
+
## Quick Start
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
import pygndc
|
|
133
|
+
|
|
134
|
+
# Open a .gndc file (auto-detects best mode)
|
|
135
|
+
with pygndc.open("samples/S2_sample_2022_to_2025.gndc") as ds:
|
|
136
|
+
print(ds) # Shows mode, shape, CRS, etc.
|
|
137
|
+
|
|
138
|
+
# Read a frame
|
|
139
|
+
frame = ds.read(t=0) # (H, W, C) by index
|
|
140
|
+
frame = ds.read(t="2024-06-15") # by date string
|
|
141
|
+
frame = ds.read_at_time("2024-06-15 12:00:00") # continuous interpolation
|
|
142
|
+
|
|
143
|
+
# Point query (coordinates within the sample's bounds)
|
|
144
|
+
series = ds.sample(lon=116.825, lat=40.486) # (T, C) full time series
|
|
145
|
+
values = ds.sample(lon=116.825, lat=40.486, t=0) # (C,) single time
|
|
146
|
+
|
|
147
|
+
# Pixel time series
|
|
148
|
+
series = ds.pixel_series(row=140, col=140) # (T, C)
|
|
149
|
+
|
|
150
|
+
# Analysis
|
|
151
|
+
ndvi = ds.ndvi(t=0, red_band=2, nir_band=3) # (H, W)
|
|
152
|
+
dx, dy = ds.gradient(t=0, mode="spatial") # analytic gradients
|
|
153
|
+
|
|
154
|
+
# Export
|
|
155
|
+
arr = ds.to_numpy(t=0) # (H, W, C) numpy array
|
|
156
|
+
ds.to_tif("frame_0.tif", t=0) # single frame to GeoTIFF
|
|
157
|
+
ds.to_tifs("output_dir/") # all frames
|
|
158
|
+
xds = ds.to_xarray() # xarray Dataset
|
|
159
|
+
|
|
160
|
+
# Specify mode explicitly
|
|
161
|
+
with pygndc.open("samples/S2_sample_2022_to_2025.gndc", mode="torch_cpu") as ds:
|
|
162
|
+
frame = ds.read(t=0)
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## CLI Commands
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
# Show model info
|
|
169
|
+
pygndc info model.gndc
|
|
170
|
+
pygndc info model.gndc --json
|
|
171
|
+
|
|
172
|
+
# Decompress to GeoTIFF files
|
|
173
|
+
pygndc decompress -i model.gndc -o ./output
|
|
174
|
+
pygndc decompress -i model.gndc -o ./output --timestamp 2024-06-15
|
|
175
|
+
pygndc decompress -i model.gndc -o ./output --start 2024-01-01 --end 2024-12-31 --interval 5
|
|
176
|
+
|
|
177
|
+
# Compute NDVI
|
|
178
|
+
pygndc ndvi -i model.gndc -o ndvi.tif --red-band 0 --nir-band 1
|
|
179
|
+
|
|
180
|
+
# Compute spatial gradient
|
|
181
|
+
pygndc derivative -i model.gndc -o gradient.tif --grad-mode mag
|
|
182
|
+
|
|
183
|
+
# Point query
|
|
184
|
+
pygndc sample -i model.gndc --lon 116.5 --lat 39.9
|
|
185
|
+
|
|
186
|
+
# Export pixel time series to CSV
|
|
187
|
+
pygndc timeseries -i model.gndc --row 100 --col 200 -o series.csv
|
|
188
|
+
|
|
189
|
+
# Launch interactive viewer
|
|
190
|
+
pygndc viewer -i model.gndc
|
|
191
|
+
|
|
192
|
+
# All commands support --mode (auto, tcnn_cuda, torch_gpu, torch_cpu)
|
|
193
|
+
pygndc decompress -i model.gndc -o ./output --mode torch_cpu
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## Interactive Viewer
|
|
197
|
+
|
|
198
|
+
A GUI tool for visualizing `.gndc` files with multiple display modes, time navigation, and pixel inspection.
|
|
199
|
+
|
|
200
|
+
```python
|
|
201
|
+
from pygndc import start_viewer
|
|
202
|
+
start_viewer()
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
Features:
|
|
206
|
+
- RGB, NDVI, temporal gradient, and spatial gradient display modes
|
|
207
|
+
- Time slider with date navigation
|
|
208
|
+
- Click-to-inspect pixel time series
|
|
209
|
+
- Region selection and zoom
|
|
210
|
+
- Export current frame or entire time series
|
|
211
|
+
|
|
212
|
+
## File Format
|
|
213
|
+
|
|
214
|
+
A `.gndc` file is a zstandard-compressed archive containing:
|
|
215
|
+
|
|
216
|
+
| Component | Description |
|
|
217
|
+
|-----------|-------------|
|
|
218
|
+
| Header | JSON metadata (dimensions, timestamps, CRS, band info) |
|
|
219
|
+
| Model Weights | Compressed neural network parameters |
|
|
220
|
+
| Mask Data | Optional validity mask (static or dynamic) |
|
|
221
|
+
| Residuals | Optional correction data for higher accuracy |
|
|
222
|
+
|
|
223
|
+
## API Reference
|
|
224
|
+
|
|
225
|
+
See [API_Reference.md](API_Reference.md) for the full API documentation.
|
|
226
|
+
|
|
227
|
+
## License
|
|
228
|
+
|
|
229
|
+
MIT License
|
|
230
|
+
|
|
231
|
+
## Citation
|
|
232
|
+
|
|
233
|
+
```bibtex
|
|
234
|
+
@software{pygndc,
|
|
235
|
+
author = {Jianbo Qi},
|
|
236
|
+
title = {pygndc: Geographic Neural Data Cube},
|
|
237
|
+
year = {2024},
|
|
238
|
+
url = {https://github.com/jianboqi/pygndc},
|
|
239
|
+
license = {MIT}
|
|
240
|
+
}
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
## Contact
|
|
244
|
+
|
|
245
|
+
- Author: Jianbo Qi
|
|
246
|
+
- Email: jianboqi@126.com
|
|
247
|
+
- Issues: [GitHub Issues](https://github.com/jianboqi/pygndc/issues)
|
pygndc-1.0.0/README.md
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
|
|
2
|
+
# pygndc
|
|
3
|
+
|
|
4
|
+
**Geographic Neural Data Cube** - A Python SDK for reading and analyzing `.gndc` compressed geospatial time-series data.
|
|
5
|
+
|
|
6
|
+
<img width="286" height="320" alt="GeoNDC" src="https://github.com/user-attachments/assets/6c526878-93bc-4b70-bc99-cbb99193931a" />
|
|
7
|
+
|
|
8
|
+
## What is GeoNDC?
|
|
9
|
+
|
|
10
|
+
GeoNDC is a neural network-based compression format for multi-dimensional geospatial raster data. A single `.gndc` file stores 4D spatiotemporal data (Time x Height x Width x Bands) with up to **300:1 compression ratios**.
|
|
11
|
+
|
|
12
|
+
Key capabilities:
|
|
13
|
+
|
|
14
|
+
- **Arbitrary time reconstruction** - reconstruct data at any time point, not just original observation times
|
|
15
|
+
- **Fast random access** - query any pixel at any timestamp instantly
|
|
16
|
+
- **Analytic gradients** - compute spatial/temporal derivatives directly from the neural network
|
|
17
|
+
- **Multi-sensor support** - Sentinel-2, Landsat, MODIS, HiGLASS, and more
|
|
18
|
+
|
|
19
|
+
## Online Viewer & Data
|
|
20
|
+
|
|
21
|
+
- **Web Viewer**: Browse `.gndc` files directly in the browser via WebGPU at [geondc.org/viewer](https://www.geondc.org/viewer/) — no installation required, GPU-accelerated, runs entirely client-side.
|
|
22
|
+
- **Sample Data**: Download `.gndc` datasets from [Hugging Face](https://huggingface.co/datasets/geondc/geondc-data).
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pip install pygndc
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Or from source:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
git clone https://github.com/jianboqi/pygndc.git
|
|
34
|
+
cd pygndc
|
|
35
|
+
pip install .
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### GPU support (recommended)
|
|
39
|
+
|
|
40
|
+
`pip install pygndc` installs CPU-only PyTorch by default. For GPU acceleration, install CUDA-enabled PyTorch **first**:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
# Example for CUDA 12.1 (check https://pytorch.org for your CUDA version)
|
|
44
|
+
pip install torch --index-url https://download.pytorch.org/whl/cu121
|
|
45
|
+
|
|
46
|
+
# Then install pygndc
|
|
47
|
+
pip install pygndc
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### tiny-cuda-nn (fastest)
|
|
51
|
+
|
|
52
|
+
For best performance, install [tiny-cuda-nn](https://github.com/NVlabs/tiny-cuda-nn). This provides the optimized TCNN backend with significantly faster inference and lower memory usage.
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pip install git+https://github.com/NVlabs/tiny-cuda-nn/#subdirectory=bindings/torch
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
> **Note**: tiny-cuda-nn requires an NVIDIA GPU with CUDA support and a C++ compiler. If you cannot install it, pygndc will automatically fall back to pure PyTorch (`torch_gpu` or `torch_cpu`).
|
|
59
|
+
|
|
60
|
+
### Optional dependencies
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
pip install pygndc[all] # xarray + geopandas + scipy
|
|
64
|
+
pip install pygndc[xarray] # xarray support
|
|
65
|
+
pip install pygndc[geo] # geopandas + shapely
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Inference modes
|
|
69
|
+
|
|
70
|
+
pygndc uses a single `mode` parameter to control both the backend and device:
|
|
71
|
+
|
|
72
|
+
| Mode | Backend | Device | Description |
|
|
73
|
+
|------|---------|--------|-------------|
|
|
74
|
+
| `auto` | auto-detect | auto-detect | **Default.** Best available mode |
|
|
75
|
+
| `tcnn_cuda` | tiny-cuda-nn | GPU | Fastest. Requires tinycudann + CUDA |
|
|
76
|
+
| `torch_gpu` | PyTorch | GPU | No extra dependencies, requires CUDA |
|
|
77
|
+
| `torch_cpu` | PyTorch | CPU | Works everywhere, slowest |
|
|
78
|
+
|
|
79
|
+
## Quick Start
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
import pygndc
|
|
83
|
+
|
|
84
|
+
# Open a .gndc file (auto-detects best mode)
|
|
85
|
+
with pygndc.open("samples/S2_sample_2022_to_2025.gndc") as ds:
|
|
86
|
+
print(ds) # Shows mode, shape, CRS, etc.
|
|
87
|
+
|
|
88
|
+
# Read a frame
|
|
89
|
+
frame = ds.read(t=0) # (H, W, C) by index
|
|
90
|
+
frame = ds.read(t="2024-06-15") # by date string
|
|
91
|
+
frame = ds.read_at_time("2024-06-15 12:00:00") # continuous interpolation
|
|
92
|
+
|
|
93
|
+
# Point query (coordinates within the sample's bounds)
|
|
94
|
+
series = ds.sample(lon=116.825, lat=40.486) # (T, C) full time series
|
|
95
|
+
values = ds.sample(lon=116.825, lat=40.486, t=0) # (C,) single time
|
|
96
|
+
|
|
97
|
+
# Pixel time series
|
|
98
|
+
series = ds.pixel_series(row=140, col=140) # (T, C)
|
|
99
|
+
|
|
100
|
+
# Analysis
|
|
101
|
+
ndvi = ds.ndvi(t=0, red_band=2, nir_band=3) # (H, W)
|
|
102
|
+
dx, dy = ds.gradient(t=0, mode="spatial") # analytic gradients
|
|
103
|
+
|
|
104
|
+
# Export
|
|
105
|
+
arr = ds.to_numpy(t=0) # (H, W, C) numpy array
|
|
106
|
+
ds.to_tif("frame_0.tif", t=0) # single frame to GeoTIFF
|
|
107
|
+
ds.to_tifs("output_dir/") # all frames
|
|
108
|
+
xds = ds.to_xarray() # xarray Dataset
|
|
109
|
+
|
|
110
|
+
# Specify mode explicitly
|
|
111
|
+
with pygndc.open("samples/S2_sample_2022_to_2025.gndc", mode="torch_cpu") as ds:
|
|
112
|
+
frame = ds.read(t=0)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## CLI Commands
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
# Show model info
|
|
119
|
+
pygndc info model.gndc
|
|
120
|
+
pygndc info model.gndc --json
|
|
121
|
+
|
|
122
|
+
# Decompress to GeoTIFF files
|
|
123
|
+
pygndc decompress -i model.gndc -o ./output
|
|
124
|
+
pygndc decompress -i model.gndc -o ./output --timestamp 2024-06-15
|
|
125
|
+
pygndc decompress -i model.gndc -o ./output --start 2024-01-01 --end 2024-12-31 --interval 5
|
|
126
|
+
|
|
127
|
+
# Compute NDVI
|
|
128
|
+
pygndc ndvi -i model.gndc -o ndvi.tif --red-band 0 --nir-band 1
|
|
129
|
+
|
|
130
|
+
# Compute spatial gradient
|
|
131
|
+
pygndc derivative -i model.gndc -o gradient.tif --grad-mode mag
|
|
132
|
+
|
|
133
|
+
# Point query
|
|
134
|
+
pygndc sample -i model.gndc --lon 116.5 --lat 39.9
|
|
135
|
+
|
|
136
|
+
# Export pixel time series to CSV
|
|
137
|
+
pygndc timeseries -i model.gndc --row 100 --col 200 -o series.csv
|
|
138
|
+
|
|
139
|
+
# Launch interactive viewer
|
|
140
|
+
pygndc viewer -i model.gndc
|
|
141
|
+
|
|
142
|
+
# All commands support --mode (auto, tcnn_cuda, torch_gpu, torch_cpu)
|
|
143
|
+
pygndc decompress -i model.gndc -o ./output --mode torch_cpu
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Interactive Viewer
|
|
147
|
+
|
|
148
|
+
A GUI tool for visualizing `.gndc` files with multiple display modes, time navigation, and pixel inspection.
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
from pygndc import start_viewer
|
|
152
|
+
start_viewer()
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Features:
|
|
156
|
+
- RGB, NDVI, temporal gradient, and spatial gradient display modes
|
|
157
|
+
- Time slider with date navigation
|
|
158
|
+
- Click-to-inspect pixel time series
|
|
159
|
+
- Region selection and zoom
|
|
160
|
+
- Export current frame or entire time series
|
|
161
|
+
|
|
162
|
+
## File Format
|
|
163
|
+
|
|
164
|
+
A `.gndc` file is a zstandard-compressed archive containing:
|
|
165
|
+
|
|
166
|
+
| Component | Description |
|
|
167
|
+
|-----------|-------------|
|
|
168
|
+
| Header | JSON metadata (dimensions, timestamps, CRS, band info) |
|
|
169
|
+
| Model Weights | Compressed neural network parameters |
|
|
170
|
+
| Mask Data | Optional validity mask (static or dynamic) |
|
|
171
|
+
| Residuals | Optional correction data for higher accuracy |
|
|
172
|
+
|
|
173
|
+
## API Reference
|
|
174
|
+
|
|
175
|
+
See [API_Reference.md](API_Reference.md) for the full API documentation.
|
|
176
|
+
|
|
177
|
+
## License
|
|
178
|
+
|
|
179
|
+
MIT License
|
|
180
|
+
|
|
181
|
+
## Citation
|
|
182
|
+
|
|
183
|
+
```bibtex
|
|
184
|
+
@software{pygndc,
|
|
185
|
+
author = {Jianbo Qi},
|
|
186
|
+
title = {pygndc: Geographic Neural Data Cube},
|
|
187
|
+
year = {2024},
|
|
188
|
+
url = {https://github.com/jianboqi/pygndc},
|
|
189
|
+
license = {MIT}
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Contact
|
|
194
|
+
|
|
195
|
+
- Author: Jianbo Qi
|
|
196
|
+
- Email: jianboqi@126.com
|
|
197
|
+
- Issues: [GitHub Issues](https://github.com/jianboqi/pygndc/issues)
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"""
|
|
2
|
+
pygndc - Geographic Neural Data Cube
|
|
3
|
+
|
|
4
|
+
A Python library for compressing geospatial time-series data using neural networks
|
|
5
|
+
|
|
6
|
+
Quick Start:
|
|
7
|
+
import pygndc
|
|
8
|
+
|
|
9
|
+
# High-level API (recommended)
|
|
10
|
+
with pygndc.open("satellite.gndc") as ds:
|
|
11
|
+
print(ds.crs, ds.bounds, ds.shape)
|
|
12
|
+
frame = ds.read(t=0) # (H, W, C)
|
|
13
|
+
frame = ds.read_at_time("2024-06-15") # continuous interpolation
|
|
14
|
+
ts = ds.sample(lon=116.5, lat=39.9) # (T, C) point query
|
|
15
|
+
|
|
16
|
+
# Low-level API (backward compatible)
|
|
17
|
+
reader = pygndc.GNDCReader()
|
|
18
|
+
reader.load("model.gndc")
|
|
19
|
+
frame = reader.reconstruct_single_frame(0)
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
# Fix Intel OpenMP conflict
|
|
23
|
+
import os
|
|
24
|
+
os.environ["KMP_DUPLICATE_LIB_OK"] = "TRUE"
|
|
25
|
+
|
|
26
|
+
from pygndc._version import __version__, __author__, __license__
|
|
27
|
+
|
|
28
|
+
# Public API - Reader
|
|
29
|
+
from pygndc.reader import GNDCReader
|
|
30
|
+
|
|
31
|
+
# Public API - Dataset (high-level)
|
|
32
|
+
from pygndc.dataset import GNDCDataset
|
|
33
|
+
|
|
34
|
+
# Public API - Analysis
|
|
35
|
+
from pygndc.analysis import (
|
|
36
|
+
compute_ndvi,
|
|
37
|
+
compute_evi,
|
|
38
|
+
compute_ndwi,
|
|
39
|
+
compute_ndmi,
|
|
40
|
+
compute_temporal_gradient,
|
|
41
|
+
compute_spatial_gradient
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
# Public API - Viewer
|
|
45
|
+
from pygndc.viewer import GNDCInteractiveViewer, start_viewer
|
|
46
|
+
|
|
47
|
+
def open(path: str, mode: str = "auto") -> GNDCDataset:
|
|
48
|
+
"""
|
|
49
|
+
Open a .gndc file and return a GNDCDataset.
|
|
50
|
+
|
|
51
|
+
This is the recommended entry point for working with .gndc files.
|
|
52
|
+
|
|
53
|
+
Args:
|
|
54
|
+
path: Path to the .gndc file.
|
|
55
|
+
mode: Inference mode.
|
|
56
|
+
- 'auto': auto-detect best available (default)
|
|
57
|
+
- 'tcnn_cuda': tinycudann on GPU (fastest)
|
|
58
|
+
- 'torch_gpu': pure PyTorch on GPU
|
|
59
|
+
- 'torch_cpu': pure PyTorch on CPU
|
|
60
|
+
|
|
61
|
+
Returns:
|
|
62
|
+
GNDCDataset instance.
|
|
63
|
+
|
|
64
|
+
Examples:
|
|
65
|
+
>>> ds = pygndc.open("data.gndc")
|
|
66
|
+
>>> with pygndc.open("data.gndc", mode="torch_cpu") as ds:
|
|
67
|
+
... frame = ds.read(t=0)
|
|
68
|
+
"""
|
|
69
|
+
return GNDCDataset(path, mode=mode)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
__all__ = [
|
|
73
|
+
# Version info
|
|
74
|
+
"__version__",
|
|
75
|
+
"__author__",
|
|
76
|
+
"__license__",
|
|
77
|
+
# High-level API
|
|
78
|
+
"open",
|
|
79
|
+
"GNDCDataset",
|
|
80
|
+
# Reader
|
|
81
|
+
"GNDCReader",
|
|
82
|
+
# Analysis
|
|
83
|
+
"compute_ndvi",
|
|
84
|
+
"compute_evi",
|
|
85
|
+
"compute_ndwi",
|
|
86
|
+
"compute_ndmi",
|
|
87
|
+
"compute_temporal_gradient",
|
|
88
|
+
"compute_spatial_gradient",
|
|
89
|
+
# Viewer
|
|
90
|
+
"GNDCInteractiveViewer",
|
|
91
|
+
"start_viewer",
|
|
92
|
+
]
|