Changeset 824 for trunk/GSASIIIO.py


Ignore:
Timestamp:
Jan 10, 2013 3:22:25 PM (9 years ago)
Author:
vondreele
Message:

added read of edf (European data file) image files
more work on texture restraints - no derivatives yet

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIIO.py

    r798 r824  
    9494    if not ospath.exists(imagefile):
    9595        dlg = wx.FileDialog(G2frame, 'Bad image file name; choose name', '.', '',\
    96         'Any image file (*.tif;*.tiff;*.mar*;*.avg;*.sum;*.img)\
    97         |*.tif;*.tiff;*.mar*;*.avg;*.sum;*.img|\
     96        'Any image file (*.edf;*.tif;*.tiff;*.mar*;*.avg;*.sum;*.img)\
     97        |*.edf;*.tif;*.tiff;*.mar*;*.avg;*.sum;*.img|\
     98        European detector file (*.edf)|*.edf|\
    9899        Any detector tif (*.tif;*.tiff)|*.tif;*.tiff|\
    99100        MAR file (*.mar*)|*.mar*|\
     
    116117    if ext == '.tif' or ext == '.tiff':
    117118        Comments,Data,Npix,Image = GetTifData(imagefile)
     119    elif ext == '.edf':
     120        Comments,Data,Npix,Image = GetEdfData(imagefile)
    118121    elif ext == '.img':
    119122        Comments,Data,Npix,Image = GetImgData(imagefile)
     
    142145    return Comments,Data,Npix,image
    143146   
     147def GetEdfData(filename,imageOnly=False):   
     148    import struct as st
     149    import array as ar
     150    if not imageOnly:
     151        print 'Read European detector data edf file: ',filename
     152    File = open(filename,'rb')
     153    head = File.read(3072)
     154    lines = head.split('\n')
     155    sizexy = [0,0]
     156    pixSize = [0,0]
     157    cent = [0,0]
     158    head = ['European detector data',]
     159    for line in lines:
     160        fields = line.split()
     161        if 'Dim_1' in line:
     162            sizexy[0] = int(fields[2])
     163        elif 'Dim_2' in line:
     164            sizexy[1] = int(fields[2])
     165        elif 'DataType' in line:
     166            dType = fields[2]
     167        elif 'refined_wavelength' in line:
     168            wave = float(fields[2])
     169        elif 'Size' in line:
     170            imSize = int(fields[2])
     171        elif 'DataType' in lines:
     172            dType = fields[2]
     173        elif 'pixel_size_x' in line:
     174            pixSize[0] = float(fields[2])
     175        elif 'pixel_size_y' in line:
     176            pixSize[1] = float(fields[2])
     177        elif 'beam_center_x' in line:
     178            cent[0] = float(fields[2])
     179        elif 'beam_center_y' in line:
     180            cent[1] = float(fields[2])
     181        elif 'refined_distance' in line:
     182            dist = float(fields[2])
     183        if line:
     184            head.append(line)
     185    if dType == 'UnsignedShort':       
     186        image = np.array(ar.array('H',File.read(imSize)),dtype=np.int32)
     187    image = np.reshape(image,(sizexy[1],sizexy[0]))
     188    data = {'pixelSize':pixSize,'wavelength':wave,'distance':dist,'center':cent,'size':sizexy}
     189    Npix = sizexy[0]*sizexy[1]
     190    File.close()   
     191    if imageOnly:
     192        return image
     193    else:
     194        return head,data,Npix,image
     195       
    144196def GetGEsumData(filename,imageOnly=False):
    145197    import struct as st
     
    285337    else:
    286338        return head,data,Npix,image.T
    287        
     339
    288340def GetTifData(filename,imageOnly=False):
    289341    import struct as st
Note: See TracChangeset for help on using the changeset viewer.