You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+50-44Lines changed: 50 additions & 44 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# OMX Python API Documentation
2
2
3
-
The Python OMX API borrows heavily from PyTables. An OMX file extends the equivalent PyTables File object, so anything you can do in PyTables you can do with OMX as well. This API attempts to be very Pythonic, including dictionary-style lookup of matrix names.
3
+
The Python OMX API is built on top of h5py. An OMX file extends the equivalent h5py File object, so anything you can do in h5py you can do with OMX as well. This API attempts to be very Pythonic, including dictionary-style lookup of matrix names.
4
4
5
5
*[Pre-requisites](#pre-requisites)
6
6
*[Installation](#installation)
@@ -12,16 +12,22 @@ The Python OMX API borrows heavily from PyTables. An OMX file extends the equiva
12
12
13
13
# Pre-requisites
14
14
15
-
Python 2.6+, PyTables 3.1+, and NumPy. Python 3 is now supported too.
15
+
Python 3.9+, h5py 2.10+, and NumPy.
16
16
17
-
On Windows, the easiest way to get these is from [Anaconda](https://www.continuum.io/downloads#windows) or from Chris Gohlke's python binaries [page](http://www.lfd.uci.edu/~gohlke/pythonlibs/). On Linux, your distribution already has these available.
17
+
Binaries for all these dependencies are readily available from PyPI and can be installed via pip.
18
18
19
19
# Installation
20
20
21
21
The easiest way to get OMX on Python is to use pip. Get the latest package (called OpenMatrix) from the [Python Package Index](https://pypi.python.org/pypi)
22
22
23
23
`pip install openmatrix`
24
24
25
+
Using uv is also possible and much faster:
26
+
27
+
`pip install uv`
28
+
`uv pip install openmatrix`
29
+
30
+
25
31
This command will fetch openmatrix from the PyPi repository and download/install it for you. The package name "omx" was already taken on pip for a lame xml library that no one uses. Thus our little project goes by "openmatrix" on pip instead of "omx". This means your import statements should look like,
26
32
27
33
`import openmatrix as omx`
@@ -33,31 +39,30 @@ and NOT:
33
39
# Quick-Start Sample Code
34
40
35
41
```python
36
-
from__future__import print_function
37
42
import openmatrix as omx
38
43
import numpy as np
39
44
40
45
# Create some data
41
-
ones = np.ones((100,100))
42
-
twos =2.0*ones
46
+
ones = np.ones((100,100))
47
+
twos =2.0*ones
43
48
44
49
# Create an OMX file (will overwrite existing file!)
45
50
print('Creating myfile.omx')
46
-
myfile = omx.open_file('myfile.omx','w')# use 'a' to append/edit an existing file
51
+
myfile = omx.open_file('myfile.omx','w') # use 'a' to append/edit an existing file
47
52
48
53
# Write to the file.
49
54
myfile['m1'] = ones
50
55
myfile['m2'] = twos
51
-
myfile['m3'] = ones + twos # numpy array math is fast
56
+
myfile['m3'] = ones + twos # numpy array math is fast
print('cell value:', m3[tazs[100]][tazs[100]]) # 3.0 (taz (100,100) is cell [99][99])
117
+
print('cell value:', m3[tazs[100]][tazs[100]]) # 3.0 (taz (100,100) is cell [99][99])
113
118
114
119
myfile.close()
115
120
```
116
121
117
122
# Testing
118
-
Testing is done with [nose](https://nose.readthedocs.io/en/latest/). Run the tests via:
123
+
Testing is done with [pytest](https://docs.pytest.org/). Run the tests via:
119
124
120
125
```
121
-
openmatrix\test> nosetests -v
126
+
pytest
122
127
```
123
128
124
129
# OMX File Validator
@@ -132,7 +137,7 @@ omx-validate my_file.omx
132
137
133
138
### File Objects
134
139
135
-
OMX File objects extend Pytables.File, so all Pytables functions work normally. We've also added some useful stuff to make things even easier.
140
+
OMX File objects extend h5py.File, so all h5py functions work normally. We've also added some useful stuff to make things even easier.
136
141
137
142
### Writing Data
138
143
@@ -148,25 +153,24 @@ will call createMatrix() for you and populate it with the specified array.
148
153
149
154
### Accessing Data
150
155
151
-
You can access matrix objects by name, using dictionary lookup e.g. `myfile['hwydist']` or using PyTables path notation, e.g. `myfile.root.hwydist`
156
+
You can access matrix objects by name, using dictionary lookup e.g. `myfile['hwydist']`.
152
157
153
158
### Matrix objects
154
159
155
-
OMX matrices extend numpy arrays. An OMX matrix object extends a Pytables/HDF5 "node" which means all HDF5 methods and properties behave normally. Generally these datasets are going to be numpy CArray objects of arbitrary shape.
160
+
OMX matrices are h5py Dataset objects. An OMX matrix object extends an h5py Dataset which means all h5py methods and properties behave normally.
156
161
You can access a matrix object by name using:
157
162
158
163
* dictionary syntax, e.g. `myfile['hwydist']`
159
-
* or by Pytables path syntax, e.g. `myfile.root.hwydist`
160
164
161
165
Once you have a matrix object, you can perform normal numpy math on it or you can access rows and columns pythonically:
Every Matrix has its own dictionary of key/value pair attributes (properties) which can be accessed using the standard Pytables .attrs field. Add as many attributes as you like; attributes can be string, ints, floats, and lists:
173
+
Every Matrix has its own dictionary of key/value pair attributes (properties) which can be accessed using the standard h5py .attrs field. Add as many attributes as you like; attributes can be string, ints, floats, and lists:
170
174
171
175
```python
172
176
print mymatrix.attrs
@@ -202,7 +206,7 @@ OMX module version string. Currently '0.3.5' as of this writing. This is the Py
202
206
### `__omx_version__`
203
207
OMX file format version. Currently '0.2'. This is the OMX file format specification that omx-python adheres to.
0 commit comments