source: trunk/sphinxdocs/build/html/_modules/G2phase_GPX.html @ 1183

Last change on this file since 1183 was 1183, checked in by toby, 8 years ago

fixup number formatting; update produced doc files

  • Property svn:mime-type set to text/html
File size: 13.6 KB
Line 
1
2
3<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
6
7<html xmlns="http://www.w3.org/1999/xhtml">
8  <head>
9    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
10   
11    <title>G2phase_GPX &mdash; GSAS-II 0.2.0 documentation</title>
12   
13    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
14    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
15   
16    <script type="text/javascript">
17      var DOCUMENTATION_OPTIONS = {
18        URL_ROOT:    '../',
19        VERSION:     '0.2.0',
20        COLLAPSE_INDEX: false,
21        FILE_SUFFIX: '.html',
22        HAS_SOURCE:  true
23      };
24    </script>
25    <script type="text/javascript" src="../_static/jquery.js"></script>
26    <script type="text/javascript" src="../_static/underscore.js"></script>
27    <script type="text/javascript" src="../_static/doctools.js"></script>
28    <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
29    <link rel="top" title="GSAS-II 0.2.0 documentation" href="../index.html" />
30    <link rel="up" title="Module code" href="index.html" /> 
31  </head>
32  <body>
33    <div class="related">
34      <h3>Navigation</h3>
35      <ul>
36        <li class="right" style="margin-right: 10px">
37          <a href="../genindex.html" title="General Index"
38             accesskey="I">index</a></li>
39        <li class="right" >
40          <a href="../py-modindex.html" title="Python Module Index"
41             >modules</a> |</li>
42        <li><a href="../index.html">GSAS-II 0.2.0 documentation</a> &raquo;</li>
43          <li><a href="index.html" accesskey="U">Module code</a> &raquo;</li> 
44      </ul>
45    </div> 
46
47    <div class="document">
48      <div class="documentwrapper">
49        <div class="bodywrapper">
50          <div class="body">
51           
52  <h1>Source code for G2phase_GPX</h1><div class="highlight"><pre>
53<span class="c"># -*- coding: utf-8 -*-</span>
54<span class="c">########### SVN repository information ###################</span>
55<span class="c"># $Date: 2013-12-16 10:43:01 -0600 (Mon, 16 Dec 2013) $</span>
56<span class="c"># $Author: toby $</span>
57<span class="c"># $Revision: 1168 $</span>
58<span class="c"># $URL: https://subversion.xor.aps.anl.gov/pyGSAS/trunk/imports/G2phase_GPX.py $</span>
59<span class="c"># $Id: G2phase_GPX.py 1168 2013-12-16 16:43:01Z toby $</span>
60<span class="c">########### SVN repository information ###################</span>
61<span class="sd">&#39;&#39;&#39;</span>
62<span class="sd">*Module G2phase_GPX: Import phase from GSAS-II project*</span>
63<span class="sd">--------------------------------------------------------</span>
64
65<span class="sd">Copies a phase from another GSAS-II project file into the</span>
66<span class="sd">current project.</span>
67
68<span class="sd">&#39;&#39;&#39;</span>
69<span class="kn">import</span> <span class="nn">sys</span>
70<span class="kn">import</span> <span class="nn">cPickle</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">GSASIIstrIO</span> <span class="kn">as</span> <span class="nn">G2stIO</span>
73<span class="kn">import</span> <span class="nn">GSASIIpath</span>
74<span class="n">GSASIIpath</span><span class="o">.</span><span class="n">SetVersionNumber</span><span class="p">(</span><span class="s">&quot;$Revision: 1168 $&quot;</span><span class="p">)</span>
75
76<div class="viewcode-block" id="PhaseReaderClass"><a class="viewcode-back" href="../imports.html#G2phase_GPX.PhaseReaderClass">[docs]</a><span class="k">class</span> <span class="nc">PhaseReaderClass</span><span class="p">(</span><span class="n">G2IO</span><span class="o">.</span><span class="n">ImportPhase</span><span class="p">):</span>
77    <span class="s">&#39;Opens a .GPX file and pulls out a selected phase&#39;</span>
78    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
79        <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 ImportPhase.__init__</span>
80            <span class="n">extensionlist</span><span class="o">=</span><span class="p">(</span><span class="s">&#39;.gpx&#39;</span><span class="p">,),</span>
81            <span class="n">strictExtension</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span>
82            <span class="n">formatName</span> <span class="o">=</span> <span class="s">&#39;GSAS-II gpx&#39;</span><span class="p">,</span>
83            <span class="n">longFormatName</span> <span class="o">=</span> <span class="s">&#39;GSAS-II project (.gpx file) import&#39;</span>
84            <span class="p">)</span>
85       
86<div class="viewcode-block" id="PhaseReaderClass.ContentsValidator"><a class="viewcode-back" href="../imports.html#G2phase_GPX.PhaseReaderClass.ContentsValidator">[docs]</a>    <span class="k">def</span> <span class="nf">ContentsValidator</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filepointer</span><span class="p">):</span>
87        <span class="s">&quot;Test if the 1st section can be read as a cPickle block, if not it can&#39;t be .GPX!&quot;</span>
88        <span class="k">try</span><span class="p">:</span> 
89            <span class="n">cPickle</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">filepointer</span><span class="p">)</span>
90        <span class="k">except</span><span class="p">:</span>
91            <span class="bp">self</span><span class="o">.</span><span class="n">errors</span> <span class="o">=</span> <span class="s">&#39;This is not a valid .GPX file. Not recognized by cPickle&#39;</span>
92            <span class="k">return</span> <span class="bp">False</span>
93        <span class="k">return</span> <span class="bp">True</span>
94</div>
95<div class="viewcode-block" id="PhaseReaderClass.Reader"><a class="viewcode-back" href="../imports.html#G2phase_GPX.PhaseReaderClass.Reader">[docs]</a>    <span class="k">def</span> <span class="nf">Reader</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">filename</span><span class="p">,</span><span class="n">filepointer</span><span class="p">,</span> <span class="n">ParentFrame</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="o">**</span><span class="n">unused</span><span class="p">):</span>
96        <span class="sd">&#39;&#39;&#39;Read a phase from a .GPX file. Does not (yet?) support selecting and reading</span>
97<span class="sd">        more than one phase at a time.&#39;&#39;&#39;</span>
98        <span class="k">try</span><span class="p">:</span>
99            <span class="n">phasenames</span> <span class="o">=</span> <span class="n">G2stIO</span><span class="o">.</span><span class="n">GetPhaseNames</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span>
100        <span class="k">except</span><span class="p">:</span>
101            <span class="bp">self</span><span class="o">.</span><span class="n">errors</span> <span class="o">=</span> <span class="s">&#39;Reading of phase names failed&#39;</span>
102            <span class="k">return</span> <span class="bp">False</span>
103        <span class="k">if</span> <span class="ow">not</span> <span class="n">phasenames</span><span class="p">:</span>
104            <span class="bp">self</span><span class="o">.</span><span class="n">errors</span> <span class="o">=</span> <span class="s">&#39;No phases found in &#39;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span>
105            <span class="k">return</span> <span class="bp">False</span>            <span class="c"># no blocks with coordinates</span>
106        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">phasenames</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span> <span class="c"># one block, no choices</span>
107            <span class="n">selblk</span> <span class="o">=</span> <span class="mi">0</span>
108        <span class="k">else</span><span class="p">:</span>                       <span class="c"># choose from options                </span>
109            <span class="n">selblk</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">PhaseSelector</span><span class="p">(</span>
110                <span class="n">phasenames</span><span class="p">,</span>
111                <span class="n">ParentFrame</span><span class="o">=</span><span class="n">ParentFrame</span><span class="p">,</span>
112                <span class="n">title</span><span class="o">=</span> <span class="s">&#39;Select a phase from the list below&#39;</span><span class="p">,</span>
113                <span class="p">)</span>
114            <span class="k">if</span> <span class="n">selblk</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
115                <span class="bp">self</span><span class="o">.</span><span class="n">errors</span> <span class="o">=</span> <span class="s">&#39;No phase selected&#39;</span>
116                <span class="k">return</span> <span class="bp">False</span> <span class="c"># User pressed cancel</span>
117        <span class="k">try</span><span class="p">:</span>
118            <span class="bp">self</span><span class="o">.</span><span class="n">Phase</span> <span class="o">=</span> <span class="n">G2stIO</span><span class="o">.</span><span class="n">GetAllPhaseData</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span><span class="n">phasenames</span><span class="p">[</span><span class="n">selblk</span><span class="p">])</span>
119            <span class="bp">self</span><span class="o">.</span><span class="n">Phase</span><span class="p">[</span><span class="s">&#39;Histograms&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>       <span class="c">#remove any histograms</span>
120            <span class="bp">self</span><span class="o">.</span><span class="n">Phase</span><span class="p">[</span><span class="s">&#39;Pawley ref&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span>       <span class="c"># &amp; any Pawley refl.</span>
121            <span class="k">return</span> <span class="bp">True</span>
122        <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">detail</span><span class="p">:</span>
123            <span class="bp">self</span><span class="o">.</span><span class="n">errors</span> <span class="o">=</span> <span class="s">&#39;Error reading selected phase&#39;</span>
124            <span class="bp">self</span><span class="o">.</span><span class="n">errors</span> <span class="o">+=</span> <span class="s">&#39;</span><span class="se">\n</span><span class="s">  &#39;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">detail</span><span class="p">)</span>
125            <span class="k">print</span> <span class="bp">self</span><span class="o">.</span><span class="n">formatName</span><span class="o">+</span><span class="s">&#39; error:&#39;</span><span class="p">,</span><span class="n">detail</span> <span class="c"># for testing</span>
126            <span class="k">print</span> <span class="n">sys</span><span class="o">.</span><span class="n">exc_info</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span> <span class="c"># for testing</span>
127            <span class="kn">import</span> <span class="nn">traceback</span>
128            <span class="k">print</span> <span class="n">traceback</span><span class="o">.</span><span class="n">format_exc</span><span class="p">()</span></div></div>
129</pre></div>
130
131          </div>
132        </div>
133      </div>
134      <div class="sphinxsidebar">
135        <div class="sphinxsidebarwrapper">
136            <p class="logo"><a href="../index.html">
137              <img class="logo" src="../_static/G2_html_logo.png" alt="Logo"/>
138            </a></p>
139<div id="searchbox" style="display: none">
140  <h3>Quick search</h3>
141    <form class="search" action="../search.html" method="get">
142      <input type="text" name="q" />
143      <input type="submit" value="Go" />
144      <input type="hidden" name="check_keywords" value="yes" />
145      <input type="hidden" name="area" value="default" />
146    </form>
147    <p class="searchtip" style="font-size: 90%">
148    Enter search terms or a module, class or function name.
149    </p>
150</div>
151<script type="text/javascript">$('#searchbox').show(0);</script>
152        </div>
153      </div>
154      <div class="clearer"></div>
155    </div>
156    <div class="related">
157      <h3>Navigation</h3>
158      <ul>
159        <li class="right" style="margin-right: 10px">
160          <a href="../genindex.html" title="General Index"
161             >index</a></li>
162        <li class="right" >
163          <a href="../py-modindex.html" title="Python Module Index"
164             >modules</a> |</li>
165        <li><a href="../index.html">GSAS-II 0.2.0 documentation</a> &raquo;</li>
166          <li><a href="index.html" >Module code</a> &raquo;</li> 
167      </ul>
168    </div>
169    <div class="footer">
170        &copy; Copyright 2013, Von Dreele and Toby for Argonne National Laboratory.
171      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2.
172    </div>
173  </body>
174</html>
Note: See TracBrowser for help on using the repository browser.