Skip to content

Commit

Permalink
Merge branch 'master' of github.com:cta-observatory/ctapipe into rect…
Browse files Browse the repository at this point in the history
…_converter
  • Loading branch information
LukasNickel committed Jun 2, 2021
2 parents 22bfc86 + 6d0051e commit da6f1df
Show file tree
Hide file tree
Showing 32 changed files with 508 additions and 559 deletions.
5 changes: 4 additions & 1 deletion .github/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ if [[ "$INSTALL_METHOD" == "conda" ]]; then
conda update -q conda # get latest conda version
# Useful for debugging any issues with conda
conda info -a
conda install -c conda-forge mamba

sed -i -e "s/- python=.*/- python=$PYTHON_VERSION/g" environment.yml
conda env create -n ci --file environment.yml
mamba env create -n ci --file environment.yml
conda activate ci
echo 'source $CONDA/etc/profile.d/conda.sh' >> ~/.bash_profile
echo 'conda activate ci' >> ~/.bash_profile
else
echo "Using pip"
pip install -U pip setuptools wheel
Expand Down
18 changes: 10 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,21 @@ jobs:
run: |
source .github/install.sh
python --version
pip install codecov pytest-cov
pip install codecov pytest-cov pyflakes pytest-xdist
pip install -e .[all]
pip freeze
- name: Static codechecks
# need to use a login shell for the conda setup to work
shell: bash -leo pipefail {0}
run: |
pyflakes ctapipe
- name: Tests
env:
INSTALL_METHOD: ${{ matrix.install-method }}
# need to use a login shell for the conda setup to work
shell: bash -leo pipefail {0}
run: |
if [[ "$INSTALL_METHOD" == "conda" ]]; then
source $CONDA/etc/profile.d/conda.sh
conda activate ci;
fi
pytest --cov --cov-report=xml
pytest --cov --cov-report=xml -n auto --dist loadscope
ctapipe-info --version
- uses: codecov/codecov-action@v1
Expand Down
27 changes: 21 additions & 6 deletions ctapipe/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,27 @@
from ctapipe.instrument import CameraGeometry


@pytest.fixture(scope="session")
def camera_geometries():
return [
CameraGeometry.from_name(name)
for name in ["LSTCam", "NectarCam", "CHEC", "FlashCam", "MAGICCam"]
]
# names of camera geometries available on the data server
camera_names = [
"ASTRICam",
"CHEC",
"DigiCam",
"FACT",
"FlashCam",
"HESS-I",
"HESS-II",
"LSTCam",
"MAGICCam",
"NectarCam",
"SCTCam",
"VERITAS",
"Whipple490",
]


@pytest.fixture(scope="session", params=camera_names)
def camera_geometry(request):
return CameraGeometry.from_name(request.param)


@pytest.fixture(scope="session")
Expand Down
2 changes: 1 addition & 1 deletion ctapipe/core/tests/test_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def test_extra_config_missing():
config["ExampleSubclass1"]["extra"] = 199.0

with pytest.raises(TraitError):
comp = ExampleSubclass1(config=config)
ExampleSubclass1(config=config)


def test_default():
Expand Down
4 changes: 2 additions & 2 deletions ctapipe/core/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import os
import re

from traitlets import default, TraitError
from traitlets import default
from traitlets.config import Application, Configurable

from .. import __version__ as version
Expand Down Expand Up @@ -286,7 +286,7 @@ def run(self, argv=None):

# check for any traitlets warnings using our custom handler
if len(self.trait_warning_handler.errors) > 0:
raise ToolConfigurationError(f"Found config errors")
raise ToolConfigurationError("Found config errors")

# remove handler to not impact performance with regex matching
self.log.removeHandler(self.trait_warning_handler)
Expand Down
1 change: 0 additions & 1 deletion ctapipe/image/tests/test_cleaning.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import numpy as np
from numpy.testing import assert_allclose
from ctapipe.image import cleaning
Expand Down
10 changes: 0 additions & 10 deletions ctapipe/image/tests/test_geometry_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@
import astropy.units as u


