Changeset 3123
- Timestamp:
- Oct 5, 2017 3:00:45 PM (6 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASII.py
r3000 r3123 23 23 24 24 if __name__ == '__main__': 25 GSASIIpath.SetBinaryPath() 25 try: 26 GSASIIpath.SetBinaryPath() 27 except: 28 print('Unable to run with current setup, do you want to update to the') 29 try: 30 ans = raw_input("latest GSAS-II version? Update ([Yes]/no): ") 31 except: 32 ans = 'no' 33 if ans.strip().lower() == "no": 34 import sys 35 print('Exiting') 36 sys.exit() 37 print('Updating...') 38 GSASIIpath.svnUpdateProcess() 26 39 GSASIIpath.SetVersionNumber("$Revision$") 27 40 GSASIIpath.InvokeDebugOpts() -
trunk/GSASIIpath.py
r3093 r3123 325 325 return changed 326 326 327 def svnUpdateDir(fpath=os.path.split(__file__)[0],version=None ):327 def svnUpdateDir(fpath=os.path.split(__file__)[0],version=None,verbose=True): 328 328 '''This performs an update of the files in a local directory from a server. 329 329 … … 341 341 else: 342 342 verstr = '-rHEAD' 343 if verbose: print(u"Updating files at "+fpath) 343 344 cmd = [svn,'update',fpath,verstr, 344 345 '--non-interactive', … … 347 348 cmd += ['--trust-server-cert'] 348 349 if proxycmds: cmd += proxycmds 350 if verbose: 351 s = 'subversion command:\n ' 352 for i in cmd: s += i + ' ' 353 print(s) 349 354 s = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE) 350 355 out,err = s.communicate() 351 356 if err: 352 357 print(60*"=") 353 print 358 print("****** An error was noted, see below *********") 354 359 print(60*"=") 355 print err360 print(err) 356 361 sys.exit() 362 elif verbose: 363 print(out) 357 364 358 365 def svnUpgrade(fpath=os.path.split(__file__)[0]): -
trunk/GSASIIscriptable.py
r3102 r3123 13 13 14 14 Routines for reading, writing, modifying and creating GSAS-II project (.gpx) files. 15 16 Supports a command line interface as well. Run `python GSASIIscriptable.py --help` to17 show the available subcommands, and inspect each subcommand with18 `python GSASIIscriptable.py <subcommand> --help`.19 20 15 This file specifies several wrapper classes around GSAS-II data representations. 21 16 They all inherit from :class:`G2ObjectWrapper`. The chief class is :class:`G2Project`, 22 17 which represents an entire GSAS-II project and provides several methods to access 23 18 phases, powder histograms, and execute Rietveld refinements. 19 These routines can be accessed either by directly calling these routines 20 or via a command line interface. Run:: 21 22 python GSASIIscriptable.py --help 23 24 to show the available subcommands, and inspect each subcommand with 25 `python GSASIIscriptable.py <subcommand> --help`. 26 24 27 25 28 .. _Refinement_parameters_kinds: … … 29 32 ===================== 30 33 31 There are three types of refinement parameters: 32 33 * Histogram: These can be turned on and off through 34 :meth:`G2PwdrData.set_refinements` and :func:`G2PwdrData.clear_refinements` 35 * Phase: Turned on and off through :func:`G2Phase.set_refinements` 36 and :func:`G2Phase.clear_refinements` 37 * Histogram-and-phase (HAP): Turned on and off through 38 :func:`G2Phase.set_HAP_refinements` and :func:`G2Phase.clear_HAP_refinements` 39 40 These parameters can be combined and set by :meth:`G2Project.do_refinements` 41 or :meth:`G2Project.set_refinement`. 34 Note that parameters and refinement flags used in GSAS-II fall into three classes: 35 36 * **Histogram**: There will be a set of these for each dataset loaded into a 37 project file. The parameters available depend on the type of histogram 38 (Bragg-Brentano, Single-Crystal, TOF,...). Typical Histogram parameters 39 include the overall scale factor, background, instrument and sample parameters; 40 see the :ref:`Histogram_parameters_table` table for a list of the histogram 41 parameters where access has been provided. 42 43 * **Phase**: There will be a set of these for each phase loaded into a 44 project file. While some parameters are found in all types of phases, 45 others are only found in certain types (modulated, magnetic, protein...). 46 Typical phase parameters include unit cell lengths and atomic positions; see the 47 :ref:`Phase_parameters_table` table for a list of the phase 48 parameters where access has been provided. 49 50 * **Histogram-and-phase** (HAP): There is a set of these for every histogram 51 that is associated with each phase, so that if there are ``N`` phases and ``M`` 52 histograms, there can be ``N*M`` total sets of "HAP" parameters sets (fewer if all 53 histograms are not linked to all phases.) Typical HAP parameters include the 54 phase fractions, sample microstrain and crystallite size broadening terms, 55 hydrostatic strain pertibations of the unit cell and preferred orientation 56 values. 57 See the :ref:`HAP_parameters_table` table for the HAP parameters where access has 58 been provided. 59 60 There are several ways to set parameters using different objects, as described below, 61 62 ------------------------ 63 Histogram/Phase objects 64 ------------------------ 65 Each histogram and phase has an object. 66 Parameters within each individual object can be turned on and off by calling 67 :meth:`G2PwdrData.set_refinements` or :meth:`G2PwdrData.clear_refinements` 68 for histogram parameters; 69 :meth:`G2Phase.set_refinements` or :meth:`G2Phase.clear_refinements` 70 for phase parameters; and :meth:`G2Phase.set_HAP_refinements` or 71 :meth:`G2Phase.clear_HAP_refinements`. As an example, if some_histogram is a histogram object (of type :class:`G2PwdrData`), use this to set parameters in that histogram: 72 73 .. code-block:: python 74 75 params = { 'Limits': [0.8, 12.0], 76 'Sample Parameters': ['Absorption', 'Contrast', 'DisplaceX'], 77 'Background': {'type': 'chebyschev', 'refine': True} 78 some_histogram.set_refinements(params) 79 80 Likewise to turn refinement flags on, use code such as this: 81 82 .. code-block:: python 83 84 params = { 'Instrument Parameters': ['U', 'V', 'W']} 85 some_histogram.set_refinements(params) 86 87 and to turn these refinement flags, off use this (Note that the 88 ``.clear_refinements()`` methods will usually will turn off refinement even 89 if a refinement parameter is set in the dict to True.): 90 91 .. code-block:: python 92 93 params = { 'Instrument Parameters': ['U', 'V', 'W']} 94 some_histogram.clear_refinements(params) 95 96 For phase parameters, use code such as this: 97 98 .. code-block:: python 99 100 params = { 'LeBail': True, 'Cell': True, 101 'Atoms': { 'Mn1': 'X', 102 'O3': 'XU', 103 'V4': 'FXU'}} 104 some_histogram.set_refinements(params) 105 106 107 and here is an example for HAP parameters: 108 109 .. code-block:: python 110 111 params = { 'Babinet': 'BabA', 112 'Extinction': True, 113 'Mustrain': { 'type': 'uniaxial', 114 'direction': [0, 0, 1], 115 'refine': True}} 116 some_phase.set_HAP_refinements(params) 117 118 Note that the parameters must match the object type and method (phase vs. histogram vs. HAP). 119 120 ------------------------ 121 Project objects 122 ------------------------ 123 It is also possible to create a composite dictionary containing parameters of any type. 124 In this case dictionaries are nested with keys at the outer level of "set" and "clear" 125 to specify which function is used with function :meth:`G2Project.set_refinement`. Note 126 that optionally a list of histograms and/or phases can be supplied to 127 :meth:`G2Project.set_refinement`, where the default is to use all phases and histograms. 128 As an example: 129 130 .. code-block:: python 131 132 pardict = {'set': { 'Limits': [0.8, 12.0], 133 'Sample Parameters': ['Absorption', 'Contrast', 'DisplaceX'], 134 'Background': {'type': 'chebyschev', 'refine': True}}, 135 'clear': {'Instrument Parameters': ['U', 'V', 'W']}} 136 my_project.set_refinement(pardict) 137 138 ------------------------ 139 Refinement recipe 140 ------------------------ 141 Finally, it is possible to specify a sequence of refinement actions as a list of dicts. 142 Note in the following example, the list contains a set of dicts, each defined as before. 143 It is not possible to specify different actions for differing phases or histograms 144 with this method. Note that a 145 separate refinement step will be performed for each element in the list. 146 An example follows: 147 148 .. code-block:: python 149 150 reflist = [ 151 {"set": { "Limits": { "low": 0.7 }, 152 "Background": { "no. coeffs": 3, 153 "refine": True }}}, 154 {"set": { "LeBail": True, 155 "Cell": True }}, 156 {"set": { "Sample Parameters": ["DisplaceX"]}}, 157 {"set": { "Instrument Parameters": ["U", "V", "W", "X", "Y"]}}, 158 {"set": { "Mustrain": { "type": "uniaxial", 159 "refine": "equatorial", 160 "direction": [0, 0, 1]}}}, 161 {"set": { "Mustrain": { "type": "uniaxial", 162 "refine": "axial"}}}, 163 {"clear": { "LeBail": True}, 164 "set": { "Atoms": { "Mn": "X" }}}, 165 {"set": { "Atoms": { "O1": "X", "O2": "X" }}},] 166 my_project.do_refinements(reflist) 167 168 Note that in the second from last refinement step (``reflist[6]``), parameters are both set and cleared. To perform a single refinement without changing any parameters, use this 169 call: 170 171 .. code-block:: python 172 173 my_project.do_refinements([]) 174 175 42 176 43 177 ============================ … … 57 191 This table describes the dictionaries supplied to :func:`G2PwdrData.set_refinements` 58 192 and :func:`G2PwdrData.clear_refinements`. 59 60 Example:61 62 .. code-block:: python63 64 params = {'set': { 'Limits': [0.8, 12.0],65 'Sample Parameters': ['Absorption', 'Contrast', 'DisplaceX'],66 'Background': {'type': 'chebyschev', 'refine': True}},67 'clear': {'Instrument Parameters': ['U', 'V', 'W']}}68 some_histogram.set_refinements(params['set'])69 some_histogram.clear_refinements(params['clear'])70 193 71 194 .. tabularcolumns:: |l|l|p{3.5in}| … … 115 238 and :func:`G2Phase.clear_refinements`. 116 239 117 Example:118 119 .. code-block:: python120 121 params = { 'LeBail': True, 'Cell': True,122 'Atoms': { 'Mn1': 'X',123 'O3': 'XU',124 'V4': 'FXU'}}125 some_histogram.set_refinements(params)126 127 240 .. tabularcolumns:: |l|p{4.5in}| 128 241 … … 150 263 and :func:`G2Phase.clear_HAP_refinements`. 151 264 152 Example:153 154 .. code-block:: python155 156 params = { 'Babinet': 'BabA',157 'Extinction': True,158 'Mustrain': { 'type': 'uniaxial',159 'direction': [0, 0, 1],160 'refine': True}}161 some_phase.set_HAP_refinements(params)162 163 265 .. tabularcolumns:: |l|l|p{3.5in}| 164 266 … … 171 273 \ BabA 172 274 \ BabU 173 Extinction Should be boolean, whether or not to 174 refine. 175 HStrain Should be boolean, whether or not to 176 refine. 275 Extinction Boolean, True to refine. 276 HStrain Boolean, True to refine all appropriate 277 $D_ij$ terms. 177 278 Mustrain 178 279 \ type Mustrain model. One of 'isotropic', … … 240 341 def LoadDictFromProjFile(ProjFile): 241 342 '''Read a GSAS-II project file and load items to dictionary 343 242 344 :param str ProjFile: GSAS-II project (name.gpx) full file name 243 345 :returns: Project,nameList, where 244 346 245 * Project (dict) is a representation of gpx file following the GSAS-II tree stru ture347 * Project (dict) is a representation of gpx file following the GSAS-II tree structure 246 348 for each item: key = tree name (e.g. 'Controls','Restraints',etc.), data is dict 247 349 data dict = {'data':item data whch may be list, dict or None,'subitems':subdata (if any)} … … 335 437 :param str filename: full name of powder data file; can be "multi-Bank" data 336 438 337 :returns list rdlist: list of reader objects containing powder data, one for each439 :returns: list rdlist: list of reader objects containing powder data, one for each 338 440 "Bank" of data encountered in file. Items in reader object of interest are: 339 441 … … 1198 1300 logging of intermediate results. 1199 1301 1302 :param list refinements: A list of dictionaries defining refinements 1303 :param str histogram: Name of histogram for refinements to be applied 1304 to, a list of histograms or 'all'. 1305 See :func:`set_refinement` for more details 1306 :param str phase: Name of phase for refinements to be applied to, a 1307 list of phases or 'all'. 1308 See :func:`set_refinement` for more details 1309 1200 1310 >>> def checked_refinements(proj): 1201 1311 ... for p in proj.iter_refinements(refs): … … 1207 1317 ... raise Exception("I need a human!") 1208 1318 1209 :param list refinements: A list of dictionaries defining refinements 1210 :param str histogram: Name of histogram for refinements to be applied 1211 to, or 'all' 1212 :param str phase: Name of phase for refinements to be applied to, or 1213 'all' 1319 1214 1320 """ 1215 1321 if outputnames: … … 1243 1349 """Apply specified refinements to a given histogram(s) or phase(s). 1244 1350 1245 Refinement parameters are categorize in three groups: 1351 :param dict refinement: The refinements to be conducted 1352 :param histogram: Specifies either 'all' (default), a single histogram or 1353 a list of histograms. Histograms may be specified as histogram objects 1354 (see :class:`G2PwdrData`), the histogram name (str) or the index number (int) 1355 of the histogram in the project, numbered starting from 0. 1356 Omitting the parameter or the string 'all' indicates that parameters in 1357 all histograms should be set. 1358 :param phase: Specifies either 'all' (default), a single phase or 1359 a list of phases. Phases may be specified as phase objects 1360 (see :class:`G2Phase`), the phase name (str) or the index number (int) 1361 of the phase in the project, numbered starting from 0. 1362 Omitting the parameter or the string 'all' indicates that parameters in 1363 all phases should be set. 1364 1365 Note that refinement parameters are categorized as one of three types: 1246 1366 1247 1367 1. Histogram parameters 1248 1368 2. Phase parameters 1249 1369 3. Histogram-and-Phase (HAP) parameters 1250 1251 :param dict refinement: The refinements to be conducted 1252 :param histogram: Either a name of a histogram (str), a list of 1253 histogram names, or 'all' (default) 1254 :param phase: Either a name of a phase (str), a list of phase names, or 1255 'all' (default) 1256 1370 1257 1371 .. seealso:: 1258 1372 :meth:`G2PwdrData.set_refinements` … … 1265 1379 if histogram == 'all': 1266 1380 hists = self.histograms() 1381 elif isinstance(histogram, list) or isinstance(histogram, tuple): 1382 hists = [] 1383 for h in histogram: 1384 if isinstance(h, str) or isinstance(h, int): 1385 hists.append(self.histogram(h)) 1386 else: 1387 hists.append(h) 1267 1388 elif isinstance(histogram, str) or isinstance(histogram, int): 1268 1389 hists = [self.histogram(histogram)] 1269 1390 else: 1270 hists = [ self.histogram(name) for name inhistogram]1391 hists = [histogram] 1271 1392 1272 1393 if phase == 'all': 1273 1394 phases = self.phases() 1395 elif isinstance(phase, list) or isinstance(phase, tuple): 1396 phases = [] 1397 for ph in phase: 1398 if isinstance(ph, str) or isinstance(ph, int): 1399 phases.append(self.phase(ph)) 1400 else: 1401 phases.append(ph) 1274 1402 elif isinstance(phase, str) or isinstance(phase, int): 1275 1403 phases = [self.phase(phase)] 1276 1404 else: 1277 phases = [ self.phase(name) for name inphase]1405 phases = [phase] 1278 1406 1279 1407 # TODO: HAP parameters: … … 2026 2154 elif key == 'HStrain': 2027 2155 for h in histograms: 2028 h ist['HStrain'][1] = [bool(val) for p in hist['Hstrain'][0]]2156 h['HStrain'][1] = [bool(val) for p in h['HStrain'][1]] 2029 2157 elif key == 'Mustrain': 2030 2158 for h in histograms: … … 2091 2219 for h in histograms: 2092 2220 h['Scale'][1] = bool(val) 2221 else: 2222 print(u'Unknown HAP key: '+key) 2093 2223 2094 2224 def clear_HAP_refinements(self, refs, histograms='all'): … … 2125 2255 elif key == 'HStrain': 2126 2256 for h in histograms: 2127 h ist['HStrain'][1] = [False for p in hist['Hstrain'][0]]2257 h['HStrain'][1] = [False for p in h['HStrain'][1]] 2128 2258 elif key == 'Mustrain': 2129 2259 for h in histograms: … … 2145 2275 for h in histograms: 2146 2276 h['Scale'][1] = False 2277 else: 2278 print(u'Unknown HAP key: '+key) 2147 2279 2148 2280
Note: See TracChangeset
for help on using the changeset viewer.