import lsst.pipe.drivers.constructCalibs
assert type(config)==lsst.pipe.drivers.constructCalibs.FlatConfig, 'config is of type %s.%s instead of lsst.pipe.drivers.constructCalibs.FlatConfig' % (type(config).__module__, type(config).__name__)
import lsst.afw.display.rgb
import lsst.afw.display._displayLib
import lsst.obs.subaru.crosstalk
import lsst.obs.hsc.vignette
import lsst.obs.subaru.isr
import lsst.afw.display.displayLib
import lsst.obs.subaru.crosstalkYagi
import lsst.obs.hsc.calibs
# DataId keywords specifying a CCD
config.ccdKeys=['ccd']

# DataId keywords specifying a calibration
config.calibKeys=[]

import lsst.obs.hsc.calibs
config.combination.retarget(target=lsst.obs.hsc.calibs.HscFlatCombineTask, ConfigClass=lsst.obs.hsc.calibs.HscFlatCombineConfig)

# Clipping iterations for combination
config.combination.nIter=3

# Number of rows to read at a time
config.combination.rows=512

# Clipping iterations for background
config.combination.stats.nIter=3

# Statistic to use to estimate background (from lsst.afw.math)
config.combination.stats.stat=128

# Mask planes to reject
config.combination.stats.mask=['DETECTED', 'BAD']

# Clipping threshold for background
config.combination.stats.clip=3.0

# Clipping threshold for combination
config.combination.clip=3.0

# Mask plane to set
config.combination.maskPlane='NO_DATA'

# Mask planes to respect
config.combination.mask=['SAT', 'DETECTED', 'INTRP']

# Center of vignetting pattern, in x (focal plane coords)
config.combination.vignette.xCenter=-100.0

# Radius of vignetting pattern, in focal plane coords
config.combination.vignette.radius=17500.0

# Center of vignetting pattern, in y (focal plane coords)
config.combination.vignette.yCenter=100.0

# List of amp serial numbers in CCD
config.combination.badAmpList=[]

# Statistic to use for combination (from lsst.afw.math)
config.combination.combine=128

# List of CCD serial numbers for bad amplifiers
config.combination.badAmpCcdList=[]

# DataId keywords specifying a visit
config.visitKeys=['visit']

import lsst.obs.subaru.isr
config.isr.retarget(target=lsst.obs.subaru.isr.SubaruIsrTask, ConfigClass=lsst.obs.subaru.isr.SubaruIsrConfig)

# Number of stdev below the background to set thumbnail minimum
config.isr.thumbnailStdev=3.0

# How to estimate the average value for BAD regions.
# Allowed values:
# 	None	Field is optional
# 	MEDIAN	Correct using the median of the good data
# 	MEANCLIP	Correct using the (clipped) mean of good data
# 
config.isr.badStatistic='MEANCLIP'

# Order of polynomial or to fit if overscan fit type is a polynomial, or number of spline knots if overscan fit type is a spline.
config.isr.overscanOrder=30

# Widen bleed trails based on their width?
config.isr.doWidenSaturationTrails=True

import lsst.obs.subaru.crosstalk
config.isr.crosstalk.retarget(target=lsst.obs.subaru.crosstalk.CrosstalkTask, ConfigClass=lsst.obs.subaru.crosstalk.CrosstalkConfig)

# Shape of coeffs array
config.isr.crosstalk.coeffs.shape=[4, 4]

# Crosstalk coefficients
config.isr.crosstalk.coeffs.values=[0.0, -0.000125, -0.000149, -0.000156, -0.000124, 0.0, -0.000132, -0.000157, -0.000171, -0.000134, 0.0, -0.000153, -0.000157, -0.000151, -0.000137, 0.0]

# Name for crosstalk mask plane
config.isr.crosstalk.crosstalkMaskPlane='CROSSTALK'

# Set crosstalk mask plane for pixels over this value
config.isr.crosstalk.minPixelToMask=45000.0

# Apply dark frame correction?
config.isr.doDark=True

# update exposure metadata in the assembled ccd to reflect the effective gain of the assembled chip
config.isr.setGainAssembledCcd=True

# Fallback default filter name for calibrations
config.isr.fallbackFilterName=None

# Correct for crosstalk
config.isr.doCrosstalk=True

# FWHM of PSF used when interpolating over bad columns (arcsec)
config.isr.fwhmForBadColumnInterpolation=1.0

