Skip to content

Commit

Permalink
fix: Do not use SENSING_TIME for Temporal/RangeDateTime field (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
ceholden authored Feb 6, 2025
1 parent d3bc590 commit f3892ba
Showing 1 changed file with 0 additions and 61 deletions.
61 changes: 0 additions & 61 deletions hls_vi/generate_metadata.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import getopt
import importlib_resources
import os
import re
import sys
from xml.dom import minidom

Expand All @@ -14,62 +13,6 @@
from lxml.etree import Element, ElementBase


def parse_sensing_time(sensing_time: str) -> Tuple[str, str]:
"""Parse SENSING_TIME tag value into (start, end) tuple.
Expect `sensing_time` in one of the following forms, where each `DT` is an ISO 8601
combined date and time representation, with a `Z` suffix (and optional whitespace
surrounding `+` and `;` separators):
- `DT`
- `DT; DT`
- `DT + DT; DT`
- `DT; DT + DT`
- `DT + DT; DT + DT`
Sort all `DT` values in ascending order and return the min and max, respectively,
in a tuple. When only one `DT` value is specified, both values in the tuple are
the same value.
Examples:
>>> parse_sensing_time("2024-04-29T21:11:59.7221750Z")
('2024-04-29T21:11:59.7221750Z', '2024-04-29T21:11:59.7221750Z')
>>> parse_sensing_time(";2024-04-29T21:11:59.7221750Z")
('2024-04-29T21:11:59.7221750Z', '2024-04-29T21:11:59.7221750Z')
>>> parse_sensing_time("2024-04-29T21:11:59.7221750Z;")
('2024-04-29T21:11:59.7221750Z', '2024-04-29T21:11:59.7221750Z')
>>> parse_sensing_time("2024-04-29T21:11:59.7221750Z+")
('2024-04-29T21:11:59.7221750Z', '2024-04-29T21:11:59.7221750Z')
>>> parse_sensing_time(
... "2024-04-29T21:12:59.7221750Z ; 2024-04-29T21:11:59.7221750Z"
... )
('2024-04-29T21:11:59.7221750Z', '2024-04-29T21:12:59.7221750Z')
>>> parse_sensing_time(
... "2024-04-29T21:12:59.7221750Z + 2024-04-29T21:11:59.7221750Z;"
... )
('2024-04-29T21:11:59.7221750Z', '2024-04-29T21:12:59.7221750Z')
>>> parse_sensing_time(
... ";2024-04-29T21:12:59.7221750Z + 2024-04-29T21:11:59.7221750Z"
... )
('2024-04-29T21:11:59.7221750Z', '2024-04-29T21:12:59.7221750Z')
>>> parse_sensing_time(
... "2024-04-29T21:10:59.7221750Z;"
... "2024-04-29T21:12:59.7221750Z + 2024-04-29T21:11:59.7221750Z;"
... )
('2024-04-29T21:10:59.7221750Z', '2024-04-29T21:12:59.7221750Z')
>>> parse_sensing_time(
... "2024-04-29T21:12:59.7221750Z+2024-04-29T21:11:59.7221750Z;"
... "2024-04-29T21:10:59.7221750Z + 2024-04-29T21:11:59.7221750Z;"
... )
('2024-04-29T21:10:59.7221750Z', '2024-04-29T21:12:59.7221750Z')
"""
sensing_times = sorted(
t.strip() for t in re.split("[+;]", sensing_time) if t.strip()
)
return sensing_times[0], sensing_times[-1]


def generate_metadata(input_dir: Path, output_dir: Path) -> None:
"""
Create CMR XML metadata file for an HLS VI granule.
Expand All @@ -89,7 +32,6 @@ def generate_metadata(input_dir: Path, output_dir: Path) -> None:
with rasterio.open(next(output_dir.glob("*.tif"))) as vi_tif:
tags = vi_tif.tags()

sensing_time_begin, sensing_time_end = parse_sensing_time(tags["SENSING_TIME"])
processing_time = tags["HLS_VI_PROCESSING_TIME"]

granule_ur = tree.find("GranuleUR")
Expand Down Expand Up @@ -127,9 +69,6 @@ def generate_metadata(input_dir: Path, output_dir: Path) -> None:
producer_granule_id = data_granule.find("ProducerGranuleId")
producer_granule_id.text = producer_granule_id.text.replace("HLS", "HLS-VI")

tree.find("Temporal/RangeDateTime/BeginningDateTime").text = sensing_time_begin
tree.find("Temporal/RangeDateTime/EndingDateTime").text = sensing_time_end

tree.find("DataFormat").text = "COG"

append_fmask_online_access_urls(
Expand Down

0 comments on commit f3892ba

Please sign in to comment.