source: sphinxdocs/build/html/_modules/G2export_pwdr.html @ 1998

Last change on this file since 1998 was 1998, checked in by toby, 7 years ago

rebuild docs

  • Property svn:mime-type set to text/html
File size: 36.5 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: 2015-10-10 11:58:12 -0500 (Sat, 10 Oct 2015) $</span>
55<span class="c"># $Author: toby $</span>
56<span class="c"># $Revision: 1997 $</span>
57<span class="c"># $URL: https://subversion.xray.aps.anl.gov/pyGSAS/trunk/exports/G2export_pwdr.py $</span>
58<span class="c"># $Id: G2export_pwdr.py 1997 2015-10-10 16:58:12Z toby $</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: 1997 $&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.6e%15.6e%15.6e%15.6e</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.6e%15.6e%15.6e%15.6e</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.Writer"><a class="viewcode-back" href="../exports.html#G2export_pwdr.ExportPowderFXYE.Writer">[docs]</a>    <span class="k">def</span> <span class="nf">Writer</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">TreeName</span><span class="p">,</span><span class="n">filename</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span><span class="n">prmname</span><span class="o">=</span><span class="s">&#39;&#39;</span><span class="p">):</span>
115        <span class="sd">&#39;&#39;&#39;Write a single PWDR entry to a FXYE file</span>
116<span class="sd">        &#39;&#39;&#39;</span>
117        <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">TreeName</span><span class="p">]</span>
118        <span class="bp">self</span><span class="o">.</span><span class="n">OpenFile</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span> <span class="c"># ***rethink</span>
119        <span class="bp">self</span><span class="o">.</span><span class="n">Write</span><span class="p">(</span><span class="n">TreeName</span><span class="p">[</span><span class="mi">5</span><span class="p">:])</span>
120        <span class="k">if</span> <span class="n">prmname</span><span class="p">:</span> <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>
121        <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>
122        <span class="c"># convert weights to sigmas; use largest weight as minimum esd</span>
123        <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>
124        <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>
125        <span class="n">s</span> <span class="o">=</span> <span class="mf">1.</span><span class="o">/</span><span class="n">s</span>
126        <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>
127            <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>
128            <span class="p">))</span>
129<span class="c">#            for X,Y,S in zip(x,histblk[&#39;Data&#39;][1],s):</span>
130<span class="c">#                self.Write(&quot;{:15.6g} {:15.6g} {:15.6g}&quot;.format(X,Y,S))</span>
131        <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>
132            <span class="n">line</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
133            <span class="k">for</span> <span class="n">val</span> <span class="ow">in</span> <span class="n">XYS</span><span class="p">:</span>
134                <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>
135            <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>
136        <span class="bp">self</span><span class="o">.</span><span class="n">CloseFile</span><span class="p">()</span>
137        </div>
138<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>
139        <span class="sd">&#39;&#39;&#39;Export one or more sets of powder data as FXYE file(s)</span>
140<span class="sd">        &#39;&#39;&#39;</span>
141        <span class="c"># the export process starts here</span>
142        <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>
143        <span class="bp">self</span><span class="o">.</span><span class="n">loadTree</span><span class="p">()</span> <span class="c"># load all of the tree into a set of dicts</span>
144        <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>
145            <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>
146            <span class="p">):</span> <span class="k">return</span>
147        <span class="n">filenamelist</span> <span class="o">=</span> <span class="p">[]</span>
148        <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>
149            <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>
150                <span class="c"># multiple files: create a unique name from the histogram</span>
151                <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>
152                <span class="c"># create an instrument parameter file</span>
153                <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>
154            <span class="k">else</span><span class="p">:</span>
155                <span class="c"># use the supplied name, but force the extension</span>
156                <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>
157
158            <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">TreeName</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>
159            <span class="bp">self</span><span class="o">.</span><span class="n">Writer</span><span class="p">(</span><span class="n">hist</span><span class="p">,</span><span class="n">prmname</span><span class="o">=</span><span class="n">prmname</span><span class="p">)</span>
160            <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>
161
162</div></div>
163<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>
164    <span class="sd">&#39;&#39;&#39;Used to create a Topas XYE file for a powder data set</span>
165
166<span class="sd">    :param wx.Frame G2frame: reference to main GSAS-II frame</span>
167<span class="sd">    &#39;&#39;&#39;</span>
168    <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>
169        <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>
170            <span class="n">G2frame</span><span class="o">=</span><span class="n">G2frame</span><span class="p">,</span>
171            <span class="n">formatName</span> <span class="o">=</span> <span class="s">&#39;Topas XYE file&#39;</span><span class="p">,</span>
172            <span class="n">extension</span><span class="o">=</span><span class="s">&#39;.xye&#39;</span><span class="p">,</span>
173            <span class="n">longFormatName</span> <span class="o">=</span> <span class="s">&#39;Export powder data as Topas XYE (column) file&#39;</span>
174            <span class="p">)</span>
175        <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>
176        <span class="bp">self</span><span class="o">.</span><span class="n">multiple</span> <span class="o">=</span> <span class="bp">True</span>
177       
178    <span class="k">def</span> <span class="nf">Writer</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">TreeName</span><span class="p">,</span><span class="n">filename</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
179        <span class="n">GSASIIpath</span><span class="o">.</span><span class="n">IPyBreak</span><span class="p">()</span>
180
181        <span class="bp">self</span><span class="o">.</span><span class="n">OpenFile</span><span class="p">()</span>
182        <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">TreeName</span><span class="p">]</span>
183        <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>
184        <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">TreeName</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>
185        <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>
186        <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>
187        <span class="c"># convert weights to sigmas; use largest weight as minimum esd</span>
188        <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>
189        <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>
190        <span class="n">s</span> <span class="o">=</span> <span class="mf">1.</span><span class="o">/</span><span class="n">s</span>
191        <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>
192            <span class="n">line</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
193            <span class="k">for</span> <span class="n">val</span> <span class="ow">in</span> <span class="n">XYS</span><span class="p">:</span>
194                <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>
195            <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>
196        <span class="bp">self</span><span class="o">.</span><span class="n">CloseFile</span><span class="p">()</span>
197
198<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>
199        <span class="sd">&#39;&#39;&#39;Export one or more sets of powder data as XYE file(s)</span>
200<span class="sd">        &#39;&#39;&#39;</span>
201        <span class="c"># the export process starts here</span>
202        <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>
203        <span class="c"># load all of the tree into a set of dicts</span>
204        <span class="bp">self</span><span class="o">.</span><span class="n">loadTree</span><span class="p">()</span>
205        <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>
206            <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>
207            <span class="p">):</span> <span class="k">return</span>
208        <span class="n">filenamelist</span> <span class="o">=</span> <span class="p">[]</span>
209        <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>
210            <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>
211                <span class="c"># multiple files: create a unique name from the histogram</span>
212                <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>
213                <span class="c"># create an instrument parameter file</span>
214                <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>
215            <span class="k">else</span><span class="p">:</span>
216                <span class="c"># use the supplied name, but force the extension</span>
217                <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>
218
219            <span class="bp">self</span><span class="o">.</span><span class="n">Writer</span><span class="p">(</span><span class="n">hist</span><span class="p">)</span>
220            <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>
221</pre></div>
222
223          </div>
224        </div>
225      </div>
226      <div class="sphinxsidebar">
227        <div class="sphinxsidebarwrapper">
228            <p class="logo"><a href="../index.html">
229              <img class="logo" src="../_static/G2_html_logo.png" alt="Logo"/>
230            </a></p>
231<div id="searchbox" style="display: none">
232  <h3>Quick search</h3>
233    <form class="search" action="../search.html" method="get">
234      <input type="text" name="q" />
235      <input type="submit" value="Go" />
236      <input type="hidden" name="check_keywords" value="yes" />
237      <input type="hidden" name="area" value="default" />
238    </form>
239    <p class="searchtip" style="font-size: 90%">
240    Enter search terms or a module, class or function name.
241    </p>
242</div>
243<script type="text/javascript">$('#searchbox').show(0);</script>
244        </div>
245      </div>
246      <div class="clearer"></div>
247    </div>
248    <div class="related">
249      <h3>Navigation</h3>
250      <ul>
251        <li class="right" style="margin-right: 10px">
252          <a href="../genindex.html" title="General Index"
253             >index</a></li>
254        <li class="right" >
255          <a href="../py-modindex.html" title="Python Module Index"
256             >modules</a> |</li>
257        <li><a href="../index.html">GSAS-II 0.2.0 documentation</a> &raquo;</li>
258          <li><a href="index.html" >Module code</a> &raquo;</li> 
259      </ul>
260    </div>
261    <div class="footer">
262        &copy; Copyright 2013, Von Dreele and Toby for Argonne National Laboratory.
263      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.2.
264    </div>
265  </body>
266</html>
Note: See TracBrowser for help on using the repository browser.