예제 #1
0
파일: imaging.py 프로젝트: llerussell/sima
    def export_averages(self, filenames, fmt='TIFF16', scale_values=True):
        """Save TIFF files with the time average of each channel.

        For datasets with multiple frames, the resulting TIFF files
        have multiple pages.

        Parameters
        ----------
        filenames : str or list of str
            A single (.h5) output filename, or a list of (.tif) output
            filenames with one per channel.
        fmt : {'TIFF8', 'TIFF16', 'HDF5'}, optional
            The format of the output files. Defaults to 16-bit TIFF.
        scale_values : bool, optional
            Whether to scale the values to use the full range of the
            output format. Defaults to False.
        """
        if fmt == 'HDF5':
            if not isinstance(filenames, basestring):
                raise ValueError(
                    'A single filename must be passed for HDF5 format.')
        elif not len(filenames) == self.frame_shape[-1]:
            raise ValueError(
                "The number of filenames must equal the number of channels.")
        if fmt == 'HDF5':
            if not h5py_available:
                raise ImportError('h5py >= 2.2.1 required')
            f = h5py.File(filenames, 'w')
            im = self.time_averages
            if scale_values:
                im = sima.misc.to16bit(im)
            else:
                im = im.astype('uint16')
            f.create_dataset(name='time_average', data=im)
            for idx, label in enumerate(['z', 'y', 'x', 'c']):
                f['time_average'].dims[idx].label = label
            if self.channel_names is not None:
                f['time_average'].attrs['channel_names'] = [
                    np.string_(s) for s in self.channel_names
                ]
                # Note: https://github.com/h5py/h5py/issues/289
            f.close()
        else:
            for chan, filename in enumerate(filenames):
                im = self.time_averages[:, :, :, chan]
                if dirname(filename):
                    mkdir_p(dirname(filename))
                if fmt == 'TIFF8':
                    if scale_values:
                        out = sima.misc.to8bit(im)
                    else:
                        out = im.astype('uint8')
                elif fmt == 'TIFF16':
                    if scale_values:
                        out = sima.misc.to16bit(im)
                    else:
                        out = im.astype('uint16')
                else:
                    raise ValueError('Unrecognized format.')
                imsave(filename, out)
예제 #2
0
파일: imaging.py 프로젝트: jacknojunk/sima
    def export_averages(self, filenames, fmt='TIFF16', scale_values=True):
        """Save TIFF files with the time average of each channel.

        For datasets with multiple frames, the resulting TIFF files
        have multiple pages.

        Parameters
        ----------
        filenames : str or list of str
            A single (.h5) output filename, or a list of (.tif) output
            filenames with one per channel.
        fmt : {'TIFF8', 'TIFF16', 'HDF5'}, optional
            The format of the output files. Defaults to 16-bit TIFF.
        scale_values : bool, optional
            Whether to scale the values to use the full range of the
            output format. Defaults to False.
        """
        if fmt == 'HDF5':
            if not isinstance(filenames, basestring):
                raise ValueError(
                    'A single filename must be passed for HDF5 format.')
        elif not len(filenames) == self.frame_shape[-1]:
            raise ValueError(
                "The number of filenames must equal the number of channels.")
        if fmt == 'HDF5':
            if not h5py_available:
                raise ImportError('h5py >= 2.2.1 required')
            f = h5py.File(filenames, 'w')
            im = self.time_averages
            if scale_values:
                im = sima.misc.to16bit(im)
            else:
                im = im.astype('uint16')
            f.create_dataset(name='time_average', data=im)
            for idx, label in enumerate(['z', 'y', 'x', 'c']):
                f['time_average'].dims[idx].label = label
            if self.channel_names is not None:
                f['time_average'].attrs['channel_names'] = [
                    np.string_(s) for s in self.channel_names]
                # Note: https://github.com/h5py/h5py/issues/289
            f.close()
        else:
            for chan, filename in enumerate(filenames):
                im = self.time_averages[:, :, :, chan]
                if dirname(filename):
                    mkdir_p(dirname(filename))
                if fmt == 'TIFF8':
                    if scale_values:
                        out = sima.misc.to8bit(im)
                    else:
                        out = im.astype('uint8')
                elif fmt == 'TIFF16':
                    if scale_values:
                        out = sima.misc.to16bit(im)
                    else:
                        out = im.astype('uint16')
                else:
                    raise ValueError('Unrecognized format.')
                imsave(filename, out)
예제 #3
0
파일: imaging.py 프로젝트: darkmajere/sima
    def export_averages(self, filenames, fmt='TIFF16', scale_values=True):
        """Save TIFF files with the time average of each channel.

        For datasets with multiple frames, the resulting TIFF files
        have multiple pages.

        Parameters
        ----------
        filenames : str or list of str
            A single (.h5) output filename, or a list of (.tif) output
            filenames with one per channel.
        fmt : {'TIFF8', 'TIFF16'}, optional
            The format of the output files. Defaults to 16-bit TIFF.
        scale_values : bool, optional
            Whether to scale the values to use the full range of the
            output format. Defaults to False.
        """
        if fmt == 'HDF5':
            if not isinstance(filenames, str):
                raise ValueError(
                    'A single filename must be passed for HDF5 format.')
        elif not len(filenames) == self.frame_shape[-1]:
            raise ValueError(
                "The number of filenames must equal the number of channels.")
        for chan, filename in enumerate(filenames):
            im = self.time_averages[:, :, :, chan]
            if dirname(filename):
                mkdir_p(dirname(filename))
            if fmt is 'TIFF8':
                if scale_values:
                    out = sima.misc.to8bit(im)
                else:
                    out = im.astype('uint8')
            elif fmt is 'TIFF16':
                if scale_values:
                    out = sima.misc.to16bit(im)
                else:
                    out = im.astype('uint16')
            else:
                raise ValueError('Unrecognized format.')
            imsave(filename, out)