Changeset 4015


Ignore:
Timestamp:
Jun 2, 2019 1:26:06 PM (3 years ago)
Author:
toby
Message:

add setHAPvalues to scriptable; disable import G(r) because broken

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIdataGUI.py

    r4003 r4015  
    23602360        submenu = wx.Menu()
    23612361        item = parent.AppendSubMenu(submenu,'PDF G(R) Data','Import PDF G(R) data')
     2362        item.Enable(False) # TODO: this does not appear to have ever been made to work
    23622363        for reader in self.ImportPDFReaderlist:
    23632364            item = submenu.Append(wx.ID_ANY,u'from '+reader.formatName+u' file',reader.longFormatName)
  • trunk/GSASIIscriptable.py

    r4005 r4015  
    37373737                print(u'Unknown HAP key: '+key)
    37383738
    3739     def _decodeHist(self,hist):
    3740         '''Convert a histogram reference to a histogram name string
    3741         '''
    3742         if isinstance(hist, G2PwdrData):
    3743             return hist.name
    3744         elif hist in self.data['Histograms']:
    3745             return hist
    3746         elif type(hist) is int:
    3747             return self.proj.histograms()[hist].name
    3748         else:
    3749             raise G2ScriptException("Invalid histogram reference: "+str(hist))
    3750        
    3751     def getHAPvalues(self, histname):
    3752         """Returns a dict with HAP values for the selected histogram
    3753 
    3754         :param histogram: is a histogram object (:class:`G2PwdrData`) or
    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.
    3758         :returns: HAP value dict
    3759         """
    3760         return self.data['Histograms'][self._decodeHist(histname)]
    3761 
    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.
    3765 
    3766         :param sourcehist: is a histogram object (:class:`G2PwdrData`) or
    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.
    3771         :param list targethistlist: a list of histograms where each item in the
    3772             list can be a histogram object (:class:`G2PwdrData`),
    3773             a histogram name or the index number of the histogram.
    3774             If the string 'all' (default), then all histograms in the phase
    3775             are used.
    3776         :param list skip: items in the HAP dict that should not be
    3777             copied. The default is an empty list, which causes all items
    3778             to be copied. To see a list of items in the dict, use
    3779             :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.
    3794         """
    3795         sourcehist = self._decodeHist(sourcehist)
    3796         if targethistlist == 'all':
    3797             targethistlist = self.histograms()
    3798        
    3799         copydict = copy.deepcopy(self.data['Histograms'][sourcehist])
    3800         for item in skip:
    3801             if item in list(copydict.keys()):
    3802                 del copydict[item]
    3803             else:
    3804                 print('items in HAP dict are: {}'.format(
    3805                     list(self.data['Histograms'][sourcehist])))
    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]))
    3814         for h in targethistlist:
    3815             h = self._decodeHist(h)
    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))
    3820            
    38213739    def clear_HAP_refinements(self, refs, histograms='all'):
    38223740        """Clears the given HAP refinement parameters between this phase and
     
    38823800                else:
    38833801                    print(u'Unknown HAP key: '+key)
     3802
     3803    def _decodeHist(self,hist):
     3804        '''Convert a histogram reference to a histogram name string
     3805        '''
     3806        if isinstance(hist, G2PwdrData):
     3807            return hist.name
     3808        elif hist in self.data['Histograms']:
     3809            return hist
     3810        elif type(hist) is int:
     3811            return self.proj.histograms()[hist].name
     3812        else:
     3813            raise G2ScriptException("Invalid histogram reference: "+str(hist))
     3814       
     3815    def getHAPvalues(self, histname):
     3816        """Returns a dict with HAP values for the selected histogram
     3817
     3818        :param histogram: is a histogram object (:class:`G2PwdrData`) or
     3819            a histogram name or the index number of the histogram.
     3820            The index number is relative to all histograms in the tree, not to
     3821            those in the phase.
     3822        :returns: HAP value dict
     3823        """
     3824        return self.data['Histograms'][self._decodeHist(histname)]
     3825
     3826    def copyHAPvalues(self, sourcehist, targethistlist='all', skip=[], use=None):
     3827        """Copies HAP parameters for one histogram to a list of other histograms.
     3828        Use skip or use to select specific entries to be copied or not used.
     3829
     3830        :param sourcehist: is a histogram object (:class:`G2PwdrData`) or
     3831            a histogram name or the index number of the histogram to copy
     3832            parameters from.
     3833            The index number is relative to all histograms in the tree, not to
     3834            those in the phase.
     3835        :param list targethistlist: a list of histograms where each item in the
     3836            list can be a histogram object (:class:`G2PwdrData`),
     3837            a histogram name or the index number of the histogram.
     3838            If the string 'all' (default), then all histograms in the phase
     3839            are used.
     3840        :param list skip: items in the HAP dict that should not be
     3841            copied. The default is an empty list, which causes all items
     3842            to be copied. To see a list of items in the dict, use
     3843            :meth:`getHAPvalues` or use an invalid item, such as '?'.
     3844        :param list use: specifies the items in the HAP dict should be
     3845            copied. The default is None, which causes all items
     3846            to be copied.
     3847
     3848        examples::
     3849
     3850            ph0.copyHAPvalues(0,[1,2,3])
     3851            ph0.copyHAPvalues(0,use=['HStrain','Size'])
     3852
     3853        The first example copies all HAP parameters from the first histogram to
     3854        the second, third and fourth histograms (as listed in the project tree).
     3855        The second example copies only the 'HStrain' (Dij parameters and
     3856        refinement flags) and the 'Size' (crystallite size settings, parameters
     3857        and refinement flags) from the first histogram to all histograms.
     3858        """
     3859        sourcehist = self._decodeHist(sourcehist)
     3860        if targethistlist == 'all':
     3861            targethistlist = self.histograms()
     3862       
     3863        copydict = copy.deepcopy(self.data['Histograms'][sourcehist])
     3864        for item in skip:
     3865            if item in list(copydict.keys()):
     3866                del copydict[item]
     3867            else:
     3868                print('items in HAP dict are: {}'.format(
     3869                    list(self.data['Histograms'][sourcehist])))
     3870                raise Exception('HAP skip list entry {} invalid'.format(item))
     3871        if use:
     3872            for item in list(copydict.keys()):
     3873                if item not in use:
     3874                    del copydict[item]
     3875
     3876        print('Copying item(s) {} from histogram {}'.format(list(copydict.keys()),sourcehist))
     3877        print(' to histogram(s) {}'.format([self._decodeHist(h) for h in targethistlist]))
     3878        for h in targethistlist:
     3879            h = self._decodeHist(h)
     3880            if h not in self.data['Histograms']:
     3881                print('Unexpected Warning: histogram {} not in phase {}'.format(h,self.name))
     3882                continue
     3883            self.data['Histograms'][h].update(copy.deepcopy(copydict))
     3884
     3885    def setHAPvalues(self, HAPdict, targethistlist='all', skip=[], use=None):
     3886        """Copies HAP parameters for one histogram to a list of other histograms.
     3887        Use skip or use to select specific entries to be copied or not used.
     3888        Note that ``HStrain`` and sometimes ``Mustrain`` values can be specific to
     3889        a Laue class and should be copied with care between phases of different
     3890        symmetry. A "sanity check" on the number of Dij terms is made if ``HStrain``
     3891        values are copied.
     3892
     3893        :param dict HAPdict: is a dict returned by :meth:`getHAPvalues` containing
     3894            HAP parameters.
     3895        :param list targethistlist: a list of histograms where each item in the
     3896            list can be a histogram object (:class:`G2PwdrData`),
     3897            a histogram name or the index number of the histogram.
     3898            The index number is relative to all histograms in the tree, not to
     3899            those in the phase.
     3900            If the string 'all' (default), then all histograms in the phase
     3901            are used.
     3902        :param list skip: items in the HAP dict that should not be
     3903            copied. The default is an empty list, which causes all items
     3904            to be copied. To see a list of items in the dict, use
     3905            :meth:`getHAPvalues` or use an invalid item, such as '?'.
     3906        :param list use: specifies the items in the HAP dict should be
     3907            copied. The default is None, which causes all items
     3908            to be copied.
     3909
     3910        example::
     3911
     3912            HAPdict = ph0.getHAPvalues(0)
     3913            ph1.setHAPvalues(HAPdict,use=['HStrain','Size'])
     3914
     3915        This copies the Dij (hydrostatic strain) HAP parameters and the
     3916        crystallite size broadening terms from the first histogram in
     3917        phase ``ph0`` to all histograms in phase ``ph1``.
     3918        """
     3919        if targethistlist == 'all':
     3920            targethistlist = self.histograms()
     3921        copydict = copy.deepcopy(HAPdict)
     3922        for item in skip:
     3923            if item in list(copydict.keys()):
     3924                del copydict[item]
     3925            else:
     3926                print('items in HAP dict are: {}'.format(
     3927                    list(self.data['Histograms'][sourcehist])))
     3928                raise Exception('HAP skip list entry {} invalid'.format(item))
     3929        if use:
     3930            for item in list(copydict.keys()):
     3931                if item not in use:
     3932                    del copydict[item]
     3933
     3934        first = True
     3935        for h in targethistlist:
     3936            h = self._decodeHist(h)
     3937            if h not in self.data['Histograms']:
     3938                print('Warning: histogram {} not in phase {}'.format(h,self.name))
     3939                continue
     3940            if first:
     3941                first = False
     3942                if 'HStrain' in self.data['Histograms'][h] and 'HStrain' in copydict:
     3943                    if len(copydict['HStrain'][0]) != len(self.data['Histograms'][h]['HStrain'][0]):
     3944                        print('HStrain has differing numbers of terms. Input: {}, phase {}: {}'.
     3945                                  format(len(copydict['HStrain'][0]),
     3946                                        self.name,len(self.data['Histograms'][h]['HStrain'][0])))
     3947                        raise Exception('HStrain has differing numbers of terms.')
     3948            self.data['Histograms'][h].update(copy.deepcopy(copydict))           
     3949        print('Copied item(s) {} from dict'.format(list(copydict.keys())))
     3950        print(' to histogram(s) {}'.format([self._decodeHist(h) for h in targethistlist]))
    38843951
    38853952class G2SeqRefRes(G2ObjectWrapper):
  • trunk/imports/G2pdf_gr.py

    r3136 r4015  
    3434
    3535    # Validate the contents -- make sure we only have valid lines
    36     def ContentsValidator(self, filepointer):
     36    def ContentsValidator(self, filename):
    3737        'Look through the file for expected types of lines in a valid r-step file'
     38        filepointer = open(filename,'r')
    3839        Ndata = 0
    3940        for i,S in enumerate(filepointer):
    4041            if '#L' in S[:2]:
    4142                break
    42         filepointer.seek(i)
    4343        for i,S in enumerate(filepointer):           
    4444            vals = S.split()
     
    5151        if not Ndata:     
    5252            self.errors = 'No 2 or more column numeric data found'
     53            filepointer.close()
    5354            return False
     55        filepointer.close()
    5456        return True # no errors encountered
    5557
    56     def Reader(self,filename,filepointer, ParentFrame=None, **unused):
     58    def Reader(self,filename,ParentFrame=None, **unused):
    5759        print ('Read a q-step text file')
    5860        x = []
    5961        y = []
    6062        ifData = False
     63        filepointer = open(filename,'r')
    6164        for i,S in enumerate(filepointer):
    6265            if not ifData:
Note: See TracChangeset for help on using the changeset viewer.