psychoinformatics-de / ClusteredNetwork_pub

0 stars 1 forks source link

Migrate pickle files to format with better longevity #5

Open mih opened 4 months ago

mih commented 4 months ago
>>> import pandas as pd
>>> df = pd.read_pickle('pickle/joe011_3.pickle')
>>> type(df)
>>> dict
>>> from pprint import pprint
>>> pprint({k: type(v) for k, v in df.items()})
{'column_names': <class 'list'>,
 'event_names': <class 'numpy.ndarray'>,
 'eventtimes': <class 'numpy.ndarray'>,
 'gdf_file': <class 'str'>,
 'spiketimes': <class 'numpy.ndarray'>}

This could be put into npz files: https://numpy.org/doc/stable/reference/generated/numpy.lib.format.html#module-numpy.lib.format

>>> df = pd.read_pickle('pickle/joe011_3.pickle')
>>> numpy.savez('dummy.npz', **df)

>>> npz=numpy.load('dummy.npz')
>>> npz['gdf_file']
array('joe011-345.gdf', dtype='<U14')

>>> npz['gdf_file'].item()
'joe011-345.gdf'

but it can complicate the code in some cases.