source: 1dwg/trunk/doc/cansas1d_binding_Python.xml @ 107

Last change on this file since 107 was 107, checked in by prjemian, 12 years ago

minor

  • Property svn:executable set to *
  • Property svn:keywords set to Date Revision Author HeadURL Id
File size: 8.9 KB
Line 
1<?xml version="1.0" encoding="UTF-8"?>
2<?oxygen RNGSchema="http://www.oasis-open.org/docbook/xml/5.0/rng/docbook.rng" type="xml"?>
3<!--
4    ########### SVN repository information ###################
5    # $Date$
6    # $Author$
7    # $Revision$
8    # $HeadURL$
9    # $Id$
10    ########### SVN repository information ###################
11-->
12<!-- from: http://www.smallangles.net/wgwiki/index.php/cansas1d_binding_Python -->
13<section xml:id="cansas1d_documentation-binding-Python" xmlns="http://docbook.org/ns/docbook"
14    version="5.0" xmlns:xlink="http://www.w3.org/1999/xlink">
15    <title>Python binding</title>
16    <para>
17        Specific <link xlink:href="http://danse.us/trac/sans"><citetitle>support</citetitle></link> 
18        for the cansas1d/1.0 data standard in Python is being developed by
19        <link xlink:href="http://www.ncnr.nist.gov/"><citetitle>NIST/NCNR</citetitle></link> 
20        as part of their contribution to the
21        <link xlink:href="http://wiki.cacr.caltech.edu/danse"><citetitle>DANSE</citetitle></link> project.
22    </para>
23    <para>
24        Here are some terse instructions to get you started:
25        <programlisting>svn co http://danse.us/trac/sans/browser/trunk/DataLoader DataLoader
26cd DataLoader
27python setup.py install</programlisting>
28        The <link xlink:href="http://danse.us/trac/sans/browser/trunk/DataLoader/release_notes.txt"><citetitle>release notes</citetitle></link> have a list of the dependencies.
29    </para>
30    <section><title>Comments</title>
31        <para>
32            Other constructive suggestions (that predate the NIST/NCNR support) have been gathered on this page.
33        </para>   
34    </section>
35    <section><title>gnosis.xml.objectify</title>
36        <para>
37            The GnosisUtils (http://freshmeat.net/projects/gnosisxml/) offer a method to readany XML file into Python data structures. This utility does not validate the XML against aspecific XML Schema which can be both good (flexible, especially when XML Foreign Namespace elements are used) and not so good (XML content not guaranteed to be <emphasis>by the rules</emphasis>).
38        </para>
39        <para>
40            A quick test of this turned up an acceptable result in that it was able to read several of the canSAS test XML files, including those with foreign namespaces.And <emphasis role="bold"><emphasis>it was very easy.</emphasis></emphasis> (Especially with some help from http://www.xml.com/pub/a/2003/07/02/py-xml.html)
41        </para>
42        <para>
43            Here is a quick example.
44        </para>
45        <section><title>installation</title>
46            <para>
47                Here is the condensed installation (without all that output) steps. Your system may have gnosis already installed. You may also need sysAdmin privileges. You may need ...
48                <programlisting>cd /tmp
49wget http://freshmeat.net/redir/gnosisxml/22028/url_tgz/Gnosis_Utils-1.2.2.tar.gz
50tar xzf Gnosis_Utils-1.2.2.tar.gz
51cd Gnosis_Utils-1.2.2/
52python setup.py install_all</programlisting>
53            </para>
54        </section>
55        <section><title>quick test in Python</title>
56            <para>
57                Here is the Python code (without all that output)
58                (called <emphasis>python-test.py</emphasis>):
59                <programlisting>
60import gnosis.xml.objectify
61
62sasxml = gnosis.xml.objectify.XML_Objectify('bimodal-test1.xml').make_instance() 
63print sasxml.SASentry.Title.PCDATA
64print sasxml.SASentry.Run.PCDATA
65print sasxml.SASentry.SASinstrument.name.PCDATA
66print sasxml.SASentry.SASdata.Idata[0].Q.unit,  sasxml.SASentry.SASdata.Idata[0].I.unit
67print sasxml.SASentry.SASdata.Idata[0].Q.PCDATA,  sasxml.SASentry.SASdata.Idata[0].I.PCDATA,  sasxml.SASentry.SASdata.Idata[0].Idev.PCDATA</programlisting>
68            </para>           
69        </section>
70        <section>
71            <title>execution of that Python code</title>
72            <para>
73                <programlisting>[Pete@regitte,2441,cansas1dwg-regitte]$ ./python-test.py
74SAS bimodal test1
751992
76simulated SAS calculation
771/A 1/cm
780.0040157139 3497.473 90.72816
79                </programlisting>
80            </para>
81        </section>
82        <section>
83            <title>full session output</title>
84            <programlisting>[Pete@regitte,2429,/tmp]$ cd /tmp
85/tmp
86[Pete@regitte,2430,/tmp]$ wget http://freshmeat.net/redir/gnosisxml/22028/url_tgz/Gnosis_Utils-1.2.2.tar.gz
87--11:43:16--  http://freshmeat.net/redir/gnosisxml/22028/url_tgz/Gnosis_Utils-1.2.2.tar.gz
88           => `Gnosis_Utils-1.2.2.tar.gz'
89Resolving freshmeat.net... 66.35.250.168
90Connecting to freshmeat.net|66.35.250.168|:80... connected.
91HTTP request sent, awaiting response... 302 Found
92Location: http://www.gnosis.cx/download/Gnosis_Utils.More/Gnosis_Utils-1.2.2.tar.gz [following]
93--11:43:16--  http://www.gnosis.cx/download/Gnosis_Utils.More/Gnosis_Utils-1.2.2.tar.gz
94           => `Gnosis_Utils-1.2.2.tar.gz'
95Resolving www.gnosis.cx... 64.41.64.172
96Connecting to www.gnosis.cx|64.41.64.172|:80... connected.
97HTTP request sent, awaiting response... 200 OK
98Length: 287,989 (281K) [application/x-tar]
99
100100%[====================================================================================================================>] 287,989       --.--K/s             
101
10211:43:16 (2.47 MB/s) - `Gnosis_Utils-1.2.2.tar.gz' saved [287989/287989]
103
104[Pete@regitte,2431,/tmp]$ tar xzf Gnosis_Utils-1.2.2.tar.gz
105[Pete@regitte,2432,/tmp]$ cd Gnosis_Utils-1.2.2/
106/tmp/Gnosis_Utils-1.2.2
107[Pete@regitte,2433,Gnosis_Utils-1.2.2]$ python setup.py install_all
108[Pete@regitte,2434,Gnosis_Utils-1.2.2]$ cd ~/workspace/cansas1dwg-regitte
109[Pete@regitte,2435,cansas1dwg-regitte]$ python
110Python 2.5.1 (r251:54863, May 18 2007, 16:56:43)
111[GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin
112Type "help", "copyright", "credits" or "license" for more information.
113>>> import gnosis.xml.objectify
114>>> sasxml = gnosis.xml.objectify.XML_Objectify('bimodal-test1.xml').make_instance() 
115>>> print sasxml.SASentry.Title.PCDATA
116SAS bimodal test1
117>>> print sasxml.SASentry.Run.PCDATA
1181992
119>>> print sasxml.SASentry.SASinstrument.name.PCDATA
120simulated SAS calculation
121>>> print sasxml.SASentry.SASdata.Idata[0].Q.unit
1221/A
123>>> print sasxml.SASentry.SASdata.Idata[0].I.unit
1241/cm
125>>> print sasxml.SASentry.SASdata.Idata[0].Q.PCDATA,  sasxml.SASentry.SASdata.Idata[0].I.PCDATA,  sasxml.SASentry.SASdata.Idata[0].Idev.PCDATA
1260.0040157139 3497.473 90.72816</programlisting>
127        </section>
128        <section><title>Conclusion: OK</title>
129            <para>
130                This has the promise of being a useful approach to reading this format in Python.Now, how to write back out... ?
131            </para>
132        </section>
133    </section>
134    <section><title>generateDS.py</title>       
135        <para>
136            <emphasis>generateDS.py</emphasis> 
137            (http://www.rexx.com/~dkuhlman/, http://www.rexx.com/~dkuhlman/generateDS.html)
138            can build a binding (map the structure of the XML file directly into a
139            Python data structure) for Python from an XML Schema.
140            However, the cansas1d/1.0 XML schema (cansas1d.xsd) does not seem to
141            fit the model.It seems, for now, that <emphasis>generateDS-1.12a</emphasis> 
142            fails on a certain <emphasis>annotate</emphasis> line.
143            <programlisting>[Pete@regitte,2402,cansas1dwg-regitte]$ python ~/generateDS-1.12a/generateDS.py -p CS1D_ -o cansas1d.py -s cansas1dsubs.py cansas1d.xsd
144Traceback (most recent call last):
145  File "/home/Pete/generateDS-1.12a/generateDS.py", line 3997, in &lt;module>
146    main()
147  File "/home/Pete/generateDS-1.12a/generateDS.py", line 3993, in main
148    processIncludes, superModule=superModule)
149  File "/home/Pete/generateDS-1.12a/generateDS.py", line 3909, in parseAndGenerate
150    root.annotate()
151AttributeError: 'NoneType' object has no attribute 'annotate'</programlisting>
152        </para>
153        <section>
154                        <title>Conclusion: not ready yet</title>
155            <para>
156                Either the canSAS standard (by means of the cansas1d.xsd XML Schema)
157                                is not ready or <emphasis>generateDS.py</emphasis> does not cover the
158                                XML Schema requirements we have at this time.Either way,
159                                this is not a viable tool to use now. (2008-05-16)
160            </para>
161        </section>
162    </section>
163    <section>
164        <title>Other suggestions</title>
165        <itemizedlist mark="opencircle"><listitem>
166            <para>
167                http://www.devx.com/ibm/Article/20261
168            </para>
169        </listitem>
170            <listitem>
171                <para>
172                    http://mail.python.org/pipermail/xml-sig/2002-April/007559.html
173                </para>
174            </listitem>
175            <listitem>
176                <para>
177                    http://pywebsvcs.sourceforge.net/
178                </para>
179            </listitem>
180        </itemizedlist>
181    </section>
182</section>
Note: See TracBrowser for help on using the repository browser.