Skip to content

Commit

Permalink
Merge pull request #2207 from cta-observatory/provision-with-micromamba
Browse files Browse the repository at this point in the history
Change actions for mamba / pip install methods.
  • Loading branch information
maxnoe authored Jan 13, 2023
2 parents 8467f9f + ff94eed commit 3cebb42
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 40 deletions.
59 changes: 27 additions & 32 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,33 @@ jobs:
include:
- os: ubuntu-latest
python-version: "3.8"
install-method: conda
install-method: mamba

- os: ubuntu-latest
python-version: "3.9"
install-method: conda
install-method: mamba

- os: ubuntu-latest
python-version: "3.10"
install-method: conda
codecov: true
install-method: mamba
extra-args: ['codecov']

- os: ubuntu-latest
python-version: "3.10"
install-method: pip

- os: macos-latest
python-version: "3.10"
install-method: conda
install-method: mamba

- os: macos-latest
python-version: "3.8"
install-method: pip

defaults:
run:
shell: bash -l {0}
# We need login shells (-l) for micromamba to work.
shell: bash -leo pipefail {0}

steps:
- uses: actions/checkout@v3
Expand All @@ -60,36 +61,34 @@ jobs:
path: ~/.cache/ctapipe
key: ctapipe-test-data

- name: Prepare conda installation
if: matrix.install-method == 'conda'
- name: Prepare mamba installation
if: matrix.install-method == 'mamba'
env:
PYTHON_VERSION: ${{ matrix.python-version }}
run: |
# fix mamba error that the directory does not exist
mkdir -p ~/conda_pkgs_dir/cache
# setup correct python version
sed -i -e "s/- python=.*/- python=$PYTHON_VERSION/g" environment.yml
- name: Conda setup
if: matrix.install-method == 'conda'
uses: conda-incubator/setup-miniconda@v2
with:
mamba-version: "*"
auto-update-conda: true
activate-environment: "cta-dev"
environment-file: environment.yml
- name: mamba setup
if: matrix.install-method == 'mamba'
uses: mamba-org/provision-with-micromamba@v14

- name: Python setup
if: matrix.install-method == 'pip'
uses: conda-incubator/setup-miniconda@v2
uses: actions/setup-python@v4
with:
mamba-version: "*"
channels: conda-forge,default
python-version: ${{ matrix.python-version }}

- name: Update pip
if: matrix.install-method == 'pip'
run: pip install -U pip
check-latest: true

- if: ${{ matrix.install-method == 'pip' && runner.os == 'macOS' }}
name: Fix Python PATH on macOS
# See https://github.com/actions/setup-python/issues/132 and
# https://github.com/actions/setup-python/issues/132#issuecomment-779406058
# Login shells on macOS prepend system paths, so we need to
# prepend the python path from actions/setup-python.
# Micromamba sets up ~/.bash_profile, where we need to set the path now.
run: |
tee -a ~/.bash_profile <<<'export PATH="$pythonLocation/bin:$PATH"'
- name: Install dependencies
run: |
Expand All @@ -99,14 +98,10 @@ jobs:
pip freeze
- name: Static codechecks
# need to use a login shell for the conda setup to work
shell: bash -leo pipefail {0}
run: |
flake8 ctapipe
- name: Tests
# need to use a login shell for the conda setup to work
shell: bash -leo pipefail {0}
run: |
cd $(mktemp -d)
pytest -n auto --dist loadscope \
Expand All @@ -117,8 +112,8 @@ jobs:
ctapipe-info --version
- uses: codecov/codecov-action@v2
if: matrix.codecov
- uses: codecov/codecov-action@v3
if: contains(matrix.extra-args, 'codecov')

docs:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -147,7 +142,7 @@ jobs:
- name: Build docs
run: make doc

- name: Deploy to gihub pages
- name: Deploy to github pages
# only run on push to master
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
uses: JamesIves/github-pages-deploy-action@3.7.1
Expand Down
58 changes: 50 additions & 8 deletions ctapipe/visualization/tests/test_mpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pytest
from astropy import units as u
from astropy.coordinates import AltAz, SkyCoord
from matplotlib import __version__ as mpl_version

