Changeset 3022


Ignore:
Timestamp:
Aug 23, 2017 10:17:15 AM (6 years ago)
Author:
odonnell
Message:

new pId/hId setters, factor out hist/phase linking code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIscriptable.py

    r3016 r3022  
    694694            self.filename = os.path.abspath(os.path.expanduser(gpxfile))
    695695            self.data, self.names = LoadDictFromProjFile(gpxfile)
     696            self.update_ids()
    696697            self.index_ids()
    697698        else:
     
    758759                self.names.append(new_names)
    759760        self.data[histname] = pwdrdata
     761        self.update_ids()
    760762        return self.histogram(histname)
    761763
     
    811813        UseList = data['Histograms']
    812814
    813         for histname in histograms:
    814             if histname.startswith('HKLF '):
    815                 raise NotImplementedError("Does not support HKLF yet")
    816             elif histname.startswith('PWDR '):
    817                 hist = self.histogram(histname)
    818                 hist['Reflection Lists'][generalData['Name']] = {}
    819                 UseList[histname] = SetDefaultDData('PWDR', histname, NShkl=NShkl, NDij=NDij)
    820                 for key, val in [('Use', True), ('LeBail', False),
    821                                  ('newLeBail', True),
    822                                  ('Babinet', {'BabA': [0.0, False],
    823                                               'BabU': [0.0, False]})]:
    824                     if key not in UseList[histname]:
    825                         UseList[histname][key] = val
    826             else:
    827                 raise NotImplementedError("Unexpected histogram" + histname)
     815        for hist in histograms:
     816            self.link_histogram_phase(hist, phasename)
     817            # if histname.startswith('HKLF '):
     818            #     raise NotImplementedError("Does not support HKLF yet")
     819            # elif histname.startswith('PWDR '):
     820            #     hist = self.histogram(histname)
     821            #     hist['Reflection Lists'][generalData['Name']] = {}
     822            #     UseList[histname] = SetDefaultDData('PWDR', histname, NShkl=NShkl, NDij=NDij)
     823            #     for key, val in [('Use', True), ('LeBail', False),
     824            #                      ('newLeBail', True),
     825            #                      ('Babinet', {'BabA': [0.0, False],
     826            #                                   'BabU': [0.0, False]})]:
     827            #         if key not in UseList[histname]:
     828            #             UseList[histname][key] = val
     829            # else:
     830            #     raise NotImplementedError("Unexpected histogram" + histname)
    828831
    829832        for obj in self.names:
     
    840843        self.index_ids()
    841844
     845        self.update_ids()
    842846        return self.phase(phasename)
     847
     848    def link_histogram_phase(self, histogram, phase):
     849        """Associates a given histogram and phase.
     850
     851        .. seealso::
     852
     853            :func:`~G2Project.histogram`
     854            :func:`~G2Project.phase`"""
     855        hist = self.histogram(histogram)
     856        phase = self.phase(phase)
     857
     858        generalData = phase['General']
     859
     860        if hist.name.startswith('HKLF '):
     861            raise NotImplementedError("HKLF not yet supported")
     862        elif hist.name.startswith('PWDR '):
     863            hist['Reflection Lists'][generalData['Name']] = {}
     864            UseList = phase['Histograms']
     865            SGData = generalData['SGData']
     866            NShkl = len(G2spc.MustrainNames(SGData))
     867            NDij = len(G2spc.HStrainNames(SGData))
     868            UseList[hist.name] = SetDefaultDData('PWDR', hist.name, NShkl=NShkl, NDij=NDij)
     869            UseList[hist.name]['hId'] = hist.id
     870            for key, val in [('Use', True), ('LeBail', False),
     871                             ('newLeBail', True),
     872                             ('Babinet', {'BabA': [0.0, False],
     873                                          'BabU': [0.0, False]})]:
     874                if key not in UseList[hist.name]:
     875                    UseList[hist.name][key] = val
     876        else:
     877            raise RuntimeError("Unexpected histogram" + hist.name)
     878
    843879
    844880    def reload(self):
     
    935971                return [self.phase(p) for p in obj[1:]]
    936972        return []
     973
     974    def update_ids(self):
     975        """Makes sure all phases and histograms have proper hId and pId"""
     976        # Translated from GetUsedHistogramsAndPhasesfromTree,
     977        #   GSASIIdataGUI.py:4107
     978        for i, h in enumerate(self.histograms()):
     979            h.id = i
     980        for i, p in enumerate(self.phases()):
     981            p.id = i
    937982
    938983    def do_refinements(self, refinements, histogram='all', phase='all',
     
    12681313    @property
    12691314    def id(self):
     1315        self.proj.update_ids()
    12701316        return self.data['data'][0]['hId']
     1317
     1318    @id.setter
     1319    def id(self, val):
     1320        self.data['data'][0]['hId'] = val
    12711321
    12721322    def fit_fixed_points(self):
     
    15271577    def id(self):
    15281578        return self.data['pId']
     1579
     1580    @id.setter
     1581    def id(self, val):
     1582        self.data['pId'] = val
    15291583
    15301584    def get_cell(self):
Note: See TracChangeset for help on using the changeset viewer.