Changeset 4416


Ignore:
Timestamp:
May 9, 2020 2:14:54 PM (4 years ago)
Author:
vondreele
Message:

fix 3D surface problem when changing mystrain/size axis
remove MPLsubplots - obsolete sine mpl 2.2
reduce mpl > 3.03 warnings to just one
fix plotting of 3D size/mustrain surfaces - now consistent with values & table
add size & mustrain columns to Reflection Lists - checked against plots
provide better escape from crashed sequential refinement

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIddataGUI.py

    r4370 r4416  
    242242        h,k,l = hkl
    243243        Obj.SetValue('%3d %3d %3d'%(h,k,l))
    244         G2plt.PlotSizeStrainPO(G2frame,data,G2frame.hist)
     244        wx.CallAfter(G2plt.PlotSizeStrainPO,G2frame,data,hist)
    245245       
    246246    def OnResetStrain(event):
  • trunk/GSASIIplot.py

    r4415 r4416  
    290290    fil.write(line+'\n')
    291291
    292 # def MPLsubplots(figure, nrows=1, ncols=1, sharex=False, sharey=False,
    293 #                  squeeze=True, subplot_kw=None, gridspec_kw=None):
    294 #         """
    295 #         Add a set of subplots to this figure.
    296        
    297 #         This is a copy of Figure.figure.subplots from matplotlib.figure.py.
    298 #         Included here because this appears only in later versions of
    299 #         matplotlib. When v2.2 is standard, this should be removed from GSAS-II.
    300        
    301 #         :param int nrows, ncols: default: 1
    302 #             Number of rows/cols of the subplot grid.
    303 #         :param bool/str sharex, sharey: True/False or {'none', 'all', 'row', 'col'}, default: False
    304 
    305 #             Controls sharing of properties among x (`sharex`) or y (`sharey`)
    306 #             axes:
    307            
    308 #                 - True or 'all': x- or y-axis will be shared among all
    309 #                   subplots.
    310 #                 - False or 'none': each subplot x- or y-axis will be
    311 #                   independent.
    312 #                 - 'row': each subplot row will share an x- or y-axis.
    313 #                 - 'col': each subplot column will share an x- or y-axis.
    314                
    315 #             When subplots have a shared x-axis along a column, only the x tick
    316 #             labels of the bottom subplot are visible.  Similarly, when
    317 #             subplots have a shared y-axis along a row, only the y tick labels
    318 #             of the first column subplot are visible.
    319 #         :param bool squeeze: default: True
    320 
    321 #             - If True, extra dimensions are squeezed out from the returned
    322 #               axis object:
    323              
    324 #                 - if only one subplot is constructed (nrows=ncols=1), the
    325 #                   resulting single Axes object is returned as a scalar.
    326 #                 - for Nx1 or 1xN subplots, the returned object is a 1D numpy
    327 #                   object array of Axes objects are returned as numpy 1D
    328 #                   arrays.
    329 #                 - for NxM, subplots with N>1 and M>1 are returned as a 2D
    330 #                   arrays.
    331                  
    332 #             - If False, no squeezing at all is done: the returned Axes object
    333 #               is always a 2D array containing Axes instances, even if it ends
    334 #               up being 1x1.
    335              
    336 #         :param dict subplot_kw: default: {}
    337 #             Dict with keywords passed to the
    338 #             :meth:`matplotlib.figure.Figure.add_subplot` call used to create
    339 #             each subplots.
    340 #         :param dict gridspec_kw: default: {}
    341 #             Dict with keywords passed to the
    342 #             :class:`matplotlib.gridspec.GridSpec` constructor used to create
    343 #             the grid the subplots are placed on.
    344            
    345 #         :returns: A single Axes object or array of Axes objects with
    346 #             the added axes.  The dimensions of the resulting array can be
    347 #             controlled with the squeeze keyword, see above.
    348            
    349 #         See also: pyplot.subplots: pyplot API; docstring includes examples.
    350        
    351 #         """
    352 
    353 #         # for backwards compatibility
    354 #         if isinstance(sharex, bool):
    355 #             sharex = "all" if sharex else "none"
    356 #         if isinstance(sharey, bool):
    357 #             sharey = "all" if sharey else "none"
    358 #         share_values = ["all", "row", "col", "none"]
    359 #         if sharex not in share_values:
    360 #             # This check was added because it is very easy to type
    361 #             # `subplots(1, 2, 1)` when `subplot(1, 2, 1)` was intended.
    362 #             # In most cases, no error will ever occur, but mysterious behavior
    363 #             # will result because what was intended to be the subplot index is
    364 #             # instead treated as a bool for sharex.
    365 #             if isinstance(sharex, int):
    366 #                 warnings.warn(
    367 #                     "sharex argument to subplots() was an integer. "
    368 #                     "Did you intend to use subplot() (without 's')?")
    369 
    370 #             raise ValueError("sharex [%s] must be one of %s" %
    371 #                              (sharex, share_values))
    372 #         if sharey not in share_values:
    373 #             raise ValueError("sharey [%s] must be one of %s" %
    374 #                              (sharey, share_values))
    375 #         if subplot_kw is None:
    376 #             subplot_kw = {}
    377 #         if gridspec_kw is None:
    378 #             gridspec_kw = {}
    379 
    380 #         # if figure.get_constrained_layout():
    381 #         #     gs = GridSpec(nrows, ncols, figure=figure, **gridspec_kw)
    382 #         # else:
    383 #         #     # this should turn constrained_layout off if we don't want it
    384 #         #     gs = GridSpec(nrows, ncols, figure=None, **gridspec_kw)
    385 #         gs = mpl.gridspec.GridSpec(nrows, ncols, **gridspec_kw)
    386 
    387 #         # Create array to hold all axes.
    388 #         axarr = np.empty((nrows, ncols), dtype=object)
    389 #         for row in range(nrows):
    390 #             for col in range(ncols):
    391 #                 shared_with = {"none": None, "all": axarr[0, 0],
    392 #                                "row": axarr[row, 0], "col": axarr[0, col]}
    393 #                 subplot_kw["sharex"] = shared_with[sharex]
    394 #                 subplot_kw["sharey"] = shared_with[sharey]
    395 #                 axarr[row, col] = figure.add_subplot(gs[row, col], **subplot_kw)
    396 
    397 #         # turn off redundant tick labeling
    398 #         if sharex in ["col", "all"]:
    399 #             # turn off all but the bottom row
    400 #             for ax in axarr[:-1, :].flat:
    401 #                 ax.xaxis.set_tick_params(which='both',
    402 #                                          labelbottom=False, labeltop=False)
    403 #                 ax.xaxis.offsetText.set_visible(False)
    404 #         if sharey in ["row", "all"]:
    405 #             # turn off all but the first column
    406 #             for ax in axarr[:, 1:].flat:
    407 #                 ax.yaxis.set_tick_params(which='both',
    408 #                                          labelleft=False, labelright=False)
    409 #                 ax.yaxis.offsetText.set_visible(False)
    410 
    411 #         if squeeze:
    412 #             # Discarding unneeded dimensions that equal 1.  If we only have one
    413 #             # subplot, just return it instead of a 1-element array.
    414 #             return axarr.item() if axarr.size == 1 else axarr.squeeze()
    415 #         else:
    416 #             # Returned axis array will be always 2-d, even if nrows=ncols=1.
    417 #             return axarr
    418292
    419293class _tabPlotWin(wx.Panel):   
     
    512386        self.nb.Bind(wx.EVT_KEY_UP,self.OnNotebookKey)
    513387        self.G2frame = G2frame
     388        self.MPLwarn = False
    514389       
    515390        self.plotList = []   # contains the tab label for each plot
     
    666541        self._addPage(name,page)
    667542        mplv = mpl.__version__.split('.')
    668         if mplv[0] == '3' and (mplv[1] == '1' or mplv[1] == '2'): # patch for bad MPL 3D
    669 
     543        if mplv[0] == '3' and (mplv[1] == '1' or mplv[1] == '2') and not self.MPLwarn: # patch for bad MPL 3D
     544            self.MPLwarn = True
    670545            G2G.G2MessageBox(self,'3D plots with Matplotlib 3.1.x and 3.2.x are distorted, we suggest regressing to MPL 3.0.3 until 3.3.x or later is available.. You have '+mpl.__version__,
    671546                                 'Avoid Matplotlib 3.1 & 3.2')
     
    58665741    PHI = np.linspace(0.,360.,40,True)
    58675742    PSI = np.linspace(0.,180.,40,True)
    5868     X = np.outer(npcosd(PHI),npsind(PSI))/2.
    5869     Y = np.outer(npsind(PHI),npsind(PSI))/2.
    5870     Z = np.outer(np.ones(np.size(PHI)),npcosd(PSI))/2.
     5743    X = np.outer(npcosd(PHI),npsind(PSI))
     5744    Y = np.outer(npsind(PHI),npsind(PSI))
     5745    Z = np.outer(np.ones(np.size(PHI)),npcosd(PSI))
    58715746    try:        #temp patch instead of 'mustrain' for old files with 'microstrain'
    58725747        if plotDict[plotType]:
     
    58755750        return
    58765751    if plotType in ['Mustrain','Size']:
     5752        diam = 0.5
     5753        if plotType == 'Mustrain':
     5754            diam = 1.0
    58775755        if coeff[0] == 'isotropic':
    5878             X *= coeff[1][0]
    5879             Y *= coeff[1][0]
    5880             Z *= coeff[1][0]                               
     5756            X *= diam*coeff[1][0]
     5757            Y *= diam*coeff[1][0]
     5758            Z *= diam*coeff[1][0]                               
    58815759        elif coeff[0] == 'uniaxial':
    58825760           
     
    58865764                sp = np.sqrt(1.-cp**2)
    58875765                R = iso*aniso/np.sqrt((iso*cp)**2+(aniso*sp)**2)
    5888                 return R*xyz
     5766                return R*xyz*diam
    58895767               
    58905768            iso,aniso = coeff[1][:2]
     
    59035781            def ellipseCalc(xyz,E,R):
    59045782                XYZ = xyz*E.T
    5905                 return np.inner(XYZ.T,R)
     5783                return np.inner(XYZ.T,R)*diam
    59065784               
    59075785            S6 = coeff[4]
  • trunk/GSASIIpwd.py

    r4415 r4416  
    11801180        dRdS[i] = (lenP-lenM)/(2.*delt)
    11811181    return lenR,dRdS
     1182
     1183def getMustrain(HKL,G,SGData,muStrData):
     1184    if muStrData[0] == 'isotropic':
     1185        return np.ones(HKL.shape[1])*muStrData[1][0]
     1186    elif muStrData[0] == 'uniaxial':
     1187        H = np.array(HKL)
     1188        P = np.array(muStrData[3])
     1189        cosP,sinP = np.array([G2lat.CosSinAngle(h,P,G) for h in H.T]).T
     1190        Si = muStrData[1][0]
     1191        Sa = muStrData[1][1]
     1192        return Si*Sa/(np.sqrt((Si*cosP)**2+(Sa*sinP)**2))
     1193    else:       #generalized - P.W. Stephens model
     1194        H = np.array(HKL)
     1195        rdsq = np.array([G2lat.calc_rDsq2(h,G) for h in H.T])
     1196        Strms = np.array(G2spc.MustrainCoeff(H,SGData))
     1197        Sum = np.sum(np.array(muStrData[4])[:,nxs]*Strms,axis=0)
     1198        return np.sqrt(Sum)/rdsq
     1199   
     1200def getCrSize(HKL,G,GB,sizeData):
     1201    if sizeData[0] == 'isotropic':
     1202        return np.ones(HKL.shape[1])*sizeData[1][0]
     1203    elif sizeData[0] == 'uniaxial':
     1204        H = np.array(HKL)
     1205        P = np.array(sizeData[3])
     1206        cosP,sinP = np.array([G2lat.CosSinAngle(h,P,G) for h in H.T]).T
     1207        Si = sizeData[1][0]
     1208        Sa = sizeData[1][1]
     1209        return Si*Sa/(np.sqrt((Si*cosP)**2+(Sa*sinP)**2))
     1210    else:
     1211        Sij =[sizeData[4][i] for i in range(6)]
     1212        H = np.array(HKL)
     1213        return 1./np.array([ellipseSize(h,Sij,GB) for h in H.T])**2
    11821214
    11831215def getHKLpeak(dmin,SGData,A,Inst=None,nodup=False):
  • trunk/GSASIIpwdGUI.py

    r4410 r4416  
    47274727                if phaseId:         #is phase deleted?
    47284728                    General = G2frame.GPXtree.GetItemPyData(phaseId)['General']
     4729                    G,g = G2lat.cell2Gmat(General['Cell'][1:7])
     4730                    GA,GB = G2lat.Gmat2AB(G)    #Orthogonalization matricies
     4731                    SGData = General['SGData']
    47294732                    if General.get('Modulated',False):
    47304733                        Super = 1
     4734                    Histograms = G2frame.GPXtree.GetItemPyData(phaseId)['Histograms']
     4735                    histName = G2frame.GPXtree.GetItemText(G2frame.PatternId)
     4736                    histData = Histograms[histName]
     4737                    muStrData = histData['Mustrain']
     4738                    sizeData = histData['Size']
    47314739        rowLabels = []
    47324740        if HKLF:
     
    47444752                refList = np.array([refl[:11+Super] for refl in data[phaseName]])
    47454753                I100 = refList.T[8+Super]*np.array([refl[11+Super] for refl in data[phaseName]])
     4754            MuStr = G2pwd.getMustrain(refList.T[:3],G,SGData,muStrData)
     4755            CrSize = G2pwd.getCrSize(refList.T[:3],G,GB,sizeData)
    47464756            Imax = np.max(I100)
    47474757            if Imax:
    47484758                I100 *= 100.0/Imax
    47494759            if 'C' in Inst['Type'][0]:
    4750                 refs = np.vstack((refList.T[:15+Super],I100)).T
     4760                refs = np.vstack((refList.T[:15+Super],I100,MuStr,CrSize)).T
    47514761            elif 'T' in Inst['Type'][0]:
    4752                 refs = np.vstack((refList.T[:18+Super],I100)).T
     4762                refs = np.vstack((refList.T[:18+Super],I100,MuStr,CrSize)).T
    47534763        rowLabels = [str(i) for i in range(len(refs))]
    47544764        Types = (4+Super)*[wg.GRID_VALUE_LONG,]+4*[wg.GRID_VALUE_FLOAT+':10,4',]+ \
     
    47644774        else:
    47654775            if 'C' in Inst['Type'][0]:
    4766                 colLabels = ['H','K','L','mul','d','pos','sig','gam','Fosq','Fcsq','phase','Icorr','Prfo','Trans','ExtP','I100']
    4767                 Types += 4*[wg.GRID_VALUE_FLOAT+':10,3',]
     4776                colLabels = ['H','K','L','mul','d','pos','sig','gam','Fosq','Fcsq','phase','Icorr','Prfo','Trans','ExtP','I100','mustrain','Size']
     4777                Types += 6*[wg.GRID_VALUE_FLOAT+':10,3',]
    47684778            elif 'T' in Inst['Type'][0]:
    4769                 colLabels = ['H','K','L','mul','d','pos','sig','gam','Fosq','Fcsq','phase','Icorr','alp','bet','wave','Prfo','Abs','Ext','I100']
    4770                 Types += 7*[wg.GRID_VALUE_FLOAT+':10,3',]
     4779                colLabels = ['H','K','L','mul','d','pos','sig','gam','Fosq','Fcsq','phase','Icorr','alp','bet','wave','Prfo','Abs','Ext','I100','mustrain','Size']
     4780                Types += 9*[wg.GRID_VALUE_FLOAT+':10,3',]
    47714781            if Super:
    47724782                colLabels.insert(3,'M')
  • trunk/GSASIIstrMain.py

    r4399 r4416  
    512512                refPlotUpdate=refPlotUpdate)
    513513            G2fil.G2Print ('  wR = %7.2f%%, chi**2 = %12.6g, reduced chi**2 = %6.2f, last delta chi = %.4f, last shft/sig = %.4f'%(
    514                 Rvals['Rwp'],Rvals['chisq'],Rvals['GOF']**2,Rvals['DelChi2'],Rvals['Max shft/sig']))
     514                Rvals['Rwp'],Rvals['chisq'],Rvals['GOF']**2,Rvals['DelChi2'],Rvals.get('Max shft/sig',np.nan)))
    515515            # add the uncertainties into the esd dictionary (sigDict)
    516516            if not IfOK:
Note: See TracChangeset for help on using the changeset viewer.