Image size: 1.2 GB

For more on pulling from the registry, see the ilifu documentation.

First, once: add the registry and make it your default

singularity remote add --no-login idia-registry https://sregistry.idia.ac.za
singularity remote use idia-registry

If you added it before, as the ilifu docs describe, remote add says it already exists: just run remote use.

Log in, for a private collection

singularity remote login idia-registry

Paste a token from your token page when asked. Public collections need no login.

Pull the container

singularity pull library://casa/casa-modular:v6.7.2-py3.12-2025-11-14

Shell into the container

singularity shell library://casa/casa-modular:v6.7.2-py3.12-2025-11-14

Run the container

singularity run library://casa/casa-modular:v6.7.2-py3.12-2025-11-14

First, once: add the registry and make it your default

apptainer remote add --no-login idia-registry https://sregistry.idia.ac.za
apptainer remote use idia-registry

If you added it before, as the ilifu docs describe, remote add says it already exists: just run remote use.

Log in, for a private collection

apptainer remote login idia-registry

Paste a token from your token page when asked. Public collections need no login.

Pull the container

apptainer pull library://casa/casa-modular:v6.7.2-py3.12-2025-11-14

Shell into the container

apptainer shell library://casa/casa-modular:v6.7.2-py3.12-2025-11-14

Run the container

apptainer run library://casa/casa-modular:v6.7.2-py3.12-2025-11-14
Bootstrap: debootstrap
MirrorURL: http://archive.ubuntu.com/ubuntu/
OSVersion: noble

%labels
    APPLICATION_NAME Ubuntu LTS + CASA 6 (Modular) v6.7.2
    OS_VERSION 24.04
    APPLICATION_URL https://casadocs.readthedocs.io/en/stable/notebooks/introduction.html#Modular-Packages

    SYSTEM_NAME ilifu
    SYSTEM_SINGULARITY_VERSION 4.1.3
    SYSTEM_URL http://www.ilifu.ac.za

    AUTHOR_NAME IDIA
    AUTHOR_EMAIL support@ilifu.ac.za

%environment
    export PYTHONPATH=$PYTHONPATH:/opt/casaaddons
    export XDG_RUNTIME_DIR=$HOME 
    export LD_LIBRARY_PATH=/usr/local/lib:/usr/lib/x86_64-linux-gnu
    
    export PATH=$PATH:/opt/casaplotms/usr/bin
    export PATH=$PATH:/opt/casaviewer/usr/bin
    export PATH=$PATH:/opt/casatablebrowser/usr/bin
    export PATH=$PATH:/opt/casalogger/usr/bin
    export PATH=$PATH:/opt/casafeather/usr/bin
    export PATH=$PATH:~/.local/bin
    
    export CASARCFILES=/opt/.casarc

