Feature/parameter component enhancement#1008
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #1008 +/- ##
===========================================
+ Coverage 81.80% 82.44% +0.63%
===========================================
Files 236 237 +1
Lines 15922 16620 +698
Branches 768 801 +33
===========================================
+ Hits 13025 13702 +677
- Misses 2671 2681 +10
- Partials 226 237 +11 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@pawel-wolff, thanks for this improvement. Please consider to following issues/questions:
|
…f Field For GRIB data, "chem_variable" key maps to the GRIB-key "parameter.chemShortName" which does not use "unknown" value, contrary to "chemShortName"
…direction, wave_frequency
…variables added Docs on xr_engine dimensions updated and how-to notebooks on chem/optical/2d wave spectra dimensions added.
…tFieldList.unique_values: it now applies the plain `sorted()` whenever all items are either: * int/float, or * datetime.date (which includes datetime.datetime), or * datetime.time, or * datetime.timedelta. Otherwise, it falls back to `sorted(*, key=str)`
Tests added `chem_variable` attributes updated
How-to notebook on extra_dims updated xr_engine tests for new dimensions added
…s moved from `create_parameter()` to `SimpleFieldComponent.__init_subclass__()` hook Validation of keys for a component `__init__()` factored out into `SimpleFieldComponent._create_component()` TODO: use the above pattern for other components
…th_bounds, wave_direction_index, wave_direction_bounds, wave_frequency_index, wave_frequency_bounds
…with 5 new metadata keys
…y_units Tests updated
…tional argument `units` earthkit-utils>=1.0.0rc2 Tests updated
…, wavelength, wavelength_bounds, wave_direction_index, wave_frequency_index Tests added
df5bcdb to
0da557d
Compare
|
@sandorkertesz , thanks for the comments.
Now each of these keys have a corresponding key returning a units object, for example:
A reasonable support for mapping the new keys back to GRIB is now implemented.
With the following code run on GRIB data containing regular fields (no chemical/optical/waves) is less than 10% slower comparing to develop branch (i.e. no new parameter keys). This seems to be the cost of querying for a few more GRIB keys (it's already a bit optimised - e.g. if |
| def __init_subclass__(cls): | ||
| super().__init_subclass__() | ||
| sig = inspect.signature(cls.__init__) | ||
| cls._ALLOWED_CREATE_KEYS = tuple(key for key in sig.parameters.keys() if key not in {"self", "args", "kwargs"}) |
There was a problem hiding this comment.
This will not work e.g. for ForecastTime where we can use more keys than the constructor has.
There was a problem hiding this comment.
I see the problem...
This was just an attempt to reduce (in the future) the code duplication within the field/component subpackage (by providing a generic validator for keys passed to a concrete component class __init__, instead of passing an explicit list of keys to SimpleFieldComponent._normalise_create_kwargs() and SimpleFieldComponent._normalise_set_kwargs()).
But now I see that it would not be useful for TimeBase subclasses, at least. So I will revert the changes and go back to the original design.
| chem: str = None, | ||
| chem_long_name: str = None, | ||
| ) -> None: | ||
| Parameter.__init__(self, variable=variable, standard_name=standard_name, long_name=long_name, units=units) |
There was a problem hiding this comment.
Should not it be super().init(?
There was a problem hiding this comment.
Yes, I will change to super().
|
@pawel-wolff, this is a massive improvement! Many thanks! |
Description
Field
This PR extends
parametercomponent of aFieldby adding the following keys:chem: Optional[str](replaceschem_variable)chem_long_name : Optional[str]wavelength: Optional[Union[int, float]]wavelength_bounds: Optional[Union[tuple[int, int], tuple[float, float]]]wavelength_units: Optional["Units"]wave_direction: Optional[float]wave_direction_index: Optional[int]wave_direction_bounds: Optional[tuple[float, float]]wave_direction_units: Optional["Units"]wave_frequency: Optional[float]wave_frequency_index: Optional[int]wave_frequency_bounds: Optional[tuple[float, float]]wave_frequency_units: Optional["Units"]The accessors to the keys representing physical quantities (
wavelength,wavelength_bounds,wave_direction,wave_frequency, etc.) have now an optional argumentunits; if provided, a unit conversion is performed:Note that the following is not yet possible
but can be considered in the future.
The unit conversion is made via
earthkit-utils, where the appropriate feature was added in the version 1.0.0rc2. For this reason the required version ofearthkit-utilswas changed.Xarray engine
Four new built-in dimensions, related to the above
Fieldmetadata keys, were added to the Xarray engine:CF-compliant attributes of the corresponding coordinate variables were proposed (
src/earthkit/data/xr_engine/profiles/defaults.yaml)Coordinate sorting was improved: a fallback on sorting string representations is now the very last option, behind sorting homogenous types; see
earthkit-data/src/earthkit/data/xr_engine/fieldlist.py
Line 175 in df5bcdb
The previous implementation was wrong on sorting float coordinates, because
floatwere converted tostrearly (e.g."5.0">"11.0").Mapping parameter keys from GRIB
The metadata key
chemis mapped from the GRIB keyparameter.chemShortName(previously this waschemShortNamewhich can have"unknown"value instead ofNonewhen undefined).For mapping the other keys from GRIB see: src/earthkit/data/field/grib/parameter.py
Mapping parameter keys to GRIB
Currently a limited set of parameter keys is mapped back to GRIB after a user modification (via
Field.set(), for example):variable->shortNamechem->chemShortNamewavelength_boundsis set, then their values (in meters) are mapped to(firstWavelength, secondWavelength)andtypeOfWavelengthIntervalis set to 2 (which means "Between first and second limit."). If onlywavelengthis set, then its value (in meters) is mapped tofirstWavelength. (The complexity of this mapping comes from the fact that a more direct GRIB keymars.wavelengthis read-only).wave_direction_index + 1->directionNumberwave_frequency_index + 1->frequencyNumberOther keys are not mapped to GRIB for the moment.
Mapping parameter keys from xarray and mars
Will be addressed in another PR.
Docs, tests
Documentation, example notebooks and tests were updated, accordingly.
Contributor Declaration
By opening this pull request, I affirm the following: