Skip to content

Commit

Permalink
Merge pull request #13 from lsst/tickets/DM-23526
Browse files Browse the repository at this point in the history
DM-23526: Fix fgcmcal issues exposed during PDR2 run
  • Loading branch information
erykoff committed Feb 20, 2020
2 parents 14d874a + a4115ba commit 0c71a93
Show file tree
Hide file tree
Showing 8 changed files with 1,851 additions and 17 deletions.
6 changes: 3 additions & 3 deletions examples/configs/fgcm_atm_subaru.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# default Subaru (HSC) Atmosphere File

atmosphereTableFile: fgcm_atm_subaru2.fits
atmosphereTableFile: fgcm_atm_subaru3.fits

elevation: 4139.0

Expand All @@ -19,8 +19,8 @@ tauSteps: 11
alphaRange: [0.0,2.0]
alphaSteps: 9

zenithRange: [0.0,70.0]
zenithSteps: 21
zenithRange: [0.0,75.0]
zenithSteps: 23

pmbStd: 828.0
pwvStd: 1.5
Expand Down
2 changes: 1 addition & 1 deletion fgcm/_version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import division, absolute_import, print_function

__version__ = '3.1.0'
__version__ = '3.1.3'

__version_info__ = __version__.split('.')
1,812 changes: 1,812 additions & 0 deletions fgcm/data/tables/fgcm_atm_subaru3.fits

Large diffs are not rendered by default.

18 changes: 14 additions & 4 deletions fgcm/fgcmApertureCorrection.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ def computeApertureCorrections(self):
expGray = snmm.getArray(self.fgcmGray.expGrayHandle)
expGrayTemp = expGray.copy()

# save original pivot and range in case it fails
originalSlope = self.fgcmPars.compAperCorrSlope.copy()
originalPivot = self.fgcmPars.compAperCorrPivot.copy()
originalRange = self.fgcmPars.compAperCorrRange.copy()

# first, remove any previous correction if necessary...
if (np.max(self.fgcmPars.compAperCorrRange[1,:]) >
np.min(self.fgcmPars.compAperCorrRange[0,:])) :
Expand Down Expand Up @@ -110,7 +115,6 @@ def computeApertureCorrections(self):
continue

# sort to set the range...
#st=np.argsort(expGrayTemp[use])
st=np.argsort(self.fgcmPars.expSeeingVariable[expIndexUse[use]])
use=use[st]

Expand All @@ -131,7 +135,9 @@ def computeApertureCorrections(self):
gd,=np.where(binStruct['Y_ERR'] > 0.0)
if (gd.size < 3):
self.fgcmLog.warn('Could not compute aperture correction for band %s (too few exposures)' % (self.fgcmPars.bands[i]))
self.fgcmPars.compAperCorrSlope[i] = 0.0
self.fgcmPars.compAperCorrSlope[i] = originalSlope[i]
self.fgcmPars.compAperCorrPivot[i] = originalPivot[i]
self.fgcmPars.compAperCorrRange[:, i] = originalRange[:, i]
self.fgcmPars.compAperCorrSlopeErr[i] = 0.0

continue
Expand All @@ -158,14 +164,18 @@ def computeApertureCorrections(self):
except Exception as inst:
self.fgcmLog.info('aperture correction completely failed for band %s' %
(self.fgcmPars.bands[i]))
self.fgcmPars.compAperCorrSlope[i] = 0.0
self.fgcmPars.compAperCorrSlope[i] = originalSlope[i]
self.fgcmPars.compAperCorrPivot[i] = originalPivot[i]
self.fgcmPars.compAperCorrRange[:, i] = originalRange[:, i]
self.fgcmPars.compAperCorrSlopeErr[i] = 0.0
continue

if ((cov[0,0] < 0.0) or (not np.isfinite(cov[0,0]))) :
self.fgcmLog.warn('Aperture correction computation failed for band %s' %
(self.fgcmPars.bands[i]))
self.fgcmPars.compAperCorrSlope[i] = 0.0
self.fgcmPars.compAperCorrSlope[i] = originalSlope[i]
self.fgcmPars.compAperCorrPivot[i] = originalPivot[i]
self.fgcmPars.compAperCorrRange[:, i] = originalRange[:, i]
self.fgcmPars.compAperCorrSlopeErr[i] = 0.0

