-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add stitched geometry creation (#12)
* add static layer download and geometry creation * add more types, fix pre-commits * add tests and fix failing * add tests and fix failing * spacing * try to fix pytet warning, io is optional * install rastserio too * try reverse * try this version * install deps correctly * add another warning ignore, gdal 3.4 * gdal min is 3.5 * missing future import * use `lru_cache` for py38 * add changelog, bump to py39 * remove `cast` * back to `@cache`
- Loading branch information
1 parent
199f2ce
commit 628ece4
Showing
16 changed files
with
1,218 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# [Unreleased](https://github.com/opera-adt/opera-utils/compare/v0.1.4...main) | ||
|
||
**Added** | ||
- Based raster metadata convenience functions as `_io.get_raster_*` | ||
- Ability to download CSLC static layers and stitch into line-of-sight rasters | ||
|
||
|
||
**Requirements** | ||
Minimum python version is 3.9 | ||
|
||
- click>=7.0 | ||
- h5py>=1.10 | ||
- numpy>=1.20 | ||
- pooch>=1.7 | ||
- pyproj>=3.3 | ||
- shapely>=1.8 | ||
- typing_extensions>=4 | ||
|
||
For other interactions with geospatial rasters (i.e. reading metadata, creating geometries from Static Layers): | ||
- asf_search>=6.7.2 | ||
- gdal>=3.5 | ||
- rasterio>=1.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
channels: | ||
- conda-forge | ||
dependencies: | ||
- pyogrio>=0.5 | ||
- gdal>=3.3 | ||
- geopandas-base>=0.12 | ||
- asf_search>=6.7 | ||
- gdal>=3.5 | ||
- rasterio>=1.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Any | ||
|
||
import numpy as np | ||
import rasterio as rio | ||
from affine import Affine | ||
from pyproj import CRS | ||
|
||
from ._types import Bbox, PathOrStr | ||
|
||
|
||
def get_raster_nodata(filename: PathOrStr, band: int = 1) -> float | None: | ||
"""Get the nodata value from a file. | ||
Parameters | ||
---------- | ||
filename : PathOrStr | ||
Path to the file to load. | ||
band : int, optional | ||
Band to get nodata value for, by default 1. | ||
Returns | ||
------- | ||
Optional[float] | ||
Nodata value, or None if not found. | ||
""" | ||
nodatas = _get_dataset_attr(filename, "nodatavals") | ||
return nodatas[band - 1] | ||
|
||
|
||
def get_raster_crs(filename: PathOrStr) -> CRS: | ||
"""Get the CRS from a file. | ||
Parameters | ||
---------- | ||
filename : PathOrStr | ||
Path to the file to load. | ||
Returns | ||
------- | ||
CRS | ||
pyproj CRS for `filename` | ||
""" | ||
return _get_dataset_attr(filename, "crs") | ||
|
||
|
||
def get_raster_transform(filename: PathOrStr) -> Affine: | ||
"""Get the rasterio `Affine` transform from a file. | ||
Parameters | ||
---------- | ||
filename : PathOrStr | ||
Path to the file to load. | ||
Returns | ||
------- | ||
List[float] | ||
6 floats representing a GDAL Geotransform. | ||
""" | ||
return _get_dataset_attr(filename, "transform") | ||
|
||
|
||
def get_raster_gt(filename: PathOrStr) -> list[float]: | ||
"""Get the gdal geotransform from a file. | ||
Parameters | ||
---------- | ||
filename : PathOrStr | ||
Path to the file to load. | ||
Returns | ||
------- | ||
Affine | ||
Two dimensional affine transform for 2D linear mapping. | ||
""" | ||
return get_raster_transform(filename).to_gdal() | ||
|
||
|
||
def get_raster_dtype(filename: PathOrStr, band: int = 1) -> np.dtype: | ||
"""Get the numpy data type from a raster file. | ||
Parameters | ||
---------- | ||
filename : PathOrStr | ||
Path to the file to load. | ||
band : int, optional | ||
Band to get nodata value for, by default 1. | ||
Returns | ||
------- | ||
np.dtype | ||
Data type. | ||
""" | ||
dtype_per_band = _get_dataset_attr(filename, "dtypes") | ||
return np.dtype(dtype_per_band[band - 1]) | ||
|
||
|
||
def get_raster_driver(filename: PathOrStr) -> str: | ||
"""Get the GDAL driver `ShortName` from a file. | ||
Parameters | ||
---------- | ||
filename : PathOrStr | ||
Path to the file to load. | ||
Returns | ||
------- | ||
str | ||
Driver name. | ||
""" | ||
return _get_dataset_attr(filename, "driver") | ||
|
||
|
||
def get_raster_bounds(filename: PathOrStr) -> Bbox: | ||
"""Get the (left, bottom, right, top) bounds of the image.""" | ||
return _get_dataset_attr(filename, "bounds") | ||
|
||
|
||
def _get_dataset_attr(filename: PathOrStr, attr_name: str) -> Any: | ||
with rio.open(filename) as src: | ||
return getattr(src, attr_name) |
Oops, something went wrong.