Skip to content
Open
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
191 changes: 191 additions & 0 deletions hands-on/session II/Materials/build_jetstream_environment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
#!/usr/bin/env bash
set -euo pipefail

# ----------------------------------------
# Pretty printing helpers (same style)
# ----------------------------------------

function generate_separator {
local max_len=0
for arg in "$@"; do
((${#arg} > max_len)) && max_len=${#arg}
done

local spaces
printf -v spaces "%${max_len}s" ""
echo "${spaces// /=}"
}

function print_separated_message {
local sep
sep=$(generate_separator "$@")

echo "$sep"
for line in "$@"; do
echo "$line"
done
echo "$sep"
}

function die {
echo "ERROR: $*" >&2
exit 1
}

function step {
# Usage: step "1/7" "Message"
print_separated_message "[${1}] ${2}"
}

# ----------------------------------------
# Static settings (change only if needed)
# ----------------------------------------

ENV_NAME="NSDF-Tutorial"
KERNEL_NAME="nsdf-tutorial"
KERNEL_DISPLAY='Python (NSDF-Tutorial)'

# ----------------------------------------
# Derived paths
# ----------------------------------------

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"

# ----------------------------------------
# 0) Ensure conda is available
# ----------------------------------------

step "0/7" "Checking conda availability"

if command -v module >/dev/null 2>&1; then
# Jetstream module environment
module purge >/dev/null 2>&1 || true
module load miniforge >/dev/null 2>&1 || true
fi

command -v conda >/dev/null 2>&1 || die "conda not found. Did you 'module load miniforge'?"

# Make conda activate work in scripts
# shellcheck disable=SC1090
source "$(conda info --base)/etc/profile.d/conda.sh"

# ----------------------------------------
# 1) Create env from environment.yml (replace if exists)
# ----------------------------------------

step "1/7" "Create env from environment.yml (name: ${ENV_NAME})"

if conda env list | awk '{print $1}' | grep -qx "$ENV_NAME"; then
echo "Removing existing env: ${ENV_NAME}"
conda env remove -n "$ENV_NAME" -y >/dev/null
fi

conda env create -f environment.yml >/dev/null

# ----------------------------------------
# 2) Activate environment
# ----------------------------------------

step "2/7" "Activate env: ${ENV_NAME}"

conda activate "$ENV_NAME"
hash -r

# ----------------------------------------
# 3) Verify activation (hard fail if wrong)
# ----------------------------------------

step "3/7" "Verify activation"

python - <<PY
import os, sys
env = os.environ.get("CONDA_DEFAULT_ENV")
prefix = os.environ.get("CONDA_PREFIX")
print("CONDA_DEFAULT_ENV:", env)
print("CONDA_PREFIX:", prefix)
print("sys.executable:", sys.executable)
if env != "$ENV_NAME":
raise SystemExit(f"ERROR: expected CONDA_DEFAULT_ENV=$ENV_NAME but got {env}")
PY

# ----------------------------------------
# 4) Install GEOtiled/geotiled editable
# ----------------------------------------

step "4/7" "Install GEOtiled/geotiled editable"

GEOTILED_DIR="$SCRIPT_DIR/GEOtiled/geotiled"
[[ -d "$GEOTILED_DIR" ]] || die "GEOtiled/geotiled dir not found: $GEOTILED_DIR"

python -m pip install -e "$GEOTILED_DIR" >/dev/null

# ----------------------------------------
# 5) Configure Openvisuspy environment variables
# ----------------------------------------

step "5/7" "Configure Openvisuspy env vars (~/.bashrc)"

OPENVISUSPY_SRC="$SCRIPT_DIR/openvisuspy/src"
[[ -d "$OPENVISUSPY_SRC" ]] || die "openvisuspy/src not found: $OPENVISUSPY_SRC"

# Append only if not already present (idempotent-ish)
append_if_missing () {
local line="$1"
local file="$2"
grep -Fqx "$line" "$file" 2>/dev/null || echo "$line" >> "$file"
}

BASHRC="$HOME/.bashrc"

append_if_missing "export PATH=\"\$PATH:${OPENVISUSPY_SRC}\"" "$BASHRC"
append_if_missing "export PYTHONPATH=\"\$PYTHONPATH:${OPENVISUSPY_SRC}\"" "$BASHRC"
append_if_missing "export BOKEH_ALLOW_WS_ORIGIN='*'" "$BASHRC"
append_if_missing "export BOKEH_RESOURCES='cdn'" "$BASHRC"
append_if_missing "export VISUS_CACHE=/tmp/visus-cache/nsdf-services/somospie" "$BASHRC"
append_if_missing "export VISUS_CPP_VERBOSE=1" "$BASHRC"
append_if_missing "export VISUS_NETSERVICE_VERBOSE=1" "$BASHRC"
append_if_missing "export VISUS_VERBOSE_DISKACCESS=1" "$BASHRC"

# Load into current shell too
# shellcheck disable=SC1090
source "$BASHRC"

# ----------------------------------------
# 6) Install openvisuspy editable
# ----------------------------------------

step "6/7" "Install openvisuspy editable"

OPENVISUSPY_DIR="$SCRIPT_DIR/openvisuspy"
[[ -d "$OPENVISUSPY_DIR" ]] || die "openvisuspy dir not found: $OPENVISUSPY_DIR"

python -m pip install -e "$OPENVISUSPY_DIR" >/dev/null

# ----------------------------------------
# 7) Install ipykernel + register kernel
# ----------------------------------------

step "7/7" "Install Jupyter kernel + extras"

# keep these visible enough to diagnose, but not too noisy
ENV_BIN_DIR="$CONDA_PREFIX/bin"

python -m ipykernel install --user \
--name "$KERNEL_NAME" \
--display-name "$KERNEL_DISPLAY" \
--env PATH "$ENV_BIN_DIR:$OPENVISUSPY_SRC:$PATH" \
--env LD_LIBRARY_PATH "$CONDA_PREFIX/lib:$CONDA_PREFIX/lib/gdalplugins" \
--env PROJ_LIB "$CONDA_PREFIX/share/proj" \
--env GDAL_DATA "$CONDA_PREFIX/share/gdal" \
--env PROJ_NETWORK "ON"

print_separated_message \
"DONE" \
"" \
"Environment:" \
" conda activate ${ENV_NAME}" \
"" \
"Kernel:" \
" jupyter kernelspec list" \
" (look for '${KERNEL_DISPLAY}')"
2 changes: 1 addition & 1 deletion hands-on/session II/Materials/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ dependencies:
- pip
- pip:
- panel==1.3.8
- OpenVisusNoGui==2.2.128
- OpenVisusNoGui==2.2.149
Binary file not shown.
76 changes: 74 additions & 2 deletions hands-on/session II/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ You can download the introductory slides [here](https://drive.google.com/file/d/
1. [Running the Tutorial](#running-the-tutorial)
2. [Option 1: GitHub Codespaces (Recommended)](#option-1-GitHub-codespaces-recommended)
3. [Option 2: Docker](#0ption-2-docker)
4. [APPENDIX: Prerequities for Docker](#appendix-prerequities-for-docker)
5. [Community and Resources](#community-and-resources)
4. [Option 3: Jetstream2](#option-3-jetstream2)
5. [APPENDIX: Prerequities for Docker](#appendix-prerequities-for-docker)
6. [Community and Resources](#community-and-resources)
7. [Publications](#publications)
8. [Copyright and License](#copyright-and-license)
9. [Authors](#authors)
Expand Down Expand Up @@ -118,6 +119,77 @@ docker-compose up -d</code></pre>
</li>
</ol>

## Option 3: Jetstream2
<p><strong>Requirements:</strong> Access to a Jetstream2 instance via SSH.</p>

<h4>Initial Setup (First Time Only)</h4>
<ol>
<li>
If you do not already have a Jetstream2 instance, follow the
<a href="Materials/jetstream2_manual.pdf" target="_blank">
Jetstream2 Setup Manual
</a>
to create and connect to one.
</li>

<li>Connect to your Jetstream2 instance via SSH.</li>

<li>
Clone the tutorial repository:
<pre><code>git clone https://github.com/TauferLab/NSDF-Tutorial-2025.git</code></pre>
</li>

<li>
Navigate to the session materials directory and build the environment:
<pre><code>cd NSDF-Tutorial-2025/hands-on/session\ II/Materials/
module load miniforge
./build_jetstream_environment.sh</code></pre>
</li>

<li>
Start Jupyter Lab:
<pre><code>cd ..
jupyter-ip.sh</code></pre>
</li>

<li>Open the Jupyter Lab URL printed in the terminal in your web browser.</li>

<li>
In Jupyter Lab, select the kernel named
<strong>NSDF-Tutorial</strong>.
</li>
</ol>

<h4>Starting the Environment (After Installation)</h4>
<ol>
<li>
Load Conda:
<pre><code>module load miniforge
</code></pre>
</li>

<li>
Navigate to the tutorial directory and start Jupyter:
<pre><code>cd hands-on/session\ II
jupyter-ip.sh</code></pre>
</li>

<li>Open the Jupyter Lab URL printed in the terminal in your browser.</li>
</ol>

<h4>Accessing OpenVisuspy Dashboards</h4>
<ol>
<li>
From your local machine, create an SSH tunnel to forward the dashboard port:
<pre><code>ssh -L 8989:127.0.0.1:8989 &lt;Jetstream Native SSH&gt;</code></pre>
</li>

<li>
After executing the corresponding dashboard cell in Jupyter, open your browser and navigate to:
<pre><code>http://localhost:8989</code></pre>
</li>
</ol>


## APPENDIX: Prerequisites

Expand Down
1 change: 1 addition & 0 deletions hands-on/session III/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ channels:
- defaults
dependencies:
- python=3.10
- ipykernel==6.29.2
- pip
- pip:
- numpy
Expand Down