コード例 #1
0
ファイル: helper.py プロジェクト: rhomspuron/sardana
def main():
    data_handler = DataHandler()
    file_name = "/tmp/data_nxs.hdf5"
    nx_recorder = NXscan_FileRecorder(filename=file_name,
                                      macro="dscan", overwrite=True)
    data_handler.addRecorder(nx_recorder)
    scan_dir, scan_file = os.path.split(file_name)
    columns = ['ch1', 'ch2']

    env = createScanDataEnvironment(columns, scan_dir, scan_file)
    scan_data = ScanData(environment=env, data_handler=data_handler)

    data1 = [10.0, [6.0, 3.4]]
    data2 = [10.0, None, None, 5]

    srcs = [
        DummyEventSource(columns[0], scan_data, data1),
        DummyEventSource(columns[1], scan_data, data2)
    ]
    scan_data.start()
    for s in srcs:
        s.start()
    for s in srcs:
        s.join()
    scan_data.end()
    # Test read nxs file
    import nxs
    f = nxs.load(file_name)
    m = f['entry1']['measurement']
    ch1 = m['ch1']
    print ch1.nxdata
コード例 #2
0
def main():
    data_handler = DataHandler()
    file_name = "/tmp/data_nxs.hdf5"
    nx_recorder = NXscan_FileRecorder(filename=file_name,
                                      macro="dscan",
                                      overwrite=True)
    data_handler.addRecorder(nx_recorder)
    scan_dir, scan_file = os.path.split(file_name)
    columns = ['ch1', 'ch2']

    env = createScanDataEnvironment(columns, scan_dir, scan_file)
    scan_data = ScanData(environment=env, data_handler=data_handler)

    data1 = [10.0, [6.0, 3.4]]
    data2 = [10.0, None, None, 5]

    srcs = [
        DummyEventSource(columns[0], scan_data, data1),
        DummyEventSource(columns[1], scan_data, data2)
    ]
    scan_data.start()
    for s in srcs:
        s.start()
    for s in srcs:
        s.join()
    scan_data.end()
    # Test read nxs file
    import nxs
    f = nxs.load(file_name)
    m = f['entry1']['measurement']
    ch1 = m['ch1']
    print(ch1.nxdata)
コード例 #3
0
 def setUp(self):
     """SetUp
     """
     unittest.TestCase.setUp(self)
     self.data_handler = DataHandler()
     self.file_name = "/tmp/data_nxs.hdf5"
     nx_recorder = NXscan_FileRecorder(filename=self.file_name,
                                       macro="dscan",
                                       overwrite=True)
     self.data_handler.addRecorder(nx_recorder)
コード例 #4
0
ファイル: scandata.py プロジェクト: tacaswell/sardana
 def __init__(self,
              environment=None,
              data_handler=None,
              apply_interpolation=False,
              apply_extrapolation=False):
     dh = data_handler or DataHandler()
     RecordList.__init__(self, dh, environment, apply_interpolation,
                         apply_extrapolation)
コード例 #5
0
ファイル: test_recorddata.py プロジェクト: tacaswell/sardana
    def setUp(self):
        """SetUp
        """
        try:
            import nxs
            self.nxs = nxs
        except ImportError:
            self.skipTest("nxs module is not available")
        # In real world addData are always called sequentially.
        # This test was developed assuming that these may arrive in
        # parallel and that addData would protect the critical section, this
        # is no more the case.
        self.skipTest("this test wrongly assumes that data may arrive in "
                      "parallel")

        unittest.TestCase.setUp(self)
        self.data_handler = DataHandler()
        self.file_name = "/tmp/data_nxs.hdf5"
        nx_recorder = NXscan_FileRecorder(filename=self.file_name,
                                          macro="dscan", overwrite=True)
        self.data_handler.addRecorder(nx_recorder)
コード例 #6
0
ファイル: scandata.py プロジェクト: tacaswell/sardana
 def getDataHandler(self):
     return DataHandler()
