question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

grid_deltas_from_dataarray() returns all nans

See original GitHub issue

What went wrong?

When attempting to use absolute_vorticity(), I encountered some trouble getting any values at all.

This line: https://github.com/Unidata/MetPy/blob/7af0d4949a6ec8ad02e233f4f4a211744b5c6567/src/metpy/xarray.py#L1420-L1421

Causes dx/dy values to be all NaN because lat_lon_grid_deltas() does not appear to properly handle Xarray DataArray’s.

I’m not sure whether the fix is to modify xarray.py call to lat_lon_grid_deltas() to be something like latitude.data and longitude.data, or change how lat_lon_grid_deltas() works so that if given a DataArray it can get the underlying data out.

Happy to make a contribution with a little guidance. Thanks.

P.S.- still having trouble getting appropriate-looking absolute vorticity values but still working on that.

Operating System

Linux

Version

1.3.1

Python Version

3.9.15

Code to Reproduce

# If I use some sample ERA5 latitude/longitude grid data with this code:
dx, dy = mpcalc.lat_lon_grid_deltas(ds['longitude'],ds['latitude'])
print(dx)
print(dy)

# [[nan nan nan ... nan nan nan] [nan nan nan ... nan nan nan] [nan nan nan ... nan nan nan] ... [nan nan nan ... nan nan nan] # [nan nan nan ... nan nan nan] [nan nan nan ... nan nan nan]] meter
# [[nan nan nan ... nan nan nan] [nan nan nan ... nan nan nan] [nan nan nan ... nan nan nan] ... [nan nan nan ... nan nan nan] # [nan nan nan ... nan nan nan] [nan nan nan ... nan nan nan]] meter

dx, dy = mpcalc.lat_lon_grid_deltas(ds['longitude'].data,ds['latitude'].data)
print(dx)
print(dy)
# [[13899.351016076906 13899.351016076906 13899.351016076906 ...  13899.351016076906 13899.351016076906 # 13899.351016076906] [14004.262721525833 14004.262721525833 14004.262721525833 ...  14004.262721525833 # 14004.262721525833 14004.262721525833] [14108.90780683885 14108.90780683885 14108.90780683885 ...  # 14108.90780683885 14108.90780683885 14108.90780683885] ... [26787.690257756163 26787.690257756163 # 26787.690257756163 ...  26787.690257756163 26787.690257756163 26787.690257756163] [26819.849824192395 # 26819.849824192395 26819.849824192395 ...  26819.849824192395 26819.849824192395 26819.849824192395]# [26851.498778762038 26851.498778762038 26851.498778762038 ...  26851.498778762038 26851.498778762038 # 26851.498778762038]] meter
# [[-27798.718571171168 -27798.718571171168 -27798.718571171168 ...  -27798.718571171168 -27798.718571171168 # -27798.718571171168] [-27798.7185711694 -27798.7185711694 -27798.7185711694 ...  -27798.7185711694 # -27798.7185711694 -27798.7185711694] [-27798.71857117152 -27798.71857117152 -27798.71857117152 ...  # -27798.71857117152 -27798.71857117152 -27798.71857117152] ... [-27798.718571170106 -27798.718571170106 # -27798.718571170106 ...  -27798.718571170106 -27798.718571170106 -27798.718571170106] [-27798.71857117046 # -27798.71857117046 -27798.71857117046 ...  -27798.71857117046 -27798.71857117046 -27798.71857117046] # [-27798.71857117046 -27798.71857117046 -27798.71857117046 ...  -27798.71857117046 -27798.71857117046 # -27798.71857117046]] meter

# The first dx/dy are all NaN but the second dx/dy seem reasonable.

Errors, Traceback, and Logs

None

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
DanielAdriaansencommented, Dec 20, 2022

Update:

I am stripping attrs myself I think: ds = xr.combine_by_coords(singlesets,combine_attrs="drop")

So, no fault of the RDA here.

1reaction
dopplershiftcommented, Dec 20, 2022

sigh What’s the source for this data?

Can you see if it works if you add units of ‘degrees’ to those DataArrays? (ds[‘latitude’].attrs[‘units’] = ‘degrees’)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Select all Rows with NaN Values in Pandas DataFrame
Here are 4 ways to select all rows with NaN values in Pandas DataFrame: (1) Using isna() to select all rows with NaN...
Read more >
pandas map returning all NaNs - Stack Overflow
But the resulting dataframe returns NaN for all IDs . I was able to successfully create the desired dataframe using Excel Vlookup though....
Read more >
Pandas Drop Rows with NaN Values in DataFrame
Use dropna() function to drop rows with NaN / None values in pandas DataFrame. ... Below are a quick example # Drop all...
Read more >
Determine which array elements are NaN - MATLAB isnan
This MATLAB function returns a logical array containing 1 (true) where the elements of A are NaN, and 0 (false) where they are...
Read more >
Working with missing data — pandas 1.5.2 documentation
The sum of an empty or all-NA Series or column of a DataFrame is 0. >>> In [36]: pd.Series([np.nan]).sum() Out[36]: 0.0 In [37]:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found