Open sgdecker opened 2 years ago
I would argue that this is not a MetPy bug, as this dataset contains several variables with units that don't make any sense in the context of CF/UDUNITS:
varname | unit |
---|---|
Soil_type_surface | (Code table 4.213) |
Categorical_Rain_surface | Code table 4.222 |
Categorical_Freezing_Rain_surface | Code table 4.222 |
Categorical_Ice_Pellets_surface | Code table 4.222 |
Categorical_Snow_surface | Code table 4.222 |
Rime_Factor_hybrid | non-dim |
Drag_Coefficient_surface | non-dim |
Convective_Cloud_Efficiency_entire_atmosphere_single_layer | non-dim |
Volumetric_Soil_Moisture_Content_depth_below_surface_layer | Fraction |
Vegetation_Type_surface | Integer.(0-13) |
Wilting_Point_surface | Fraction |
Solar_parameter_in_canopy_conductance_surface | Fraction |
Temperature_parameter_in_canopy_conductance_surface | Fraction |
Humidity_parameter_in_canopy_conductance_surface | Fraction |
Soil_moisture_parameter_in_canopy_conductance_surface | Fraction |
Number_of_Soil_Layers_in_Root_Zone_surface | non-dim |
Since this dataset isn't following CF conventions even though it declares itself to be, what would be the appropriate upstream fix on the TDS side?
That all being said, as an enhancement, I think MetPy could raise a more informative error in place of Pint's ValueError...perhaps something like Variable "Soil_type_surface" has invalid units attribute "(Code table 4.213)". Verify that all units attributes are valid prior to calling quantify().
? (Or even better, just match how pint-xarray
does it: https://github.com/xarray-contrib/pint-xarray/blob/main/pint_xarray/accessors.py#L1034-L1052)
Yes, those are some sketchy units! Maybe MetPy issues warnings for these invalid units and at least returns a Dataset containing the variables that are valid?
Maybe MetPy issues warnings for these invalid units and at least returns a Dataset containing the variables that are valid?
That could work too! I guess it's the choice between failing out and letting the user handle it or assuming the user is okay with variables with invalid units being dropped.
I'd be ok with making it an opt-in flag to ignore invalid units on parse_cf
, and any other needed methods. Could be added as a keyword-only argument to maintain current behavior. An improved error exception would also be good to have.
What went wrong?
I attempted to use
metpy.quantify
on the NAM 212 dataset returned by Unidata's TDS, but it didn't like one of the variables. There are 180 variables in the dataset, and I haven't tracked down which one is problematic.Output:
Operating System
Linux
Version
1.1.0.post39+gd43d5eb02.d20210825
Python Version
3.9.5
Code to Reproduce