Skip to content

Possible lambda-cutoff bug in simple IFU mode #957

Description

@teutoburg

What happened?

While testing flux conservation across different source geometries, a weird inconsistency was discovered in the simple_ifu mode of the basic instrument (using that for testing simplicity), MVE below. Could not check if this also occurs in e.g. METIS lms_cube mode because not enough memory.

What appears to happen is that the first wavelength slice of the input cube gets cut in half.

Code to reproduce

import numpy as np
import astropy.units as u
from astropy.io import fits
from astropy.wcs import WCS

import scopesim as sim
from scopesim import Source
from scopesim.source.source_fields import CubeSourceField

nx = ny = 16
nlam = 5
scale = 0.2            # arcsec / pixel
waves = np.linspace(1.9, 2.3, nlam)   # um, well inside simple_ifu's 1.7-2.5

flux = np.ones(nlam)                  # spectrally flat -> planes should be equal
w = np.zeros((ny, nx))
w[5:11, 5:11] = 1.0                   # uniform spatial block
data = (w[None, :, :] * flux[:, None, None]) / scale**2   # PHOTLAM/arcsec2

wcs = WCS(naxis=3)
wcs.wcs.ctype = "RA---TAN", "DEC--TAN", "WAVE"
wcs.wcs.cunit = "arcsec", "arcsec", "um"
wcs.wcs.crpix = (nx + 1) / 2, (ny + 1) / 2, 1.0
wcs.wcs.crval = 0.0, 0.0, waves[0]
wcs.wcs.cdelt = scale, scale, waves[1] - waves[0]
hdr = wcs.to_header()
hdr["NAXIS1"], hdr["NAXIS2"], hdr["NAXIS3"] = nx, ny, nlam
# Explicit FITS spelling of PHOTLAM/arcsec2
hdr["BUNIT"] = "ph Angstrom-1 s-1 cm-2 arcsec-2"

src = Source(field=CubeSourceField(field=fits.ImageHDU(header=hdr, data=data)))

# Simple OpticalTrain without atmosphere or PSF
opt = sim.load_example_optical_train(set_modes=["simple_ifu"])
opt["psf"].include = False
opt["atmospheric_radiometry"].include = False
opt.observe(src, update=True)

cube_out = opt.image_planes[0].data
per_plane = cube_out.sum(axis=(1, 2))

print(f"output cube shape : {cube_out.shape}")
print(f"flux per plane    : {per_plane.round(-2)}")
print(f"plane / last plane: {per_plane / per_plane[-1]}")

Exception traceback

ScopeSim bug_report()

IRDB installation

Cloned and linked IRDB repository

Use case

Other

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    Status
    📋 Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions