GithubHelp home page GithubHelp logo

Comments (16)

AntSimi avatar AntSimi commented on July 18, 2024 1

@CoriPegliasco in your case x & y are empty array...

from py-eddy-tracker.

AntSimi avatar AntSimi commented on July 18, 2024 1

Must be solved now

from py-eddy-tracker.

AntSimi avatar AntSimi commented on July 18, 2024

Inside method return for each given position if there are in one eddy of the list (you get an array of boolean).
So you could imagine use like this:

mask = a1.inside(x=df.longitude.values.astype('f8'), y=df.latitude.values.astype('f8'))
obs_inside = df[mask]     

To get parameters of eddy which enclosed Insitu observation, use contains method which will return index of a1 observations (-1 in case of insitu obs are not enclosed by eddy) instead of a boolean:

index_eddy = a1.contains(x=df.longitude.values.astype('f8'), y=df.latitude.values.astype('f8'))
mask = index_eddy != -1
insitu_inside = df[mask] 
eddy_lat_which_enclosed_insitu = a1.lat[index_eddy[mask]]

from py-eddy-tracker.

acapet avatar acapet commented on July 18, 2024

Thanks! Somehow, the last line in the following induces a segmentation fault, and I can't find the dumped core to give additional information..

for d in range(dmin,dmax):
    a1=ta1.extract_with_period((d,d))
    dfsub = df[df["time"]==d]
    mask = a1.inside(x=dfsub.longitude.values.astype('f8'), y=dfsub.latitude.values.astype('f8'))

    if any(mask):
        print(d)
        index_eddy = a1.contains(x=dfsub.longitude.values.astype('f8'), y=dfsub.latitude.values.astype('f8'))

from py-eddy-tracker.

AntSimi avatar AntSimi commented on July 18, 2024

All your longitude and latitude are valid? Could you share min/max? You could also skip mask computation and use directly contains to avoid double computation.

from py-eddy-tracker.

acapet avatar acapet commented on July 18, 2024

They are valid, but generally contain only 1 element.

    print(dfsub.longitude.values.astype('f8'))
    print(dfsub.latitude.values.astype('f8'))

works fine below the if part above

from py-eddy-tracker.

AntSimi avatar AntSimi commented on July 18, 2024

Which version of py eddy tracker did you use?

from py-eddy-tracker.

acapet avatar acapet commented on July 18, 2024

I updated everything (pull, re-install) two days ago, and used the overlap tracker (but that was before, though, the tracking files were produced some months ago)

from py-eddy-tracker.

CoriPegliasco avatar CoriPegliasco commented on July 18, 2024

Hi,
I also have an issue with contains (on the latest version)

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-33-d13a49993c9c> in <module>
      7                             dissociate_network=True,
      8                             correct_close_events=45,
----> 9                             remove_dead_end=14
     10                             )

--/dev/py-eddy-tracker/src/py_eddy_tracker/observations/network.py in analysis_coherence(self, date_function, uv_params, advection_mode, dt_advect, step_mesh, output_name, dissociate_network, correct_close_events, remove_dead_end)
   1368             output_name=output_name,
   1369             dt_advect=dt_advect,
-> 1370             step_mesh=step_mesh,
   1371         )
   1372 

--/dev/py-eddy-tracker/src/py_eddy_tracker/observations/network.py in segment_coherence(self, date_function, uv_params, advection_mode, dt_advect, step_mesh, output_name)
   1496                         i_target_b,
   1497                         pct_target_b,
-> 1498                         n_days=-dt_advect,
   1499                     )
   1500 

--/dev/py-eddy-tracker/src/py_eddy_tracker/observations/groups.py in particle_candidate(x, y, c, eddies, t_start, i_target, pct, **kwargs)
    121     translate_end = where(m_end)[0]
    122     # Id eddies for each alive particle (in core and extern)
--> 123     i_end = e_end.contains(x, y)
    124     # compute matrix and fill target array
    125     get_matrix(i_start, i_end, translate_start, translate_end, i_target, pct)

--/dev/py-eddy-tracker/src/py_eddy_tracker/observations/observation.py in contains(self, x, y, intern)
   2057         m = ~(isnan(x) + isnan(y))
   2058         i = -ones(x.shape, dtype="i4")
-> 2059         i[m] = poly_indexs(x[m], y[m], self[xname], self[yname])
   2060         return i
   2061 

~/.conda/envs/eddy37/lib/python3.7/site-packages/numba/np/arraymath.py in array_min_impl()
    533         def array_min_impl(arry):
    534             if arry.size == 0:
--> 535                 raise ValueError(MSG)
    536 
    537             it = np.nditer(arry)

ValueError: zero-size array to reduction operation minimum which has no identity

Could it be because I have longitudes between [-180°, 180°] and poly_indexs is waiting for [0°, 360°]?
Thus the validity for longitudes is ok if >0 ?

from py-eddy-tracker.

AntSimi avatar AntSimi commented on July 18, 2024

ok @acapet, i do some update to speed up poly_index few month ago, maybe it's a side effect ..., to understand the problem i will need a Minimal Working Example, if you are ok, you could create like that:

import pickle
a1.write_file(filename="eddy.nc")
x, y = dfsub.longitude.values.astype('f8'), dfsub.latitude.values.astype('f8')
with open("insitu_position.pkl", "wb") as pkl:
    pickle.dump((x,y), pkl)
a1.contains(x=x, y=y)

from py-eddy-tracker.

CoriPegliasco avatar CoriPegliasco commented on July 18, 2024

The error and associated files

error_contains.tar.gz

from py_eddy_tracker.observations.network import NetworkObservations
import pickle
n = NetworkObservations.load_file("obs_error.nc")
with open("test_particles", "rb") as pkl:
           x,y= pickle.load(pkl)
i_end = n.contains(x, y)

from py-eddy-tracker.

acapet avatar acapet commented on July 18, 2024

Here are the files for the minimal example :

ProfileCollocationFail.tar.gz

I have to mention that the fail is not systematic, which makes it even stranger.
Executing the following goes fine sometimes, but fails at some point if I repeat ~5-10 times.

from py_eddy_tracker.observations.network import NetworkObservations
import pickle
n = NetworkObservations.load_file("./ProfileCollocationFail/eddy.nc")
with open("./ProfileCollocationFail/insitu_position.pkl", "rb") as pkl:
       x,y= pickle.load(pkl)
i_end = n.contains(x, y)

from py-eddy-tracker.

AntSimi avatar AntSimi commented on July 18, 2024

So, it's due to a specific case, which give a bad index and sometime this index is in a forbidden area...
I didn't notice this wrong indexing/code due too a numba silence (numba/numba#7045).
I will release a patch soon.

from py-eddy-tracker.

acapet avatar acapet commented on July 18, 2024

Ok. If I got this right, the problem is due to applying the method when applied on small sets (with one eddy, or one profile).
This arises from the fact that I loop on individual days, which is necessary for matching eddies and external data since "contains" only considers lon and lat, and not time.

I guess the patch will totally do for me. If that goes further, one could of a version of "contain" including the time dimension.

from py-eddy-tracker.

AntSimi avatar AntSimi commented on July 18, 2024

This arises from the fact that I loop on individual days, which is necessary for matching eddies and external data since "contains" only considers lon and lat, and not time

It come when you call contains with one or two observations to compare with eddies.

Root problem come from a bad code which was silent. So i will re-wrote it.
And this root problem is in a method which are use in several other method...

If that goes further, one could of a version of "contain" including the time dimension.

I am not pro to do that, because you must manage time sampling which could be different between your eddies and other observations. My opinion is : it's best that user manage explicitly time coherence.
Maybe, it could be build with iter_on method.

from py-eddy-tracker.

acapet avatar acapet commented on July 18, 2024

Works like a charm, thank you!

from py-eddy-tracker.

Related Issues (20)

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.