desihub / desisim

DESI simulations
BSD 3-Clause "New" or "Revised" License
16 stars 22 forks source link

TestPixsim negative flux failure #547

Closed sbailey closed 3 years ago

sbailey commented 3 years ago

Test failure:

======================================================================
ERROR: test_main_defaults (desisim.test.test_pixsim.TestPixsim)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/global/common/software/desi/cori/desiconda/20200801-1.4.0-spec/code/desisim/master/py/desisim/test/test_pixsim.py", line 199, in test_main_defaults
    desisim.scripts.pixsim.main(pixsimargs)
  File "/global/common/software/desi/cori/desiconda/20200801-1.4.0-spec/code/desisim/master/py/desisim/scripts/pixsim.py", line 124, in main
    simulate_exposure(args.simspec, args.rawfile, cameras=args.cameras,
  File "/global/common/software/desi/cori/desiconda/20200801-1.4.0-spec/code/desisim/master/py/desisim/pixsim.py", line 158, in simulate_exposure
    image, rawpix, truepix = simulate(camera, simspec, psf, comm=comm_node, preproc=False, cosmics=cosmics, **kwargs)
  File "/global/common/software/desi/cori/desiconda/20200801-1.4.0-spec/code/desisim/master/py/desisim/pixsim.py", line 331, in simulate
    photpix2raw(pix[0:ny, 0:nx], gain, rdnoiseA,
  File "/global/common/software/desi/cori/desiconda/20200801-1.4.0-spec/code/desisim/master/py/desisim/pixsim.py", line 516, in photpix2raw
    img = np.random.poisson(img) + noise
  File "mtrand.pyx", line 3569, in numpy.random.mtrand.RandomState.poisson
  File "_common.pyx", line 824, in numpy.random._common.disc
  File "_common.pyx", line 621, in numpy.random._common.discrete_broadcast_d
  File "_common.pyx", line 357, in numpy.random._common.check_array_constraint
ValueError: lam < 0 or lam contains NaNs

I'm pretty sure this was caused by specter commit #6a0d107 which now allows PSF projection of negative flux, which was needed for proper normalization when projecting ringing deconvolved real data spectra for studying the 2D model. i.e. now it is the responsibility of the input spectrum to not include negatives if they aren't supposed to be there. I haven't tracked why desisim has negative flux resulting in negative pixels resulting in failing poisson (or if that is actually what is happening).