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
18 changes: 17 additions & 1 deletion sar_pipeline/aws/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from sar_pipeline.aws.metadata.odc import (
make_static_layer_browse_url,
)
from sar_pipeline.aws.metadata.xml import XMLMapper
from sar_pipeline.utils.s3upload import push_files_in_folder_to_s3
from sar_pipeline.utils.general import log_timing
from sar_pipeline.utils.spatial import write_burst_geometries_to_geojson
Expand Down Expand Up @@ -724,13 +725,19 @@ def make_rtc_opera_stac_and_upload_bursts(
# use this to map assets to the file
logger.info("Linking static layers to product")
burst_stac_manager.add_linked_static_layers_as_assets_to_stac()
# add additional links to metadata files. e.g. stac, xml, proc config
logging.info(f"Adding links to metadata files and self")
# set the filepaths for stac and xml data if applicable
stac_filepath = burst_folder / f"{burst_product_name}_stac-item.json"
if product == "RTC_S1":
xml_filepath = burst_folder / f"{burst_product_name}_metadata.xml"
else:
xml_filepath = None # no xml for static layers
# add additional links to metadata files. e.g. stac, xml, proc config
burst_stac_manager.add_metadata_links(
stac_filepath=stac_filepath,
h5_filepath=burst_h5_filepath,
runconfig_filepath=burst_run_config_filepath,
xml_filepath=xml_filepath,
)
# reference the production stac catalogue for collection number > 0
logging.info(f"Adding stac collection link")
Expand All @@ -751,6 +758,15 @@ def make_rtc_opera_stac_and_upload_bursts(
logger.warning(
"STAC document is not being validated. set --validate-stac if required."
)
# create the XML file from the existing metadata files
if xml_filepath:
logger.info("Creating the XML file from the stac and .h5 metadata files")
XML = XMLMapper(stac_path=stac_filepath, h5_path=burst_h5_filepath)
logger.info("Populating the XML template using the mapping file")
XML.populate_xml()
logger.info(f"Saving XML file to : {xml_filepath}")
XML.save_xml(xml_filepath)

# push folder to S3
if skip_upload_to_s3:
logger.info(f"Skipping upload to S3.")
Expand Down
40 changes: 30 additions & 10 deletions sar_pipeline/aws/metadata/stac.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,13 @@ def add_properties_from_h5(self):
self.item.properties["sarard:ionospheric_correction_applied"] = False

# TODO when official document, link the study supporting these values
self.item.properties["sarard:geometric_accuracy_ALE"] = 2.94
# Northing and Easting error is based on surat basin CR's
self.item.properties["sarard:geometric_accuracy_absolute"] = 2.93
self.item.properties["sarard:geometric_accuracy_rmse"] = 3.08
self.item.properties["sarard:geometric_accuracy_range"] = 1.63
self.item.properties["sarard:geometric_accuracy_azimuth"] = 1.92
self.item.properties["sarard:geometric_accuracy_north_bias"] = 2.25
self.item.properties["sarard:geometric_accuracy_east_bias"] = 1.14
self.item.properties["sarard:geometric_accuracy_north_std"] = 1.30
self.item.properties["sarard:geometric_accuracy_east_std"] = 1.19
self.item.properties["sarard:geometric_accuracy_unit"] = "metre"

# add the storage stac extension properties
Expand Down Expand Up @@ -491,11 +494,13 @@ def add_metadata_links(
stac_filepath: Path | str,
h5_filepath: Path | str,
runconfig_filepath: Path | str,
xml_filepath: Path | str | None,
):
"""Add:
- Link to self / STAC metadata doc,
- Link to the h5 metadata file
- Link to the processing config yaml file
- Link to the xml metadata file (if provided)
- Link to the product folder in s3 that can be used for browsing

This will be appended to the base_href for product.
Expand All @@ -508,6 +513,8 @@ def add_metadata_links(
Filepath of the .h5 file
runconfig_filepath: Path | str
Filepath of the config .yaml
xml_filepath : Path | str | None
Filepath of the xml file. If None, no file linked
"""

if not Path(h5_filepath).exists():
Expand Down Expand Up @@ -543,6 +550,17 @@ def add_metadata_links(
)
)

if xml_filepath:
# link the xml file. We do not check if it exists yet as it is created
# after the stac file is saved. i.e. the xml file is built from the stac json
self.item.add_link(
pystac.Link(
rel="xml-metadata",
target=f"{self.base_href}/{Path(xml_filepath).name}",
media_type=pystac.media_type.MediaType.XML,
)
)

# the stac file gets referenced as self. We do not check if it
# exists yet as it is saved after this process once all info as been added.
self.item.add_link(
Expand Down Expand Up @@ -716,13 +734,6 @@ def add_assets_from_folder(
else str(r.nodata)
),
}
# add pixel coordinate convention
if "area" in raster_sampling:
extra_fields["raster:pixel_coordinate_convention"] = "pixel ULC"
elif "point" in raster_sampling:
extra_fields["raster:pixel_coordinate_convention"] = (
"pixel centre"
)

if asset_filetype == "_mask.tif":
extra_fields["raster:values"] = {
Expand All @@ -746,6 +757,15 @@ def add_assets_from_folder(
self.item.properties["sarard:number_of_pixels_per_line"] = (
shape[1]
)
# add pixel coordinate convention
if "area" in raster_sampling:
self.item.properties[
"sarard:pixel_coordinate_convention"
] = "pixel ULC"
elif "point" in raster_sampling:
self.item.properties[
"sarard:pixel_coordinate_convention"
] = "pixel centre"

else:
extra_fields = {}
Expand Down
Loading
Loading