soft-matter / trackpy

Python particle tracking toolkit
http://soft-matter.github.io/trackpy
Other
448 stars 132 forks source link

Index-handling in filter functions and other feedback #498

Open lagru opened 6 years ago

lagru commented 6 years ago

Hello devs, first of all I'd like to thank you for your work on this small but promising library. I'm currently wrapping parts of your library to use with a command line tool intended for particle tracking at my university. Thanks to your great example section and generally well documented API that process is very easy and satisfying.

However I also encountered some minor hiccups and annoyances. Maybe you find my feedback in that regard useful:

from functools import partial
from multiprocessing.pool import ThreadPool

def batch_threaded(frames, locate_kw, threads=4, report_hook=None):
    if not report_hook:
        def report_hook(): pass
    func = partial(trackpy.locate, **locate_kw)
    with ThreadPool(threads) as pool:
        stats = []
        for i, frame_stats in enumerate(pool.imap(func, frames)):
            frame_stats["frame"] = i
            stats.append(frame_stats)
            report_hook()
    return pd.concat(stats, ignore_index=True)

I'm aware that this criticism is subjective and these are only minor points. So please take this as well meant feedback. Of course I would be happy to work on these points myself if help is desired! :slightly_smiling_face:

caspervdw commented 6 years ago

Hi @lagru, thanks for your feedback, it is always welcome! Per point:

nkeim commented 6 years ago

Addressing the broader point of pandas: it does have a learning curve and at first I wasn't sure what is so great about it. But it has made trackpy easier to write and, in some places, both faster and more versatile than we would have been willing to make it ourselves. It is a very natural fit for tracks data, so I encourage you to learn more about it. I think that @danielballan would agree with me that more scientists should be using it!

That said, docstrings, tutorials, and (maybe) helper functions could make it easier to use trackpy if you are unfamiliar with pandas. To echo @caspervdw , please make a note of the sticking points you encounter and please do suggest changes!