Changeset 2015


Ignore:
Timestamp:
Oct 17, 2015 4:32:42 PM (6 years ago)
Author:
toby
Message:

redo image read to avoid reloads; prevent open of Edit image parms on reread; fix multilevel TIF read error; cleanup self in GSASIIimage

Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASII.py

    r2003 r2015  
    777777            G2IO.LoadImage(rd.readfilename,self,rd.Comments,rd.Data,rd.Npix,rd.Image)
    778778        self.PatternTree.SelectItem(G2gd.GetPatternTreeItemId(self,self.Image,'Image Controls'))             #show last image to have beeen read
    779         # replace G2IO.GetImageData with something using imports
    780         # look over G2IO.ReadLoadImage
    781779                   
    782780    def _Add_ImportMenu_Sfact(self,parent):
     
    22452243        self.plotView = 0
    22462244        self.Image = 0
    2247         self.oldImagefile = ''
    2248         self.ImageZ = []
     2245        self.oldImagefile = '' # the name of the last image file read
     2246        self.ImageZ = []  # this contains the image plotted and used for integration
     2247        # self.ImageZ and self.oldImagefile are set in GSASIIplot.PlotImage
     2248        # and GSASIIIO.ReadImageData (GetImageData soon)
     2249        # any changes to self.ImageZ should initialize self.oldImagefile to force a reread
    22492250        self.Integrate = 0
    22502251        self.imageDefault = {}
  • trunk/GSASIIIO.py

    r2013 r2015  
    351351   
    352352def ReadImageData(G2frame,imagefile,imageOnly=False):
    353     '''Read a single image with an image importer. replacement for GetImageData
     353    '''Read a single image with an image importer. Replacement for GetImageData
    354354
    355355    :param wx.Frame G2frame: main GSAS-II Frame and data object.
     
    388388                continue
    389389        rdbuffer = {} # create temporary storage for file reader
     390        if imageOnly:
     391            ParentFrame = None # prevent GUI access on reread
     392        else:
     393            ParentFrame = G2frame
    390394        if GSASIIpath.GetConfigValue('debug'):
    391             flag = rd.Reader(imagefile,fp,G2frame)
     395            flag = rd.Reader(imagefile,fp,ParentFrame)
    392396        else:
    393397            flag = False
    394398            try:
    395                 flag = rd.Reader(imagefile,fp,G2frame)
     399                flag = rd.Reader(imagefile,fp,ParentFrame)
    396400            except rd.ImportException as detail:
    397401                rd.errors += "\n  Read exception: "+str(detail)
     
    418422def GetImageData(G2frame,imagefile,imageOnly=False):
    419423    '''Read an image with the file reader keyed by the
    420     file extension
     424    file extension.
     425
     426    This routine will be replaced by ReadImageData, which will be renamed to this.
    421427
    422428    :param wx.Frame G2frame: main GSAS-II Frame and data object.
     
    967973        lines = ['not a known detector tiff file',]
    968974        return lines,0,0,0
     975
     976    if sizexy[1]*sizexy[0] != image.size: # test is resize is allowed
     977        lines = ['not a known detector tiff file',]
     978        return lines,0,0,0
    969979       
    970980    image = np.reshape(image,(sizexy[1],sizexy[0]))
     
    20622072        self.Image = None
    20632073
     2074    def LoadImage(self,ParentFrame,imagefile):
     2075        '''Optionally, call this after reading in an image to load it into the tree.
     2076        This does saves time by preventing a reread of the same information.
     2077        '''
     2078        if ParentFrame:
     2079            ParentFrame.ImageZ = self.Image   # store the image for plotting
     2080            ParentFrame.oldImagefile = imagefile # save the name of the last image file read
     2081           
     2082
    20642083######################################################################
    20652084class ExportBaseclass(object):
  • trunk/GSASIIimage.py

    r1834 r2015  
    501501    return tam.T
    502502   
    503 def ImageRecalibrate(self,data,masks):
     503def ImageRecalibrate(G2frame,data,masks):
    504504    'Needs a doc string'
    505505    import ImageCalibrants as calFile
     
    536536    wave = data['wavelength']
    537537    frame = masks['Frames']
    538     tam = ma.make_mask_none(self.ImageZ.shape)
     538    tam = ma.make_mask_none(G2frame.ImageZ.shape)
    539539    if frame:
    540540        tam = ma.mask_or(tam,MakeFrameMask(data,frame))
     
    547547            break
    548548        ellipse = GetEllipse(dsp,data)
    549         Ring = makeRing(dsp,ellipse,pixLimit,cutoff,scalex,scaley,ma.array(self.ImageZ,mask=tam))
     549        Ring = makeRing(dsp,ellipse,pixLimit,cutoff,scalex,scaley,ma.array(G2frame.ImageZ,mask=tam))
    550550        if Ring:
    551551            if iH >= skip:
     
    574574        data['ellipses'].append(copy.deepcopy(ellipse+('b',)))   
    575575    print 'calibration time = ',time.time()-time0
    576     G2plt.PlotImage(self,newImage=True)       
     576    G2plt.PlotImage(G2frame,newImage=True)       
    577577    return True
    578578           
    579 def ImageCalibrate(self,data):
     579def ImageCalibrate(G2frame,data):
    580580    'Needs a doc string'
    581581    import copy
     
    611611    #setup 360 points on that ring for "good" fit
    612612    data['ellipses'].append(ellipse[:]+('g',))
    613     Ring = makeRing(1.0,ellipse,pixLimit,cutoff,scalex,scaley,self.ImageZ)
     613    Ring = makeRing(1.0,ellipse,pixLimit,cutoff,scalex,scaley,G2frame.ImageZ)
    614614    if Ring:
    615615        ellipse = FitEllipse(Ring)
    616         Ring = makeRing(1.0,ellipse,pixLimit,cutoff,scalex,scaley,self.ImageZ)    #do again
     616        Ring = makeRing(1.0,ellipse,pixLimit,cutoff,scalex,scaley,G2frame.ImageZ)    #do again
    617617        ellipse = FitEllipse(Ring)
    618618    else:
     
    624624    data['ellipses'].append(ellipse[:]+('r',))
    625625    data['rings'].append(np.array(Ring))
    626     G2plt.PlotImage(self,newImage=True)
     626    G2plt.PlotImage(G2frame,newImage=True)
    627627   
    628628#setup for calibration
     
    658658        tth = npatan2d(radii[0],dist)
    659659        data['wavelength'] = wave =  2.0*dsp*sind(tth/2.0)
    660     Ring0 = makeRing(dsp,ellipse,3,cutoff,scalex,scaley,self.ImageZ)
     660    Ring0 = makeRing(dsp,ellipse,3,cutoff,scalex,scaley,G2frame.ImageZ)
    661661    ttth = nptand(tth)
    662662    stth = npsind(tth)
     
    694694            ellipsep = GetEllipse2(tth,0.,dist,centp,tilt,phi)
    695695            print fmt%('plus ellipse :',ellipsep[0][0],ellipsep[0][1],ellipsep[1],ellipsep[2][0],ellipsep[2][1])
    696             Ringp = makeRing(dsp,ellipsep,3,cutoff,scalex,scaley,self.ImageZ)
     696            Ringp = makeRing(dsp,ellipsep,3,cutoff,scalex,scaley,G2frame.ImageZ)
    697697            parmDict = {'dist':dist,'det-X':centp[0],'det-Y':centp[1],
    698698                'tilt':tilt,'phi':phi,'wave':wave,'dep':0.0}       
     
    708708            ellipsem = GetEllipse2(tth,0.,dist,centm,-tilt,phi)
    709709            print fmt%('minus ellipse:',ellipsem[0][0],ellipsem[0][1],ellipsem[1],ellipsem[2][0],ellipsem[2][1])
    710             Ringm = makeRing(dsp,ellipsem,3,cutoff,scalex,scaley,self.ImageZ)
     710            Ringm = makeRing(dsp,ellipsem,3,cutoff,scalex,scaley,G2frame.ImageZ)
    711711            if len(Ringm) > 10:
    712712                parmDict['tilt'] *= -1
     
    732732        data['ellipses'].append(ellipsem[:]+('r',))
    733733        data['rings'].append(np.array(Ringm))
    734         G2plt.PlotImage(self,newImage=True)
     734        G2plt.PlotImage(G2frame,newImage=True)
    735735    parmDict = {'dist':data['distance'],'det-X':data['center'][0],'det-Y':data['center'][1],
    736736        'tilt':data['tilt'],'phi':data['rotation'],'wave':data['wavelength'],'dep':data['DetDepth']}
     
    748748        data['ellipses'].append(copy.deepcopy(ellipse+('g',)))
    749749        if debug:   print fmt%('predicted ellipse:',elcent[0],elcent[1],phi,radii[0],radii[1])
    750         Ring = makeRing(dsp,ellipse,pixLimit,cutoff,scalex,scaley,self.ImageZ)
     750        Ring = makeRing(dsp,ellipse,pixLimit,cutoff,scalex,scaley,G2frame.ImageZ)
    751751        if Ring:
    752752            data['rings'].append(np.array(Ring))
     
    763763                if debug:   print fmt2%('fitted ellipse:   ',elcent[0],elcent[1],phi,radii[0],radii[1],chisq,len(rings))
    764764            data['ellipses'].append(copy.deepcopy(ellipse+('r',)))
    765 #            G2plt.PlotImage(self,newImage=True)
     765#            G2plt.PlotImage(G2frame,newImage=True)
    766766        else:
    767767            if debug:   print 'insufficient number of points in this ellipse to fit'
    768768#            break
    769     G2plt.PlotImage(self,newImage=True)
    770     fullSize = len(self.ImageZ)/scalex
     769    G2plt.PlotImage(G2frame,newImage=True)
     770    fullSize = len(G2frame.ImageZ)/scalex
    771771    if 2*radii[1] < .9*fullSize:
    772772        print 'Are all usable rings (>25% visible) used? Try reducing Min ring I/Ib'
     
    784784        data['ellipses'].append(copy.deepcopy(ellipse+('b',)))
    785785    print 'calibration time = ',time.time()-time0
    786     G2plt.PlotImage(self,newImage=True)       
     786    G2plt.PlotImage(G2frame,newImage=True)       
    787787    return True
    788788   
  • trunk/GSASIIplot.py

    r2009 r2015  
    39263926        darkfile = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,
    39273927            G2frame.root,dark[0]))[1]
    3928     if imagefile != G2frame.oldImagefile:
     3928    if imagefile != G2frame.oldImagefile or dark[0]: # always reread with dark correction
    39293929        imagefile = G2IO.CheckImageFile(G2frame,imagefile)
    39303930        if not imagefile:
     
    39363936            darkImg = G2IO.GetImageData(G2frame,darkfile,imageOnly=True)
    39373937            G2frame.ImageZ += dark[1]*darkImg
    3938         G2frame.oldImagefile = imagefile
     3938        G2frame.oldImagefile = imagefile # save name of the last image file read
     3939    else:
     3940        if GSASIIpath.GetConfigValue('debug'): print('Skipping image reread')
    39393941
    39403942    imScale = 1
  • trunk/imports/G2img_1TIF.py

    r2012 r2015  
    5656            self.Image = scipy.misc.imread(filename,flatten=True)
    5757            self.Npix = self.Image.size
    58             self.Comments = ['no metadata']
    59             self.Data = {'wavelength': 0.1, 'pixelSize': [200, 200], 'distance': 100.0}
    60             self.Data['size'] = list(self.Image.shape)
    61             self.Data['center'] = [int(i/2) for i in self.Image.shape]
    6258            if ParentFrame:
     59                self.Comments = ['no metadata']
     60                self.Data = {'wavelength': 0.1, 'pixelSize': [200, 200], 'distance': 100.0}
     61                self.Data['size'] = list(self.Image.shape)
     62                self.Data['center'] = [int(i/2) for i in self.Image.shape]
    6363                G2IO.EditImageParms(ParentFrame,self.Data,self.Comments,self.Image,filename)
    64         if self.Npix == 0 or not self.Comments:
     64        if self.Npix == 0:
    6565            return False
     66        self.LoadImage(ParentFrame,filename)
    6667        return True
    6768
  • trunk/imports/G2img_ADSC.py

    r2003 r2015  
    4141        if self.Npix == 0 or not self.Comments:
    4242            return False
     43        self.LoadImage(ParentFrame,filename)
    4344        return True
  • trunk/imports/G2img_CheMin.py

    r2003 r2015  
    4242        self.Image = scipy.misc.imread(filename,flatten=True)
    4343        self.Npix = self.Image.size
    44         self.Comments = ['no metadata']
    45         pixy = list(self.Image.shape)
    46         sizexy = [40,40]
    47         self.Data = {'wavelength': 1.78892, 'pixelSize': sizexy, 'distance': 18.0,'size':pixy}
    48         self.Data['center'] = [pixy[0]*sizexy[0]/1000,pixy[1]*sizexy[1]/2000]
    49         if self.Npix == 0 or not self.Comments:
     44        if self.Npix == 0:
    5045            return False
    5146        if ParentFrame:
     47            self.Comments = ['no metadata']
     48            pixy = list(self.Image.shape)
     49            sizexy = [40,40]
     50            self.Data = {'wavelength': 1.78892, 'pixelSize': sizexy, 'distance': 18.0,'size':pixy}
     51            self.Data['center'] = [pixy[0]*sizexy[0]/1000,pixy[1]*sizexy[1]/2000]
    5252            G2IO.EditImageParms(ParentFrame,self.Data,self.Comments,self.Image,filename)
     53        self.LoadImage(ParentFrame,filename)
    5354        return True
    5455# N.B. This replaces G2IO.GetPNGData
  • trunk/imports/G2img_EDF.py

    r2003 r2015  
    4141        if self.Npix == 0 or not self.Comments:
    4242            return False
     43        self.LoadImage(ParentFrame,filename)
    4344        return True
  • trunk/imports/G2img_GE.py

    r2003 r2015  
    4040        if self.Npix == 0 or not self.Comments:
    4141            return False
     42        self.LoadImage(ParentFrame,filename)
    4243        return True
  • trunk/imports/G2img_MAR.py

    r2003 r2015  
    4040        if self.Npix == 0 or not self.Comments:
    4141            return False
     42        self.LoadImage(ParentFrame,filename)
    4243        return True
  • trunk/imports/G2img_Rigaku.py

    r2003 r2015  
    4646        if self.Npix == 0 or not self.Comments:
    4747            return False
     48        self.LoadImage(ParentFrame,filename)
    4849        return True
  • trunk/imports/G2img_SumG2.py

    r2003 r2015  
    4242        self.Comments,self.Data,self.Npix,self.image = cPickle.load(Fp)
    4343        Fp.close()
     44        self.LoadImage(ParentFrame,filename)
    4445        return True
    4546# N.B. This replaces G2IO.GetG2Image
Note: See TracChangeset for help on using the changeset viewer.