Skip to content
This repository has been archived by the owner on May 2, 2024. It is now read-only.

Drive vcoord_type and origin_z from grib message #120

Merged
merged 5 commits into from
Mar 21, 2024

Conversation

cfkanesan
Copy link
Collaborator

@cfkanesan cfkanesan commented Mar 7, 2024

Purpose

Use the typeOfLevel key as the source of truth for the vcoord_type attribute. An extract function is added to the metadata module to enable this workflow. The override function now updates all attributes previously extracted by the grib_decoder module. This does not include the origin_x and origin_y attributes as they need to be derived from a reference field.

Code changes

  • Added metadata.extract
  • metadata.override will call the extract function to update attributes in the return value

@cfkanesan cfkanesan requested a review from cosunae March 18, 2024 09:30
@victoria-cherkas victoria-cherkas self-requested a review March 20, 2024 10:30
@cfkanesan cfkanesan merged commit 2328d98 into main Mar 21, 2024
2 checks passed
@cfkanesan cfkanesan deleted the metadata-vcoord-type branch March 21, 2024 09:10
Comment on lines +17 to +21
VCOORD_TYPE = {
"generalVertical": ("model_level", -0.5),
"generalVerticalLayer": ("model_level", 0.0),
"isobaricInPa": ("pressure", 0.0),
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

How come surface and hybrid keys are removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The typeOfLevel is the same as the vcoord_type for those so they're actually handled by the pass through

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah ok thanks

@@ -96,6 +96,15 @@ def _update_grid(field: xr.DataArray, dim: Literal["x", "y"]) -> dict[str, Any]:
)


def _update_vertical(field) -> dict[str, Any]:
if field.vcoord_type != "model_level":
raise ValueError("Field.vcoord_type must model_level")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
raise ValueError("Field.vcoord_type must model_level")
raise ValueError("Vertical coordinate type must equal model_level")

@@ -155,7 +164,7 @@ def destagger(
keep_attrs=True,
)
.transpose(*dims)
.assign_attrs(origin=field.origin | {dim: 0.0})
.assign_attrs({f"origin_{dim}": 0.0}, **_update_vertical(field))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why does destaggering z enforce typeOfLevel="generalVerticalLayer" ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

All staggered fields should be defined on the generalVertical levels as far as I understand

Copy link
Collaborator

Choose a reason for hiding this comment

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

But why then does it change from generalVertical to generalVerticalLayer during destaggering?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I believe that's just the way that those level types are defined.


def override(message: bytes, **kwargs: typing.Any) -> dict[str, typing.Any]:
"""Override GRIB metadata contained in message.

Note that no special consideration is made for maintaining consistency when
overriding template definition keys such as productDefinitionTemplateNumber.
Note that the origin components in x and y will be unset.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I cant see where in override or extract origin_x or origin_y are unset. Does this happen in earthkit-data's GribMetadata override method?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah this note is a bit outdated, in the current implementation, the origin_xy values just remain untouched. I'll update the note

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes thanks, since untouched and unset have different meanings it would be good to update

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants