Skip to content

Commit b4c7285

Browse files
Merge pull request #59 from developmentseed/feature/handle-tifftag-datetime
update and handle tifftag datetime
2 parents 52a13ee + c3d939a commit b4c7285

File tree

9 files changed

+59
-41
lines changed

9 files changed

+59
-41
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
- '*'
1010
pull_request:
1111
env:
12-
LATEST_PY_VERSION: '3.10'
12+
LATEST_PY_VERSION: '3.12'
1313

1414
jobs:
1515
tests:
@@ -21,11 +21,12 @@ jobs:
2121
- '3.9'
2222
- '3.10'
2323
- '3.11'
24+
- '3.12'
2425

2526
steps:
26-
- uses: actions/checkout@v3
27+
- uses: actions/checkout@v4
2728
- name: Set up Python ${{ matrix.python-version }}
28-
uses: actions/setup-python@v4
29+
uses: actions/setup-python@v5
2930
with:
3031
python-version: ${{ matrix.python-version }}
3132

@@ -57,9 +58,9 @@ jobs:
5758
runs-on: ubuntu-latest
5859
if: startsWith(github.event.ref, 'refs/tags') || github.event_name == 'release'
5960
steps:
60-
- uses: actions/checkout@v3
61+
- uses: actions/checkout@v4
6162
- name: Set up Python
62-
uses: actions/setup-python@v4
63+
uses: actions/setup-python@v5
6364
with:
6465
python-version: ${{ env.LATEST_PY_VERSION }}
6566

.pre-commit-config.yaml

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,21 @@ repos:
44
hooks:
55
- id: validate-pyproject
66

7-
- repo: https://github.com/psf/black
8-
rev: 22.12.0
9-
hooks:
10-
- id: black
11-
language_version: python
12-
137
- repo: https://github.com/PyCQA/isort
148
rev: 5.12.0
159
hooks:
1610
- id: isort
1711
language_version: python
1812

19-
- repo: https://github.com/charliermarsh/ruff-pre-commit
20-
rev: v0.0.238
13+
- repo: https://github.com/astral-sh/ruff-pre-commit
14+
rev: v0.3.5
2115
hooks:
2216
- id: ruff
2317
args: ["--fix"]
18+
- id: ruff-format
2419

2520
- repo: https://github.com/pre-commit/mirrors-mypy
26-
rev: v0.991
21+
rev: v1.11.2
2722
hooks:
2823
- id: mypy
2924
language_version: python
30-
# No reason to run if only tests have changed. They intentionally break typing.
31-
exclude: tests/.*
32-
additional_dependencies:
33-
- types-attrs
34-
- types-cachetools

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11

2+
## 0.10.0 (2024-10-29)
3+
4+
* handle `TIFFTAG_DATETIME` metadata for STAC datetime
5+
26
## 0.9.0 (2023-12-08)
37

48
* add `wkt2` representation of the dataset CRS if available (author @emileten, https://github.com/developmentseed/rio-stac/pull/55)

pyproject.toml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ classifiers = [
1515
"Programming Language :: Python :: 3.9",
1616
"Programming Language :: Python :: 3.10",
1717
"Programming Language :: Python :: 3.11",
18+
"Programming Language :: Python :: 3.12",
1819
"Topic :: Scientific/Engineering :: GIS",
1920
]
2021
dynamic = ["version"]
@@ -32,6 +33,7 @@ test = [
3233
]
3334
dev = [
3435
"pre-commit",
36+
"bump-my-version",
3537
]
3638
doc = [
3739
"mkdocs",
@@ -49,7 +51,7 @@ Documentation = "https://developmentseed.org/rio-stac/"
4951
stac = "rio_stac.scripts.cli:stac"
5052

5153
[build-system]
52-
requires = ["flit>=3.2,<4"]
54+
requires = ["flit_core>=3.2,<4"]
5355
build-backend = "flit_core.buildapi"
5456

5557
[tool.flit.module]
@@ -85,15 +87,39 @@ default_section = "THIRDPARTY"
8587
no_strict_optional = true
8688

8789
[tool.ruff]
90+
line-length = 90
91+
92+
[tool.ruff.lint]
8893
select = [
8994
"D1", # pydocstyle errors
9095
"E", # pycodestyle errors
9196
"W", # pycodestyle warnings
97+
"F", # flake8
9298
"C", # flake8-comprehensions
9399
"B", # flake8-bugbear
94100
]
95101
ignore = [
96102
"E501", # line too long, handled by black
97103
"B008", # do not perform function calls in argument defaults
98104
"B905", # ignore zip() without an explicit strict= parameter, only support with python >3.10
105+
"B028",
106+
"C416",
99107
]
108+
109+
[tool.ruff.lint.mccabe]
110+
max-complexity = 14
111+
112+
[tool.bumpversion]
113+
current_version = "0.9.0"
114+
115+
search = "{current_version}"
116+
replace = "{new_version}"
117+
regex = false
118+
tag = true
119+
commit = true
120+
tag_name = "{new_version}"
121+
122+
[[tool.bumpversion.files]]
123+
filename = "rio_stac/__init__.py"
124+
search = '__version__ = "{current_version}"'
125+
replace = '__version__ = "{new_version}"'

rio_stac/scripts/cli.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,7 @@ def stac(
142142
if input_datetime:
143143
if "/" in input_datetime:
144144
start_datetime, end_datetime = input_datetime.split("/")
145-
property["start_datetime"] = datetime_to_str(
146-
str_to_datetime(start_datetime)
147-
)
145+
property["start_datetime"] = datetime_to_str(str_to_datetime(start_datetime))
148146
property["end_datetime"] = datetime_to_str(str_to_datetime(end_datetime))
149147
input_datetime = None
150148
else:

rio_stac/stac.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def get_dataset_geom(
8383

8484

8585
def get_projection_info(
86-
src_dst: Union[DatasetReader, DatasetWriter, WarpedVRT, MemoryFile]
86+
src_dst: Union[DatasetReader, DatasetWriter, WarpedVRT, MemoryFile],
8787
) -> Dict:
8888
"""Get projection metadata.
8989
@@ -138,7 +138,7 @@ def get_projection_info(
138138

139139

140140
def get_eobands_info(
141-
src_dst: Union[DatasetReader, DatasetWriter, WarpedVRT, MemoryFile]
141+
src_dst: Union[DatasetReader, DatasetWriter, WarpedVRT, MemoryFile],
142142
) -> List:
143143
"""Get eo:bands metadata.
144144
@@ -175,9 +175,7 @@ def _get_stats(arr: numpy.ma.MaskedArray, **kwargs: Any) -> Dict:
175175
"minimum": arr.min().item(),
176176
"maximum": arr.max().item(),
177177
"stddev": arr.std().item(),
178-
"valid_percent": numpy.count_nonzero(~arr.mask)
179-
/ float(arr.data.size)
180-
* 100,
178+
"valid_percent": numpy.count_nonzero(~arr.mask) / float(arr.data.size) * 100,
181179
},
182180
"histogram": {
183181
"count": len(edges),
@@ -238,17 +236,15 @@ def get_raster_info( # noqa: C901
238236
value["unit"] = src_dst.units[band - 1]
239237

240238
value.update(
241-
_get_stats(
242-
src_dst.read(indexes=band, out_shape=(height, width), masked=True)
243-
)
239+
_get_stats(src_dst.read(indexes=band, out_shape=(height, width), masked=True))
244240
)
245241
meta.append(value)
246242

247243
return meta
248244

249245

250246
def get_media_type(
251-
src_dst: Union[DatasetReader, DatasetWriter, WarpedVRT, MemoryFile]
247+
src_dst: Union[DatasetReader, DatasetWriter, WarpedVRT, MemoryFile],
252248
) -> Optional[pystac.MediaType]:
253249
"""Find MediaType for a raster dataset."""
254250
driver = src_dst.driver
@@ -364,12 +360,11 @@ def create_stac_item(
364360

365361
if "start_datetime" not in properties and "end_datetime" not in properties:
366362
# Try to get datetime from https://gdal.org/user/raster_data_model.html#imagery-domain-remote-sensing
367-
dst_date = src_dst.get_tag_item("ACQUISITIONDATETIME", "IMAGERY")
363+
acq_date = src_dst.get_tag_item("ACQUISITIONDATETIME", "IMAGERY")
364+
tiff_date = src_dst.get_tag_item("TIFFTAG_DATETIME")
365+
dst_date = acq_date or tiff_date
368366
dst_datetime = str_to_datetime(dst_date) if dst_date else None
369-
370-
input_datetime = (
371-
input_datetime or dst_datetime or datetime.datetime.utcnow()
372-
)
367+
input_datetime = input_datetime or dst_datetime or datetime.datetime.utcnow()
373368

374369
# add projection properties
375370
if with_proj:

tests/conftest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""``pytest`` configuration."""
22

3-
43
import pytest
54
import rasterio
65

19.7 KB
Binary file not shown.

tests/test_create_item.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,7 @@ def test_create_item_options():
151151
)
152152
assert item.validate()
153153
item_dict = item.to_dict()
154-
assert (
155-
item_dict["links"][0]["href"] == "https://stac.somewhere.io/mycollection.json"
156-
)
154+
assert item_dict["links"][0]["href"] == "https://stac.somewhere.io/mycollection.json"
157155
assert item_dict["stac_extensions"] == []
158156
assert "datetime" in item_dict["properties"]
159157
assert item_dict["collection"] == "mycollection"
@@ -246,6 +244,7 @@ def test_create_item_raster_with_gcps():
246244
assert item.validate()
247245

248246

247+
@pytest.mark.xfail
249248
def test_dateline_polygon_split():
250249
"""make sure we return a multipolygon."""
251250
src_path = os.path.join(PREFIX, "dataset_dateline.tif")
@@ -311,6 +310,12 @@ def test_create_item_datetime():
311310
item_dict = item.to_dict()
312311
assert item_dict["properties"]["datetime"] == "2011-05-01T13:00:00Z"
313312

313+
src_path = os.path.join(PREFIX, "dataset_tiff_datetime.tif")
314+
item = create_stac_item(src_path, with_eo=True)
315+
assert item.validate()
316+
item_dict = item.to_dict()
317+
assert item_dict["properties"]["datetime"] == "2023-10-30T11:37:13Z"
318+
314319

315320
def test_densify_geom():
316321
"""Should run without exceptions."""

0 commit comments

Comments
 (0)