diff --git a/tools/h5part_reader.py b/tools/h5part_reader.py index 7f97b932..82d25aa3 100755 --- a/tools/h5part_reader.py +++ b/tools/h5part_reader.py @@ -17,8 +17,7 @@ import h5py import numpy as np -from pydrex import core as _core -from pydrex import minerals as _minerals +from pydrex import Mineral, MineralFabric, MineralPhase def _get_args() -> argparse.Namespace: @@ -76,14 +75,14 @@ def _get_args() -> argparse.Namespace: for particle_id in file["Step#0/id"][:]: option_map = { - "olivine": _core.MineralPhase.olivine, - "enstatite": _core.MineralPhase.enstatite, - "A": _minerals.OlivineFabric.A, - "B": _minerals.OlivineFabric.B, - "C": _minerals.OlivineFabric.C, - "D": _minerals.OlivineFabric.D, - "E": _minerals.OlivineFabric.E, - "N": _minerals.EnstatiteFabric.A, + "olivine": MineralPhase.olivine, + "enstatite": MineralPhase.enstatite, + "A": MineralFabric.olivine_A, + "B": MineralFabric.olivine_B, + "C": MineralFabric.olivine_C, + "D": MineralFabric.olivine_D, + "E": MineralFabric.olivine_E, + "N": MineralFabric.enstatite_AB, } # Temporary data arrays. @@ -115,7 +114,7 @@ def _get_args() -> argparse.Namespace: _postfix = str(particle_id) _fractions = list(fractions) _orientations = list(orientations) - mineral = _minerals.Mineral( + mineral = Mineral( phase=option_map[args.fabric], fabric=option_map[args.phase], n_grains=args.ngrains, diff --git a/tools/venv_install.sh b/tools/venv_install.sh new file mode 100755 index 00000000..0bf84aaf --- /dev/null +++ b/tools/venv_install.sh @@ -0,0 +1,44 @@ +#!/bin/env sh +set -eu +readonly SCRIPTNAME="${0##*/}" +usage() { + printf 'Usage: %s [-h]\n' "$SCRIPTNAME" + printf ' %s [-u]\n' "$SCRIPTNAME" +} +helpf() { + echo 'Options:' + echo '-u Update pydrex and dependencies in the venv' + echo ' and compile new requirements.txt' + echo + echo 'Install local pydrex tree in a Python venv (virtual environment),' + echo 'in editable mode with development dependencies.' + echo 'This script should be executed in a context which has access to a' + echo 'Python binary of the appropriate version (check requires-python in' + echo 'pyproject.toml). If the necessary version is not available on your' + echo 'system, you can install it using pyenv' + echo '(https://github.com/pyenv/pyenv) and this script will prefer the' + echo 'local pyenv binary over the system one.' + echo + echo 'Backups of the last requirements.txt are stored in requirements.bak' +} + +upgrade() { + . .venv-"${PWD##*/}"/bin/activate + [ -f requirements.txt ] && mv -i requirements.txt requirements.bak + pip install --upgrade pip pip-tools && pip-compile --resolver=backtracking && pip-sync + pip install -e "$PWD"\[dev\] +} + +if [ $# -eq 0 ]; then # first install + [ -d .venv-"${PWD##*/}" ] && exit 0 # venv already exists, no-op + "$(2>/dev/null pyenv prefix||printf '/usr')"/bin/python -m venv .venv-"${PWD##*/}" + upgrade +fi + +while getopts "hu" OPT; do + case $OPT in + h ) usage && helpf; exit 0;; + u ) upgrade;; + * ) usage; exit 1;; + esac +done