Changeset 2996


Ignore:
Timestamp:
Aug 11, 2017 12:16:08 PM (4 years ago)
Author:
odonnell
Message:

fixed background fitting, made GSASIIpath printing optional

Location:
branch/2frame
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branch/2frame/GSASIIpath.py

    r2979 r2996  
    665665
    666666BinaryPathLoaded = False
    667 def SetBinaryPath():
     667def SetBinaryPath(printInfo=True):
    668668    '''
    669669    Add location of GSAS-II shared libraries (binaries: .so or .pyd files) to path
     
    710710    if binpath:                                            # were GSAS-II binaries found
    711711        sys.path.insert(0,binpath)
    712         print('GSAS-II binary directory: {}'.format(binpath))
     712        if printInfo:
     713            print('GSAS-II binary directory: {}'.format(binpath))
    713714        BinaryPathLoaded = True
    714715    else:                                                  # try loading them
    715         print('Attempting to download GSAS-II binary files...')
     716        if printInfo:
     717            print('Attempting to download GSAS-II binary files...')
    716718        try:
    717719            binpath = DownloadG2Binaries(g2home)
    718720        except AttributeError:   # this happens when building in Read The Docs
    719             print('Problem with download')
     721            if printInfo:
     722                print('Problem with download')
    720723        if binpath and TestSPG(binpath):
    721             print('GSAS-II binary directory: {}'.format(binpath))
     724            if printInfo:
     725                print('GSAS-II binary directory: {}'.format(binpath))
    722726            sys.path.insert(0,binpath)
    723727            BinaryPathLoaded = True
     
    754758                if TestSPG(fpth):
    755759                    sys.path.insert(0,binpath)
    756                     print('\n'+75*'*')
    757                     print('  Warning. Using an old-style GSAS-II binary library. This is unexpected')
    758                     print('  and will break in future GSAS-II versions. Please contact toby@anl.gov')
    759                     print('  so we can learn what is not working on your installation.')
    760                     print('GSAS-II binary directory: {}'.format(binpath))
    761                     print(75*'*')
     760                    if printInfo:
     761                        print('\n'+75*'*')
     762                        print('  Warning. Using an old-style GSAS-II binary library. This is unexpected')
     763                        print('  and will break in future GSAS-II versions. Please contact toby@anl.gov')
     764                        print('  so we can learn what is not working on your installation.')
     765                        print('GSAS-II binary directory: {}'.format(binpath))
     766                        print(75*'*')
    762767                    break
    763768            else:
     
    765770            #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    766771            #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    767                 print(75*'*')
    768                 print('Use of GSAS-II binary directory {} failed!'.format(binpath))
    769                 print(75*'*')
     772                if printInfo:
     773                    print(75*'*')
     774                    print('Use of GSAS-II binary directory {} failed!'.format(binpath))
     775                    print(75*'*')
    770776                raise Exception,"**** ERROR GSAS-II binary libraries not found, GSAS-II cannot run ****"
    771777
     
    783789        import inspect
    784790        vals = [True for i in inspect.getmembers(config) if '__' not in i[0]]
    785         print str(len(vals))+' values read from config file '+os.path.abspath(config.__file__)
     791        if printInfo:
     792            print str(len(vals))+' values read from config file '+os.path.abspath(config.__file__)
    786793    except ImportError:
    787794        configDict = {'Clip_on':True}
    788795    except Exception as err:
    789         print("Error importing config.py file: "+str(err))
     796        if printInfo:
     797            print("Error importing config.py file: "+str(err))
    790798        configDict = {'Clip_on':True}
    791799
  • branch/2frame/GSASIIscriptable.py

    r2984 r2996  
    3434
    3535import GSASIIpath
    36 GSASIIpath.SetBinaryPath() # would rather have this in __name__ == '__main__' stanza
     36GSASIIpath.SetBinaryPath(False) # would rather have this in __name__ == '__main__' stanza
    3737import GSASIIIO as G2IO
    3838import GSASIIfiles as G2fil
     
    11621162        return self['data'][0]['ranId']
    11631163
     1164    @property
     1165    def residuals(self):
     1166        data = self['data'][0]
     1167        return {key: data[key]
     1168                for key in ['R', 'Rb', 'wR', 'wRb', 'wRmin']}
     1169
    11641170    def fit_fixed_points(self):
    11651171        """Attempts to apply a background fit to the fixed points currently specified."""
     
    11991205
    12001206        # Some simple lookups
     1207        controls = self.proj['Controls']['data']
    12011208        inst, inst2 = self['Instrument Parameters']
    12021209        pwddata = self['data'][1]
     
    12151222
    12161223        # Do the fit
    1217         # TODO get controls from root
    12181224        data = np.array([xdata, ydata, W, Z, Z, Z])
    12191225        G2pwd.DoPeakFit('LSQ', [], bgrnd, limits, inst, inst2, data,
    1220                         bakVary, controls={})
     1226                        prevVaryList=bakVary, controls=controls)
    12211227
    12221228        # Post-fit
     
    12361242        return self['data'][1][3]
    12371243
    1238     def plot(self, Yobs=True, Ycalc=True, Background=True):
     1244    def plot(self, Yobs=True, Ycalc=True, Background=True, Residual=True):
    12391245        if plt:
    12401246            data = self['data'][1]
     
    12451251            if Background:
    12461252                plt.plot(data[0], data[4], label='Background')
     1253            if Residual:
     1254                plt.plot(data[0], data[5], label="Residual")
    12471255
    12481256    def set_refinements(self, refs):
     
    13101318        # are added
    13111319        if do_fit_fixed_points:
     1320            # Background won't be fit if refinement flag not set
     1321            orig = self['Background'][0][1]
     1322            self['Background'][0][1] = True
    13121323            self.fit_fixed_points()
     1324            # Restore the previous value
     1325            self['Background'][0][1] = orig
    13131326
    13141327    def clear_refinements(self, refs):
     
    13541367    def is_valid_refinement_key(key):
    13551368        valid_keys = ["Cell", "Atoms", "LeBail"]
     1369        return key in valid_keys
     1370
     1371    @staticmethod
     1372    def is_valid_HAP_refinement_key(key):
     1373        valid_keys = ["Babinet", "Extinction", "HStrain", "Mustrain",
     1374                      "Pref.Ori.", "Show", "Size", "Use", "Scale"]
    13561375        return key in valid_keys
    13571376
Note: See TracChangeset for help on using the changeset viewer.