source: trunk/ReadMarCCDFrame.py @ 905

Last change on this file since 905 was 905, checked in by vondreele, 9 years ago

new MAR CCD reader
testDeriv.py is new - old testGSASIIstruct.py deleted
fixes to SC derivatives - refine on F now OK; extinction messed up, RB still a problem

File size: 29.4 KB
Line 
1#!/usr/bin/env python
2# ReadMarCCDFrame.py
3"""
4  from /opt/marccd/documentation/header.txt
5
6   MarCCD Header Documentataion
7
8   from C code in frame.h  and types.h
9
10   Documentation updated by R. Doyle Mon Mar 22 15:04:00 CDT 2010
11   Documentation updated by M. Blum Tue Oct 11 11:49:20 CDT 2005
12
13   Description documents marccd v0.20.0
14
15
16   Summary of file structure:
17   |-- 1024 bytes TIFF HEADER -------------|
18   |-- 3072 byte frame_header structure ---|
19   |-- nfast*nslow*depth byte image -------|
20
21   The full header, as written to the file, is a TIFF header.
22   The initial 1024 bytes are a minimal TIFF header with a standard
23   TIFF TAG pointing to the image data and a private TIFF TAG
24   pointing to this header structure.  As written by mmx/marccd, the
25   frame_header structure always begins at byte 1024 and is 3072 bytes long
26   making the full header 4096 bytes.
27
28   immediately following the header is the image - it is of arbitrary size defined
29   by the header fields nfast, nslow and depth. The total size is
30   nfast * nslow * depth bytes.
31
32   The meanings of the data types should be self evident:
33   (example:  UINT32 is an unsigned 32 bit integer)
34   The exact C language definition is machine dependent but these
35   are the most common definitions on a 32bit architecture cpu.
36#define UINT16  unsigned short
37#define INT16   short
38#define UINT32  unsigned int
39#define INT32   int
40
41   Currently frames are always written as defined below:
42         origin=UPPER_LEFT
43         orientation=HFAST
44         view_direction=FROM_SOURCE
45
46
47/* This number is  written into the byte_order fields in the
48   native byte order of the machine writing the file */
49#define LITTLE_ENDIAN   1234
50#define BIG_ENDIAN      4321
51
52/* possible orientations of frame data (stored in orienation field) */
53#define HFAST                   0        /* Horizontal axis is fast */
54#define VFAST                   1        /* Vertical axis is fast */
55
56/* possible origins of frame data (stored in origin field) */
57#define UPPER_LEFT              0
58#define LOWER_LEFT              1
59#define UPPER_RIGHT             2
60#define LOWER_RIGHT             3
61
62/* possible view directions of frame data for
63   the given orientation and origin (stored in view_direction field) */
64#define FROM_SOURCE             0
65#define TOWARD_SOURCE           1
66
67/* possible types of data (in data_type field) */
68#define DATA_UNSIGNED_INTEGER   0
69#define DATA_SIGNED_INTEGER     1
70#define DATA_FLOAT              2
71
72#define MAXIMAGES 9
73#define MAXSUBIMAGES 4096
74#define MAXFRAMEDIMENSION       8192
75
76typedef struct frame_header_type {
77        /* File/header format parameters (256 bytes) */
78        UINT32        header_type;      /* flag for header type  (can be used as magic number) */
79        char header_name[16];           /* header name (MARCCD) */
80        UINT32        header_major_version;     /* header_major_version (n.) */
81        UINT32        header_minor_version;     /* header_minor_version (.n) */
82        UINT32        header_byte_order;/* BIG_ENDIAN (Motorola,MIPS); LITTLE_ENDIAN (DEC, Intel) */
83        UINT32        data_byte_order;  /* BIG_ENDIAN (Motorola,MIPS); LITTLE_ENDIAN (DEC, Intel) */
84        UINT32        header_size;      /* in bytes                     */
85        UINT32        frame_type;       /* flag for frame type */
86        UINT32        magic_number;     /* to be used as a flag - usually to indicate new file */
87        UINT32        compression_type; /* type of image compression    */
88        UINT32        compression1;     /* compression parameter 1 */
89        UINT32        compression2;     /* compression parameter 2 */
90        UINT32        compression3;     /* compression parameter 3 */
91        UINT32        compression4;     /* compression parameter 4 */
92        UINT32        compression5;     /* compression parameter 4 */
93        UINT32        compression6;     /* compression parameter 4 */
94        UINT32        nheaders;         /* total number of headers      */
95        UINT32        nfast;            /* number of pixels in one line */
96        UINT32        nslow;            /* number of lines in image     */
97        UINT32        depth;            /* number of bytes per pixel    */
98        UINT32        record_length;    /* number of pixels between succesive rows */
99        UINT32        signif_bits;      /* true depth of data, in bits  */
100        UINT32        data_type;        /* (signed,unsigned,float...) */
101        UINT32        saturated_value;  /* value marks pixel as saturated */
102        UINT32        sequence;         /* TRUE or FALSE */
103        UINT32        nimages;          /* total number of images - size of each is nfast*(nslow/nimages) */
104        UINT32        origin;           /* corner of origin             */
105        UINT32        orientation;      /* direction of fast axis       */
106        UINT32        view_direction;   /* direction to view frame      */
107        UINT32        overflow_location;/* FOLLOWING_HEADER, FOLLOWING_DATA */
108        UINT32        over_8_bits;      /* # of pixels with counts > 255 */
109        UINT32        over_16_bits;     /* # of pixels with count > 65535 */
110        UINT32        multiplexed;      /* multiplex flag */
111        UINT32        nfastimages;      /* # of images in fast direction */
112        UINT32        nslowimages;      /* # of images in slow direction */
113        UINT32        darkcurrent_applied; /* flags correction has been applied - hold magic number ? */
114        UINT32        bias_applied;       /* flags correction has been applied - hold magic number ? */
115        UINT32        flatfield_applied;  /* flags correction has been applied - hold magic number ? */
116        UINT32        distortion_applied; /* flags correction has been applied - hold magic number ? */
117        UINT32        original_header_type;     /* Header/frame type from file that frame is read from */
118        UINT32        file_saved;         /* Flag that file has been saved, should be zeroed if modified */
119        UINT32        n_valid_pixels;     /* Number of pixels holding valid data - first N pixels */
120        UINT32        defectmap_applied; /* flags correction has been applied - hold magic number ? */
121        UINT32        subimage_nfast;       /* when divided into subimages (eg. frameshifted) */
122        UINT32        subimage_nslow;       /* when divided into subimages (eg. frameshifted) */
123        UINT32        subimage_origin_fast; /* when divided into subimages (eg. frameshifted) */
124        UINT32        subimage_origin_slow; /* when divided into subimages (eg. frameshifted) */
125        UINT32        readout_pattern;      /* BIT Code - 1 = A, 2 = B, 4 = C, 8 = D */
126        UINT32        saturation_level;     /* at this value and above, data are not reliable */
127        UINT32        orientation_code;     /* Describes how this frame needs to be rotated to make it "right" */
128        UINT32        frameshift_multiplexed;  /* frameshift multiplex flag */
129        UINT32        prescan_nfast;            /* Number of non-image pixels preceeding imaging pixels - fast direction */
130        UINT32        prescan_nslow;            /* Number of non-image pixels preceeding imaging pixels - slow direction */
131        UINT32        postscan_nfast;           /* Number of non-image pixels followng imaging pixels - fast direction */
132        UINT32        postscan_nslow;           /* Number of non-image pixels followng imaging pixels - slow direction */
133        UINT32        prepost_trimmed;          /* trimmed==1 means pre and post scan pixels have been removed */
134        char reserve1[(64-55)*sizeof(INT32)-16];
135
136        /* Data statistics (128) */
137        UINT32        total_counts[2];  /* 64 bit integer range = 1.85E19*/
138        UINT32        special_counts1[2];
139        UINT32        special_counts2[2];
140        UINT32        min;
141        UINT32        max;
142        INT32        mean;                      /* mean * 1000 */
143        UINT32        rms;                      /* rms * 1000 */
144        UINT32        n_zeros;                  /* number of pixels with 0 value  - not included in stats in unsigned data */
145        UINT32        n_saturated;              /* number of pixels with saturated value - not included in stats */
146        UINT32        stats_uptodate;           /* Flag that stats OK - ie data not changed since last calculation */
147        UINT32        pixel_noise[MAXIMAGES];           /* 1000*base noise value (ADUs) */
148        char reserve2[(32-13-MAXIMAGES)*sizeof(INT32)];
149
150        /* Sample Changer info */
151        char          barcode[16];
152        UINT32        barcode_angle;
153        UINT32        barcode_status;
154        /* Pad to 256 bytes */
155        char reserve2a[(64-6)*sizeof(INT32)];
156
157        /* Goniostat parameters (128 bytes) */
158        INT32 xtal_to_detector;         /* 1000*distance in millimeters */
159        INT32 beam_x;                   /* 1000*x beam position (pixels) */
160        INT32 beam_y;                   /* 1000*y beam position (pixels) */
161        INT32 integration_time;         /* integration time in milliseconds */
162        INT32 exposure_time;            /* exposure time in milliseconds */
163        INT32 readout_time;             /* readout time in milliseconds */
164        INT32 nreads;                   /* number of readouts to get this image */
165        INT32 start_twotheta;           /* 1000*two_theta angle */
166        INT32 start_omega;              /* 1000*omega angle */
167        INT32 start_chi;                        /* 1000*chi angle */
168        INT32 start_kappa;              /* 1000*kappa angle */
169        INT32 start_phi;                        /* 1000*phi angle */
170        INT32 start_delta;              /* 1000*delta angle */
171        INT32 start_gamma;              /* 1000*gamma angle */
172        INT32 start_xtal_to_detector;   /* 1000*distance in mm (dist in um)*/
173        INT32 end_twotheta;             /* 1000*two_theta angle */
174        INT32 end_omega;                        /* 1000*omega angle */
175        INT32 end_chi;                  /* 1000*chi angle */
176        INT32 end_kappa;                        /* 1000*kappa angle */
177        INT32 end_phi;                  /* 1000*phi angle */
178        INT32 end_delta;                        /* 1000*delta angle */
179        INT32 end_gamma;                        /* 1000*gamma angle */
180        INT32 end_xtal_to_detector;     /* 1000*distance in mm (dist in um)*/
181        INT32 rotation_axis;            /* active rotation axis (index into above ie. 0=twotheta,1=omega...) */
182        INT32 rotation_range;           /* 1000*rotation angle */
183        INT32 detector_rotx;            /* 1000*rotation of detector around X */
184        INT32 detector_roty;            /* 1000*rotation of detector around Y */
185        INT32 detector_rotz;            /* 1000*rotation of detector around Z */
186        INT32 total_dose;               /* Hz-sec (counts) integrated over full exposure */
187        char reserve3[(32-29)*sizeof(INT32)]; /* Pad Gonisotat parameters to 128 bytes */
188
189        /* Detector parameters (128 bytes) */
190        INT32 detector_type;            /* detector type */
191        INT32 pixelsize_x;              /* pixel size (nanometers) */
192        INT32 pixelsize_y;              /* pixel size (nanometers) */
193        INT32 mean_bias;                        /* 1000*mean bias value */
194        INT32 photons_per_100adu;       /* photons / 100 ADUs */
195        INT32 measured_bias[MAXIMAGES]; /* 1000*mean bias value for each image*/
196        INT32 measured_temperature[MAXIMAGES];  /* Temperature of each detector in milliKelvins */
197        INT32 measured_pressure[MAXIMAGES];     /* Pressure of each chamber in microTorr */
198        /* Retired reserve4 when MAXIMAGES set to 9 from 16 and two fields removed, and temp and pressure added
199        char reserve4[(32-(5+3*MAXIMAGES))*sizeof(INT32)];
200        */
201
202        /* X-ray source and optics parameters (128 bytes) */
203        /* X-ray source parameters (14*4 bytes) */
204        INT32 source_type;              /* (code) - target, synch. etc */
205        INT32 source_dx;                        /* Optics param. - (size microns) */
206        INT32 source_dy;                        /* Optics param. - (size microns) */
207        INT32 source_wavelength;                /* wavelength (femtoMeters) */
208        INT32 source_power;             /* (Watts) */
209        INT32 source_voltage;           /* (Volts) */
210        INT32 source_current;           /* (microAmps) */
211        INT32 source_bias;              /* (Volts) */
212        INT32 source_polarization_x;    /* () */
213        INT32 source_polarization_y;    /* () */
214        INT32 source_intensity_0;       /* (arbitrary units) */
215        INT32 source_intensity_1;       /* (arbitrary units) */
216        char reserve_source[2*sizeof(INT32)];
217
218        /* X-ray optics_parameters (8*4 bytes) */
219        INT32 optics_type;              /* Optics type (code)*/
220        INT32 optics_dx;                        /* Optics param. - (size microns) */
221        INT32 optics_dy;                        /* Optics param. - (size microns) */
222        INT32 optics_wavelength;                /* Optics param. - (size microns) */
223        INT32 optics_dispersion;                /* Optics param. - (*10E6) */
224        INT32 optics_crossfire_x;       /* Optics param. - (microRadians) */
225        INT32 optics_crossfire_y;       /* Optics param. - (microRadians) */
226        INT32 optics_angle;             /* Optics param. - (monoch. 2theta - microradians) */
227        INT32 optics_polarization_x;    /* () */
228        INT32 optics_polarization_y;    /* () */
229        char reserve_optics[4*sizeof(INT32)];
230
231        char reserve5[((32-28)*sizeof(INT32))]; /* Pad X-ray parameters to 128 bytes */
232
233        /* File parameters (1024 bytes) */
234        char filetitle[128];            /* Title                                */
235        char filepath[128];             /* path name for data file              */
236        char filename[64];              /* name of data file                    */
237        char acquire_timestamp[32];     /* date and time of acquisition         */
238        char header_timestamp[32];      /* date and time of header update       */
239        char save_timestamp[32];        /* date and time file saved             */
240        char file_comment[512]; /* comments  - can be used as desired   */
241        char reserve6[1024-(128+128+64+(3*32)+512)]; /* Pad File parameters to 1024 bytes */
242
243        /* Dataset parameters (512 bytes) */
244        char dataset_comment[512];      /* comments  - can be used as desired   */
245
246        /* Reserved for user definable data - will not be used by Mar! */
247        char user_data[512];
248
249        /* char pad[----] USED UP! */     /* pad out to 3072 bytes */
250
251        } frame_header;
252"""
253
254import struct as st
255import array as ar
256import string, re
257
258MAXIMAGES=9
259
260class marFrame():
261    '''A class to extract correct mar header and image info from a MarCCD file'''
262
263    def __init__(self,File,byteOrd='<',IFD={}):
264        # simple TIFF header info
265        self.TIFFsizeX = IFD[256][2][0]
266        self.TIFFsizeY = IFD[257][2][0]
267        self.TIFFbitDepth = IFD[258][2][0]
268        self.TIFFcompression = IFD[259][2][0] # 1 = no compression
269        self.TIFFphotometricInterpretation = IFD[262][2][0] # 1 = bilevel or grayscale where 0 is imaged as black
270        self.TIFFstripOffsets = IFD[273][2][0] # seems to be 4096 for marCCD
271        self.TIFForientation = IFD[274][2][0] # 1 = 0th row it top, 0th column is left
272        self.TIFFrowsPerStrip = IFD[278][2][0] # varies based on image size
273        self.TIFFstripByteCounts = IFD[279][2][0] # number of bytes in a strip also varies based on size
274        self.TIFFxResolution = IFD[282][2][0] # pixels per resolutionUnit in X direction (ImageWidth direction)
275        self.TIFFyResolution = IFD[283][2][0] # pixels per resolutionUnit in Y direction (ImageLength direction
276        self.TIFFresolutionUnit = IFD[296][2][0] # 3 = centimeter
277        self.byteDepth = self.TIFFbitDepth/8
278        self.arrayTypeCode = ['','B','H','L'][self.byteDepth]
279        # MarCCD specific header info
280        File.seek(IFD[34710][2][0])
281        self.headerType = st.unpack(byteOrd+'I',File.read(4))[0] #/* flag for header type  (can be used as magic number) */
282        self.headerName = re.sub(r'\x00','',string.join(st.unpack(byteOrd+16*'c',File.read(16)),''))
283        self.headerMajorVersion = st.unpack(byteOrd+'I',File.read(4))[0] #/* header_major_version (n.) */
284        self.headerMinorVersion = st.unpack(byteOrd+'I',File.read(4))[0] #/* header_minor_version (.n) */
285        self.headerByteOrder = st.unpack(byteOrd+'I',File.read(4))[0] #/* BIG_ENDIAN (Motorola,MIPS); LITTLE_ENDIAN (DEC, Intel) */
286        self.dataByteOrder = st.unpack(byteOrd+'I',File.read(4))[0] #/* BIG_ENDIAN (Motorola,MIPS); LITTLE_ENDIAN (DEC, Intel) */
287        self.headerSize = st.unpack(byteOrd+'I',File.read(4))[0] #/* in bytes                   */
288        self.frameType = st.unpack(byteOrd+'I',File.read(4))[0] #/* flag for frame type */
289        self.magicNumber = st.unpack(byteOrd+'I',File.read(4))[0] #/* to be used as a flag - usually to indicate new file */
290        self.compressionType = st.unpack(byteOrd+'I',File.read(4))[0] #/* type of image compression    */
291        self.compression1 = st.unpack(byteOrd+'I',File.read(4))[0] #/* compression parameter 1 */
292        self.compression2 = st.unpack(byteOrd+'I',File.read(4))[0] #/* compression parameter 2 */
293        self.compression3 = st.unpack(byteOrd+'I',File.read(4))[0] #/* compression parameter 3 */
294        self.compression4 = st.unpack(byteOrd+'I',File.read(4))[0] #/* compression parameter 4 */
295        self.compression5 = st.unpack(byteOrd+'I',File.read(4))[0] #/* compression parameter 4 */
296        self.compression6 = st.unpack(byteOrd+'I',File.read(4))[0] #/* compression parameter 4 */
297        self.nheaders = st.unpack(byteOrd+'I',File.read(4))[0] #/* total number of headers      */
298        self.nfast = st.unpack(byteOrd+'I',File.read(4))[0] #/* number of pixels in one line */
299        self.nslow = st.unpack(byteOrd+'I',File.read(4))[0] #/* number of lines in image     */
300        self.depth = st.unpack(byteOrd+'I',File.read(4))[0] #/* number of bytes per pixel    */
301        self.recordLength = st.unpack(byteOrd+'I',File.read(4))[0] #/* number of pixels between succesive rows */
302        self.signifBits = st.unpack(byteOrd+'I',File.read(4))[0] #/* true depth of data, in bits  */
303        self.dataType = st.unpack(byteOrd+'I',File.read(4))[0] #/* (signed,unsigned,float...) */
304        self.saturatedValue = st.unpack(byteOrd+'I',File.read(4))[0] #/* value marks pixel as saturated */
305        self.sequence = st.unpack(byteOrd+'I',File.read(4))[0] #/* TRUE or FALSE */
306        self.nimages = st.unpack(byteOrd+'I',File.read(4))[0] #/* total number of images - size of each is nfast*(nslow/nimages) */
307        self.origin = st.unpack(byteOrd+'I',File.read(4))[0] #/* corner of origin               */
308        self.orientation = st.unpack(byteOrd+'I',File.read(4))[0] #/* direction of fast axis    */
309        self.viewDirection = st.unpack(byteOrd+'I',File.read(4))[0] #/* direction to view frame      */
310        self.overflowLocation = st.unpack(byteOrd+'I',File.read(4))[0] #/* FOLLOWING_HEADER, FOLLOWING_DATA */
311        self.over8Bits = st.unpack(byteOrd+'I',File.read(4))[0] #/* # of pixels with counts > 255 */
312        self.over16Bits = st.unpack(byteOrd+'I',File.read(4))[0] #/* # of pixels with count > 65535 */
313        self.multiplexed = st.unpack(byteOrd+'I',File.read(4))[0] #/* multiplex flag */
314        self.nfastimages = st.unpack(byteOrd+'I',File.read(4))[0] #/* # of images in fast direction */
315        self.nslowimages = st.unpack(byteOrd+'I',File.read(4))[0] #/* # of images in slow direction */
316        self.darkcurrentApplied = st.unpack(byteOrd+'I',File.read(4))[0] #/* flags correction has been applied - hold magic number ? */
317        self.biasApplied = st.unpack(byteOrd+'I',File.read(4))[0] #/* flags correction has been applied - hold magic number ? */
318        self.flatfieldApplied = st.unpack(byteOrd+'I',File.read(4))[0] #/* flags correction has been applied - hold magic number ? */
319        self.distortionApplied = st.unpack(byteOrd+'I',File.read(4))[0] #/* flags correction has been applied - hold magic number ? */
320        self.originalHeaderType = st.unpack(byteOrd+'I',File.read(4))[0] #/* Header/frame type from file that frame is read from */
321        self.fileSaved = st.unpack(byteOrd+'I',File.read(4))[0] #/* Flag that file has been saved, should be zeroed if modified */
322        self.nValidPixels = st.unpack(byteOrd+'I',File.read(4))[0] #/* Number of pixels holding valid data - first N pixels */
323        self.defectmapApplied = st.unpack(byteOrd+'I',File.read(4))[0] #/* flags correction has been applied - hold magic number ? */
324        self.subimageNfast = st.unpack(byteOrd+'I',File.read(4))[0] #/* when divided into subimages (eg. frameshifted) */
325        self.subimageNslow = st.unpack(byteOrd+'I',File.read(4))[0] #/* when divided into subimages (eg. frameshifted) */
326        self.subimageOriginFast = st.unpack(byteOrd+'I',File.read(4))[0] #/* when divided into subimages (eg. frameshifted) */
327        self.subimageOriginSlow = st.unpack(byteOrd+'I',File.read(4))[0] #/* when divided into subimages (eg. frameshifted) */
328        self.readoutPattern = st.unpack(byteOrd+'I',File.read(4))[0] #/* BIT Code - 1 = A, 2 = B, 4 = C, 8 = D */
329        self.saturationLevel = st.unpack(byteOrd+'I',File.read(4))[0] #/* at this value and above, data are not reliable */
330        self.orientationCode = st.unpack(byteOrd+'I',File.read(4))[0] #/* Describes how this frame needs to be rotated to make it "right" */
331        self.frameshiftMultiplexed = st.unpack(byteOrd+'I',File.read(4))[0] #/* frameshift multiplex flag */
332        self.prescanNfast = st.unpack(byteOrd+'I',File.read(4))[0] #/* Number of non-image pixels preceeding imaging pixels - fast direction */
333        self.prescanNslow = st.unpack(byteOrd+'I',File.read(4))[0] #/* Number of non-image pixels preceeding imaging pixels - slow direction */
334        self.postscanNfast = st.unpack(byteOrd+'I',File.read(4))[0] #/* Number of non-image pixels followng imaging pixels - fast direction */
335        self.postscanNslow = st.unpack(byteOrd+'I',File.read(4))[0] #/* Number of non-image pixels followng imaging pixels - slow direction */
336        self.prepostTrimmed = st.unpack(byteOrd+'I',File.read(4))[0] #/* trimmed==1 means pre and post scan pixels have been removed */
337
338        File.seek(IFD[34710][2][0]+256)
339        #self.totalCounts = st.unpack(byteOrd+'Q',File.read(8))[0] # /* 64 bit integer range = 1.85E19*/
340        #self.specialCounts1 = st.unpack(byteOrd+'Q',File.read(8))[0]
341        #self.specialCounts2 = st.unpack(byteOrd+'Q',File.read(8))[0]
342        self.totalCounts = st.unpack(byteOrd+'II',File.read(8))
343        self.specialCounts1 = st.unpack(byteOrd+'II',File.read(8))
344        self.specialCounts2 = st.unpack(byteOrd+'II',File.read(8))
345        self.min = st.unpack(byteOrd+'I',File.read(4))[0]
346        self.max = st.unpack(byteOrd+'I',File.read(4))[0]
347        self.mean = st.unpack(byteOrd+'i',File.read(4))[0] # /* mean * 1000 */
348        self.rms = st.unpack(byteOrd+'I',File.read(4))[0] #/* rms * 1000 */
349        self.nZeros = st.unpack(byteOrd+'I',File.read(4))[0] #/* number of pixels with 0 value  - not included in stats in unsigned data */
350        self.nSaturated = st.unpack(byteOrd+'I',File.read(4))[0] #/* number of pixels with saturated value - not included in stats */
351        self.statsUptodate = st.unpack(byteOrd+'I',File.read(4))[0] #/* Flag that stats OK - ie data not changed since last calculation */
352        self.pixelNoise = st.unpack(byteOrd+'I'*MAXIMAGES,File.read(4*MAXIMAGES)) # /* 1000*base noise value (ADUs) */
353
354        File.seek(IFD[34710][2][0]+256+128)
355        self.barcode = re.sub(r'\x00','',string.join(st.unpack(byteOrd+16*'c',File.read(16)),''))
356        self.barcodeAngle = st.unpack(byteOrd+'I',File.read(4))[0]
357        self.barcodeStatus = st.unpack(byteOrd+'I',File.read(4))[0]
358
359        File.seek(IFD[34710][2][0]+256+128+256)
360        self.xtalToDetector = st.unpack(byteOrd+'i',File.read(4))[0] #/* 1000*distance in millimeters */
361        self.beamX = st.unpack(byteOrd+'i',File.read(4))[0] #/* 1000*x beam position (pixels) */
362        self.beamY = st.unpack(byteOrd+'i',File.read(4))[0] #/* 1000*y beam position (pixels) */
363        self.integrationTime = st.unpack(byteOrd+'i',File.read(4))[0] #/* integration time in milliseconds */
364        self.exposureTime = st.unpack(byteOrd+'i',File.read(4))[0] #/* exposure time in milliseconds */
365        self.readoutTime = st.unpack(byteOrd+'i',File.read(4))[0] #/* readout time in milliseconds */
366        self.nreads = st.unpack(byteOrd+'i',File.read(4))[0] #/* number of readouts to get this image */
367        self.startTwotheta = st.unpack(byteOrd+'i',File.read(4))[0] #/* 1000*two_theta angle */
368        self.startOmega = st.unpack(byteOrd+'i',File.read(4))[0] #/* 1000*omega angle */
369        self.startChi = st.unpack(byteOrd+'i',File.read(4))[0] #/* 1000*chi angle */
370        self.startKappa = st.unpack(byteOrd+'i',File.read(4))[0] #/* 1000*kappa angle */
371        self.startPhi = st.unpack(byteOrd+'i',File.read(4))[0] #/* 1000*phi angle */
372        self.startDelta = st.unpack(byteOrd+'i',File.read(4))[0] #/* 1000*delta angle */
373        self.startGamma = st.unpack(byteOrd+'i',File.read(4))[0] #/* 1000*gamma angle */
374        self.startXtalToDetector = st.unpack(byteOrd+'i',File.read(4))[0] #/* 1000*distance in mm (dist in um)*/
375        self.endTwotheta = st.unpack(byteOrd+'i',File.read(4))[0] #/* 1000*two_theta angle */
376        self.endOmega = st.unpack(byteOrd+'i',File.read(4))[0] #/* 1000*omega angle */
377        self.endChi = st.unpack(byteOrd+'i',File.read(4))[0] #/* 1000*chi angle */
378        self.endKappa = st.unpack(byteOrd+'i',File.read(4))[0] #/* 1000*kappa angle */
379        self.endPhi = st.unpack(byteOrd+'i',File.read(4))[0] #/* 1000*phi angle */
380        self.endDelta = st.unpack(byteOrd+'i',File.read(4))[0] #/* 1000*delta angle */
381        self.endGamma = st.unpack(byteOrd+'i',File.read(4))[0] #/* 1000*gamma angle */
382        self.endXtalToDetector = st.unpack(byteOrd+'i',File.read(4))[0] #/* 1000*distance in mm (dist in um)*/
383        self.rotationAxis = st.unpack(byteOrd+'i',File.read(4))[0] #/* active rotation axis (index into above ie. 0=twotheta,1=omega...) */
384        self.rotationRange = st.unpack(byteOrd+'i',File.read(4))[0] #/* 1000*rotation angle */
385        self.detectorRotx = st.unpack(byteOrd+'i',File.read(4))[0] #/* 1000*rotation of detector around X */
386        self.detectorRoty = st.unpack(byteOrd+'i',File.read(4))[0] #/* 1000*rotation of detector around Y */
387        self.detectorRotz = st.unpack(byteOrd+'i',File.read(4))[0] #/* 1000*rotation of detector around Z */
388        self.totalDose = st.unpack(byteOrd+'i',File.read(4))[0] #/* Hz-sec (counts) integrated over full exposure */
389
390        File.seek(IFD[34710][2][0]+256+128+256+128)
391        self.detectorType = st.unpack(byteOrd+'i',File.read(4))[0] #/* detector type */
392        self.pixelsizeX = st.unpack(byteOrd+'i',File.read(4))[0] #/* pixel size (nanometers) */
393        self.pixelsizeY = st.unpack(byteOrd+'i',File.read(4))[0] #/* pixel size (nanometers) */
394        self.meanBias = st.unpack(byteOrd+'i',File.read(4))[0] #/* 1000*mean bias value */
395        self.photonsPer100adu = st.unpack(byteOrd+'i',File.read(4))[0] #/* photons / 100 ADUs */
396        self.measuredBias = st.unpack(byteOrd+'i'*MAXIMAGES,File.read(4*MAXIMAGES)) # /* 1000*mean bias value for each image*/
397        self.measuredTemperature = st.unpack(byteOrd+'i'*MAXIMAGES,File.read(4*MAXIMAGES)) # /* Temperature of each detector in milliKelvins */
398        self.measuredPressure = st.unpack(byteOrd+'i'*MAXIMAGES,File.read(4*MAXIMAGES)) # /* Pressure of each chamber in microTorr */
399
400        File.seek(IFD[34710][2][0]+256+128+256+128+128)
401        self.sourceType = st.unpack(byteOrd+'i',File.read(4))[0] #/* (code) - target, synch. etc */
402        self.sourceDx = st.unpack(byteOrd+'i',File.read(4))[0] #/* Optics param. - (size microns) */
403        self.sourceDy = st.unpack(byteOrd+'i',File.read(4))[0] #/* Optics param. - (size microns) */
404        self.sourceWavelength = st.unpack(byteOrd+'i',File.read(4))[0] #/* wavelength (femtoMeters) */
405        self.sourcePower = st.unpack(byteOrd+'i',File.read(4))[0] #/* (Watts) */
406        self.sourceVoltage = st.unpack(byteOrd+'i',File.read(4))[0] #/* (Volts) */
407        self.sourceCurrent = st.unpack(byteOrd+'i',File.read(4))[0] #/* (microAmps) */
408        self.sourceBias = st.unpack(byteOrd+'i',File.read(4))[0] #/* (Volts) */
409        self.sourcePolarizationX = st.unpack(byteOrd+'i',File.read(4))[0] #/* () */
410        self.sourcePolarizationY = st.unpack(byteOrd+'i',File.read(4))[0] #/* () */
411        self.sourceIntensity0 = st.unpack(byteOrd+'i',File.read(4))[0] #/* (arbitrary units) */
412        self.sourceIntensity1 = st.unpack(byteOrd+'i',File.read(4))[0] #/* (arbitrary units) */
413
414        File.seek(IFD[34710][2][0]+256+128+256+128+128+14*4)
415        self.opticsType = st.unpack(byteOrd+'i',File.read(4))[0] #/* Optics type (code)*/
416        self.opticsDx = st.unpack(byteOrd+'i',File.read(4))[0] #/* Optics param. - (size microns) */
417        self.opticsDy = st.unpack(byteOrd+'i',File.read(4))[0] #/* Optics param. - (size microns) */
418        self.opticsWavelength = st.unpack(byteOrd+'i',File.read(4))[0] #/* Optics param. - (size microns) */
419        self.opticsDispersion = st.unpack(byteOrd+'i',File.read(4))[0] #/* Optics param. - (*10E6) */
420        self.opticsCrossfireX = st.unpack(byteOrd+'i',File.read(4))[0] #/* Optics param. - (microRadians) */
421        self.opticsCrossfireY = st.unpack(byteOrd+'i',File.read(4))[0] #/* Optics param. - (microRadians) */
422        self.opticsAngle = st.unpack(byteOrd+'i',File.read(4))[0] #/* Optics param. - (monoch. 2theta - microradians) */
423        self.opticsPolarizationX = st.unpack(byteOrd+'i',File.read(4))[0] #/* () */
424        self.opticsPolarizationY = st.unpack(byteOrd+'i',File.read(4))[0] #/* () */
425
426        File.seek(IFD[34710][2][0]+256+128+256+128+128+128)
427        self.filetitle = re.sub(r'\x00','',string.join(st.unpack(byteOrd+128*'c',File.read(128)),''))
428        self.filepath = re.sub(r'\x00','',string.join(st.unpack(byteOrd+'c'*128,File.read(128)),'')) #/* path name for data file*/
429        self.filename = re.sub(r'\x00','',string.join(st.unpack(byteOrd+'c'*64,File.read(64)),'')) #/* name of data file*/
430        self.acquireTimestamp = re.sub(r'\x00','',string.join(st.unpack(byteOrd+'c'*32,File.read(32)),'')) #/* date and time of acquisition*/
431        self.headerTimestamp = re.sub(r'\x00','',string.join(st.unpack(byteOrd+'c'*32,File.read(32)),'')) #/* date and time of header update*/
432        self.saveTimestamp = re.sub(r'\x00','',string.join(st.unpack(byteOrd+'c'*32,File.read(32)),'')) #/* date and time file saved */
433        self.fileComment = re.sub(r'\x00','',string.join(st.unpack(byteOrd+'c'*512,File.read(512)),'')) #/* comments  - can be used as desired */
434        self.datasetComment = re.sub(r'\x00','',string.join(st.unpack(byteOrd+'c'*512,File.read(512)),'')) #/* comments  - can be used as desired */
435
436        self.userData = re.sub(r'\x00','',string.join(st.unpack(byteOrd+'c'*512,File.read(512)),''))
437
438        File.seek(4096)
439        self.image = ar.array(self.arrayTypeCode,File.read(self.byteDepth*self.TIFFsizeX*self.TIFFsizeY))
440        # reverse the array so if can have the same view as is read in marccd
441        # also switch the view direction
442        self.image.reverse()
443        self.viewDirection = abs(self.viewDirection - 1)
444
445    def outputHead(self):
446        myHead = []
447        for curAttr in dir(self):
448            if ( curAttr != '__doc__' and \
449                 curAttr != '__init__' and \
450                 curAttr != '__module__' and \
451                 curAttr != 'outputHead' and \
452                 curAttr != 'image' ):
453                myHead.append(" %s = %s" % (curAttr,getattr(self,curAttr)))
454        return myHead
Note: See TracBrowser for help on using the repository browser.