iFit: Saving/exporting objects




Commands we use in this page: iData, saveas, methods

Once you have managed to actually do something, it is desirable to save your work for future use and communication (print, edit, send to friends...). We thus provide a general interface to save the iData objects.

Among the available formats, some retain the integrity of the object (or at least a significant portion of it) - labeled as lossless formats, and some degrade the object information - labeled as lossy formats.

The text based formats are usually easier to read and edit by humans, whereas the binary formats are much more compact in storage but require dedicated libraries for reading/editing.

The only method required for saving objects is saveas(object, filename, format). When the filename is not specified (left empty as ''), a default name is built from the object unique ID (tag). When the filename is set to 'gui', a file selector dialog pops-up. The filename extension defines the format to use, when this latter is not specified initially. Last, when the format is set to 'gui', a format selector dialog pops-up.The save method is equivalent to saveas.
>> a = iData([ ifitpath 'Data/ILL_IN6.dat'])
>> save(a,'','pdf') % save object as a PDF and use object ID as file name
>> save(a,'MakeItSo','hdf5') % save object as a HDF5 into specified filename. Extension is appended automatically
>> saveas(a,'MakeItSo','hdf5') % 'save' is equivalent to 'saveas'

We recommend the following formats for storing data sets:
A short list of available export formats is displayed with:
>> a = saveas(iData, 'formats');
Last, the getframe method generates a snapshot picture (thumbnail). The class2str function can more generally write any Matlab variable as a character string. And the str2struct function can read a character string and search for [name{=: }value] pairs in single lines, to set a return structure.

Conversion to other Matlab types


Convert to
Description
cell(a)
Convert the iData content and field names to cell arrays
char(a)
Assemble Title/Label/Filename into a comprehensive description (does not actually export the data)
double(a)
Extracts the object Signal as a double float array, this is the same as double(a.Signal/a.Monitor)
single(a)
Extracts the object Signal as a single float array, this is the same as single(a.Signal/a.Monitor), and uses less memory than double.
struct(a)
Converts the object to a raw structure. iData methods can not apply on the structure itself. Use iData(structure) to come back to the initial object.
iData(a)
Import an array/structure/cell/file and check iData object structure

Export to lossless formats (retain object)

text based lossless formats

Text files have the advantage that any one can look inside files, and understand what it contains. However, files are usually large as no compression mechanism is applied, natively. However, in some cases, a simple numerical representation can be very compact. And such files can be compressed afterwards with e.g. ZIP.

The last column indicates if the generated format for export can be re-used afterwards and re-imported with iFit.

format (save)
Text/Binary
Lossless
Description
Read?
'm'
Matlab
M-file

text
Yes
The M-file format is a flat text file which reconstructs the whole initial object. It is not easily readable by humans, and does not have any compression mechanism, producing large files. Such files can be imported directly by typing their name from Matlab, even without iFit/iData installed. They can also be edited with any text editor.
Yes
'dat'
flat text file
text
Mostly
The DAT format is a flat text file with numerical blocks preceded with a header and readable comments. It can be edited with any text editor. Can be re-imported with iFit/iData, but axes/alias definitions are not re-generated.
Yes

binary lossless formats

format (save)
Text/Binary
Lossless
Description
Read?
'mat'
Matlab
Mat-file

binary
Yes
The Matlab workspace binary file is compact and fast to read/write. It carries the whole object information. Such files require Matlab (or Octave) to be installed prior to importation. Yes
'hdf5'
HDF 5
binary
Mostly
The HDF5 format is a compact, compressed binary storage format. However, in its use here, it does not reconstruct the whole object, but only its main values and alias/axes names. Such files can be edited/viewed with e.g hdfview, OpenDX. Such files can of course also be imported into iData objects.
Yes
'nc'
NetCDF
binary
Mostly
The NetCDF format is a compact binary format. However, in its use here, it does not reconstruct the whole object, but only its main values and alias/axes names. Such files can be edited/viewed with e.g ncview or ncBrowse. OpenDXhdfview. Such files can of course also be imported into iData objects. Yes

Export to lossy formats

The following formats are mainly intended to be used as object representations. They mostly display/export the object Signal usually weighted by the Monitor, and with axes. No other metadata nor alias is exported. Most of these formats are restricted to flat images (1D and 2D).

format (save)
Text/Binary
Lossless
Description
Read?
'fig' Matlab figure
binary
signal/monitor, with axes The Matlab figure contains the 'visible' part of the object, and can be re-opened/edited from Matlab.
Yes, use openfig, then iData(gcf).
'csv'
Matlab
comma separated values

text
signal only
The comma separated value format is a single dump of the object Signal. The other information is lost. Such files can be imported by e.g. any spreadsheet software (OpenOffice, Excel, Gnumeric), or with iFit/iData. Yes
'hdf4'
HDF 4
image

binary
signal only
The HDF4 format is a compact, binary storage format. However, in its use here, it does not reconstruct the whole object, but only its Signal/Monitor values as an image. Such files can be edited/viewed with e.g hdfview. Such files can of course also be imported into iData objects. IDL and Matlab also have dedicated HDF 4 browsers (see hdftool). Yes
'edf'
EDF ESRF Data format
binary with 512-multiple length text header
signal plus limited metadata
The EDF format is mainly used at the ESRF and can be viewed with e.g. PyMCA, Zimg, GnuPlot, EDFExplorer, Fit2D. This format saves a single image/numeric block plus some metadata in its header.
Yes
'gif' 'bmp' 'png' 'tiff' 'jpeg'

binary
signal only
or signal/monitor
Standard image formats. Can be re-imported with iFit/iData, or used elsewhere (web, email, ...). View with e.g. GIMP, xv.
Yes
'fits'
FITS astronomical image format
binary
signal/monitor,
only for 2D data.
The FITS format is a standard data format used in astronomy. Can be displayed with e.g. GIMP, xv. Yes
'ps' 'eps'
PostScript
text/binary
signal/monitor, with axes
Usual PostScript files. Can be directly printed. Edit/View with Adobe Illustrator, Acrobat Reader, Gnome/Evince, GIMP.
'pdf'
Adobe PDF
binary
signal/monitor, with axes
A portable format for displaying/printing with e.g. Acrobat Reader or Google Chrome, Gnome/Evince, GIMP.
'ill'
Adobe Illustrator
binary
signal/monitor, with axes Similar to PostScript. Files are large. Edit/View with Adobe Illustrator.

'xls'
Excel spreadsheet
binary
signal only
Exports as a single spreadsheet. Requires Excel to be installed. Can be re-imported with iFit/iData. Yes
'svg'
Scalable Vector Graphics
text/binary
signal/monitor, with axes A portable editable vectorial representation of the object. Can be viewed with e.g. Inkscape, GIMP.
'wrl'
Virtual Reality world (VRML)
text
signal/monitor, with axes A portable editable vectorial representation of the object. Can be viewed with e.g Freewrl, Octaga Player, WhiteDune, View3DScene...

'vtk'
Visual ToolKit
text/binary
signal/monitor, with some metadata
A portable vectorial representation of 1D/2D/3D objects. Can be viewed with ParaView and Mayavi2.
'hdr'+'img'
MRI 3D volume
binary (2 files)
signal/monitor, with some metadata A MRI volume data format. The 'hdr' file requires an ssociated 'img' file. Format from the Analyze Biomedical Imaging Resource of the Mayo Clinic. Yes



E. Farhi - iFit/iData saving data -  $Date: 2012-03-05 10:56:28 $ $Revision: 1.20 $ - back to Main iFit Page ILL, Grenoble, France <www.ill.eu>