Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Python package

on:
push:
branches:
- 'master'
pull_request:


jobs:
lint-coverage:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.13"]
steps:
- uses: actions/checkout@v6

- name: Setup uv
uses: astral-sh/setup-uv@v7

- name: Lint
run: uv run --python ${{ matrix.python-version }} --extra dev ruff check --output-format=github

- name: Generate coverage report
run: |
uv run --python ${{ matrix.python-version }} --extra dev \
pytest tests/ \
--cov=. \
--cov-branch \
--cov-report=term-missing \
--cov-report=html:cov_html \
--cov-report=markdown-append:$GITHUB_STEP_SUMMARY \
--verbose

- uses: actions/upload-artifact@v6
with:
name: html-coverage-artifact
path: ./cov_html/

test:
needs: lint-coverage
runs-on: ${{ matrix.os }}
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.os }}-${{ matrix.python-version }}
cancel-in-progress: true
strategy:
fail-fast: true
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
os: [ubuntu-latest, windows-latest, macos-latest]
exclude:
- os: macos-latest
python-version: "3.9"
- os: macos-latest
python-version: "3.10"

steps:
- uses: actions/checkout@v6

- name: Setup uv
uses: astral-sh/setup-uv@v7

- name: Install and test
run: uv run --python ${{ matrix.python-version }} --extra dev pytest
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,9 @@ nosetests.xml

# Python build directory
api/python/build

.venv/
venv/
pyenv/
.idea/
build/
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ v0.3.3, 2017-03-07 -- Python 3 compatible
v0.3.4, 2018-04-05 -- Fix incorrect version being saved
v0.3.4.1, 2018-10-19 -- python3 compatible next for generator
v0.3.5, 2019-12-21 -- add validator and clean-up repo structure
v0.4.0, 2025-12-21 -- Replaces PyTables with H5Py, cleans repo structure, adds CI

3 changes: 0 additions & 3 deletions MANIFEST.in

This file was deleted.

357 changes: 205 additions & 152 deletions README.md

Large diffs are not rendered by default.

66 changes: 32 additions & 34 deletions example/python-omx-sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,35 @@
import numpy as np

# Create some data
ones = np.ones((100,100))
twos = 2.0*ones
ones = np.ones((100, 100))
twos = 2.0 * ones


# Create an OMX file (will overwrite existing file!)
print('Creating myfile.omx')
myfile = omx.open_file('myfile.omx','w') # use 'a' to append/edit an existing file
print("Creating myfile.omx")
myfile = omx.open_file("myfile.omx", "w") # use 'a' to append/edit an existing file


# Write to the file.
myfile['m1'] = ones
myfile['m2'] = twos
myfile['m3'] = ones + twos # numpy array math is fast
myfile["m1"] = ones
myfile["m2"] = twos
myfile["m3"] = ones + twos # numpy array math is fast
myfile.close()


# Open an OMX file for reading only
print('Reading myfile.omx')
myfile = omx.open_file('myfile.omx')
print("Reading myfile.omx")
myfile = omx.open_file("myfile.omx")

print ('Shape:', myfile.shape()) # (100,100)
print ('Number of tables:', len(myfile)) # 3
print ('Table names:', myfile.list_matrices()) # ['m1','m2',',m3']
print("Shape:", myfile.shape()) # (100,100)
print("Number of tables:", len(myfile)) # 3
print("Table names:", myfile.list_matrices()) # ['m1','m2',',m3']


# Work with data. Pass a string to select matrix by name:
# -------------------------------------------------------
m1 = myfile['m1']
m2 = myfile['m2']
m3 = myfile['m3']
m1 = myfile["m1"]
m2 = myfile["m2"]

# halves = m1 * 0.5 # CRASH! Don't modify an OMX object directly.
# # Create a new numpy array, and then edit it.
Expand All @@ -46,43 +45,42 @@

# FANCY: Use attributes to find matrices
# --------------------------------------
myfile.close() # was opened read-only, so let's reopen.
myfile = omx.open_file('myfile.omx','a') # append mode: read/write existing file
myfile.close() # was opened read-only, so let's reopen.
myfile = omx.open_file("myfile.omx", "a") # append mode: read/write existing file

myfile['m1'].attrs.timeperiod = 'am'
myfile['m1'].attrs.mode = 'hwy'
myfile["m1"].attrs.timeperiod = "am"
myfile["m1"].attrs.mode = "hwy"

myfile['m2'].attrs.timeperiod = 'md'
myfile["m2"].attrs.timeperiod = "md"

myfile['m3'].attrs.timeperiod = 'am'
myfile['m3'].attrs.mode = 'trn'
myfile["m3"].attrs.timeperiod = "am"
myfile["m3"].attrs.mode = "trn"

print('attributes:', myfile.list_all_attributes()) # ['mode','timeperiod']
print("attributes:", myfile.list_all_attributes()) # ['mode','timeperiod']

# Use a DICT to select matrices via attributes:

all_am_trips = myfile[ {'timeperiod':'am'} ] # [m1,m3]
all_hwy_trips = myfile[ {'mode':'hwy'} ] # [m1]
all_am_trn_trips = myfile[ {'mode':'trn','timeperiod':'am'} ] # [m3]
all_am_trips = myfile[{"timeperiod": "am"}] # [m1,m3]
all_hwy_trips = myfile[{"mode": "hwy"}] # [m1]
all_am_trn_trips = myfile[{"mode": "trn", "timeperiod": "am"}] # [m3]

print('sum of some tables:', np.sum(all_am_trips))
print("sum of some tables:", np.sum(all_am_trips))


# SUPER FANCY: Create a mapping to use TAZ numbers instead of matrix offsets
# --------------------------------------------------------------------------
# (any mapping would work, such as a mapping with large gaps between zone
# numbers. For this simple case we'll just assume TAZ numbers are 1-100.)

taz_equivs = np.arange(1,101) # 1-100 inclusive
taz_equivs = np.arange(1, 101) # 1-100 inclusive

myfile.create_mapping('taz', taz_equivs)
print('mappings:', myfile.list_mappings()) # ['taz']
myfile.create_mapping("taz", taz_equivs)
print("mappings:", myfile.list_mappings()) # ['taz']

tazs = myfile.mapping('taz') # Returns a dict: {1:0, 2:1, 3:2, ..., 100:99}
tazs = myfile.mapping("taz") # Returns a dict: {1:0, 2:1, 3:2, ..., 100:99}

m3 = myfile['m3']
m3 = myfile["m3"]

print('cell value:', m3[tazs[100]][tazs[100]]) # 3.0 (taz (100,100) is cell [99][99])
print("cell value:", m3[tazs[100]][tazs[100]]) # 3.0 (taz (100,100) is cell [99][99])

myfile.close()

Loading