Comments (4)
@lesommer : I understand your issue with the specification of np.nan. However, when I run the code below (without dtype specification):
`import numpy as np
import xarray as xr
def is_numpy(array):
test = bool( isinstance(array,np.ndarray)
+ isinstance(array,np.ma.masked_array) )
return test
def _horizontal_gradient(scalararray):
data = scalararray.data
coords = scalararray.coords
dims = scalararray.dims
chunks = scalararray.chunks
if is_numpy(data):
da_dj,da_di = np.gradient(data)
else:
x_derivative = lambda arr:np.gradient(arr,axis=-1) # req. numpy > 1.11
y_derivative = lambda arr:np.gradient(arr,axis=-2) # req. numpy > 1.11
gx = data.map_overlap(x_derivative,depth=(0,1),boundary={1: np.nan})#, dtype=data.dtype)
gy = data.map_overlap(y_derivative,depth=(1,0),boundary={0: np.nan})#, dtype=data.dtype)
da_di = xr.DataArray(gx,coords,dims)
da_dj = xr.DataArray(gy,coords,dims)
return da_dj,da_di
ds = xr.open_dataset('../data/heigh_2017011715Z_1000hPa.nc')
ds = ds.chunk(chunks = 40)
ds`
I get this error:
ValueError:
dtypeinference failed in
map_blocks`.
Original error is below:
ValueError('Shape of array too small to calculate a numerical gradient, at least two elements are required.',)
Traceback:
File "c:\python27\lib\site-packages\dask\array\core.py", line 457, in apply_infer_dtype
o = func(*args, **kwargs)
File "", line 26, in
x_derivative = lambda arr:np.gradient(arr,axis=-1) # req. numpy > 1.11
File "c:\python27\lib\site-packages\numpy\lib\function_base.py", line 1642, in gradient
"Shape of array too small to calculate a numerical gradient, "
`
This issue is induced by the non-specification of dtype.
from oocgcm.
I think your current version would not work anyway if you don't specify a dtype explicitly, see my issue here.
from oocgcm.
@kuchaale : thanks for your comment and your suggestion. But I am not sure to get what you mean by "would not work" here. The present version of the code actually produce a result, but does not compute the gradient close to the boundary (thanks to the specification of np.nan).
from oocgcm.
Hi @kuchaale, your solution worked for me, please open a PR or allow me to do it
from oocgcm.
Related Issues (20)
- Allow grid object to describe periodic grids (with a periodic x-axis).
- Shall I rename projection coordinates ? HOT 2
- How to reimplement grid coarsening and statistics-in-boxes in oocgcm ? HOT 7
- How to implement spatial integration methods in oocgcm ? HOT 2
- A decorator for testing chunks/grid_location.
- Add a class in order to access vertical coordinates and metrics HOT 4
- lon/lat information in xarray_dataset does not go through grid functions (norm_of_vectorfield for example) HOT 7
- Add method for Okubo-Weiss parameter in core.generic_2d_grid HOT 7
- Problem while reading a self-made netcdf file with io.return_xarray_mfdataset HOT 6
- Problem when slicing a NEMO 2d grid objects defined with dask chunks. HOT 4
- Suggestion: correct coordinates after curl/norm HOT 4
- Inheritance of DataArray HOT 1
- Data objects (scalar, vectors ...)
- Can not manage memory properly with norm_of_vectorfield
- use geojson for defining spatial diagnostics. HOT 1
- Add imports of sub-packages to top-level __init__.py HOT 2
- Slicing/isosurfaces methods for 3D grids. HOT 5
- pycomodo vs sgrid HOT 1
- oocgcm does not trivially apply to mitgcm outputs HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from oocgcm.