Ignore:
Timestamp:
May 2, 2017 10:03:41 AM (6 years ago)
Author:
vondreele
Message:

major revision - move all importers to GSASIIobj & make them independent of wx so they can be used in a scripting environment.
Still to move are PhaseSelector?, and 3 BlockSelector? dialogs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/imports/G2img_MAR.py

    r2133 r2817  
    1010*Module G2img_MAR: MAR image files*
    1111--------------------------------------
    12 
    1312'''
    1413
    15 import sys
    16 import os
    17 import GSASIIIO as G2IO
     14import GSASIIobj as G2obj
    1815import GSASIIpath
     16import numpy as np
    1917GSASIIpath.SetVersionNumber("$Revision$")
    20 class MAR_ReaderClass(G2IO.ImportImage):
     18class MAR_ReaderClass(G2obj.ImportImage):
    2119    '''Routine to read several MAR formats, .mar3450,.mar2300,.mar2560
    2220    '''
     
    3533       
    3634    def Reader(self,filename,filepointer, ParentFrame=None, **unused):
    37         '''Read using Bob's routine :func:`GSASIIIO.GetMAR345Data`
    38         (to be moved to this file, eventually)
    39         '''
    40         self.Comments,self.Data,self.Npix,self.Image = G2IO.GetMAR345Data(filename)
     35        self.Comments,self.Data,self.Npix,self.Image = GetMAR345Data(filename)
    4136        if self.Npix == 0 or not self.Comments:
    4237            return False
    4338        self.LoadImage(ParentFrame,filename)
    4439        return True
     40
     41def GetMAR345Data(filename,imageOnly=False):
     42    'Read a MAR-345 image plate image'
     43    try:
     44        import pack_f as pf
     45    except:
     46        print '**** ERROR - Unable to load the GSAS MAR image decompression, pack_f'
     47        return None,None,None,None
     48
     49    if not imageOnly:
     50        print 'Read Mar345 file: ',filename
     51    File = open(filename,'rb')
     52    head = File.read(4095)
     53    lines = head[128:].split('\n')
     54    head = []
     55    for line in lines:
     56        line = line.strip()
     57        if 'PIXEL' in line:
     58            values = line.split()
     59            pixel = (int(values[2]),int(values[4]))     #in microns
     60        elif 'WAVELENGTH' in line:
     61            wave = float(line.split()[1])
     62        elif 'DISTANCE' in line:
     63            distance = float(line.split()[1])           #in mm
     64            if not distance:
     65                distance = 500.
     66        elif 'CENTER' in line:
     67            values = line.split()
     68            center = [float(values[2])/10.,float(values[4])/10.]    #make in mm from pixels
     69        if line:
     70            head.append(line)
     71    data = {'pixelSize':pixel,'wavelength':wave,'distance':distance,'center':center}
     72    for line in head:
     73        if 'FORMAT' in line[0:6]:
     74            items = line.split()
     75            sizex = int(items[1])
     76            Npix = int(items[3])
     77            sizey = int(Npix/sizex)
     78    pos = 4096
     79    data['size'] = [sizex,sizey]
     80    File.seek(pos)
     81    line = File.read(8)
     82    while 'CCP4' not in line:       #get past overflow list for now
     83        line = File.read(8)
     84        pos += 8
     85    pos += 37
     86    File.seek(pos)
     87    raw = File.read()
     88    File.close()
     89    image = np.zeros(shape=(sizex,sizey),dtype=np.int32)
     90   
     91    image = np.flipud(pf.pack_f(len(raw),raw,sizex,sizey,image).T)  #transpose to get it right way around & flip
     92    if imageOnly:
     93        return image
     94    else:
     95        return head,data,Npix,image
     96       
Note: See TracChangeset for help on using the changeset viewer.