Discovery test set:
  wfc3_rn_ir1_cases.py (r592)

Investigation test case:
wfc3_rn_ir1_cases/testcrspec/wfc3C26 

Symptom:
  All cases that use a spectrum are failing because there's a change
  in shape at lambda=10000 angstroms. Synphot steps down at 10000 but
  pysynphot doesn't.

  There are also other differences in slope further redward.

What's magic about 10000A:
  These spectra, all taken from the Bruzual atlas, change to a very
  sparse wavelength spacing beginning with 10000A.

Determination of which package is correct:
  Compare the shape of the original spectrum to the shape of the
  renormalized spectrum. Renormalization should be a simple linear
  transformation: the shape should not change. It was demonstrated that
  this condition is not met for the synphot renormalization, but is
  met for the pysynphot renormalization.

  Details:
    Some complications were necessary to perform this comparison because
    of the sampling issue. The test case results were on the same
    sampling as each other, which did not match the wavelength sampling
    of the original spectrum.

    Pysynphot was used to read in the original spectrum and
    renormalize it, retaining its native sampling. A ratio of the two
    was taken, and the finite elements of this ratio were examined and
    determined to have a constant value. 

    This constant value was then used to, effectively,
    "un-renormalize" the synphot-normalized spectrum in wfc3C26.fits,
    so that it could be plotted on the same scale as the original
    spectrum. 

    The departure from the original shape is clearly seen on the
    resulting plot.

Conclusions:
  - the SYNPHOT code has a bug, probably related to 
  suddenly-sparse wavelength tables, that causes it to incorrectly
  modify the shape of the spectrum being renormalized in the vicinity
  of such points.

  - the bug has been demonstrated to occur in the renormalization
  code. No effort has been devoted to determine
  whether this bug also manifests elsewhere in the SYNPHOT codebase.

  - spectra with these characteristics should not be used in the
    syn-pysyn commissioning tests. This includes the entire Bruzual
    atlas, which is now in any case obsolescent and the Pickles atlas
    is recommended for use instead.

Other potentially affected test cases:
  The following syn_pysyn test sets make use of a spectrum from the
  Bruzual atlas:
    nicmos_etc_cases.py : 25
    wfc3_ir_imaging_78_cases.py : 144
    wfc3_ir_spec_61_cases.py : 14
    wfc3_rn_ir1_cases.py : 24
    wfc3_uvis1_imaging_61_cases.py : 144
    wfc3_uvis1_spec_62_cases.py : 14
    wfc3_uvis2_imaging_18_cases.py : 144
    wfc3_uvis2_spec_18_cases.py : 14

NICMOS and WFC3 team members may wish to revisit these cases in order
to avoid this SYNPHOT bug.





Script details to reproduce the plots:

#let's look at C26:wfc3_rn_ir1_cases/testcrspec/wfc3C26::
#sp=rn(spec(/grp/hst/cdbs/grid/bz77/bz_48.fits),band(wfc3,ir,f105w),25.0,stmag)

import pysynphot as S
import numpy as N
from pylab import *

sp=S.FileSpectrum('/grp/hst/cdbs/grid/bz77/bz_48.fits')
bp=S.ObsBandpass('wfc3,ir,f105w')
sprn=sp.renorm(25.0,'stmag',bp)
syn=S.FileSpectrum('wfc3C26.fits')
sprn.convert('photlam')
sp.convert('photlam')
plot(syn.wave,syn.flux,'.-')
plot(sprn.wave,sprn.flux,'.-')
legend(['syn','pysyn'])
grid()
title('wfc3C26')

figure(2)
rat=sp.flux/sprn.flux
realrat=N.isfinite(rat)       
print rat[realrat].min()
#5.7189608156e+15
>>> print N.where(rat[realrat]!=rat[realrat].min())
#(array([], dtype=int64),)
plot(syn.wave,syn.flux*rat[realrat].min(),'.-')
plot(sp.wave,sp.flux,'.-')
legend(['synphot renormalized then rescaled',sp])



Details of investigation case:
gaudete> cat wfc3_rn_ir1_cases/testcrspec/wfc3C26.log
wfc3_rn_ir1_cases/testcrspec/wfc3C26:: Name=wfc3_rn_ir1_cases/testcrspec/wfc3C26
wfc3_rn_ir1_cases/testcrspec/wfc3C26:: Status=F
wfc3_rn_ir1_cases/testcrspec/wfc3C26:: Time=Tue Sep  2 11:51:15 2008
wfc3_rn_ir1_cases/testcrspec/wfc3C26:: tda_SkyLines=False
wfc3_rn_ir1_cases/testcrspec/wfc3C26:: tda_Obsmode=None
wfc3_rn_ir1_cases/testcrspec/wfc3C26:: tda_Spectrum=rn(spec(/grp/hst/cdbs/grid/bz77/bz_48.fits),band(wfc3,ir,f105w),25.0,stmag)
wfc3_rn_ir1_cases/testcrspec/wfc3C26:: tda_Thresh=0.01
wfc3_rn_ir1_cases/testcrspec/wfc3C26:: tda_SigThresh=0.01
wfc3_rn_ir1_cases/testcrspec/wfc3C26:: tda_Superthresh=0.2
wfc3_rn_ir1_cases/testcrspec/wfc3C26:: tra_Discrepmean=-0.000242284646813
wfc3_rn_ir1_cases/testcrspec/wfc3C26:: tra_Outliers=2
wfc3_rn_ir1_cases/testcrspec/wfc3C26:: tra_Discrepmax=0.137682874702
wfc3_rn_ir1_cases/testcrspec/wfc3C26:: tra_Discrepstd=0.0215893046358
wfc3_rn_ir1_cases/testcrspec/wfc3C26:: tra_Discrepfrac=0.310638297872
wfc3_rn_ir1_cases/testcrspec/wfc3C26:: tra_Discrepmin=-0.136706452009
wfc3_rn_ir1_cases/testcrspec/wfc3C26:: tra_Extreme=True
END