@pytest.fixture(params=["LSTCam", "CHEC", "FlashCam", "NectarCam", "MAGICCam", "FACT"])
def camera_geometry(request):
"""
Fixture to get one camera geometry at a time and perform tests with different geometries.
"""
return CameraGeometry.from_name(request.param)


def create_mock_image(geom):
"""
creates a mock image, which parameters are adapted to the camera size
Expand Down Expand Up @@ -86,5 +78,3 @@ def test_convert_geometry_mock(camera_geometry, rot):
# originally rectangular geometries don't need a buffer and therefore no mock
# conversion
return

assert_allclose(image, image1d)
1 change: 0 additions & 1 deletion ctapipe/instrument/camera/readout.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import numpy as np
from astropy import units as u
from astropy.table import Table
from scipy.stats import norm
from ctapipe.utils import get_table_dataset


Expand Down
12 changes: 2 additions & 10 deletions ctapipe/instrument/camera/tests/test_description.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
from ctapipe.instrument import CameraDescription


def test_known_camera_names(camera_geometries):
def test_known_camera_names(camera_geometry):
""" Check that we can get a list of known camera names """
cams = CameraDescription.get_known_camera_names()
assert len(cams) > 4
assert "FlashCam" in cams
assert "NectarCam" in cams

# TODO: Requires camreadout files to be generated
# for cam in cams:
# camera = CameraDescription.from_name(cam)
# camera.info()
assert camera_geometry.camera_name in CameraDescription.get_known_camera_names()
34 changes: 13 additions & 21 deletions ctapipe/instrument/camera/tests/test_geometry.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
""" Tests for CameraGeometry """
import numpy as np
from astropy import units as u
from ctapipe.instrument import CameraDescription, CameraGeometry, PixelShape
from ctapipe.instrument import CameraGeometry, PixelShape
import pytest

camera_names = CameraDescription.get_known_camera_names()


def test_construct():
""" Check we can make a CameraGeometry from scratch """
Expand Down Expand Up @@ -93,15 +91,13 @@ def test_find_neighbor_pixels():
assert set(neigh[11]) == {16, 6, 10, 12}


@pytest.mark.parametrize("camera_name", camera_names)
def test_neighbor_pixels(camera_name):
def test_neighbor_pixels(camera_geometry):
"""
test if each camera has a reasonable number of neighbor pixels (4 for
rectangular, and 6 for hexagonal. Other than edge pixels, the majority
should have the same value
"""

geom = CameraGeometry.from_name(camera_name)
geom = camera_geometry
n_pix = len(geom.pix_id)
n_neighbors = [len(x) for x in geom.neighbors]

Expand All @@ -116,7 +112,7 @@ def test_neighbor_pixels(camera_name):

# whipple has inhomogenious pixels that mess with pixel neighborhood
# calculation
if camera_name != "Whipple490":
if not geom.camera_name.startswith("Whipple"):
assert np.all(geom.neighbor_matrix == geom.neighbor_matrix.T)
assert n_neighbors.count(1) == 0 # no pixel should have a single neighbor

Expand Down Expand Up @@ -229,15 +225,13 @@ def test_slicing():
assert len(sliced2.pix_x) == 5


@pytest.mark.parametrize("camera_name", camera_names)
def test_slicing_rotation(camera_name):
def test_slicing_rotation(camera_geometry):
""" Check that we can rotate and slice """
cam = CameraGeometry.from_name(camera_name)
cam.rotate("25d")
camera_geometry.rotate("25d")

sliced1 = cam[5:10]
sliced1 = camera_geometry[5:10]

assert sliced1.pix_x[0] == cam.pix_x[5]
assert sliced1.pix_x[0] == camera_geometry.pix_x[5]


def test_rectangle_patch_neighbors():
Expand Down Expand Up @@ -296,19 +290,17 @@ def test_hashing():
assert len(set([cam1, cam2, cam3])) == 2


@pytest.mark.parametrize("camera_name", camera_names)
def test_camera_from_name(camera_name):
def test_camera_from_name(camera_geometry):
""" check we can construct all cameras from name"""
camera = CameraGeometry.from_name(camera_name)
assert str(camera) == camera_name
camera = CameraGeometry.from_name(camera_geometry.camera_name)
assert str(camera) == camera_geometry.camera_name


@pytest.mark.parametrize("camera_name", camera_names)
def test_camera_coordinate_transform(camera_name):
def test_camera_coordinate_transform(camera_geometry):
"""test conversion of the coordinates stored in a camera frame"""
from ctapipe.coordinates import EngineeringCameraFrame, CameraFrame, TelescopeFrame

geom = CameraGeometry.from_name(camera_name)
geom = camera_geometry
trans_geom = geom.transform_to(EngineeringCameraFrame())

unit = geom.pix_x.unit
Expand Down
15 changes: 6 additions & 9 deletions ctapipe/instrument/camera/tests/test_readout.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
""" Tests for CameraGeometry """
import numpy as np
from astropy import units as u
from ctapipe.instrument import CameraDescription, CameraReadout
from ctapipe.instrument import CameraReadout
import pytest

camera_names = CameraDescription.get_known_camera_names()


def test_construct():
""" Check we can make a CameraReadout from scratch """
Expand Down Expand Up @@ -142,14 +140,13 @@ def test_hashing():
assert len({readout1, readout2, readout3}) == 2


@pytest.mark.parametrize("camera_name", camera_names)
def test_camera_from_name(camera_name):
def test_camera_from_name(camera_geometry):
""" check we can construct all cameras from name"""

try:
camera = CameraReadout.from_name(camera_name)
assert str(camera) == camera_name
camera = CameraReadout.from_name(camera_geometry.camera_name)
assert str(camera) == camera_geometry.camera_name
except FileNotFoundError:
# these two don't have readout definitions on the dataserver
if camera_name not in ["MAGICCam", "Whipple109"]:
# Most non-cta cameras don't have readout provided on the data server
if camera_geometry.camera_name in ["LSTCam", "NectarCam", "FlashCam", "CHEC"]:
raise
1 change: 0 additions & 1 deletion ctapipe/instrument/subarray.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
Description of Arrays or Subarrays of telescopes
"""
from collections import defaultdict
from pathlib import Path

import numpy as np
Expand Down
12 changes: 4 additions & 8 deletions ctapipe/instrument/tests/test_telescope.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,13 @@ def test_hash():
assert len(set(telescopes)) == 3


OPTICS_NAMES = OpticsDescription.get_known_optics_names()
CAMERA_NAMES = CameraDescription.get_known_camera_names()


@pytest.mark.parametrize("camera_name", CAMERA_NAMES)
@pytest.mark.parametrize("optics_name", OPTICS_NAMES)
def test_telescope_from_name(optics_name, camera_name):
@pytest.mark.parametrize("optics_name", ["LST", "MST"])
def test_telescope_from_name(optics_name, camera_geometry):
""" Check we can construct all telescopes from their names """
camera_name = camera_geometry.camera_name
tel = TelescopeDescription.from_name(optics_name, camera_name)
assert optics_name in str(tel)
assert camera_name in str(tel)
assert tel.camera.geometry.pix_x.shape[0] > 0
assert tel.optics.equivalent_focal_length.to("m") > 0
assert tel.type in ["MST", "SST", "LST", "UNKNOWN"]
assert tel.type in {"MST", "SST", "LST", "UNKNOWN"}
2 changes: 1 addition & 1 deletion ctapipe/io/astropy_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from contextlib import ExitStack

__all__ = ["h5_table_to_astropy"]
__all__ = ["read_table"]


def read_table(h5file, path, start=None, stop=None, step=None) -> Table:
Expand Down
Loading

0 comments on commit da6f1df

Please sign in to comment.