コード例 #7
0
class ScanDataTestCase(unittest.TestCase):
    """Use ScanData, DataHandler and ScanDataEnvironment in order to record
    data and verify that the stored data in the NeXus file corresponds with
    the initial data that has been sent for storage.
    """
    def setUp(self):
        """SetUp
        """
        try:
            import nxs
            self.nxs = nxs
        except ImportError:
            self.skipTest("nxs module is not available")
        # In real world addData are always called sequentially.
        # This test was developed assuming that these may arrive in
        # parallel and that addData would protect the critical section, this
        # is no more the case.
        self.skipTest("this test wrongly assumes that data may arrive in "
                      "parallel")

        unittest.TestCase.setUp(self)
        self.data_handler = DataHandler()
        self.file_name = "/tmp/data_nxs.hdf5"
        nx_recorder = NXscan_FileRecorder(filename=self.file_name,
                                          macro="dscan",
                                          overwrite=True)
        self.data_handler.addRecorder(nx_recorder)

    def prepareScandData(self, data, apply_interpolation=False):
        scan_dir, scan_file = os.path.split(self.file_name)
        env = createScanDataEnvironment(list(data.keys()), scan_dir, scan_file)
        self.scan_data = ScanData(environment=env,
                                  data_handler=self.data_handler,
                                  apply_interpolation=apply_interpolation)
        self.srcs = []
        self.inputs = {}
        max_len = -1
        for name, dat in list(data.items()):
            des = DummyEventSource(name, self.scan_data, dat, [0] * len(dat))
            self.srcs.append(des)
            input_list = []
            for e in dat:
                if isinstance(e, list):
                    input_list.extend(e)
                else:
                    input_list.append(e)
            self.inputs[name] = input_list
            len_il = len(input_list)
            if max_len < len_il:
                max_len = len_il
        # Pading the list to fill it with float('Nan')
        for name, dat in list(self.inputs.items()):
            diff = max_len - len(dat)
            self.inputs[name] = dat + [float('Nan')] * diff

    def recorddata(self, data, apply_interpolation):
        """Verify that the data sent for storage is equal
           to the actual data present in the created NeXus file.
        """
        self.prepareScandData(data, apply_interpolation)
        # Fill the recoder
        self.scan_data.start()
        for s in self.srcs:
            s.start()
        for s in self.srcs:
            s.join()
        self.scan_data.end()
        # Test the generated nxs file
        f = self.nxs.load(self.file_name)
        m = f['entry1']['measurement']
        for chn in list(data.keys()):
            chn_data = m[chn].nxdata
            # check the data element by element
            for i in range(len(chn_data)):
                msg = ('%s: input data is not equal to stored data. '
                       'Expected: %s , Read: %s' %
                       (chn, self.inputs[chn][i], chn_data[i]))
                if math.isnan(chn_data[i]) and \
                        math.isnan(self.inputs[chn][i]):
                    continue
                self.assertEqual(chn_data[i], self.inputs[chn][i], msg)

    def zeroOrderInterpolation(self, data, apply_interpolation):
        """Verify that the data write in the NeXus file has been
           modified using a zero order interpolation.
        """
        self.prepareScandData(data, apply_interpolation)
        # Fill the recoder
        self.scan_data.start()
        for s in self.srcs:
            s.start()
        for s in self.srcs:
            s.join()
        self.scan_data.end()
        # Test the generated nxs file
        f = self.nxs.load(self.file_name)
        m = f['entry1']['measurement']
        for chn in list(data.keys()):
            chn_data = m[chn].nxdata
            # check the interpolations
            for i in range(len(chn_data)):
                msg = '%s[%s]: has a "Nan" value.' % (chn, i)
                if math.isnan(self.inputs[chn][i]):
                    self.assertFalse(math.isnan(chn_data[i]), msg)
                    if i > 0:
                        msg = ('%s[%s]: data has not been interpolated '
                               'properly. Expected: %s , Read: %s' %
                               (chn, i, chn_data[i], chn_data[i - 1]))
                        self.assertEqual(chn_data[i - 1], chn_data[i], msg)

    def tearDown(self):
        unittest.TestCase.tearDown(self)
コード例 #8
0
 def __init__(self, environment=None, data_handler=None):
     dh = data_handler or DataHandler()
     RecordList.__init__(self, dh, environment)
