Changeset 1217 for trunk/GSASIIIO.py


Ignore:
Timestamp:
Feb 11, 2014 9:42:03 PM (8 years ago)
Author:
vondreele
Message:

add reading of CheMin? tif & png files
continue work on small angle stuff

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIIO.py

    r1216 r1217  
    267267        Comments,Data,Npix,Image = GetG2Image(imagefile)
    268268    elif ext == '.png':
    269         import scipy.misc
    270         Image = scipy.misc.imread(imagefile,flatten=True)
    271         Npix = Image.size
    272         Comments = ['no metadata']
    273         Data = {'wavelength': 0.1, 'pixelSize': [200, 200], 'distance': 100.0}
    274         Data['size'] = list(Image.shape)
    275         Data['center'] = [int(i/2) for i in Image.shape]
     269        Comments,Data,Npix,Image = GetPNGData(imagefile)
    276270        if not imageOnly:
    277271            EditImageParms(G2frame,Data,Comments,Image,imagefile)
     
    501495    else:
    502496        return head,data,Npix,image
     497       
     498def GetPNGData(filename,imageOnly=False):
     499    '''Read an image in a png format, assumes image is converted from CheMin tif file
     500    so default parameters are that machine.
     501    '''
     502    import scipy.misc
     503    Image = scipy.misc.imread(filename,flatten=True)
     504    Npix = Image.size
     505    Comments = ['no metadata']
     506    pixy = list(Image.shape)
     507    sizexy = [40,40]
     508    Data = {'wavelength': 1.78892, 'pixelSize': sizexy, 'distance': 18.0,'size':pixy}
     509    Data['center'] = [pixy[0]*sizexy[0]/1000,pixy[1]*sizexy[1]/2000]
     510    if imageOnly:
     511        return Image.T
     512    else:
     513        return Comments,Data,Npix,Image.T
    503514
    504515def GetTifData(filename,imageOnly=False):
     
    508519    '''
    509520    import struct as st
     521    import Image as Im
    510522    import array as ar
    511523    import ReadMarCCDFrame as rmf
     
    540552    NED = int(st.unpack(byteOrd+'h',File.read(2))[0])
    541553    IFD = {}
     554    nSlice = 1
    542555    for ied in range(NED):
    543556        Tag,Type = st.unpack(byteOrd+'Hh',File.read(4))
    544557        nVal = st.unpack(byteOrd+'i',File.read(4))[0]
     558        if DEBUG: print 'Try:',Tag,Type,nVal
    545559        if Type == 1:
    546560            Value = st.unpack(byteOrd+nVal*'b',File.read(nVal))
     
    551565            x = st.unpack(byteOrd+nVal*'h',File.read(nVal*2))
    552566        elif Type == 4:
     567            if Tag in [273,279]:
     568                nSlice = nVal
     569                nVal = 1
    553570            Value = st.unpack(byteOrd+nVal*'i',File.read(nVal*4))
    554571        elif Type == 5:
     
    581598        center = (center[0] != 0 and center[1] != 0) and center or [None,None]
    582599#print head,tifType,pixy
     600    elif nSlice > 1:    #CheMin multislice tif file!
     601        tifType = 'CheMin'
     602        pixy = [40,40]
     603        image = np.array(Im.open(filename))
     604        distance = 18.0
     605        center = [pixy[0]*sizexy[0]/2000,pixy[1]*sizexy[1]/1000]
     606        wavelength = 1.78892
    583607    elif 272 in IFD:
    584608        ifd = IFD[272]
Note: See TracChangeset for help on using the changeset viewer.