GithubHelp home page GithubHelp logo

gher-uliege / divand.py Goto Github PK

View Code? Open in Web Editor NEW
8.0 8.0 3.0 390 KB

divand performs an n-dimensional variational analysis of arbitrarily located observations (python interface)

License: GNU General Public License v2.0

Python 64.12% Shell 35.88%

divand.py's People

Contributors

alexander-barth avatar ctroupin avatar gher-diva avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

divand.py's Issues

Julia Domain Error linked to len parameters

Good morning,

I am trying to interpolate oceanographic data (nutrients concentrations) with DIVAnd through Python using PyJulia but encounter this error :

RuntimeError: <PyCall.jlwrap (in a Julia function called from Python)
JULIA: DomainError with -0.0007120454096863318:
sqrt will only return a complex result if called with a complex argument. Try sqrt(Complex(x)).
Stacktrace:
  [1] throw_complex_domainerror(f::Symbol, x::Float64)
    @ Base.Math .\math.jl:33
  [2] sqrt
    @ .\math.jl:567 [inlined]
  [3] _broadcast_getindex_evalf
    @ .\broadcast.jl:670 [inlined]
  [4] _broadcast_getindex
    @ .\broadcast.jl:643 [inlined]
  [5] _getindex
    @ .\broadcast.jl:667 [inlined]
  [6] _getindex
    @ .\broadcast.jl:666 [inlined]
  [7] _broadcast_getindex
    @ .\broadcast.jl:642 [inlined]
  [8] getindex
    @ .\broadcast.jl:597 [inlined]
  [9] macro expansion
    @ .\broadcast.jl:961 [inlined]
 [10] macro expansion
    @ .\simdloop.jl:77 [inlined]
 [11] copyto!
    @ .\broadcast.jl:960 [inlined]
 [12] copyto!
    @ .\broadcast.jl:913 [inlined]
 [13] copy
    @ .\broadcast.jl:885 [inlined]
 [14] materialize(bc::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{2}, Nothing, typeof(/), Tuple{Int64, Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{2}, Nothing, typeof(sqrt), Tuple{Matrix{Float64}}}}})
    @ Base.Broadcast .\broadcast.jl:860
 [15] DIVAnd_background(operatortype::Type, mask::BitMatrix, pmn::Tuple{Matrix{Float64}, Matrix{Float64}}, Labs::Tuple{Matrix{Float64}, Matrix{Float64}}, alpha::Vector{Any}, moddim::Vector{Any}, scale_len::Bool, mapindex::Vector{Any}; btrunc::Vector{Any}, coeff_laplacian::Vector{Float64}, coeff_derivative2::Vector{Float64}, mean_Labs::Nothing)
    @ DIVAnd C:\Users\Léo\.julia\packages\DIVAnd\Iwjb1\src\DIVAnd_background.jl:123
 [16] DIVAndrun(operatortype::Type, mask::BitMatrix, pmnin::Tuple{Matrix{Float64}, Matrix{Float64}}, xiin::Tuple{Matrix{Float64}, Matrix{Float64}}, x::Tuple{Vector{Float64}, Vector{Float64}}, f::Vector{Float64}, lin::Tuple{Float64, Float64}, epsilon2::Int64; velocity::Tuple{}, primal::Bool, factorize::Bool, tol::Float64, maxit::Int64, minit::Int64, constraints::Tuple{}, inversion::Symbol, moddim::Vector{Any}, fracindex::Matrix{Float64}, alpha::Vector{Any}, keepLanczosVectors::Int64, compPC::typeof(DIVAnd.DIVAnd_pc_none), progress::DIVAnd.var"#285#287", fi0::Matrix{Float64}, f0::Vector{Float64}, alphabc::Float64, scale_len::Bool, btrunc::Vector{Any}, MEMTOFIT::Float64, topographyforfluxes::Tuple{}, fluxes::Tuple{}, epsfluxes::Int64, epsilon2forfractions::Int64, RTIMESONESCALES::Tuple{}, QCMETHOD::Tuple{}, coeff_laplacian::Vector{Float64}, coeff_derivative2::Vector{Float64}, mean_Labs::Nothing)
    @ DIVAnd C:\Users\Léo\.julia\packages\DIVAnd\Iwjb1\src\DIVAndrun.jl:53
 [17] DIVAndrun(operatortype::Type, mask::BitMatrix, pmnin::Tuple{Matrix{Float64}, Matrix{Float64}}, xiin::Tuple{Matrix{Float64}, Matrix{Float64}}, x::Tuple{Vector{Float64}, Vector{Float64}}, f::Vector{Float64}, lin::Tuple{Float64, Float64}, epsilon2::Int64)
    @ DIVAnd C:\Users\Léo\.julia\packages\DIVAnd\Iwjb1\src\DIVAndrun.jl:45
 [18] #DIVAndrun#290
    @ C:\Users\Léo\.julia\packages\DIVAnd\Iwjb1\src\DIVAndrun.jl:298 [inlined]
 [19] DIVAndrun
    @ C:\Users\Léo\.julia\packages\DIVAnd\Iwjb1\src\DIVAndrun.jl:298 [inlined]
 [20] #DIVAndrun#289
    @ C:\Users\Léo\.julia\packages\DIVAnd\Iwjb1\src\DIVAndrun.jl:152 [inlined]
 [21] DIVAndrun(::Matrix{Bool}, ::Tuple{Matrix{Float64}, Matrix{Float64}}, ::Tuple{Matrix{Float64}, Matrix{Float64}}, ::Tuple{Vector{Float64}, Vector{Float64}}, ::Vector{Float64}, ::Tuple{Float64, Float64}, ::Int64)
    @ DIVAnd C:\Users\Léo\.julia\packages\DIVAnd\Iwjb1\src\DIVAndrun.jl:152
 [22] DIVAndrunfi(::Matrix{Bool}, ::Vararg{Any})
    @ DIVAnd C:\Users\Léo\.julia\packages\DIVAnd\Iwjb1\src\DIVAndrun.jl:157
 [23] invokelatest(::Any, ::Any, ::Vararg{Any}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Base .\essentials.jl:716
 [24] invokelatest(::Any, ::Any, ::Vararg{Any})
    @ Base .\essentials.jl:714
 [25] _pyjlwrap_call(f::Function, args_::Ptr{PyCall.PyObject_struct}, kw_::Ptr{PyCall.PyObject_struct})
    @ PyCall C:\Users\Léo\.julia\packages\PyCall\7a7w0\src\callback.jl:28
 [26] pyjlwrap_call(self_::Ptr{PyCall.PyObject_struct}, args_::Ptr{PyCall.PyObject_struct}, kw_::Ptr{PyCall.PyObject_struct})
    @ PyCall C:\Users\Léo\.julia\packages\PyCall\7a7w0\src\callback.jl:44>

The parameters used are defined as follow :

lenx = 1/12 * 110000 * np.cos(np.pi * 40 / 180)  # we estimate measures are not drastically different whithin a 1/12° square
leny = 1/12 * 110000
epsilon2 = 1.
mask = np.full(XX.shape, True, dtype=bool)
pm = np.ones(XX.shape) / (XX[0, 1] - XX[0, 0])
pn = np.ones(XX.shape) / (YY[1, 0] - YY[0, 0])
interp_values = DIVAnd(mask, (pm, pn), (XX, YY), (points[:, 0], points[:, 1]), values, (lenx, leny), epsilon2)
print("va", interp_values)

Where XX and YY are the meshgrid to which we interpolate, points are lon and lat measures coordinates and values the measures, all positive.

I observed that the value explained in Domain error decreases when (lenx, leny) increases, but never becomes positive.

Any solution or idea about this ?

Great day,
Léo

All zero results with 3D fields

Hi,
I'm trying to use DIVAnd.py with a 3d field so I just adapted one of the example written in JULIA to check if it works but I just obtain a zero fields. Here is the code I used:

from julia import DIVAnd
import numpy as np

x = np.random.rand(75);
y = np.random.rand(75);
z = np.random.rand(75);
f = np.sin(x*6) * np.cos(y*6)+np.sin(z*6) * np.cos(x*6) ;

testsize=300
testsizez=3
xi,yi,zi = np.meshgrid(np.arange(0,1,1/testsize),np.arange(0,1,1/testsize),np.arange(0,1,1/testsizez));

fref = np.sin(xi*6) * np.cos(yi*6)+np.sin(zi*6) * np.cos(xi*6) ;

mask = np.ones(xi.shape)==1;

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])
po = np.ones(xi.shape) / (zi[1,1,2]-zi[1,1,1])

lenx = 0.5;

epsilon2 = 1.;

va = DIVAnd.DIVAndrunfi(mask,(pm,pn,po),(xi,yi,zi),(x,y,z),f,lenx,epsilon2)

I have also tryed to transpose some of the fields (as in DIVAnd.py) but I still obtain a zero output

va = DIVAnd.DIVAndrunfi(np.transpose(mask),(np.transpose(pm),np.transpose(pn),np.transpose(po)),
(np.transpose(xi),np.transpose(yi),np.transpose(zi)),
(x,y,z),f,lenx,epsilon2)

I am supposing there is a different way in which JULIA and python order the axes, I will do other tests swapping them.

ImportError

Hi,

I followed all steps to install divand.py (on a workstation with Win 8.1 64 bit)
After I downloaded divand.py, I set a system variable:
PYTHONPATH=C:\Python27;C:\Python27\Lib;C:\Python27\DLLs;C:\divand.py\divand\divand.py

I run: python divand_argo.py
I got : ImportError: No module named divand

Cheers!
George

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.