Changeset 2001 for trunk/GSASIIIO.py


Ignore:
Timestamp:
Oct 12, 2015 1:48:43 PM (6 years ago)
Author:
toby
Message:

add initial Image imports code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIIO.py

    r1997 r2001  
    130130
    131131def CheckImageFile(G2frame,imagefile):
    132     '''Get an new image file name if the specified one does not
    133     exist
     132    '''Try to locate an image file if the project and image have been moved
     133    together. If the image file cannot be found, request the location from
     134    the user.
    134135
    135136    :param wx.Frame G2frame: main GSAS-II Frame and data object
    136 
    137137    :param str imagefile: name of image file
    138 
    139138    :returns: imagefile, if it exists, or the name of a file
    140139      that does exist or False if the user presses Cancel
     
    270269    '''Read a GSAS-II image file and load it into the data tree
    271270    '''
    272     # get a list of existing Image entries
    273     ImgNames = []
    274     if G2frame.PatternTree.GetCount():
    275         item, cookie = G2frame.PatternTree.GetFirstChild(G2frame.root)
    276         while item:
    277             name = G2frame.PatternTree.GetItemText(item)
    278             if name.startswith('IMG'): ImgNames.append(name)       
    279             item, cookie = G2frame.PatternTree.GetNextChild(G2frame.root, cookie)
    280271    # if a zip file, open and extract
    281272    if os.path.splitext(imagefile)[1].lower() == '.zip':
     
    285276    Comments,Data,Npix,Image = GetImageData(G2frame,imagefile)
    286277    if Comments:
    287         TreeName = G2obj.MakeUniqueLabel('IMG '+os.path.basename(imagefile),ImgNames)
    288         print 'b=','IMG '+os.path.basename(imagefile)
    289         print 'a=',TreeName
    290         Id = G2frame.PatternTree.AppendItem(parent=G2frame.root,text=TreeName)
    291         G2frame.PatternTree.SetItemPyData(G2frame.PatternTree.AppendItem(Id,text='Comments'),Comments)
    292         Imax = np.amax(Image)
    293         Imin = max(0.0,np.amin(Image))          #force positive
    294         if G2frame.imageDefault:
    295             Data = copy.copy(G2frame.imageDefault)
    296             Data['showLines'] = True
    297             Data['ring'] = []
    298             Data['rings'] = []
    299             Data['cutoff'] = 10
    300             Data['pixLimit'] = 20
    301             Data['edgemin'] = 100000000
    302             Data['calibdmin'] = 0.5
    303             Data['calibskip'] = 0
    304             Data['ellipses'] = []
    305             Data['calibrant'] = ''
    306             Data['GonioAngles'] = [0.,0.,0.]
    307             Data['DetDepthRef'] = False
    308         else:
    309             Data['type'] = 'PWDR'
    310             Data['color'] = 'Paired'
    311             Data['tilt'] = 0.0
    312             Data['rotation'] = 0.0
    313             Data['showLines'] = False
    314             Data['ring'] = []
    315             Data['rings'] = []
    316             Data['cutoff'] = 10
    317             Data['pixLimit'] = 20
    318             Data['calibdmin'] = 0.5
    319             Data['calibskip'] = 0
    320             Data['edgemin'] = 100000000
    321             Data['ellipses'] = []
    322             Data['GonioAngles'] = [0.,0.,0.]
    323             Data['DetDepth'] = 0.
    324             Data['DetDepthRef'] = False
    325             Data['calibrant'] = ''
    326             Data['IOtth'] = [2.0,5.0]
    327             Data['LRazimuth'] = [135,225]
    328             Data['azmthOff'] = 0.0
    329             Data['outChannels'] = 2500
    330             Data['outAzimuths'] = 1
    331             Data['centerAzm'] = False
    332             Data['fullIntegrate'] = False
    333             Data['setRings'] = False
    334             Data['background image'] = ['',-1.0]                           
    335             Data['dark image'] = ['',-1.0]
    336             Data['Flat Bkg'] = 0.0
    337         Data['setDefault'] = False
    338         Data['range'] = [(Imin,Imax),[Imin,Imax]]
    339         G2frame.PatternTree.SetItemPyData(G2frame.PatternTree.AppendItem(Id,text='Image Controls'),Data)
    340         Masks = {'Points':[],'Rings':[],'Arcs':[],'Polygons':[],'Frames':[],'Thresholds':[(Imin,Imax),[Imin,Imax]]}
    341         G2frame.PatternTree.SetItemPyData(G2frame.PatternTree.AppendItem(Id,text='Masks'),Masks)
    342         G2frame.PatternTree.SetItemPyData(G2frame.PatternTree.AppendItem(Id,text='Stress/Strain'),
    343             {'Type':'True','d-zero':[],'Sample phi':0.0,'Sample z':0.0,'Sample load':0.0})
    344         G2frame.PatternTree.SetItemPyData(Id,[Npix,imagefile])
    345         G2frame.PickId = Id
    346         G2frame.PickIdText = G2frame.GetTreeItemsList(G2frame.PickId)
    347         G2frame.Image = Id
     278        LoadImage(imagefile,G2frame,Comments,Data,Npix,Image)
     279   
     280def LoadImage(imagefile,G2frame,Comments,Data,Npix,Image):
     281    '''Load an image into the tree
     282    '''
     283   
     284    ImgNames = []
     285    if G2frame.PatternTree.GetCount(): # get a list of existing Image entries
     286        item, cookie = G2frame.PatternTree.GetFirstChild(G2frame.root)
     287        while item:
     288            name = G2frame.PatternTree.GetItemText(item)
     289            if name.startswith('IMG'): ImgNames.append(name)       
     290            item, cookie = G2frame.PatternTree.GetNextChild(G2frame.root, cookie)
     291    TreeName = G2obj.MakeUniqueLabel('IMG '+os.path.basename(imagefile),ImgNames)
     292    Id = G2frame.PatternTree.AppendItem(parent=G2frame.root,text=TreeName)
     293    G2frame.PatternTree.SetItemPyData(G2frame.PatternTree.AppendItem(Id,text='Comments'),Comments)
     294    Imax = np.amax(Image)
     295    Imin = max(0.0,np.amin(Image))          #force positive
     296    if G2frame.imageDefault:
     297        Data = copy.copy(G2frame.imageDefault)
     298        Data['showLines'] = True
     299        Data['ring'] = []
     300        Data['rings'] = []
     301        Data['cutoff'] = 10
     302        Data['pixLimit'] = 20
     303        Data['edgemin'] = 100000000
     304        Data['calibdmin'] = 0.5
     305        Data['calibskip'] = 0
     306        Data['ellipses'] = []
     307        Data['calibrant'] = ''
     308        Data['GonioAngles'] = [0.,0.,0.]
     309        Data['DetDepthRef'] = False
     310    else:
     311        Data['type'] = 'PWDR'
     312        Data['color'] = 'Paired'
     313        Data['tilt'] = 0.0
     314        Data['rotation'] = 0.0
     315        Data['showLines'] = False
     316        Data['ring'] = []
     317        Data['rings'] = []
     318        Data['cutoff'] = 10
     319        Data['pixLimit'] = 20
     320        Data['calibdmin'] = 0.5
     321        Data['calibskip'] = 0
     322        Data['edgemin'] = 100000000
     323        Data['ellipses'] = []
     324        Data['GonioAngles'] = [0.,0.,0.]
     325        Data['DetDepth'] = 0.
     326        Data['DetDepthRef'] = False
     327        Data['calibrant'] = ''
     328        Data['IOtth'] = [2.0,5.0]
     329        Data['LRazimuth'] = [135,225]
     330        Data['azmthOff'] = 0.0
     331        Data['outChannels'] = 2500
     332        Data['outAzimuths'] = 1
     333        Data['centerAzm'] = False
     334        Data['fullIntegrate'] = False
     335        Data['setRings'] = False
     336        Data['background image'] = ['',-1.0]                           
     337        Data['dark image'] = ['',-1.0]
     338        Data['Flat Bkg'] = 0.0
     339    Data['setDefault'] = False
     340    Data['range'] = [(Imin,Imax),[Imin,Imax]]
     341    G2frame.PatternTree.SetItemPyData(G2frame.PatternTree.AppendItem(Id,text='Image Controls'),Data)
     342    Masks = {'Points':[],'Rings':[],'Arcs':[],'Polygons':[],'Frames':[],'Thresholds':[(Imin,Imax),[Imin,Imax]]}
     343    G2frame.PatternTree.SetItemPyData(G2frame.PatternTree.AppendItem(Id,text='Masks'),Masks)
     344    G2frame.PatternTree.SetItemPyData(G2frame.PatternTree.AppendItem(Id,text='Stress/Strain'),
     345        {'Type':'True','d-zero':[],'Sample phi':0.0,'Sample z':0.0,'Sample load':0.0})
     346    G2frame.PatternTree.SetItemPyData(Id,[Npix,imagefile])
     347    G2frame.PickId = Id
     348    G2frame.PickIdText = G2frame.GetTreeItemsList(G2frame.PickId)
     349    G2frame.Image = Id
    348350   
    349351def GetImageData(G2frame,imagefile,imageOnly=False):
     
    19521954        self.numbanks = 1
    19531955        self.instdict = {} # place items here that will be transferred to the instrument parameters
     1956
     1957######################################################################
     1958class ImportImage(ImportBaseclass):
     1959    '''Defines a base class for the reading of images
     1960
     1961    Structure factors are read with a call to :meth:`GSASII.GSASII.OnImportImage`
     1962    which in turn calls :meth:`GSASII.GSASII.OnImportGeneric`, which calls
     1963    methods :meth:`ExtensionValidator`, :meth:`ContentsValidator` and
     1964    :meth:`Reader`.
     1965
     1966    See :ref:`Writing a Import Routine<Import_Routines>`
     1967    for an explanation on how to use import classes in general. The specifics
     1968    for reading an image requires that the ``Reader()`` routine in the import
     1969    class need to do only a few things:...
     1970   
     1971    (should load :attr:`RefDict` item ``'RefList'`` with the reflection list,
     1972    (and set :attr:`Parameters` with the instrument parameters
     1973    (initialized with :meth:`InitParameters` and set with :meth:`UpdateParameters`).
     1974    '''
     1975    def __init__(self,formatName,longFormatName=None,extensionlist=[],
     1976        strictExtension=False,):
     1977        ImportBaseclass.__init__(self,formatName,longFormatName,
     1978            extensionlist,strictExtension)
     1979        self.InitParameters()
     1980       
     1981    def ReInitialize(self):
     1982        'Reinitialize the Reader to initial settings -- not used at present'
     1983        ImportBaseclass.ReInitialize(self)
     1984        self.InitParameters()
     1985       
     1986    def InitParameters(self):
     1987        'initialize the instrument parameters structure'
     1988        self.Comments = ['No comments']
     1989        self.Data = {}
     1990        self.Npix = 0
     1991        self.Image = None
     1992
    19541993######################################################################
    19551994class ExportBaseclass(object):
Note: See TracChangeset for help on using the changeset viewer.