# Path: photometry/quality.py
# class CorrectorQualityFlags(QualityFlagsBase):
# 	"""
# 	This class encodes the meaning of the various TESS QUALITY bitmask flags.
# 	"""
# 	FlaggedBadData = 1
# 	ManualExclude = 2
# 	SigmaClip = 4
# 	JumpAdditiveConstant = 8
# 	JumpAdditiveLinear = 16
# 	JumpMultiplicativeConstant = 32
# 	JumpMultiplicativeLinear = 64
# 	Interpolated = 128
# 	BackgroundShenanigans = 256
# 
# 	# Default bitmask
# 	DEFAULT_BITMASK = (FlaggedBadData | ManualExclude)
# 
# 	# Pretty string descriptions for each flag
# 	STRINGS = {
# 		FlaggedBadData: "Bad data based on pixel flags",
# 		ManualExclude: "Manual exclude",
# 		SigmaClip: "Point removed due to sigma clipping",
# 		JumpAdditiveConstant: "Jump corrected using additive constant",
# 		JumpAdditiveLinear: "Jump corrected using additive linear trend",
# 		JumpMultiplicativeConstant: "Jumb corrected using multiplicative constant",
# 		JumpMultiplicativeLinear: "Jump corrected using multiplicative linear trend",
# 		Interpolated: "Point is interpolated",
# 		BackgroundShenanigans: "Background Shenanigans detected in stamp",
# 	}
# 
# class TESSQualityFlags(QualityFlagsBase):
# 	"""
# 	This class encodes the meaning of the various TESS PIXEL_QUALITY bitmask flags.
# 	"""
# 	AttitudeTweak = 1
# 	SafeMode = 2
# 	CoarsePoint = 4
# 	EarthPoint = 8
# 	ZeroCrossing = 16
# 	Desat = 32
# 	ApertureCosmic = 64
# 	ManualExclude = 128
# 	SensitivityDropout = 256
# 	ImpulsiveOutlier = 512
# 	CollateralCosmic = 1024
# 	EarthMoonPlanetInFOV = 2048
# 	ScatteredLight = 4096
# 
# 	# Which is the recommended QUALITY mask to identify bad data?
# 	DEFAULT_BITMASK = (AttitudeTweak | SafeMode | CoarsePoint | EarthPoint
# 		| Desat | ApertureCosmic | ManualExclude | ScatteredLight)
# 
# 	# This bitmask includes flags that are known to identify both good and bad cadences.
# 	# Use it wisely.
# 	HARD_BITMASK = (DEFAULT_BITMASK | SensitivityDropout | CollateralCosmic)
# 
# 	# Bitmask of all of the flags that are relevant to FFIs:
# 	# We are on purpose not including ManualExclude here, as it would
# 	# result in many (~20%) of FFI data to be marked with ManualExclude
# 	# and therefore be rejected in the following processing.
# 	# There is also no reason for why a single timestamp in a TPF marked
# 	# as ManualExclude should necessarily cause the FFI timestamp to be invalid.
# 	FFI_RELEVANT_BITMASK = (AttitudeTweak | SafeMode | CoarsePoint | EarthPoint
# 		| Desat | EarthMoonPlanetInFOV | ScatteredLight)
# 
# 	# Pretty string descriptions for each flag
# 	STRINGS = {
# 		AttitudeTweak: "Attitude tweak",
# 		SafeMode: "Safe mode",
# 		CoarsePoint: "Spacecraft in Coarse point",
# 		EarthPoint: "Spacecraft in Earth point",
# 		ZeroCrossing: "Reaction wheel zero crossing",
# 		Desat: "Reaction wheel desaturation event",
# 		ApertureCosmic: "Cosmic ray in optimal aperture pixel",
# 		ManualExclude: "Manual exclude",
# 		SensitivityDropout: "Sudden sensitivity dropout",
# 		ImpulsiveOutlier: "Impulsive outlier",
# 		CollateralCosmic: "Cosmic ray in collateral data",
# 		EarthMoonPlanetInFOV: "Earth, Moon or other planet in camera FOV",
# 		ScatteredLight: "Scattered light from Earth or Moon in CCD"
# 	}
# 
# class PixelQualityFlags(QualityFlagsBase):
# 	"""
# 	This class encodes the meaning of the various TESS QUALITY bitmask flags.
# 	"""
# 	NotUsedForBackground = 1
# 	ManualExclude = 2
# 	BackgroundShenanigans = 4
# 
# 	# Default bitmask
# 	DEFAULT_BITMASK = (ManualExclude)
# 
# 	# Pretty string descriptions for each flag
# 	STRINGS = {
# 		NotUsedForBackground: "Pixel was not used in background calculation",
# 		ManualExclude: "Manual exclude",
# 		BackgroundShenanigans: "Background Shenanigans detected in pixel",
# 	}


