Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [PEP 440](https://www.python.org/dev/peps/pep-0440/)
and uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.1.6]

### Added
- Update lineage statement in ISO XML files output to include mention of ASF and hyp3-OPERA-RTC version

## [0.1.5]

### Changed
Expand Down
34 changes: 34 additions & 0 deletions src/hyp3_opera_rtc/upload_rtc.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import argparse
from pathlib import Path
from shutil import copyfile, make_archive
from xml.etree import ElementTree as et

from hyp3lib.aws import upload_file_to_s3

import hyp3_opera_rtc


class FailedToFindLineageStatementError(Exception):
pass


def upload_rtc(bucket: str, bucket_prefix: str, output_dir: Path) -> None:
output_files = [f for f in output_dir.iterdir() if not f.is_dir()]
Expand Down Expand Up @@ -42,6 +49,32 @@ def make_zip_name(product_files: list[Path]) -> str:
return h5_file.name.split('.h5')[0]


def update_xmls_with_asf_lineage(output_dir: Path) -> None:
xml_paths = [f for f in output_dir.iterdir() if f.suffix == '.xml']

for xml_path in xml_paths:
update_xml_with_asf_lineage(xml_path)


def update_xml_with_asf_lineage(xml_path: Path) -> None:
iso_tree = et.parse(str(xml_path))

gmd = '{http://www.isotc211.org/2005/gmd}'
gco = '{http://www.isotc211.org/2005/gco}'
lineage_tag_path = f'.//{gmd}LI_Lineage/{gmd}statement/{gco}CharacterString'

lineage_search = iso_tree.findall(lineage_tag_path)
if len(lineage_search) == 0:
raise FailedToFindLineageStatementError('Failed to find lineage statement in iso xml')

lineage = lineage_search[0]
version = hyp3_opera_rtc.__version__
assert lineage.text is not None
lineage.text = f'{lineage.text.replace("JPL", "ASF")} via HyP3 OPERA-RTC v{version}'

iso_tree.write(str(xml_path))


def main() -> None:
"""Upload results of OPERA RTC.

Expand All @@ -56,6 +89,7 @@ def main() -> None:
parser.add_argument('--bucket-prefix', default='', help='Add a bucket prefix to products')

args, _ = parser.parse_known_args()
update_xmls_with_asf_lineage(args.output_dir)

if not args.bucket:
print('No bucket provided, skipping upload')
Expand Down
Loading
Loading