Beispiel #1
0
 def test_write(self):
     "Rest writing with self consistency at the fabio level"
     name = os.path.basename(self.cbf_filename)
     obj = cbfimage()
     obj.read(self.cbf_filename)
     obj.write(os.path.join(self.tempdir, name))
     other = cbfimage()
     other.read(os.path.join(self.tempdir, name))
     self.assertEqual(abs(obj.data - other.data).max(), 0, "data are the same")
     for key in obj.header:
         if key in ["filename", "X-Binary-Size-Padding"]:
             continue
         self.assertTrue(key in other.header, "Key %s is in header" % key)
         self.assertEqual(obj.header[key], other.header[key], "value are the same for key %s" % key)
Beispiel #2
0
 def test_write(self):
     "Rest writing with self consistency at the fabio level"
     name = os.path.basename(self.cbf_filename)
     obj = cbfimage()
     obj.read(self.cbf_filename)
     obj.write(os.path.join(self.tempdir, name))
     other = cbfimage()
     other.read(os.path.join(self.tempdir, name))
     self.assertEqual(abs(obj.data - other.data).max(), 0, "data are the same")
     for key in obj.header:
         if key in[ "filename", "X-Binary-Size-Padding"]:
             continue
         self.assertTrue(key in other.header, "Key %s is in header" % key)
         self.assertEqual(obj.header[key], other.header[key], "value are the same for key %s" % key)
Beispiel #3
0
 def test_write(self):
     "Rest writing with self consistency at the fabio level"
     name = os.path.basename(self.cbf_filename)
     obj = cbfimage()
     obj.read(self.cbf_filename)
     obj.write(os.path.join(UtilsTest.tempdir, name))
     other = cbfimage()
     other.read(os.path.join(UtilsTest.tempdir, name))
     self.assertEqual(abs(obj.data - other.data).max(), 0, "data are the same")
     for key in obj.header:
         if key in["filename", "X-Binary-Size-Padding"]:
             continue
         self.assertTrue(key in other.header, "Key %s is in header" % key)
         self.assertEqual(obj.header[key], other.header[key], "value are the same for key %s" % key)
     #By destroying the object, one actually closes the file, which is needed under windows.
     del obj
     del other
     if os.path.exists(os.path.join(UtilsTest.tempdir, name)):
         os.unlink(os.path.join(UtilsTest.tempdir, name))
Beispiel #4
0
 def test_write(self):
     "Rest writing with self consistency at the fabio level"
     name = os.path.basename(self.cbf_filename)
     obj = cbfimage()
     obj.read(self.cbf_filename)
     obj.write(os.path.join(UtilsTest.tempdir, name))
     other = cbfimage()
     other.read(os.path.join(UtilsTest.tempdir, name))
     self.assertEqual(abs(obj.data - other.data).max(), 0, "data are the same")
     for key in obj.header:
         if key in["filename", "X-Binary-Size-Padding"]:
             continue
         self.assertTrue(key in other.header, "Key %s is in header" % key)
         self.assertEqual(obj.header[key], other.header[key], "value are the same for key %s" % key)
     # By destroying the object, one actually closes the file, which is needed under windows.
     del obj
     del other
     if os.path.exists(os.path.join(UtilsTest.tempdir, name)):
         os.unlink(os.path.join(UtilsTest.tempdir, name))
Beispiel #5
0
    def get_hdr(self, path):
        _root, ext = os.path.splitext(path)
        hdr = None

        if ext.lower() == '.cbf':
            cbf_img = cbfimage(fname=path)
            float_data = cbf_img.data.astype(np.float32)
            hdr = cbf_img.header
            parsed_ext_hdr, braggy_hdr = self._parse_header(hdr, float_data)
            hdr['parsed_ext_hdr'] = parsed_ext_hdr
            hdr['braggy_hdr'] = braggy_hdr

        return hdr
Beispiel #6
0
    def preload(self, path):
        cbf_image = cbfimage(fname=path)
        float_data = cbf_image.data.astype(np.float32)
        raw_data = float_data.tobytes()

        preview_data = self._8bit_raw_repr(cbf_image)

        parsed_ext_hdr, braggy_hdr = self._parse_header(cbf_image, float_data)

        img_hdr = {}
        img_hdr['parsed_ext_hdr'] = parsed_ext_hdr
        img_hdr['braggy_hdr'] = braggy_hdr

        return img_hdr, raw_data, preview_data
Beispiel #7
0
    def get_preview_data(self, path):
        cbf_image = cbfimage(fname=path)
        data = self._8bit_raw_repr(cbf_image)

        return data
Beispiel #8
0
    def get_raw_data(self, path, **kwargs):
        cbf_image = cbfimage(fname=path)
        raw_data = cbf_image.data.astype(np.float32).tobytes()

        return raw_data