source: trunk/ReadMarCCDFrame.py @ 5036

Last change on this file since 5036 was 4800, checked in by toby, 10 months ago

finish up docs cleanups

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