Changeset 1120 for trunk/bindings/python/nxs.py
- Timestamp:
- 25/10/08 00:17:16 (4 years ago)
- File:
-
- 1 edited
-
trunk/bindings/python/nxs.py (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bindings/python/nxs.py
r1116 r1120 6 6 Wrapper for the NeXus shared library. 7 7 8 Use this interface when converting code from other languages which 9 do not support the natural view of the hierarchy. 8 10 9 11 Library Location … … 11 13 12 14 This wrapper needs the location of the libNeXus precompiled binary. It 13 looks in the following places in order: 15 looks in the following places in order:: 16 14 17 os.environ['NEXUSLIB'] - All 15 18 directory containing nxs.py - All … … 21 24 /usr/lib - Unix and Darwin 22 25 23 On Windows it looks for libNeXus.dll and libNeXus-0.dll; 24 NEXUSDIR defaults to r'C:\Program Files\NeXus Data Format' 26 On Windows it looks for one of libNeXus.dll or libNeXus-0.dll. 25 27 On OS X it looks for libNeXus.dylib 26 28 On Unix it looks for libNeXus.so 29 NEXUSDIR defaults to r'C:\Program Files\NeXus Data Format'. 27 30 PREFIX defaults to /usr/local, but is replaced by the value of 28 31 --prefix during configure. … … 36 39 first import of nxs. 37 40 41 Example 42 ======= 43 44 import nxs 45 file = nxs.open('filename.nxs','rw') 46 file.opengroup('entry1') 47 file.opendata('definition') 48 print file.getdata() 49 file.close() 50 51 See nxstest.py for a more complete example. 52 38 53 Interface 39 54 ========= 40 55 41 Full documentation of the NeXus API is available at nexusformat.org. 42 43 This wrapper differs from napi in several respects: 56 When converting code to python from other languages you do not 57 necessarily want to redo the file handling code. The nxs 58 provides an interface which more closely follows the 59 NeXus application programming interface (NAPI_). 60 61 This wrapper differs from NAPI in several respects:: 62 44 63 - Data values are loaded/stored directly from numpy arrays. 45 64 - Return codes are turned into exceptions. … … 51 70 - NXmalloc/NXfree are not needed. 52 71 53 Example: 54 55 import nxs 56 file = nxs.open('filename.nxs','rw') 57 file.opengroup('entry1') 58 file.opendata('definition') 59 print file.getdata() 60 file.close() 61 62 See nxstest.py for a more complete example. 63 64 File open modes can be constants or strings: 72 File open modes can be constants or strings:: 65 73 66 74 nxs.ACC_READ 'r' … … 71 79 nxs.ACC_CREATEXML 'wx' 72 80 73 Dimension constants: 81 Dimension constants:: 74 82 75 83 nxs.UNLIMITED - for the extensible data dimension 76 84 nxs.MAXRANK - for the number of possible dimensions 77 85 78 Data types are strings corresponding to the numpy data types: 86 Data types are strings corresponding to the numpy data types:: 79 87 80 88 'float32' 'float64' … … 82 90 'uint8' 'uint16' 'uint32' 'uint64' 83 91 84 Use 'char' for strings. You can use the numpy dtype attribute for the 85 data type. 92 Use 'char' for string data. 93 94 You can use the numpy A.dtype attribute for the type of array A. 86 95 87 96 Dimensions are lists of integers or numpy arrays. You can use the 88 numpy shape attribute for the dimensions.89 90 Compression codes are: 97 numpy A.shape attribute for the dimensions of array A. 98 99 Compression codes are:: 91 100 92 101 'none' 'lzw' 'rle' 'huffman' … … 94 103 As of this writing NeXus only supports 'none' and 'lzw'. 95 104 96 Miscellaneous constants: 105 Miscellaneous constants:: 97 106 98 107 nxs.MAXNAMELEN - names must be shorter than this … … 112 121 - if I remove the open/close call in the wrapper it doesn't leak. 113 122 123 .. _NAPI: http://www.nexusformat.org/Application_Program_Interface 114 124 """ 125 __all__ = ['MAXNAMELEN','MAXPATHLEN','NeXus','open'] 126 115 127 import sys, os, numpy, ctypes 116 128
Note: See TracChangeset
for help on using the changeset viewer.
