Skip to content

Commit

Permalink
Prevent other possible occurances of this bug
Browse files Browse the repository at this point in the history
  • Loading branch information
hugobuddel committed Jan 11, 2024
1 parent 719b534 commit a0fc8c9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
7 changes: 7 additions & 0 deletions scopesim/optics/fov.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
from copy import deepcopy
from itertools import chain
from collections.abc import Iterable

import numpy as np
from scipy.interpolate import interp1d
Expand Down Expand Up @@ -389,6 +390,10 @@ def make_image_hdu(self, use_photlam=False):

for flux, weight, x, y in self._make_image_tablefields(fluxes):
if utils.from_currsys(self.meta["sub_pixel"]):
# These x and y should not be arrays when sub_pixel is
# enabled, it is therefore not necessary to deploy the fix
# below in the else-branch.
assert not isinstance(x, Iterable), "x must be an integer"
canvas_image_hdu.data[y, x] += flux * weight
else:
# Mask out any stars that were pushed out of the fov by rounding
Expand Down Expand Up @@ -592,6 +597,8 @@ def make_cube_hdu(self):
start=canvas_cube_hdu.data)

for flux, x, y in self._make_cube_tablefields(specs):
# To prevent adding array values in this manner.
assert not isinstance(x, Iterable), "x should be integer"
canvas_cube_hdu.data[:, y, x] += flux

canvas_cube_hdu.data = sum(self._make_cube_backfields(specs),
Expand Down
5 changes: 5 additions & 0 deletions scopesim/optics/image_plane_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
from typing import Tuple
from itertools import product
from collections.abc import Iterable

import numpy as np
from astropy import units as u
Expand Down Expand Up @@ -328,6 +329,8 @@ def _add_intpixel_sources_to_canvas(canvas_hdu, xpix, ypix, flux, mask):
canvas_hdu.header["comment"] = f"Adding {len(flux)} int-pixel files"
for xpx, ypx, flx, msk in zip(xpix.astype(int), ypix.astype(int),
flux, mask):
# To prevent adding array values in this manner.
assert not isinstance(xpx, Iterable), "xpx should be integer"
canvas_hdu.data[ypx, xpx] += flx.value * msk

return canvas_hdu
Expand All @@ -341,6 +344,8 @@ def _add_subpixel_sources_to_canvas(canvas_hdu, xpix, ypix, flux, mask):
xx, yy, fracs = sub_pixel_fractions(xpx, ypx)
for x, y, frac in zip(xx, yy, fracs):
if y < canvas_shape[0] and x < canvas_shape[1]:
# To prevent adding array values in this manner.
assert not isinstance(x, Iterable), "x should be integer"
canvas_hdu.data[y, x] += frac * flx.value

return canvas_hdu
Expand Down
7 changes: 5 additions & 2 deletions scopesim/source/source_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from collections.abc import Iterable

import numpy as np
from astropy import wcs, units as u
Expand Down Expand Up @@ -146,8 +147,10 @@ def make_imagehdu_from_table(x, y, flux, pix_scale=1*u.arcsec):
yint, xint = ypix.astype(int), xpix.astype(int)

image = np.zeros((np.max(xint) + 1, np.max(yint) + 1))
for ii in range(len(xint)):
image[xint[ii], yint[ii]] += flux[ii]
for xi, yi, fluxi in zip(xint, yint, flux):
# To prevent adding array values in this manner.
assert not isinstance(xi, Iterable), "xi should be integer"
image[xi, yi] += fluxi

hdu = fits.ImageHDU(data=image)
hdu.header.extend(the_wcs.to_header())
Expand Down

0 comments on commit a0fc8c9

Please sign in to comment.