ajdawson / windspharm

A Python library for spherical harmonic computations on vector winds.
http://ajdawson.github.io/windspharm
MIT License
82 stars 36 forks source link

ValueError: equally-spaced latitudes are invalid (they may be non-global) #125

Closed faahrin closed 9 months ago

faahrin commented 10 months ago

I am trying to calculate streamfunction with ERA5 wind data using the recipe from this example: https://ajdawson.github.io/windspharm/latest/examples/sfvp_xarray.html

I am getting an error in the following line. My data set is from 30N - 30S.

w = VectorWind(uwnd, vwnd)

And the error says the following:


ValueError                                Traceback (most recent call last)
Cell In[40], line 3
      1 # Create a VectorWind instance to handle the computation of streamfunction and
      2 # velocity potential.
----> 3 w = VectorWind(uwnd, vwnd)

File ~/.local/lib/python3.10/site-packages/windspharm/xarray.py:90, in VectorWind.__init__(self, u, v, rsphere, legfunc)
     88     lat, lat_dim = _find_latitude_coordinate(u)
     89 # Determine the gridtype of the input.
---> 90 gridtype = inspect_gridtype(lat.values)
     91 # Determine how the DataArrays should be reordered to conform to the
     92 # windspharm.standard API.
     93 apiorder, _ = get_apiorder(u.ndim, lat_dim, lon_dim)

File ~/.local/lib/python3.10/site-packages/windspharm/_common.py:112, in inspect_gridtype(latitudes)
    110     difference = np.abs(latitudes - equal_reference)
    111     if (difference > tolerance).any():
--> 112         raise ValueError('equally-spaced latitudes are invalid '
    113                          '(they may be non-global)')
    114     gridtype = 'regular'
    115 return gridtype

ValueError: equally-spaced latitudes are invalid (they may be non-global)

Can anyone help? Thanks.

ajdawson commented 9 months ago

This package does not support non-global fields, as it is not possible to turn them into spherical harmonic coefficients. This is a fundamental limitation and cannot be addressed. You will either need to use a different tool to work with limited areas, or work with the full global fields in this package.