Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Install Required Software or Run a Docker Image


This notebook installs the Pixi software environment required to run the other notebooks in the NISAR GCOV Cookbook.


Overview

  1. Prerequisites

  2. (Option 1) Install the environment with the Pixi pacakage manager

  3. (Option 2) Run a Docker Image with the software environment already installed

  4. Summary

  5. Resources and references


1. Prerequisites

PrerequisiteImportanceNotes
Option 1: The Pixi package manager must be installed on the system running Jupyter LabNecessaryPixi may not be supported on all Jupyter Hubs
Option 2: Docker must be installed and running on the system running Jupyter LabNecessaryRun the Docker image locally or in a Jupyter Hub
UW Scientific Software Engineering Center’s Pixi guideHelpfulThis is a great resource to get quickly get started with Pixi
  • Rough Notebook Time Estimate: 3 minutes


2. (Option 1) Install the environment with the Pixi pacakage manager

2a. Create a work_dir context manager

This is useful when you want to run a command in a working directory and then automatically change back to your original directory

import os
from contextlib import contextmanager
from pathlib import Path

@contextmanager
def work_dir(new_dir):
    old_dir = os.getcwd()
    os.chdir(new_dir)
    try:
        yield
    finally:
        os.chdir(old_dir)

2b. Install the isce3 environment with Pixi

with work_dir(Path.cwd().parent):
    !pixi install -e isce3

2c. Register the isce3 environment’s Python kernel with ipykernel

env_name = "isce3"
display_name = f'"{env_name} (Python)"'

!pixi run -e isce3 python -m ipykernel install \
  --user \
  --name $env_name \
  --display-name $display_name

2d. Ensure notebook shell commands run in the isce3 environment

This ensures that shell commands executed from inside a notebook with ! run in the notebook kernel’s environment. This works by launching the entire Jupyter kernel process inside the Pixi environment, so the kernel’s PATH, environment variables, and Python executable all come from that Pixi environment, not from the parent JupyterLab environment.

from jupyter_client.kernelspec import KernelSpecManager
import json

ksm = KernelSpecManager()
spec = ksm.get_kernel_spec(env_name)
kernel_dir = Path(spec.resource_dir)
kernel_json = kernel_dir / "kernel.json"

data = json.loads(kernel_json.read_text())
orig_argv = data.get("argv", [])

new_argv = [
    "pixi",
    "run",
    "--manifest-path",
    str(Path.cwd().parent),
    "-e",
    env_name,
] + orig_argv

data["argv"] = new_argv
kernel_json.write_text(json.dumps(data, indent=2))
print(f"Updated kernel.json at {kernel_json} with Pixi wrapper.")
print("argv:", data["argv"])

2e. (Optional) Delete the environment and remove its kernelspec

# Uncomment and run the code below to delete your pixi environment

# with work_dir(Path.cwd().parent):
#     !pixi clean
#     !jupyter kernelspec remove isce3 -y

3. (Option 2) Run a Docker Image with the software environment already installed

Coming soon

4. Summary

Now that you have installed the software environment or have the Docker image running, make sure you have access to the data. You will then be ready to run the remaining notebooks in the NISAR GCOV Cookbook.


5. Resources and references

References

Author: Alex Lewandowski