%post
    # Exit immediately if a command exits with a non-zero status.
    set -e 

    # System Setup
    mkdir -p /opt
    export DEBIAN_FRONTEND=noninteractive
    
    # STEP 1: Initial Update and Install Repo Management Tools
    apt-get update -y
    apt-get install -y --no-install-recommends software-properties-common apt-transport-https ca-certificates gnupg lsb-release

    # STEP 2: Enable Ubuntu repositories
    add-apt-repository universe || true
    add-apt-repository -y multiverse || true
    add-apt-repository -y restricted || true
    
    # The problematic KERN PPA line has been REMOVED.

    # STEP 3: Update package lists again after adding repositories
    apt-get update -y

    # STEP 4: Install Core Build/Runtime Dependencies
    apt-get install -y --no-install-recommends \
        wget vim apt-utils git build-essential bzip2 libpng-dev gfortran xvfb ghostscript \
        curl pkg-config libxi-dev libfuse-dev python-is-python3 python3-pip python3-venv \
        python3-dev fuse perl libopenmpi-dev

    # Install CASA/PlotMS dependencies
    # This step installs casacore-dev and casacore-data, which brings in python3-casacore and python3-numpy
    apt-get install -y --no-install-recommends libc-ares-dev libgoogle-perftools-dev libgrpc-dev libgrpc++1
    apt-get install -y --no-install-recommends casacore-dev casacore-data || true

    # libgrpc fallback symlink
    ln -sf /usr/lib/x86_64-linux-gnu/libgrpc++.so.1 /usr/lib/x86_64-linux-gnu/libgrpc.so.7 || true

    # Python Package Installation (All using --break-system-packages)
    
    # FIX: Install core packages with --no-deps to prevent pip from trying to uninstall the system's NumPy.
    python -m pip install --no-cache-dir \
        cloudpickle holoviews datashader bokeh pandas "dask-ms[xarray]" protobuf==3.20 scikit-image matplotlib katdal astroquery DateTime \
        --break-system-packages --no-deps

    # Install NumPy and Scipy explicitly (without --no-deps, but allowing system NumPy to be used)
    # We must explicitly use --upgrade here to ensure newer versions are installed if possible/needed, or at least confirmed.
    python -m pip install --no-cache-dir --upgrade numpy scipy==1.13.0 --break-system-packages || true
    
    # Install python-casacore from source (needed the python headers/compiler, now available)
    python -m pip install --no-cache-dir --no-binary :all: python-casacore --break-system-packages || true

    # Notebooks and Virtual Display
    python -m pip install --no-cache-dir pyvirtualdisplay jupyter ipykernel --break-system-packages

    # PyBDSF/Qt Dependencies
    apt-get install -y --no-install-recommends libboost-python-dev libboost-numpy-dev python-setuptools \
        qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools || true
    python -m pip install --no-cache-dir PyQt5==5.15.7 --break-system-packages || true
    python -m pip install --no-cache-dir astropy --break-system-packages || true
    python -m pip install --no-cache-dir "bdsf[ishell]" --break-system-packages || true

    # Other Astronomy Packages
    # Healpy / PYGDSM
    apt-get install -y --no-install-recommends python3-healpy || true
    python -m pip install --no-cache-dir h5py --break-system-packages
    python -m pip install --no-cache-dir git+https://github.com/telegraphic/pygdsm --break-system-packages || true
    python -m pip install --no-cache-dir git+https://github.com/ska-sa/katbeam --break-system-packages || true

    # CASA Modular Packages
    CASA_INDEX_URL="https://pypi.nrao.edu/repository/pypi-casa/simple"

    python -m pip install --index-url "$CASA_INDEX_URL" --no-cache-dir \
        casaconfig==1.4.0 \
        casatools==6.7.2.42 \
        casatasks==6.7.2.42 \
        casashell==6.7.2.42 \
        casatestutils==6.7.2.42 \
        casampi==0.5.9 \
        casaplotms==2.7.4 \
        casaviewer==2.4.4 \
        casaplotserver==2.0.3 \
        casatablebrowser==0.0.39 \
        casalogger==1.0.23 \
        casafeather==0.0.27 --break-system-packages || true

    # casadata from public PyPI
    python -m pip install --no-cache-dir casadata==2024.8.26 --break-system-packages || true

    # Clean reinstall for matplotlib
    python -m pip uninstall -y matplotlib --break-system-packages || true
    python -m pip install --no-cache-dir matplotlib --break-system-packages

    # Optional: casaaddons (may require network access to NRAO bitbucket)
    cd /opt
    git clone https://open-bitbucket.nrao.edu/scm/casa/casaaddons.git || true

    # AppImage Extraction and Patching
    cd /opt || true

    # CASApLotMS AppImage
    if [ -f /usr/local/lib/python3.12/dist-packages/casaplotms/__bin__/casaplotms-x86_64.AppImage ]; then
        /usr/local/lib/python3.12/dist-packages/casaplotms/__bin__/casaplotms-x86_64.AppImage --appimage-extract || true
        [ -d squashfs-root ] && mv -T squashfs-root /opt/casaplotms || true
        chmod -R go+rx /opt/casaplotms || true
        sed -i -E "s|app_path = .*casaplotms-x86_64.AppImage.*|app_path = '/opt/casaplotms/usr/bin/casaplotms'|g" /usr/local/lib/python3.12/dist-packages/casaplotms/private/plotmstool.py || true
    fi

    # CASAviewer
    if [ -f /usr/local/lib/python3.12/dist-packages/casaviewer/__bin__/casaviewer-x86_64.AppImage ]; then
        /usr/local/lib/python3.12/dist-packages/casaviewer/__bin__/casaviewer-x86_64.AppImage --appimage-extract || true
        [ -d squashfs-root ] && mv -T squashfs-root /opt/casaviewer || true
        chmod -R go+rx /opt/casaviewer || true
        sed -i -E "s|app_path = .*casaviewer-x86_64.AppImage.*|app_path = '/opt/casaviewer/usr/bin/casaviewer'|g" /usr/local/lib/python3.12/dist-packages/casaviewer/private/config.py || true
    fi

    # CASAtablebrowser
    if [ -f /usr/local/lib/python3.12/dist-packages/casatablebrowser/__bin__/casatablebrowser-x86_64.AppImage ]; then
        /usr/local/lib/python3.12/dist-packages/casatablebrowser/__bin__/casatablebrowser-x86_64.AppImage --appimage-extract || true
        [ -d squashfs-root ] && mv -T squashfs-root /opt/casatablebrowser || true
        chmod -R go+rx /opt/casatablebrowser || true
        sed -i -E "s|app_path = __os.path.abspath__\(.*|app_path = '/opt/casatablebrowser/usr/bin'|g" /usr/local/lib/python3.12/dist-packages/casatablebrowser/__casatablebrowser.py || true
        sed -i -E "s|app_path = .*__bin__.*casatablebrowser-x86_64.AppImage.*|app_path = __os.path.join( app_path, \"casatablebrowser\" )|g" /usr/local/lib/python3.12/dist-packages/casatablebrowser/__casatablebrowser.py || true
    fi

    # CASAlogger
    if [ -f /usr/local/lib/python3.12/dist-packages/casalogger/__bin__/casalogger-x86_64.AppImage ]; then
        /usr/local/lib/python3.12/dist-packages/casalogger/__bin__/casalogger-x86_64.AppImage --appimage-extract || true
        [ -d squashfs-root ] && mv -T squashfs-root /opt/casalogger || true
        chmod -R go+rx /opt/casalogger || true
        sed -i -E "s|^app_path = .*|app_path = '/opt/casalogger/usr/bin/casalogger'|g" /usr/local/lib/python3.12/dist-packages/casalogger/casalogger.py || true
        sed -i '31,33d' /usr/local/lib/python3.12/dist-packages/casalogger/casalogger.py || true
    fi

    # CASAfeather
    if [ -f /usr/local/lib/python3.12/dist-packages/casafeather/__bin__/casafeather-x86_64.AppImage ]; then
        /usr/local/lib/python3.12/dist-packages/casafeather/__bin__/casafeather-x86_64.AppImage --appimage-extract || true
        [ -d squashfs-root ] && mv -T squashfs-root /opt/casafeather || true
        chmod -R go+rx /opt/casafeather || true
        sed -i -E "s|^app_path = .*|app_path = '/opt/casafeather/usr/bin/casafeather'|g" /usr/local/lib/python3.12/dist-packages/casafeather/casafeather.py || true
        sed -i '52,54d' /usr/local/lib/python3.12/dist-packages/casafeather/casafeather.py || true
    fi

    # Final Configuration and Cleanup
    # Fix path to casacore data, used by the CASA tools
    echo 'measures.directory: /usr/share/casacore/data' > /opt/.casarc

    # Ensure singularity env dir exists and set PS1 (prompt)
    mkdir -p /.singularity.d/env || true
    printf 'export PS1="\\u@$SINGULARITY_NAME:\\w$ "' > /.singularity.d/env/999-psvars.sh || true

    # Final cleanup to reduce image size
    apt-get clean || true
    apt-get autoclean -y || true
    rm -rf /var/lib/apt/lists/* || true
    rm -rf /opt/squashfs-root || true 

%runscript
    # Run CASA python by default; allows passing arguments directly to the Python interpreter
    exec python "$@"
Download casa-casa-modular_v6.7.2-py3.12-2025-11-14.def
#!/bin/sh

    # Run CASA python by default; allows passing arguments directly to the Python interpreter
    exec python "$@"
# /.singularity.d/env/90-environment.sh
#!/bin/sh
# Custom environment shell code should follow


    export PYTHONPATH=$PYTHONPATH:/opt/casaaddons
    export XDG_RUNTIME_DIR=$HOME 
    export LD_LIBRARY_PATH=/usr/local/lib:/usr/lib/x86_64-linux-gnu
    
    export PATH=$PATH:/opt/casaplotms/usr/bin
    export PATH=$PATH:/opt/casaviewer/usr/bin
    export PATH=$PATH:/opt/casatablebrowser/usr/bin
    export PATH=$PATH:/opt/casalogger/usr/bin
    export PATH=$PATH:/opt/casafeather/usr/bin
    export PATH=$PATH:~/.local/bin
    
    export CASARCFILES=/opt/.casarc