You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
set up collection of / extend utility functions #526
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.
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)))
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)
Activity
apdavison commentedon Apr 21, 2018
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)))samuelgarcia commentedon Apr 23, 2018
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
With proxy neo object
apdavison commentedon Oct 22, 2018
@JuliaSprenger what do you think about making a PR to add your
neo_utils.py to Neo as
neo/utils.py?apdavison commentedon Jun 6, 2025
Is it worth revisiting this idea @JuliaSprenger ?