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: Cube 'U velocity' must contain a single 1D x coordinate. #115

Closed w142236 closed 3 years ago

w142236 commented 3 years ago

I am trying to regrid my data which is on a global grid (just like in case #77), but when I try to regrid the data by running: u.regrid(v, iris.analysis.Linear()) as was done by Corinne77 I get the following error:

ValueError: Cube 'U velocity' must contain a single 1D x coordinate.

The data file that I am using can be found in my dropbox here

My full code is: import xarray as xr import iris from windspharm.iris import VectorWind import numpy as np

file = '2020042412_plev_era5.nc' da = xr.open_dataset(file) u_0 = da['u'][0] #level = 100hPa v_0 = da['v'][0] #level = 100hPa u = u_0.to_iris() #convert to iris from xarray v = v_0.to_iris()

u.regrid(v, iris.analysis.Linear()) #Fails here

I know it is probably inappropriate to post this question here as this is more of an iris inquiry than a windspharm inquiry, but I figured someone here might have some insight as to how to deal with this issue. This is the first time I have ever used Windspharm and it is also the first time that I have ever used iris so I don't really know what I am doing to begin with. Any help would be appreciated.

w142236 commented 3 years ago

I feel like a total moron right now. I turned to the iris method because the standard method did not work. Turns our that when you use netCDF4's Dataset function, you get the type numpy.ma.core.MaskedArray. All I had to do to get the standard method to work was to put the array inside np.array() to convert it into a numpy.marray as the documentation states it has to be, and it worked.

For anyone wondering exactly how I got it to work, here is my code:

from windspharm.standard import VectorWind import numpy as np import netCDF4 as nc from netCDF4 import Dataset

file = '2020042412_plev_era5.nc' fh = Dataset(file) FIX STARTS HERE u = np.array(fh.variables['u'][:]) #put inside np.array() here v = np.array(fh.variables['v'][:]) END OF FIX w = VectorWind(u, v) uchi, vchi = w.irrotationalcomponent() #Now Works

Not sure why this didn't work when I put the data into iris cubes, but the standard form works.