diff --git a/README.md b/README.md index e505efb..273d5fa 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,6 @@ [![Conda-Forge][conda-badge]][conda-link] [![GitHub Discussion][github-discussions-badge]][github-discussions-link] - [actions-badge]: https://github.com/opera-adt/opera-utils/workflows/CI/badge.svg [actions-link]: https://github.com/opera-adt/opera-utils/actions diff --git a/environment.yml b/environment.yml index 9c2c051..275224f 100644 --- a/environment.yml +++ b/environment.yml @@ -5,6 +5,6 @@ dependencies: - python>=3.9 - pip>=21.3 # https://pip.pypa.io/en/stable/reference/build-system/pyproject-toml/#editable-installation - git # for pip install, due to setuptools_scm - - gdal>=3.3 - h5py>=1.10 - shapely>=1.8 + # - gdal>=3.3 # For now, gdal will be an optional dependency diff --git a/src/opera_utils/_dates.py b/src/opera_utils/_dates.py index ebb5057..d4ebb72 100644 --- a/src/opera_utils/_dates.py +++ b/src/opera_utils/_dates.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import datetime import re from pathlib import Path diff --git a/src/opera_utils/_io.py b/src/opera_utils/_io.py index e93ceb3..e69de29 100644 --- a/src/opera_utils/_io.py +++ b/src/opera_utils/_io.py @@ -1,27 +0,0 @@ -from os import fspath - -from osgeo import gdal - -from ._types import Filename - -__all__ = [ - "get_raster_gt", -] - - -def get_raster_gt(filename: Filename) -> list[float]: - """Get the geotransform from a file. - - Parameters - ---------- - filename : Filename - Path to the file to load. - - Returns - ------- - List[float] - 6 floats representing a GDAL Geotransform. - """ - ds = gdal.Open(fspath(filename)) - gt = ds.GetGeoTransform() - return gt diff --git a/src/opera_utils/bursts.py b/src/opera_utils/bursts.py index 5926eda..02f64ba 100644 --- a/src/opera_utils/bursts.py +++ b/src/opera_utils/bursts.py @@ -6,13 +6,13 @@ import re import subprocess import tempfile +from os import fspath from pathlib import Path from typing import Iterable, Pattern, Sequence, Union, overload import h5py from shapely import geometry, ops, wkt -from ._io import get_raster_gt from ._types import Filename, PathLikeT from .constants import OPERA_BURST_RE, OPERA_DATASET_NAME, OPERA_IDENTIFICATION @@ -178,7 +178,7 @@ def make_nodata_mask( buffer_pixels: int = 0, overwrite: bool = False, ): - """Make a boolean raster mask from the union of nodata polygons. + """Make a boolean raster mask from the union of nodata polygons using GDAL. Parameters ---------- @@ -245,3 +245,23 @@ def make_nodata_mask( cmd = f"gdal_rasterize -q -burn 1 {temp_vector_file} {out_file}" logger.info(cmd) subprocess.check_call(cmd, shell=True) + + +def get_raster_gt(filename: Filename) -> list[float]: + """Get the geotransform from a file. + + Parameters + ---------- + filename : Filename + Path to the file to load. + + Returns + ------- + List[float] + 6 floats representing a GDAL Geotransform. + """ + from osgeo import gdal + + ds = gdal.Open(fspath(filename)) + gt = ds.GetGeoTransform() + return gt diff --git a/src/opera_utils/constants.py b/src/opera_utils/constants.py index d9326f0..468baf7 100644 --- a/src/opera_utils/constants.py +++ b/src/opera_utils/constants.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import re __all__ = [