freezebase 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.
- freezebase-0.3.0/.gitignore +59 -0
- freezebase-0.3.0/CHANGELOG.md +120 -0
- freezebase-0.3.0/LICENSE +21 -0
- freezebase-0.3.0/PKG-INFO +191 -0
- freezebase-0.3.0/README.md +149 -0
- freezebase-0.3.0/pyproject.toml +239 -0
- freezebase-0.3.0/src/freezebase/__init__.py +42 -0
- freezebase-0.3.0/src/freezebase/download.py +543 -0
- freezebase-0.3.0/src/freezebase/mgrs.py +768 -0
- freezebase-0.3.0/src/freezebase/pandas_utils.py +97 -0
- freezebase-0.3.0/src/freezebase/progress.py +124 -0
- freezebase-0.3.0/src/freezebase/py.typed +0 -0
- freezebase-0.3.0/src/freezebase/raster.py +751 -0
- freezebase-0.3.0/src/freezebase/s3.py +330 -0
- freezebase-0.3.0/src/freezebase/utils.py +265 -0
- freezebase-0.3.0/src/freezebase/vectools.py +200 -0
- freezebase-0.3.0/src/freezebase/vectordata.py +263 -0
- freezebase-0.3.0/src/freezebase/vrt.py +425 -0
- freezebase-0.3.0/tests/__init__.py +1 -0
- freezebase-0.3.0/tests/test_download.py +341 -0
- freezebase-0.3.0/tests/test_mgrs.py +248 -0
- freezebase-0.3.0/tests/test_pandas_utils.py +39 -0
- freezebase-0.3.0/tests/test_raster.py +246 -0
- freezebase-0.3.0/tests/test_s3.py +356 -0
- freezebase-0.3.0/tests/test_s3_integration.py +190 -0
- freezebase-0.3.0/tests/test_utils.py +119 -0
- freezebase-0.3.0/tests/test_vectools.py +211 -0
- freezebase-0.3.0/tests/test_vectordata.py +126 -0
- freezebase-0.3.0/tests/test_vrt.py +309 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Environments
|
|
2
|
+
.env
|
|
3
|
+
.venv/
|
|
4
|
+
|
|
5
|
+
# Storage
|
|
6
|
+
data/
|
|
7
|
+
cache/
|
|
8
|
+
models/
|
|
9
|
+
|
|
10
|
+
# Python temp files
|
|
11
|
+
__pycache__
|
|
12
|
+
|
|
13
|
+
# macOS
|
|
14
|
+
**/.DS_Store
|
|
15
|
+
|
|
16
|
+
# Distribution / packaging
|
|
17
|
+
.Python
|
|
18
|
+
build/
|
|
19
|
+
develop-eggs/
|
|
20
|
+
dist/
|
|
21
|
+
downloads/
|
|
22
|
+
eggs/
|
|
23
|
+
.eggs/
|
|
24
|
+
lib/
|
|
25
|
+
lib64/
|
|
26
|
+
parts/
|
|
27
|
+
sdist/
|
|
28
|
+
var/
|
|
29
|
+
wheels/
|
|
30
|
+
share/python-wheels/
|
|
31
|
+
*.egg-info/
|
|
32
|
+
.installed.cfg
|
|
33
|
+
*.egg
|
|
34
|
+
MANIFEST
|
|
35
|
+
|
|
36
|
+
# Tools
|
|
37
|
+
.mypy_cache/
|
|
38
|
+
.dmypy*.json
|
|
39
|
+
dmypy*.json
|
|
40
|
+
.ruff_cache/
|
|
41
|
+
.claude/
|
|
42
|
+
|
|
43
|
+
# Documentation
|
|
44
|
+
great-docs/
|
|
45
|
+
|
|
46
|
+
# Unit test / coverage reports
|
|
47
|
+
htmlcov/
|
|
48
|
+
.tox/
|
|
49
|
+
.nox/
|
|
50
|
+
.coverage
|
|
51
|
+
.coverage.*
|
|
52
|
+
.cache
|
|
53
|
+
nosetests.xml
|
|
54
|
+
coverage.xml
|
|
55
|
+
*.cover
|
|
56
|
+
*.py.cover
|
|
57
|
+
.hypothesis/
|
|
58
|
+
.pytest_cache/
|
|
59
|
+
cover/
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
While the project is pre-1.0 (`0.x`), minor releases may contain breaking changes.
|
|
8
|
+
|
|
9
|
+
## [0.3.0] - 2026-08-05
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- Per-path named AWS profile support in `make_s3_upath`. Combinable with a custom
|
|
14
|
+
`endpoint_url`, mutually exclusive with `anon=True` and explicit
|
|
15
|
+
`key`/`secret`/`token`. Setting a profile takes environment credentials out of
|
|
16
|
+
boto's resolution chain, so the path signs with the profile's keys only.
|
|
17
|
+
- `aws_session`, returning the cached Rasterio `AWSSession` for an S3 path, and
|
|
18
|
+
`clear_aws_session_cache` to discard those sessions. Prefer `aws_session` over
|
|
19
|
+
constructing an `AWSSession` directly, so every layer signs identically.
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
|
|
23
|
+
- Renamed the package to `freezebase`, to allow publication on
|
|
24
|
+
PyPI under the same name. The import path, PyPI distribution name,
|
|
25
|
+
`FREEZEBASE_CACHE`/`FREEZEBASE_DATA` environment variables, and the GitHub
|
|
26
|
+
repository all changed accordingly; there is no compatibility shim for the old names.
|
|
27
|
+
- `s3_env` reuses a cached `AWSSession` per distinct S3 configuration instead of
|
|
28
|
+
building one per call. Constructing a session resolves boto's whole credential
|
|
29
|
+
chain eagerly, and `s3_env` is entered on every raster operation, so a
|
|
30
|
+
profile-authenticated path previously re-read the shared credentials file
|
|
31
|
+
for every raster read and write. Refreshable STS/SSO credentials still rotate, because
|
|
32
|
+
Rasterio re-freezes them on each `Env` entry; static credentials rewritten
|
|
33
|
+
mid-process now need `clear_aws_session_cache`.
|
|
34
|
+
- `make_s3_upath` rejects credentials in `client_kwargs`, which reach s3fs but
|
|
35
|
+
not `s3_env`.
|
|
36
|
+
|
|
37
|
+
## [0.2.0] - 2026-08-03
|
|
38
|
+
|
|
39
|
+
### Added
|
|
40
|
+
|
|
41
|
+
- Explicit `anon` argument on `make_s3_upath`, matching the `anon` parameter of
|
|
42
|
+
`s3fs.S3FileSystem`: `anon=True` uses an anonymous connection (public buckets
|
|
43
|
+
only); `anon=False` (the default) uses the `key`/`secret` given, or boto's
|
|
44
|
+
credential resolver. Combining `anon=True` with `key`, `secret`, or `token`
|
|
45
|
+
raises `ValueError`.
|
|
46
|
+
|
|
47
|
+
### Changed
|
|
48
|
+
|
|
49
|
+
- **Breaking:** anonymous S3 access is now opt-in.
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
# before
|
|
53
|
+
path = make_s3_upath("s3://copernicus-dem-30m/x.tif", region="eu-central-1")
|
|
54
|
+
# after
|
|
55
|
+
path = make_s3_upath("s3://copernicus-dem-30m/x.tif", region="eu-central-1", anon=True)
|
|
56
|
+
|
|
57
|
+
### Fixed
|
|
58
|
+
|
|
59
|
+
- `make_s3_upath` (for s3fs) and `s3_env` (for GDAL) now agree on the
|
|
60
|
+
anonymous/signed decision. Previously, without passing credentials, GDAL read
|
|
61
|
+
unsigned while s3fs signed via boto's resolver.
|
|
62
|
+
|
|
63
|
+
## [0.1.0] - 2026-07-27
|
|
64
|
+
|
|
65
|
+
### Added
|
|
66
|
+
|
|
67
|
+
- `py.typed` marker so downstream type checkers use the inline annotations.
|
|
68
|
+
- Optional `DatasetMetadata.sha256` to verify a raw download against a known
|
|
69
|
+
hash (`freezebase.vectordata`).
|
|
70
|
+
- `freezebase.utils.file_sha256` helper.
|
|
71
|
+
- Packaging metadata: project URLs, keywords, and classifiers.
|
|
72
|
+
- GitHub Actions CI (lint, type-check, test matrix on 3.12/3.13, a
|
|
73
|
+
lowest-bound dependency job, a MinIO-backed S3 integration job, and a build +
|
|
74
|
+
wheel smoke-test) and a Trusted-Publishing release workflow.
|
|
75
|
+
- S3 integration tests (`tests/test_s3_integration.py`, `integration` marker),
|
|
76
|
+
skipped unless `FREEZEBASE_TEST_S3_*` is set.
|
|
77
|
+
- `freezebase.s3.s3_env`, a rasterio context manager that configures
|
|
78
|
+
credentials and endpoint for S3-compatible object storage from a `UPath`'s
|
|
79
|
+
storage options. Usable with `rasterio` or `rioxarray`.
|
|
80
|
+
- `rewrite_tiff` can now copy between two different S3 backends (e.g. an
|
|
81
|
+
unsigned public bucket to a private one); the source read and destination
|
|
82
|
+
write each apply their own credentials, so the previous same-backend
|
|
83
|
+
restriction is gone.
|
|
84
|
+
|
|
85
|
+
### Changed
|
|
86
|
+
|
|
87
|
+
- **Breaking:** `make_s3_upath` renamed its first parameter `root` → `path` and
|
|
88
|
+
gained optional `token` and `region`; `key`/`secret` are now optional so it
|
|
89
|
+
can build paths for anonymous (unsigned) access to public buckets.
|
|
90
|
+
- S3 rasterio setup consolidated into `freezebase.s3` and is now rasterio-only:
|
|
91
|
+
the optional GDAL helper were removed
|
|
92
|
+
- Dependency lower bounds corrected to the oldest versions that actually
|
|
93
|
+
install and work on Python 3.12: notably `numpy>=2.0` (code uses `np.concat`),
|
|
94
|
+
`shapely>=2.1.0` (`transform(interleaved=...)`), `pyarrow>=17.0` (NumPy 2 ABI),
|
|
95
|
+
`pyproj>=3.6.1`, `boto3>=1.36`, and `s3fs>=2026.2.0`/`fsspec>=2026.2.0`
|
|
96
|
+
(`set_custom_error_handler`).
|
|
97
|
+
- Licensing metadata modernized to PEP 639 (`license = "MIT"` +
|
|
98
|
+
`license-files`), and the sdist no longer ships `.python-version`/`uv.lock`.
|
|
99
|
+
- **Breaking:** `GeoVectorData.remove()` is renamed to `cleanup()` and now
|
|
100
|
+
defaults to removing only the raw download (`raw=True, processed=False`),
|
|
101
|
+
keeping the processed data.
|
|
102
|
+
- **Breaking:** `rewrite_tiff()` no longer deletes the source by default; pass
|
|
103
|
+
`move=True` for the previous move semantics.
|
|
104
|
+
- `HTTPDownloader.__call__` gained an `overwrite` keyword (default `False`) and
|
|
105
|
+
now rejects unsafe/inferred filenames that would escape the destination.
|
|
106
|
+
- S3 transient-retry codes narrowed so a permanent `AccessDenied`/403 is no
|
|
107
|
+
longer retried.
|
|
108
|
+
- `COG_PROFILE` now sets `OVERVIEW_RESAMPLING=AVERAGE` (GDAL defaults to
|
|
109
|
+
`CUBIC`, which propagates NODATA into overview pyramids) and
|
|
110
|
+
`PREDICTOR=YES`/`PREDICTOR_OVERVIEW=YES`, which shrinks float32 rasters by
|
|
111
|
+
~10-15% at unchanged write cost.
|
|
112
|
+
|
|
113
|
+
### Fixed
|
|
114
|
+
|
|
115
|
+
- Filename confinement and redirect credential handling in the downloader.
|
|
116
|
+
- Destination/source preservation on failure in `rewrite_tiff`.
|
|
117
|
+
- Numerous MGRS/UTM/CRS validation and parsing defects.
|
|
118
|
+
- VRT/merge input validation and XML-safe VRT generation.
|
|
119
|
+
- Z-coordinate detection across polygon interior rings and mixed collections.
|
|
120
|
+
- Atomic cache writes and verification-state reset on removal.
|
freezebase-0.3.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Luis Q. Gentner
|
|
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.
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: freezebase
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Lightweight geospatial helpers for reproducible MGRS grids and S3-backed raster workflows.
|
|
5
|
+
Project-URL: Homepage, https://github.com/lqgentner/freezebase
|
|
6
|
+
Project-URL: Repository, https://github.com/lqgentner/freezebase
|
|
7
|
+
Project-URL: Issues, https://github.com/lqgentner/freezebase/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/lqgentner/freezebase/blob/main/CHANGELOG.md
|
|
9
|
+
Author-email: Luis Gentner <luis.gentner@geo.uzh.ch>
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: cog,geospatial,geotiff,mgrs,raster,remote-sensing,s3,sentinel-1,utm,vrt
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Science/Research
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: GIS
|
|
20
|
+
Classifier: Typing :: Typed
|
|
21
|
+
Requires-Python: >=3.12
|
|
22
|
+
Requires-Dist: affine>=2.4.0
|
|
23
|
+
Requires-Dist: geopandas>=1.1
|
|
24
|
+
Requires-Dist: mgrs>=1.4.4
|
|
25
|
+
Requires-Dist: numpy>=2.0
|
|
26
|
+
Requires-Dist: odc-geo>=0.5.0
|
|
27
|
+
Requires-Dist: pandas>=2.3
|
|
28
|
+
Requires-Dist: platformdirs>=3.0
|
|
29
|
+
Requires-Dist: pyarrow>=17.0
|
|
30
|
+
Requires-Dist: pyproj>=3.6.1
|
|
31
|
+
Requires-Dist: rasterio>=1.5.0
|
|
32
|
+
Requires-Dist: requests>=2.28
|
|
33
|
+
Requires-Dist: rich>=13
|
|
34
|
+
Requires-Dist: shapely>=2.1.0
|
|
35
|
+
Requires-Dist: tenacity>=8.2
|
|
36
|
+
Requires-Dist: universal-pathlib>=0.3
|
|
37
|
+
Provides-Extra: s3
|
|
38
|
+
Requires-Dist: boto3>=1.36; extra == 's3'
|
|
39
|
+
Requires-Dist: fsspec>=2026.2.0; extra == 's3'
|
|
40
|
+
Requires-Dist: s3fs>=2026.2.0; extra == 's3'
|
|
41
|
+
Description-Content-Type: text/markdown
|
|
42
|
+
|
|
43
|
+
# freezebase
|
|
44
|
+
|
|
45
|
+
Lightweight geospatial helpers for reproducible MGRS grids and S3-backed raster workflows.
|
|
46
|
+
|
|
47
|
+
freezebase grew out of large-scale glacier mapping, where scattered areas of
|
|
48
|
+
interest require several local projections and large raster collections live
|
|
49
|
+
in object storage.
|
|
50
|
+
|
|
51
|
+
The centrepiece of freezebase is **`MGRSGrid`**: a 10 km grid for the UTM-covered
|
|
52
|
+
world that gives every MGRS code a dataset-independent target backed by an
|
|
53
|
+
[`odc.geo.GeoBox`](https://odc-geo.readthedocs.io/en/latest/intro-geobox.html).
|
|
54
|
+
Rasters resampled to the same code and resolution share their CRS, transform,
|
|
55
|
+
and shape. See
|
|
56
|
+
[The MGRS grid](https://lqgentner.github.io/freezebase/user-guide/mgrs-grid.html)
|
|
57
|
+
for the reasoning.
|
|
58
|
+
|
|
59
|
+
## Installation
|
|
60
|
+
|
|
61
|
+
Requires Python 3.12 or newer, and [uv](https://docs.astral.sh/uv/) or pip.
|
|
62
|
+
|
|
63
|
+
freezebase is on [PyPI](https://pypi.org/project/freezebase/):
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
# uv
|
|
67
|
+
uv add freezebase
|
|
68
|
+
|
|
69
|
+
# pip
|
|
70
|
+
pip install freezebase
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
S3 support is optional; see [Raster and S3 helpers](#raster-and-s3-helpers)
|
|
74
|
+
below.
|
|
75
|
+
|
|
76
|
+
## MGRS quick start
|
|
77
|
+
|
|
78
|
+
Build the 10 km grid covering an area of interest:
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
from shapely import box
|
|
82
|
+
|
|
83
|
+
from freezebase.mgrs import MGRSGrid
|
|
84
|
+
|
|
85
|
+
grid = MGRSGrid(box(8.4, 47.3, 8.6, 47.5)) # Zürich, WGS84
|
|
86
|
+
gdf = grid.to_geodataframe() # mgrs_code, zone, epsg, geometry, ...
|
|
87
|
+
square = grid[0] # an odc.geo GeoBox per grid square
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Each square is an `MGRSGeoBox` — a subclass of
|
|
91
|
+
[`odc.geo.GeoBox`](https://odc-geo.readthedocs.io/en/latest/intro-geobox.html)
|
|
92
|
+
carrying the CRS, affine transform, and shape needed to resample any raster onto
|
|
93
|
+
it. Reconstruct one from its code alone, without building a grid:
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
from freezebase.mgrs import MGRSGeoBox
|
|
97
|
+
|
|
98
|
+
square = MGRSGeoBox.from_mgrs("32TMS35", resolution=10.0) # 1000 x 1000 px, EPSG:32632
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Raster and S3 helpers
|
|
102
|
+
|
|
103
|
+
The raster helpers use [Rasterio](https://rasterio.readthedocs.io/) for local
|
|
104
|
+
I/O. For object storage, freezebase bridges Rasterio/GDAL with
|
|
105
|
+
[Universal Pathlib](https://universal-pathlib.readthedocs.io/), so filesystem
|
|
106
|
+
operations and raster I/O use the same per-path credentials and endpoint
|
|
107
|
+
configuration.
|
|
108
|
+
|
|
109
|
+
Rewrite a local GeoTIFF as a Cloud-Optimized GeoTIFF:
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
from freezebase.raster import COG_PROFILE, rewrite_tiff
|
|
113
|
+
|
|
114
|
+
rewrite_tiff("in.tif", "out.tif", profile=COG_PROFILE) # copy
|
|
115
|
+
rewrite_tiff("in.tif", "out.tif", profile=COG_PROFILE, move=True) # move
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### The `s3` extra
|
|
119
|
+
|
|
120
|
+
S3 support needs the optional `s3fs`, `fsspec`, and `boto3` dependencies:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
uv add "freezebase[s3]"
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Credentials and endpoint configuration travel with each path. Named profiles
|
|
127
|
+
make it possible to select different stores without attaching raw credential
|
|
128
|
+
values:
|
|
129
|
+
|
|
130
|
+
```python
|
|
131
|
+
from freezebase.s3 import make_s3_upath
|
|
132
|
+
|
|
133
|
+
aws_path = make_s3_upath("s3://aws-bucket/data", profile="research")
|
|
134
|
+
ceph_path = make_s3_upath(
|
|
135
|
+
"s3://ceph-bucket/data",
|
|
136
|
+
profile="ceph-research",
|
|
137
|
+
endpoint_url="https://objects.example.org",
|
|
138
|
+
)
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
An explicitly selected profile also prevents boto from falling back to ambient
|
|
142
|
+
`AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` values from the shell.
|
|
143
|
+
|
|
144
|
+
The same configured path works for pathlib-style discovery and Rasterio reads:
|
|
145
|
+
|
|
146
|
+
```python
|
|
147
|
+
from freezebase.raster import rasterio_open
|
|
148
|
+
|
|
149
|
+
scene = aws_path / "scene.tif"
|
|
150
|
+
if scene.exists():
|
|
151
|
+
with rasterio_open(scene) as src:
|
|
152
|
+
data = src.read(1)
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Public buckets use `anon=True`. See [Rasters on
|
|
156
|
+
S3](https://lqgentner.github.io/freezebase/user-guide/rasters-on-s3.html) for
|
|
157
|
+
authentication patterns, custom endpoints, and S3-to-S3 copies.
|
|
158
|
+
|
|
159
|
+
## Other helpers
|
|
160
|
+
|
|
161
|
+
Download a file with retries and a progress bar:
|
|
162
|
+
|
|
163
|
+
```python
|
|
164
|
+
from freezebase.download import HTTPDownloader
|
|
165
|
+
|
|
166
|
+
download = HTTPDownloader(auth=("user", "pass"))
|
|
167
|
+
path = download("https://example.org/data.zip", "cache/") # -> Path
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## Documentation
|
|
171
|
+
|
|
172
|
+
Full documentation, including the MGRS grid guide and the S3 raster guide, is at
|
|
173
|
+
**<https://lqgentner.github.io/freezebase/>**.
|
|
174
|
+
|
|
175
|
+
## Support
|
|
176
|
+
|
|
177
|
+
This is a small internal core library maintained on a best-effort basis. Please
|
|
178
|
+
file bugs and questions on the
|
|
179
|
+
[issue tracker](https://github.com/lqgentner/freezebase/issues).
|
|
180
|
+
|
|
181
|
+
## Contributing
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
git clone https://github.com/lqgentner/freezebase.git
|
|
185
|
+
cd freezebase
|
|
186
|
+
uv sync --all-extras
|
|
187
|
+
uv run pytest
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
See the [contributing guide](https://lqgentner.github.io/freezebase/user-guide/contributing.html)
|
|
191
|
+
for the full checks, the S3 integration tests, and how to build these docs.
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# freezebase
|
|
2
|
+
|
|
3
|
+
Lightweight geospatial helpers for reproducible MGRS grids and S3-backed raster workflows.
|
|
4
|
+
|
|
5
|
+
freezebase grew out of large-scale glacier mapping, where scattered areas of
|
|
6
|
+
interest require several local projections and large raster collections live
|
|
7
|
+
in object storage.
|
|
8
|
+
|
|
9
|
+
The centrepiece of freezebase is **`MGRSGrid`**: a 10 km grid for the UTM-covered
|
|
10
|
+
world that gives every MGRS code a dataset-independent target backed by an
|
|
11
|
+
[`odc.geo.GeoBox`](https://odc-geo.readthedocs.io/en/latest/intro-geobox.html).
|
|
12
|
+
Rasters resampled to the same code and resolution share their CRS, transform,
|
|
13
|
+
and shape. See
|
|
14
|
+
[The MGRS grid](https://lqgentner.github.io/freezebase/user-guide/mgrs-grid.html)
|
|
15
|
+
for the reasoning.
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
Requires Python 3.12 or newer, and [uv](https://docs.astral.sh/uv/) or pip.
|
|
20
|
+
|
|
21
|
+
freezebase is on [PyPI](https://pypi.org/project/freezebase/):
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
# uv
|
|
25
|
+
uv add freezebase
|
|
26
|
+
|
|
27
|
+
# pip
|
|
28
|
+
pip install freezebase
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
S3 support is optional; see [Raster and S3 helpers](#raster-and-s3-helpers)
|
|
32
|
+
below.
|
|
33
|
+
|
|
34
|
+
## MGRS quick start
|
|
35
|
+
|
|
36
|
+
Build the 10 km grid covering an area of interest:
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
from shapely import box
|
|
40
|
+
|
|
41
|
+
from freezebase.mgrs import MGRSGrid
|
|
42
|
+
|
|
43
|
+
grid = MGRSGrid(box(8.4, 47.3, 8.6, 47.5)) # Zürich, WGS84
|
|
44
|
+
gdf = grid.to_geodataframe() # mgrs_code, zone, epsg, geometry, ...
|
|
45
|
+
square = grid[0] # an odc.geo GeoBox per grid square
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Each square is an `MGRSGeoBox` — a subclass of
|
|
49
|
+
[`odc.geo.GeoBox`](https://odc-geo.readthedocs.io/en/latest/intro-geobox.html)
|
|
50
|
+
carrying the CRS, affine transform, and shape needed to resample any raster onto
|
|
51
|
+
it. Reconstruct one from its code alone, without building a grid:
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
from freezebase.mgrs import MGRSGeoBox
|
|
55
|
+
|
|
56
|
+
square = MGRSGeoBox.from_mgrs("32TMS35", resolution=10.0) # 1000 x 1000 px, EPSG:32632
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Raster and S3 helpers
|
|
60
|
+
|
|
61
|
+
The raster helpers use [Rasterio](https://rasterio.readthedocs.io/) for local
|
|
62
|
+
I/O. For object storage, freezebase bridges Rasterio/GDAL with
|
|
63
|
+
[Universal Pathlib](https://universal-pathlib.readthedocs.io/), so filesystem
|
|
64
|
+
operations and raster I/O use the same per-path credentials and endpoint
|
|
65
|
+
configuration.
|
|
66
|
+
|
|
67
|
+
Rewrite a local GeoTIFF as a Cloud-Optimized GeoTIFF:
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
from freezebase.raster import COG_PROFILE, rewrite_tiff
|
|
71
|
+
|
|
72
|
+
rewrite_tiff("in.tif", "out.tif", profile=COG_PROFILE) # copy
|
|
73
|
+
rewrite_tiff("in.tif", "out.tif", profile=COG_PROFILE, move=True) # move
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### The `s3` extra
|
|
77
|
+
|
|
78
|
+
S3 support needs the optional `s3fs`, `fsspec`, and `boto3` dependencies:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
uv add "freezebase[s3]"
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Credentials and endpoint configuration travel with each path. Named profiles
|
|
85
|
+
make it possible to select different stores without attaching raw credential
|
|
86
|
+
values:
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
from freezebase.s3 import make_s3_upath
|
|
90
|
+
|
|
91
|
+
aws_path = make_s3_upath("s3://aws-bucket/data", profile="research")
|
|
92
|
+
ceph_path = make_s3_upath(
|
|
93
|
+
"s3://ceph-bucket/data",
|
|
94
|
+
profile="ceph-research",
|
|
95
|
+
endpoint_url="https://objects.example.org",
|
|
96
|
+
)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
An explicitly selected profile also prevents boto from falling back to ambient
|
|
100
|
+
`AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` values from the shell.
|
|
101
|
+
|
|
102
|
+
The same configured path works for pathlib-style discovery and Rasterio reads:
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
from freezebase.raster import rasterio_open
|
|
106
|
+
|
|
107
|
+
scene = aws_path / "scene.tif"
|
|
108
|
+
if scene.exists():
|
|
109
|
+
with rasterio_open(scene) as src:
|
|
110
|
+
data = src.read(1)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Public buckets use `anon=True`. See [Rasters on
|
|
114
|
+
S3](https://lqgentner.github.io/freezebase/user-guide/rasters-on-s3.html) for
|
|
115
|
+
authentication patterns, custom endpoints, and S3-to-S3 copies.
|
|
116
|
+
|
|
117
|
+
## Other helpers
|
|
118
|
+
|
|
119
|
+
Download a file with retries and a progress bar:
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
from freezebase.download import HTTPDownloader
|
|
123
|
+
|
|
124
|
+
download = HTTPDownloader(auth=("user", "pass"))
|
|
125
|
+
path = download("https://example.org/data.zip", "cache/") # -> Path
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Documentation
|
|
129
|
+
|
|
130
|
+
Full documentation, including the MGRS grid guide and the S3 raster guide, is at
|
|
131
|
+
**<https://lqgentner.github.io/freezebase/>**.
|
|
132
|
+
|
|
133
|
+
## Support
|
|
134
|
+
|
|
135
|
+
This is a small internal core library maintained on a best-effort basis. Please
|
|
136
|
+
file bugs and questions on the
|
|
137
|
+
[issue tracker](https://github.com/lqgentner/freezebase/issues).
|
|
138
|
+
|
|
139
|
+
## Contributing
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
git clone https://github.com/lqgentner/freezebase.git
|
|
143
|
+
cd freezebase
|
|
144
|
+
uv sync --all-extras
|
|
145
|
+
uv run pytest
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
See the [contributing guide](https://lqgentner.github.io/freezebase/user-guide/contributing.html)
|
|
149
|
+
for the full checks, the S3 integration tests, and how to build these docs.
|