import pytest
import numpy as np
import conftest # noqa: F401
from photometry.quality import CorrectorQualityFlags, TESSQualityFlags, PixelQualityFlags
	assert len(dc) == 2
	assert 'Manual exclude' in dc

	# A default bitmask should be set:
	dmask = TESSQualityFlags.DEFAULT_BITMASK
	print(dmask)

	# Test HARDEST_BITMASK:
	hrep = TESSQualityFlags.binary_repr(TESSQualityFlags.HARDEST_BITMASK)
	assert hrep == '11111111111111111111111111111111'

	#for flag in TESSQualityFlags:
	#	print(flag)
	#	indx = TESSQualityFlags.filter(quality, flag)
	#	rep = CorrectorQualityFlags.binary_repr(quality)
	#	assert len(rep) == 32

#--------------------------------------------------------------------------------------------------
def test_PixelQuality():
	"""Test of TESSQualityFlags"""

	# Quality flags:
	quality = np.zeros(10, dtype='int32')
	print(quality)

	# When quality is all zeros, filter should give all True:
	assert all(PixelQualityFlags.filter(quality))

	# Assign a random flag to one of the qualities and see if it filters:
	quality[3] = PixelQualityFlags.ManualExclude | PixelQualityFlags.BackgroundShenanigans

# Path: photometry/quality.py
# class CorrectorQualityFlags(QualityFlagsBase):
# 	"""
# 	This class encodes the meaning of the various TESS QUALITY bitmask flags.
# 	"""
# 	FlaggedBadData = 1
# 	ManualExclude = 2
# 	SigmaClip = 4
# 	JumpAdditiveConstant = 8
# 	JumpAdditiveLinear = 16
# 	JumpMultiplicativeConstant = 32
# 	JumpMultiplicativeLinear = 64
# 	Interpolated = 128
# 	BackgroundShenanigans = 256
# 
# 	# Default bitmask
# 	DEFAULT_BITMASK = (FlaggedBadData | ManualExclude)
# 
# 	# Pretty string descriptions for each flag
# 	STRINGS = {
# 		FlaggedBadData: "Bad data based on pixel flags",
# 		ManualExclude: "Manual exclude",
# 		SigmaClip: "Point removed due to sigma clipping",
# 		JumpAdditiveConstant: "Jump corrected using additive constant",
# 		JumpAdditiveLinear: "Jump corrected using additive linear trend",
# 		JumpMultiplicativeConstant: "Jumb corrected using multiplicative constant",
# 		JumpMultiplicativeLinear: "Jump corrected using multiplicative linear trend",
# 		Interpolated: "Point is interpolated",
# 		BackgroundShenanigans: "Background Shenanigans detected in stamp",
# 	}
# 
# class TESSQualityFlags(QualityFlagsBase):
# 	"""
# 	This class encodes the meaning of the various TESS PIXEL_QUALITY bitmask flags.
# 	"""
# 	AttitudeTweak = 1
# 	SafeMode = 2
# 	CoarsePoint = 4
# 	EarthPoint = 8
# 	ZeroCrossing = 16
# 	Desat = 32
# 	ApertureCosmic = 64
# 	ManualExclude = 128
# 	SensitivityDropout = 256
# 	ImpulsiveOutlier = 512
# 	CollateralCosmic = 1024
# 	EarthMoonPlanetInFOV = 2048
# 	ScatteredLight = 4096
# 
# 	# Which is the recommended QUALITY mask to identify bad data?
# 	DEFAULT_BITMASK = (AttitudeTweak | SafeMode | CoarsePoint | EarthPoint
# 		| Desat | ApertureCosmic | ManualExclude | ScatteredLight)
# 
# 	# This bitmask includes flags that are known to identify both good and bad cadences.
# 	# Use it wisely.
# 	HARD_BITMASK = (DEFAULT_BITMASK | SensitivityDropout | CollateralCosmic)
# 
# 	# Bitmask of all of the flags that are relevant to FFIs:
# 	# We are on purpose not including ManualExclude here, as it would
# 	# result in many (~20%) of FFI data to be marked with ManualExclude
# 	# and therefore be rejected in the following processing.
# 	# There is also no reason for why a single timestamp in a TPF marked
# 	# as ManualExclude should necessarily cause the FFI timestamp to be invalid.
# 	FFI_RELEVANT_BITMASK = (AttitudeTweak | SafeMode | CoarsePoint | EarthPoint
# 		| Desat | EarthMoonPlanetInFOV | ScatteredLight)
# 
# 	# Pretty string descriptions for each flag
# 	STRINGS = {
# 		AttitudeTweak: "Attitude tweak",
# 		SafeMode: "Safe mode",
# 		CoarsePoint: "Spacecraft in Coarse point",
# 		EarthPoint: "Spacecraft in Earth point",
# 		ZeroCrossing: "Reaction wheel zero crossing",
# 		Desat: "Reaction wheel desaturation event",
# 		ApertureCosmic: "Cosmic ray in optimal aperture pixel",
# 		ManualExclude: "Manual exclude",
# 		SensitivityDropout: "Sudden sensitivity dropout",
# 		ImpulsiveOutlier: "Impulsive outlier",
# 		CollateralCosmic: "Cosmic ray in collateral data",
# 		EarthMoonPlanetInFOV: "Earth, Moon or other planet in camera FOV",
# 		ScatteredLight: "Scattered light from Earth or Moon in CCD"
# 	}
# 
# class PixelQualityFlags(QualityFlagsBase):
# 	"""
# 	This class encodes the meaning of the various TESS QUALITY bitmask flags.
# 	"""
# 	NotUsedForBackground = 1
# 	ManualExclude = 2
# 	BackgroundShenanigans = 4
# 
# 	# Default bitmask
# 	DEFAULT_BITMASK = (ManualExclude)
# 
# 	# Pretty string descriptions for each flag
# 	STRINGS = {
# 		NotUsedForBackground: "Pixel was not used in background calculation",
# 		ManualExclude: "Manual exclude",
# 		BackgroundShenanigans: "Background Shenanigans detected in pixel",
# 	}


# Path: tests/test_quality.py
import pytest
import numpy as np
import conftest # noqa: F401
from photometry.quality import CorrectorQualityFlags, TESSQualityFlags, PixelQualityFlags

	assert len(dc) == 2
	assert 'Manual exclude' in dc

	# A default bitmask should be set:
	dmask = TESSQualityFlags.DEFAULT_BITMASK
	print(dmask)

	# Test HARDEST_BITMASK:
	hrep = TESSQualityFlags.binary_repr(TESSQualityFlags.HARDEST_BITMASK)
	assert hrep == '11111111111111111111111111111111'

	#for flag in TESSQualityFlags:
	#	print(flag)
	#	indx = TESSQualityFlags.filter(quality, flag)
	#	rep = CorrectorQualityFlags.binary_repr(quality)
	#	assert len(rep) == 32

#--------------------------------------------------------------------------------------------------
def test_PixelQuality():
	"""Test of TESSQualityFlags"""

	# Quality flags:
	quality = np.zeros(10, dtype='int32')
	print(quality)

	# When quality is all zeros, filter should give all True:
	assert all(PixelQualityFlags.filter(quality))

	# Assign a random flag to one of the qualities and see if it filters:
	quality[3] = PixelQualityFlags.ManualExclude | PixelQualityFlags.BackgroundShenanigans

	indx = TESSQualityFlags.filter(quality, PixelQualityFlags.ManualExclude)