Repository navigation
DAS-2552: Add dimensions overrides for VIIRS D1F - #46
Conversation
| variables_to_delete = granule_varinfo.get_excluded_science_variables() | ||
| with xr.open_datatree( | ||
| input_file_name, | ||
| chunks={}, |
There was a problem hiding this comment.
xarray will load data lazily using dask and will write back on disk chunk by chunk.
There was a problem hiding this comment.
I also wasn't 100% sure I believed it would work, but I validated that it OOM exits without this.
| # 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 | ||
| ) |
There was a problem hiding this comment.
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.
| if swap_dict: | ||
| datatree[group_path].dataset = group_dataset.swap_dims(swap_dict) |
There was a problem hiding this comment.
.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
| { | ||
| "Name": "standard_name", | ||
| "Value": "latitude" | ||
| }, | ||
| { | ||
| "Name": "axis", | ||
| "Value": "Y" | ||
| } |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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={}, |
| variables_to_delete = granule_varinfo.get_excluded_science_variables() | ||
| with xr.open_datatree( | ||
| input_file_name, | ||
| chunks={}, |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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.
| 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) |
There was a problem hiding this comment.
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:
| 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...
Description
Harmony requests that reformat VIIRS D1F (VNP10D1F, VJ110D1F or VJ210D1F) granules to GeoTIFF fail in net2cog with:
The granules metadata is missing HDF5 dimension scales. This PR adds metadata overrides for the science vars and the existing
latandlonvariables so they become dimensions and coordinate variables.To avoid a separate memory issue, the
amend_in_file_metadatafunction 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
net2cogchain. Until that is deployed, the annotator has to be added to the chain locally to test.Jira Issue ID
DAS-2552
Local Test Steps
net2cogchain./bin/build-image && ./bin/build-test && ./bin/run-testhttps://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:
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:
and the science vars have:
PR Acceptance Checklist
CHANGELOG.mdupdated to include high level summary of PR changes.docker/service_version.txtupdated if publishing a release.