Example #1
0
 def test_insertion_of_history(self):
     fn = '/tmp/{}'.format(uuid.uuid4())
     f = EDDHDFFileWriter(fn)
     self.addCleanup(os.remove, f.filename)
     self.assertTrue('history' in f._file.keys())
     self.assertEqual(f._file['history'][0][1], b'mpikat.HDF5Writer')
     f.close()
Example #2
0
    def test_gated_spectrometer_data_insert(self):
        f = EDDHDFFileWriter()
        self.addCleanup(os.remove, f.filename)

        nchannels = 64 * 1024

        data = {}
        for n, d in gated_spectrometer_format(nchannels).items():
            data[n] = np.empty(**d)

        f.newSubscan()
        attr = {'foo': 'bar', 'nu': 3}
        f.addData('mysection', data, attr)
        f.close()

        infile = h5py.File(f.filename, "r")

        self.assertTrue("scan" in infile)
        self.assertTrue("scan/000" in infile)

        dataset = infile["scan/000/mysection"]
        for k in data:
            # Strip NaNs from test
            idx = data[k] == data[k]
            self.assertTrue((data[k] == dataset[k][0])[idx].all())

        self.assertEqual(dataset.attrs['foo'], 'bar')
        self.assertEqual(dataset.attrs['nu'], 3)
Example #3
0
    def test_auto_filename(self):
        f = EDDHDFFileWriter()

        self.assertTrue(f.getFileSize())
        self.addCleanup(os.remove, f.filename)
        f.close()
        self.assertTrue(os.path.exists(f.filename))
Example #4
0
    def test_creation_of_subscans(self):
        fn = '/tmp/{}'.format(uuid.uuid4())
        f = EDDHDFFileWriter(fn)
        self.addCleanup(os.remove, f.filename)

        f.newSubscan()
        f.newSubscan()
        f.close()
        infile = h5py.File(f.filename, "r")
        self.assertEqual(len(infile['scan'].keys()), 2)
Example #5
0
    def measurement_prepare(self, config={}):
        try:
            config = json.loads(config)
        except:
            _log.error("Cannot parse json:\n{}".format(config))
            raise RuntimeError("Cannot parse json.")

        if ("new_file" in config
                and config["new_file"]) or (not self._output_file):
            _log.debug("Creating new file")
            if "file_id" in config:
                file_id = config["file_id"]
            else:
                file_id = None

            if self._config["use_date_based_subfolders"]:
                _log.debug("Using date based subfolders:")

                dirlist = list(os.path.split(self._config["output_directory"]))
                timestamp = datetime.utcnow()
                dirlist.append("{}".format(timestamp.year))
                dirlist.append("{:02}".format(timestamp.month))
                dirlist.append("{:02}".format(timestamp.day))
                path = ""
                for d in dirlist:
                    path = os.path.join(path, d)
                    if not os.path.isdir(path):
                        _log.debug("Creating directory: %s", path)
                        os.mkdir(path)
            else:
                _log.debug("Using flat file hirarchy:")
                path = self._config["output_directory"]

            self._output_file = EDDHDFFileWriter(path=path, file_id_no=file_id)
            self._current_file.set_value(self._output_file.filename)

        if ("override_newsubscan" in config and config["override_newsubscan"]):
            _log.debug("Overriding new subscan creation")
        else:
            _log.debug("Creating new subscan")
            self._output_file.newSubscan()
Example #6
0
 def test_insertion_of_format_version(self):
     fn = '/tmp/{}'.format(uuid.uuid4())
     f = EDDHDFFileWriter(fn)
     self.addCleanup(os.remove, f.filename)
     self.assertTrue('FORMAT_VERSION' in f._file.attrs.keys())
     f.close()
Example #7
0
 def test_manual_filename(self):
     fn = '/tmp/{}'.format(uuid.uuid4())
     f = EDDHDFFileWriter(fn)
     self.addCleanup(os.remove, f.filename)
     f.close()
     self.assertTrue(os.path.exists(f.filename))