GithubHelp home page GithubHelp logo

Comments (5)

ctroupin avatar ctroupin commented on June 29, 2024

Quick try: could you replace:

pm = np.ones(xi.shape) / (xi[1,2,1]-xi[1,1,1])
pn = np.ones(xi.shape) / (yi[2,1,1]-yi[1,1,1])

with

pm = np.ones(xi.shape) / (xi[2,1,1]-xi[1,1,1])
pn = np.ones(xi.shape) / (yi[1,2,1]-yi[1,1,1])

from divand.py.

ecutolo avatar ecutolo commented on June 29, 2024

In the way you said pm and pn gives infinity while in the way I did the results are the same as DIVAnd with julia anyway I think I found a solution. It was a problem with the axes ordering using the numpy function swapaxes instead of transpose it works also with 3D fields. There is a pull-request pending. I did not check with 4D yet.

from divand.py.

Alexander-Barth avatar Alexander-Barth commented on June 29, 2024

Did you see this note of meshgrid? (https://docs.scipy.org/doc/numpy/reference/generated/numpy.meshgrid.html)

In the 2-D case with inputs of length M and N, the outputs are of shape (N, M) for ‘xy’ indexing and (M, N) for ‘ij’ indexing. In the 3-D case with inputs of length M, N and P, outputs are of shape (N, M, P) for ‘xy’ indexing and (M, N, P) for ‘ij’ indexing.

Does it work when you use ‘ij’ indexing and a suitable definition of pm, pn, ...

pm = np.ones(xi.shape) / (xi[1,0,0]-xi[0,0,0])
# [...]

from divand.py.

ecutolo avatar ecutolo commented on June 29, 2024

Ok yes, using the 'ij' indexing it works if you do not transpose the matrix nor use the swapaxes inside the DIVAnd wrapper function. This last in facts should be modified anyway removing the np.transpose and just preserving the masking:

def DIVAnd(mask, pmn, xi, x, f, corlen, epsilon2):
    va = D.DIVAndrunfi(mask,pmn,xi,x, f, corlen, epsilon2)
    return np.ma.MaskedArray(va, np.logical_not(mask))

from divand.py.

Alexander-Barth avatar Alexander-Barth commented on June 29, 2024

This file is an example for applying DIVAnd.py in 3D:
https://github.com/gher-ulg/DIVAnd.py/blob/88787becfff206e247dbee24a74963062050fe5e/examples/DIVAnd_3d.py

As you will see, there are 2 ways to call DIVAnd:

Both variants do actually work for 3D.

I made the wrapper in an attempt to make DIVAnd more natural for python users because the default order of the dimensions is usually (depth, latitude, longitude, at least when I read a NetCDF file in python, or C/C++,...) while the order of Julia (and Fortran, Octave, ...) is longitude, latitude and depth. But this creates more confusion that it is actually worth. Also, numpy supports both storage orders.

So what is will do, it to skip the wrapper (what is actually what you did in the code sample in this issue) DIVAnd.py and use the first variant in the example file:

https://github.com/gher-ulg/DIVAnd.py/blob/88787becfff206e247dbee24a74963062050fe5e/examples/DIVAnd_3d.py#L32

The julia code DIVAnd has also grown considerably, and it would not be feasible to have a wrapper which transpose the arguments of all functions and at the same time pyjulia made it quite convenient to call julia code directly from python.

from divand.py.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.