def _prepare_environ(self): self.environ = dict() self.environ["startts"] = ts = time.time() self.environ["starttime"] = datetime.datetime.fromtimestamp(ts) self.environ["serialno"] = 0 data_desc = list() data_desc.append( ColumnDesc(name="point_nb", label="#Pt No", dtype="int64")) for i in range(self.nb_of_scalars): data_desc.append( ColumnDesc(name="spectrum%d" % i, label="spectrum%d" % i, dtype="float64")) for i in range(self.nb_of_spectrums): data_desc.append( ColumnDesc(name="spectrum%d" % i, label="spectrum%d" % i, dtype="(float64, )")) for i in range(self.nb_of_images): data_desc.append( ColumnDesc(name="image%d" % i, label="image%d" % i, dtype="((float64, ), )")) data_desc.append( ColumnDesc(name="timestamp", label="dt", dtype="float64")) self.environ["datadesc"] = data_desc self.environ["title"] = DESCRIPTION self.environ["user"] = "******"
def test_dtype_float64(recorder): """Test creation of dataset with float64 data type""" nb_records = 1 # create description of channel data data_desc = [ ColumnDesc(name=COL1_NAME, label=COL1_NAME, dtype="float64", shape=tuple()) ] environ = ENV.copy() environ["datadesc"] = data_desc # simulate sardana scan environ["starttime"] = datetime.now() record_list = RecordList(environ) recorder._startRecordList(record_list) for i in range(nb_records): record = Record({COL1_NAME: 0.1}, i) recorder._writeRecord(record) environ["endtime"] = datetime.now() recorder._endRecordList(record_list) # assert if reading datasets from the sardana file access to the # dataset of the partial files file_ = h5py.File(recorder.filename) for i in range(nb_records): expected_data = 0.1 data = file_["entry0"]["measurement"][COL1_NAME][i] msg = "data does not match" assert data == expected_data, msg
def test_value_ref(recorder): """Test creation of dataset with str data type""" nb_records = 1 # create description of channel data data_desc = [ ColumnDesc(name=COL1_NAME, label=COL1_NAME, dtype="float64", shape=(1024, 1024), value_ref_enabled=True) ] environ = ENV.copy() environ["datadesc"] = data_desc # simulate sardana scan environ["starttime"] = datetime.now() record_list = RecordList(environ) recorder._startRecordList(record_list) for i in range(nb_records): record = Record({COL1_NAME: "file:///tmp/test.edf"}, i) recorder._writeRecord(record) environ["endtime"] = datetime.now() recorder._endRecordList(record_list) # assert if reading datasets from the sardana file access to the # dataset of the partial files file_ = h5py.File(recorder.filename) for i in range(nb_records): expected_data = "file:///tmp/test.edf" try: dataset = file_["entry0"]["measurement"][COL1_NAME].asstr() except AttributeError: # h5py < 3 dataset = file_["entry0"]["measurement"][COL1_NAME] data = dataset[i] msg = "data does not match" assert data == expected_data, msg
def test_dtype_float64(self): """Test creation of dataset with float64 data type""" nb_records = 1 # create description of channel data data_desc = [ ColumnDesc(name=COL1_NAME, label=COL1_NAME, dtype="float64", shape=tuple()) ] self.env["datadesc"] = data_desc # simulate sardana scan recorder = NXscanH5_FileRecorder(filename=self.path) self.env["starttime"] = datetime.now() recorder._startRecordList(self.record_list) for i in range(nb_records): record = Record({COL1_NAME: 0.1}, i) recorder._writeRecord(record) self.env["endtime"] = datetime.now() recorder._endRecordList(self.record_list) # assert if reading datasets from the sardana file access to the # dataset of the partial files file_ = h5py.File(self.path) for i in range(nb_records): expected_data = 0.1 data = file_["entry0"]["measurement"][COL1_NAME][i] msg = "data does not match" self.assertEqual(data, expected_data, msg)
def test_VDS(self): """Test creation of VDS when channel reports URIs (str) of h5file scheme in a simulated sardana scan (3 points). """ try: h5py.VirtualLayout except AttributeError: self.skipTest("VDS not available in this version of h5py") nb_records = 3 # create partial files part_file_name_pattern = "test_vds_part{0}.h5" part_file_paths = [] for i in range(nb_records): path = os.path.join(self.dir_name, part_file_name_pattern.format(i)) part_file_paths.append(path) part_file = h5py.File(path, "w") img = numpy.array([[i, i], [i, i]]) dataset = "dataset" part_file.create_dataset(dataset, data=img) part_file.flush() part_file.close() try: # create description of channel data data_desc = [ ColumnDesc(name=COL1_NAME, label=COL1_NAME, dtype="float64", shape=(2, 2), value_ref_enabled=True) ] self.env["datadesc"] = data_desc # simulate sardana scan recorder = NXscanH5_FileRecorder(filename=self.path) self.env["starttime"] = datetime.now() recorder._startRecordList(self.record_list) for i in range(nb_records): ref = "h5file://" + part_file_paths[i] + "::" + dataset record = Record({COL1_NAME: ref}, i) recorder._writeRecord(record) self.env["endtime"] = datetime.now() recorder._endRecordList(self.record_list) # assert if reading datasets from the sardana file access to the # dataset of the partial files file_ = h5py.File(self.path) for i in range(nb_records): expected_img = numpy.array([[i, i], [i, i]]) img = file_["entry0"]["measurement"][COL1_NAME][i] msg = "VDS extracted image does not match" # TODO: check if this assert works well numpy.testing.assert_array_equal(img, expected_img, msg) finally: # remove partial files for path in part_file_paths: os.remove(path)
def _scan(path, serialno=0): env = ENV.copy() env["serialno"] = serialno record_list = RecordList(env) nb_records = 2 # create description of channel data data_desc = [ ColumnDesc(name=COL1_NAME, label=COL1_NAME, dtype="float64", shape=()) ] env["datadesc"] = data_desc # simulate sardana scan recorder = NXscanH5_FileRecorder(filename=path) env["starttime"] = datetime.now() recorder._startRecordList(record_list) for i in range(nb_records): record = Record({COL1_NAME: 0.1}, i) recorder._writeRecord(record) env["endtime"] = datetime.now() recorder._endRecordList(record_list)