Changeset 3123


Ignore:
Timestamp:
Oct 5, 2017 3:00:45 PM (6 years ago)
Author:
toby
Message:

do update when load of binaries fails; improve docs and bug fixes in G2scriptable

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASII.py

    r3000 r3123  
    2323
    2424if __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()
    2639    GSASIIpath.SetVersionNumber("$Revision$")
    2740    GSASIIpath.InvokeDebugOpts()
  • trunk/GSASIIpath.py

    r3093 r3123  
    325325    return changed
    326326
    327 def svnUpdateDir(fpath=os.path.split(__file__)[0],version=None):
     327def svnUpdateDir(fpath=os.path.split(__file__)[0],version=None,verbose=True):
    328328    '''This performs an update of the files in a local directory from a server.
    329329
     
    341341    else:
    342342        verstr = '-rHEAD'
     343    if verbose: print(u"Updating files at "+fpath)
    343344    cmd = [svn,'update',fpath,verstr,
    344345           '--non-interactive',
     
    347348        cmd += ['--trust-server-cert']
    348349    if proxycmds: cmd += proxycmds
     350    if verbose:
     351        s = 'subversion command:\n  '
     352        for i in cmd: s += i + ' '
     353        print(s)
    349354    s = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    350355    out,err = s.communicate()
    351356    if err:
    352357        print(60*"=")
    353         print ("****** An error was noted, see below *********")
     358        print("****** An error was noted, see below *********")
    354359        print(60*"=")
    355         print err
     360        print(err)
    356361        sys.exit()
     362    elif verbose:
     363        print(out)
    357364
    358365def svnUpgrade(fpath=os.path.split(__file__)[0]):
  • trunk/GSASIIscriptable.py

    r3102 r3123  
    1313
    1414Routines 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` to
    17 show the available subcommands, and inspect each subcommand with
    18 `python GSASIIscriptable.py <subcommand> --help`.
    19 
    2015This file specifies several wrapper classes around GSAS-II data representations.
    2116They all inherit from :class:`G2ObjectWrapper`. The chief class is :class:`G2Project`,
    2217which represents an entire GSAS-II project and provides several methods to access
    2318phases, powder histograms, and execute Rietveld refinements.
     19These routines can be accessed either by directly calling these routines
     20or via a command line interface. Run::
     21
     22   python GSASIIscriptable.py --help
     23
     24to show the available subcommands, and inspect each subcommand with
     25`python GSASIIscriptable.py <subcommand> --help`.
     26
    2427
    2528.. _Refinement_parameters_kinds:
     
    2932=====================
    3033
    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`.
     34Note 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
     60There are several ways to set parameters using different objects, as described below,
     61
     62------------------------
     63Histogram/Phase objects
     64------------------------
     65Each histogram and phase has an object.
     66Parameters within each individual object can be turned on and off by calling
     67:meth:`G2PwdrData.set_refinements` or :meth:`G2PwdrData.clear_refinements`
     68for histogram parameters;
     69:meth:`G2Phase.set_refinements` or :meth:`G2Phase.clear_refinements`
     70for 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
     80Likewise 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
     87and to turn these refinement flags, off use this (Note that the
     88``.clear_refinements()`` methods will usually will turn off refinement even
     89if 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
     96For 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
     107and 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
     118Note that the parameters must match the object type and method (phase vs. histogram vs. HAP).
     119
     120------------------------
     121Project objects
     122------------------------
     123It is also possible to create a composite dictionary containing parameters of any type.
     124In this case dictionaries are nested with keys at the outer level of "set" and "clear"
     125to specify which function is used with function :meth:`G2Project.set_refinement`. Note
     126that 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.
     128As 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------------------------
     139Refinement recipe
     140------------------------
     141Finally, it is possible to specify a sequence of refinement actions as a list of dicts.
     142Note in the following example, the list contains a set of dicts, each defined as before.
     143It is not possible to specify different actions for differing phases or histograms
     144with this method. Note that a
     145separate refinement step will be performed for each element in the list.
     146An 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   
     168Note 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
     169call:
     170
     171.. code-block::  python
     172
     173    my_project.do_refinements([])
     174
     175
    42176
    43177============================
     
    57191This table describes the dictionaries supplied to :func:`G2PwdrData.set_refinements`
    58192and :func:`G2PwdrData.clear_refinements`.
    59 
    60 Example:
    61 
    62 .. code-block::  python
    63 
    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'])
    70193
    71194.. tabularcolumns:: |l|l|p{3.5in}|
     
    115238and :func:`G2Phase.clear_refinements`.
    116239
    117 Example:
    118 
    119 .. code-block::  python
    120 
    121     params = { 'LeBail': True, 'Cell': True,
    122                'Atoms': { 'Mn1': 'X',
    123                           'O3': 'XU',
    124                           'V4': 'FXU'}}
    125     some_histogram.set_refinements(params)
    126 
    127240.. tabularcolumns:: |l|p{4.5in}|
    128241
     
    150263and :func:`G2Phase.clear_HAP_refinements`.
    151264
    152 Example:
    153 
    154 .. code-block::  python
    155 
    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 
    163265.. tabularcolumns:: |l|l|p{3.5in}|
    164266
     
    171273\                     BabA
    172274\                     BabU
    173 Extinction                                   Should be boolean, whether or not to
    174                                              refine.
    175 HStrain                                      Should be boolean, whether or not to
    176                                              refine.
     275Extinction                                   Boolean, True to refine.
     276HStrain                                      Boolean, True to refine all appropriate
     277                                             $D_ij$ terms.
    177278Mustrain
    178279\                     type                   Mustrain model. One of 'isotropic',
     
    240341def LoadDictFromProjFile(ProjFile):
    241342    '''Read a GSAS-II project file and load items to dictionary
     343   
    242344    :param str ProjFile: GSAS-II project (name.gpx) full file name
    243345    :returns: Project,nameList, where
    244346
    245       * Project (dict) is a representation of gpx file following the GSAS-II tree struture
     347      * Project (dict) is a representation of gpx file following the GSAS-II tree structure
    246348        for each item: key = tree name (e.g. 'Controls','Restraints',etc.), data is dict
    247349        data dict = {'data':item data whch may be list, dict or None,'subitems':subdata (if any)}
     
    335437    :param str filename: full name of powder data file; can be "multi-Bank" data
    336438
    337     :returns list rdlist: list of reader objects containing powder data, one for each
     439    :returns: list rdlist: list of reader objects containing powder data, one for each
    338440        "Bank" of data encountered in file. Items in reader object of interest are:
    339441
     
    11981300        logging of intermediate results.
    11991301
     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           
    12001310        >>> def checked_refinements(proj):
    12011311        ...     for p in proj.iter_refinements(refs):
     
    12071317        ...             raise Exception("I need a human!")
    12081318
    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           
    12141320        """
    12151321        if outputnames:
     
    12431349        """Apply specified refinements to a given histogram(s) or phase(s).
    12441350
    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:
    12461366
    12471367        1. Histogram parameters
    12481368        2. Phase parameters
    12491369        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       
    12571371        .. seealso::
    12581372            :meth:`G2PwdrData.set_refinements`
     
    12651379        if histogram == 'all':
    12661380            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)
    12671388        elif isinstance(histogram, str) or isinstance(histogram, int):
    12681389            hists = [self.histogram(histogram)]
    12691390        else:
    1270             hists = [self.histogram(name) for name in histogram]
     1391            hists = [histogram]
    12711392
    12721393        if phase == 'all':
    12731394            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)
    12741402        elif isinstance(phase, str) or isinstance(phase, int):
    12751403            phases = [self.phase(phase)]
    12761404        else:
    1277             phases = [self.phase(name) for name in phase]
     1405            phases = [phase]
    12781406
    12791407        # TODO: HAP parameters:
     
    20262154                elif key == 'HStrain':
    20272155                    for h in histograms:
    2028                         hist['HStrain'][1] = [bool(val) for p in hist['Hstrain'][0]]
     2156                        h['HStrain'][1] = [bool(val) for p in h['HStrain'][1]]
    20292157                elif key == 'Mustrain':
    20302158                    for h in histograms:
     
    20912219                    for h in histograms:
    20922220                        h['Scale'][1] = bool(val)
     2221                else:
     2222                    print(u'Unknown HAP key: '+key)
    20932223
    20942224    def clear_HAP_refinements(self, refs, histograms='all'):
     
    21252255                elif key == 'HStrain':
    21262256                    for h in histograms:
    2127                         hist['HStrain'][1] = [False for p in hist['Hstrain'][0]]
     2257                        h['HStrain'][1] = [False for p in h['HStrain'][1]]
    21282258                elif key == 'Mustrain':
    21292259                    for h in histograms:
     
    21452275                    for h in histograms:
    21462276                        h['Scale'][1] = False
     2277                else:
     2278                    print(u'Unknown HAP key: '+key)
    21472279
    21482280
Note: See TracChangeset for help on using the changeset viewer.