コード例 #9
0
ファイル: test_recorddata.py プロジェクト: rhomspuron/sardana
class ScanDataTestCase(unittest.TestCase):
    """Use ScanData, DataHandler and ScanDataEnvironment in order to record
    data and verify that the stored data in the NeXus file corresponds with
    the initial data that has been sent for storage.
    """

    def setUp(self):
        """SetUp
        """
        try:
            import nxs
            self.nxs = nxs
        except ImportError:
            self.skipTest("nxs module is not available")
        # In real world addData are always called sequentially.
        # This test was developed assuming that these may arrive in
        # parallel and that addData would protect the critical section, this
        # is no more the case.
        self.skipTest("this test wrongly assumes that data may arrive in "
                      "parallel")

        unittest.TestCase.setUp(self)
        self.data_handler = DataHandler()
        self.file_name = "/tmp/data_nxs.hdf5"
        nx_recorder = NXscan_FileRecorder(filename=self.file_name,
                                          macro="dscan", overwrite=True)
        self.data_handler.addRecorder(nx_recorder)

    def prepareScandData(self, data, apply_interpolation=False):
        scan_dir, scan_file = os.path.split(self.file_name)
        env = createScanDataEnvironment(data.keys(), scan_dir, scan_file)
        self.scan_data = ScanData(environment=env,
                                  data_handler=self.data_handler,
                                  apply_interpolation=apply_interpolation)
        self.srcs = []
        self.inputs = {}
        max_len = -1
        for name, dat in data.items():
            des = DummyEventSource(name, self.scan_data, dat, [0] * len(dat))
            self.srcs.append(des)
            input_list = []
            for e in dat:
                if isinstance(e, list):
                    input_list.extend(e)
                else:
                    input_list.append(e)
            self.inputs[name] = input_list
            len_il = len(input_list)
            if max_len < len_il:
                max_len = len_il
        # Pading the list to fill it with float('Nan')
        for name, dat in self.inputs.items():
            diff = max_len - len(dat)
            self.inputs[name] = dat + [float('Nan')] * diff

    def recorddata(self, data, apply_interpolation):
        """Verify that the data sent for storage is equal
           to the actual data present in the created NeXus file.
        """
        self.prepareScandData(data, apply_interpolation)
        # Fill the recoder
        self.scan_data.start()
        for s in self.srcs:
            s.start()
        for s in self.srcs:
            s.join()
        self.scan_data.end()
        # Test the generated nxs file
        f = self.nxs.load(self.file_name)
        m = f['entry1']['measurement']
        for chn in data.keys():
            chn_data = m[chn].nxdata
            # check the data element by element
            for i in range(len(chn_data)):
                msg = ('%s: input data is not equal to stored data. '
                       'Expected: %s , Read: %s' %
                       (chn, self.inputs[chn][i], chn_data[i]))
                if math.isnan(chn_data[i]) and \
                        math.isnan(self.inputs[chn][i]):
                    continue
                self.assertEqual(chn_data[i], self.inputs[chn][i], msg)

    def zeroOrderInterpolation(self, data, apply_interpolation):
        """Verify that the data write in the NeXus file has been
           modified using a zero order interpolation.
        """
        self.prepareScandData(data, apply_interpolation)
        # Fill the recoder
        self.scan_data.start()
        for s in self.srcs:
            s.start()
        for s in self.srcs:
            s.join()
        self.scan_data.end()
        # Test the generated nxs file
        f = self.nxs.load(self.file_name)
        m = f['entry1']['measurement']
        for chn in data.keys():
            chn_data = m[chn].nxdata
            # check the interpolations
            for i in range(len(chn_data)):
                msg = '%s[%s]: has a "Nan" value.' % (chn, i)
                if math.isnan(self.inputs[chn][i]):
                    self.assertFalse(math.isnan(chn_data[i]), msg)
                    if i > 0:
                        msg = ('%s[%s]: data has not been interpolated '
                               'properly. Expected: %s , Read: %s' %
                               (chn, i, chn_data[i], chn_data[i - 1]))
                        self.assertEqual(chn_data[i - 1], chn_data[i], msg)

    def tearDown(self):
        unittest.TestCase.tearDown(self)