예제 #1
0
def _metadata(path):
    with ser.fileSER(path) as ser1:
        data, metaData = ser1.getDataset(0)  # have to get 1 image and its meta data

        # Add extra meta data from the EMI file if it exists
        if ser1._emi is not None:
            metaData.update(ser1._emi)

    metaData.update(ser1.head)  # some header data for the ser file

    # Clean the dictionary
    for k, v in metaData.items():
        if isinstance(v, bytes):
            metaData[k] = v.decode('UTF8')

    # Store the X and Y pixel size, offset and unit
    try:
        metaData['PhysicalSizeX'] = metaData['Calibration'][0]['CalibrationDelta']
        metaData['PhysicalSizeXOrigin'] = metaData['Calibration'][0]['CalibrationOffset']
        metaData['PhysicalSizeXUnit'] = 'm'  # always meters
        metaData['PhysicalSizeY'] = metaData['Calibration'][1]['CalibrationDelta']
        metaData['PhysicalSizeYOrigin'] = metaData['Calibration'][1]['CalibrationOffset']
        metaData['PhysicalSizeYUnit'] = 'm'  # always meters
    except:
        metaData['PhysicalSizeX'] = 1
        metaData['PhysicalSizeXOrigin'] = 0
        metaData['PhysicalSizeXUnit'] = ''
        metaData['PhysicalSizeY'] = 1
        metaData['PhysicalSizeYOrigin'] = 0
        metaData['PhysicalSizeYUnit'] = ''

    metaData['FileName'] = path

    return metaData
예제 #2
0
    def get_tiles(self, tiling_scheme, dest_dtype="float32", roi=None):
        shape = Shape((1, ) + tuple(self.shape.sig),
                      sig_dims=self.shape.sig.dims)

        self.validate_tiling_scheme(tiling_scheme)

        start = self._start_frame
        stop = start + self._num_frames
        if roi is None:
            indices = np.arange(start, stop)
            offset = start
        else:
            indices = _roi_to_indices(roi, start, stop)
            offset = np.count_nonzero(roi.reshape((-1, ))[:start])

        with fileSER(self._path) as f:
            for num, idx in enumerate(indices):
                tile_slice = Slice(origin=(num + offset, 0, 0), shape=shape)
                data, metadata = f.getDataset(int(idx))
                if data.dtype != np.dtype(dest_dtype):
                    data = data.astype(dest_dtype)
                yield DataTile(
                    data.reshape(shape),
                    tile_slice=tile_slice,
                    scheme_idx=0,
                )
예제 #3
0
def ser_to_png(source_file, dest_file):
    """ Saves the SER source_file as PNG dest_file."""
    emi_file = _discover_emi(source_file)
    f = fileSER(source_file, emi_file)
    ds = f.getDataset(0)
    img = ds[0]
    imsave(dest_file, img, format="png")
    return f
예제 #4
0
 def check_valid(self):
     try:
         with fileSER(self._path, emifile=self._emipath) as f1:
             if f1.head['ValidNumberElements'] == 0:
                 raise DataSetException("no data found in file")
             if f1.head['DataTypeID'] not in (0x4120, 0x4122):
                 raise DataSetException("unknown datatype id: %s" % f1.head['DataTypeID'])
         return True
     except (IOError, OSError) as e:
         raise DataSetException("invalid dataset: %s" % e) from e
예제 #5
0
파일: ser.py 프로젝트: saisunku/LiberTEM
    def get_tiles(self, tiling_scheme, dest_dtype="float32", roi=None):
        sync_offset = self.meta.sync_offset
        shape = Shape((1,) + tuple(self.shape.sig), sig_dims=self.shape.sig.dims)

        self.validate_tiling_scheme(tiling_scheme)

        start = self._start_frame
        if start < self.meta.image_count:
            stop = min(start + self._num_frames, self.meta.image_count)
            if roi is None:
                indices = np.arange(max(0, start), stop)
                # in case of a negative sync_offset, 'start' can be negative
                if start < 0:
                    offset = abs(sync_offset)
                else:
                    offset = start - sync_offset
            else:
                indices = _roi_to_indices(roi, max(0, start), stop, sync_offset)
                # in case of a negative sync_offset, 'start' can be negative
                if start < 0:
                    offset = np.count_nonzero(roi.reshape((-1,))[:abs(sync_offset)])
                else:
                    offset = np.count_nonzero(roi.reshape((-1,))[:start - sync_offset])

            with fileSER(self._path) as f:
                for num, idx in enumerate(indices):
                    origin = (num + offset,) + tuple([0] * self.shape.sig.dims)
                    tile_slice = Slice(origin=origin, shape=shape)
                    data, metadata = f.getDataset(int(idx))
                    if data.dtype != np.dtype(dest_dtype):
                        data = data.astype(dest_dtype)
                    data = data.reshape(shape)
                    self._preprocess(data, tile_slice)
                    yield DataTile(
                        data,
                        tile_slice=tile_slice,
                        scheme_idx=0,
                    )
예제 #6
0
 def _get_handle(self):
     return fileSER(self._path, emifile=self._emipath)
예제 #7
0
파일: ser.py 프로젝트: saisunku/LiberTEM
 def _get_handle(self):
     return fileSER(self._path)
예제 #8
0
def _get_slice(path, t):
    with ser.fileSER(path) as ser_obj:
        return ser_obj.getDataset(t)[0]