Skip to content

Commit

Permalink
update notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
tkittel committed Mar 1, 2025
1 parent f696187 commit c0739e8
Show file tree
Hide file tree
Showing 18 changed files with 32 additions and 62 deletions.
24 changes: 14 additions & 10 deletions .github/resources/run_notebooks.x
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
set -eu
export REPOROOT="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )/../../" && pwd )"
CODCACHE_SRC="${REPOROOT}/.github/resources/codcache"
Expand All @@ -19,22 +19,26 @@ for notebookfile in `find "${REPOROOT}"/notebooks/ -name '*.ipynb'`; do
cp -rp "${CODCACHE_SRC}" ./ncrystal_onlinedb_filecache
python3 -mvenv create ./venv
. ./venv/bin/activate

if [ "x${NCNOTEBOOKS_USE_NCRYSTAL_REPO}" != "x" ]; then
time python3 -m pip install "${NCNOTEBOOKS_USE_NCRYSTAL_REPO}/ncrystal_core"
python3 -m pip install "${NCNOTEBOOKS_USE_NCRYSTAL_REPO}/ncrystal_python"
python3 -m pip install "${NCNOTEBOOKS_USE_NCRYSTAL_REPO}/ncrystal_metapkg"
fi

#Workaround for https://github.com/spglib/spglib/issues/553 :
TMPPYVER=$(python3 -c 'import sys; print("%i.%i"%sys.version_info[0:2])')
if [ "${TMPPYVER}" == "3.13" ]; then
python3 -mpip install git+https://github.com/tkittel/spglib.git
fi

python3 -mpip install jupyter ipython
echo " .. converting to script"
cat "${notebookfile}" | \
sed 's#always_do_pip_installs = False#always_do_pip_installs = True#' \
> ./thenotebook.ipynb
jupyter nbconvert --to script ./thenotebook.ipynb --output="${PWD}/thenotebook_converted"
test -f ./thenotebook_converted.py
#For now, the texture plugin notebook should only be run on linux and not in
#NCrystal 4 before it has been ported:
DO_RUN_PLUGIN_NOTEBOOKS=0
if [ -e /proc ]; then
DO_RUN_PLUGIN_NOTEBOOKS=1
fi
if [ "x${NCNOTEBOOKS_FORCE_SKIP_PLUGIN_NB:-0}" == "x1" ]; then
DO_RUN_PLUGIN_NOTEBOOKS=0
fi
if [ "x${bn}" == "xNEUWAVE_12_Examples_Transmission_with_NCrystal_and_McStas.ipynb" ]; then
echo
echo
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/run_notebooks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ jobs:
with:
python-version: ${{ matrix.python }}

- name: Pip install
run: python3 -m pip install ncrystal[all]>=4.0.0
# - name: Pip install
# run: python3 -m pip install ncrystal[all]>=4.0.0

