source: trunk/sphinxdocs/build/html/_modules/G2export_pwdr.html @ 1513

Last change on this file since 1513 was 1513, checked in by toby, 9 years ago

update and rebuild docs

  • Property svn:mime-type set to text/html
File size: 34.9 KB
Line 
1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
4
5<html xmlns="http://www.w3.org/1999/xhtml">
6  <head>
7    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
8   
9    <title>G2export_pwdr &mdash; GSAS-II 0.2.0 documentation</title>
10   
11    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
12    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
13   
14    <script type="text/javascript">
15      var DOCUMENTATION_OPTIONS = {
16        URL_ROOT:    '../',
17        VERSION:     '0.2.0',
18        COLLAPSE_INDEX: false,
19        FILE_SUFFIX: '.html',
20        HAS_SOURCE:  true
21      };
22    </script>
23    <script type="text/javascript" src="../_static/jquery.js"></script>
24    <script type="text/javascript" src="../_static/underscore.js"></script>
25    <script type="text/javascript" src="../_static/doctools.js"></script>
26    <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
27    <link rel="top" title="GSAS-II 0.2.0 documentation" href="../index.html" />
28    <link rel="up" title="Module code" href="index.html" /> 
29  </head>
30  <body>
31    <div class="related">
32      <h3>Navigation</h3>
33      <ul>
34        <li class="right" style="margin-right: 10px">
35          <a href="../genindex.html" title="General Index"
36             accesskey="I">index</a></li>
37        <li class="right" >
38          <a href="../py-modindex.html" title="Python Module Index"
39             >modules</a> |</li>
40        <li><a href="../index.html">GSAS-II 0.2.0 documentation</a> &raquo;</li>
41          <li><a href="index.html" accesskey="U">Module code</a> &raquo;</li> 
42      </ul>
43    </div> 
44
45    <div class="document">
46      <div class="documentwrapper">
47        <div class="bodywrapper">
48          <div class="body">
49           
50  <h1>Source code for G2export_pwdr</h1><div class="highlight"><pre>
51<span class="c">#!/usr/bin/env python</span>
52<span class="c"># -*- coding: utf-8 -*-</span>
53<span class="c">########### SVN repository information ###################</span>
54<span class="c"># $Date: 2014-05-06 12:19:05 -0500 (Tue, 06 May 2014) $</span>
55<span class="c"># $Author: vondreele $</span>
56<span class="c"># $Revision: 1329 $</span>
57<span class="c"># $URL: https://subversion.xor.aps.anl.gov/pyGSAS/trunk/exports/G2export_pwdr.py $</span>
58<span class="c"># $Id: G2export_pwdr.py 1329 2014-05-06 17:19:05Z vondreele $</span>
59<span class="c">########### SVN repository information ###################</span>
60<span class="sd">&#39;&#39;&#39;</span>
61<span class="sd">*Module G2export_pwdr: Export powder input files*</span>
62<span class="sd">-------------------------------------------------</span>
63
64<span class="sd">Creates files used by GSAS (FXYE) &amp; TOPAS (XYE) as input</span>
65
66<span class="sd">&#39;&#39;&#39;</span>
67<span class="kn">import</span> <span class="nn">os.path</span>
68<span class="kn">import</span> <span class="nn">numpy</span> <span class="kn">as</span> <span class="nn">np</span>
69<span class="kn">import</span> <span class="nn">GSASIIpath</span>
70<span class="n">GSASIIpath</span><span class="o">.</span><span class="n">SetVersionNumber</span><span class="p">(</span><span class="s">&quot;$Revision: 1329 $&quot;</span><span class="p">)</span>
71<span class="kn">import</span> <span class="nn">GSASIIIO</span> <span class="kn">as</span> <span class="nn">G2IO</span>
72<span class="kn">import</span> <span class="nn">GSASIIpy3</span> <span class="kn">as</span> <span class="nn">G2py3</span>
73<span class="kn">import</span> <span class="nn">GSASIIobj</span> <span class="kn">as</span> <span class="nn">G2obj</span>
74
75<div class="viewcode-block" id="ExportPowderFXYE"><a class="viewcode-back" href="../exports.html#G2export_pwdr.ExportPowderFXYE">[docs]</a><span class="k">class</span> <span class="nc">ExportPowderFXYE</span><span class="p">(</span><span class="n">G2IO</span><span class="o">.</span><span class="n">ExportBaseclass</span><span class="p">):</span>
76    <span class="sd">&#39;&#39;&#39;Used to create a FXYE file for a powder data set</span>
77
78<span class="sd">    :param wx.Frame G2frame: reference to main GSAS-II frame</span>
79<span class="sd">    &#39;&#39;&#39;</span>
80    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">G2frame</span><span class="p">):</span>
81        <span class="nb">super</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__class__</span><span class="p">,</span><span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span> <span class="c"># fancy way to say &lt;parentclass&gt;.__init__</span>
82            <span class="n">G2frame</span><span class="o">=</span><span class="n">G2frame</span><span class="p">,</span>
83            <span class="n">formatName</span> <span class="o">=</span> <span class="s">&#39;GSAS FXYE file&#39;</span><span class="p">,</span>
84            <span class="n">extension</span><span class="o">=</span><span class="s">&#39;.fxye&#39;</span><span class="p">,</span>
85            <span class="n">longFormatName</span> <span class="o">=</span> <span class="s">&#39;Export powder data as GSAS FXYE (column) file&#39;</span>
86            <span class="p">)</span>
87        <span class="bp">self</span><span class="o">.</span><span class="n">exporttype</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;powder&#39;</span><span class="p">]</span>
88        <span class="bp">self</span><span class="o">.</span><span class="n">multiple</span> <span class="o">=</span> <span class="bp">True</span>
89
90<div class="viewcode-block" id="ExportPowderFXYE.WriteInstFile"><a class="viewcode-back" href="../exports.html#G2export_pwdr.ExportPowderFXYE.WriteInstFile">[docs]</a>    <span class="k">def</span> <span class="nf">WriteInstFile</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">hist</span><span class="p">,</span><span class="n">Inst</span><span class="p">):</span>
91        <span class="sd">&#39;&#39;&#39;Write an instrument parameter file</span>
92<span class="sd">        &#39;&#39;&#39;</span>
93        <span class="n">prmname</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">splitext</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">filename</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="s">&#39;.prm&#39;</span>
94        <span class="n">prmname</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dirname</span><span class="p">,</span><span class="n">prmname</span><span class="p">)</span>
95        <span class="bp">self</span><span class="o">.</span><span class="n">OpenFile</span><span class="p">(</span><span class="n">prmname</span><span class="p">)</span>
96        <span class="bp">self</span><span class="o">.</span><span class="n">Write</span><span class="p">(</span> <span class="s">&#39;            123456789012345678901234567890123456789012345678901234567890        &#39;</span><span class="p">)</span>
97        <span class="bp">self</span><span class="o">.</span><span class="n">Write</span><span class="p">(</span> <span class="s">&#39;INS   BANK      1                                                               &#39;</span><span class="p">)</span>
98        <span class="bp">self</span><span class="o">.</span><span class="n">Write</span><span class="p">((</span><span class="s">&#39;INS   HTYPE   </span><span class="si">%s</span><span class="s">R                                                              &#39;</span><span class="p">)</span><span class="o">%</span><span class="p">(</span><span class="n">Inst</span><span class="p">[</span><span class="s">&#39;Type&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]))</span>
99        <span class="k">if</span> <span class="s">&#39;Lam1&#39;</span> <span class="ow">in</span> <span class="n">Inst</span><span class="p">:</span>              <span class="c">#Ka1 &amp; Ka2</span>
100            <span class="bp">self</span><span class="o">.</span><span class="n">Write</span><span class="p">((</span><span class="s">&#39;INS  1 ICONS</span><span class="si">%10.7f%10.7f</span><span class="s">    0.0000               0.990    0     0.500   &#39;</span><span class="p">)</span><span class="o">%</span><span class="p">(</span><span class="n">Inst</span><span class="p">[</span><span class="s">&#39;Lam1&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">],</span><span class="n">Inst</span><span class="p">[</span><span class="s">&#39;Lam2&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]))</span>
101        <span class="k">elif</span> <span class="s">&#39;Lam&#39;</span> <span class="ow">in</span> <span class="n">Inst</span><span class="p">:</span>             <span class="c">#single wavelength</span>
102            <span class="bp">self</span><span class="o">.</span><span class="n">Write</span><span class="p">((</span><span class="s">&#39;INS  1 ICONS</span><span class="si">%10.7f%10.7f</span><span class="s">    0.0000               0.990    0     0.500   &#39;</span><span class="p">)</span><span class="o">%</span><span class="p">(</span><span class="n">Inst</span><span class="p">[</span><span class="s">&#39;Lam&#39;</span><span class="p">][</span><span class="mi">1</span><span class="p">],</span><span class="mf">0.0</span><span class="p">))</span>
103        <span class="bp">self</span><span class="o">.</span><span class="n">Write</span><span class="p">(</span> <span class="s">&#39;INS  1 IRAD     0                                                               &#39;</span><span class="p">)</span>
104        <span class="bp">self</span><span class="o">.</span><span class="n">Write</span><span class="p">(</span> <span class="s">&#39;INS  1I HEAD                                                                    &#39;</span><span class="p">)</span>
105        <span class="bp">self</span><span class="o">.</span><span class="n">Write</span><span class="p">(</span> <span class="s">&#39;INS  1I ITYP    0    0.0000  180.0000         1                                 &#39;</span><span class="p">)</span>
106        <span class="bp">self</span><span class="o">.</span><span class="n">Write</span><span class="p">((</span><span class="s">&#39;INS  1DETAZM</span><span class="si">%10.3f</span><span class="s">                                                          &#39;</span><span class="p">)</span><span class="o">%</span><span class="p">(</span><span class="n">Inst</span><span class="p">[</span><span class="s">&#39;Azimuth&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]))</span>
107        <span class="bp">self</span><span class="o">.</span><span class="n">Write</span><span class="p">(</span> <span class="s">&#39;INS  1PRCF1     3    8   0.00100                                                &#39;</span><span class="p">)</span>
108        <span class="bp">self</span><span class="o">.</span><span class="n">Write</span><span class="p">((</span><span class="s">&#39;INS  1PRCF11     </span><span class="si">%15.6g%15.6g%15.6g%15.6g</span><span class="s">   &#39;</span><span class="p">)</span><span class="o">%</span><span class="p">(</span><span class="n">Inst</span><span class="p">[</span><span class="s">&#39;U&#39;</span><span class="p">][</span><span class="mi">1</span><span class="p">],</span><span class="n">Inst</span><span class="p">[</span><span class="s">&#39;V&#39;</span><span class="p">][</span><span class="mi">1</span><span class="p">],</span><span class="n">Inst</span><span class="p">[</span><span class="s">&#39;W&#39;</span><span class="p">][</span><span class="mi">1</span><span class="p">],</span><span class="mf">0.0</span><span class="p">))</span>
109        <span class="bp">self</span><span class="o">.</span><span class="n">Write</span><span class="p">((</span><span class="s">&#39;INS  1PRCF12     </span><span class="si">%15.6g%15.6g%15.6g%15.6g</span><span class="s">   &#39;</span><span class="p">)</span><span class="o">%</span><span class="p">(</span><span class="n">Inst</span><span class="p">[</span><span class="s">&#39;X&#39;</span><span class="p">][</span><span class="mi">1</span><span class="p">],</span><span class="n">Inst</span><span class="p">[</span><span class="s">&#39;Y&#39;</span><span class="p">][</span><span class="mi">1</span><span class="p">],</span><span class="n">Inst</span><span class="p">[</span><span class="s">&#39;SH/L&#39;</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span><span class="o">/</span><span class="mf">2.</span><span class="p">,</span><span class="n">Inst</span><span class="p">[</span><span class="s">&#39;SH/L&#39;</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span><span class="o">/</span><span class="mf">2.</span><span class="p">))</span>
110        <span class="bp">self</span><span class="o">.</span><span class="n">CloseFile</span><span class="p">()</span>
111        <span class="k">print</span><span class="p">(</span><span class="s">&#39;Parameters from &#39;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">hist</span><span class="p">)</span><span class="o">+</span><span class="s">&#39; written to file &#39;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">prmname</span><span class="p">))</span>
112        <span class="k">return</span> <span class="n">prmname</span>
113</div>
114<div class="viewcode-block" id="ExportPowderFXYE.Exporter"><a class="viewcode-back" href="../exports.html#G2export_pwdr.ExportPowderFXYE.Exporter">[docs]</a>    <span class="k">def</span> <span class="nf">Exporter</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">event</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
115        <span class="sd">&#39;&#39;&#39;Export one or more sets of powder data as FXYE file(s)</span>
116<span class="sd">        &#39;&#39;&#39;</span>
117        <span class="c"># the export process starts here</span>
118        <span class="bp">self</span><span class="o">.</span><span class="n">InitExport</span><span class="p">(</span><span class="n">event</span><span class="p">)</span>
119        <span class="c"># load all of the tree into a set of dicts</span>
120        <span class="bp">self</span><span class="o">.</span><span class="n">loadTree</span><span class="p">()</span>
121        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">ExportSelect</span><span class="p">(</span> <span class="c"># set export parameters</span>
122            <span class="n">AskFile</span><span class="o">=</span><span class="s">&#39;single&#39;</span> <span class="c"># get a file name/directory to save in</span>
123            <span class="p">):</span> <span class="k">return</span>
124        <span class="n">filenamelist</span> <span class="o">=</span> <span class="p">[]</span>
125        <span class="k">for</span> <span class="n">hist</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">histnam</span><span class="p">:</span>
126            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">histnam</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
127                <span class="c"># multiple files: create a unique name from the histogram</span>
128                <span class="n">fileroot</span> <span class="o">=</span> <span class="n">G2obj</span><span class="o">.</span><span class="n">MakeUniqueLabel</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">MakePWDRfilename</span><span class="p">(</span><span class="n">hist</span><span class="p">),</span><span class="n">filenamelist</span><span class="p">)</span>
129                <span class="c"># create an instrument parameter file</span>
130                <span class="bp">self</span><span class="o">.</span><span class="n">filename</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dirname</span><span class="p">,</span><span class="n">fileroot</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">extension</span><span class="p">)</span>
131            <span class="k">else</span><span class="p">:</span>
132                <span class="c"># use the supplied name, but force the extension</span>
133                <span class="bp">self</span><span class="o">.</span><span class="n">filename</span><span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">splitext</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">filename</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">extension</span>
134               
135            <span class="n">histblk</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">Histograms</span><span class="p">[</span><span class="n">hist</span><span class="p">]</span>
136            <span class="n">prmname</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">WriteInstFile</span><span class="p">(</span><span class="n">hist</span><span class="p">,</span><span class="n">histblk</span><span class="p">[</span><span class="s">&#39;Instrument Parameters&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">])</span>
137           
138            <span class="bp">self</span><span class="o">.</span><span class="n">OpenFile</span><span class="p">()</span>
139            <span class="bp">self</span><span class="o">.</span><span class="n">Write</span><span class="p">(</span><span class="n">hist</span><span class="p">[</span><span class="mi">5</span><span class="p">:])</span>
140            <span class="bp">self</span><span class="o">.</span><span class="n">Write</span><span class="p">(</span><span class="s">&#39;Instrument parameter file:&#39;</span><span class="o">+</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="n">prmname</span><span class="p">)[</span><span class="mi">1</span><span class="p">])</span>
141            <span class="n">x</span> <span class="o">=</span> <span class="mi">100</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">histblk</span><span class="p">[</span><span class="s">&#39;Data&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">])</span>
142            <span class="c"># convert weights to sigmas; use largest weight as minimum esd</span>
143            <span class="n">s</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">maximum</span><span class="p">(</span><span class="mf">0.</span><span class="p">,</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">histblk</span><span class="p">[</span><span class="s">&#39;Data&#39;</span><span class="p">][</span><span class="mi">2</span><span class="p">])))</span>
144            <span class="n">s</span><span class="p">[</span><span class="n">s</span><span class="o">==</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">s</span><span class="p">)</span>
145            <span class="n">s</span> <span class="o">=</span> <span class="mf">1.</span><span class="o">/</span><span class="n">s</span>
146            <span class="bp">self</span><span class="o">.</span><span class="n">Write</span><span class="p">(</span><span class="s">&#39;BANK 1 </span><span class="si">%d</span><span class="s"> </span><span class="si">%d</span><span class="s"> CONS </span><span class="si">%.2f</span><span class="s"> </span><span class="si">%.2f</span><span class="s"> 0 0 FXYE&#39;</span> <span class="o">%</span> <span class="p">(</span>
147                <span class="nb">len</span><span class="p">(</span><span class="n">x</span><span class="p">),</span><span class="nb">len</span><span class="p">(</span><span class="n">x</span><span class="p">),</span><span class="n">x</span><span class="p">[</span><span class="mi">0</span><span class="p">],(</span><span class="n">x</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">-</span><span class="n">x</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
148                <span class="p">))</span>
149<span class="c">#            for X,Y,S in zip(x,histblk[&#39;Data&#39;][1],s):</span>
150<span class="c">#                self.Write(&quot;{:15.6g} {:15.6g} {:15.6g}&quot;.format(X,Y,S))</span>
151            <span class="k">for</span> <span class="n">XYS</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">histblk</span><span class="p">[</span><span class="s">&#39;Data&#39;</span><span class="p">][</span><span class="mi">1</span><span class="p">],</span><span class="n">s</span><span class="p">):</span>
152                <span class="n">line</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
153                <span class="k">for</span> <span class="n">val</span> <span class="ow">in</span> <span class="n">XYS</span><span class="p">:</span>
154                    <span class="n">line</span> <span class="o">+=</span> <span class="n">G2py3</span><span class="o">.</span><span class="n">FormatPadValue</span><span class="p">(</span><span class="n">val</span><span class="p">,(</span><span class="mi">15</span><span class="p">,</span><span class="mi">6</span><span class="p">))</span>
155                <span class="bp">self</span><span class="o">.</span><span class="n">Write</span><span class="p">(</span><span class="n">line</span><span class="p">)</span>
156            <span class="bp">self</span><span class="o">.</span><span class="n">CloseFile</span><span class="p">()</span>
157            <span class="k">print</span><span class="p">(</span><span class="s">&#39;Histogram &#39;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">hist</span><span class="p">)</span><span class="o">+</span><span class="s">&#39; written to file &#39;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">fullpath</span><span class="p">))</span>
158
159</div></div>
160<div class="viewcode-block" id="ExportPowderXYE"><a class="viewcode-back" href="../exports.html#G2export_pwdr.ExportPowderXYE">[docs]</a><span class="k">class</span> <span class="nc">ExportPowderXYE</span><span class="p">(</span><span class="n">G2IO</span><span class="o">.</span><span class="n">ExportBaseclass</span><span class="p">):</span>
161    <span class="sd">&#39;&#39;&#39;Used to create a Topas XYE file for a powder data set</span>
162
163<span class="sd">    :param wx.Frame G2frame: reference to main GSAS-II frame</span>
164<span class="sd">    &#39;&#39;&#39;</span>
165    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">G2frame</span><span class="p">):</span>
166        <span class="nb">super</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__class__</span><span class="p">,</span><span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span> <span class="c"># fancy way to say &lt;parentclass&gt;.__init__</span>
167            <span class="n">G2frame</span><span class="o">=</span><span class="n">G2frame</span><span class="p">,</span>
168            <span class="n">formatName</span> <span class="o">=</span> <span class="s">&#39;Topas XYE file&#39;</span><span class="p">,</span>
169            <span class="n">extension</span><span class="o">=</span><span class="s">&#39;.xye&#39;</span><span class="p">,</span>
170            <span class="n">longFormatName</span> <span class="o">=</span> <span class="s">&#39;Export powder data as Topas XYE (column) file&#39;</span>
171            <span class="p">)</span>
172        <span class="bp">self</span><span class="o">.</span><span class="n">exporttype</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;powder&#39;</span><span class="p">]</span>
173        <span class="bp">self</span><span class="o">.</span><span class="n">multiple</span> <span class="o">=</span> <span class="bp">True</span>
174
175<div class="viewcode-block" id="ExportPowderXYE.Exporter"><a class="viewcode-back" href="../exports.html#G2export_pwdr.ExportPowderXYE.Exporter">[docs]</a>    <span class="k">def</span> <span class="nf">Exporter</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">event</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
176        <span class="sd">&#39;&#39;&#39;Export one or more sets of powder data as XYE file(s)</span>
177<span class="sd">        &#39;&#39;&#39;</span>
178        <span class="c"># the export process starts here</span>
179        <span class="bp">self</span><span class="o">.</span><span class="n">InitExport</span><span class="p">(</span><span class="n">event</span><span class="p">)</span>
180        <span class="c"># load all of the tree into a set of dicts</span>
181        <span class="bp">self</span><span class="o">.</span><span class="n">loadTree</span><span class="p">()</span>
182        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">ExportSelect</span><span class="p">(</span> <span class="c"># set export parameters</span>
183            <span class="n">AskFile</span><span class="o">=</span><span class="s">&#39;single&#39;</span> <span class="c"># get a file name/directory to save in</span>
184            <span class="p">):</span> <span class="k">return</span>
185        <span class="n">filenamelist</span> <span class="o">=</span> <span class="p">[]</span>
186        <span class="k">for</span> <span class="n">hist</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">histnam</span><span class="p">:</span>
187            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">histnam</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
188                <span class="c"># multiple files: create a unique name from the histogram</span>
189                <span class="n">fileroot</span> <span class="o">=</span> <span class="n">G2obj</span><span class="o">.</span><span class="n">MakeUniqueLabel</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">MakePWDRfilename</span><span class="p">(</span><span class="n">hist</span><span class="p">),</span><span class="n">filenamelist</span><span class="p">)</span>
190                <span class="c"># create an instrument parameter file</span>
191                <span class="bp">self</span><span class="o">.</span><span class="n">filename</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dirname</span><span class="p">,</span><span class="n">fileroot</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">extension</span><span class="p">)</span>
192            <span class="k">else</span><span class="p">:</span>
193                <span class="c"># use the supplied name, but force the extension</span>
194                <span class="bp">self</span><span class="o">.</span><span class="n">filename</span><span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">splitext</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">filename</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">extension</span>
195
196            <span class="bp">self</span><span class="o">.</span><span class="n">OpenFile</span><span class="p">()</span>
197            <span class="n">histblk</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">Histograms</span><span class="p">[</span><span class="n">hist</span><span class="p">]</span>
198            <span class="bp">self</span><span class="o">.</span><span class="n">Write</span><span class="p">(</span><span class="s">&#39;/*&#39;</span><span class="p">)</span>    <span class="c">#The ugly c comment delimiter used in topas!</span>
199            <span class="bp">self</span><span class="o">.</span><span class="n">Write</span><span class="p">(</span><span class="s">&#39;# &#39;</span><span class="o">+</span><span class="n">hist</span><span class="p">[</span><span class="mi">5</span><span class="p">:])</span>  <span class="c">#evidently this by itself fails in topas</span>
200            <span class="bp">self</span><span class="o">.</span><span class="n">Write</span><span class="p">(</span><span class="s">&#39;*/&#39;</span><span class="p">)</span>
201            <span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">histblk</span><span class="p">[</span><span class="s">&#39;Data&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">])</span>
202            <span class="c"># convert weights to sigmas; use largest weight as minimum esd</span>
203            <span class="n">s</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">maximum</span><span class="p">(</span><span class="mf">0.</span><span class="p">,</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">histblk</span><span class="p">[</span><span class="s">&#39;Data&#39;</span><span class="p">][</span><span class="mi">2</span><span class="p">])))</span>
204            <span class="n">s</span><span class="p">[</span><span class="n">s</span><span class="o">==</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">s</span><span class="p">)</span>
205            <span class="n">s</span> <span class="o">=</span> <span class="mf">1.</span><span class="o">/</span><span class="n">s</span>
206            <span class="k">for</span> <span class="n">XYS</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">histblk</span><span class="p">[</span><span class="s">&#39;Data&#39;</span><span class="p">][</span><span class="mi">1</span><span class="p">],</span><span class="n">s</span><span class="p">):</span>
207                <span class="n">line</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
208                <span class="k">for</span> <span class="n">val</span> <span class="ow">in</span> <span class="n">XYS</span><span class="p">:</span>
209                    <span class="n">line</span> <span class="o">+=</span> <span class="n">G2py3</span><span class="o">.</span><span class="n">FormatPadValue</span><span class="p">(</span><span class="n">val</span><span class="p">,(</span><span class="mi">15</span><span class="p">,</span><span class="mi">6</span><span class="p">))</span>
210                <span class="bp">self</span><span class="o">.</span><span class="n">Write</span><span class="p">(</span><span class="n">line</span><span class="p">)</span>
211            <span class="bp">self</span><span class="o">.</span><span class="n">CloseFile</span><span class="p">()</span>
212            <span class="k">print</span><span class="p">(</span><span class="s">&#39;Histogram &#39;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">hist</span><span class="p">)</span><span class="o">+</span><span class="s">&#39; written to file &#39;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">fullpath</span><span class="p">))</span></div></div>
213</pre></div>
214
215          </div>
216        </div>
217      </div>
218      <div class="sphinxsidebar">
219        <div class="sphinxsidebarwrapper">
220            <p class="logo"><a href="../index.html">
221              <img class="logo" src="../_static/G2_html_logo.png" alt="Logo"/>
222            </a></p>
223<div id="searchbox" style="display: none">
224  <h3>Quick search</h3>
225    <form class="search" action="../search.html" method="get">
226      <input type="text" name="q" />
227      <input type="submit" value="Go" />
228      <input type="hidden" name="check_keywords" value="yes" />
229      <input type="hidden" name="area" value="default" />
230    </form>
231    <p class="searchtip" style="font-size: 90%">
232    Enter search terms or a module, class or function name.
233    </p>
234</div>
235<script type="text/javascript">$('#searchbox').show(0);</script>
236        </div>
237      </div>
238      <div class="clearer"></div>
239    </div>
240    <div class="related">
241      <h3>Navigation</h3>
242      <ul>
243        <li class="right" style="margin-right: 10px">
244          <a href="../genindex.html" title="General Index"
245             >index</a></li>
246        <li class="right" >
247          <a href="../py-modindex.html" title="Python Module Index"
248             >modules</a> |</li>
249        <li><a href="../index.html">GSAS-II 0.2.0 documentation</a> &raquo;</li>
250          <li><a href="index.html" >Module code</a> &raquo;</li> 
251      </ul>
252    </div>
253    <div class="footer">
254        &copy; Copyright 2013, Von Dreele and Toby for Argonne National Laboratory.
255      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.2.
256    </div>
257  </body>
258</html>
Note: See TracBrowser for help on using the repository browser.