Skip to content

Commit

Permalink
reorg so that gdal is optional
Browse files Browse the repository at this point in the history
only one function uses it for now
  • Loading branch information
scottstanie committed Nov 8, 2023
1 parent 30e2a50 commit 6b8923a
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 31 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
[![Conda-Forge][conda-badge]][conda-link]
[![GitHub Discussion][github-discussions-badge]][github-discussions-link]


<!-- prettier-ignore-start -->
[actions-badge]: https://github.com/opera-adt/opera-utils/workflows/CI/badge.svg
[actions-link]: https://github.com/opera-adt/opera-utils/actions
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/opera_utils/_dates.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import datetime
import re
from pathlib import Path
Expand Down
27 changes: 0 additions & 27 deletions src/opera_utils/_io.py
Original file line number Diff line number Diff line change
@@ -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
24 changes: 22 additions & 2 deletions src/opera_utils/bursts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
----------
Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/opera_utils/constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import re

__all__ = [
Expand Down

0 comments on commit 6b8923a

Please sign in to comment.