MPBA / pyphysio

GNU General Public License v3.0
47 stars 13 forks source link

Make Signal and Algorithm pickable #18

Closed andbiz closed 6 years ago

Alebat commented 7 years ago

Could you post a non working example of pickleing-unpickleing?

andbiz commented 7 years ago

The main problem is that currently class attributes (?), e.g. start_time, sampling_freq, are not saved.

Save

import pickle
import pyphysio as ph

ibi = ...
pickle.dump(ibi, open( "ibi.p", "wb" ) )

or:

import pyphysio as ph
ibi.save('ibi.p')

Load

import pickle
import pyphysio as ph

ibi = pickle.load( open( "ibi.p", "rb" ) )

or

import pyphysio as ph
ibi = ph.load_pk('ibi.p')
Alebat commented 7 years ago

Must use sign.p to retrieve something pickleable and Signal.unp(...) to recover the full object

andbiz commented 7 years ago

create a method in Signal, e.g.:

def to_pickle(filename, gzip=True):
    #saves a pickle file (with optional gzip compression)
    if gzip:
        f = gzip.open(filename, mode="wb")
    else:
        f = open(filename, mode="wb")
    pickle.dump(signal.pickleable, f)
    f.close()
    print('saved in: '+os.getcwd())

And analogous from_pickle(filename)

to load a Signal from a pickle file

andbiz commented 7 years ago

Sorry, there is already the method save_pickle... Changed name to to_pickle (develop-andrea)

Alebat commented 7 years ago

Should I also rename load_pickle to from_pickle?