Report on Calcspec/Countrate discrepancy
  discovered during pysynphot commissioning testing
======================================================

10 July 2008, V. Laidler & H. Bushouse

File location: /eng/ssb/syn_pysyn/calcspec_countrate
Location of sample case files:
  /eng/ssb/syn_pysyn/8jul_r505M/stis_etc_cases/*/


Sample syn-pysyn case to look into:
-----------------------------------
stis_etc_cases/SpecSourcerateSpecCase23
  tda_Obsmode=stis,ccd,g430l
  tda_Spectrum=spec(earthshine.fits)*0.5+rn(spec(Zodi.fits),band(johnson,v),22.7,vegamag)

stis_etc_cases/SpecSourcerateSpecCase25
  tda_Obsmode=stis,ccd,g750l,c7751
  tda_Spectrum=spec(earthshine.fits)*0.5+rn(spec(Zodi.fits),band(johnson,v),22.7,vegamag)

These differ only in obsmode, yet:

case23:cs  pysyn < syn  (counts and photlam)
case25:cs  pysyn > syn  (counts and photlam)

case23 and case25: testspecphotlam results are identical
                   fail, non-extreme, most notable difference is at
                   the end perhaps due to tapering; but there are also
                   slight differences in the narrow features

case23 and case25: testthru passes

Case23:: tra_Discrepmean=1.70936656617e-10
Case23:: tra_Outliers=0
Case23:: tra_Discrepmax=1.98063708812e-07
Case23:: tra_Discrepstd=5.91500353683e-08
Case23:: tra_Discrepfrac=0.0
Case23:: tra_Discrepmin=-2.24487489258e-07


Case25:: tra_Discrepmean=-1.31022519282e-09
Case25:: tra_Outliers=0
Case25:: tra_Discrepmax=2.36381865556e-07
Case25:: tra_Discrepstd=6.30496455361e-08
Case25:: tra_Discrepfrac=0.0
Case25:: tra_Discrepmin=-2.31917703813e-07


Further synphot-only investigations:
------------------------------------
We used the genwave task to create wavesets c23.fits and c25.fits,
corresponding to the entries in the standard wavecat. Notably, dwave
for c23 = 2.7, c25=4.9.

Excerpt from the wavecat:
   stis,g430l              (2900.0,5700.0,2.7)
   stis,g750l,c7751        (5236.0,10266.0,4.9)

We then used calcspec to generate the spectrum alone, but using these
obsmode-related wavesets.We did this both in photlam and in counts.

We discovered that in the area in which the wavesets overlapped, the
spectra were offset from each other,*even in photlam*, which should be
independent of the bin size because it is a unit of photons per
angstrom. (See figure cs_box.ps.)

In counts, the offset was bigger, and close to the expected
factor of 1.8 due to the difference in binsize.

We used countrate and lied to it with a box(10000,30000) to simulate
not using an obsmode. The countrate-produced results agreed with each
other, as expected. (See figures cr_box.ps and cr_box_zoom.ps.)

Conclusion:
===========
  Calcspec is broken.
  We should not be comparing pysynphot to calcspec, period.
============================================================

Appendix: Synphot commands used to generate the test files:

 --> calcspec "spec(earthshine.fits)*0.5+rn(spec(Zodi.fits),band(johnson,v),22.7,vegamag)" c25_cs_noobs.fits wavetab=c25.fits

--> calcspec "spec(earthshine.fits)*0.5+rn(spec(Zodi.fits),band(johnson,v),22.7,vegamag)" c23_cs_noobs.fits wavetab=c23.fits
--> calcspec "spec(earthshine.fits)*0.5+rn(spec(Zodi.fits),band(johnson,v),22.7,vegamag)" c25_cs_noobs_counts.fits form=counts wavetab=c25.fits
--> calcspec "spec(earthshine.fits)*0.5+rn(spec(Zodi.fits),band(johnson,v),22.7,vegamag)" c23_cs_noobs_box.fits form=photlam wavetab=c23.fits

--> calcspec "box(10000.,30000.)*spec(earthshine.fits)*0.5+rn(spec(Zodi.fits),band(johnson,v),22.7,vegamag)" c25_cs_box_photlam.fits form=photlam wavetab=c25.fits
--> calcspec "box(10000.,30000.)*spec(earthshine.fits)*0.5+rn(spec(Zodi.fits),band(johnson,v),22.7,vegamag)" c23_cs_box_photlam.fits form=photlam wavetab=c23.fits
--> countrate "spec(earthshine.fits)*0.5+rn(spec(Zodi.fits),band(johnson,v),22.7,vegamag)" "" "box(10000.,30000.)" form=photlam out=c23_cr_box_photlam.fits wavecat=c23.cat
--> countrate "spec(earthshine.fits)*0.5+rn(spec(Zodi.fits),band(johnson,v),22.7,vegamag)" "" "box(10000.,30000.)" form=photlam out=c23_cr_box_photlam.fits wavecat=c23.cat
--> countrate "spec(earthshine.fits)*0.5+rn(spec(Zodi.fits),band(johnson,v),22.7,vegamag)" "" "box(10000.,30000.)" form=photlam out=c25_cr_box_photlam.fits wavecat=c25.cat

