Changeset 4917 for trunk


Ignore:
Timestamp:
May 28, 2021 10:20:46 PM (4 months ago)
Author:
toby
Message:

split G2 & pillow readers for TIF; document

Location:
trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIstrIO.py

    r4882 r4917  
    19011901    '''Compute the standard uncertainty on cell parameters
    19021902   
    1903     :param str pfx: prefix of form p::
     1903    :param str pfx: prefix of form p\:\:
    19041904    :param SGdata: space group information
    19051905    :param list A: Reciprocal cell Ai terms
  • trunk/docs/source/imports.rst

    r3828 r4917  
    339339    :members:
    340340
     341.. automodule:: G2img_PILTIF
     342    :members:
     343
    341344.. automodule:: G2img_CheMin
    342345    :members:
  • trunk/imports/G2img_1TIF.py

    r4763 r4917  
    1313Routine to read an image in Tagged-image file (TIF) format as well as a variety
    1414of slightly incorrect pseudo-TIF formats used at instruments around the world.
     15This uses a custom reader that attempts to determine the instrument and detector
     16parameters from various aspects of the file.
     17
    1518Note that the name ``G2img_1TIF`` is used so that this file will
    1619sort to the top of the image formats and thus show up first in the menu.
     
    3134    '''Reads TIF files using a routine (:func:`GetTifData`) that looks
    3235    for files that can be identified from known instruments and will
    33     correct for slightly incorrect TIF usage. If that routine fails,
    34     it will be read with a standard TIF reader, which can handle compression
    35     and other things less commonly used at beamlines.
     36    correct for slightly incorrect TIF usage.
    3637    '''
    3738    def __init__(self):
     
    3940            extensionlist=('.tif','.tiff'),
    4041            strictExtension=False,
    41             formatName = 'TIF image',
    42             longFormatName = 'Various .tif and pseudo-TIF formats'
     42            formatName = 'GSAS-II known TIF image',
     43            longFormatName = 'Various .tif and pseudo-TIF formats using GSAS-II reader'
    4344            )
    4445        self.scriptable = True
     
    4748        '''Does the header match the required TIF header?
    4849        '''
    49         fp = open(filename,'rb')
    50         tag = fp.read(2)
    51         if 'bytes' in str(type(tag)):
    52             tag = tag.decode('latin-1')
    53         if tag == 'II' and int(st.unpack('<h',fp.read(2))[0]) == 42: #little endian
    54             pass
    55         elif tag == 'MM' and int(st.unpack('>h',fp.read(2))[0]) == 42: #big endian
    56             pass
    57         else:
    58             return False # header not found; not valid TIF
    59             fp.close()
    60         fp.close()
    61         return True
     50        return TIFValidator(filename)
    6251   
    6352    def Reader(self,filename, ParentFrame=None, **unused):
    64         '''Read the TIF file using :func:`GetTifData`. If that fails,
    65         use :func:`scipy.misc.imread` and give the user a chance to
    66         edit the likely wrong default image parameters.
     53        '''Read the TIF file using :func:`GetTifData` which attempts to
     54        recognize the detector type and set various parameters
    6755        '''
     56        self.Npix = 0
    6857        self.Comments,self.Data,self.Npix,self.Image = GetTifData(filename)
    69         if self.Npix == 0:
    70             G2fil.G2Print("GetTifData failed to read "+str(filename)+" Trying PIL")
    71             import PIL.Image as PI
    72             self.Image = PI.open(filename,mode='r')
    73             self.Npix = self.Image.size
    74             if ParentFrame:
    75                 self.SciPy = True
    76                 self.Comments = ['no metadata']
    77                 self.Data = {'wavelength': 0.1, 'pixelSize': [200., 200.], 'distance': 100.0}
    78                 self.Data['size'] = list(self.Image.size)
    79                 self.Data['center'] = [int(i/2) for i in self.Image.size]
    8058        if self.Npix == 0:
    8159            return False
    8260        self.LoadImage(ParentFrame,filename)
    8361        return True
    84 
     62   
    8563def GetTifData(filename):
    8664    '''Read an image in a pseudo-tif format,
     
    379357    File.close()   
    380358    return head,data,Npix,image
     359
     360def TIFValidator(filename):
     361    '''Does the header match the required TIF header?
     362    '''
     363    fp = open(filename,'rb')
     364    tag = fp.read(2)
     365    if 'bytes' in str(type(tag)):
     366        tag = tag.decode('latin-1')
     367    if tag == 'II' and int(st.unpack('<h',fp.read(2))[0]) == 42: #little endian
     368        pass
     369    elif tag == 'MM' and int(st.unpack('>h',fp.read(2))[0]) == 42: #big endian
     370        pass
     371    else:
     372        return False # header not found; not valid TIF
     373        fp.close()
     374    fp.close()
     375    return True
Note: See TracChangeset for help on using the changeset viewer.