Skip to content

DAS-2552: Add dimensions overrides for VIIRS D1F - #46

Merged
mdashkezari merged 3 commits into
mainfrom
DAS-2552-viirs-dims
Nov 17, 2026
Merged

mdashkezari merged 3 commits into
mainfrom
DAS-2552-viirs-dims

Conversation

@mdashkezari

Copy link
Copy Markdown
Contributor

Description

Harmony requests that reformat VIIRS D1F (VNP10D1F, VJ110D1F or VJ210D1F) granules to GeoTIFF fail in net2cog with:

WorkItem failed: podaac/net2cog:1.4.0: net2cog failed to convert
VJ110D1F.A2026244.002.2026245085124.h5: Variable [] cannot be converted to tif:
No output files generated for ...

The granules metadata is missing HDF5 dimension scales. This PR adds metadata overrides for the science vars and the existing lat and lon variables so they become dimensions and coordinate variables.

To avoid a separate memory issue, the amend_in_file_metadata function in annotate.py opens the input granule with chunked variables using dask, so the output file is written back chunk by chunk.

DAS-2562 will add Metadata Annotator to net2cog chain. Until that is deployed, the annotator has to be added to the chain locally to test.

Jira Issue ID

DAS-2552

Local Test Steps

  • Insert metadata annotator in net2cog chain
  • pip install -r requirements.txt
  • unit and das-harmony-regression tests should pass
  • ./bin/build-image && ./bin/build-test && ./bin/run-test
  • Run VIIRS 1DF requests on UAT and locally; here is an example request:

https://harmony.uat.earthdata.nasa.gov/C1276816343-NSIDC_CUAT/ogc-api-coverages/1.0.0/collections/all/coverage/rangeset?forceAsync=true&granuleId=G1283069749-NSIDC_CUAT&format=image%2Ftiff&skipPreview=true&label=eed-edsc-uat%2Cedsc-id%3D5450999763

Fails on UAT with:

WorkItem failed: podaac/net2cog:1.4.1: net2cog failed to convert VJ210D1F.A2026238.002.2026239093808.h5: Variable [] cannot be converted to tif: ...

On local harmony, annotator should show up and complete successfully. However, net2cog will fail but that's due to a separate memory issue that needs to be coordinated with PO.DAAC. To verify that the override has been successful, download the output file of the annotator step (via /steps endpoint) and confirm lat & lon have:

  • CLASS = DIMENSION_SCALE
  • NAME = lat/lon

and the science vars have:

  • DIMENSION_LIST (pointing to lat/lon)
  • coordinates = lat lon

PR Acceptance Checklist

  • Jira ticket acceptance criteria met.
  • CHANGELOG.md updated to include high level summary of PR changes.
  • docker/service_version.txt updated if publishing a release.
  • Fix version [harmony-metadata-annotator-1.9.0] added to Jira ticket.
  • Tests added/updated and passing.
  • Documentation updated (if needed).

variables_to_delete = granule_varinfo.get_excluded_science_variables()
with xr.open_datatree(
input_file_name,
chunks={},

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xarray will load data lazily using dask and will write back on disk chunk by chunk.

https://docs.xarray.dev/en/stable/generated/xarray.open_dataset.html#:~:text=for%20all%20arrays.-,chunks={},-loads%20the%20data

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great catch.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also wasn't 100% sure I believed it would work, but I validated that it OOM exits without this.

Comment on lines +120 to +124
# Dimension renaming applies whether or not new variables are created.
if is_dimension_renaming_required(granule_varinfo, items_to_update):
update_dimension_variables(
datatree, items_to_update, variables_to_create, granule_varinfo
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this was inside the if variables_to_create block. But if a variable has dimension override (as it has for VIIRS’s, renaming to lat/lon) the dimension rename should happen regardless of new var creations.

Comment on lines +295 to +296
if swap_dict:
datatree[group_path].dataset = group_dataset.swap_dims(swap_dict)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.swap_dims will turn the new dimension variables (lat/lon here) into a coordinate variable automatically 

https://docs.xarray.dev/en/latest/generated/xarray.DataArray.swap_dims.html

Comment on lines +1746 to +1753
{
"Name": "standard_name",
"Value": "latitude"
},
{
"Name": "axis",
"Value": "Y"
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not strictly needed for this PR, but worth adding for better coverage

datatree[variable_to_update] = data_array.rename(remaining_rename_dict)


def check_dimension_variables_distinct(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When dim scales are missing and the grid is square, lat and lon both get the same phony dim (phony_dim_0). We want to swap the phony dims for lat and lon, but for a square grid that would be ambiguous. So, we create a mapping between the phony dims and the new dims (lat/lon), and if two new dims share the same phony dim, we raise the ambiguous error.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this, I'm totally second guessing if this could ever happen, but I think it's fine to leave it and be explicit.

@flamingbear flamingbear left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great. I think I have 90% of what's going on here.

I did have just one suggestion for simplification that had nothing do to with your change. you can take it or leave it.

variables_to_delete = granule_varinfo.get_excluded_science_variables()
with xr.open_datatree(
input_file_name,
chunks={},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great catch.

variables_to_delete = granule_varinfo.get_excluded_science_variables()
with xr.open_datatree(
input_file_name,
chunks={},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also wasn't 100% sure I believed it would work, but I validated that it OOM exits without this.

datatree[variable_to_update] = data_array.rename(remaining_rename_dict)


def check_dimension_variables_distinct(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this, I'm totally second guessing if this could ever happen, but I think it's fine to leave it and be explicit.

Comment thread metadata_annotator/annotate.py Outdated
datatree[variable_to_update] = data_array.rename(rename_dict)
rename_dict = {
source_dim: new_dim
for source_dim, new_dim in zip(source_dims, rename_dim_list)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the comment on 279 and the slice on 280 are no ops since L273 has already guaranteed this. I think L279 and 280 could be deleted and 283 updated like this:

Suggested change
for source_dim, new_dim in zip(source_dims, rename_dim_list)
for source_dim, new_dim in zip(data_array.dims, rename_dim_list)

I know this has nothing to do with your change...

@mdashkezari
mdashkezari merged commit 758b9a1 into main Nov 17, 2026
4 checks passed
@mdashkezari
mdashkezari deleted the DAS-2552-viirs-dims branch November 17, 2026 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants