Skip to content

set up collection of / extend utility functions #526

Open

Description

@JuliaSprenger

Using the neo structure can be quite cumbersome in some cases, eg like slicing objects based on an epoch array (#525). To improve on this we could A) extend the methods neo objects offer and B) start an object-independent collection of utility functions in a separate file.
Most likely a combination of both is necessary to achieve best usability of the neo structure.

Here are some suggestions for helpful utility functions:

  • create a neo.Epoch based on a neo.Event object (or maybe two neo.Event objects)
  • implement a time_slice function for neo.Segment that also slices child objects accordingly
  • slicing a neo.Segment based on a neo.Epoch
  • add shift methods for neo Data objects, which move timescale of the object (including t_start and t_stop adjustment, etc)
  • support inplace slicing to avoid data duplication and keep original neo structure.

Any thoughts on this? Additional suggestions?

Activity

  1. added this to the future milestone on Apr 21, 2018
  2. apdavison commented on Apr 21, 2018

    @apdavison
    Member

    I support a combination of (A) and (B). In general I prefer adding functionality as new methods on the Neo classes, but by making some of this functionality also accessible as utility functions we improve the discoverability (NumPy does this a lot (e.g. arr.min() and np.min(arr)))

  3. samuelgarcia commented on Apr 23, 2018

    @samuelgarcia
    Contributor

    For this utils functions/methods, I think it could be good to take proxy object in account.

    Here are two possible slicing without/with proxy object.
    Having the same function/method that autodetect proxyobject and do the slicing could be good.
    No ?

    With Standard neo objects

    lim0, lim1 = -500*pq.ms, +1500*pq.ms
    seg = reader.read_segment(lazy=False)
    triggers = seg.events[0]
    anasig = seg.analogsignals[0]  # here anasig contain the whole recording in memory
    all_sig_chunks = []
    for t in triggers.times:
        t0, t1 = (t + lim0), (t + lim1)
        anasig_chunk = anasig.time_slice(t0, t1)
        all_sig_chunks.append(anasig_chunk)
    apply_my_fancy_average(all_sig_chunks)
    

    With proxy neo object

    lim0, lim1 = -500*pq.ms, +1500*pq.ms
    seg = reader.read_segment(lazy=True)
    triggers = seg.events[0].load(time_slice=None)  # this load all trigers in memory
    anasigproxy = seg.analogsignals[0]  # this is a proxy
    all_sig_chunks = []
    for t in triggers.times:
        t0, t1 = (t + lim0), (t + lim1)
        anasig_chunk = anasigproxy.load(time_slice=(t0, t1))  # here real data are loaded
        all_sig_chunks.append(anasig_chunk)
    apply_my_fancy_average(all_sig_chunks)
    
  4. apdavison commented on Oct 22, 2018

    @apdavison
    Member

    @JuliaSprenger what do you think about making a PR to add your
    neo_utils.py to Neo as neo/utils.py?

  5. apdavison commented on Jun 6, 2025

    @apdavison
    Member

    Is it worth revisiting this idea @JuliaSprenger ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions