ajdawson / windspharm Goto Github PK
View Code? Open in Web Editor NEWA Python library for spherical harmonic computations on vector winds.
Home Page: http://ajdawson.github.io/windspharm
License: MIT License
A Python library for spherical harmonic computations on vector winds.
Home Page: http://ajdawson.github.io/windspharm
License: MIT License
Hi @ajdawson I just wanted to touch base and ask what your plans are (if any) for future maintenance of windspharm
. We noticed there haven't been any updates here for a while, so perhaps you no longer have time for it. It's used a fair bit here in the Met Office and my group uses it for operational post-processing, so we obviously need to make some future-proof plans. I've just checked that it seems to work quite happily with python 3.9 and Iris 3.0.1, so I don't have any immediate worries, just thinking a bit longer term.
Huge thanks to you for making it available to begin with!
Hi Andrew,
I'm in the process of calculating the Rossby wave source (for which your examples on the windspharm website are very useful - thanks!) however I've been getting strange results. I've traced the problem back to the fact that the calculated planetary vorticity [i.e. w.planetaryvorticity()] is negative in the Northern Hemisphere and positive in the Southern Hemisphere, when it should obviously be the other way around.
I'm using the standard interface of windspharm and the version that was included with version 1.2.0 of UV-CDAT. Is this a known problem that has been fixed in later releases of windspharm, or is this a bug at my end and not yours...?
There are no tests for the latitude reversal part of iris, which allowed a serious bug to go unnoticed. The tests should be improved to ensure this does not happen.
This is one part of the windspharm API that doesn't make sense to me.
As far as I can tell, the direct arguments to truncate
and gradient
contain all the information necessary to calculate them. Indeed, based on my tests, I get identical results when I call these methods on a VectorWind
instance initialized with u
and v
fields multiplied by 0.
In general, methods that do not rely on any properties of the attached object should simply be functions.
In this case, this would have the additional advantage of letting users use these methods even if u and v fields are not available.
@ajdawson Both myself and @didiermonselesan get the following error after installing windspharm (via conda install -c https://conda.anaconda.org/ajdawson windspharm
) on MacOS El Capitan:
>>> import windspharm
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/irv033/miniconda2/envs/test2/lib/python2.7/site-packages/windspharm/__init__.py", line 23, in <module>
from . import standard
File "/Users/irv033/miniconda2/envs/test2/lib/python2.7/site-packages/windspharm/standard.py", line 22, in <module>
from spharm import Spharmt, gaussian_lats_wts
File "/Users/irv033/miniconda2/envs/test2/lib/python2.7/site-packages/spharm/__init__.py", line 1, in <module>
from .spharm import __doc__
File "/Users/irv033/miniconda2/envs/test2/lib/python2.7/site-packages/spharm/spharm.py", line 123, in <module>
import _spherepack, numpy, math, sys
ImportError: dlopen(/Users/irv033/miniconda2/envs/test2/lib/python2.7/site-packages/_spherepack.so, 2): Library not loaded: /usr/local/lib/gcc/x86_64-apple-darwin13.3.0/4.9.1/libgfortran.3.dylib
Referenced from: /Users/irv033/miniconda2/envs/test2/lib/python2.7/site-packages/_spherepack.so
Reason: image not found
Any ideas?
(@didiermonselesan has no problem installing on Ubuntu 14.04 LTS)
(We get the same error if we use conda install -c https://conda.anaconda.org/ioos windspharm
to install it instead)
The docstring examples erroneously refer to invert_latdim_order instead of reverse_latdim.
Hi Andrew,
Thanks for the feedbacks.
I found this error when issuing w=VectorWind(u,v)
where u
and v
are global winds from ERA-I, both being 2D slabs (lat, lon). It seems that when inputs are both 2D, line 93 in cdms.py
gives this error because np.prod(u.shape[2:])
gives 1.0
, thus making an numpy.float64
in the reshape arg.
My numpy is 1.13.3, windspharm 1.5.1
I guess a possible fix is to use np.prod(u.shape[2:]).astype('int')
Guangzhi
I have finally been able to install windspharm in both UV-CDAT 1.5.1 and 2.1.0, but it took me quite some time to figure out how to do it :-(
I just typed pip install windspharm, the installation seemed to start, then nothing took place until I typed , and then I got some weird SPHEREPACK license/download errors
I eventually started installing pyspharm first, and typed 'yes' to accept the license+download, and then installed windspharm from the tarball sources
And then I discovered that pip install windspharm worked indeed, when installing windspharm into UV-CDAT versions I had on other servers, but the problem was that the message asking me to type yes or no was not displayed! I found out the hard way I had to use the following steps:
So, my suggestions:
Hi,
thanks for this nice package! It would be great to have a statement on the README page about which versions of python windspharm does support. Installating the latest master with pip on python 3.4 worked fine, but I get two test errors (see log below).
Do you think there will be other problems when using windspharm with python 3?
[c7071047@zid-gpl windspharm-master]$ nosetests .
SS..........SSSSSS....................................E..E.
======================================================================
ERROR: windspharm.tests.test_tools.TestTools.test_get_recovery
----------------------------------------------------------------------
Traceback (most recent call last):
File "/scratch/c707/c7071047/miniconda3/lib/python3.4/site-packages/nose/case.py", line 198, in runTest
self.test(*self.arg)
File "/scratch/c707/c7071047/packages/windspharm-master/lib/windspharm/tests/test_tools.py", line 47, in test_get_recovery
ur1 = recover_data(up, uinfo)
File "/scratch/c707/c7071047/packages/windspharm-master/lib/windspharm/tools.py", line 148, in recover_data
for i in xrange(len(rolldims)):
NameError: name 'xrange' is not defined
======================================================================
ERROR: windspharm.tests.test_tools.TestTools.test_prep_recover_data
----------------------------------------------------------------------
Traceback (most recent call last):
File "/scratch/c707/c7071047/miniconda3/lib/python3.4/site-packages/nose/case.py", line 198, in runTest
self.test(*self.arg)
File "/scratch/c707/c7071047/packages/windspharm-master/lib/windspharm/tests/test_tools.py", line 40, in test_prep_recover_data
ur = recover_data(up, uinfo)
File "/scratch/c707/c7071047/packages/windspharm-master/lib/windspharm/tools.py", line 148, in recover_data
for i in xrange(len(rolldims)):
NameError: name 'xrange' is not defined
----------------------------------------------------------------------
Ran 51 tests in 2.536s
FAILED (SKIP=8, errors=2)
Hi Andrew,
Probably more a question than an issue. Can windspharm work with data on a Mercator grid that by definition can't cover the poles? Suppose I got some regional WRF data on Mercator grid, what's my best bet? Do I need to create a global grid and paste the relevant region, call windspharm and regrid back?
Many thanks in advance.
Guangzhi
The directions for the winds appear to be off but the values appear to be of correct magnitude albeit in the wrong areas when I try using it for ERA5 0.25x0.25 degree resolution data using the full global model (as is recommended). Is there perhaps an error in the calculations which you perform in your coding or does it not work with ERA5 data?
In my approach to solving for the irrotational winds, I used the 2D Discrete Fourier Transform method of solving the Poisson's Equation wherein div = laplacian (velocity potential) and then I took the gradient of the obtained velocity potential field in order to get the irrotational winds which were all pointed in the correct direction and had correct relative magnitudes to one another (strong near areas of divergence and weak in areas with little to no divergence), but the values themselves were too small by one order of magnitude (perhaps Poisson's Equation has a constant out front that needs to be solved for and I missed it?). Did you attempt trying something similar?
Thank you!
NCL has this functionality - https://www.ncl.ucar.edu/Document/Functions/Contributed/shear_stretch_deform.shtml. Is it possible to calculate shear and stretch deform using windspharm ?
All we need is the vector gradient of the wind and then we can add and subtract the components to get the respective quantities. Is this doable ?
Hi Andrew
I am using VectorWind to calculate divergence and absolute vorticity in model runs. Both work fine when using seasonal U and V data however when I switched to daily data extracting season of interest, DJF, it cannot calculate the VectorWind, crashing at u.transpose(apiorder) in source code and producing the error IndexError: Indice mismatch. Indices must have the same length.
My data is:
In [45]: print ctl_uwnd
x_wind / (m s-1) (time: 5220; latitude: 144; longitude: 192)
Dimension coordinates:
time x - -
latitude - x -
longitude - - x
Auxiliary coordinates:
clim_season x - -
forecast_period x - -
month x - -
year x - -
Scalar coordinates:
forecast_reference_time: 1981-09-01 00:00:00
pressure: 200.0 hPa
Attributes:
Conventions: CF-1.5
STASH: m01s15i243
source: Data from Met Office Unified Model
um_version: 8.4
Cell methods:
mean: time (1 hour)
In [46]: print ctl_vwnd
y_wind / (m s-1) (time: 5220; latitude: 144; longitude: 192)
Dimension coordinates:
time x - -
latitude - x -
longitude - - x
Auxiliary coordinates:
clim_season x - -
forecast_period x - -
month x - -
year x - -
Scalar coordinates:
forecast_reference_time: 1981-09-01 00:00:00
pressure: 200.0 hPa
Attributes:
Conventions: CF-1.5
STASH: m01s15i244
source: Data from Met Office Unified Model
um_version: 8.4
Cell methods:
mean: time (1 hour)
With the seasonal data the same lat and lon dimensions but only 58 timesteps.
What would the error be in using daily data as opposed to seasonally averaged data for VectorWind?
Hi,
I wonder if it's possible to import JRA-55 files from the Japanese 55-year Reanalysis website.
Thanks in advance,
Nosratullah
Is the Rossby Wave source formula correct in rws_example.py?
S = -eta * div - uchi * etax - vchi * etay and not S = -eta * div - uchi * etax + vchi * etay as per example
S = -eta * div - dot(v_chi , grad(eta))
Cheers, Didier
Hi Andrew
I get an error if I try to create
ww=VectorWind(u,v)
TypeError Traceback (most recent call last)
in ()
----> 1 ww=VectorWind(uu,vv)
~/.conda/envs/py36/lib/python3.6/site-packages/windspharm/iris.py in init(self, u, v, rsphere)
94 self._coords = u.dim_coords
95 # Reshape the inputs so they are compatible with pyspharm.
---> 96 u = u.data.reshape(u.shape[:2] + (np.prod(u.shape[2:]),))
97 v = v.data.reshape(v.shape[:2] + (np.prod(v.shape[2:]),))
98 # Create a base VectorWind instance to do the computations.
TypeError: 'numpy.float64' object cannot be interpreted as an integer
The problem is that u and v are 2-D iris cubes. np.prod(u.shape[2:]) returns 1.0 a float, not 1 an integer, which causes the fail. This is because u.shape[2:] is () an empty tuple.
It works ok if I use lat-long-time u and v cubes.
I have fixed my version of this by modifying the windspharm iris.py with an int built-in, ie
np.prod(u.shape[2:]) is changed to int(np.prod(u.shape[2:])) and similarly for v in the next line
Is this correct, and can you update the package?
Cheers
Adrian
from windspharm.xray import VectorWind
w = VectorWind(u, v)
should be
from windspharm.xarray import VectorWind
w = VectorWind(u, v)
Hi,
Looking forward to using this package, thanks for developing! As a first run through to check everything works (having installed Windspharm in my Conda environment), I'm attempting to run the example standard interface streamfunction/velocity potential script with some of my own data. An error is thrown up which looks like a problem in the interaction with Xarray:
Traceback (most recent call last):
File "windspharm_example.py", line 21, in <module>
from windspharm.standard import VectorWind
File "/ouce-home/students/sedm4616/.conda/envs/jk_venv/lib/python2.7/site-packages/windspharm/__init__.py", line 49, in <module>
from . import xarray
File "/ouce-home/students/sedm4616/.conda/envs/jk_venv/lib/python2.7/site-packages/windspharm/xarray.py", line 24, in <module>
import xarray as xr
File "/ouce-home/students/sedm4616/.conda/envs/jk_venv/lib/python2.7/site-packages/xarray/__init__.py", line 10, in <module>
from .core.alignment import align, broadcast, broadcast_arrays
File "/ouce-home/students/sedm4616/.conda/envs/jk_venv/lib/python2.7/site-packages/xarray/core/alignment.py", line 11, in <module>
from .indexing import get_indexer_nd
File "/ouce-home/students/sedm4616/.conda/envs/jk_venv/lib/python2.7/site-packages/xarray/core/indexing.py", line 11, in <module>
from . import duck_array_ops, nputils, utils
File "/ouce-home/students/sedm4616/.conda/envs/jk_venv/lib/python2.7/site-packages/xarray/core/duck_array_ops.py", line 22, in <module>
from . import dask_array_compat
File "/ouce-home/students/sedm4616/.conda/envs/jk_venv/lib/python2.7/site-packages/xarray/core/dask_array_compat.py", line 47, in <module>
AxisError = np.AxisError
AttributeError: 'module' object has no attribute 'AxisError'
Any advice on this would be very much appreciated.
Best,
James
I've just installed both windspharm and pyspharm and am currently trying to get the example here to work before adapting it for my own uses. I can successfully load windspharm and the code works up until the line:
w = VectorWind(uwnd, vwnd)
which produces the error:
'module' object has no attribute 'shaesi'
I'm not sure if this is an issue with windspharm or pyspharm, but I thought I'd try here as Google hasn't provided any answers. Thanks!
If one of u or v is a masked array and the other is not then the missing value check in windspharm.standard.VectorWind.__init__
might fail as it relies on both u and v having the filled()
method available.
Hi, I'm new to windspharm but already excited to use a package that seems like it will be extremely useful in the future.
However, I'm having a little trouble loading up my input fields as a WindVector object.
surfwind = VectorWind(uwindj, vwindj, gridtype='gaussian')
uwindj and vwindj are, usually, (17, 72, 96) numpy arrays, with dimensions ('lev', 'lat', 'lon')
When I either manually swap the axes to be in the order ('lat', 'lon', 'lev') as the documentation suggests, or use the prep_data method on the arrays - in an attempt to comply with the proper ordering for VectorWind -
uwindj, uwnd_info = prep_data(uwindj, 'zyx')
vwindj, vwnd_info = prep_data(vwindj, 'zyx')
File "/media/thomas/Seagate Exp/kaphs/windspharm.py", line 51, in <module>
surfwind = VectorWind(uwindj, vwindj, gridtype='gaussian')
File "/home/thomas/anaconda2/lib/python2.7/site-packages/windspharm/standard.py", line 120, in __init__
raise ValueError(err)
ValueError: invalid input dimensions
However, it is happy to read in the vector with the 'lev' dimension first.
I tried to get around this by just dealing with 2D fields, i.e. creating a new VectorWind instance for 17 separate (72, 96) arrays.
But windspharm refused to create a VectorWind instance from a 2D (72, 96) array altogether, although the docs suggest that it can work with 2D arrays.
Am I missing something obvious out?
Thanks.
Hi Andrew,
I've installed Anaconda, then used conda/binstar to install iris, cartopy and cdat-lite alongside it (thanks for providing a binstar for cdat-lite). What would be the best way to install windspharm and eofs alongside all this? I noticed that you don't have binstar files for windspharm and eofs specifically, but you do have one for pyspharm, which may help in this situation...
ECMWF has several filters for filtering spectral data .e.g - low pass filter in terms of a tanh function that requires the wavenumber
A bell shaped filter. Since we are using derivatives to calculate divergence and vorticity any interests in adding any filter ?
The current unit tests verify that input is properly handled and that the WindVector
methods produce arrays with the numerically correct values, but -- as far as I can tell -- they don't verify that the metadata interfaces produce arrays with the appropriate metadata.
This would be useful -- I suspect that adding checks would possibly even turn up a few bugs.
I am getting the above error for a netCDF file with this ordering of dimensions - time,lat,lev,lon
and in my code I have this order -
uwnd, uwnd_info = prep_data(uwnd850, 'tyzx')
vwnd, vwnd_info = prep_data(vwnd850, 'tyzx')
Traceback (most recent call last):
File "monsoon_index.py", line 86, in
uwnd, uwnd_info = prep_data(uwnd850, 'tyzx')
File "/usr/local/lib/python3.5/dist-packages/windspharm-1.5.1-py3.5.egg/windspharm/tools.py", line 97, in prep_data
pdata, intorder = __order_dims(data, dimorder)
File "/usr/local/lib/python3.5/dist-packages/windspharm-1.5.1-py3.5.egg/windspharm/tools.py", line 35, in __order_dims
d = np.rollaxis(d, lonpos)
File "/usr/lib/python3/dist-packages/numpy/core/numeric.py", line 1450, in rollaxis
raise ValueError(msg % ('axis', axis, n))
ValueError: rollaxis: axis (3) must be >=0 and < 2
So line 86 is this line -
uwnd, uwnd_info = prep_data(uwnd850, 'tyzx')
I have had issues with running out of memory when processing large grids (1921 lat x 2560 lon). I got around this with a small hack to pass legfunc='computed'
when setting up the spharm.Spharmt
instance. Would you be interested in a PR that enables passing of the legfunc
keyword through the various VectorWind.__init__
methods?
The docstrings currently do not indicate required types. They simple say that they take input in the form of a "data array".
I use xarray to read netcdf data
import xarray as xr
from windspharm.xarray import VectorWind
from windspharm.tools import prep_data, recover_data, order_latdim
from windspharm.examples import example_data_path
nc = xr.open_dataset('era5/era5_3d_201906070809.nc')
uwnd = nc.u
uwnd, uwnd_info = prep_data(uwnd, 'tzyx')
<xarray.DataArray 'u' (time: 4, level: 22, latitude: 721, longitude: 1440)>
[91365120 values with dtype=float32]
Coordinates:
- longitude (longitude) float32 0.0 0.25 0.5 0.75 ... 359.25 359.5 359.75
- latitude (latitude) float32 90.0 89.75 89.5 89.25 ... -89.5 -89.75 -90.0
- level (level) int32 1 2 3 5 7 10 20 30 ... 400 500 600 700 850 925 1000
- time (time) datetime64[ns] 2019-06-01 2019-07-01 2019-08-01 2019-09-01
Attributes:
units: m s**-1
long_name: U component of wind
standard_name: eastward_wind
the error message are as following:
uwnd, uwnd_info = prep_data(uwnd, 'tzyx')
File "/g3/liuchong/software/anaconda3/lib/python3.8/site-packages/windspharm/tools.py", line 97, in prep_data
pdata, intorder = __order_dims(data, dimorder)
File "/g3/liuchong/software/anaconda3/lib/python3.8/site-packages/windspharm/tools.py", line 35, in __order_dims
d = np.rollaxis(d, lonpos)
File "<__array_function__ internals>", line 5, in rollaxis
File "/g3/liuchong/software/anaconda3/lib/python3.8/site-packages/numpy/core/numeric.py", line 1274, in rollaxis
return a.transpose(axes)
File "/g3/liuchong/software/anaconda3/lib/python3.8/site-packages/xarray/core/dataarray.py", line 2036, in transpose
dims = tuple(utils.infix_dims(dims, self.dims))
File "/g3/liuchong/software/anaconda3/lib/python3.8/site-packages/xarray/core/utils.py", line 724, in infix_dims
if set(dims_supplied) ^ set(dims_all):
**TypeError: unhashable type: 'list'**
how to fix this? Thanks
I am trying to compute the vorticity according to the 'recipe'
# Read u and v wind components from file.
u = iris.load_cube('uwind_file.nc')
v = iris.load_cube('vwind_file.nc')
# Create an instance of the VectorWind class to do the computations.
w = VectorWind(u, v)
#Call methods to compute streamfunction and relative vorticity.
psi = w.streamfunction()
xi = w.vorticity()
with the difference that I need to concatenate netcdf files (I use CMIP5 data) to cover large time periods.
I get the error message:
w = VectorWind(u,v)
File "/usr/lib/python2.7/site-packages/windspharm/iris.py", line 73, in __init__
gridtype = self._gridtype(lat.points)
File "/usr/lib/python2.7/site-packages/windspharm/iris.py", line 127, in _gridtype
raise ValueError('equally-spaced latitudes are '
ValueError: equally-spaced latitudes are invalid (non-global?)
I guess that CMIP5 data cover the whole Earth. Can anyone help?
Thank you
The method planetaryvorticity
only returns correct values for gridtype='regular' grids. Support for gridtype='gaussian' was omitted somehow.
I am having problems when converting numpy float arrays using the prep_data command with recent versions of windpharm. The following code:
import numpy as np
from windspharm.tools import prep_data
u = np.zeros([180,360], np.float)
uwnd, uwnd_info = prep_data(u, 'yx')
Causes the following error:
Traceback (most recent call last):
File "test.py", line 9, in <module>
uwnd, uwnd_info = prep_data(u, 'yx')
File "/home/tom/tmp/windpharm-bug/two/windspharm/lib/windspharm/tools.py", line 98, in prep_data
pdata, intshape = __reshape(pdata)
File "/home/tom/tmp/windpharm-bug/two/windspharm/lib/windspharm/tools.py", line 46, in __reshape
out = d.reshape(d.shape[:2] + (np.prod(d.shape[2:]),))
TypeError: 'numpy.float64' object cannot be interpreted as an index
With numpy 1.12 and 1.13 (anaconda nomkl installs).
However, I may be using prep_data incorrectly?
The Xray package is a fantastic tool for climate data analysis, through its support of netCDF-style labeled dimensions and coordinates. So it would be great for windspharm to have an interface for Xray objects (DataArray
s and Dataset
s).
Both windpsharm and Xray have interfaces with cdms2. So, on the one hand, that could be an easy adapter for making the former two work together. On the other hand, I have found cdat-late maddening to install (both on my own Mac and my linux workstation), so it would be nice if ultimately that wasn't a dependency.
Thanks! Not sure if you're still developing windspharm, but it's a nice package.
Dear all,
I found the divergence calculation has some weird behaviors.
Here I use the example data to calculate the divergence in two ways. They are largely equal except over high latitudes.
import xarray as xr
from windspharm.xarray import VectorWind
from windspharm.examples import example_data_path
### compute the divergence suing example data
ds = xr.open_mfdataset([example_data_path(f)
for f in ('uwnd_mean.nc', 'vwnd_mean.nc')])
uwnd = ds['uwnd']
vwnd = ds['vwnd']
w = VectorWind(uwnd, vwnd)
div = w.divergence()
dudx, _ = w.gradient(uwnd)
_, dvdy = w.gradient(vwnd)
div1 = dudx + dvdy
### They are the same!
fig, ax = plt.subplots(1, 2, figsize=(8, 4))
div[5].plot(ax=ax[0])
div1[5].plot(ax=ax[1])
However, for my test data, it obviously fails.
ds = xr.open_dataset('0temp_data/test3.nc')
w_uvh = VectorWind(ds.UH, ds.VH)
div2 = w_uvh.divergence()
dudx1, _ = w_uvh.gradient(ds.UH)
_, dvdy1 = w_uvh.gradient(ds.VH)
div3 = dudx1 + dvdy1
# They are not equal!
fig, ax = plt.subplots(1, 2, figsize=(8, 4))
div2.plot(ax=ax[0])
div3.plot(ax=ax[1])
Check my test data here.
test3.nc.zip
Any thoughts?
Best
conda create -n ws -c conda-forge windspharm "numpy=1.12"
Fetching package metadata .........
Solving package specifications: ....
UnsatisfiableError: The following specifications were found to be in conflict:
- numpy 1.12*
- windspharm
Use "conda info <package>" to see the dependencies for each package.
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.
I tried to conda install windspharm
using miniforge's conda
on an M1-based Mac, but it fails, and search explains it:
$>conda search windspharm
Loading channels: done
No match found for: windspharm. Search: *windspharm*
PackagesNotFoundError: The following packages are not available from current channels:
- windspharm
Current channels:
- https://conda.anaconda.org/conda-forge/osx-arm64
- https://conda.anaconda.org/conda-forge/noarch
Is it possible to install on M1 Mac?
Adapted from the sfvp example:
>>> VectorWind(uwnd, vwnd[:, :, :10])
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-47-80b64ca64fa5> in <module>()
----> 1 VectorWind(uwnd, vwnd[:, :, :10])
/Users/shoyer/conda/envs/windspharm/lib/python3.5/site-packages/windspharm/xarray.py in __init__(self, u, v, rsphere)
69 msg = 'u and v must have the same dimension coordinates'
70 raise ValueError(msg)
---> 71 if not all([(uc == vc).all() for uc, vc in zip(ucoords, vcoords)]):
72 msg = 'u and v must have the same dimension coordinate values'
73 raise ValueError(msg)
/Users/shoyer/conda/envs/windspharm/lib/python3.5/site-packages/windspharm/xarray.py in <listcomp>(.0)
69 msg = 'u and v must have the same dimension coordinates'
70 raise ValueError(msg)
---> 71 if not all([(uc == vc).all() for uc, vc in zip(ucoords, vcoords)]):
72 msg = 'u and v must have the same dimension coordinate values'
73 raise ValueError(msg)
AttributeError: 'bool' object has no attribute 'all'
I'm writing a paper at the moment and would like to cite windspharm (along with the other software packages and libraries that I used). I was therefore wondering if you have thought about writing a paper about windspharm for the Journal of Open Research Software? This would great way for you to get academic credit for the hard work you've put into it, and would also make it very easy for authors like me to cite windspharm.
(You could probably write a separate paper for eofs too?)
When using the standard interface, the calculation of absolute vorticity works fine when my input data are a three dimensional array (i.e. 'tyx', which I put in the correct order using the prep_data function), however when the input data are a two dimensional array (i.e. 'yx', which I pass to prep_data but are actually in the correct order anyway) I get the following error message:
File "/usr/local/uvcdat/1.2.0rc1/lib/python2.7/site-packages/windspharm/standard.py", line 261, in absolutevorticity
return pvrt + rvrt
ValueError: shape mismatch: objects cannot be broadcast to a single shape
I'm not sure if this is a bug in your code, or an error in my application of that code?
Hi Andrew, Just putting my email in a ticket here. As you know, I get the ValueError in the title when trying to create a VectorWind instance from a uwnd and vwnd cube from ERA-interim reanalysis data. The data are on a Gaussian grid. You said this was probably due to the tolerance variable being set too low. Can you change this please? Thanks. Adrian.
SHTns[1] is a "blazingly fast" library for Spherical Harmonic Transform. It is used in gfs-dycore[2] instead of spherepack and Jeffrey Whitaker provided a nice shallow water example in python with some wrappers[3] to equivalent pyspharm functions. It should be straitforward to implement into windspharm as an optionnal backend.
[1] http://users.isterre.fr/nschaeff/SHTns/
[2] https://code.google.com/p/gfs-dycore/
https://code.google.com/p/gfs-dycore/source/browse/trunk/src/shtns.f90
[3] http://users.isterre.fr/nschaeff/SHTns/shallow_water_8py-example.html
It might be good to have an interface like the standard interface where the user can supply the order of the input dimensions and have the shapes of the input automatically conformed to the requirements, and have outputs transformed back to the same shape as the inputs.
I would very much like to use windspharm, but I need to be able to input divergence and/or vorticity, then use those to compute the winds, streamfunction, and/or velocity potential. Any plans to do that, or advice on how I can modify windspharm to do so? The current version seems to require the winds (u,v) as input.
I am getting this error when I use the latest version of windspharm -
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/windspharm-1.5.1-py3.5.egg/windspharm/standard.py", line 105, in __init__
rsphere=rsphere)
File "/usr/local/lib/python3.5/dist-packages/spharm/spharm.py", line 220, in __init__
raise ValueError(msg)
ValueError: Spharmt.__init__ illegal value of nlat (1) - must be at least 3
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "velocity_stream.py", line 52, in <module>
w = VectorWind(uwnd, vwnd)
File "/usr/local/lib/python3.5/dist-packages/windspharm-1.5.1-py3.5.egg/windspharm/standard.py", line 111, in __init__
raise ValueError(err)
ValueError: invalid input dimensions
This is the shape of u wind and v wind - (1, 181, 360) (1, 181, 360)
and this is my source code - sorry I am a newbie just starting off today
nc_f1 = './u-component_of_wind_isobaric_100_2006_16_1_18Z.nc' # Your filename
nc_f2 = './v-component_of_wind_isobaric_100_2006_16_1_18Z.nc' # Your filename
nc_fid1 = Dataset(nc_f1,'r')
nc_fid2 = Dataset(nc_f2,'r')
lats = nc_fid1.variables['lat'][:] # extract/copy the data
lons = nc_fid1.variables['lon'][:]
uwnd = nc_fid1.variables['u-component_of_wind_isobaric'][:]
vwnd = nc_fid2.variables['v-component_of_wind_isobaric'][:]
# The standard interface requires that latitude and longitude be the leading
# dimensions of the input wind components, and that wind components must be
# either 2D or 3D arrays. The data read in is 3D and has latitude and
# longitude as the last dimensions. The bundled tools can make the process of
# re-shaping the data a lot easier to manage.
uwnd, uwnd_info = prep_data(uwnd, 'tyx')
vwnd, vwnd_info = prep_data(vwnd, 'tyx')
# It is also required that the latitude dimension is north-to-south. Again the
# bundled tools make this easy.
lats, uwnd, vwnd = order_latdim(lats, uwnd, vwnd)
print(lats.shape,uwnd.shape,vwnd.shape)
# Create a VectorWind instance to handle the computation of streamfunction and
# velocity potential.
w = VectorWind(uwnd, vwnd)
sys.exit()
I had windspharm
working fine a week or so ago, but it is no longer working and I haven't managed to figure out why.
Quite simply, if I try to use the package, it throws a dlopen
error.
Thanks for any suggestions
>>> import windspharm
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/miniconda3/envs/pyfloods/lib/python3.6/site-packages/windspharm/__init__.py", line 23, in <module>
from . import standard
File "/usr/local/miniconda3/envs/pyfloods/lib/python3.6/site-packages/windspharm/standard.py", line 22, in <module>
from spharm import Spharmt, gaussian_lats_wts
File "/usr/local/miniconda3/envs/pyfloods/lib/python3.6/site-packages/spharm/__init__.py", line 1, in <module>
from .spharm import __doc__
File "/usr/local/miniconda3/envs/pyfloods/lib/python3.6/site-packages/spharm/spharm.py", line 123, in <module>
import _spherepack, numpy, math, sys
ImportError: dlopen(/usr/local/miniconda3/envs/pyfloods/lib/python3.6/site-packages/_spherepack.cpython-36m-darwin.so, 2): Library not loaded: @rpath/libgfortran.3.dylib
Referenced from: /usr/local/miniconda3/envs/pyfloods/lib/python3.6/site-packages/_spherepack.cpython-36m-darwin.so
Reason: image not found
>>>
More info: using python 3.6 and install with conda install -c conda-forge windspharm
.
Dear Andrew Dawson,
unfortunately, I cannot use your module, since there is some problem with the relative import of standard.py and tools.py:
In [26]: from windspharm.standard import VectorWind
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-26-37081f3a34f9> in <module>()
----> 1 from windspharm.standard import VectorWind
/usr/local/lib/python2.7/site-packages/windspharm/__init__.py in <module>()
21 from __future__ import absolute_import
22
---> 23 from . import standard
24 from . import tools
25
ImportError: cannot import name standard
Do you know what I could do about it. In other modules, the relative import works, so it should not be a problem with regard to my python setup.
Thank you very much.
Alex
Hello, I find this module very convenient, but have encountered a problem when computing the vorticity of a numerical weather prediction (NWP) model output. While there is no error during the computation, the results turn out to be quite non-physical.
In my opinion, it appears to be due to the longitude and latitude increments being different. The model I used here is the regridded version of GDAPS-UM, the Korean model borrowed from the Met Office, with a horizontal resolution of 0.234375 (769 latitude points) x 0.3515625 (1024 longitude points). Other models were interpolated to 0.125 x 0.125, 0.25 x 0.25, 0.5 x 0.5, or even 0.140625 x 0.140625, but you can see that the resolution is the same in the x and y directions.
I have used the same function in the standard interface:
w = ws.standard.VectorWind(u, v, rsphere = 6371229.)
rvo, div = w.vrtdiv()
This is the GDAPS-UM result for vorticity (shaded).
These are results of ECMWF-IFS, GFS, and the Korean Integrated Model, or KIM (vorticity shaded in each figure).
The u and v seem to be similar, considering these are different forecasts and each have different resolutions. However, only the GDAPS-UM model has a peculiar vorticity pattern.
I can't quite find out what is wrong with the code. Could anybody help me on this matter? Thank you in advance.
P.S. Please mind that the model outputs cannot be publicly released.
I've been using the standard interface and I've come across a bug in the calculation of the wind magnitude.
Instead of,
return (u ** 2 + v ** 2) ** 0.5
the code should read:
return (self.u ** 2 + self.v ** 2) ** 0.5
The standard interface raises an error complaining about gridtype being invalid although it is possible that the input arrays have the wrong shape. Could this be made clearer?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.