Skip to content

Commit

Permalink
Update DataSetId and DOI
Browse files Browse the repository at this point in the history
Fixes #13
  • Loading branch information
chuckwondo committed Jul 15, 2024
1 parent 87f058a commit 39ec63e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
33 changes: 31 additions & 2 deletions hls_vi/generate_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,19 @@ def generate_metadata(input_dir: Path, output_dir: Path):
tree.find("InsertTime").text = formatted_date
tree.find("LastUpdate").text = formatted_date

# TODO: Find out what the Collection ID should be
tree.find("Collection/DataSetId").text = "Update HLS-VI New Collection ID String"
dataset_id = tree.find("Collection/DataSetId")
dataset_id.text = (
"HLS Operational Land Imager Vegetation Indices Daily Global 30 m V2.0"
if "L30" in metadata_path.name
else "HLS Sentinel-2 Multi-spectral Instrument Vegetation Indices Daily Global 30 m V2.0" # noqa: E501
)
set_additional_attribute(
tree.find("AdditionalAttributes"),
"IDENTIFIER_PRODUCT_DOI",
"10.5067/HLS/HLSL30_VI.002"
if "L30" in metadata_path.name
else "10.5067/HLS/HLSS30_VI.002",
)

data_granule = tree.find("DataGranule")
data_granule.remove(data_granule.find("DataGranuleSizeInBytes"))
Expand All @@ -57,6 +68,24 @@ def generate_metadata(input_dir: Path, output_dir: Path):
)


def set_additional_attribute(attrs: ET.Element, name: str, value: str):
attr = attrs.find(f'./AdditionalAttribute[Name="{name}"]')

if attr is not None:
attr.find(".//Value").text = value
else:
attr = ET.Element("AdditionalAttribute")
attr_name = ET.Element("Name")
attr_name.text = name
attr_values = ET.Element("Values")
attr_value = ET.Element("Value")
attr_value.text = value
attr_values.append(attr_value)
attr.append(attr_name)
attr.append(attr_values)
attrs.append(attr)


def parse_args() -> Tuple[Path, Path]:
short_options = "i:o:"
long_options = ["instrument=", "inputdir=", "outputdir="]
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/HLS-VI.L30.T06WVS.2024120T211159.v2.0.cmr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<InsertTime>2024-05-08T21:25:20.907010Z</InsertTime>
<LastUpdate>2024-05-08T21:25:20.907443Z</LastUpdate>
<Collection>
<DataSetId>Update HLS-VI New Collection ID String</DataSetId>
<DataSetId>HLS Operational Land Imager Vegetation Indices Daily Global 30 m V2.0</DataSetId>
</Collection>
<DataGranule>
<ProducerGranuleId>HLS-VI.L30.T06WVS.2024120T211159</ProducerGranuleId>
Expand Down Expand Up @@ -231,7 +231,7 @@
<AdditionalAttribute>
<Name>IDENTIFIER_PRODUCT_DOI</Name>
<Values>
<Value>10.5067/HLS/HLSL30.002</Value>
<Value>10.5067/HLS/HLSL30_VI.002</Value>
</Values>
</AdditionalAttribute>
<AdditionalAttribute>
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/HLS-VI.S30.T13RCN.2024128T173909.v2.0.cmr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<InsertTime>2024-05-09T20:08:04.550553Z</InsertTime>
<LastUpdate>2024-05-09T20:08:04.550572Z</LastUpdate>
<Collection>
<DataSetId>Update HLS-VI New Collection ID String</DataSetId>
<DataSetId>HLS Sentinel-2 Multi-spectral Instrument Vegetation Indices Daily Global 30 m V2.0</DataSetId>
</Collection>
<DataGranule>
<ProducerGranuleId>HLS-VI.S30.T13RCN.2024128T173909</ProducerGranuleId>
Expand Down Expand Up @@ -293,7 +293,7 @@
<AdditionalAttribute>
<Name>IDENTIFIER_PRODUCT_DOI</Name>
<Values>
<Value>10.5067/HLS/HLSS30.002</Value>
<Value>10.5067/HLS/HLSS30_VI.002</Value>
</Values>
</AdditionalAttribute>
<AdditionalAttribute>
Expand Down

0 comments on commit 39ec63e

Please sign in to comment.