diff --git a/hls_vi/generate_metadata.py b/hls_vi/generate_metadata.py index d75cf11..e5f9048 100644 --- a/hls_vi/generate_metadata.py +++ b/hls_vi/generate_metadata.py @@ -131,6 +131,11 @@ def generate_metadata(input_dir: Path, output_dir: Path) -> None: tree.find("DataFormat").text = "COG" + append_fmask_online_access_urls( + tree.find("OnlineAccessURLs"), + input_granule_ur, + ) + # ensure any added attributes are indented ET.indent(tree) @@ -202,6 +207,38 @@ def set_additional_attribute(attrs: ElementBase, name: str, value: str) -> None: attrs.append(attr) +def append_fmask_online_access_urls(access_urls: ElementBase, hls_granule_ur: str) -> None: + """Include links to Fmask layer from HLS granule in metadata + + This is intended to help users find the relevant Fmask band without + having to duplicate it into the HLS-VI product. See, + https://github.com/NASA-IMPACT/hls-vi/issues/47 + """ + prefix = ( + "HLSL30.020" if hls_granule_ur.startswith("HLS.L30") + else "HLSS30.020" + ) + + http_attr = Element("OnlineAccessURL", None, None) + http_attr_url = Element("URL", None, None) + http_attr_url.text = f"https://data.lpdaac.earthdatacloud.nasa.gov/lp-prod-protected/{prefix}/{hls_granule_ur}/{hls_granule_ur}.Fmask.tif" + http_attr_desc = Element("URLDescription", None, None) + http_attr_desc.text = f"Download Fmask quality layer {hls_granule_ur}.Fmask.tif" + http_attr.append(http_attr_url) + http_attr.append(http_attr_desc) + + s3_attr = Element("OnlineAccessURL", None, None) + s3_attr_url = Element("URL", None, None) + s3_attr_url.text = f"s3://lp-prod-protected//{prefix}/{hls_granule_ur}/{hls_granule_ur}.Fmask.tif" + s3_attr_desc = Element("URLDescription", None, None) + s3_attr_desc.text = f"This link provides direct download access via S3 to the Fmask quality layer {hls_granule_ur}.Fmask.tif" + s3_attr.append(s3_attr_url) + s3_attr.append(s3_attr_desc) + + access_urls.append(http_attr) + access_urls.append(s3_attr) + + def parse_args() -> Tuple[Path, Path]: short_options = "i:o:" long_options = ["instrument=", "inputdir=", "outputdir="] diff --git a/tests/fixtures/HLS-VI.L30.T06WVS.2024120T211159.v2.0.cmr.xml b/tests/fixtures/HLS-VI.L30.T06WVS.2024120T211159.v2.0.cmr.xml index c4a2b7e..c6911b5 100644 --- a/tests/fixtures/HLS-VI.L30.T06WVS.2024120T211159.v2.0.cmr.xml +++ b/tests/fixtures/HLS-VI.L30.T06WVS.2024120T211159.v2.0.cmr.xml @@ -248,6 +248,14 @@ + + https://data.lpdaac.earthdatacloud.nasa.gov/lp-prod-protected/HLSL30.020/HLS.L30.T06WVS.2024120T211159.v2.0/HLS.L30.T06WVS.2024120T211159.v2.0.Fmask.tif + Download Fmask quality layer HLS.L30.T06WVS.2024120T211159.v2.0.Fmask.tif + + + s3://lp-prod-protected//HLSL30.020/HLS.L30.T06WVS.2024120T211159.v2.0/HLS.L30.T06WVS.2024120T211159.v2.0.Fmask.tif + This link provides direct download access via S3 to the Fmask quality layer HLS.L30.T06WVS.2024120T211159.v2.0.Fmask.tif + diff --git a/tests/fixtures/HLS-VI.S30.T13RCN.2024128T173909.v2.0.cmr.xml b/tests/fixtures/HLS-VI.S30.T13RCN.2024128T173909.v2.0.cmr.xml index 80e3062..00abbd0 100644 --- a/tests/fixtures/HLS-VI.S30.T13RCN.2024128T173909.v2.0.cmr.xml +++ b/tests/fixtures/HLS-VI.S30.T13RCN.2024128T173909.v2.0.cmr.xml @@ -310,6 +310,14 @@ + + https://data.lpdaac.earthdatacloud.nasa.gov/lp-prod-protected/HLSS30.020/HLS.S30.T13RCN.2024128T173909.v2.0/HLS.S30.T13RCN.2024128T173909.v2.0.Fmask.tif + Download Fmask quality layer HLS.S30.T13RCN.2024128T173909.v2.0.Fmask.tif + + + s3://lp-prod-protected//HLSS30.020/HLS.S30.T13RCN.2024128T173909.v2.0/HLS.S30.T13RCN.2024128T173909.v2.0.Fmask.tif + This link provides direct download access via S3 to the Fmask quality layer HLS.S30.T13RCN.2024128T173909.v2.0.Fmask.tif +