lat_lon_grid_deltas
(and in turn xarray grid argument magic) fails silently on xarray input with missing lat/lon units due to incorrect unit conversion
#2028
Labels
Area: Calc
Pertains to calculations
Area: Units
Pertains to unit information
Area: Xarray
Pertains to xarray integration
Type: Bug
Something is not working like it should
Milestone
In the process of helping someone troubleshoot, I came across an example for which MetPy's automatic xarray grid argument handling failed and gave an all-
nan
result:(simplified and cleaned up from original
wrf-python
output)gives
whereas the expected is
or an error/warning either about missing units or passing too large of radian values.
While
mpcalc.lat_lon_grid_deltas
assumes units of degrees when no units are given, this path is not triggered for xarray arguments, as the decorator casts them toQuantity
s (which are 'dimensionless' if no units string is present on the DataArray). And so, these latitudes and longitudes are treated as if they are in radians, which makes pyproj and the rest of the grid delta calculation givenan
s.Given that there is already a path for assuming degrees when units are missing (that is, non-quantity arguments), I'd lean towards moving xarray handling inside
lat_lon_grid_deltas
and not using the default decorator. This would allow situations like the above to work seamlessly via the same fallback. However, I also see the point that this can be viewed as incorrect metadata on the input, and we shouldn't silently guess that it is degrees. In that case, we should probably include something like the_check_radians
helper insidelat_lon_grid_deltas
. Alternatively, if we want to enforce a more general rule of "xarray coordinates need to have correct units", we could include unit-checking in theadd_grid_arguments_to_dataarray
decorator (or other suitable helper).The text was updated successfully, but these errors were encountered: