Skip to content

lazy=True in read_XXX and proxy object #406

@samuelgarcia

Description

@samuelgarcia

Now, in read_segment() or read_block() or read_XXX(), lazy=True is use to load an object without its data but with all attributes and annotations.

The main use case is to open a dataset with a small memory footprint. Explore, filter, select some neo object and load a few of them or one by one.

The actual behavior is more or less this one:

reader = MyIO(filename='yep')
block = reader.read_block(lazy=True)

lazy_anasig = block.segments[15].analogsignals[128]
print(lazy_anasig.shape)
#this give (0, )
print(lazy_anasig.lazy_shape)
#this give (100000, 1)

anasig = reader.load_lazy_olbject(lazy_anasig)
print(anasig.shape)
#this give (100000, 1)

All IOs propose lazy=True but very few IOs propose load_lazy_olbject() because it is very hard to implement it (need to keep trace of id object).

Now with rawio, this could be easier to really implement it.
I propose to modify a bit the behavior to a better API.

The idea is to implement proxy object for thoses containing arrays : AnalogSognal, Event, Epoch, SpikeTrain and IrregularlySampledSignal. This obect would keep a link to the reader to be able to load the data when needed in a given time slice.

Example:

reader = MyIO(filename='yep')
block = reader.read_block(lazy=True)

proxy_anasig = block.segments[15].analogsignals[128]
print(proxy_anasig)
# this give ProxyAnalogSignal withh all attributes and annotations
print(proxy_anasig.t_start, proxy_anasig.sampling_rate)
print(proxy_anasig.annotations)

#put signals ion memory
anasig = proxy_anasig.load() 
print(lazy_anasig.shape)
#this give (100000, 1)

#put part of signals ion memory
chunk_anasig = proxy_anasig.load(time_slice=(10*pq.s, 15*pq.s))
print(anasig.shape)
#this give (5000, 1)


...
same idea for spike and events

Any idea on that ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions