import hsc.pipe.tasks.detrends
assert type(root)==hsc.pipe.tasks.detrends.DarkConfig, 'config is of type %s.%s instead of hsc.pipe.tasks.detrends.DarkConfig' % (type(root).__module__, type(root).__name__)
import lsst.obs.subaru.crosstalk
'''Interpolate over defects? (ignored unless you provide a list of defects) '''
root.repair.doInterpolate=True

'''Smoothly taper (on the PSF scale) to the fallback value at the edge of the image? '''
root.repair.interp.useFallbackValueAtEdge=True

'''Interpolation kernel size = interpFwhm converted to pixels * interpKernelSizeFactor. '''
root.repair.interp.interpKernelSizeFactor=3.0

'''Find and mask out cosmic rays? '''
root.repair.doCosmicRay=True

'''Don't interpolate over CR pixels '''
root.repair.cosmicray.keepCRs=False

'''used in condition 3 for CR; see CR.cc code '''
root.repair.cosmicray.cond3_fac=2.5

'''used in condition 3 for CR; see CR.cc code '''
root.repair.cosmicray.cond3_fac2=0.6

'''Names of mask planes to ignore while estimating the background '''
root.repair.cosmicray.background.ignoredPixelMask=['BAD', 'EDGE', 'DETECTED', 'DETECTED_NEGATIVE', 'NO_DATA']

'''behaviour if there are too few points in grid for requested interpolation style
Allowed values:
	INCREASE_NXNYSAMPLE	Increase the number of samples used to make the interpolation grid.
	THROW_EXCEPTION	throw an exception if there are too few points
	None	Field is optional
	REDUCE_INTERP_ORDER	use an interpolation style with a lower order.
 '''
root.repair.cosmicray.background.undersampleStyle='REDUCE_INTERP_ORDER'

'''how to interpolate the background values. This maps to an enum; see afw::math::Background
Allowed values:
	NONE	No background estimation is to be attempted
	CONSTANT	Use a single constant value
	LINEAR	Use linear interpolation
	AKIMA_SPLINE	higher-level nonlinear spline that is more robust to outliers
	None	Field is optional
	NATURAL_SPLINE	cubic spline with zero second derivative at endpoints
 '''
root.repair.cosmicray.background.algorithm='AKIMA_SPLINE'

'''how large a region of the sky should be used for each background point
	Valid Range = [10,inf) '''
root.repair.cosmicray.background.binSize=100000

'''Ignore NaNs when estimating the background '''
root.repair.cosmicray.background.isNanSafe=False

'''type of statistic to use for grid points
Allowed values:
	MEDIAN	median
	MEANCLIP	clipped mean
	None	Field is optional
	MEAN	unclipped mean
 '''
root.repair.cosmicray.background.statisticsProperty='MEDIAN'

'''Apprimation order for background Chebyshev (valid only with useApprox=True) '''
root.repair.cosmicray.background.approxOrder=6

'''Use Approximate (Chebyshev) to model background. '''
root.repair.cosmicray.background.useApprox=False

'''number of times to look for contaminated pixels near known CR pixels '''
root.repair.cosmicray.niteration=3

'''maximum number of contaminated pixels '''
root.repair.cosmicray.nCrPixelMax=1000000

'''CRs must be > this many sky-sig above sky '''
root.repair.cosmicray.minSigma=5.0

'''CRs must have > this many DN (== electrons/gain) in initial detection '''
root.repair.cosmicray.min_DN=50.0

'''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 planes to respect '''
root.combination.mask=['SAT', 'DETECTED', 'INTRP', 'CR']

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

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

'''Repair artifacts? '''
root.doRepair=True

'''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=False

'''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=False

'''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

'''Repair PSF size (pixels) '''
root.psfSize=21

'''Grow radius for CR (pixels) '''
root.crGrow=2

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

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

'''Key for detrend date in calib registry '''
root.dateCalib='calibDate'

'''Repair PSF FWHM (pixels) '''
root.psfFwhm=3.0

'''Header keyword for time since last CCD wipe, or None '''
root.darkTime=None

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

