Skip to content

Commit

Permalink
add 2d/3d plotting support to base
Browse files Browse the repository at this point in the history
  • Loading branch information
bloyl committed Jun 24, 2021
1 parent e3e9722 commit 0bfa5fc
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 5 deletions.
49 changes: 44 additions & 5 deletions base/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,40 @@
FROM continuumio/miniconda3:4.8.2
FROM ubuntu:20.04

ENV DEBIAN_FRONTEND=noninteractive

ARG MNE_USER="mne_user"
ARG HOME_DIR="/home/${MNE_USER}"
ENV MNE_USER=${MNE_USER}
ENV HOME_DIR=${HOME_DIR}

ARG CONDA_DIR="/opt/conda/"

# install xvfb
RUN apt-get update && \
apt-get install -y xvfb wget && \
apt-get install -y qt5-default && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# setup entry point
COPY prepare.sh /usr/bin/prepare.sh
RUN chmod a+x /usr/bin/prepare.sh

RUN chmod 777 /opt

# setup mne user
RUN useradd -ms /bin/bash -d ${HOME_DIR} ${MNE_USER}
USER $MNE_USER
WORKDIR $HOME_DIR

# setup conda
ENV PATH="${CONDA_DIR}/bin:${PATH}"
ARG PATH="${CONDA_DIR}/bin:${PATH}"
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \
sh ./Miniconda3-latest-Linux-x86_64.sh -b -p ${CONDA_DIR} && \
rm -f ./Miniconda3-latest-Linux-x86_64.sh && \
conda init
SHELL ["/bin/bash", "--login", "-c"]

RUN conda install --yes \
-c conda-forge \
Expand All @@ -19,11 +55,14 @@ RUN conda install --yes \
&& rm -rf /opt/conda/pkgs

RUN pip install s3fs
RUN pip install mne
RUN pip install bokeh
RUN pip install vtk pyvista pyvistaqt PyQt5 matplotlib nibabel joblib h5py mne

COPY prepare.sh /usr/bin/prepare.sh

RUN mkdir /opt/app
# setup environment for mne
# MNE_3D_OPTION_ANTIALIAS is needed to avoid blank screenshots.
# PYVISTA_OFF_SCREEN=true is *NOT* needed
ENV \
MNE_3D_BACKEND=pyvista \
MNE_3D_OPTION_ANTIALIAS=false

ENTRYPOINT ["tini", "-g", "--", "/usr/bin/prepare.sh"]
31 changes: 31 additions & 0 deletions base/examples/test_mne_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# modified from 70_report.py

import os
import matplotlib.pyplot as plt
import mne
import sys

path = mne.datasets.sample.data_path(verbose=True)

subjects_dir = os.path.join(path, 'subjects')
report = mne.Report(subject='sample', subjects_dir=subjects_dir,
raw_psd=True, projs=True, verbose=True)
report.parse_folder(path, render_bem=True)

fname_stc = os.path.join(path, 'MEG', 'sample', 'sample_audvis-meg')
stc = mne.read_source_estimate(fname_stc, subject='sample')
figs = list()
kwargs = dict(subjects_dir=subjects_dir, initial_time=0.13,
clim=dict(kind='value', lims=[3, 6, 9]))
for hemi in ('lh', 'rh'):
brain = stc.plot(hemi=hemi, **kwargs)
brain.toggle_interface(False)
figs.append(brain.screenshot(time_viewer=True))
brain.close()

# add the stc plot to the report:
report.add_slider_to_section(figs)

if len(sys.argv) >= 2:
report.save(sys.argv[1], overwrite=True, open_browser=False)

4 changes: 4 additions & 0 deletions base/prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,9 @@ if [ "$EXTRA_PIP_PACKAGES" ]; then
/opt/conda/bin/pip install $EXTRA_PIP_PACKAGES
fi

/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -screen 0 1400x900x24 -ac +extension GLX +render -noreset
sleep 3
export DISPLAY=:99

# Run extra commands
exec "$@"

0 comments on commit 0bfa5fc

Please sign in to comment.