Density.to_file#
- Density.to_file(filename, gzip=False)[source]#
Writes class instance to disk.
- Parameters:
- filenamestr
Path to write to.
- gzipbool, optional
Gzip compress the output and add corresponding suffix to filename if not present. False by default.
See also
Notes
If
filename
endswith “.em” or “.h5” a EM file or HDF5 file will be created. The default output format is CCP4/MRC and on failure,skimage.io.imsave
is used.References
Examples
The following creates a
Density
instance dens holding random data values and writes it to disk:>>> import numpy as np >>> from tme import Density >>> data = np.random.rand(50,50,50) >>> dens = Density(data=data, origin=(0, 0, 0), sampling_rate=(1, 1, 1)) >>> dens.to_file("example.mrc")
The output file can also be directly
gzip
compressed. The corresponding “.gz” extension will be automatically added if absent [1].>>> dens.to_file("example.mrc", gzip=True)
The
Density.to_file()
method also supports writing EM files [2]:>>> dens.to_file("example.em")
In addition, a variety of image file formats are supported [3]:
>>> data = np.random.rand(50,50) >>> dens = Density(data=data, origin=(0, 0), sampling_rate=(1, 1)) >>> dens.to_file("example.tiff")