addition of additional data loaders
@@ -8,6 +8,7 @@ import sys
import tempfile
import time
import tarfile
+import pickle
from io import BytesIO
import numpy as np
@@ -64,6 +65,23 @@ def aux_data_loader(fieldname, data_filename, segment, single_point):
raise ValueError('could not read any data for {}'.format(fieldname))
+def npy_data_loader(fieldname, coord_file, segment, single_point):
+ log.debug('using npy_data_loader')
+ data = np.load(coord_file)
+ segment.data[fieldname] = data
+ if data.nbytes == 0:
+ raise ValueError('could not read any data for {}'.format(fieldname))
+
+
+def pickle_data_loader(fieldname, coord_file, segment, single_point):
+ log.debug('using pickle_data_loader')
+ with open(coord_file, 'rb') as fo:
+ data = pickle.load(fo)
+ segment.data[fieldname] = data
+ if data.nbytes == 0:
+ raise ValueError('could not read any data for {}'.format(fieldname))
+
+
def trajectory_loader(fieldname, coord_folder, segment, single_point):
'''Load data from the trajectory return. ``coord_folder`` should be the path to a folder
containing trajectory files. ``segment`` is the ``Segment`` object that the data is associated with.
@@ -259,6 +277,14 @@ class ExecutablePropagator(WESTPropagator):
loader_directive = dsinfo.get('loader')
if loader_directive:
+ if loader_directive == 'default':
+ if dsname not in ['pcoord', 'seglog', 'restart', 'trajectory']:
+ loader = aux_data_loader
+ elif loader_directive == 'npy_loader':
+ loader = npy_data_loader
+ elif loader_directive == 'pickle_loader':
+ loader = pickle_data_loader
+ else:
loader = get_object(loader_directive)
dsinfo['loader'] = loader
elif dsname not in ['pcoord', 'seglog', 'restart', 'trajectory']:
