Skip to content

Commit

Permalink
Fix detectorwindow (#507)
Browse files Browse the repository at this point in the history
  • Loading branch information
teutoburg authored Dec 5, 2024
2 parents 2d42d74 + ebd354c commit a43ac16
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
40 changes: 22 additions & 18 deletions scopesim/effects/detector_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,24 +198,28 @@ def image_plane_header(self):
# FIXME: Heavy property.....
tbl = self.active_table
pixel_size = np.min(quantity_from_table("pixel_size", tbl, u.mm))
x_unit = unit_from_table("x_size", tbl, u.mm)
y_unit = unit_from_table("y_size", tbl, u.mm)

xcen = tbl["x_cen"].data.astype(float)
ycen = tbl["y_cen"].data.astype(float)
dx = 0.5 * tbl["x_size"].data.astype(float)
dy = 0.5 * tbl["y_size"].data.astype(float)

scale_unit = 1 # either unitless to retain
if "pix" in x_unit.name:
scale_unit = u.mm / u.pix
dx *= pixel_size.value
dy *= pixel_size.value

x_det_min = np.min(xcen - dx) * x_unit * scale_unit
x_det_max = np.max(xcen + dx) * x_unit * scale_unit
y_det_min = np.min(ycen - dy) * y_unit * scale_unit
y_det_max = np.max(ycen + dy) * y_unit * scale_unit
x_size_unit = unit_from_table("x_size", tbl, u.mm)
y_size_unit = unit_from_table("y_size", tbl, u.mm)
# This is mm everywhere in the IRDB, but could be something else...
x_cen_unit = unit_from_table("x_cen", tbl, u.mm)
y_cen_unit = unit_from_table("y_cen", tbl, u.mm)

xcen = tbl["x_cen"].data.astype(float) * x_cen_unit
ycen = tbl["y_cen"].data.astype(float) * y_cen_unit
dx = 0.5 * tbl["x_size"].data.astype(float) * x_size_unit
dy = 0.5 * tbl["y_size"].data.astype(float) * y_size_unit

pixel_scale = u.pixel_scale(pixel_size / u.pixel)
with u.set_enabled_equivalencies(pixel_scale):
xcen <<= u.mm
ycen <<= u.mm
dx <<= u.mm
dy <<= u.mm

x_det_min = np.min(xcen - dx)
x_det_max = np.max(xcen + dx)
y_det_min = np.min(ycen - dy)
y_det_max = np.max(ycen + dy)

x_det = [x_det_min.to(u.mm).value, x_det_max.to(u.mm).value]
y_det = [y_det_min.to(u.mm).value, y_det_max.to(u.mm).value]
Expand Down
7 changes: 3 additions & 4 deletions scopesim/tests/tests_effects/test_DetectorList.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def test_happy_using_x_size_unit_in_mm(self):
"id": [0, 1],
"x_cen": [-0.2, 0.2], # mm
"y_cen": [0, 0],
"x_size": [0.32, 0.32], # pixel
"x_size": [0.32, 0.32], # mm
"y_size": [0.32, 0.32],
"pixsize": [0.01, 0.01], # mm/pixel
"angle": [0, 0],
Expand Down Expand Up @@ -132,13 +132,12 @@ def test_happy_using_x_size_unit_in_pixels(self):
assert hdr["NAXIS1"] == 32
assert hdr["NAXIS2"] == 32

# FIXME: why is this defined twice???
def test_happy_using_x_size_unit_in_pixels(self):
def test_happy_using_x_size_unit_in_mm(self):
det_list = DetectorList(array_dict={
"id": [0, 1],
"x_cen": [-0.2, 0.2], # mm
"y_cen": [0, 0],
"x_size": [0.32, 0.32], # pixel
"x_size": [0.32, 0.32], # mm
"y_size": [0.32, 0.32],
"pixsize": [0.01, 0.01], # mm/pixel
"angle": [0, 0],
Expand Down

0 comments on commit a43ac16

Please sign in to comment.