Differences between revisions 54 and 55
Revision 54 as of 2013-07-11 22:46:28
Size: 11991
Editor: SteveLudtke
Comment:
Revision 55 as of 2013-07-11 22:47:04
Size: 12007
Editor: SteveLudtke
Comment:
Deletions are marked like this. Additions are marked like this.
Line 30: Line 30:
This documentation is preserved mostly for historical reasons as we transition to EMAN2.1, the BDB mechanism is being completely retired, so the information below no longer applies. The documentation below this point is preserved mostly for historical reasons as we transition to EMAN2.1, the BDB mechanism is being completely retired, so the information below no longer applies.

Dealing with image data on disk in EMAN2

EMAN2 supports a variety of mechanisms for dealing with your data on disk. Virtually all cryo-EM file formats are supported as well as some good generic formats. The default format used in EMAN2 processing is HDF5, which supports stacks of 2-D and 3-D images as well as arbitrary header information for each image in the file, but virtually any program can read and write any format transparently.

File Formats

This is a quick summary of SOME supported formats.

For a complete list of supported formats and capabilities see this image formats page.:

HDF5

R/W

MRC/CCP4

R/W

IMAGIC

R/W

SPIDER

R/W

PIF

R/W

ICOS

R/W

VTK

R/W

PGM

R/W

Amira

R/W

Xplor

W

Gatan DM2

R

Gatan DM3

R

Gatan DM4

R

FEI SER

R

TIFF

R/W

Scans-a-lot

R

LST

R/W

PNG

R/W

Video-4-Linux

R

JPEG

W

You can convert files between formats directly from the file browser in e2display.py and e2workflow.py. Just right-click on any valid image file, and select 'save as'.

To convert from one format to another, the e2proc2d.py and e2proc3d.py programs can be used for 2-D and 3-D images respectively. The basic usage e2proc2d.py <infile> <outfile> will simply convert from one file format to another. By default, image type for the output file is recognized by file extension. Both programs also have options for specifying file type when it would otherwise be ambiguous. For 2-D (and sometimes 3-D) stack files, e2proc2d.py operates on all images in the stack by default (see the docs). We also have two options to convert MRC image to short or byte storage types, please refer to this page.

Any program in EMAN should be able to read/write any of the above file formats seamlessly, though each format may have its own limitations. We attempt to preserve as much metadata as possible, but some formats simply aren't very flexible in this regard. The only format supporting EMAN2's full model for associating attributes with individual images is HDF5, which is the format we encourage for general use and file interchange moving forward. This would be considered the default format for EMAN2. Unfortunately, while HDF5 is exceptionally flexible and portable, its performance on large image stacks is substantially worse than the simpler flat-file formats. For this reason, the primary storage mechanism in EMAN2 for internal processing is a BerkeleyDB-based embedded database system.

For those dealing with MRC 'stack' files (a set of 2-D images crammed into a 3-D volume, with no per-image header information): e2proc2d.py has a variety of options that can be used to stack and unstack these images into a proper format which distinguishes between sets of images and 3-D volumes (ie - virtually any other format).


obsolete

The documentation below this point is preserved mostly for historical reasons as we transition to EMAN2.1, the BDB mechanism is being completely retired, so the information below no longer applies.

EMAN2 Embedded Database

In EMAN2, we have converted to a model where most of the image data being processed is stored in an 'embedded database' in the local directory rather than in the traditional MRC/IMAGIC/SPIDER files. When files are added to this local database for the first time, you will see an EMAN2DB directory appear in the local directory. This subdirectory contains all of the image data and header information for an unlimited number of 'virtual files'. Files may still be copied into and out of this database into conventional files, but by storing data internally, we gain a (sometimes substantial) performance benefit, have much more flexibility in how metadata (known as 'header information') is stored, and permit much better tracking of what tasks have been completed on each data item. This idea might take some getting used to, and we hope you will appreciate its elegance once you do.

The files contained in the database directory (EMAN2DB) should never be manipulated by hand. Don't rename or copy files. This could cause errors or data loss. The entire directory can be safely moved from one directory to another, but its contents must not be altered. If you need to extract data for use with another program or somesuch, you MUST use an EMAN2 program to copy the data into a standard disk file. Note that the only standard disk file that supports the full metadata model used in the database system at present is the HDF format. If you want to insure there is no loss of metadata, use the HDF format for this purpose. If you copy a database image to, for example, a SPIDER file, you will lose any metadata which cannot be represented in the SPIDER header.

Using the database with normal EMAN2 programs

Note: It is very important that you not manually rename or edit the files in the EMAN2DB directory. Doing so could corrupt the entire database in such a way that EMAN2 programs will no longer be able to access it properly. You can safely move the directory as a whole to a different location, but otherwise it should not be modified.

You can browse the database using the workflow interface, or by running 'e2display.py' with no arguments, and browsing to the 'bdb' item in any directory. This will show the content of any database, which in some cases may contain only metadata and not images (in most cases they contain image stacks just like a spider or imagic format file).

The database can be accessed by any of the EMAN2 programs. Normally you would specify a file as 'test.hdf' or '/home/stevel/test.hdf'. To access the database, simply specify 'bdb:test' or 'bdb:/home/stevel/data/test'. In the first instance (bdb:test), the named database 'test' will be accessed in the EMAN2DB database in the local directory. Specifying 'bdb:/home/stevel/data/test' will access the database named test in /home/stevel/data/EMAN2DB. Each of the EMAN2DB directories can contain an unlimited number of individual named databases. The EMAN2 GUI interface will provide tools for browsing these databases interactively, and you can find all of their names by listing the 'EMAN2DB/*.bdb' files. Please note that when specifying database names, you don't use the '.bdb' extension. There is more to the database than just the '.bdb' file you see.

For example, say you have a database called 'averages' containing 200 class-averages, and you want to get them out for processing in Spider. Just:

e2proc2d.py bdb:averages averages.spi

and you will end up with a Spider format stack file containing all of the images.

The way you specify an image inside one of these databases is any of:

For a database in the local directory: bdb:dbname

For a database in another directory referenced to the current one: bdb:../local/path#dbname

For a database at an absolute path: bdb:/absolute/path/to/directory#dbname

With a selection list: bdb:dbname?select.selectname

To access keys as a virtual database: bdb:/absolute/path/to/directory#dbname?key,key,key

Important note: If using any URL conaining a '?', you should put the entire specifier in double or single quotes, ie- "bdb:dbname?select.selectname". The '?' character is interpreted by most unix shells as a wildcard character for the filesystem, and not using the quotes could result in errors like "zsh: no matches found: bdb:dbname?select.abc".

The 'select.selectname' mechanism allows you to have a local database named 'select', and each key within that database contains a list of integers to be treated as image numbers in the file. ie bdb:db?select.abc would refer to a database called 'select' with key 'abc' referring to a list of image numbers which would then be dereferenced from 'db'.

The final access method is not very commonly used, but can be quite powerful for specialized purposes. In a typical image stack file, such as SPIDER or IMAGIC format, the individual images are numbered from 0 to n. Say you have a database with 50 images in it, and you want to extract image numbers 0,3,6,10 and 12 from the database. You could do this several ways, including running 5 separate proc2d commands or putting the numbers in a text file and having proc2d use the text file. An alternative would be:

e2proc2d.py bdb:averages?0,3,6,10,12 selected.hed

EMAN2 programs will treat averages?0,3,6,10,12 as if it were actually a database with only 5 images in it, numbered from 0-4: 0=0, 1=3,2=6,3=10,4=12.

The FAQ has a few questions answered which may shed more light on this.

e2bdb.py

e2bdb.py is a utility for examining and interacting with databases from the command-line. e2bdb.py issued with no arguments will show a list of the databases in the current directory (much like ls for regular files). e2bdb.py -l will give details for each database. e2bdb.py -s will return each database name in 'bdb:database' format for use in other commands such as:

foreach i (`e2bdb.py -s`)
e2proc2d.py $i output.spi
end

The --filt and --match options allow you to filter the results of the search, by either doing a substring match (--filt), or full python regular expression matching (--match).

Finally, --makevstack can be used to make a 'virtual' image stack from one or more other stacks. For example e2bdb.py bdb:.#db1 bdb:.#db2 --makevstack=bdb:.#db3 will combine the images in db1 and db2 into db3. However, unlike doing this same task with e2proc2d.py bdb:.#db1 bdb:.#db3; e2proc2d.py bdb:.#db2 bdb:.#db3, the --makevstack option will not actually copy the image data. Instead it creates 'db3' which references the data already stored in 'db1' and 'db2'. If the image data in 'db1' or 'db2' is changed, the corresponding images in 'db3' will also appear to change. However, 'db3' has its own copy of the metadata associated with the image data. That is, if you added an attribute to image 5 in 'db1' : 'fred=25', this attribute would appear only in image 5 in 'db1'. It would not appear in 'db3'. However if you inverted the image contrast in 'db1' : e2proc2d.py bdb:db1 bdb:db1 --inplace --mult=-1, that change WOULD be reflected in 'db3'. Note that if image data is WRITTEN to 'db3', it will NOT overwrite the image data in the original databases ('db1' or 'db2'), but will store the image data in 'db3'. For example, if image 7 were written to 'db3', image 7 in 'db1' would remain unchanged. Future reads of image 7 from 'db3' would read this new data. The reference to 'db1' for that specific image would be broken. However, reading image 6 from 'db3' would still reference image 6 from 'db1'.

Clusters/MPI

Multiple processes/threads on a single machine can safely have the same database open at the same time (reading and writing). The databases (based on BerkeleyDB) support record-level locking. If one process is writing to a record and another process simultaneously tries to read the record, the read operation will block until the write completes. On a single machine the databases coordinate with each other using the database cache in /tmp which MUST be on a locally mounted filesystem (not NFS).

Multiple processes accessing (reading and writing) to a single file from multiple machines on a network-mounted filesystem IS NOT SAFE, and may result in unpredictable errors.

If you are using one of the EMAN2 standard parallelism mechanisms (MPI or distributed processing), all writes are coordinated through a single node. If you are trying to look at a project read-only while, for example, an MPI job is running on another node, you may do so (just be careful not to write anything to the database). Also, unless you run e2bdb.py -c first, you may observe some strange inconsistencies in the files.

Eman2DataStorage (last edited 2022-03-08 23:55:01 by SteveLudtke)