Changeset 5611 for trunk/docs/source/GSASIIscriptable.rst
- Timestamp:
- Jun 11, 2023 1:56:25 PM (6 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/docs/source/GSASIIscriptable.rst
r5572 r5611 1 ======================================= 2 *GSASIIscriptable: Scripting Interface*3 ======================================= 1 ========================================= 2 *GSASIIscriptable: Scripting Interface* 3 ========================================= 4 4 5 5 6 6 *Summary/Contents* 7 ================== ================================7 ================== 8 8 9 9 Routines to use an increasing amount of GSAS-II's capabilities from scripts, 10 10 without use of the graphical user interface (GUI). GSASIIscriptable can create and access 11 11 GSAS-II project (.gpx) files and can directly perform image handling and refinements. 12 The module defines wrapper classes (inheriting from :class:` G2ObjectWrapper`) for a growing number12 The module defines wrapper classes (inheriting from :class:`~GSASIIscriptable.G2ObjectWrapper`) for a growing number 13 13 of data tree items. 14 14 … … 17 17 used is via Python scripts that 18 18 call the module's application interface (API), see API summary that follows or the :ref:`API` 19 section. The command-line mode 19 section. 20 21 While the command-line mode 20 22 provides access a number of features without writing Python scripts 21 via shell/batch commands (see :ref:`CommandlineInterface`) but this 23 via shell/batch commands (see :ref:`CommandlineInterface`), use in practice 24 seems somewhat clumsy. Command-line mode 22 25 is no longer being developed and its use is discouraged. 23 26 24 27 .. contents:: Section Contents 25 28 29 Installation of GSASIIscriptable 30 ================================ 31 32 GSASIIscriptable is included as part of a standard GSAS-II installation that includes the GSAS-II GUI (as described in the `installation instructions <https://subversion.xray.aps.anl.gov/trac/pyGSAS#Installationinstructions>`_). People who will will use scripting extensively will still need access to the GUI 33 for some activities, since the scripting API has not yet been extended to all 34 features of GSAS-II and even if that is ever completed, there will still be some things that GSAS-II does with the GUI would be almost impossible to implement without a interactive graphical view of the data. 35 36 Nonetheless, there may be times where it does make sense to install GSAS-II without all of the GUI components, for example on a compute server. 37 The minimal requirements for use of GSASIIscriptable are only Python, numpy and scipy, but additional optional requirements are described in 38 the :ref:`ScriptingRequirements`, which also provides some installation instructions. 39 40 In a standard GSAS-II installation, no changes are made to Python. When the GUI is invoked, a small script or Windows batch file is used to start GSAS-II inside Python. When 41 GSASIIscriptable is used, Python must be provided with the location of the GSAS-II files. There are two ways this can be done: 42 43 * define the GSAS-II installation location in the Python ``sys.path``, or 44 * install a reference to GSAS-II inside Python. 45 46 The latter method requires an extra installation step, but has the advantage that 47 it allows writing portable GSAS-II scripts. This is discussed further in the 48 :ref:`ScriptingShortcut` section of this chapter. 26 49 27 50 Application Interface (API) Summary 28 =================================== ===============51 =================================== 29 52 This section of the documentation provides an overview to API, with full documentation 30 53 in the :ref:`API` section. The typical API use will be with a Python script, such as … … 32 55 summarized below. 33 56 34 Overview of Classes 35 ------------------- --57 Overview of Classes 58 ------------------- 36 59 37 60 .. tabularcolumns:: |l|p{4in}| 38 61 39 =============================== 40 class Encapsulates41 =============================== 42 :class:` G2Project` A GSAS-II project file,provides references to objects below,43 each corresponding to a tree item44 (exception is :class:`G2AtomRecord`)45 :class:` G2Phase`Provides phase information access46 (also provides access to atom info via :class:`G2AtomRecord`)47 :class:` G2AtomRecord` Access to an atom within a phase48 :class:` G2PwdrData` Access to powder histogram info49 :class:` G2Image` Access to image info50 :class:` G2PDF` PDF histogram info51 :class:` G2SeqRefRes` The sequential results table52 =============================== 62 ======================================= =============================================================================================================== 63 class Encapsulated by class 64 ======================================= =============================================================================================================== 65 :class:`~GSASIIscriptable.G2Project` A GSAS-II project file; provides references to objects below, 66 each corresponding to a tree item 67 (exception is :class:`~GSASIIscriptable.G2AtomRecord`) 68 :class:`~GSASIIscriptable.G2Phase` Provides phase information access 69 (also provides access to atom info via :class:`~GSASIIscriptable.G2AtomRecord`) 70 :class:`~GSASIIscriptable.G2AtomRecord` Access to an atom within a phase 71 :class:`~GSASIIscriptable.G2PwdrData` Access to powder histogram info 72 :class:`~GSASIIscriptable.G2Image` Access to image info 73 :class:`~GSASIIscriptable.G2PDF` PDF histogram info 74 :class:`~GSASIIscriptable.G2SeqRefRes` The sequential results table 75 ======================================= =============================================================================================================== 53 76 54 77 Functions 55 --------- ------------56 57 A small amount of the Scriptable code doesnot require use of objects.78 --------- 79 80 A small number of Scriptable routines do not require use of objects. 58 81 59 82 .. tabularcolumns:: |l|p{4in}| 83 84 =================================================== =============================================================================================================== 85 method Use 86 =================================================== =============================================================================================================== 87 :func:`~GSASIIscriptable.GenerateReflections` Generates a list of unique powder reflections 88 :func:`~GSASIIscriptable.SetPrintLevel` Sets the amount of output generated when running a script 89 :func:`~GSASIIscriptable.installScriptingShortcut` Installs GSASIIscriptable within Python as G2script 90 =================================================== =============================================================================================================== 91 92 Class :class:`~GSASIIscriptable.G2Project` 93 --------------------------------------------- 94 95 All GSASIIscriptable scripts will need to create a :class:`~GSASIIscriptable.G2Project` object 96 either for a new GSAS-II project or to read in an existing project (.gpx) file. 97 The most commonly used routines in this object are: 98 99 .. tabularcolumns:: |l|p{3.in}| 100 101 ==================================================================== =============================================================================================================== 102 method Use 103 ==================================================================== =============================================================================================================== 104 :meth:`~GSASIIscriptable.G2Project.save` Writes the current project to disk. 105 106 :meth:`~GSASIIscriptable.G2Project.add_powder_histogram` Used to read in powder diffraction data into a project file. 107 108 :meth:`~GSASIIscriptable.G2Project.add_simulated_powder_histogram` Defines a "dummy" powder diffraction data that will be simulated after a refinement step. 109 110 :meth:`~GSASIIscriptable.G2Project.add_image` Reads in an image into a project. 111 112 :meth:`~GSASIIscriptable.G2Project.add_phase` Adds a phase to a project 113 114 :meth:`~GSASIIscriptable.G2Project.add_PDF` Adds a PDF entry to a project (does not compute it) 115 116 :meth:`~GSASIIscriptable.G2Project.histograms` Provides a list of histograms in the current project, as :class:`~GSASIIscriptable.G2PwdrData` objects 117 118 :meth:`~GSASIIscriptable.G2Project.phases` Provides a list of phases defined in the current project, as :class:`~GSASIIscriptable.G2Phase` objects 119 120 :meth:`~GSASIIscriptable.G2Project.images` Provides a list of images in the current project, as :class:`~GSASIIscriptable.G2Image` objects 121 122 :meth:`~GSASIIscriptable.G2Project.pdfs` Provides a list of PDFs in the current project, as :class:`~GSASIIscriptable.G2PDF` objects 123 124 :meth:`~GSASIIscriptable.G2Project.seqref` Returns a :class:`~GSASIIscriptable.G2SeqRefRes` object if there are Sequential Refinement results 125 126 :meth:`~GSASIIscriptable.G2Project.do_refinements` This is passed a list of dictionaries, where each dict defines a refinement step. 127 Passing a list with a single empty dict initiates a refinement with the current 128 parameters and flags. A refinement dict sets up a single refinement step 129 (as described in :ref:`Project_dicts`). Also see :ref:`Refinement_recipe`. 130 131 :meth:`~GSASIIscriptable.G2Project.set_refinement` This is passed a single dict which is used to set parameters and flags. 132 These actions can be performed also in :meth:`~GSASIIscriptable.G2Project.do_refinements`. 133 :meth:`~GSASIIscriptable.G2Project.get_Variable` Retrieves the value and esd for a parameter 134 :meth:`~GSASIIscriptable.G2Project.get_Covariance` Retrieves values and covariance for a set of refined parameters 135 :meth:`~GSASIIscriptable.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:`~GSASIIscriptable.G2Project.get_Controls` to read values.) 137 :meth:`~GSASIIscriptable.G2Project.imageMultiDistCalib` Performs a global calibration fit with images at multiple distance settings. 138 :meth:`~GSASIIscriptable.G2Project.get_Constraints` Retrieves :ref:`constraint definition <Constraint_definitions_table>` entries. 139 :meth:`~GSASIIscriptable.G2Project.add_HoldConstr` Adds a hold constraint on one or more variables 140 :meth:`~GSASIIscriptable.G2Project.add_EquivConstr` Adds an equivalence constraint on two or more variables 141 :meth:`~GSASIIscriptable.G2Project.add_EqnConstr` Adds an equation-type constraint on two or more variables 142 :meth:`~GSASIIscriptable.G2Project.add_NewVarConstr` Adds an new variable as a constraint on two or more variables 143 ==================================================================== =============================================================================================================== 144 145 Class :class:`~GSASIIscriptable.G2Phase` 146 ------------------------------------------- 147 148 149 Another common object in GSASIIscriptable scripts is :class:`~GSASIIscriptable.G2Phase`, used to encapsulate each phase in a project, with commonly used methods: 150 151 .. tabularcolumns:: |l|p{3.5in}| 152 153 ======================================================== =============================================================================================================== 154 method Use 155 ======================================================== =============================================================================================================== 156 :meth:`~GSASIIscriptable.G2Phase.set_refinements` Provides a mechanism to set values and refinement flags for the phase. See :ref:`Phase_parameters_table` 157 for more details. This information also can be supplied within a call 158 to :meth:`~GSASIIscriptable.G2Project.do_refinements` 159 or :meth:`~GSASIIscriptable.G2Project.set_refinement`. 160 :meth:`~GSASIIscriptable.G2Phase.clear_refinements` Unsets refinement flags for the phase. 161 :meth:`~GSASIIscriptable.G2Phase.set_HAP_refinements` Provides a mechanism to set values and refinement flags for parameters specific to both this phase and 162 one of its histograms. See :ref:`HAP_parameters_table`. This information also can be supplied within 163 a call to :meth:`~GSASIIscriptable.G2Project.do_refinements` or :meth:`~GSASIIscriptable.G2Project.set_refinement`. 164 :meth:`~GSASIIscriptable.G2Phase.clear_HAP_refinements` Clears refinement flags specific to both this phase and one of its histograms. 165 :meth:`~GSASIIscriptable.G2Phase.getHAPvalues` Returns values of parameters specific to both this phase and one of its histograms. 166 :meth:`~GSASIIscriptable.G2Phase.copyHAPvalues` Copies HAP settings between from one phase/histogram and to other histograms in same phase. 167 :meth:`~GSASIIscriptable.G2Phase.atoms` Returns a list of atoms in the phase 168 :meth:`~GSASIIscriptable.G2Phase.atom` Returns an atom from its label 169 :meth:`~GSASIIscriptable.G2Phase.histograms` Returns a list of histograms linked to the phase 170 :meth:`~GSASIIscriptable.G2Phase.get_cell` Returns unit cell parameters (also see :meth:`~GSASIIscriptable.G2Phase.get_cell_and_esd`) 171 :meth:`~GSASIIscriptable.G2Phase.export_CIF` Writes a CIF for the phase 172 :meth:`~GSASIIscriptable.G2Phase.setSampleProfile` Sets sample broadening parameters 173 :meth:`~GSASIIscriptable.G2Phase.clearDistRestraint` Clears any previously defined bond distance restraint(s) for the selected phase 174 :meth:`~GSASIIscriptable.G2Phase.addDistRestraint` Finds and defines new bond distance restraint(s) for the selected phase 175 :meth:`~GSASIIscriptable.G2Phase.setDistRestraintWeight` Sets the weighting factor for the bond distance restraints 176 ======================================================== =============================================================================================================== 177 178 Class :class:`~GSASIIscriptable.G2PwdrData` 179 --------------------------------------------- 180 181 Another common object in GSASIIscriptable scripts is :class:`~GSASIIscriptable.G2PwdrData`, which encapsulate each powder diffraction histogram in a project, with commonly used methods: 182 183 .. tabularcolumns:: |l|p{3.5in}| 184 185 ======================================================= =============================================================================================================== 186 method Use 187 ======================================================= =============================================================================================================== 188 :meth:`~GSASIIscriptable.G2PwdrData.set_refinements` Provides a mechanism to set values and refinement flags for the powder histogram. See 189 :ref:`Histogram_parameters_table` for details. 190 :meth:`~GSASIIscriptable.G2PwdrData.clear_refinements` Unsets refinement flags for the the powder histogram. 191 :meth:`~GSASIIscriptable.G2PwdrData.residuals` Reports R-factors etc. for the the powder histogram (also see :meth:`~GSASIIscriptable.G2PwdrData.get_wR`) 192 :meth:`~GSASIIscriptable.G2PwdrData.add_back_peak` Adds a background peak to the histogram. Also see :meth:`~GSASIIscriptable.G2PwdrData.del_back_peak` 193 and :meth:`~GSASIIscriptable.G2PwdrData.ref_back_peak`. 194 :meth:`~GSASIIscriptable.G2PwdrData.fit_fixed_points` Fits background to the specified fixed points. 195 :meth:`~GSASIIscriptable.G2PwdrData.getdata` Provides access to the diffraction data associated with the histogram. 196 :meth:`~GSASIIscriptable.G2PwdrData.reflections` Provides access to the reflection lists for the histogram. 197 :meth:`~GSASIIscriptable.G2PwdrData.Export` Writes the diffraction data or reflection list into a file 198 :meth:`~GSASIIscriptable.G2PwdrData.add_peak` Adds a peak to the peak list. Also see :ref:`PeakRefine`. 199 :meth:`~GSASIIscriptable.G2PwdrData.set_peakFlags` Sets refinement flags for peaks 200 :meth:`~GSASIIscriptable.G2PwdrData.refine_peaks` Starts a peak/background fitting cycle, returns refinement results 201 :attr:`~GSASIIscriptable.G2PwdrData.Peaks` Provides access to the peak list data structure 202 :attr:`~GSASIIscriptable.G2PwdrData.PeakList` Provides the peak list parameter values 203 :meth:`~GSASIIscriptable.G2PwdrData.Export_peaks` Writes the peak parameters to a text file 204 :meth:`~GSASIIscriptable.G2PwdrData.set_background` Sets a background histogram that will be subtracted (point by point) from the current histogram. 205 ======================================================= =============================================================================================================== 206 207 Class :class:`~GSASIIscriptable.G2Image` 208 ----------------------------------------- 209 210 When working with images, there will be a :class:`~GSASIIscriptable.G2Image` object for each image (also see :meth:`~GSASIIscriptable.G2Project.add_image` and :meth:`~GSASIIscriptable.G2Project.images`). 211 212 .. tabularcolumns:: |l|p{3.5in}| 213 214 ==================================================== =============================================================================================================== 215 method Use 216 ==================================================== =============================================================================================================== 217 :meth:`~GSASIIscriptable.G2Image.Recalibrate` Invokes a recalibration fit starting from the current Image Controls calibration coefficients. 218 :meth:`~GSASIIscriptable.G2Image.Integrate` Invokes an image integration All parameters Image Controls will have previously been set. 219 :meth:`~GSASIIscriptable.G2Image.GeneratePixelMask` Searches for "bad" pixels creating a pixel mask. 220 :meth:`~GSASIIscriptable.G2Image.setControl` Set an Image Controls parameter in the current image. 221 :meth:`~GSASIIscriptable.G2Image.getControl` Return an Image Controls parameter in the current image. 222 :meth:`~GSASIIscriptable.G2Image.findControl` Get the names of Image Controls parameters. 223 :meth:`~GSASIIscriptable.G2Image.loadControls` Load controls from a .imctrl file (also see :meth:`~GSASIIscriptable.G2Image.saveControls`). 224 :meth:`~GSASIIscriptable.G2Image.loadMasks` Load masks from a .immask file. 225 :meth:`~GSASIIscriptable.G2Image.setVary` Set a refinement flag for Image Controls parameter in the current image. 226 (Also see :meth:`~GSASIIscriptable.G2Image.getVary`) 227 :meth:`~GSASIIscriptable.G2Image.setCalibrant` Set a calibrant type (or show choices) for the current image. 228 :meth:`~GSASIIscriptable.G2Image.setControlFile` Set a image to be used as a background/dark/gain map image. 229 :meth:`~GSASIIscriptable.G2Image.getControls` Returns the Image Controls dict for the current image. 230 :meth:`~GSASIIscriptable.G2Image.setControls` Updates the Image Controls dict for the current image with specified key/value pairs. 231 :meth:`~GSASIIscriptable.G2Image.getMasks` Returns the Masks dict for the current image. 232 :meth:`~GSASIIscriptable.G2Image.setMasks` Updates the Masks dict for the current image with specified key/value pairs. 233 :meth:`~GSASIIscriptable.G2Image.IntThetaAzMap` Computes the set of 2theta-azimuth mapping matrices to integrate the current image. 234 :meth:`~GSASIIscriptable.G2Image.IntMaskMap` Computes the masking map for the current image for integration. 235 :meth:`~GSASIIscriptable.G2Image.MaskThetaMap` Computes the 2theta mapping matrix to determine a pixel mask. 236 :meth:`~GSASIIscriptable.G2Image.MaskFrameMask` Computes the Frame mask needed to determine a pixel mask. 237 :meth:`~GSASIIscriptable.G2Image.TestFastPixelMask` Returns True if fast pixel masking is available. 238 :meth:`~GSASIIscriptable.G2Image.clearImageCache` Clears a saved image from memory, if one is present. 239 :meth:`~GSASIIscriptable.G2Image.clearPixelMask` Clears a saved Pixel map from the project, if one is present. 240 ==================================================== =============================================================================================================== 241 242 243 Class :class:`~GSASIIscriptable.G2PDF` 244 ----------------------------------------- 245 246 To work with PDF entries, object :class:`~GSASIIscriptable.G2PDF`, encapsulates a PDF entry with methods: 247 248 .. tabularcolumns:: |l|p{3.5in}| 60 249 61 250 ================================================== =============================================================================================================== 62 251 method Use 63 252 ================================================== =============================================================================================================== 64 :func:`GenerateReflections` Generates a list of unique powder reflections 65 :func:`SetPrintLevel` Sets the amout of output generated when running a script 253 :meth:`~GSASIIscriptable.G2PDF.export` Used to write G(r), etc. as a file 254 :meth:`~GSASIIscriptable.G2PDF.calculate` Computes the PDF using parameters in the object 255 :meth:`~GSASIIscriptable.G2PDF.optimize` Optimizes selected PDF parameters 256 :meth:`~GSASIIscriptable.G2PDF.set_background` Sets the histograms used for sample background, container, etc. 257 :meth:`~GSASIIscriptable.G2PDF.set_formula` Sets the chemical formula for the sample 66 258 ================================================== =============================================================================================================== 67 259 68 Class :class:`G2Project` 69 --------------------------------- 70 71 All GSASIIscriptable scripts will need to create a :class:`G2Project` object 72 either for a new GSAS-II project or to read in an existing project (.gpx) file. 73 The most commonly used routines in this object are: 74 75 .. tabularcolumns:: |l|p{3.in}| 76 77 ================================================== =============================================================================================================== 78 method Use 79 ================================================== =============================================================================================================== 80 :meth:`G2Project.save` Writes the current project to disk. 81 82 :meth:`G2Project.add_powder_histogram` Used to read in powder diffraction data into a project file. 83 84 :meth:`G2Project.add_simulated_powder_histogram` Defines a "dummy" powder diffraction data that will be simulated after a refinement step. 85 86 :meth:`G2Project.add_image` Reads in an image into a project. 87 88 :meth:`G2Project.add_phase` Adds a phase to a project 89 90 :meth:`G2Project.add_PDF` Adds a PDF entry to a project (does not compute it) 91 92 :meth:`G2Project.histograms` Provides a list of histograms in the current project, as :class:`G2PwdrData` objects 93 94 :meth:`G2Project.phases` Provides a list of phases defined in the current project, as :class:`G2Phase` objects 95 96 :meth:`G2Project.images` Provides a list of images in the current project, as :class:`G2Image` objects 97 98 :meth:`G2Project.pdfs` Provides a list of PDFs in the current project, as :class:`G2PDF` objects 99 100 :meth:`G2Project.seqref` Returns a :class:`G2SeqRefRes` object if there are Sequential Refinement results 101 102 :meth:`G2Project.do_refinements` This is passed a list of dictionaries, where each dict defines a refinement step. 103 Passing a list with a single empty dict initiates a refinement with the current 104 parameters and flags. A refinement dict sets up a single refinement step 105 (as described in :ref:`Project_dicts`). Also see :ref:`Refinement_recipe`. 106 107 :meth:`G2Project.set_refinement` This is passed a single dict which is used to set parameters and flags. 108 These actions can be performed also in :meth:`G2Project.do_refinements`. 109 :meth:`G2Project.get_Variable` Retrieves the value and esd for a parameter 110 :meth:`G2Project.get_Covariance` Retrieves values and covariance for a set of refined parameters 111 :meth:`G2Project.set_Controls` Set overall GSAS-II control settings such as number of cycles and to set up a sequential 112 fit. (Also see :meth:`G2Project.get_Controls` to read values.) 113 :meth:`G2Project.imageMultiDistCalib` Performs a global calibration fit with images at multiple distance settings. 114 :meth:`G2Project.get_Constraints` Retrieves :ref:`constraint definition <Constraint_definitions_table>` entries. 115 :meth:`G2Project.add_HoldConstr` Adds a hold constraint on one or more variables 116 :meth:`G2Project.add_EquivConstr` Adds an equivalence constraint on two or more variables 117 :meth:`G2Project.add_EqnConstr` Adds an equation-type constraint on two or more variables 118 :meth:`G2Project.add_NewVarConstr` Adds an new variable as a constraint on two or more variables 119 ================================================== =============================================================================================================== 120 121 Class :class:`G2Phase` 122 --------------------------------- 123 124 125 Another common object in GSASIIscriptable scripts is :class:`G2Phase`, used to encapsulate each phase in a project, with commonly used methods: 260 Class :class:`~GSASIIscriptable.G2SeqRefRes` 261 ----------------------------------------------- 262 263 To work with Sequential Refinement results, object :class:`~GSASIIscriptable.G2SeqRefRes`, encapsulates the sequential refinement table with methods: 126 264 127 265 .. tabularcolumns:: |l|p{3.5in}| 128 266 129 ================================================== =============================================================================================================== 130 method Use 131 ================================================== =============================================================================================================== 132 :meth:`G2Phase.set_refinements` Provides a mechanism to set values and refinement flags for the phase. See :ref:`Phase_parameters_table` 133 for more details. This information also can be supplied within a call to :meth:`G2Project.do_refinements` 134 or :meth:`G2Project.set_refinement`. 135 :meth:`G2Phase.clear_refinements` Unsets refinement flags for the phase. 136 :meth:`G2Phase.set_HAP_refinements` Provides a mechanism to set values and refinement flags for parameters specific to both this phase and 137 one of its histograms. See :ref:`HAP_parameters_table`. This information also can be supplied within 138 a call to :meth:`G2Project.do_refinements` or :meth:`G2Project.set_refinement`. 139 :meth:`G2Phase.clear_HAP_refinements` Clears refinement flags specific to both this phase and one of its histograms. 140 :meth:`G2Phase.getHAPvalues` Returns values of parameters specific to both this phase and one of its histograms. 141 :meth:`G2Phase.copyHAPvalues` Copies HAP settings between from one phase/histogram and to other histograms in same phase. 142 :meth:`G2Phase.atoms` Returns a list of atoms in the phase 143 :meth:`G2Phase.atom` Returns an atom from its label 144 :meth:`G2Phase.histograms` Returns a list of histograms linked to the phase 145 :meth:`G2Phase.get_cell` Returns unit cell parameters (also see :meth:`G2Phase.get_cell_and_esd`) 146 :meth:`G2Phase.export_CIF` Writes a CIF for the phase 147 :meth:`G2Phase.setSampleProfile` Sets sample broadening parameters 148 :meth:`G2Phase.clearDistRestraint` Clears any previously defined bond distance restraint(s) for the selected phase 149 :meth:`G2Phase.addDistRestraint` Finds and defines new bond distance restraint(s) for the selected phase 150 :meth:`G2Phase.setDistRestraintWeight` Sets the weighting factor for the bond distance restraints 151 152 ================================================== =============================================================================================================== 153 154 Class :class:`G2PwdrData` 155 --------------------------------- 156 157 Another common object in GSASIIscriptable scripts is :class:`G2PwdrData`, which encapsulate each powder diffraction histogram in a project, with commonly used methods: 158 159 .. tabularcolumns:: |l|p{3.5in}| 160 161 ================================================== =============================================================================================================== 162 method Use 163 ================================================== =============================================================================================================== 164 :meth:`G2PwdrData.set_refinements` Provides a mechanism to set values and refinement flags for the powder histogram. See 165 :ref:`Histogram_parameters_table` for details. 166 :meth:`G2PwdrData.clear_refinements` Unsets refinement flags for the the powder histogram. 167 :meth:`G2PwdrData.residuals` Reports R-factors etc. for the the powder histogram (also see :meth:`G2PwdrData.get_wR`) 168 :meth:`G2PwdrData.add_back_peak` Adds a background peak to the histogram. Also see :meth:`G2PwdrData.del_back_peak` and 169 :meth:`G2PwdrData.ref_back_peak`. 170 :meth:`G2PwdrData.fit_fixed_points` Fits background to the specified fixed points. 171 :meth:`G2PwdrData.getdata` Provides access to the diffraction data associated with the histogram. 172 :meth:`G2PwdrData.reflections` Provides access to the reflection lists for the histogram. 173 :meth:`G2PwdrData.Export` Writes the diffraction data or reflection list into a file 174 :meth:`G2PwdrData.add_peak` Adds a peak to the peak list. Also see :ref:`PeakRefine`. 175 :meth:`G2PwdrData.set_peakFlags` Sets refinement flags for peaks 176 :meth:`G2PwdrData.refine_peaks` Starts a peak/background fitting cycle, returns refinement results 177 :attr:`G2PwdrData.Peaks` Provides access to the peak list data structure 178 :attr:`G2PwdrData.PeakList` Provides the peak list parameter values 179 :meth:`G2PwdrData.Export_peaks` Writes the peak parameters to a text file 180 :meth:`G2PwdrData.set_background` Sets a background histogram that will be subtracted (point by point) from the current histogram. 181 ================================================== =============================================================================================================== 182 183 Class :class:`G2Image` 184 --------------------------------- 185 186 When working with images, there will be a :class:`G2Image` object for each image (also see :meth:`G2Project.add_image` and :meth:`G2Project.images`). 187 188 .. tabularcolumns:: |l|p{3.5in}| 189 190 ================================================== =============================================================================================================== 191 method Use 192 ================================================== =============================================================================================================== 193 :meth:`G2Image.Recalibrate` Invokes a recalibration fit starting from the current Image Controls calibration coefficients. 194 :meth:`G2Image.Integrate` Invokes an image integration All parameters Image Controls will have previously been set. 195 :meth:`G2Image.setControl` Set an Image Controls parameter in the current image. 196 :meth:`G2Image.getControl` Return an Image Controls parameter in the current image. 197 :meth:`G2Image.findControl` Get the names of Image Controls parameters. 198 :meth:`G2Image.loadControls` Load controls from a .imctrl file (also see :meth:`G2Image.saveControls`). 199 :meth:`G2Image.loadMasks` Load masks from a .immask file. 200 :meth:`G2Image.setVary` Set a refinement flag for Image Controls parameter in the current image. (Also see :meth:`G2Image.getVary`) 201 :meth:`G2Image.setCalibrant` Set a calibrant type (or show choices) for the current image. 202 :meth:`G2Image.setControlFile` Set a image to be used as a background/dark/gain map image. 203 ================================================== =============================================================================================================== 204 205 206 Class :class:`G2PDF` 207 --------------------------------- 208 209 To work with PDF entries, object :class:`G2PDF`, encapsulates a PDF entry with methods: 210 211 .. tabularcolumns:: |l|p{3.5in}| 212 213 ================================================== =============================================================================================================== 214 method Use 215 ================================================== =============================================================================================================== 216 :meth:`G2PDF.export` Used to write G(r), etc. as a file 217 :meth:`G2PDF.calculate` Computes the PDF using parameters in the object 218 :meth:`G2PDF.optimize` Optimizes selected PDF parameters 219 :meth:`G2PDF.set_background` Sets the histograms used for sample background, container, etc. 220 :meth:`G2PDF.set_formula` Sets the chemical formula for the sample 221 ================================================== =============================================================================================================== 222 223 Class :class:`G2SeqRefRes` 224 --------------------------------- 225 226 To work with Sequential Refinement results, object :class:`G2SeqRefRes`, encapsulates the sequential refinement table with methods: 227 228 .. tabularcolumns:: |l|p{3.5in}| 229 230 ================================================== =============================================================================================================== 231 method Use 232 ================================================== =============================================================================================================== 233 :meth:`G2SeqRefRes.histograms` Provides a list of histograms used in the Sequential Refinement 234 :meth:`G2SeqRefRes.get_cell_and_esd` Returns cell dimensions and standard uncertainies for a phase and histogram from the Sequential Refinement 235 :meth:`G2SeqRefRes.get_Variable` Retrieves the value and esd for a parameter from a particular histogram in the Sequential Refinement 236 :meth:`G2SeqRefRes.get_Covariance` Retrieves values and covariance for a set of refined parameters for a particular histogram 237 ================================================== =============================================================================================================== 238 239 Class :class:`G2AtomRecord` 240 --------------------------------- 241 242 When working with phases, :class:`G2AtomRecord` objects provide access to the contents of each atom in a phase. This provides access to "properties" that can be 267 ====================================================== =============================================================================================================== 268 method Use 269 ====================================================== =============================================================================================================== 270 :meth:`~GSASIIscriptable.G2SeqRefRes.histograms` Provides a list of histograms used in the Sequential Refinement 271 :meth:`~GSASIIscriptable.G2SeqRefRes.get_cell_and_esd` Returns cell dimensions and standard uncertainties for a phase and histogram from the Sequential Refinement 272 :meth:`~GSASIIscriptable.G2SeqRefRes.get_Variable` Retrieves the value and esd for a parameter from a particular histogram in the Sequential Refinement 273 :meth:`~GSASIIscriptable.G2SeqRefRes.get_Covariance` Retrieves values and covariance for a set of refined parameters for a particular histogram 274 ====================================================== =============================================================================================================== 275 276 Class :class:`~GSASIIscriptable.G2AtomRecord` 277 ----------------------------------------------- 278 279 When working with phases, :class:`~GSASIIscriptable.G2AtomRecord` objects provide access to the contents of each atom in a phase. This provides access to "properties" that can be 243 280 used to get values of much of the atoms associated settings: label, type, refinement_flags, coordinates, occupancy, ranId, adp_flag, and uiso. In addition, 244 refinement_flags, occupancy and uiso can be used to set values. See the :class:` G2AtomRecord` docs and source code.281 refinement_flags, occupancy and uiso can be used to set values. See the :class:`~GSASIIscriptable.G2AtomRecord` docs and source code. 245 282 246 283 .. _Refinement_dicts: … … 258 295 259 296 Project-level Parameter Dict 260 ---------------------------- -297 ---------------------------- 261 298 262 299 As noted below (:ref:`Refinement_parameters_kinds`), there are three types of refinement parameters, … … 264 301 but it will often be simplest to create a composite dictionary 265 302 that is used at the project-level. A dict is created with keys 266 "set" and "clear" that can be supplied to :meth:` G2Project.set_refinement`267 (or :meth:` G2Project.do_refinements`, see :ref:`Refinement_recipe` below) that will303 "set" and "clear" that can be supplied to :meth:`~GSASIIscriptable.G2Project.set_refinement` 304 (or :meth:`~GSASIIscriptable.G2Project.do_refinements`, see :ref:`Refinement_recipe` below) that will 268 305 determine parameter values and will determine which parameters will be refined. 269 306 … … 272 309 273 310 Note that optionally a list of histograms and/or phases can be supplied in the call to 274 :meth:` G2Project.set_refinement`, but if not specified, the default is to use all defined311 :meth:`~GSASIIscriptable.G2Project.set_refinement`, but if not specified, the default is to use all defined 275 312 phases and histograms. 276 313 … … 289 326 290 327 Refinement recipe 291 ----------------- -------328 ----------------- 292 329 293 330 Building on the :ref:`Project_dicts`, 294 331 it is possible to specify a sequence of refinement actions as a list of 295 332 these dicts and supplying this list 296 as an argument to :meth:` G2Project.do_refinements`.333 as an argument to :meth:`~GSASIIscriptable.G2Project.do_refinements`. 297 334 298 335 As an example, this code performs the same actions as in the example in the section above: … … 318 355 319 356 The keys defined in the following table 320 may be used in a dict supplied to :meth:` G2Project.do_refinements`. Note that keys ``histograms``357 may be used in a dict supplied to :meth:`~GSASIIscriptable.G2Project.do_refinements`. Note that keys ``histograms`` 321 358 and ``phases`` are used to limit actions to specific sets of parameters within the project. 322 359 … … 355 392 The value supplied can be the object (typically a function) 356 393 that will be called or a string that will evaluate (in the 357 namespace inside :meth:`G2Project.iter_refinements` where 394 namespace inside 395 :meth:`~GSASIIscriptable.G2Project.iter_refinements` where 358 396 ``self`` references the project.) 359 397 Nothing is called if this is not specified. … … 393 431 394 432 Refinement parameter types 395 -------------------------- --433 -------------------------- 396 434 397 435 Note that parameters and refinement flags used in GSAS-II fall into three classes: … … 425 463 426 464 Specifying Refinement Parameters 427 ================================ =465 ================================ 428 466 429 467 Refinement parameter values and flags to turn refinement on and off are specified within dictionaries, … … 437 475 -------------------- 438 476 439 This table describes the dictionaries supplied to :func:` G2PwdrData.set_refinements`440 and :func:` G2PwdrData.clear_refinements`. As an example,477 This table describes the dictionaries supplied to :func:`~GSASIIscriptable.G2PwdrData.set_refinements` 478 and :func:`~GSASIIscriptable.G2PwdrData.clear_refinements`. As an example, 441 479 442 480 .. code-block:: python … … 446 484 "Limits": [10000, 40000]}) 447 485 448 With :meth:` G2Project.do_refinements`, these parameters should be placed inside a dict with a key486 With :meth:`~GSASIIscriptable.G2Project.do_refinements`, these parameters should be placed inside a dict with a key 449 487 ``set``, ``clear``, or ``once``. Values will be set for all histograms, unless the ``histograms`` 450 488 key is used to define specific histograms. As an example: … … 489 527 Note that background peaks are not handled 490 528 via this; see 491 :meth:` G2PwdrData.ref_back_peak` instead.529 :meth:`~GSASIIscriptable.G2PwdrData.ref_back_peak` instead. 492 530 When value is a dict, 493 531 supply any of the following keys: … … 507 545 are allowed). 508 546 509 Instrument Parameters As in Sample Param ters, provide as a **list** of547 Instrument Parameters As in Sample Parameters, provide as a **list** of 510 548 subkeys to 511 549 set or clear, e.g. ['X', 'Y', 'Zero', 'SH/L'] … … 528 566 ---------------- 529 567 530 This table describes the dictionaries supplied to :func:` G2Phase.set_refinements`531 and :func:` G2Phase.clear_refinements`. With :meth:`G2Project.do_refinements`,568 This table describes the dictionaries supplied to :func:`~GSASIIscriptable.G2Phase.set_refinements` 569 and :func:`~GSASIIscriptable.G2Phase.clear_refinements`. With :meth:`~GSASIIscriptable.G2Project.do_refinements`, 532 570 these parameters should be placed inside a dict with a key 533 571 ``set``, ``clear``, or ``once``. Values will be set for all phases, unless the ``phases`` … … 558 596 ------------------------------ 559 597 560 This table describes the dictionaries supplied to :func:` G2Phase.set_HAP_refinements`561 and :func:` G2Phase.clear_HAP_refinements`. When supplied to562 :meth:` G2Project.do_refinements`, these parameters should be placed inside a dict with a key598 This table describes the dictionaries supplied to :func:`~GSASIIscriptable.G2Phase.set_HAP_refinements` 599 and :func:`~GSASIIscriptable.G2Phase.clear_HAP_refinements`. When supplied to 600 :meth:`~GSASIIscriptable.G2Project.do_refinements`, these parameters should be placed inside a dict with a key 563 601 ``set``, ``clear``, or ``once``. Values will be set for all histograms used in each phase, 564 602 unless the ``histograms`` and ``phases`` keys are used to define specific phases and histograms. … … 610 648 611 649 Histogram/Phase objects 612 ----------------------- -613 Each phase and powder histogram in a :class:` G2Project` object has an associated650 ----------------------- 651 Each phase and powder histogram in a :class:`~GSASIIscriptable.G2Project` object has an associated 614 652 object. Parameters within each individual object can be turned on and off by calling 615 :meth:` G2PwdrData.set_refinements` or :meth:`G2PwdrData.clear_refinements`653 :meth:`~GSASIIscriptable.G2PwdrData.set_refinements` or :meth:`~GSASIIscriptable.G2PwdrData.clear_refinements` 616 654 for histogram parameters; 617 :meth:` G2Phase.set_refinements` or :meth:`G2Phase.clear_refinements`618 for phase parameters; and :meth:` G2Phase.set_HAP_refinements` or619 :meth:` G2Phase.clear_HAP_refinements`. As an example, if some_histogram is a histogram object (of type :class:`G2PwdrData`), use this to set parameters in that histogram:655 :meth:`~GSASIIscriptable.G2Phase.set_refinements` or :meth:`~GSASIIscriptable.G2Phase.clear_refinements` 656 for phase parameters; and :meth:`~GSASIIscriptable.G2Phase.set_HAP_refinements` or 657 :meth:`~GSASIIscriptable.G2Phase.clear_HAP_refinements`. As an example, if some_histogram is a histogram object (of type :class:`~GSASIIscriptable.G2PwdrData`), use this to set parameters in that histogram: 620 658 621 659 .. code-block:: python … … 668 706 669 707 Access to other parameter settings 670 ================================== =708 ================================== 671 709 672 710 There are several hundred different types of values that can be stored in a … … 676 714 but sometimes determining what should be set to implement a parameter 677 715 change can be complex. 678 Several routines, :meth:` G2Phase.getHAPentryList`,679 :meth:` G2Phase.getPhaseEntryList` and :meth:`G2PwdrData.getHistEntryList`716 Several routines, :meth:`~GSASIIscriptable.G2Phase.getHAPentryList`, 717 :meth:`~GSASIIscriptable.G2Phase.getPhaseEntryList` and :meth:`~GSASIIscriptable.G2PwdrData.getHistEntryList` 680 718 (and their related get...Value and set.Value entries), 681 719 provide a mechanism to discover what the GUI is changing inside a .gpx file. … … 764 802 765 803 Code Examples 766 ================================= 767 768 .. _PeakRefine: 769 804 ============= 805 806 .. _ScriptingShortcut: 807 808 Shortcut for Scripting Access 809 ----------------------------- 810 811 As is seen in a number of the code examples, the location where GSAS-II is 812 specified in the GSAS-II script using commands such as 813 814 .. code-block:: python 815 816 import sys 817 sys.path.insert(0,'/Users/toby/software/G2/GSASII') # needed to "find" GSAS-II modules 818 import GSASIIscriptable as G2sc 819 820 An alternative to this is to "install" the current GSAS-II installation into the current 821 Python interpreter. Once this has been done a single time, this single command can be used to replace 822 the three commands listed above for all future uses of GSASIIscripting: 823 824 .. code-block:: python 825 826 import G2script as G2sc 827 828 There are two ways this installation can be done. The most easy way is to invoke the 829 "Install GSASIIscriptable shortcut" command in the GSAS-II GUI's 830 File menu. Alternatively it can be accomplished from within GSASIIscriptable 831 using these commands: 832 833 .. code-block:: python 834 835 import sys 836 sys.path.insert(0,'/Users/toby/software/G2/GSASII') # update this for your installation 837 import GSASIIscriptable as G2sc 838 G2sc.installScriptingShortcut() 839 840 Note the shortcut only installs use of GSAS-II with the current Python 841 installation. If more than one Python installation will be used with GSAS-II 842 (for example because different conda environments are used), a shortcut 843 should be created from within each Python environment. 844 845 If more than one GSAS-II installation will be used with a Python installation, 846 a shortcut can only be used with one of them. 847 848 .. _PeakRefine: 849 770 850 Peak Fitting 771 ------------ --------851 ------------ 772 852 773 853 Peak refinement is performed with routines 774 :meth:` G2PwdrData.add_peak`, :meth:`G2PwdrData.set_peakFlags` and775 :meth:` G2PwdrData.refine_peaks`. Method :meth:`G2PwdrData.Export_peaks` and776 properties :attr:` G2PwdrData.Peaks` and :attr:`G2PwdrData.PeakList`854 :meth:`~GSASIIscriptable.G2PwdrData.add_peak`, :meth:`~GSASIIscriptable.G2PwdrData.set_peakFlags` and 855 :meth:`~GSASIIscriptable.G2PwdrData.refine_peaks`. Method :meth:`~GSASIIscriptable.G2PwdrData.Export_peaks` and 856 properties :attr:`~GSASIIscriptable.G2PwdrData.Peaks` and :attr:`~GSASIIscriptable.G2PwdrData.PeakList` 777 857 provide ways to access the results. Note that when peak parameters are 778 refined with :meth:`~G 2PwdrData.refine_peaks`, the background may also779 be refined. Use :meth:` G2PwdrData.set_refinements` to change background858 refined with :meth:`~GSASIIscriptable.~G2PwdrData.refine_peaks`, the background may also 859 be refined. Use :meth:`~GSASIIscriptable.G2PwdrData.set_refinements` to change background 780 860 settings and the range of data used in the fit. See below for an example 781 861 peak refinement script, where the data files are taken from the … … 814 894 815 895 Pattern Simulation 816 ------------------ -----896 ------------------ 817 897 818 898 This shows two examples where a structure is read from a CIF, a … … 871 951 872 952 Simple Refinement 873 ----------------- -----953 ----------------- 874 954 875 955 GSASIIscriptable can be used to setup and perform simple refinements. … … 892 972 893 973 Sequential Refinement 894 --------------------- -974 --------------------- 895 975 896 976 GSASIIscriptable can be used to setup and perform sequential refinements. This example script … … 937 1017 938 1018 Image Processing 939 ---------------- ------1019 ---------------- 940 1020 941 1021 A sample script where an image is read, assigned calibration values from a file … … 996 1076 997 1077 Image Calibration 998 ----------------- -----1078 ----------------- 999 1079 1000 1080 This example performs a number of cycles of constrained fitting. 1001 1081 A project is created with the images found in a directory, setting initial 1002 1082 parameters as the images are read. The initial values 1003 for the calibration are not very good, so a :meth:` G2Image.Recalibrate` is done1083 for the calibration are not very good, so a :meth:`~GSASIIscriptable.G2Image.Recalibrate` is done 1004 1084 to quickly improve the fit. Once that is done, a fit of all images is performed 1005 1085 where the wavelength, an offset and detector orientation are constrained to … … 1059 1139 gpx.save() 1060 1140 1141 .. _OptInteg_Example: 1142 1143 Optimized Image Integration 1144 --------------------------- 1145 1146 This example shows how image integration, including pixel masking of outliers, 1147 can be accomplished for a series of images where the calibration and 1148 other masking (Frame, Spots, etc) are the same for all images. This code has been optimized 1149 significantly so that computations are cached and are not repeated where possible. For one 1150 set of test data, processing of the first image takes ~5 seconds, but processing of subsequent 1151 takes on the order of 0.7 sec. 1152 1153 This code uses an ``import G2script as G2sc`` statement to access GSASIIscriptable 1154 without referencing the GSAS-II installation directory. This requires installing a reference to 1155 the GSAS-II location into the current a Python installation, which can be done from the GUI 1156 or with scripting commands, as is discussed in :ref:`ScriptingShortcut`. Here 1157 function :func:`~GSASIIscriptable.installScriptingShortcut` was used to create 1158 the :mod:`G2script` module. That code has been retained here as comments to show what was done. 1159 1160 To simplify use of this script, it is assumed that the script will be placed in the same 1161 directory as where the data files will be collected. Other customization is done 1162 in variables at the beginning of the code. Note that the beamline where these data are collected 1163 opens the output .tif files before the data collection for that image is complete. Once the .metadata 1164 file has been created, the image may be read. 1165 1166 Processing progresses as follows: 1167 * Once a set of images are found, a project is created. This is never written and will be deleted after the images are processed. 1168 * For each image file, routine :meth:`~GSASIIscriptable.G2Project.add_image` is used to add image(s) from that file to the project. The .tif format can only hold one image, but others can have more than one. 1169 * When the first image is processed, calibration and mask info is read; a number of computations are performed and cached. 1170 * For subsequent images cached information is used. 1171 * Pixel masking is performed in :meth:`~GSASIIscriptable.G2Image.GeneratePixelMask` and the mask is saved into the image. 1172 * Image integration is performed in :meth:`~GSASIIscriptable.G2Image.Integrate`. 1173 * Note that multiple powder patterns could be created from one image, so creation of data files is done in a loop with :meth:`~GSASIIscriptable.G2PwdrData.Export`. 1174 * To reduce memory demands, cached versions of the Pixel map and the Image are deleted and the image file is moved to a separate directory so note that it has been processed. 1175 * The project (.gpx file) is deleted and recreated periodically so that the memory footprint for this script does not grow. 1176 1177 .. code-block:: python 1178 1179 import os,glob,time,shutil 1180 1181 #### Create G2script: do this once ################################################ 1182 #import sys 1183 #sys.path.insert(0,'/Users/toby/software/G2/GSASII') # update with your install loc 1184 #import GSASIIscriptable as G2sc 1185 #G2sc.installScriptingShortcut() 1186 ################################################################################### 1187 1188 import G2script as G2sc 1189 G2sc.SetPrintLevel('warn') # reduces output 1190 1191 cache = {} # place to save intermediate computations 1192 # define location & names of files 1193 dataLoc = os.path.abspath(os.path.split(__file__)[0]) # data in location of this file 1194 PathWrap = lambda fil: os.path.join(dataLoc,fil) # convenience function for file paths 1195 imgctrl = PathWrap('Si_ch3_d700-00000.imctrl') 1196 imgmask = PathWrap('Si_ch3_d700-00000.immask') 1197 globPattern = PathWrap("*_d700-*.tif") 1198 1199 def wait_for_metadata(tifname): 1200 '''A .tif file is created before it can be read. Wait for the 1201 metadata file to be created before trying to read both. 1202 ''' 1203 while not os.path.exists(tifname + '.metadata'): 1204 time.sleep(0.05) 1205 1206 # make a subfolder to store integrated images & integrated patterns 1207 pathImg = os.path.join(dataLoc,'img') 1208 if not os.path.exists(pathImg): os.mkdir(pathImg) 1209 pathxye = os.path.join(dataLoc,'xye') 1210 if not os.path.exists(pathxye): os.mkdir(pathxye) 1211 1212 while True: # Loop will never end, stop with ctrl+C 1213 tiflist = sorted(glob.glob(globPattern),key=lambda x: os.path.getctime(x)) # get images sorted by creation time, oldest 1st 1214 if not tiflist: 1215 time.sleep(0.1) 1216 continue 1217 gpx = G2sc.G2Project(newgpx=PathWrap('integration.gpx')) # temporary use 1218 for tifname in tiflist: 1219 starttime = time.time() 1220 wait_for_metadata(tifname) 1221 for img in gpx.add_image(tifname,fmthint="TIF",cacheImage=True): # loop unneeded for TIF (1 image/file) 1222 if not cache: # load & compute controls & 2theta values once 1223 img.loadControls(imgctrl) # set controls/calibrations/masks 1224 img.loadMasks(imgmask) 1225 cache['Image Controls'] = img.getControls() # save controls & masks contents for quick reload 1226 cache['Masks'] = img.getMasks() 1227 cache['intMaskMap'] = img.IntMaskMap() # calc mask & TA arrays to save for integrations 1228 cache['intTAmap'] = img.IntThetaAzMap() 1229 cache['FrameMask'] = img.MaskFrameMask() # calc Frame mask & T array to save for Pixel masking 1230 cache['maskTmap'] = img.MaskThetaMap() 1231 else: 1232 img.setControls(cache['Image Controls']) 1233 img.setMasks(cache['Masks'],True) # True: reset threshold masks 1234 img.GeneratePixelMask(esdMul=3,ThetaMap=cache['maskTmap'],FrameMask=cache['FrameMask']) 1235 for pwdr in img.Integrate(MaskMap=cache['intMaskMap'],ThetaAzimMap=cache['intTAmap']): 1236 pwdr.Export(os.path.join(pathxye,os.path.split(tifname)[1]),'.xye') # '.tif in name ignored 1237 img.clearImageCache() # save some space 1238 img.clearPixelMask() 1239 shutil.move(tifname, pathImg) # move file after integration so that it is not searchable 1240 shutil.move(tifname + '.metadata', pathImg) 1241 print('*=== processing complete, time=',time.time()-starttime,'sec\n') 1242 del gpx 1243 1244 1061 1245 .. _HistExport: 1062 1246 1063 1247 Histogram Export 1064 ---------------- ----1248 ---------------- 1065 1249 1066 1250 This example shows how to export a series of histograms from a collection of … … 1068 1252 matching a wildcard in the specified directory (``dataloc``). For each file 1069 1253 there is a loop over histograms in that project and for each histogram 1070 :meth:` G2PwdrData.Export` is called to write out the contents of that histogram1254 :meth:`~GSASIIscriptable.G2PwdrData.Export` is called to write out the contents of that histogram 1071 1255 as CSV (comma-separated variable) file that contains data positions, 1072 observed, computed and backgroun intensities as well as weighting for each1256 observed, computed and background intensities as well as weighting for each 1073 1257 point and Q. Note that for the Export call, there is more than one choice of 1074 1258 exporter that can write ``.csv`` extension files, so the export hint must … … 1095 1279 1096 1280 1097 Installation of GSASIIscriptable1098 =======================================1099 1100 It is assumed that most people using GSASIIscriptable will also want to use the GUI, for this the standard1101 `installation instructions <https://subversion.xray.aps.anl.gov/trac/pyGSAS#Installationinstructions>`_ should be followed. The GUI includes all files needed to run scriptable.1102 Noting that not all GSAS-II capabilities are not available1103 by scripting -- yet. Even if the scripting API were to be fully completed,1104 there will still be some things that GSAS-II does1105 with the GUI would be almost impossible to implement without a1106 interactive graphical view of the data.1107 1108 Nonetheless, there may be times where it does make sense to install GSAS-II without all of the GUI components, for example on a compute server. As `described here1109 <https://gsas-ii.readthedocs.io/en/latest/packages.html#scripting-requirements>`_ the minimal python requirements are only numpy and scipy. It is assumed that1110 anyone able to use scripting is well posed to install from the command line.1111 Below are example commands to install GSAS-II for use for scripting only.1112 1113 **Installing a minimal Python configuration**: Note I have chosen below1114 to use the free1115 miniconda installer from Anaconda, Inc., but there are also plenty of1116 other ways to install Python, Numpy and Scipy on Linux, Windows and MacOS.1117 For Linux a reasonable alternative is to install these packages1118 (and perhaps others as below) using the Linux dist (``apt-get`` etc.).1119 1120 .. code-block:: bash1121 1122 bash ~/Downloads/Miniconda3-latest-<platform>-x86_64.sh -b -p /loc/pyg2script1123 source /loc/pyg2script/bin/activate1124 conda install numpy scipy matplotlib pillow h5py hdf5 svn1125 1126 Some discussion on these commands follows:1127 1128 * the 1st command (bash) assumes that the appropriate version of Miniconda has been downloaded from https://docs.conda.io/en/latest/miniconda.html and ``/loc/pyg2script`` is where I have selected for python to be installed. You might want to use something like ``~/pyg2script``.1129 * the 2nd command (source) is needed to access Python with miniconda.1130 * the 3rd command (conda) installs all possible packages that might be used by scripting, but matplotlib, pillow, and hdf5 are not commonly needed and could be omitted. The svn package is not needed (for example on Linux) where this has been installed in another way.1131 1132 Once svn and Python has been installed and is in the path, use these commands to install GSAS-II:1133 1134 .. code-block:: bash1135 1136 svn co https://subversion.xray.aps.anl.gov/pyGSAS/trunk /loc/GSASII1137 python /loc/GSASII/GSASIIscriptable.py1138 1139 Notes on these commands:1140 1141 * the 1st command (svn) is used to download the GSAS-II software. ``/loc/GSASII`` is the location where I decided to install the software. You can select something different.1142 * the 2nd command (python) is used to invoke GSAS-II scriptable for the first time, which is needed to load the binary files from the server.1143 1144 1281 GSASIIscriptable Command-line Interface 1145 1282 ======================================= … … 1159 1296 The following subcommands are defined: 1160 1297 1161 * create, see :func:` create`1162 * add, see :func:` add`1163 * dump, see :func:` dump`1164 * refine, see :func:` refine`1165 * export, :func:` export`1166 * browse, see :func:` IPyBrowse`1298 * create, see :func:`~GSASIIscriptable.create` 1299 * add, see :func:`~GSASIIscriptable.add` 1300 * dump, see :func:`~GSASIIscriptable.dump` 1301 * refine, see :func:`~GSASIIscriptable.refine` 1302 * export, :func:`~GSASIIscriptable.export` 1303 * browse, see :func:`~GSASIIscriptable.IPyBrowse` 1167 1304 1168 1305 Run:: … … 1176 1313 1177 1314 Parameters in JSON files 1178 ------------------------ -1315 ------------------------ 1179 1316 1180 1317 The refine command requires two inputs: an existing GSAS-II project (.gpx) file and … … 1199 1336 1200 1337 API: Complete Documentation 1201 =========================== =================================1338 =========================== 1202 1339 1203 1340 .. automodule:: GSASIIscriptable
Note: See TracChangeset
for help on using the changeset viewer.