mattyowl / RSSMOSPipeline

Pipeline for reducing both longslit and multi-object spectroscopic data from the Robert Stobie Spectrograph on SALT.
https://rssmospipeline.readthedocs.io
GNU General Public License v3.0
4 stars 2 forks source link

Pipeline ends with "ValueError: array must not contain infs or NaNs" #20

Closed svw26 closed 1 year ago

svw26 commented 1 year ago

Hiya Matt,

Hope you're doing well! I'm reducing some RSS-longslit data, with a couple of nights from 2020 :S running into difficulties. In both cases ( 2020-1-MLT-008.20200919 and 2020-1-MLT-008.20200920 ) the terminal output quotes lots of RuntimeWarnings, followed by a ValueError, like so:

2022-10-11 11:25:54,997 - RSSMOSPipeline - INFO - reduced/G4Jy 148_PL0200N001/rwcmbxgpP202009190086.fits
/Users/sarahwhite/anaconda/envs/rssmospipeline_master/lib/python3.5/site-packages/RSSMOSPipeline/RSSMOSTools.py:763: RuntimeWarning: invalid value encountered in less
  chipGapMask=np.array(np.less(data, lowMaskValue), dtype = float)  # flags chip gaps as noise
/Users/sarahwhite/anaconda/envs/rssmospipeline_master/lib/python3.5/site-packages/numpy/lib/function_base.py:3250: RuntimeWarning: Invalid value encountered in median for 47 results
  r = func(a, **kwargs)
/Users/sarahwhite/anaconda/envs/rssmospipeline_master/lib/python3.5/site-packages/RSSMOSPipeline/RSSMOSTools.py:1523: RuntimeWarning: invalid value encountered in less
  prof[np.less(prof, 0)]=0.
/Users/sarahwhite/anaconda/envs/rssmospipeline_master/lib/python3.5/site-packages/RSSMOSPipeline/RSSMOSTools.py:1528: RuntimeWarning: invalid value encountered in less
  mask=np.less(abs(prof-mean), sigmaCut*sigma)
/Users/sarahwhite/anaconda/envs/rssmospipeline_master/lib/python3.5/site-packages/RSSMOSPipeline/RSSMOSTools.py:1537: RuntimeWarning: invalid value encountered in less
  prof[np.less(prof, 0)]=0.
/Users/sarahwhite/anaconda/envs/rssmospipeline_master/lib/python3.5/site-packages/RSSMOSPipeline/RSSMOSTools.py:2205: RuntimeWarning: invalid value encountered in less
  mask=np.less(abs(data-mean), sigmaCut*sigma)
/Users/sarahwhite/anaconda/envs/rssmospipeline_master/lib/python3.5/site-packages/numpy/core/fromnumeric.py:2920: RuntimeWarning: Mean of empty slice.
  out=out, **kwargs)
/Users/sarahwhite/anaconda/envs/rssmospipeline_master/lib/python3.5/site-packages/numpy/core/_methods.py:85: RuntimeWarning: invalid value encountered in double_scalars
  ret = ret.dtype.type(ret / rcount)
/Users/sarahwhite/anaconda/envs/rssmospipeline_master/lib/python3.5/site-packages/numpy/core/_methods.py:140: RuntimeWarning: Degrees of freedom <= 0 for slice
  keepdims=keepdims)
/Users/sarahwhite/anaconda/envs/rssmospipeline_master/lib/python3.5/site-packages/numpy/core/_methods.py:110: RuntimeWarning: invalid value encountered in true_divide
  arrmean, rcount, out=arrmean, casting='unsafe', subok=False)
/Users/sarahwhite/anaconda/envs/rssmospipeline_master/lib/python3.5/site-packages/numpy/core/_methods.py:132: RuntimeWarning: invalid value encountered in double_scalars
  ret = ret.dtype.type(ret / rcount)
/Users/sarahwhite/anaconda/envs/rssmospipeline_master/lib/python3.5/site-packages/RSSMOSPipeline/RSSMOSTools.py:2211: RuntimeWarning: invalid value encountered in greater
  mask=np.greater(abs(data-mean), sigmaCut*sigma)
Traceback (most recent call last):
  File "/Users/sarahwhite/anaconda/envs/rssmospipeline_master/bin/rss_mos_reducer", line 170, in <module>
    iterativeMethod = iterativeMethod, subFrac = subFrac)
  File "/Users/sarahwhite/anaconda/envs/rssmospipeline_master/lib/python3.5/site-packages/RSSMOSPipeline/RSSMOSTools.py", line 2035, in extractAndStackSpectra
    signal, sky, mData=weightedExtraction(data)
  File "/Users/sarahwhite/anaconda/envs/rssmospipeline_master/lib/python3.5/site-packages/RSSMOSPipeline/RSSMOSTools.py", line 1826, in weightedExtraction
    x, R=optimize.nnls(w, v)
  File "/Users/sarahwhite/anaconda/envs/rssmospipeline_master/lib/python3.5/site-packages/scipy/optimize/nnls.py", line 43, in nnls
    A, b = map(asarray_chkfinite, (A, b))
  File "/Users/sarahwhite/anaconda/envs/rssmospipeline_master/lib/python3.5/site-packages/numpy/lib/function_base.py", line 461, in asarray_chkfinite
    "array must not contain infs or NaNs")
ValueError: array must not contain infs or NaNs

Please what do you suggest to fix/work around this?

Many thanks, Sarah x

mattyowl commented 1 year ago

Hi Sarah,

Sorry for the delay. I can't tell anything based on that traceback. The easiest thing will be if you can put the data which is having this issue into a .tar.gz and then I can try to debug it?

Did you look at e.g. the object traces (there is a DS9 reg file that the code produces which shows where its looking for objects)? Did that look sensible? And is it failing for one object? If it's something like that, you can try fiddling with the -T switch?

Cheers Matt

svw26 commented 1 year ago

Hiya Matt,

No worries, OK, I'll send you an email with the two product/ folders as .zip files.

Yeah, the traces look sensible, but I wonder whether it's because of some bright stars in the field (maybe leading to saturated pixels?). I noticed that the diagnostics/ folder never got as far as the skyCheck plots, for example, in these runs.

Re: the -T switch, I've been using '-T 1.0' as my default, to minimise repeated work. I tried re-running just now with '-T 2.0' but run into the same complaint. Also, thought this was a bit weird: for the first run of the pipeline for the 2020-1-MLT-008.20200919 night, only G4Jy 148 started to be processed. Then re-running the pipeline, and specifying a different reduced/ folder for the output, it seems to have skipped G4Jy 148 and went ahead to G4Jy 1336 [completing successfully] and then G4Jy 1521 [where it ends with ValueError: array must not contain infs or NaNs.]

Thanks, Sarah x

mattyowl commented 1 year ago

Hi Sarah,

I've checked some changes into the master branch, which fixes some issues with how the chip gap masking and flat fielding works (should be more robust now). After doing that, your data ran through the pipeline ok. Please take a look. I might just put this out as a new tagged release.

Cheers Matt

mattyowl commented 1 year ago

Changes are in 0.4.0 (now on PyPI) - please let me know if you have any more issues.