Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix h5part reader and add venv install script #118

Merged
merged 3 commits into from
Jul 24, 2023
Merged
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
21 changes: 10 additions & 11 deletions tools/h5part_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
44 changes: 44 additions & 0 deletions tools/venv_install.sh
Original file line number Diff line number Diff line change
@@ -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