Changeset 3085


Ignore:
Timestamp:
Sep 19, 2017 12:12:48 PM (6 years ago)
Author:
odonnell
Message:

removed comments, started documenting refinement specifiers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIscriptable.py

    r3069 r3085  
    3030    * Histogram-and-phase (HAP). Turned on and off through
    3131      :func:`~G2Phase.set_HAP_refinements` and :func:`~G2Phase.clear_HAP_refinements`
     32
     33
     34============================
     35Refinement specifiers format
     36============================
     37
     38.. _Histogram_parameters_table:
     39
     40--------------------
     41Histogram parameters
     42--------------------
     43
     44This table describes the dictionaries supplied to :func:`~G2PwdrData.set_refinement`
     45and :func:`~G2PwdrData.clear_refinement`.
     46
     47.. tabularcolumns:: |l|p|
     48
     49===================== ====================  ====================
     50key                   subkey                explanation
     51===================== ====================  ====================
     52Limits                                      The 2-theta range of values to consider. Can
     53                                            be either a dictionary of 'low' and 'high',
     54                                            or a list of 2 items [low, high]
     55\                     low                   Sets the low limit
     56\                     high                  Sets the high limit
     57Sample Parameters                           Should be provided as a **list** of subkeys
     58                                            to set or clear, e.g. ['DisplaceX', 'Scale']
     59\                     Absorption
     60\                     Contrast
     61\                     DisplaceX             Sample displacement along the X direction
     62\                     DisplaceY             Sample displacement along the Y direction
     63\                     Scale                 Histogram Scale factor
     64Background                                  Sample background. If value is a boolean,
     65                                            the background's 'refine' parameter is set
     66                                            to the given boolean. Usually should be a
     67                                            dictionary with any of the following keys:
     68\                     type                  The background model, e.g. 'chebyschev'
     69\                     refine                The value of the refine flag, boolean
     70\                     no. coeffs            Number of coefficients to use, integer
     71\                     coeffs                List of floats, literal values for background
     72\                     FixedPoints           List of (2-theta, intensity) values for fixed points
     73\                     fit fixed points      If True, triggers a fit to the fixed points to be calculated. It is calculated when this key is detected, regardless of calls to refine.
     74Instrument Parameters                       As in Sample Paramters, Should be provided as a **list** of subkeys to
     75                                            set or clear, e.g. ['X', 'Y', 'Zero', 'SH/L']
     76\                     U, V, W               All separate keys. Gaussian peak profile terms
     77\                     X, Y                  Separate keys. Lorentzian peak profile terms
     78\                     Zero                  Zero shift
     79\                     SH/L
     80\                     Polariz.              Polarization parameter
     81\                     Lam                   Lambda, the incident wavelength
     82===================== ====================  ====================
     83
     84
     85.. _Phase_parameters_table:
     86
     87----------------
     88Phase parameters
     89----------------
     90
     91This table describes the dictionaries supplied to :func:`~G2Phase.set_refinement`
     92and :func:`~G2Phase.clear_refinement`.
     93
     94
     95.. _HAP_parameters_table:
     96
     97------------------------------
     98Histogram-and-phase parameters
     99------------------------------
     100
     101This table describes the dictionaries supplied to :func:`~G2Phase.set_HAP_refinement`
     102and :func:`~G2Phase.clear_HAP_refinement`.
     103
     104
     105============================
     106Scriptable API
     107============================
    32108"""
    33109from __future__ import division, print_function # needed?
     
    720796        SaveDictToProjFile(self.data, self.names, self.filename)
    721797
    722     def add_powder_histogram(self, datafile, iparams):
     798    def add_powder_histogram(self, datafile, iparams, phases=[]):
    723799        """Loads a powder data histogram into the project.
    724800
     
    728804        :param str datafile: The powder data file to read, a filename.
    729805        :param str iparams: The instrument parameters file, a filename.
     806        :param list phases: Phases to link to the new histogram
    730807
    731808        :returns: A :class:`G2PwdrData` object representing
     
    741818        if histname in self.data:
    742819            print("Warning - redefining histogram", histname)
     820        elif self.names[-1][0] == 'Phases':
     821            self.names.insert(-1, new_names)
    743822        else:
    744             if self.names[-1][0] == 'Phases':
    745                 self.names.insert(-1, new_names)
    746             else:
    747                 self.names.append(new_names)
     823            self.names.append(new_names)
    748824        self.data[histname] = pwdrdata
    749825        self.update_ids()
     826
     827        for phase in phases:
     828            phase = self.phase(phase)
     829            self.link_histogram_phase(histname, phase)
     830
    750831        return self.histogram(histname)
    751832
     
    803884        for hist in histograms:
    804885            self.link_histogram_phase(hist, phasename)
    805             # if histname.startswith('HKLF '):
    806             #     raise NotImplementedError("Does not support HKLF yet")
    807             # elif histname.startswith('PWDR '):
    808             #     hist = self.histogram(histname)
    809             #     hist['Reflection Lists'][generalData['Name']] = {}
    810             #     UseList[histname] = SetDefaultDData('PWDR', histname, NShkl=NShkl, NDij=NDij)
    811             #     for key, val in [('Use', True), ('LeBail', False),
    812             #                      ('newLeBail', True),
    813             #                      ('Babinet', {'BabA': [0.0, False],
    814             #                                   'BabU': [0.0, False]})]:
    815             #         if key not in UseList[histname]:
    816             #             UseList[histname][key] = val
    817             # else:
    818             #     raise NotImplementedError("Unexpected histogram" + histname)
    819886
    820887        for obj in self.names:
     
    11541221            string variable specifiers, or arguments for :meth:`make_var_obj`
    11551222        :param str type: A string constraint type specifier. See
    1156         :class:`~GSASIIscriptable.G2Project.add_constraint_raw`"""
     1223            :class:`~GSASIIscriptable.G2Project.add_constraint_raw`
     1224
     1225        """
    11571226        for var in vars:
    11581227            if isinstance(var, str):
     
    14181487        """Sets the refinement parameter 'key' to the specification 'value'
    14191488
    1420         :param dict refs: A dictionary of the parameters to be set.
    1421 
    1422         :returns: None"""
     1489        :param dict refs: A dictionary of the parameters to be set. See
     1490                          :ref:`Histogram_parameters_table` for a description of
     1491                          what these dictionaries should be.
     1492
     1493        :returns: None
     1494
     1495        """
    14231496        do_fit_fixed_points = False
    14241497        for key, value in refs.items():
     
    14361509                sample = self.data['Sample Parameters']
    14371510                for sparam in value:
     1511                    if sparam not in sample:
     1512                        raise ValueError("Unknown refinement parameter, "
     1513                                         + str(sparam))
    14381514                    sample[sparam][1] = True
    14391515            elif key == 'Background':
     
    15971673        .. seealso::
    15981674           :func:`~G2Phase.get_cell_and_esd`
     1675
    15991676        """
    16001677        cell = self.data['General']['Cell']
     
    16091686
    16101687        :returns: a tuple of two dictionaries
     1688
    16111689        .. seealso::
    16121690           :func:`~G2Phase.get_cell`
     1691
    16131692        """
    16141693        # translated from GSASIIstrIO.ExportBaseclass.GetCell
     
    17311810        """Sets the refinement parameter 'key' to the specification 'value'
    17321811
    1733         :param dict refs: A dictionary of the parameters to be set.
     1812        :param dict refs: A dictionary of the parameters to be set. See
     1813                          :ref:`Phase_parameters_table` for a description of
     1814                          this dictionary.
    17341815
    17351816        :returns: None"""
     
    17461827                    else:
    17471828                        atom = self.atom(atomlabel)
     1829                        if atom is None:
     1830                            raise ValueError("No such atom: " + atomlabel)
    17481831                        atom.refinement_flags = atomrefinement
    17491832            elif key == "LeBail":
     
    17831866        the given histograms
    17841867
    1785         :param dict refs: A dictionary of the parameters to be set.
     1868        :param dict refs: A dictionary of the parameters to be set. See
     1869                          :ref:`HAP_parameters_table` for a description of this
     1870                          dictionary.
    17861871        :param histograms: Either 'all' (default) or a list of the histograms
    17871872            whose HAP parameters will be set with this phase. Histogram and phase
     
    18171902                        mustrain = h['Mustrain']
    18181903                        newType = None
    1819                         if isinstance(val, str):
     1904                        if isinstance(val, (unicode, str)):
    18201905                            if val in ['isotropic', 'uniaxial', 'generalized']:
    18211906                                newType = val
     
    18321917                                mustrain[5] = [False for p in mustrain[4]]
    18331918                            elif newType == 'uniaxial':
    1834                                 pass
     1919                                if 'refine' in val:
     1920                                    types = val['refine']
     1921                                    if isinstance(types, (unicode, str)):
     1922                                        types = [types]
     1923                                else:
     1924                                    types = []
     1925
     1926                                for unitype in types:
     1927                                    if unitype == 'equatorial':
     1928                                        mustrain[2][0] = True
     1929                                    elif unitype == 'axial':
     1930                                        mustrain[2][1] = True
     1931                                    else:
     1932                                        msg = 'Invalid uniaxial mustrain type'
     1933                                        raise ValueError(msg + ': ' + unitype)
    18351934                            else:  # newtype == 'generalized'
    18361935                                mustrain[2] = [False for p in mustrain[1]]
     1936
    18371937                        if direction:
    18381938                            direction = [int(n) for n in direction]
Note: See TracChangeset for help on using the changeset viewer.