# The read noise to use if no Detector is present in the Exposure
config.isr.readNoise=0.0

# FWHM of PSF (arcsec)
config.isr.fwhm=1.0

# Name of mask plane to use for suspect pixels
config.isr.suspectMaskName='SUSPECT'

# Maximum number of iterations for the brighter fatter correction
config.isr.brighterFatterMaxIter=10

# If flatScalingType is 'USER' then scale flat by this amount; ignored otherwise
config.isr.flatUserScale=1.0

# Rejection threshold (sigma) for collapsing overscan before fit
config.isr.overscanRej=3.0

# Dataset type for input data; users will typically leave this alone, but camera-specific ISR tasks will override it
config.isr.datasetType='raw'

# Assemble amp-level exposures into a ccd-level exposure?
config.isr.doAssembleCcd=True

# Name of mask plane to use in saturation detection and interpolation
config.isr.saturatedMaskName='SAT'

# Should the gain be applied when applying the brighter fatter correction?
config.isr.brighterFatterApplyGain=True

# Kernel file used for the brighter fatter correction
config.isr.brighterFatterKernelFile=''

# Threshold used to stop iterating the brighter fatter correction.  It is the  absolute value of the difference between the current corrected image and the one from the previous iteration summed over all the pixels.
config.isr.brighterFatterThreshold=1000.0

# Correct for nonlinearity of the detector's response?
config.isr.doLinearize=True

# Should we set the level of all BAD patches of the chip to the chip's average value?
config.isr.doSetBadRegions=True

# Apply the brighter fatter correction
config.isr.doBrighterFatter=False

# Apply bias frame correction?
config.isr.doBias=True

# Mask suspect pixels?
config.isr.doSuspect=True

# Apply flat field correction?
config.isr.doFlat=False

# Remove any PC cards in the header
config.isr.removePcCards=True

# Apply fringe correction?
config.isr.doFringe=False

# trim out non-data regions?
config.isr.assembleCcd.doTrim=True

# FITS headers to remove (in addition to DATASEC, BIASSEC, TRIMSEC and perhaps GAIN)
config.isr.assembleCcd.keysToRemove=[]

# renormalize to a gain of 1? (ignored if setGain false). Setting to True gives 1 ADU per electron. Setting to True is not recommended for mosaic cameras because it breaks normalization across the focal plane. However, if the CCDs are sufficiently flat then the resulting error may be acceptable.
config.isr.assembleCcd.doRenorm=False

# set gain?
config.isr.assembleCcd.setGain=True

# The saturation level to use if no Detector is present in the Exposure (ignored if NaN)
config.isr.saturation=float('nan')

# Calculate variance?
config.isr.doVariance=True

# Assemble amp-level calibration exposures into ccd-level exposure?
config.isr.doAssembleIsrExposures=False

# Tweak flats to match observed amplifier ratios?
config.isr.doTweakFlat=False

# fields to remove from the metadata of the assembled ccd.
config.isr.keysToRemoveFromAssembledCcd=[]

# Center of vignetting pattern, in x (focal plane coords)
config.isr.vignette.xCenter=-100.0

# Radius of vignetting pattern, in focal plane coords
config.isr.vignette.radius=17500.0

# Center of vignetting pattern, in y (focal plane coords)
config.isr.vignette.yCenter=100.0

# The approximate flux of a zero-magnitude object in a one-second exposure, per filter
config.isr.fluxMag0T1={'g': 398107170553.49854, 'N816': 15848931924.611174, 'i': 275422870333.81744, 'r': 398107170553.49854, 'N921': 19054607179.632523, 'N515': 20892961308.54041, 'y': 91201083935.59116, 'z': 120226443461.74132}

# Do overscan subtraction?
config.isr.doOverscan=True

# The gain to use if no Detector is present in the Exposure (ignored if NaN)
config.isr.gain=float('nan')

# Do fringe subtraction after flat-fielding?
config.isr.fringeAfterFlat=True

# Border around saturated pixels for thumbnail
config.isr.thumbnailSatBorder=2

# Mask saturated pixels?
config.isr.doSaturation=True

# Trim guider shadow
config.isr.doGuider=False

# Softening parameter for thumbnail mapping
config.isr.thumbnailQ=20.0

# Default value for fluxMag0T1 (for an unrecognised filter)
config.isr.defaultFluxMag0T1=158489319246.11172

# Correct the amplifiers for their gains
# 
# N.b. this is intended to be used *instead* of doFlat; it's useful if you're measuring system throughput
# 
config.isr.doApplyGains=False

