Changeset 4119 for trunk/GSASIIscriptable.py
- Timestamp:
- Aug 28, 2019 11:11:22 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIscriptable.py
r4088 r4119 184 184 :meth:`G2PwdrData.fit_fixed_points` Fits background to the specified fixed points. 185 185 :meth:`G2PwdrData.getdata` Provides access to the diffraction data associated with the histogram. 186 :meth:`G2PwdrData.reflections` Provides access to the reflection lists for the histogram. 186 187 :meth:`G2PwdrData.Export` Writes the diffraction data into a file 187 188 :meth:`G2PwdrData.add_peak` Adds a peak to the peak list. Also see :ref:`PeakRefine`. … … 684 685 685 686 Note that the parameters must match the object type and method (phase vs. histogram vs. HAP). 687 ================================= 688 Code Examples 689 ================================= 686 690 687 691 .. _PeakRefine: 688 692 689 ================================= 693 -------------------- 690 694 Peak Refinement 691 ================================= 695 -------------------- 692 696 Peak refinement is performed with routines 693 697 :meth:`G2PwdrData.add_peak`, :meth:`G2PwdrData.set_peakFlags` and … … 731 735 hist.Export_peaks('pkfit.txt') 732 736 #gpx.save() # gpx file is not written without this 737 738 739 -------------------- 740 Pattern Simulation 741 -------------------- 742 743 This shows an example where a structure is read from a CIF, a 744 pattern is computed and the pattern and reflection list are computed. 745 746 .. code-block:: python 747 748 import os,sys 749 sys.path.insert(0,'/Users/toby/software/G2/GSASII') 750 import GSASIIscriptable as G2sc 751 datadir = "/Users/toby/software/G2/Tutorials/PythonScript/data" 752 PathWrap = lambda fil: os.path.join(datadir,fil) 753 gpx = G2sc.G2Project(filename='PbSO4sim.gpx') # create a project 754 # add a phase to the project 755 phase0 = gpx.add_phase(PathWrap("PbSO4-Wyckoff.cif"), 756 phasename="PbSO4",fmthint='CIF') 757 # add a simulated histogram and link it to the previous phase(s) 758 hist1 = gpx.add_simulated_powder_histogram("PbSO4 simulation", 759 PathWrap("inst_d1a.prm"),5.,120.,0.01, 760 phases=gpx.phases()) 761 # Set the scale factor to adjust the y scale 762 hist1.SampleParameters['Scale'][0] = 1000000. 763 # parameter optimization and calculate pattern 764 gpx.data['Controls']['data']['max cyc'] = 0 # refinement not needed 765 gpx.do_refinements([{}]) 766 gpx.save() 767 # save results 768 gpx.histogram(0).Export('PbSO4data','.csv','hist') # data 769 gpx.histogram(0).Export('PbSO4refl','.csv','refl') # reflections 770 733 771 734 772 .. _CommandlineInterface: … … 891 929 if typ not in exportersByExtension: 892 930 exportersByExtension[typ] = {obj.extension:obj} 931 elif obj.extension in exportersByExtension[typ]: 932 if type(exportersByExtension[typ][obj.extension]) is list: 933 exportersByExtension[typ][obj.extension].append(obj) 934 else: 935 exportersByExtension[typ][obj.extension] = [ 936 exportersByExtension[typ][obj.extension], 937 obj] 893 938 else: 894 939 exportersByExtension[typ][obj.extension] = obj … … 3128 3173 3129 3174 def y_calc(self): 3175 '''Returns the calculated intensity values; better to 3176 use :meth:`getdata` 3177 ''' 3130 3178 return self.data['data'][1][3] 3131 3179 3132 def Export(self,fileroot,extension): 3180 def reflections(self): 3181 '''Returns a dict with an entry for every phase in the 3182 current histogram. Within each entry is a dict with keys 3183 'RefList' (reflection list, see 3184 :ref:`Powder Reflections <PowderRefl_table>`), 3185 'Type' (histogram type), 'FF' 3186 (form factor information), 'Super' (True if this is superspace 3187 group). 3188 ''' 3189 return self.data['Reflection Lists'] 3190 3191 def Export(self,fileroot,extension,fmthint=None): 3133 3192 '''Write the histogram into a file. The path is specified by fileroot and 3134 3193 extension. … … 3138 3197 :param str extension: includes '.', must match an extension in global 3139 3198 exportersByExtension['powder'] or a Exception is raised. 3199 :param str fmthint: If specified, the first exporter where the format 3200 name (obj.formatName, as shown in Export menu) contains the 3201 supplied string will be used. If not specified, an error 3202 will be generated showing the possible choices. 3140 3203 :returns: name of file that was written 3141 3204 ''' … … 3146 3209 fil = os.path.abspath(os.path.splitext(fileroot)[0]+extension) 3147 3210 obj = exportersByExtension['powder'][extension] 3148 obj.SetFromArray(hist=self.data,histname=self.name) 3211 if type(obj) is list: 3212 if fmthint is None: 3213 print('Defined ',extension,'exporters are:') 3214 for o in obj: 3215 print('\t',o.formatName) 3216 raise G2ScriptException('No format hint for file type = "'+extension+'"') 3217 for o in obj: 3218 if fmthint.lower() in o.formatName.lower(): 3219 obj = o 3220 break 3221 else: 3222 print('Hint ',fmthint,'not found. Defined ',extension,'exporters are:') 3223 for o in obj: 3224 print('\t',o.formatName) 3225 raise G2ScriptException('Bad format hint for file type = "'+exten+'"') 3226 self._SetFromArray(obj) 3149 3227 obj.Writer(self.name,fil) 3150 3228 return fil 3151 3229 3230 def _SetFromArray(self,expObj): 3231 '''Load a histogram into the exporter in preparation for use of 3232 the .Writer method in the object. 3233 3234 :param Exporter expObj: Exporter object 3235 ''' 3236 expObj.Histograms[self.name] = {} 3237 expObj.Histograms[self.name]['Data'] = self.data['data'][1] 3238 for key in 'Instrument Parameters','Sample Parameters','Reflection Lists': 3239 expObj.Histograms[self.name][key] = self.data[key] 3240 3152 3241 def plot(self, Yobs=True, Ycalc=True, Background=True, Residual=True): 3153 3242 try:
Note: See TracChangeset
for help on using the changeset viewer.