Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

 

__all__ = ["CfhtIsrTaskConfig", "CfhtIsrTask"] 

 

import numpy as np 

 

import lsst.pex.config as pexConfig 

from lsst.ip.isr import IsrTask 

 

 

class CfhtIsrTaskConfig(IsrTask.ConfigClass): 

safe = pexConfig.Field( 

dtype=float, 

doc="Safety margin for CFHT sensors gain determination", 

default=0.95, 

) 

 

def setDefaults(self): 

IsrTask.ConfigClass.setDefaults(self) 

 

 

class CfhtIsrTask(IsrTask): 

ConfigClass = CfhtIsrTaskConfig 

 

def run(self, ccdExposure, bias=None, linearizer=None, dark=None, flat=None, defects=None, 

fringes=None, bfKernel=None, camera=None, **kwds): 

"""Perform instrument signature removal on an exposure 

 

Steps include: 

- Detect saturation, apply overscan correction, bias, dark and flat 

- Perform CCD assembly 

- Interpolate over defects, saturated pixels and all NaNs 

- Persist the ISR-corrected exposure as "postISRCCD" if config.doWrite is True 

 

Parameters 

---------- 

ccdExposure : `lsst.afw.image.Exposure` 

Detector data. 

bias : `lsst.afw.image.exposure` 

Exposure of bias frame. 

linearizer : `lsst.ip.isr.LinearizeBase` callable 

Linearizing functor; a subclass of lsst.ip.isr.LinearizeBase. 

dark : `lsst.afw.image.exposure` 

Exposure of dark frame. 

flat : `lsst.afw.image.exposure` 

Exposure of flatfield. 

defects : `list` 

list of detects 

fringes : `lsst.afw.image.exposure` or `list` of `lsst.afw.image.exposure` 

exposure of fringe frame or list of fringe exposure 

bfKernel : None 

kernel used for brighter-fatter correction; currently unsupported 

camera : `lsst.afw.cameraGeom.Camera` 

Camera geometry, used by addDistortionModel. 

**kwds : `dict` 

additional kwargs forwarded to IsrTask.run. 

 

Returns 

------- 

struct : `lsst.pipe.base.Struct` with fields: 

- exposure: the exposure after application of ISR 

""" 

if bfKernel is not None: 

raise ValueError("CFHT ISR does not currently support brighter-fatter correction.") 

 

ccd = ccdExposure.getDetector() 

floatExposure = self.convertIntToFloat(ccdExposure) 

metadata = floatExposure.getMetadata() 

 

# Detect saturation 

# Saturation values recorded in the fits hader is not reliable, try to estimate it from 

# the pixel vales 

# Find the peak location in the high end part the pixel values' histogram and set the saturation 

# level at safe * (peak location) where safe is a configurable parameter (typically 0.95) 

image = floatExposure.getMaskedImage().getImage() 

imageArray = image.getArray() 

maxValue = np.max(imageArray) 

if maxValue > 60000.0: 

hist, bin_edges = np.histogram(imageArray.ravel(), bins=100, range=(60000.0, maxValue+1.0)) 

saturate = int(self.config.safe*bin_edges[np.argmax(hist)]) 

else: 

saturate = metadata.getScalar("SATURATE") 

self.log.info("Saturation set to %d" % saturate) 

 

for amp in ccd: 

amp.setSaturation(saturate) 

if amp.getName() == "A": 

amp.setGain(metadata.getScalar("GAINA")) 

rdnA = metadata.getScalar("RDNOISEA") 

# Check if the noise value is making sense for this amp. If not, replace with value 

# stored in RDNOISE slot. This change is necessary to process some old CFHT images 

# (visit : 7xxxxx) where RDNOISEA/B = 65535 

if rdnA > 60000.0: 

rdnA = metadata.getScalar("RDNOISE") 

amp.setReadNoise(rdnA) 

elif amp.getName() == "B": 

amp.setGain(metadata.getScalar("GAINB")) 

rdnB = metadata.getScalar("RDNOISEB") 

# Check if the noise value is making sense for this amp. If not, replace with value 

# stored in RDNOISE slot. This change is necessary to process some old CFHT images 

# (visit : 7xxxxx) where RDNOISEA/B = 65535 

if rdnB > 60000.0: 

rdnB = metadata.getScalar("RDNOISE") 

amp.setReadNoise(rdnB) 

else: 

raise ValueError("Unexpected amplifier name : %s"%(amp.getName())) 

 

return IsrTask.run(self, 

ccdExposure=ccdExposure, 

bias=bias, 

linearizer=linearizer, 

dark=dark, 

flat=flat, 

defects=defects, 

fringes=fringes, 

camera=camera, 

**kwds 

)