-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem with boundary values in .core.grids._horizontal_gradient #21
Comments
I think your current version would not work anyway if you don't specify a dtype explicitly, see my issue here. |
@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). |
@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 def is_numpy(array): def _horizontal_gradient(scalararray): ds = xr.open_dataset('../data/heigh_2017011715Z_1000hPa.nc') I get this error: 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 |
Hi @kuchaale, your solution worked for me, please open a PR or allow me to do it |
numpy.gradient compute the spatial derivatives with a second order scheme except near boundaries where the derivatives are evaluated with a first order scheme. oocgcm.core.grids._horizontal_gradient wraps numpy.gradient for xarray.DataArray with dask.
in order for the result not to depend on the chunk size, we need to set depth and use dask.array.map_overlap.
but it is not clear how to specify that the calculation should be first order near the boundary when the chunk is close to the boundary. numpy.gradient sees the ghost cell and therefore applies the second order derivative...
the current implementation explicitely sets a np.nan boundary condition to avoid errors.
this could be a question for dask mailing list.
The text was updated successfully, but these errors were encountered: