desihub / specter

A toolkit for simulating multi-object spectrographs
Other
8 stars 7 forks source link

high priority: ex2d crash #41

Open sbailey opened 7 years ago

sbailey commented 7 years ago

The following code crashes ex2d with a dimension mismatch, apparently due to the attempt to add regularization on ill-constrained flux bins to keep the solution from being singular:

import specter.extract
import desimodel.io
import numpy as np

#- Inputs
psf = desimodel.io.load_psf('r')
nspec = 2
wmin, wmax, dw = 6000, 6030, 0.5
ww = np.arange(wmin, wmax, dw)
nwave = len(ww)
photons = np.zeros((nspec, nwave))
photons[0,::20] = 100
photons[1,5::30] = 200

xyrange = psf.xyrange([0,nspec], ww)
truepix = psf.project(ww, photons, xyrange=xyrange)

rdnoise = 2
image = np.random.poisson(truepix) + np.random.normal(scale=rdnoise, size=truepix.shape)
ivar = 1.0/(truepix + rdnoise**2)

#- unmasked cosmic
cosmic_image = image.copy()
cosmic_image[20,8] = 40
cosmic_image[21,7] = 40

#- Perform extractions of each image with lower extraction resolution
ww = np.arange(wmin, wmax, 1.3*dw)
exa = specter.extract.ex2d(image, ivar, psf, 0, nspec, ww, xyrange=xyrange, full_output=True)

For context, the original purpose of this code was to extract on a different wavelength grid than the input simulation to study systematics from the discrete wavelength sampling.

To do: