Skip to content
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

van Hove plotting problem #394

Open
Resonanz opened this issue Aug 11, 2016 · 13 comments
Open

van Hove plotting problem #394

Resonanz opened this issue Aug 11, 2016 · 13 comments
Labels

Comments

@Resonanz
Copy link

I am trying to get the van Hove function to work.

In the walkthrough I have added a little code to call the van Hove function as follows:

#existing in walkthrough
t2 = t1[((t1['mass'] > 300) & (t1['size'] < 3.5) &
         (t1['ecc'] < 0.1))]

#added to walkthrough
pos = t2.set_index(['frame','particle'])['x'].unstack()
vh = tp.vanhove(pos, lagtime=2)

I get this error for a span of lagtimes:

ValueError: ('range parameter must be finite.', 'occurred at index 0.0')

which is coming from this line in the van Hove function:

vh = disp.apply(lambda x: Series(np.histogram(x, bins=global_bins, density=True)[0]))

Any help? Thanks !

@Resonanz Resonanz changed the title van Hove van Hove plotting problem Aug 11, 2016
@Resonanz
Copy link
Author

As a follow-on, I am finding the code really hard to follow (well, pandas is quite complicated). For example. code like this does not seem to be explained by the histogram documentation:

global_bins = np.histogram(values, bins=bins)[1]

So, what exactly does the [1] at the end mean? Is this an axis? Is the [1] old code that needs replacing with axis=1?

Thanks again.

@Resonanz
Copy link
Author

Resonanz commented Aug 11, 2016

This is the error code by the way:

ValueError                                Traceback (most recent call last)
<ipython-input-47-fd307fb7b8ec> in <module>()
     29 #print(x)
     30 #print('global_bins = ' + str(global_bins))
---> 31 vh = disp.apply(lambda x: Series(np.histogram(x, bins=global_bins, density=True)[0]))
     32 #vh = Series(np.histogram(x, bins=global_bins, density=True)[0])
     33 #vh.index = global_bins[:-1]

C:\Users\rlward\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\core\frame.py in apply(self, func, axis, broadcast, raw, reduce, args, **kwds)
   4059                     if reduce is None:
   4060                         reduce = True
-> 4061                     return self._apply_standard(f, axis, reduce=reduce)
   4062             else:
   4063                 return self._apply_broadcast(f, axis)

C:\Users\rlward\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\core\frame.py in _apply_standard(self, func, axis, ignore_failures, reduce)
   4155             try:
   4156                 for i, v in enumerate(series_gen):
-> 4157                     results[i] = func(v)
   4158                     keys.append(v.name)
   4159             except Exception as e:

<ipython-input-47-fd307fb7b8ec> in <lambda>(x)
     29 #print(x)
     30 #print('global_bins = ' + str(global_bins))
---> 31 vh = disp.apply(lambda x: Series(np.histogram(x, bins=global_bins, density=True)[0]))
     32 #vh = Series(np.histogram(x, bins=global_bins, density=True)[0])
     33 #vh.index = global_bins[:-1]

C:\Users\rlward\AppData\Local\Continuum\Anaconda3\lib\site-packages\numpy\lib\function_base.py in histogram(a, bins, range, normed, weights, density)
    503     if not np.all(np.isfinite([mn, mx])):
    504         raise ValueError(
--> 505             'range parameter must be finite.')
    506     if mn == mx:
    507         mn -= 0.5

ValueError: ('range parameter must be finite.', 'occurred at index 0.0')

@tacaswell
Copy link
Member

np.histogram returns 2 values in a tuple (https://docs.scipy.org/doc/numpy/reference/generated/numpy.histogram.html). The [1] is just selecting the second value.

Those exceptions look like some invalid data (np.nan or np.inf) is getting into the histogram call.

@Resonanz
Copy link
Author

There are NaN vales in the data but I think these are processed out. Would it be possible to see an example of some working code, or should my code above work? If I add those lines into the Walkthrough, should they work?

@caspervdw
Copy link
Member

This needs some documentation.

@pipoUrdaneta
Copy link

Hi all

I signed up to this website just a while ago feeling pretty desperate about exactly the same problem Resonanz posted. Has any of you gotten around this problem yet?

PS: I'm totally new to coding (started learning Python from scratch just over a month ago).

@Resonanz
Copy link
Author

I have just started a new microrheology project so I'm keen (again) to get this working.

@pipoUrdaneta
Copy link

My seniors advised me to uninstall Anaconda3-5.x, and install Anaconda3-4.0.0. Did it just this morning and now the van Hove command worked.

@caspervdw
Copy link
Member

@pipoUrdaneta Good that it works for you! I wonder what your pandas and numpy version were with the respective installations. These can be shown easily using

import trackpy as tp
print(tp.diag.dependencies())

@danielballan Would be the one to provide a working example as he wrote the function.

For sure we need a test to at least run the vanhove function with different library versions.

@Resonanz
Copy link
Author

If you have code that now works, could you please post a working example that others can try? Thanks.

@pipoUrdaneta
Copy link

@caspervdw Thanks!
import trackpy as tp
print(tp.diag.dependencies())
gives this:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-1-1f4075b94f34> in <module>()
      1 import trackpy as tp
----> 2 print(tp.diag.dependencies())

AttributeError: module 'trackpy' has no attribute 'diag'

But for pandas and numpy in my current Anaconda3-4.0.0 installation:

import numpy as np
np.__version__

gives
'1.10.4'

and

import pandas as pd
pd.__version__ 

gives
'0.18.0'

The Anaconda version previously used was 5.2.0, with Python 3.6.
I looked up the packages from that installation here:
https://docs.anaconda.com/anaconda/packages/py3.6_win-32
and for Numpy it's 1.14.3,
while for Pandas it's 0.23.0

@pipoUrdaneta
Copy link

@Resonanz will do, although for the above I did just follow the van Hove command in TrackPy's documentation,
http://soft-matter.github.io/trackpy/dev/generated/trackpy.motion.vanhove.html

pos = traj.set_index(['frame', 'particle'])['x'].unstack() # particles as columns
vh = tp.vanhove(pos)

(and not forgetting to specify the lagtime argument after pos)

@danielballan
Copy link
Member

@danielballan Would be the one to provide a working example as he wrote the function.

Fair. See #516.

@rbnvrw rbnvrw mentioned this issue Apr 14, 2019
@nkeim nkeim modified the milestone: v0.4.2 Sep 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants