79140943

Date: 2024-10-30 11:45:28
Score: 1
Natty:
Report link

I can make a 2D array with all pixel_to_world coordinates in (RA, DEC), and I can make a mask on that array, then I use the mask on the original data cube.

y_height = data[0].shape[0]
x_width = data[0].shape[1]

x_indices, y_indices = np.meshgrid(np.arange(x_width), np.arange(y_height))

# Convert pixel indices to world coordinates
world_coords = wcsc.pixel_to_world(x_indices, y_indices)

# Extract the DEC values and store them in the coord_array
coord_array_dec = world_coords.icrs.dec.value
coord_array_l = world_coords.galactic.l.value
coord_array_b = world_coords.galactic.b.value
import numpy.ma as ma

mask_dec = ma.masked_greater(coord_array_dec, -13).mask
mask_l1 = ma.masked_greater(coord_array_l, 229).mask
mask_l2 = ma.masked_less(coord_array_l, 234).mask
mask_b1 = ma.masked_greater(coord_array_b, 4).mask
mask_b2 = ma.masked_less(coord_array_b, 14).mask
mask = mask_dec * mask_l1 * mask_l2 * mask_b1 * mask_b2
masked_data = data * mask[np.newaxis, :, :]

enter image description here

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Firestar-Reimu