continue
Expand Down
11 changes: 5 additions & 6 deletions fgcm/fgcmConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,12 +547,11 @@ def __init__(self, configDict, lutIndex, lutStd, expInfo, ccdOffsets, checkFiles
cCut[1] = list(self.bands).index(cCut[1])

# Check for input aperture corrections.
if self.aperCorrFitNBins == 0:
if len(self.aperCorrInputSlopes) == 0:
self.fgcmLog.warn("Aperture corrections will not be fit; strongly recommend setting aperCorrInputSlopes")
else:
if len(self.aperCorrInputSlopes) != len(self.bands):
raise RuntimeError("Length of aperCorrInputSlopes does not equal number of bands!")
if self.aperCorrFitNBins == 0 and len(self.aperCorrInputSlopes) == 0:
self.fgcmLog.warn("Aperture corrections will not be fit; strongly recommend setting aperCorrInputSlopes")
if len(self.aperCorrInputSlopes) > 0:
if len(self.aperCorrInputSlopes) != len(self.bands):
raise RuntimeError("Length of aperCorrInputSlopes does not equal number of bands!")

# Check the sed mapping dictionaries
# First, make sure every band is listed in the sedTermDict
Expand Down
2 changes: 1 addition & 1 deletion fgcm/fgcmParameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def __init__(self, fgcmConfig, expInfo=None, fgcmLUT=None,
self.illegalValue = fgcmConfig.illegalValue
self.quietMode = fgcmConfig.quietMode

if fgcmConfig.aperCorrFitNBins == 0 and len(fgcmConfig.aperCorrInputSlopes) > 0:
if len(fgcmConfig.aperCorrInputSlopes) > 0:
self.aperCorrInputSlopes = fgcmConfig.aperCorrInputSlopes
else:
self.aperCorrInputSlopes = None
Expand Down
5 changes: 5 additions & 0 deletions fgcm/fgcmSigmaCal.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ def run(self, applyGray=True):

ok, = np.where((objChi2[goodStars[plotIndices[band]], bandIndex] > 0.001) &
(objChi2[goodStars[plotIndices[band]], bandIndex] < 1000.0))

if ok.size < 100:
self.fgcmLog.warn('Not enough stars with decent chi2 to compute sigmaCal for band %s' % (band))
continue

# These have already been limited to the plot percentile range
h, rev = esutil.stat.histogram(objMagStdMean[goodStars[plotIndices[band][ok]], bandIndex],
nbin=nPlotBin, rev=True)
Expand Down
12 changes: 10 additions & 2 deletions fgcm/fgcmStars.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,8 +690,16 @@ def loadStars(self, fgcmPars,
# Check the airmass range
if ((np.min(obsSecZenith) < self.secZenithRange[0]) |
(np.max(obsSecZenith) > self.secZenithRange[1])):
raise ValueError("Input stars have a secZenith that is out of range of LUT."
"Observed range is %.2f to %.2f, and LUT goes from %.2f to %.2f" % (np.min(obsSecZenith), np.max(obsSecZenith), self.secZenithRange[0], self.secZenithRange[1]))
self.fgcmLog.warn("Input stars have a secZenith that is out of range of LUT."
"Observed range is %.2f to %.2f, and LUT goes from %.2f to %.2f" %
(np.min(obsSecZenith), np.max(obsSecZenith),
self.secZenithRange[0], self.secZenithRange[1]))
bad, = np.where((obsSecZenith <= self.secZenithRange[0]) |
(obsSecZenith >= self.secZenithRange[1]))
self.fgcmLog.warn("Clipping %d observations out of airmass range" % (bad.size))
obsSecZenith[bad] = np.clip(obsSecZenith[bad],
obsSecZenithRange[0],
obsSecZenithRange[1])

if not self.quietMode:
self.fgcmLog.info('Computed secZenith in %.1f seconds.' %
Expand Down

0 comments on commit 0c71a93

Please sign in to comment.