Skip to content

Commit

Permalink
Add dual-mirror case
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnoe committed Jun 10, 2019
1 parent 1b8ca1d commit c38dca0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
30 changes: 26 additions & 4 deletions ctapipe/coordinates/camera_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
BaseCoordinateFrame,
CoordinateAttribute,
QuantityAttribute,
Attribute,
TimeAttribute,
EarthLocationAttribute,
FunctionTransform,
Expand All @@ -18,13 +19,28 @@
from .representation import PlanarRepresentation


class MirrorAttribute(Attribute):
def convert_input(self, value):
if value in (1, 2):
return value, False

raise ValueError('Only 1 or 2 mirrors supported')


# Go from SimTel / HESS to MAGIC/FACT/Engineering frame and back
ENGINEERING_FRAME_TRANSFORM_MATRIX = np.array([
CAMERA_TO_ENGINEERING_1M_MATRIX = np.array([
[0, -1, 0],
[-1, 0, 0],
[0, 0, 1]
])
ENGINEERING_FRAME_TRANSFORM_OFFSET = CartesianRepresentation(0, 0, 0, unit=u.m)
ENGINEERING_1M_TO_CAMERA_MATRIX = CAMERA_TO_ENGINEERING_1M_MATRIX
CAMERA_TO_ENGINEERING_2M_MATRIX = np.array([
[0, 1, 0],
[-1, 0, 0],
[0, 0, 1]
])
ENGINEERING_2M_TO_CAMERA_MATRIX = CAMERA_TO_ENGINEERING_1M_MATRIX.T
ZERO_OFFSET = CartesianRepresentation(0, 0, 0, unit=u.m)


class CameraFrame(BaseCoordinateFrame):
Expand Down Expand Up @@ -94,6 +110,7 @@ class EngineeringCameraFrame(CameraFrame):
location : EarthLocation
location of the telescope
'''
n_mirrors = MirrorAttribute(default=1)


@frame_transform_graph.transform(FunctionTransform, CameraFrame, TelescopeFrame)
Expand Down Expand Up @@ -174,9 +191,14 @@ def telescope_to_camera(telescope_coord, camera_frame):

@frame_transform_graph.transform(AffineTransform, CameraFrame, EngineeringCameraFrame)
def camera_to_engineering(from_coord, to_frame):
return ENGINEERING_FRAME_TRANSFORM_MATRIX, ENGINEERING_FRAME_TRANSFORM_OFFSET
if to_frame.n_mirrors == 1:
return CAMERA_TO_ENGINEERING_1M_MATRIX, ZERO_OFFSET

return CAMERA_TO_ENGINEERING_2M_MATRIX, ZERO_OFFSET


@frame_transform_graph.transform(AffineTransform, EngineeringCameraFrame, CameraFrame)
def engineering_to_camera(from_coord, to_frame):
return ENGINEERING_FRAME_TRANSFORM_MATRIX, ENGINEERING_FRAME_TRANSFORM_OFFSET
if from_coord.n_mirrors == 2:
return ENGINEERING_1M_TO_CAMERA_MATRIX, ZERO_OFFSET
return ENGINEERING_2M_TO_CAMERA_MATRIX, ZERO_OFFSET
10 changes: 10 additions & 0 deletions ctapipe/coordinates/tests/test_engineering_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,13 @@ def test_conversion():
back = eng_coord.transform_to(CameraFrame())
assert back.x == coord.x
assert back.y == coord.y


eng_coord = coord.transform_to(EngineeringCameraFrame(n_mirrors=2))

assert eng_coord.x == coord.y
assert eng_coord.y == -coord.x

back = eng_coord.transform_to(CameraFrame())
assert back.x == coord.x
assert back.y == coord.y

0 comments on commit c38dca0

Please sign in to comment.