Ignore:
Timestamp:
Oct 26, 2017 3:57:59 PM (4 years ago)
Author:
vondreele
Message:

fix ReadMarCCDFrame.py for py 3.6/py 2.7 compatibility & put it back in G2img_1TIF.py - used by DND Sect. 5

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ReadMarCCDFrame.py

    r2347 r3143  
    11#!/usr/bin/env python
     2from __future__ import division, print_function
    23'''
    34*ReadMarCCDFrame: Read Mar Files*
     
    258259import struct as st
    259260import array as ar
    260 import string, re
    261261
    262262MAXIMAGES=9
     
    283283        self.TIFFyResolution = IFD[283][2][0] # pixels per resolutionUnit in Y direction (ImageLength direction
    284284        self.TIFFresolutionUnit = IFD[296][2][0] # 3 = centimeter
    285         self.byteDepth = self.TIFFbitDepth/8
     285        self.byteDepth = self.TIFFbitDepth//8
    286286        self.arrayTypeCode = ['','B','H','I','I'][self.byteDepth]
    287287        # MarCCD specific header info
    288288        File.seek(IFD[34710][2][0])
    289289        self.headerType = st.unpack(byteOrd+'I',File.read(4))[0] #/* flag for header type  (can be used as magic number) */
    290         self.headerName = re.sub(r'\x00','',string.join(st.unpack(byteOrd+16*'c',File.read(16)),''))
     290        self.headerName = st.unpack(byteOrd+16*'s',File.read(16))[0].replace(b'\x00',b'')
    291291        self.headerMajorVersion = st.unpack(byteOrd+'I',File.read(4))[0] #/* header_major_version (n.) */
    292292        self.headerMinorVersion = st.unpack(byteOrd+'I',File.read(4))[0] #/* header_minor_version (.n) */
     
    361361
    362362        File.seek(IFD[34710][2][0]+256+128)
    363         self.barcode = re.sub(r'\x00','',string.join(st.unpack(byteOrd+16*'c',File.read(16)),''))
     363        self.barcode = st.unpack(byteOrd+16*'s',File.read(16))[0].replace(b'\x00',b'')
    364364        self.barcodeAngle = st.unpack(byteOrd+'I',File.read(4))[0]
    365365        self.barcodeStatus = st.unpack(byteOrd+'I',File.read(4))[0]
     
    433433
    434434        File.seek(IFD[34710][2][0]+256+128+256+128+128+128)
    435         self.filetitle = re.sub(r'\x00','',string.join(st.unpack(byteOrd+128*'c',File.read(128)),''))
    436         self.filepath = re.sub(r'\x00','',string.join(st.unpack(byteOrd+'c'*128,File.read(128)),'')) #/* path name for data file*/
    437         self.filename = re.sub(r'\x00','',string.join(st.unpack(byteOrd+'c'*64,File.read(64)),'')) #/* name of data file*/
    438         self.acquireTimestamp = re.sub(r'\x00','',string.join(st.unpack(byteOrd+'c'*32,File.read(32)),'')) #/* date and time of acquisition*/
    439         self.headerTimestamp = re.sub(r'\x00','',string.join(st.unpack(byteOrd+'c'*32,File.read(32)),'')) #/* date and time of header update*/
    440         self.saveTimestamp = re.sub(r'\x00','',string.join(st.unpack(byteOrd+'c'*32,File.read(32)),'')) #/* date and time file saved */
    441         self.fileComment = re.sub(r'\x00','',string.join(st.unpack(byteOrd+'c'*512,File.read(512)),'')) #/* comments  - can be used as desired */
    442         self.datasetComment = re.sub(r'\x00','',string.join(st.unpack(byteOrd+'c'*512,File.read(512)),'')) #/* comments  - can be used as desired */
    443 
    444         self.userData = re.sub(r'\x00','',string.join(st.unpack(byteOrd+'c'*512,File.read(512)),''))
     435        self.filetitle = st.unpack(byteOrd+128*'s',File.read(128))[0].replace(b'\x00',b'')
     436        self.filepath = st.unpack(byteOrd+'s'*128,File.read(128))[0].replace(b'\x00',b'') #/* path name for data file*/
     437        self.filename = st.unpack(byteOrd+'s'*64,File.read(64))[0].replace(b'\x00',b'') #/* name of data file*/
     438        self.acquireTimestamp = st.unpack(byteOrd+'s'*32,File.read(32))[0].replace(b'\x00',b'') #/* date and time of acquisition*/
     439        self.headerTimestamp = st.unpack(byteOrd+'s'*32,File.read(32))[0].replace(b'\x00',b'') #/* date and time of header update*/
     440        self.saveTimestamp = st.unpack(byteOrd+'s'*32,File.read(32))[0].replace(b'\x00',b'') #/* date and time file saved */
     441        self.fileComment = st.unpack(byteOrd+'s'*512,File.read(512))[0].replace(b'\x00',b'') #/* comments  - can be used as desired */
     442        self.datasetComment = st.unpack(byteOrd+'s'*512,File.read(512))[0].replace(b'\x00',b'') #/* comments  - can be used as desired */
     443
     444        self.userData = st.unpack(byteOrd+'s'*512,File.read(512))[0].replace(b'\x00',b'')
    445445
    446446        File.seek(4096)
Note: See TracChangeset for help on using the changeset viewer.