Changeset 4005


Ignore:
Timestamp:
May 30, 2019 5:24:34 PM (4 years ago)
Author:
toby
Message:

improve scripting for HAP vars; minor doc changes

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIplot.py

    r4004 r4005  
    2424:func:`PlotStructure`         Crystal structure plotting with balls, sticks, lines,
    2525                              ellipsoids, polyhedra and magnetic moments
    26 :func:'Plot1DSngl'            1D stick plots of structure factors                             
     26:func:`Plot1DSngl`            1D stick plots of structure factors                             
    2727:func:`PlotSngl`              Structure factor plotting
    2828:func:`Plot3DSngl`            3D Structure factor plotting
  • trunk/GSASIIscriptable.py

    r4003 r4005  
    131131:meth:`G2Project.set_refinement`                      This is passed a single dict which is used to set parameters and flags.
    132132                                                      These actions can be performed also in :meth:`G2Project.do_refinements`.
    133 :meth:`G2Project.get_Variable'                        Retrieves the value and esd for a parameter
    134 :meth:`G2Project.get_Covariance'                      Retrieves values and covariance for a set of refined parameters
     133:meth:`G2Project.get_Variable`                        Retrieves the value and esd for a parameter
     134:meth:`G2Project.get_Covariance`                      Retrieves values and covariance for a set of refined parameters
     135:meth:`G2Project.set_Controls`                        Set overall GSAS-II control settings such as number of cycles and to set up a sequential
     136                                                      fit. (Also see :meth:`G2Project.get_Controls` to read values.)
    135137==================================================    ===============================================================================================================
    136138
     
    161163:meth:`G2Phase.get_cell`                              Returns unit cell parameters (also see :meth:`G2Phase.get_cell_and_esd`)
    162164:meth:`G2Phase.export_CIF`                            Writes a CIF for the phase
    163 :meth:`G2Phase.set_Controls`                          Set overall GSAS-II control settings such as number of cycles and to set up a sequential
    164                                                       fit. (Also see :meth:`G2Phase.get_Controls` to read values.)
    165165==================================================    ===============================================================================================================
    166166
     
    242242:meth:`G2SeqRefRes.histograms`                         Provides a list of histograms used in the Sequential Refinement
    243243:meth:`G2SeqRefRes.get_cell_and_esd`                   Returns cell dimensions and standard uncertainies for a phase and histogram from the Sequential Refinement
    244 :meth:`G2SeqRefRes.get_Variable'                       Retrieves the value and esd for a parameter from a particular histogram in the Sequential Refinement
    245 :meth:`G2SeqRefRes.get_Covariance'                     Retrieves values and covariance for a set of refined parameters for a particular histogram
     244:meth:`G2SeqRefRes.get_Variable`                       Retrieves the value and esd for a parameter from a particular histogram in the Sequential Refinement
     245:meth:`G2SeqRefRes.get_Covariance`                     Retrieves values and covariance for a set of refined parameters for a particular histogram
    246246==================================================    ===============================================================================================================
    247247
     
    33663366
    33673367    def histograms(self):
    3368         '''Returns a list of histogram names associated with the current phase.
    3369         '''
    3370         output = []
    3371         for hname in self.data.get('Histograms', {}).keys():
    3372             output.append(self.proj.histogram(hname))
    3373         return output
     3368        '''Returns a list of histogram names associated with the current phase ordered
     3369        as they appear in the tree (see :meth:`G2Project.histograms`).
     3370        '''
     3371        return [i.name for i in self.proj.histograms() if i.name in self.data.get('Histograms', {})]
    33743372
    33753373    @property
     
    35843582
    35853583    def set_HAP_refinements(self, refs, histograms='all'):
    3586         """Sets the given HAP refinement parameters between this phase and
    3587         the given histograms.
     3584        """Sets the given HAP refinement parameters between the current phase and
     3585        the specified histograms.
    35883586
    35893587        :param dict refs: A dictionary of the parameters to be set. See
    35903588                          the :ref:`HAP_parameters_table` table for a description of this
    35913589                          dictionary.
    3592         :param histograms: Either 'all' (default) or a list of the histograms
     3590        :param histograms: Either 'all' (default) or a list of the histograms by index, name
     3591            or object. The index number is relative to all histograms in the tree, not to
     3592            those in the phase.
     3593            Histograms not associated with the current phase will be ignored.
    35933594            whose HAP parameters will be set with this phase. Histogram and phase
    3594             must already be associated
    3595 
     3595            must already be associated.
    35963596        :returns: None
    35973597        """
    3598         if not self.data['Histograms']:
     3598        if not self.data.get('Histograms',[]):
    35993599            print("Error likely: Phase {} has no linked histograms".format(self.name))
    36003600            return
    36013601           
    36023602        if histograms == 'all':
    3603             histograms = self.data['Histograms'].values()
     3603            histograms = self.data['Histograms'].keys()
    36043604        else:
    3605             histograms = [self.data['Histograms'][h.name] for h in histograms
    3606                           if h.name in self.data['Histograms']]
    3607 
     3605            histograms = [self._decodeHist(h) for h in histograms
     3606                          if self._decodeHist(h) in self.data['Histograms']]   
    36083607        if not histograms:
    36093608            print("Skipping HAP set for phase {}, no selected histograms".format(self.name))
     
    36193618                        raise ValueError("Not sure what to do with" + param)
    36203619                    for h in histograms:
    3621                         h['Babinet'][param][1] = True
     3620                        self.data['Histograms'][h]['Babinet'][param][1] = True
    36223621            elif key == 'Extinction':
    36233622                for h in histograms:
    3624                     h['Extinction'][1] = bool(val)
     3623                    self.data['Histograms'][h]['Extinction'][1] = bool(val)
    36253624            elif key == 'HStrain':
    36263625                if isinstance(val,list) or isinstance(val,tuple):
    36273626                    for h in histograms:
    3628                         if len(h['HStrain'][1]) != len(val):
    3629                             raise Exception('Need {} HStrain terms for phase {}'
    3630                                 .format(len(h['HStrain'][1]),self.name))
     3627                        if len(self.data['Histograms'][h]['HStrain'][1]) != len(val):
     3628                            raise Exception('Need {} HStrain terms for phase {} hist {}'
     3629                                .format(len(self.data['Histograms'][h]['HStrain'][1]),self.name,h))
    36313630                        for i,v in enumerate(val):
    3632                             h['HStrain'][1][i] = bool(v)
     3631                            self.data['Histograms'][h]['HStrain'][1][i] = bool(v)
    36333632                else:
    36343633                    for h in histograms:
    3635                         h['HStrain'][1] = [bool(val) for p in h['HStrain'][1]]
     3634                        self.data['Histograms'][h]['HStrain'][1] = [bool(val) for p in self.data['Histograms'][h]['HStrain'][1]]
    36363635            elif key == 'Mustrain':
    36373636                for h in histograms:
    3638                     mustrain = h['Mustrain']
     3637                    mustrain = self.data['Histograms'][h]['Mustrain']
    36393638                    newType = None
    36403639                    direction = None
     
    36923691                    newSize = float(val['value'])
    36933692                for h in histograms:
    3694                     size = h['Size']
     3693                    size = self.data['Histograms'][h]['Size']
    36953694                    newType = None
    36963695                    direction = None
     
    37063705                    if newType:
    37073706                        size[0] = newType
    3708                         refine = True == val.get('refine')
     3707                        refine = bool(val.get('refine'))
    37093708                        if newType == 'isotropic' and refine is not None:
    37103709                            size[2][0] = bool(refine)
     
    37253724            elif key == 'Pref.Ori.':
    37263725                for h in histograms:
    3727                     h['Pref.Ori.'][2] = bool(val)
     3726                    self.data['Histograms'][h]['Pref.Ori.'][2] = bool(val)
    37283727            elif key == 'Show':
    37293728                for h in histograms:
    3730                     h['Show'] = bool(val)
     3729                    self.data['Histograms'][h]['Show'] = bool(val)
    37313730            elif key == 'Use':
    37323731                for h in histograms:
    3733                     h['Use'] = bool(val)
     3732                    self.data['Histograms'][h]['Use'] = bool(val)
    37343733            elif key == 'Scale':
    37353734                for h in histograms:
    3736                     h['Scale'][1] = bool(val)
     3735                    self.data['Histograms'][h]['Scale'][1] = bool(val)
    37373736            else:
    37383737                print(u'Unknown HAP key: '+key)
     
    37543753
    37553754        :param histogram: is a histogram object (:class:`G2PwdrData`) or
    3756             a histogram name or the index number of the histogram
    3757 
     3755            a histogram name or the index number of the histogram.
     3756            The index number is relative to all histograms in the tree, not to
     3757            those in the phase.
    37583758        :returns: HAP value dict
    37593759        """
    37603760        return self.data['Histograms'][self._decodeHist(histname)]
    37613761
    3762     def copyHAPvalues(self, sourcehist, targethistlist, skip=[]):
    3763         """Returns a dict with HAP values for the selected histogram
     3762    def copyHAPvalues(self, sourcehist, targethistlist='all', skip=[], use=None):
     3763        """Copies HAP parameters for one histogram to a list of other histograms.
     3764        Use skip or use to select specific entries to be copied or not used.
    37643765
    37653766        :param sourcehist: is a histogram object (:class:`G2PwdrData`) or
    3766             a histogram name or the index number of the histogram
     3767            a histogram name or the index number of the histogram to copy
     3768            parameters from.
     3769            The index number is relative to all histograms in the tree, not to
     3770            those in the phase.
    37673771        :param list targethistlist: a list of histograms where each item in the
    37683772            list can be a histogram object (:class:`G2PwdrData`),
    37693773            a histogram name or the index number of the histogram.
    3770             if the string 'all', then all histograms in the phase are used.
     3774            If the string 'all' (default), then all histograms in the phase
     3775            are used.
    37713776        :param list skip: items in the HAP dict that should not be
    37723777            copied. The default is an empty list, which causes all items
    37733778            to be copied. To see a list of items in the dict, use
    37743779            :meth:`getHAPvalues` or use an invalid item, such as '?'.
     3780        :param list use: specifies the items in the HAP dict should be
     3781            copied. The default is None, which causes all items
     3782            to be copied.
     3783
     3784        examples::
     3785
     3786            ph0.copyHAPvalues(0,[1,2,3])
     3787            ph0.copyHAPvalues(0,use=['HStrain','Size'])
     3788
     3789        The first example copies all HAP parameters from the first histogram to
     3790        the second, third and fourth histograms (as listed in the project tree).
     3791        The second example copies only the 'HStrain' (Dij parameters and
     3792        refinement flags) and the 'Size' (crystallite size settings, parameters
     3793        and refinement flags) from the first histogram to all histograms.
    37753794        """
    37763795        sourcehist = self._decodeHist(sourcehist)
    37773796        if targethistlist == 'all':
    3778             targethistlist = list(self.data['Histograms'].keys())
     3797            targethistlist = self.histograms()
    37793798       
    37803799        copydict = copy.deepcopy(self.data['Histograms'][sourcehist])
    37813800        for item in skip:
    3782             if item in copydict:
     3801            if item in list(copydict.keys()):
    37833802                del copydict[item]
    37843803            else:
    37853804                print('items in HAP dict are: {}'.format(
    37863805                    list(self.data['Histograms'][sourcehist])))
    3787                 raise Exception('HAP dict entry {} invalid'.format(item))
     3806                raise Exception('HAP skip list entry {} invalid'.format(item))
     3807        if use:
     3808            for item in list(copydict.keys()):
     3809                if item not in use:
     3810                    del copydict[item]
     3811
     3812        print('Copying items {} from histgram {}'.format(list(copydict.keys()),sourcehist))
     3813        print(' to histograms {}'.format([self._decodeHist(h) for h in targethistlist]))
    37883814        for h in targethistlist:
    37893815            h = self._decodeHist(h)
    3790             self.data['Histograms'][h].update(copydict)
     3816            if h not in self.data['Histograms']:
     3817                print('Warning: histogram {} not in phase {}'.format(h,self.name))
     3818                continue
     3819            self.data['Histograms'][h].update(copy.deepcopy(copydict))
    37913820           
    3792         #GSASIIpath.IPyBreak_base()
    3793                    
    37943821    def clear_HAP_refinements(self, refs, histograms='all'):
    37953822        """Clears the given HAP refinement parameters between this phase and
     
    37983825        :param dict refs: A dictionary of the parameters to be cleared.
    37993826            See the the :ref:`HAP_parameters_table` table for what can be specified.
    3800         :param histograms: Either 'all' (default) or a list of the histograms
    3801             whose HAP parameters will be cleared with this phase. Histogram and
    3802             phase must already be associated
    3803 
     3827        :param histograms: Either 'all' (default) or a list of the histograms by index, name
     3828            or object.
     3829            The index number is relative to all histograms in the tree, not to
     3830            those in the phase.
     3831            Histograms not associated with the current phase will be ignored.
     3832            whose HAP parameters will be set with this phase. Histogram and phase
     3833            must already be associated
    38043834        :returns: None
    38053835        """
    38063836        if histograms == 'all':
    3807             histograms = self.data['Histograms'].values()
     3837            histograms = self.data['Histograms'].keys()
    38083838        else:
    3809             histograms = [self.data['Histograms'][h.name] for h in histograms
    3810                           if h.name in self.data['Histograms']]
     3839            histograms = [self._decodeHist(h) for h in histograms
     3840                          if self._decodeHist(h) in self.data['Histograms']]   
    38113841
    38123842        for key, val in refs.items():
     
    38203850                        if param not in ['BabA', 'BabU']:
    38213851                            raise ValueError("Not sure what to do with" + param)
    3822                         for hist in histograms:
    3823                             hist['Babinet'][param][1] = False
     3852                        for h in histograms:
     3853                            self.data['Histograms'][h]['Babinet'][param][1] = False
    38243854                elif key == 'Extinction':
    38253855                    for h in histograms:
    3826                         h['Extinction'][1] = False
     3856                        self.data['Histograms'][h]['Extinction'][1] = False
    38273857                elif key == 'HStrain':
    38283858                    for h in histograms:
    3829                         h['HStrain'][1] = [False for p in h['HStrain'][1]]
     3859                        self.data['Histograms'][h]['HStrain'][1] = [False for p in self.data['Histograms'][h]['HStrain'][1]]
    38303860                elif key == 'Mustrain':
    38313861                    for h in histograms:
    3832                         mustrain = h['Mustrain']
     3862                        mustrain = self.data['Histograms'][h]['Mustrain']
    38333863                        mustrain[2] = [False for p in mustrain[2]]
    38343864                        mustrain[5] = [False for p in mustrain[4]]
    38353865                elif key == 'Pref.Ori.':
    38363866                    for h in histograms:
    3837                         h['Pref.Ori.'][2] = False
     3867                        self.data['Histograms'][h]['Pref.Ori.'][2] = False
    38383868                elif key == 'Show':
    38393869                    for h in histograms:
    3840                         h['Show'] = False
     3870                        self.data['Histograms'][h]['Show'] = False
    38413871                elif key == 'Size':
    38423872                    for h in histograms:
    3843                         size = h['Size']
     3873                        size = self.data['Histograms'][h]['Size']
    38443874                        size[2] = [False for p in size[2]]
    38453875                        size[5] = [False for p in size[5]]
    38463876                elif key == 'Use':
    38473877                    for h in histograms:
    3848                         h['Use'] = False
     3878                        self.data['Histograms'][h]['Use'] = False
    38493879                elif key == 'Scale':
    38503880                    for h in histograms:
    3851                         h['Scale'][1] = False
     3881                        self.data['Histograms'][h]['Scale'][1] = False
    38523882                else:
    38533883                    print(u'Unknown HAP key: '+key)
     
    39073937        :param hist: Specify a histogram or using the histogram name (str)
    39083938          or the index number (int) of the histogram in the sequential
    3909           refinement (not the project), numbered starting from 0.
     3939          refinement (not the project), numbered as in in the project tree
     3940          starting from 0.
    39103941        :returns: cell,cellESD,uniqCellIndx where cell (list)
    39113942          with the unit cell parameters (a,b,c,alpha,beta,gamma,Volume);
     
    40174048        :param hist: Specify a histogram or using the histogram name (str)
    40184049          or the index number (int) of the histogram in the sequential
    4019           refinement (not the project), numbered starting from 0.
     4050          refinement (not the project), numbered as in the project tree
     4051          starting from 0.
    40204052        :returns: a list of parameters or None if no refinement has been
    40214053          performed.
     
    40344066        :param hist: Specify a histogram or using the histogram name (str)
    40354067          or the index number (int) of the histogram in the sequential
    4036           refinement (not the project), numbered starting from 0.
     4068          refinement (not the project), numbered as in the project tree
     4069          starting from 0.
    40374070        :param str var: a variable name of form '<p>:<h>:<name>', such as
    40384071          ':0:Scale'
     
    40604093        :param hist: Specify a histogram or using the histogram name (str)
    40614094          or the index number (int) of the histogram in the sequential
    4062           refinement (not the project), numbered starting from 0.
     4095          refinement (not the project), numbered as in the project tree
     4096          starting from 0.
    40634097        :param tuple varList: a list of variable names of form '<p>:<h>:<name>'
    40644098        :returns: (valueList,CovMatrix) where valueList contains the (n) values
     
    40954129        :param hist: Specify a histogram or using the histogram name (str)
    40964130          or the index number (int) of the histogram in the sequential
    4097           refinement (not the project), numbered starting from 0.
     4131          refinement (not the project), numbered as in the project tree
     4132          starting from 0.
    40984133        :returns: a list of dicts where the first element has sequential
    40994134          refinement results and the second element has the contents of
Note: See TracChangeset for help on using the changeset viewer.