def test_read(): """ Read classifier and moments objects from file, to test data integrity. """ loadpath = '/media/plimley/TEAM 7B/MTbatch01' loadname = 'MultiAngle_MT_100_1.h5' loadfile = os.path.join(loadpath, loadname) clist = trackio.read_object_list_from_hdf5( loadfile, cl.Classifier.from_hdf5, prefix='cl_') momlist = trackio.read_object_list_from_hdf5( loadfile, tm.MomentsReconstruction.from_hdf5, prefix='mom_') return clist, momlist
def test_io(tracks=None): """ """ import etrack.reconstruction.test_moments as tm if tracks is None: tracks = tm.get_tracklist(n_files=1) mom = tm.momentlist_from_tracklist(tracks, fill_nans=False) cl = tm.classifierlist_from_tracklist(tracks, mom) filename = 'testcl.h5' print('Writing classifiers to {}...'.format(filename)) trackio.write_object_list_to_hdf5(filename, cl, prefix='cl_') print('Reading classifiers back...') clread = trackio.read_object_list_from_hdf5( filename, Classifier.from_hdf5, prefix='cl_') print('Checking attributes...') attrs = df.get_format('Classifier') error_ind = [] error_list = [] for i, c in enumerate(clread): if hasattr(c, 'error'): if c.error: error_ind.append(i) error_list.append(c.error) # if there's a track error, which fields are filled, are wonky continue for attr in attrs: if attr.name == 'g4track': continue elif getattr(cl[i], attr.name) is not None: assert getattr(cl[i], attr.name) == getattr(c, attr.name) return error_ind, error_list