import hsc.pipe.tasks.detrends
assert type(root)==hsc.pipe.tasks.detrends.FlatConfig, 'config is of type %s.%s instead of hsc.pipe.tasks.detrends.FlatConfig' % (type(root).__module__, type(root).__name__)
import lsst.obs.subaru.crosstalk
import lsst.obs.hsc.detrends
'''Key for detrend date in calib registry '''
root.dateCalib='calibDate'

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

'''Clipping threshold for background '''
root.stats.clip=3.0

'''Clipping iterations for background '''
root.stats.iter=3

import lsst.obs.hsc.detrends
root.combination.retarget(target=lsst.obs.hsc.detrends.HscFlatCombineTask, ConfigClass=lsst.obs.hsc.detrends.HscFlatCombineConfig)
'''Apply Jacobian to flat-field? '''
root.combination.doJacobian=False

'''Number of rows to read at a time '''
root.combination.rows=512

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

'''Clipping threshold for background '''
root.combination.stats.clip=3.0

'''Clipping iterations for background '''
root.combination.stats.iter=3

'''Clipping threshold for combination '''
root.combination.clip=3.0

'''Mask plane to set '''
root.combination.maskPlane='NO_DATA'

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

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

'''Radius of vignetting pattern, in focal plane coords '''
root.combination.vignette.radius=17500.0

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

'''List of amp serial numbers in CCD '''
root.combination.badAmpList=[]

'''Statistic to use for combination (from lsst.afw.math) '''
root.combination.combine=128

'''Clipping iterations for combination '''
root.combination.iter=3

'''List of CCD serial numbers for bad amplifiers '''
root.combination.badAmpCcdList=[]

'''Number of stdev below the background to set thumbnail minimum '''
root.isr.thumbnailStdev=3.0

'''Assemble detrend/calibration frames? '''
root.isr.doAssembleDetrends=False

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

'''Widen bleed trails based on their width? '''
root.isr.doWidenSaturationTrails=True

import lsst.obs.subaru.crosstalk
root.isr.crosstalk.retarget(target=lsst.obs.subaru.crosstalk.CrosstalkTask, ConfigClass=lsst.obs.subaru.crosstalk.CrosstalkConfig)
'''Shape of coeffs array '''
root.isr.crosstalk.coeffs.shape=[4, 4]

'''Crosstalk coefficients '''
root.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 '''
root.isr.crosstalk.crosstalkMaskPlane='CROSSTALK'

'''Set crosstalk mask plane for pixels over this value '''
root.isr.crosstalk.minPixelToMask=45000.0

'''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. '''
root.isr.overscanPolyOrder=30

'''Apply dark frame correction? '''
root.isr.doDark=True

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

'''Fallback default filter name for calibrations '''
root.isr.fallbackFilterName=None

'''Correct for crosstalk '''
root.isr.doCrosstalk=True

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

'''Number of points to define the Vignette polygon '''
root.isr.numPolygonPoints=100

'''FWHM of PSF (arcsec) '''
root.isr.fwhm=1.0

'''Maximum number of iterations for the brighter fatter correction '''
root.isr.brighterFatterMaxIter=10

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

'''Rejection threshold (sigma) for collapsing overscan before fit '''
root.isr.overscanRej=3.0

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

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

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

'''Correct for nonlinearity of the detector's response (ignored if coefficients are 0.0) '''
root.isr.doLinearize=True

'''Kernel file used for the brighter fatter correction '''
root.isr.brighterFatterKernelFile='/opt/hscpipe/4.0.5/Linux64/obs_subaru/HSC-4.0.3/hsc/brighter_fatter_kernel.pkl'

'''Apply the brighter fatter correction '''
root.isr.doBrighterFatter=False

'''Apply bias frame correction? '''
root.isr.doBias=True

'''Apply flat field correction? '''
root.isr.doFlat=False

'''Remove any PC cards in the header '''
root.isr.removePcCards=True

'''Apply fringe correction? '''
root.isr.doFringe=False

'''trim out non-data regions? '''
root.isr.assembleCcd.doTrim=True

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

'''renormalize to a gain of 1? (ignored if setGain false) '''
root.isr.assembleCcd.doRenorm=False

'''set gain? '''
root.isr.assembleCcd.setGain=True

'''Calculate variance? '''
root.isr.doVariance=True

'''Default value for fluxMag0T1 (for an unrecognised filter) '''
root.isr.defaultFluxMag0T1=28.0

'''Softening parameter for thumbnail mapping '''
root.isr.thumbnailQ=20.0

'''fields to remove from the metadata of the assembled ccd. '''
root.isr.keysToRemoveFromAssembledCcd=[]

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

'''Radius of vignetting pattern, in focal plane coords '''
root.isr.vignette.radius=17500.0

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

'''The approximate flux of a zero-magnitude object in a one-second exposure, per filter '''
root.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? '''
root.isr.doOverscan=True

'''Binning factor for thumbnail '''
root.isr.thumbnailBinning=4

'''Do fringe subtraction after flat-fielding? '''
root.isr.fringeAfterFlat=True

'''Border around saturated pixels for thumbnail '''
root.isr.thumbnailSatBorder=2

'''Mask saturated pixels? '''
root.isr.doSaturation=True

'''Trim guider shadow '''
root.isr.doGuider=False

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

'''Number of pixels by which to grow the saturation footprints '''
root.isr.growSaturationFootprintSize=1

'''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
 '''
root.isr.doApplyGains=False

'''Persist Polygon used to define vignetted region? '''
root.isr.doWriteVignettePolygon=True

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

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

'''Statistic to use '''
root.isr.fringe.stats.stat=32

'''Number of fitting iterations '''
root.isr.fringe.stats.iterations=3

'''Sigma clip threshold '''
root.isr.fringe.stats.clip=3.0

'''Only fringe-subtract these filters '''
root.isr.fringe.filters=['y', 'N921']

'''Sigma clip threshold '''
root.isr.fringe.clip=3.0

'''Half-size of large (background) measurements (pixels) '''
root.isr.fringe.large=30

'''Number of fringe measurements '''
root.isr.fringe.num=30000

'''Number of fitting iterations '''
root.isr.fringe.iterations=20

'''Half-size of small (fringe) measurements (pixels) '''
root.isr.fringe.small=3

'''Remove fringe pedestal? '''
root.isr.fringe.pedestal=False

'''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. '''
root.isr.brighterFatterThreshold=1000.0

'''Write OverScan-Subtracted thumbnail? '''
root.isr.qa.doThumbnailOss=True

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

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

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

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

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

'''Write flattened thumbnail? '''
root.isr.qa.doThumbnailFlattened=True

'''Write OverScan-Subtracted image? '''
root.isr.qa.doWriteOss=False

'''Write flattened image? '''
root.isr.qa.doWriteFlattened=False

'''Range for thumbnail mapping '''
root.isr.thumbnailRange=5.0

'''Persist postISRCCD? '''
root.isr.doWrite=False

'''Mask defect pixels? '''
root.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
 '''
root.isr.normalizeGains=False

'''Maximum deviation from the median for overscan '''
root.isr.overscanMaxDev=1000.0

'''The method for fitting the overscan bias level.
Allowed values:
	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
	None	Field is optional
	MEAN	Correct using the mean of the overscan region
 '''
root.isr.overscanFitType='AKIMA_SPLINE'

'''Tweak flats to match observed amplifier ratios? '''
root.isr.doTweakFlat=False

'''Key for observation date in exposure registry '''
root.dateObs='dateObs'

'''Clobber existing processed images? '''
root.clobber=True

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

'''Number of iterations for scale determination '''
root.iterations=10

