[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[python #HRU-164778]: Query about compositing on a feature



Hi,

I think that error is caused by some weirdness currently when it tries to store 
the unit-ed array inside the DataArray. Try passing `wspd.magnitude` or 
`wspd.m` when creating the new DataArray.

Ryan

> Hi,
> That is great and appears to be doing exactly what I want!
> Thanks for coming up with such a simple solution. I had started coding
> something really messy!
> 
> One quick question on another of the modules:
> 
> I use mpcalc.wind_speed to calculate the wind speed from U and V xarrays.
> U and V have associated dimensions (lev, lat, lon), and I would like for my
> final wind speed array to have these same values. I therefore try to create
> an xarray using xr.DataArray and parsing the data and dimensions. However,
> I keep on getting the error:
> 
> #####################################
> 
> Traceback (most recent call last):
> 
> File "<ipython-input-154-738cfef1e779>", line 1, in <module>
> wspdxr = xr.DataArray(data=wspd, dims=["lev", "lat", "lon"],
> coords=[lev.values,lat.values,lon.values])
> 
> File
> "/apps/Anaconda/anaconda3/lib/python3.7/site-packages/xarray/core/dataarray.py",
> line 369, in __init__
> data = as_compatible_data(data)
> 
> File
> "/apps/Anaconda/anaconda3/lib/python3.7/site-packages/xarray/core/variable.py",
> line 215, in as_compatible_data
> "Got an NumPy-like array type providing the "
> 
> TypeError: Got an NumPy-like array type providing the __array_function__
> protocol but NEP18 is not enabled. Check that numpy >= v1.16 and that the
> environment variable "NUMPY_EXPERIMENTAL_ARRAY_FUNCTION" is set to "1"
> 
> ###############################################
> 
> I have asked the IT guy in our department about this and even if I specify
> the environment, I still get the same error.
> Do you know a work around?
> I have also tried to copy the 'U' xarray and overwrite the .values with the
> windspeed values, but this does not work either.
> I am sure there must be a simple solution?
> 
> 
> 
> ##### My code ##########
> 
> lev=drop_all[YYYY]['IOP'+IOP]['U'].lev
> lon=drop_all[YYYY]['IOP'+IOP]['U'].lon
> lat=drop_all[YYYY]['IOP'+IOP]['U'].lat
> 
> for i in range(len(drop_all['years'])):
> YYYY=drop_all['years'][i]
> for j in range(len(drop_all[YYYY]['IOPs'])) :
> IOP = drop_all[YYYY]['IOPs'][j]
> print (YYYY, IOP)
> # drop_all[YYYY]['IOP'+IOP]['wspd']={}  * units.meter / units.second
> wspd=mpcalc.wind_speed(drop_all[YYYY]['IOP'+IOP]['U'].values*
> units.meter / units.second, drop_all[YYYY]['IOP'+IOP]['V'].values*
> units.meter / units.second)
> ## write windspeed as proper xarray - needs all additional info
> wspdxr = xr.DataArray(data=wspd, dims=["lev", "lat", "lon"],
> coords=[lev.values,lat.values,lon.values])
> wspdxr = xr.DataArray(data=wspd, dims=["lev", "lat", "lon"],
> coords=[lev,lat,lon])


Ticket Details
===================
Ticket ID: HRU-164778
Department: Support Python
Priority: Low
Status: Closed
===================
NOTE: All email exchanges with Unidata User Support are recorded in the Unidata 
inquiry tracking system and then made publicly available through the web.  If 
you do not want to have your interactions made available in this way, you must 
let us know in each email you send to us.