You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
xarray currently has the xarray.dot() function for calculating arbitrary dot products which is indeed very handy.
Sometimes, especially for physical applications I also need a vector cross product. I' wondering whether you would be interested in having xarray.cross as a wrapper of numpy.cross. I currently use the following implementation:
defcross(a, b, spatial_dim, output_dtype=None):
"""xarray-compatible cross product Compatible with dask, parallelization uses a.dtype as output_dtype """# TODO find spatial dim default by looking for unique 3(or 2)-valued dim?fordin (a, b):
ifspatial_dimnotind.dims:
raiseValueError('dimension {} not in {}'.format(spatial_dim, d))
ifd.sizes[spatial_dim] !=3: #TODO handle 2-valued casesraiseValueError('dimension {} has not length 3 in {}'.format(d))
ifoutput_dtypeisNone:
output_dtype=a.dtype# TODO some better way to determine default?c=xr.apply_ufunc(np.cross, a, b,
input_core_dims=[[spatial_dim], [spatial_dim]],
output_core_dims=[[spatial_dim]],
dask='parallelized', output_dtypes=[output_dtype]
)
returnc
Do you want such a function (and possibly associated DataArray.cross methods) in the xarray namespace, or should it be in some other package? I didn't find a package which would be a good fit as this is close to core numpy functionality and isn't as domain specific as some geo packages. I'm not aware of some "xrphysics" package.
I could make a PR if you'd want to have it in xarray directly.
Output of xr.show_versions()
# Paste the output here xr.show_versions() here
INSTALLED VERSIONS
------------------
commit: None
python: 3.7.3 (default, Mar 27 2019, 22:11:17)
[GCC 7.3.0]
python-bits: 64
OS: Linux
OS-release: 4.9.0-9-amd64
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
libhdf5: 1.10.4
libnetcdf: 4.6.1
xarray currently has the
xarray.dot()
function for calculating arbitrary dot products which is indeed very handy.Sometimes, especially for physical applications I also need a vector cross product. I' wondering whether you would be interested in having
xarray.cross
as a wrapper ofnumpy.cross
. I currently use the following implementation:Example usage
Main question
Do you want such a function (and possibly associated
DataArray.cross
methods) in thexarray
namespace, or should it be in some other package? I didn't find a package which would be a good fit as this is close to core numpy functionality and isn't as domain specific as some geo packages. I'm not aware of some "xrphysics" package.I could make a PR if you'd want to have it in
xarray
directly.Output of
xr.show_versions()
xarray: 0.12.3
pandas: 0.24.2
numpy: 1.16.4
scipy: 1.3.0
netCDF4: 1.4.2
pydap: None
h5netcdf: 0.7.4
h5py: 2.9.0
Nio: None
zarr: None
cftime: 1.0.3.4
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: 1.2.1
dask: 2.1.0
distributed: 2.1.0
matplotlib: 3.1.0
cartopy: None
seaborn: 0.9.0
numbagg: None
setuptools: 41.0.1
pip: 19.1.1
conda: 4.7.11
pytest: 5.0.1
IPython: 7.6.1
sphinx: 2.1.2
The text was updated successfully, but these errors were encountered: