-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from MaxBo/feature/pyproject.toml
matrixconverters as own package
- Loading branch information
Showing
81 changed files
with
15,369 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
name: Build Matrixconverters for Linux | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
build-linux: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
max-parallel: 5 | ||
matrix: | ||
python-version: [3.8, 3.9, '3.10', '3.11', '3.12'] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup base conda for Python 3.11 | ||
uses: s-weigand/setup-conda@v1 | ||
with: | ||
update-conda: true | ||
python-version: 3.11 | ||
conda-channels: MaxBo, conda-forge, defaults | ||
|
||
- name: Install dependencies and set channels | ||
run: | | ||
conda install conda-build conda-verify anaconda-client twine readme_renderer | ||
conda create -q -n test-environment python=${{ matrix.python-version }} pytest-cov | ||
- name: Build and test matrixconverters | ||
run: | | ||
export TMPDIR=${{ runner.TEMP }} | ||
export CONDA_BLD_PATH=$TMPDIR | ||
conda build --python ${{ matrix.python-version }} matrixconverters/conda.recipe | ||
- name: Create Docs | ||
if: ${{ matrix.python-version == '3.12' }} | ||
run: | | ||
/usr/share/miniconda/bin/conda shell.bash activate test-environment | ||
export PATH=$HOME/.local/bin:$PATH | ||
cd matrixconverters | ||
pip install sphinx sphinxcontrib-napoleon sphinx-autodoc-typehints 'mistune<2' m2r2 | ||
pip install . | ||
sphinx-apidoc -f --separate -o docs_rst/matrixconverters src/matrixconverters | ||
sphinx-build docs_rst ../docs | ||
- name: Deploy Docs to gh-pages | ||
if: ${{ matrix.python-version == '3.12' }} | ||
uses: JamesIves/github-pages-deploy-action@v4 | ||
with: | ||
branch: gh-pages # The branch the action should deploy to. | ||
folder: docs # The folder the action should deploy. | ||
|
||
- name: Upload files for matrixconverters | ||
env: | ||
ANACONDA_TOKEN: ${{ secrets.ANACONDA_GITHUBACTION_TOKEN }} | ||
ANACONDA_USERNAME: MaxBo | ||
CONDA_BLD_PATH: ${{ runner.TEMP }} | ||
|
||
run: | | ||
/usr/share/miniconda/bin/conda shell.bash activate test-environment | ||
export PATH=$HOME/.local/bin:$PATH | ||
anaconda -t $ANACONDA_TOKEN upload --skip-existing --user $ANACONDA_USERNAME $CONDA_BLD_PATH/linux-64/matrixconverters-*.tar.bz2 | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
name: build matrixconverters for Windows | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
build-windows: | ||
runs-on: windows-latest | ||
defaults: | ||
run: | ||
shell: cmd | ||
strategy: | ||
max-parallel: 5 | ||
matrix: | ||
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Setup base conda for Python | ||
uses: conda-incubator/setup-miniconda@v3 | ||
with: | ||
auto-activate-base: true | ||
activate-environment: "" | ||
miniforge-version: latest | ||
channels: conda-forge | ||
env: | ||
TMPDIR: ${{ runner.TEMP }} | ||
CONDA_BLD_PATH: env.TMPDIR | ||
|
||
- name: Install dependencies and set channels | ||
run: | | ||
( | ||
mamba install -n base "conda>=23.7" conda-build conda-verify anaconda-client boa twine | ||
mamba create -n test-wheels python=${{ matrix.python-version }} numpy pytest-cov build | ||
mamba create -n test-conda python=${{ matrix.python-version }} numpy pytest-cov | ||
) | ||
- name: build matrixconverters for python version | ||
env: | ||
CONDA_BLD_PATH: ${{ runner.TEMP }} | ||
TMPDIR: ${{ runner.TEMP }} | ||
LIBARCHIVE: C:\Miniconda\Library\bin\archive.dll | ||
run: | | ||
( | ||
conda build --python ${{ matrix.python-version }} --no-test matrixconverters\conda.recipe | ||
conda install -c local -c conda-forge -n test-conda matrixconverters | ||
) | ||
- name: test matrixconverters for python version | ||
env: | ||
CONDA_BLD_PATH: ${{ runner.TEMP }} | ||
TMPDIR: ${{ runner.TEMP }} | ||
run: | | ||
( | ||
mamba activate test-conda | ||
python -m pytest --pyargs matrixconverters | ||
echo "### All tests with conda passed! :rocket:" >> $GITHUB_STEP_SUMMARY | ||
) | ||
- name: Upload package to conda | ||
|
||
env: | ||
CONDA_BLD_PATH: ${{ runner.TEMP }} | ||
ANACONDA_TOKEN: ${{ secrets.ANACONDA_GITHUBACTION_TOKEN }} | ||
ANACONDA_USERNAME: MaxBo | ||
if: ${{ env.ANACONDA_TOKEN }} | ||
|
||
run: | | ||
( | ||
mamba activate base | ||
anaconda -t %ANACONDA_TOKEN% upload --skip-existing --user %ANACONDA_USERNAME% %CONDA_BLD_PATH%\win-64\matrixconverters-*.tar.bz2 | ||
) | ||
- name: Build wheel and run tests for matrixconverters | ||
run: | | ||
( | ||
conda activate test-wheels | ||
cd matrixconverters | ||
echo "build matrixconverters from folder %CD%" | ||
pip install . | ||
python -m pytest --pyargs matrixconverters | ||
python -m build -n . | ||
echo "### All tests with pip passed! :rocket:" >> $GITHUB_STEP_SUMMARY | ||
) | ||
- name: run code coverage | ||
if: ${{ matrix.python-version == '3.12' }} | ||
run: | | ||
( | ||
conda activate test-wheels | ||
cd matrixconverters | ||
echo "build matrixconverters -e from folder %CD%" | ||
pip install -e . | ||
py.test --cov=src --cov-report xml --pyargs matrixconverters | ||
coverage xml | ||
echo "### Code Coverage checked! :rocket:" >> $GITHUB_STEP_SUMMARY | ||
) | ||
- name: Upload to Codecov | ||
if: ${{ matrix.python-version == '3.12' }} | ||
uses: codecov/codecov-action@v3 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
files: ./matrixconverters/coverage.xml | ||
flags: unittests # optional | ||
fail_ci_if_error: true # optional (default = false) | ||
|
||
- name: Publish matrixconverters to PyPI | ||
if: startsWith(github.ref, 'refs/tags/') | ||
env: | ||
TWINE_USERNAME: '__token__' | ||
run: | | ||
( | ||
mamba activate base | ||
twine upload --skip-existing -p ${{ secrets.PYPI_MATRIXCONVERTERS }} dist\* | ||
) | ||
- name: Setup tmate session | ||
if: ${{ failure() }} | ||
uses: mxschmitt/action-tmate@v3 | ||
timeout-minutes: 60 | ||
with: | ||
detached: true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
*.py[co] | ||
*.pyd | ||
*.pyxbldc | ||
*.swp | ||
*.so | ||
|
||
# Packages | ||
*.egg | ||
*.eggs | ||
*.egg-info | ||
*.whl | ||
dist | ||
build | ||
docs | ||
eggs | ||
parts | ||
bin | ||
var | ||
sdist | ||
develop-eggs | ||
.installed.cfg | ||
.git | ||
# Installer logs | ||
pip-log.txt | ||
# Unit test / coverage reports | ||
.coverage | ||
coverage.xml | ||
.tox | ||
htmlcov | ||
*.log | ||
#Translations | ||
*.mo | ||
# compiled cython scripts | ||
*.c | ||
*.html | ||
|
||
#WingIDE Stuff | ||
*.wpr | ||
*.wpu | ||
|
||
wingdbstub.py | ||
|
||
.cache | ||
.spyder* | ||
|
||
|
||
# doctrees in documentation | ||
/docs/_build/doctrees |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,3 @@ | ||
[run] | ||
plugins = Cython.Coverage | ||
omit = | ||
*.pxd | ||
[report] | ||
exclude_lines = | ||
pragma: no cover | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
|
||
[![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](http://www.gnu.org/licenses/gpl-3.0) | ||
[![Build Status Linux](https://github.com/MaxBo/matrixconverters/actions/workflows/linux-conda.yml/badge.svg)](https://github.com/MaxBo/matrixconverters/actions/workflows/linux-conda.yml) | ||
[![Build Status Windows](https://github.com/MaxBo/matrixconverters/actions/workflows/windows_conda.yml/badge.svg)](https://github.com/MaxBo/matrixconverters/actions/workflows/windows_conda.yml) | ||
[![codecov](https://codecov.io/gh/MaxBo/matrixconverters/branch/master/graph/badge.svg)](https://codecov.io/gh/MaxBo/matrixconverters) | ||
|
||
|
||
##matrixconverters: | ||
[![PyPI version](https://badge.fury.io/py/matrixconverters.svg)](https://badge.fury.io/py/matrixconverters) | ||
[![Anaconda-Server Badge](https://anaconda.org/maxbo/matrixconverters/badges/version.svg)](https://anaconda.org/maxbo/matrixconverters) | ||
|
||
tools to read and write matrices in the format or PTV VISUM | ||
|
||
It implements: | ||
|
||
**Reading and writing PTV-Matrices** | ||
|
||
It can read and write the following formats: | ||
* Text-Formats: O-Format, V-Format, S-Format | ||
* Binary formats: BI-Format, BK-Format, BL-Format | ||
|
||
``` | ||
# read a matrix into a xarray-Dataset | ||
from matrixconverters import ReadPTVMatrix, SavePTVMatrix | ||
ds = ReadPTVMatrix(filepath) | ||
# save a xr.Dataset as PTV-Matrix | ||
import xarray as xr | ||
da = xr.DataArray(np.arange(9).reshape(3, 3)) | ||
zones = xr.DataArray([100, 200, 300]) | ||
names = xr.DataArray(['A-Town', 'B-Village', 'C-City']) | ||
ds = xr.Dataset({'matrix': da, | ||
'zone_no': zones, | ||
'zone_name': names,}) | ||
from matrixconverters.save_ptv import SavePTV | ||
s = SavePTV(ds) | ||
s.savePTVMatrix(file_name=matrix_fn_out, file_type='BK') | ||
``` | ||
|
||
**Writing PSV-Matrices** | ||
* Programmsystem Verkehr by Software-Kontor Helmert-Hilke) | ||
* File-Types CC and CN | ||
|
||
``` | ||
from matrixconverters.save_ptv import SavePTV | ||
s = SavePTV(ds) | ||
s.savePSVMatrix(file_name=matrix_fn_out, ftype='CC') | ||
``` | ||
|
||
**Export xarray-Dataset as compressed NetCDF-File** | ||
|
||
``` | ||
from matrixconverters.xarray2netcdf import xarray2netcdf | ||
xarray2netcdf(ds, file_path) | ||
ds_saved = xr.open_dataset(file_path) | ||
``` | ||
|
||
[Documentation](https://maxbo.github.io/matrixconverters/) | ||
|
||
# Installation | ||
You can use pip to install the packages (and the requirements like numpy). | ||
|
||
``` | ||
pip install matrixconverters | ||
``` | ||
|
||
Another way to handle dependencies is to use [conda](https://conda.io/miniconda.html). | ||
|
||
There conda packages for python 3.8-3.12 for windows and linux are generated | ||
in the channel *MaxBo* in [Anaconda Cloud](https://anaconda.org/MaxBo). | ||
|
||
``` | ||
conda create -n myenv python=3.12 | ||
conda activate myenv | ||
conda config --add channels conda-forge | ||
conda config --add channels MaxBo | ||
conda install matrixconverters | ||
``` |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.