Preparation of pyrolysis modelling publication.
DataProcessing/
: Jupyter notebooks with analysis code (sub-dirs ignored during commit)Experiments/
: folder for experimental datasetsGeneralInformation/
: general information, likerequirements.txt
Simulations/
: folder for simulation files
The Python scripts are built on Python version: 3.13.3 (tags/v3.13.3:6280bb5, Apr 8 2025, 14:47:33) [MSC v.1943 64 bit (AMD64)]
Use the requirements.txt
to build a virtual Python environment. It is located in GeneralInformation\Python_venv
.
This description assumes you intent to set up a virtual Python environment on Windows, using Powershell. Adjust the paths according to your setup.
From a clean Python installation, create a clean virtual environment. This is done by typing the following command into the Powershell terminal: C:\Programs\Python\Python313\python.exe -m venv name_of_your_environment
. You can give it a name by changing name_of_your_environment
to what ever name you like. This will create a directory of the chosen name, containing the necessary files of the environment.
In Powershell, the process needs to be given permission to run the environment, like so:
Set-ExecutionPolicy Unrestricted -Scope Process
Set the exception for this process by hitting "Y" (yes). This step needs to be repeated every time you want to run the environment from your console, but is not necessary if you use it just as Jupyter kernel (see below).
Now, you can start the environment. For this, a specific file in the directory needs to be called in Powershell: C:\Venvs\name_of_your_environment\Scripts\activate
.
The requirements.txt
can now be used to install specific packages recursively: pip install -r C:\Pyrolysis_BESKID\GeneralInformation\Python_venv\requirements.txt
.
You can use this virtual environment as kernel for your Jupyter notebooks. It can be installed as follows: python -m ipykernel install --user --name=name_of_your_environment --display-name "Python (name_of_your_environment)"
.
In an effort to keep the repo clean from unneccesary files, as well as binaries like images, a pre-commit hook is set up. This will automatically remove the output of Jupyter notebooks using nbstripout
.
Quick checklist:
- Have
.pre-commit-config.yaml
in the repo (with thenbstripout
hook). - Install pre-commit (globally on your machine is fine, see
pipx
below):pip install pre-commit
- In the repo (adds the Git hook):
pre-commit install
. - One-time clean (inside repo):
pre-commit run --all-files
(this should run on all files in the repo, if it does not, you can stage a notebook (git add notebook
) and run the command)
Step 4 will set up its own environment, which can take a few minutes on the first run. For subsequent calls it will be faster then.
Now when commits are made, the hook will run before and clean the notebooks if necessary. If it removes the output of a notebook, the file is changed and the commit itself aborts. You need to stage the changed files again, as well as the commit. If the newly staged notebook is clean, it will pass.
Possible workflows:
- Inside Jupyter-lab, run
Edit\Clear Outputs of All Cells
- Stage and commit
or
- stage notebooks
- run
pre-commit run --all-files
- stage again
- commit, once all output is removed
or
- stage and commit (fails, because output is removed)
- stage again
- commit, once all output is removed
Notes:
- The first
run --all-files
may modify notebooks; the run can exit with a non-zero status to tell you files changed. Justgit add .
and commit afterwards. - From now on, the hook runs on staged files at commit time and strips outputs automatically.
- Share with co-authors: they only need
pip install pre-commit && pre-commit install
in their clone.
Warning
In this mode, nbstripout
is used as a git hook to strip any .ipynb
files
before committing. This also modifies your working copy!
On your machine, install pipx
as an independent, global location for the Git hook related packages:
python -m pip install --user pipx
python -m pipx ensurepath
to ensure that~/.local/bin to PATH
is set up- reopen the terminal (Powershell) and run
pipx --version
to check if the path is set up correctly nbstripout
may need to be installed here too:pipx install nbstripout