from ctapipe.calib.camera.calibrator import CameraCalibrator
from ctapipe.containers import (
Expand All @@ -25,12 +26,47 @@ def prod5_lst_cam(prod5_lst):
return prod5_lst.camera.geometry


def test_camera_display_single(prod5_lst_cam):
@pytest.mark.skipif(
mpl_version != "3.6.3",
reason="See test below (test_camera_display_single)",
)
def test_norm_after_colorbar(prod5_lst_cam, tmp_path):
"""With matplotlib==3.6.3 we can not change the norm
parameter of a CameraDisplay after we attached a colorbar."""
from ..mpl_camera import CameraDisplay

image = np.ones(prod5_lst_cam.pix_x.shape)

fig, ax = plt.subplots()
disp = CameraDisplay(prod5_lst_cam, ax=ax)
disp.image = image
disp.norm = "log"
disp.add_colorbar()

fig, ax = plt.subplots()
disp = CameraDisplay(prod5_lst_cam, ax=ax)
disp.image = image
disp.add_colorbar()
with pytest.raises(ValueError):
disp.norm = "log"


@pytest.mark.skipif(
mpl_version == "3.6.3",
reason=(
"There is a problem in changing the norm after adding a colorbar. "
+ "This issue came up in #2207 and "
+ "should be fixed in a separate PR."
+ "See the test above (test_norm_after_colorbar)."
),
)
def test_camera_display_single(prod5_lst_cam, tmp_path):
"""test CameraDisplay functionality"""
from ..mpl_camera import CameraDisplay

fig, ax = plt.subplots()
geom = prod5_lst_cam
disp = CameraDisplay(geom)
disp = CameraDisplay(geom, ax=ax)
image = np.random.normal(size=len(geom.pix_x))
disp.image = image
disp.add_colorbar()
Expand All @@ -51,36 +87,41 @@ def test_camera_display_single(prod5_lst_cam):

disp.add_ellipse(centroid=(0, 0), width=0.1, length=0.1, angle=0.1)
disp.clear_overlays()
fig.savefig(tmp_path / "result.png")


def test_hillas_overlay(prod5_lst_cam):
def test_hillas_overlay(prod5_lst_cam, tmp_path):
from ctapipe.visualization import CameraDisplay

disp = CameraDisplay(prod5_lst_cam)
fig, ax = plt.subplots()
disp = CameraDisplay(prod5_lst_cam, ax=ax)
hillas = CameraHillasParametersContainer(
x=0.1 * u.m, y=-0.1 * u.m, length=0.5 * u.m, width=0.2 * u.m, psi=90 * u.deg
)

disp.overlay_moments(hillas)
disp.overlay_moments(hillas, color="w")
fig.savefig(tmp_path / "result.png")


@pytest.mark.parametrize("pix_type", PixelShape.__members__.values())
def test_pixel_shapes(pix_type, prod5_lst_cam):
def test_pixel_shapes(pix_type, prod5_lst_cam, tmp_path):
"""test CameraDisplay functionality"""
from ..mpl_camera import CameraDisplay

geom = prod5_lst_cam
geom.pix_type = pix_type

disp = CameraDisplay(geom)
fig, ax = plt.subplots()
disp = CameraDisplay(geom, ax=ax)
image = np.random.normal(size=len(geom.pix_x))
disp.image = image
disp.add_colorbar()
disp.highlight_pixels([1, 2, 3, 4, 5])
disp.add_ellipse(centroid=(0, 0), width=0.1, length=0.1, angle=0.1)
fig.savefig(tmp_path / "result.png")


def test_camera_display_multiple(prod5_lst_cam):
def test_camera_display_multiple(prod5_lst_cam, tmp_path):
"""create a figure with 2 subplots, each with a CameraDisplay"""
from ..mpl_camera import CameraDisplay

Expand All @@ -93,6 +134,7 @@ def test_camera_display_multiple(prod5_lst_cam):
image = np.ones(len(geom.pix_x), dtype=float)
d1.image = image
d2.image = image
fig.savefig(tmp_path / "result.png")


def test_array_display(prod5_mst_nectarcam):
Expand Down

0 comments on commit 3cebb42

Please sign in to comment.