Changeset 289


Ignore:
Timestamp:
Mar 16, 2013 12:26:07 AM (6 years ago)
Author:
prjemian
Message:

fixes #26

Location:
1dwg/branches/v1.1
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • 1dwg/branches/v1.1/doc/source/binding-python.rst

    r284 r289  
    6565                python setup.py install_all 
    6666 
    67 Alternatively, it might be simpler to install from the PyPI 
     67Alternatively, it *is* much simpler to install (or update) from the PyPI 
    6868repository (http://pypi.python.org/pypi/Gnosis%20Utilities): 
    6969 
     
    7171                :linenos: 
    7272                 
    73                 easy_install -U gnosis_utils 
     73                easy_install -U gnosis 
    7474 
    7575.. index:: Python file; python-test.py 
  • 1dwg/branches/v1.1/python/cansas1d_example.py

    r288 r289  
    11#!/usr/bin/env python 
    22'''  
    3 http://www.smallangles.net/wgwiki/index.php/cansas1d_binding_Python 
    4  
    5 Example use of Gnosis_utils to read cansas1d/1.0 file 
     3Example use of Gnosis_utils to read cansas1d:1.1 file 
    64''' 
    75 
    8 # ../bimodal-test1.xml 
    9 # ../s81-polyurea.xml 
    106 
     7########### SVN repository information ################### 
     8# $Date: 2011-08-05 12:25:16 -0500 (Fri, 05 Aug 2011) $ 
     9# $Author: jemian $ 
     10# $Revision: 603 $ 
     11# $URL: https://subversion.xray.aps.anl.gov/bcdaext/epicsdf/src/epicsdf.py $ 
     12# $Id: epicsdf.py 603 2011-08-05 17:25:16Z jemian $ 
     13########### SVN repository information ################### 
     14 
     15 
     16import os 
    1117import sys 
    12 import gnosis.xml.objectify 
     18import gnosis.xml.objectify     # easy_install -U gnosis 
     19 
    1320 
    1421def indra_metadata(SASentry): 
     
    2229                for item in dir(index): 
    2330                    '''discover the element names''' 
    24                     if (item[0] == '_'):    # sift out data structure management terms 
     31                    if item[0] == '_':    # sift out data structure management terms 
    2532                        continue 
    26                     if (item == 'PCDATA'):  # sift this out 
    27                         continue 
    28                     if (item == 'name'):    # sift out the "name" attribute 
    29                         continue 
    30                     if (item == 'xmlns'):   # sift out the "xmlns" attribute 
     33                    if item in ('PCDATA', 'name', 'xmlns'):  # sift this out 
    3134                        continue 
    3235                    s = '' 
     
    3639                    s += index.__dict__[item].PCDATA 
    3740                    print s 
     41 
    3842 
    3943def print_SASdata(sd): 
     
    5054        print Idata.Q.PCDATA,  Idata.I.PCDATA,  Idata.Idev.PCDATA 
    5155 
     56 
    5257def print_optional_item(title, parent, item): 
    5358    ''' this item is optional and may not be present''' 
     
    6166        print s 
    6267 
    63 xmlFile = sys.argv[1] 
    64 print '#---------------------------------------------------' 
    65 print 'XML:', xmlFile 
    66 # read in the XML file 
    67 sasxml = gnosis.xml.objectify.XML_Objectify(xmlFile).make_instance() 
    68 # might check it here to make sure it is a "cansas1d/1.0" file 
    69 print 'namespace:', sasxml.xmlns 
    70 # might check it here to make sure it is version "1.0" 
    71 print 'version:', sasxml.version 
    72 SASentry = sasxml.SASentry                  # just the first one 
    73 print 'title:', SASentry.Title.PCDATA 
    74 print 'run:', SASentry.Run.PCDATA 
    75 print_optional_item('instrument', SASentry.SASinstrument, 'name') 
    76 indra_metadata(SASentry)        # foreign XML elements from APS/USAXS 
    77 print_optional_item('sample ID', SASentry.SASsample, 'ID') 
    78 print_optional_item('sample thickness', SASentry.SASsample, 'thickness') 
    79 print_optional_item('sample transmission', SASentry.SASsample, 'transmission') 
    80 if 'position' in SASentry.SASsample.__dict__: 
    81     print_optional_item('sample X', SASentry.SASsample.position, 'x') 
    82     print_optional_item('sample Y', SASentry.SASsample.position, 'y') 
    83 print_SASdata(SASentry.SASdata) 
    8468 
     69def demo(xmlFile): 
     70    print '#---------------------------------------------------' 
     71    print 'XML:', xmlFile 
     72    # read in the XML file 
     73    sasxml = gnosis.xml.objectify.XML_Objectify(xmlFile).make_instance() 
     74    if sasxml.xmlns != 'urn:cansas1d:1.1': 
     75        print "Not cansas1d:1.1 file (found: %s)" % sasxml.xmlns 
     76        return 
     77    print 'namespace:', sasxml.xmlns 
     78    if sasxml.version != '1.1': 
     79        print "Not v1.1 file (found: %s)" % sasxml.version 
     80        return 
     81    print 'version:', sasxml.version 
     82    SASentry = sasxml.SASentry                  # just the first one 
     83    print 'title:', SASentry.Title.PCDATA 
     84    print 'run:', SASentry.Run.PCDATA 
     85    print_optional_item('instrument', SASentry.SASinstrument, 'name') 
     86    indra_metadata(SASentry)        # foreign XML elements from APS/USAXS 
     87    print_optional_item('sample ID', SASentry.SASsample, 'ID') 
     88    print_optional_item('sample thickness', SASentry.SASsample, 'thickness') 
     89    print_optional_item('sample transmission', SASentry.SASsample, 'transmission') 
     90    if 'position' in SASentry.SASsample.__dict__: 
     91        print_optional_item('sample X', SASentry.SASsample.position, 'x') 
     92        print_optional_item('sample Y', SASentry.SASsample.position, 'y') 
     93    print_SASdata(SASentry.SASdata) 
     94 
     95 
     96if __name__ == "__main__": 
     97    if len(sys.argv) == 2: 
     98        demo(sys.argv[1]) 
     99    else: 
     100        demo(os.path.join('..', 'examples', 'bimodal-test1.xml')) 
     101        demo(os.path.join('..', 'examples', 's81-polyurea.xml')) 
Note: See TracChangeset for help on using the changeset viewer.