# Number of points to define the Vignette polygon
config.isr.numPolygonPoints=100

# Persist Polygon used to define vignetted region?
config.isr.doWriteVignettePolygon=True

# Offset to the random number generator seed (full seed includes exposure ID)
config.isr.fringe.stats.rngSeedOffset=0

# Ignore pixels with these masks
config.isr.fringe.stats.badMaskPlanes=['SAT']

# Statistic to use
config.isr.fringe.stats.stat=32

# Number of fitting iterations
config.isr.fringe.stats.iterations=3

# Sigma clip threshold
config.isr.fringe.stats.clip=3.0

# Only fringe-subtract these filters
config.isr.fringe.filters=['y', 'N921', 'N926', 'N973', 'N1010']

# Sigma clip threshold
config.isr.fringe.clip=3.0

# Half-size of large (background) measurements (pixels)
config.isr.fringe.large=30

# Number of fringe measurements
config.isr.fringe.num=30000

# Number of fitting iterations
config.isr.fringe.iterations=20

# Half-size of small (fringe) measurements (pixels)
config.isr.fringe.small=3

# Remove fringe pedestal?
config.isr.fringe.pedestal=False

# The method for scaling the flat on the fly.
# Allowed values:
# 	None	Field is optional
# 	MEDIAN	Scale by the inverse of the median
# 	USER	Scale by flatUserScale
# 	MEAN	Scale by the inverse of the mean
# 
config.isr.flatScalingType='USER'

# Write OverScan-Subtracted thumbnail?
config.isr.qa.doThumbnailOss=True

# Mesh size in X (pix) to calculate count statistics
config.isr.qa.flatness.meshX=256

# How many times do we iterate clipping outliers in calculate count statistics?
config.isr.qa.flatness.nIter=3

# Do we clip outliers in calculate count statistics?
config.isr.qa.flatness.doClip=True

# How many sigma is used to clip outliers in calculate count statistics?
config.isr.qa.flatness.clipSigma=3.0

# Mesh size in Y (pix) to calculate count statistics
config.isr.qa.flatness.meshY=256

# Write flattened thumbnail?
config.isr.qa.doThumbnailFlattened=True

# Write OverScan-Subtracted image?
config.isr.qa.doWriteOss=False

# Write flattened image?
config.isr.qa.doWriteFlattened=False

# Range for thumbnail mapping
config.isr.thumbnailRange=5.0

# Persist postISRCCD?
config.isr.doWrite=False

# Mask defect pixels?
config.isr.doDefect=True

# Normalize all the amplifiers in each CCD to have the same gain
# 
# This does not measure the gains, it simply forces the median of each amplifier to be equal
# after applying the nominal gain
# 
config.isr.normalizeGains=False

# Maximum deviation from the median for overscan
config.isr.overscanMaxDev=1000.0

# The method for fitting the overscan bias level.
# Allowed values:
# 	None	Field is optional
# 	LEG	Fit Legendre polynomial to the longest axis of the overscan region
# 	CUBIC_SPLINE	Fit cubic spline to the longest axis of the overscan region
# 	MEDIAN	Correct using the median of the overscan region
# 	POLY	Fit ordinary polynomial to the longest axis of the overscan region
# 	CHEB	Fit Chebyshev polynomial to the longest axis of the overscan region
# 	AKIMA_SPLINE	Fit Akima spline to the longest axis of the overscan region
# 	NATURAL_SPLINE	Fit natural spline to the longest axis of the overscan region
# 	MEAN	Correct using the mean of the overscan region
# 
config.isr.overscanFitType='AKIMA_SPLINE'

# Number of pixels by which to grow the saturation footprints
config.isr.growSaturationFootprintSize=1

# Binning factor for thumbnail
config.isr.thumbnailBinning=4

# Key for observation date in exposure registry
config.dateObs='dateObs'

# Clobber existing processed images?
config.clobber=True

# Key for filter name in exposure/calib registries
config.filter='filter'

# Key for calib date in calib registry
config.dateCalib='calibDate'

# Number of iterations for scale determination
config.iterations=10

# Clipping iterations for background
config.stats.nIter=3

# Statistic to use to estimate background (from lsst.afw.math)
config.stats.stat=128

# Mask planes to reject
config.stats.mask=['DETECTED', 'BAD']

# Clipping threshold for background
config.stats.clip=3.0

