EdfFile.py
Generic class for Edf files manipulation.
Interface:
===========================
class EdfFile:
__init__(self,FileName)
GetNumImages(self)
def GetData(self,Index, DataType="",Pos=None,Size=None):
GetPixel(self,Index,Position)
GetHeader(self,Index)
GetStaticHeader(self,Index)
WriteImage (self,Header,Data,Append=1,DataType="",WriteAsUnsigened=0,ByteOrder="")
Edf format assumptions:
===========================
The following details were assumed for this implementation:
- Each Edf file contains a certain number of data blocks.
- Each data block represents data stored in an one, two or three-dimensional array.
- Each data block contains a header section, written in ASCII, and a data section of
binary information.
- The size of the header section in bytes is a multiple of 1024. The header is
padded with spaces (0x20). If the header is not padded to a multiple of 1024,
the file is recognized, but the output is always made in this format.
- The header section starts by '{' and finishes by '}'. It is composed by several
pairs 'keyword = value;'. The keywords are case insensitive, but the values are case
sensitive. Each pair is put in a new line (they are separeted by 0x0A). In the
end of each line, a semicolon (;) separes the pair of a comment, not interpreted.
Exemple:
{
; Exemple Header
HeaderID = EH:000001:000000:000000 ; automatically generated
ByteOrder = LowByteFirst ;
DataType = FloatValue ; 4 bytes per pixel
Size = 4000000 ; size of data section
Dim_1= 1000 ; x coordinates
Dim_2 = 1000 ; y coordinates
(padded with spaces to complete 1024 bytes)
}
- There are some fields in the header that are required for this implementation. If any of
these is missing, or inconsistent, it will be generated an error:
Size: Represents size of data block
Dim_1: size of x coordinates (Dim_2 for 2-dimentional images, and also Dim_3 for 3d)
DataType
ByteOrder
- For the written images, these fields are automatically genereted:
Size,Dim_1 (Dim_2 and Dim_3, if necessary), Byte Order, DataType, HeaderID and Image
These fields are called here "static header", and can be retrieved by the method
GetStaticHeader. Other header components are taken by GetHeader. Both methods returns
a dictionary in which the key is the keyword of the pair. When writting an image through
WriteImage method, the Header parameter should not contain the static header information,
which is automatically generated.
- The indexing of images through these functions is based just on the 0-based position in
the file, the header items HeaderID and Image are not considered for referencing the
images.
- The data section contais a number of bytes equal to the value of Size keyword. Data
section is going to be translated into an 1D, 2D or 3D Numpy Array, and accessed
through GetData method call.