- name: Check versions
shell: bash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@
"except ModuleNotFoundError:\n",
" google_colab=None#not on google colab\n",
"if always_do_pip_installs or google_colab:\n",
" from importlib.util import find_spec as _fs\n",
" if not _fs('NCrystal'):\n",
" %pip -q install ncrystal[plot] ipympl pandas\n",
" %pip -q install ncrystal[plot] ipympl pandas\n",
"#enable inline and interactive matplotlib plots:\n",
"if google_colab:\n",
" google_colab.output.enable_custom_widget_manager()\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@
"except ModuleNotFoundError:\n",
" google_colab=None#not on google colab\n",
"if always_do_pip_installs or google_colab:\n",
" from importlib.util import find_spec as _fs\n",
" if not _fs('NCrystal'):\n",
" %pip -q install ncrystal[plot] ipympl tqdm\n",
" %pip -q install ncrystal[plot] ipympl tqdm\n",
"#enable inline and interactive matplotlib plots:\n",
"if google_colab:\n",
" google_colab.output.enable_custom_widget_manager()\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@
"except ModuleNotFoundError:\n",
" google_colab=None#not on google colab\n",
"if always_do_pip_installs or google_colab:\n",
" from importlib.util import find_spec as _fs\n",
" if not _fs('NCrystal'):\n",
" %pip install -q ncrystal[all]\n",
" if not all(_fs(m) for m in ['ipympl','pandas','pickleshare']):\n",
" %pip install -q ipympl pandas pickleshare\n",
" %pip install -q ncrystal[all] ipympl pandas pickleshare\n",
"#enable inline and interactive matplotlib plots:\n",
"if google_colab:\n",
" google_colab.output.enable_custom_widget_manager()\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@
"except ModuleNotFoundError:\n",
" google_colab=None#not on google colab\n",
"if always_do_pip_installs or google_colab:\n",
" from importlib.util import find_spec as _fs\n",
" if not _fs('NCrystal'):\n",
" %pip -q install ncrystal[plot] ipympl pandas\n",
" %pip -q install ncrystal[plot] ipympl pandas\n",
"#enable inline and interactive matplotlib plots:\n",
"if google_colab:\n",
" google_colab.output.enable_custom_widget_manager()\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@
"except ModuleNotFoundError:\n",
" google_colab=None#not on google colab\n",
"if always_do_pip_installs or google_colab:\n",
" from importlib.util import find_spec as _fs\n",
" if not _fs('NCrystal'):\n",
" %pip -q install ncrystal[all] ipympl\n",
" %pip -q install ncrystal[all] ipympl\n",
"#enable inline and interactive matplotlib plots:\n",
"if google_colab:\n",
" google_colab.output.enable_custom_widget_manager()\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@
"except ModuleNotFoundError:\n",
" google_colab=None#not on google colab\n",
"if always_do_pip_installs or google_colab:\n",
" from importlib.util import find_spec as _fs\n",
" if not _fs('NCrystal'):\n",
" %pip -q install ncrystal[all] ipympl\n",
" %pip -q install ncrystal[all] ipympl\n",
"#enable inline and interactive matplotlib plots:\n",
"if google_colab:\n",
" google_colab.output.enable_custom_widget_manager()\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@
"except ModuleNotFoundError:\n",
" google_colab=None#not on google colab\n",
"if always_do_pip_installs or google_colab:\n",
" from importlib.util import find_spec as _fs\n",
" if not all(_fs(m) for m in ['NCrystal','ipympl','pandas']):\n",
" %pip -q install ncrystal[all] ipympl pandas\n",
" %pip -q install ncrystal[all] ipympl pandas\n",
"#enable inline and interactive matplotlib plots:\n",
"if google_colab:\n",
" google_colab.output.enable_custom_widget_manager()\n",
Expand Down
4 changes: 1 addition & 3 deletions notebooks/misc/ncrystal_sapphire_filter.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@
"except ModuleNotFoundError:\n",
" google_colab=None#not on google colab\n",
"if always_do_pip_installs or google_colab:\n",
" from importlib.util import find_spec as _fs\n",
" if not _fs('NCrystal'):\n",
" %pip -q install ncrystal[plot] ipympl\n",
" %pip -q install ncrystal[plot] ipympl\n",
"#enable inline and interactive matplotlib plots:\n",
"if google_colab:\n",
" google_colab.output.enable_custom_widget_manager()\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@
"except ModuleNotFoundError:\n",
" google_colab=None#not on google colab\n",
"if always_do_pip_installs or google_colab:\n",
" from importlib.util import find_spec as _fs\n",
" if not _fs('NCrystal'):\n",
" %pip -q install ncrystal[plot] ipympl\n",
" %pip -q install ncrystal[plot] ipympl\n",
"#enable inline and interactive matplotlib plots:\n",
"if google_colab:\n",
" google_colab.output.enable_custom_widget_manager()\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@
"except ModuleNotFoundError:\n",
" google_colab=None#not on google colab\n",
"if always_do_pip_installs or google_colab:\n",
" from importlib.util import find_spec as _fs\n",
" if not _fs('NCrystal'):\n",
" %pip -q install ncrystal[plot] ipympl\n",
" %pip -q install ncrystal[plot] ipympl\n",
"#enable inline and interactive matplotlib plots:\n",
"if google_colab:\n",
" google_colab.output.enable_custom_widget_manager()\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@
"except ModuleNotFoundError:\n",
" google_colab=None#not on google colab\n",
"if always_do_pip_installs or google_colab:\n",
" from importlib.util import find_spec as _fs\n",
" if not _fs('NCrystal'):\n",
" %pip -q install ncrystal[plot] ipympl numpy\n",
" %pip -q install ncrystal[plot] ipympl numpy\n",
"#enable inline and interactive matplotlib plots:\n",
"if google_colab:\n",
" google_colab.output.enable_custom_widget_manager()\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@
"except ModuleNotFoundError:\n",
" google_colab=None#not on google colab\n",
"if always_do_pip_installs or google_colab:\n",
" from importlib.util import find_spec as _fs\n",
" if not _fs('NCrystal'):\n",
" %pip -q install ncrystal[plot] ipympl\n",
" %pip -q install ncrystal[plot] ipympl\n",
"#enable inline and interactive matplotlib plots:\n",
"if google_colab:\n",
" google_colab.output.enable_custom_widget_manager()\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@
"except ModuleNotFoundError:\n",
" google_colab=None#not on google colab\n",
"if always_do_pip_installs or google_colab:\n",
" from importlib.util import find_spec as _fs\n",
" if not _fs('NCrystal'):\n",
" %pip -q install ncrystal[all] ipympl\n",
" %pip -q install ncrystal[all] ipympl\n",
"#enable inline and interactive matplotlib plots:\n",
"if google_colab:\n",
" google_colab.output.enable_custom_widget_manager()\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@
"except ModuleNotFoundError:\n",
" google_colab=None#not on google colab\n",
"if always_do_pip_installs or google_colab:\n",
" from importlib.util import find_spec as _fs\n",
" if not _fs('NCrystal'):\n",
" %pip -q install ncrystal[all] ipympl\n",
" %pip -q install ncrystal[all] ipympl\n",
"#enable inline and interactive matplotlib plots:\n",
"if google_colab:\n",
" google_colab.output.enable_custom_widget_manager()\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@
"except ModuleNotFoundError:\n",
" google_colab=None#not on google colab\n",
"if always_do_pip_installs or google_colab:\n",
" from importlib.util import find_spec as _fs\n",
" if not _fs('NCrystal'):\n",
" %pip -q install ncrystal[all] ipympl\n",
" %pip -q install ncrystal[all] ipympl\n",
"#enable inline and interactive matplotlib plots:\n",
"if google_colab:\n",
" google_colab.output.enable_custom_widget_manager()\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@
"except ModuleNotFoundError:\n",
" google_colab=None#not on google colab\n",
"if always_do_pip_installs or google_colab:\n",
" from importlib.util import find_spec as _fs\n",
" if not _fs('NCrystal'):\n",
" %pip -q install ncrystal ipympl numpy matplotlib\n",
" %pip -q install ncrystal ipympl numpy matplotlib\n",
"#enable inline and interactive matplotlib plots:\n",
"if google_colab:\n",
" google_colab.output.enable_custom_widget_manager()\n",
Expand Down

0 comments on commit c0739e8

Please sign in to comment.