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

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

423

424

425

426

427

428

429

430

431

432

433

434

435

436

437

438

439

440

441

442

443

444

445

446

447

448

449

450

451

452

453

454

455

456

457

458

459

460

461

462

463

464

465

466

467

468

469

470

471

472

473

474

475

476

477

478

479

480

481

482

483

484

485

486

487

488

489

490

491

492

493

494

495

496

497

498

499

500

501

502

503

504

505

506

507

508

509

510

511

512

513

514

515

516

517

518

519

520

521

522

523

524

525

526

527

528

529

# 

# LSST Data Management System 

# Copyright 2008, 2009, 2010 LSST Corporation. 

# 

# This product includes software developed by the 

# LSST Project (http://www.lsst.org/). 

# 

# This program is free software: you can redistribute it and/or modify 

# it under the terms of the GNU General Public License as published by 

# the Free Software Foundation, either version 3 of the License, or 

# (at your option) any later version. 

# 

# This program is distributed in the hope that it will be useful, 

# but WITHOUT ANY WARRANTY; without even the implied warranty of 

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

# GNU General Public License for more details. 

# 

# You should have received a copy of the LSST License Statement and 

# the GNU General Public License along with this program. If not, 

# see <http://www.lsstcorp.org/LegalNotices/>. 

# 

import math 

 

import numpy 

 

import lsst.afw.geom as afwGeom 

import lsst.afw.image as afwImage 

import lsst.afw.detection as afwDetection 

import lsst.afw.math as afwMath 

import lsst.meas.algorithms as measAlg 

import lsst.pex.exceptions as pexExcept 

import lsst.afw.cameraGeom as camGeom 

 

from lsst.pipe.base import Struct 

 

 

def createPsf(fwhm): 

"""Make a double Gaussian PSF 

 

@param[in] fwhm FWHM of double Gaussian smoothing kernel 

@return measAlg.DoubleGaussianPsf 

""" 

ksize = 4*int(fwhm) + 1 

return measAlg.DoubleGaussianPsf(ksize, ksize, fwhm/(2*math.sqrt(2*math.log(2)))) 

 

 

def transposeMaskedImage(maskedImage): 

"""Make a transposed copy of a masked image 

 

@param[in] maskedImage afw.image.MaskedImage to process 

@return transposed masked image 

""" 

transposed = maskedImage.Factory(afwGeom.Extent2I(maskedImage.getHeight(), maskedImage.getWidth())) 

transposed.getImage().getArray()[:] = maskedImage.getImage().getArray().T 

transposed.getMask().getArray()[:] = maskedImage.getMask().getArray().T 

transposed.getVariance().getArray()[:] = maskedImage.getVariance().getArray().T 

return transposed 

 

 

def interpolateDefectList(maskedImage, defectList, fwhm, fallbackValue=None): 

"""Interpolate over defects specified in a defect list 

 

@param[in,out] maskedImage masked image to process 

@param[in] defectList defect list 

@param[in] fwhm FWHM of double Gaussian smoothing kernel 

@param[in] fallbackValue fallback value if an interpolated value cannot be determined; 

if None then use clipped mean image value 

""" 

psf = createPsf(fwhm) 

70 ↛ 72line 70 didn't jump to line 72, because the condition on line 70 was never false if fallbackValue is None: 

fallbackValue = afwMath.makeStatistics(maskedImage.getImage(), afwMath.MEANCLIP).getValue() 

72 ↛ 73line 72 didn't jump to line 73, because the condition on line 72 was never true if 'INTRP' not in maskedImage.getMask().getMaskPlaneDict(): 

maskedImage.getMask.addMaskPlane('INTRP') 

measAlg.interpolateOverDefects(maskedImage, psf, defectList, fallbackValue, True) 

 

 

def defectListFromFootprintList(fpList): 

"""Compute a defect list from a footprint list, optionally growing the footprints 

 

@param[in] fpList footprint list 

""" 

defectList = [] 

for fp in fpList: 

for bbox in afwDetection.footprintToBBoxList(fp): 

defect = measAlg.Defect(bbox) 

defectList.append(defect) 

return defectList 

 

 

def transposeDefectList(defectList): 

"""Make a transposed copy of a defect list 

 

@param[in] defectList a list of defects (afw.meas.algorithms.Defect) 

@return a defect list with transposed defects 

""" 

retDefectList = [] 

for defect in defectList: 

bbox = defect.getBBox() 

nbbox = afwGeom.Box2I(afwGeom.Point2I(bbox.getMinY(), bbox.getMinX()), 

afwGeom.Extent2I(bbox.getDimensions()[1], bbox.getDimensions()[0])) 

retDefectList.append(measAlg.Defect(nbbox)) 

return retDefectList 

 

 

def maskPixelsFromDefectList(maskedImage, defectList, maskName='BAD'): 

"""Set mask plane based on a defect list 

 

@param[in,out] maskedImage afw.image.MaskedImage to process; mask plane is updated 

@param[in] defectList a list of defects (afw.meas.algorithms.Defect) 

@param[in] maskName mask plane name 

""" 

# mask bad pixels 

mask = maskedImage.getMask() 

bitmask = mask.getPlaneBitMask(maskName) 

for defect in defectList: 

bbox = defect.getBBox() 

afwGeom.SpanSet(bbox).clippedTo(mask.getBBox()).setMask(mask, bitmask) 

 

 

def getDefectListFromMask(maskedImage, maskName): 

"""Compute a defect list from a specified mask plane 

 

@param[in] maskedImage masked image to process 

@param[in] maskName mask plane name, or list of names 

""" 

mask = maskedImage.getMask() 

thresh = afwDetection.Threshold(mask.getPlaneBitMask(maskName), afwDetection.Threshold.BITMASK) 

fpList = afwDetection.FootprintSet(mask, thresh).getFootprints() 

return defectListFromFootprintList(fpList) 

 

 

def makeThresholdMask(maskedImage, threshold, growFootprints=1, maskName='SAT'): 

"""Mask pixels based on threshold detection 

 

@param[in,out] maskedImage afw.image.MaskedImage to process; the mask is altered 

@param[in] threshold detection threshold 

@param[in] growFootprints amount by which to grow footprints of detected regions 

@param[in] maskName mask plane name 

@return a list of defects (meas.algrithms.Defect) of regions set in the mask. 

""" 

# find saturated regions 

thresh = afwDetection.Threshold(threshold) 

fs = afwDetection.FootprintSet(maskedImage, thresh) 

 

145 ↛ 146line 145 didn't jump to line 146, because the condition on line 145 was never true if growFootprints > 0: 

fs = afwDetection.FootprintSet(fs, growFootprints) 

 

fpList = fs.getFootprints() 

# set mask 

mask = maskedImage.getMask() 

bitmask = mask.getPlaneBitMask(maskName) 

afwDetection.setMaskFromFootprintList(mask, fpList, bitmask) 

 

return defectListFromFootprintList(fpList) 

 

 

def interpolateFromMask(maskedImage, fwhm, growFootprints=1, maskName='SAT', fallbackValue=None): 

"""Interpolate over defects identified by a particular mask plane 

 

@param[in,out] maskedImage afw.image.MaskedImage to process 

@param[in] fwhm FWHM of double Gaussian smoothing kernel 

@param[in] growFootprints amount by which to grow footprints of detected regions 

@param[in] maskName mask plane name 

@param[in] fallbackValue value of last resort for interpolation 

""" 

mask = maskedImage.getMask() 

thresh = afwDetection.Threshold(mask.getPlaneBitMask(maskName), afwDetection.Threshold.BITMASK) 

fpSet = afwDetection.FootprintSet(mask, thresh) 

169 ↛ 174line 169 didn't jump to line 174, because the condition on line 169 was never false if growFootprints > 0: 

fpSet = afwDetection.FootprintSet(fpSet, rGrow=growFootprints, isotropic=False) 

# If we are interpolating over an area larger than the original masked region, we need 

# to expand the original mask bit to the full area to explain why we interpolated there. 

fpSet.setMask(mask, maskName) 

defectList = defectListFromFootprintList(fpSet.getFootprints()) 

interpolateDefectList(maskedImage, defectList, fwhm, fallbackValue=fallbackValue) 

 

 

def saturationCorrection(maskedImage, saturation, fwhm, growFootprints=1, interpolate=True, maskName='SAT', 

fallbackValue=None): 

"""Mark saturated pixels and optionally interpolate over them 

 

@param[in,out] maskedImage afw.image.MaskedImage to process 

@param[in] saturation saturation level (used as a detection threshold) 

@param[in] fwhm FWHM of double Gaussian smoothing kernel 

@param[in] growFootprints amount by which to grow footprints of detected regions 

@param[in] interpolate interpolate over saturated pixels? 

@param[in] maskName mask plane name 

@param[in] fallbackValue value of last resort for interpolation 

""" 

defectList = makeThresholdMask( 

maskedImage=maskedImage, 

threshold=saturation, 

growFootprints=growFootprints, 

maskName=maskName, 

) 

if interpolate: 

interpolateDefectList(maskedImage, defectList, fwhm, fallbackValue=fallbackValue) 

 

 

def biasCorrection(maskedImage, biasMaskedImage): 

"""Apply bias correction in place 

 

@param[in,out] maskedImage masked image to correct 

@param[in] biasMaskedImage bias, as a masked image 

""" 

206 ↛ 207line 206 didn't jump to line 207, because the condition on line 206 was never true if maskedImage.getBBox(afwImage.LOCAL) != biasMaskedImage.getBBox(afwImage.LOCAL): 

raise RuntimeError("maskedImage bbox %s != biasMaskedImage bbox %s" % 

(maskedImage.getBBox(afwImage.LOCAL), biasMaskedImage.getBBox(afwImage.LOCAL))) 

maskedImage -= biasMaskedImage 

 

 

def darkCorrection(maskedImage, darkMaskedImage, expScale, darkScale, invert=False): 

"""Apply dark correction in place 

 

maskedImage -= dark * expScaling / darkScaling 

 

@param[in,out] maskedImage afw.image.MaskedImage to correct 

@param[in] darkMaskedImage dark afw.image.MaskedImage 

@param[in] expScale exposure scale 

@param[in] darkScale dark scale 

@param[in] invert if True, remove the dark from an already-corrected image 

""" 

223 ↛ 224line 223 didn't jump to line 224, because the condition on line 223 was never true if maskedImage.getBBox(afwImage.LOCAL) != darkMaskedImage.getBBox(afwImage.LOCAL): 

raise RuntimeError("maskedImage bbox %s != darkMaskedImage bbox %s" % 

(maskedImage.getBBox(afwImage.LOCAL), darkMaskedImage.getBBox(afwImage.LOCAL))) 

 

scale = expScale / darkScale 

228 ↛ 231line 228 didn't jump to line 231, because the condition on line 228 was never false if not invert: 

maskedImage.scaledMinus(scale, darkMaskedImage) 

else: 

maskedImage.scaledPlus(scale, darkMaskedImage) 

 

 

def updateVariance(maskedImage, gain, readNoise): 

"""Set the variance plane based on the image plane 

 

@param[in,out] maskedImage afw.image.MaskedImage; image plane is read and variance plane is written 

@param[in] gain amplifier gain (e-/ADU) 

@param[in] readNoise amplifier read noise (ADU/pixel) 

""" 

var = maskedImage.getVariance() 

var[:] = maskedImage.getImage() 

var /= gain 

var += readNoise**2 

 

 

def flatCorrection(maskedImage, flatMaskedImage, scalingType, userScale=1.0, invert=False): 

"""Apply flat correction in place 

 

@param[in,out] maskedImage afw.image.MaskedImage to correct 

@param[in] flatMaskedImage flat field afw.image.MaskedImage 

@param[in] scalingType how to compute flat scale; one of 'MEAN', 'MEDIAN' or 'USER' 

@param[in] userScale scale to use if scalingType is 'USER', else ignored 

@param[in] invert if True, unflatten an already-flattened image instead. 

""" 

256 ↛ 257line 256 didn't jump to line 257, because the condition on line 256 was never true if maskedImage.getBBox(afwImage.LOCAL) != flatMaskedImage.getBBox(afwImage.LOCAL): 

raise RuntimeError("maskedImage bbox %s != flatMaskedImage bbox %s" % 

(maskedImage.getBBox(afwImage.LOCAL), flatMaskedImage.getBBox(afwImage.LOCAL))) 

 

# Figure out scale from the data 

# Ideally the flats are normalized by the calibration product pipelin, but this allows some flexibility 

# in the case that the flat is created by some other mechanism. 

263 ↛ 264line 263 didn't jump to line 264, because the condition on line 263 was never true if scalingType == 'MEAN': 

flatScale = afwMath.makeStatistics(flatMaskedImage.getImage(), afwMath.MEAN).getValue(afwMath.MEAN) 

265 ↛ 266line 265 didn't jump to line 266, because the condition on line 265 was never true elif scalingType == 'MEDIAN': 

flatScale = afwMath.makeStatistics(flatMaskedImage.getImage(), 

afwMath.MEDIAN).getValue(afwMath.MEDIAN) 

268 ↛ 271line 268 didn't jump to line 271, because the condition on line 268 was never false elif scalingType == 'USER': 

flatScale = userScale 

else: 

raise pexExcept.Exception('%s : %s not implemented' % ("flatCorrection", scalingType)) 

 

273 ↛ 276line 273 didn't jump to line 276, because the condition on line 273 was never false if not invert: 

maskedImage.scaledDivides(1.0/flatScale, flatMaskedImage) 

else: 

maskedImage.scaledMultiplies(1.0/flatScale, flatMaskedImage) 

 

 

def illuminationCorrection(maskedImage, illumMaskedImage, illumScale): 

"""Apply illumination correction in place 

 

@param[in,out] maskedImage afw.image.MaskedImage to correct 

@param[in] illumMaskedImage illumination correction masked image 

@param[in] illumScale scale value for illumination correction 

""" 

286 ↛ 287line 286 didn't jump to line 287, because the condition on line 286 was never true if maskedImage.getBBox(afwImage.LOCAL) != illumMaskedImage.getBBox(afwImage.LOCAL): 

raise RuntimeError("maskedImage bbox %s != illumMaskedImage bbox %s" % 

(maskedImage.getBBox(afwImage.LOCAL), illumMaskedImage.getBBox(afwImage.LOCAL))) 

 

maskedImage.scaledDivides(1./illumScale, illumMaskedImage) 

 

 

def overscanCorrection(ampMaskedImage, overscanImage, fitType='MEDIAN', order=1, collapseRej=3.0, 

statControl=None): 

"""Apply overscan correction in-place 

 

The ``ampMaskedImage`` and ``overscanImage`` are modified, with the fit 

subtracted. Note that the ``overscanImage`` should not be a subimage of 

the ``ampMaskedImage``, to avoid being subtracted twice. 

 

Parameters 

---------- 

ampMaskedImage : `lsst.afw.image.MaskedImage` 

Image of amplifier to correct; modified. 

overscanImage : `lsst.afw.image.Image` or `lsst.afw.image.MaskedImage` 

Image of overscan; modified. 

fitType : `str` 

Type of fit for overscan correction. May be one of: 

 

- ``MEAN``: use mean of overscan. 

- ``MEDIAN``: use median of overscan. 

- ``POLY``: fit with ordinary polynomial. 

- ``CHEB``: fit with Chebyshev polynomial. 

- ``LEG``: fit with Legendre polynomial. 

- ``NATURAL_SPLINE``: fit with natural spline. 

- ``CUBIC_SPLINE``: fit with cubic spline. 

- ``AKIMA_SPLINE``: fit with Akima spline. 

 

order : `int` 

Polynomial order or number of spline knots; ignored unless 

``fitType`` indicates a polynomial or spline. 

collapseRej : `float` 

Rejection threshold (sigma) for collapsing dimension of overscan. 

statControl : `lsst.afw.math.StatisticsControl` 

Statistics control object. 

 

Returns 

------- 

result : `lsst.pipe.base.Struct` 

Result struct with components: 

 

- ``imageFit``: Value(s) removed from image (scalar or 

`lsst.afw.image.Image`) 

- ``overscanFit``: Value(s) removed from overscan (scalar or 

`lsst.afw.image.Image`) 

""" 

ampImage = ampMaskedImage.getImage() 

338 ↛ 340line 338 didn't jump to line 340, because the condition on line 338 was never false if statControl is None: 

statControl = afwMath.StatisticsControl() 

340 ↛ 341line 340 didn't jump to line 341, because the condition on line 340 was never true if fitType == 'MEAN': 

offImage = afwMath.makeStatistics(overscanImage, afwMath.MEAN, statControl).getValue(afwMath.MEAN) 

overscanFit = offImage 

elif fitType == 'MEDIAN': 

offImage = afwMath.makeStatistics(overscanImage, afwMath.MEDIAN, statControl).getValue(afwMath.MEDIAN) 

overscanFit = offImage 

346 ↛ 476line 346 didn't jump to line 476, because the condition on line 346 was never false elif fitType in ('POLY', 'CHEB', 'LEG', 'NATURAL_SPLINE', 'CUBIC_SPLINE', 'AKIMA_SPLINE'): 

if hasattr(overscanImage, "getImage"): 

biasArray = overscanImage.getImage().getArray() 

biasArray = numpy.ma.masked_where(overscanImage.getMask().getArray() & statControl.getAndMask(), 

biasArray) 

else: 

biasArray = overscanImage.getArray() 

# Fit along the long axis, so collapse along each short row and fit the resulting array 

shortInd = numpy.argmin(biasArray.shape) 

if shortInd == 0: 

# Convert to some 'standard' representation to make things easier 

biasArray = numpy.transpose(biasArray) 

 

# Do a single round of clipping to weed out CR hits and signal leaking into the overscan 

percentiles = numpy.percentile(biasArray, [25.0, 50.0, 75.0], axis=1) 

medianBiasArr = percentiles[1] 

stdevBiasArr = 0.74*(percentiles[2] - percentiles[0]) # robust stdev 

diff = numpy.abs(biasArray - medianBiasArr[:, numpy.newaxis]) 

biasMaskedArr = numpy.ma.masked_where(diff > collapseRej*stdevBiasArr[:, numpy.newaxis], biasArray) 

collapsed = numpy.mean(biasMaskedArr, axis=1) 

366 ↛ 367line 366 didn't jump to line 367, because the condition on line 366 was never true if collapsed.mask.sum() > 0: 

collapsed.data[collapsed.mask] = numpy.mean(biasArray.data[collapsed.mask], axis=1) 

del biasArray, percentiles, stdevBiasArr, diff, biasMaskedArr 

 

if shortInd == 0: 

collapsed = numpy.transpose(collapsed) 

 

num = len(collapsed) 

indices = 2.0*numpy.arange(num)/float(num) - 1.0 

 

if fitType in ('POLY', 'CHEB', 'LEG'): 

# A numpy polynomial 

poly = numpy.polynomial 

fitter, evaler = {"POLY": (poly.polynomial.polyfit, poly.polynomial.polyval), 

"CHEB": (poly.chebyshev.chebfit, poly.chebyshev.chebval), 

"LEG": (poly.legendre.legfit, poly.legendre.legval), 

}[fitType] 

 

coeffs = fitter(indices, collapsed, order) 

fitBiasArr = evaler(indices, coeffs) 

386 ↛ 416line 386 didn't jump to line 416, because the condition on line 386 was never false elif 'SPLINE' in fitType: 

# An afw interpolation 

numBins = order 

# 

# numpy.histogram needs a real array for the mask, but numpy.ma "optimises" the case 

# no-values-are-masked by replacing the mask array by a scalar, numpy.ma.nomask 

# 

# Issue DM-415 

# 

collapsedMask = collapsed.mask 

try: 

397 ↛ 402line 397 didn't jump to line 402, because the condition on line 397 was never false if collapsedMask == numpy.ma.nomask: 

collapsedMask = numpy.array(len(collapsed)*[numpy.ma.nomask]) 

except ValueError: # If collapsedMask is an array the test fails [needs .all()] 

pass 

 

numPerBin, binEdges = numpy.histogram(indices, bins=numBins, 

weights=1-collapsedMask.astype(int)) 

# Binning is just a histogram, with weights equal to the values. 

# Use a similar trick to get the bin centers (this deals with different numbers per bin). 

with numpy.errstate(invalid="ignore"): # suppress NAN warnings 

values = numpy.histogram(indices, bins=numBins, 

weights=collapsed.data*~collapsedMask)[0]/numPerBin 

binCenters = numpy.histogram(indices, bins=numBins, 

weights=indices*~collapsedMask)[0]/numPerBin 

interp = afwMath.makeInterpolate(binCenters.astype(float)[numPerBin > 0], 

values.astype(float)[numPerBin > 0], 

afwMath.stringToInterpStyle(fitType)) 

fitBiasArr = numpy.array([interp.interpolate(i) for i in indices]) 

 

import lsstDebug 

417 ↛ 418line 417 didn't jump to line 418, because the condition on line 417 was never true if lsstDebug.Info(__name__).display: 

import matplotlib.pyplot as plot 

figure = plot.figure(1) 

figure.clear() 

axes = figure.add_axes((0.1, 0.1, 0.8, 0.8)) 

axes.plot(indices[~collapsedMask], collapsed[~collapsedMask], 'k+') 

if collapsedMask.sum() > 0: 

axes.plot(indices[collapsedMask], collapsed.data[collapsedMask], 'b+') 

axes.plot(indices, fitBiasArr, 'r-') 

figure.show() 

prompt = "Press Enter or c to continue [chp]... " 

while True: 

ans = input(prompt).lower() 

if ans in ("", "c",): 

break 

if ans in ("p",): 

import pdb 

pdb.set_trace() 

elif ans in ("h", ): 

print("h[elp] c[ontinue] p[db]") 

figure.close() 

 

offImage = ampImage.Factory(ampImage.getDimensions()) 

offArray = offImage.getArray() 

overscanFit = afwImage.ImageF(overscanImage.getDimensions()) 

overscanArray = overscanFit.getArray() 

if shortInd == 1: 

offArray[:, :] = fitBiasArr[:, numpy.newaxis] 

overscanArray[:, :] = fitBiasArr[:, numpy.newaxis] 

else: 

offArray[:, :] = fitBiasArr[numpy.newaxis, :] 

overscanArray[:, :] = fitBiasArr[numpy.newaxis, :] 

 

# We don't trust any extrapolation: mask those pixels as SUSPECT 

# This will occur when the top and or bottom edges of the overscan 

# contain saturated values. The values will be extrapolated from 

# the surrounding pixels, but we cannot entirely trust the value of 

# the extrapolation, and will mark the image mask plane to flag the 

# image as such. 

mask = ampMaskedImage.getMask() 

maskArray = mask.getArray() if shortInd == 1 else mask.getArray().transpose() 

suspect = mask.getPlaneBitMask("SUSPECT") 

try: 

460 ↛ 477line 460 didn't jump to line 477, because the condition on line 460 was never false if collapsed.mask == numpy.ma.nomask: 

# There is no mask, so the whole array is fine 

pass 

except ValueError: # If collapsed.mask is an array the test fails [needs .all()] 

464 ↛ 467line 464 didn't jump to line 467, because the loop on line 464 didn't complete for low in range(num): 

465 ↛ 464line 465 didn't jump to line 464, because the condition on line 465 was never false if not collapsed.mask[low]: 

break 

467 ↛ 468line 467 didn't jump to line 468, because the condition on line 467 was never true if low > 0: 

maskArray[:low, :] |= suspect 

469 ↛ 472line 469 didn't jump to line 472, because the loop on line 469 didn't complete for high in range(1, num): 

470 ↛ 469line 470 didn't jump to line 469, because the condition on line 470 was never false if not collapsed.mask[-high]: 

break 

472 ↛ 473line 472 didn't jump to line 473, because the condition on line 472 was never true if high > 1: 

maskArray[-high:, :] |= suspect 

 

else: 

raise pexExcept.Exception('%s : %s an invalid overscan type' % ("overscanCorrection", fitType)) 

ampImage -= offImage 

overscanImage -= overscanFit 

return Struct(imageFit=offImage, overscanFit=overscanFit) 

 

 

def attachTransmissionCurve(exposure, opticsTransmission=None, filterTransmission=None, 

sensorTransmission=None, atmosphereTransmission=None): 

"""Attach a TransmissionCurve to an Exposure, given separate curves for 

different components. 

 

Parameters 

---------- 

exposure : `lsst.afw.image.Exposure` 

Exposure object to modify by attaching the product of all given 

``TransmissionCurves`` in post-assembly trimmed detector coordinates. 

Must have a valid ``Detector`` attached that matches the detector 

associated with sensorTransmission. 

opticsTransmission : `lsst.afw.image.TransmissionCurve` 

A ``TransmissionCurve`` that represents the throughput of the optics, 

to be evaluated in focal-plane coordinates. 

filterTransmission : `lsst.afw.image.TransmissionCurve` 

A ``TransmissionCurve`` that represents the throughput of the filter 

itself, to be evaluated in focal-plane coordinates. 

sensorTransmission : `lsst.afw.image.TransmissionCurve` 

A ``TransmissionCurve`` that represents the throughput of the sensor 

itself, to be evaluated in post-assembly trimmed detector coordinates. 

atmosphereTransmission : `lsst.afw.image.TransmissionCurve` 

A ``TransmissionCurve`` that represents the throughput of the 

atmosphere, assumed to be spatially constant. 

 

All ``TransmissionCurve`` arguments are optional; if none are provided, the 

attached ``TransmissionCurve`` will have unit transmission everywhere. 

 

Returns 

------- 

combined : ``lsst.afw.image.TransmissionCurve`` 

The TransmissionCurve attached to the exposure. 

""" 

combined = afwImage.TransmissionCurve.makeIdentity() 

if atmosphereTransmission is not None: 

combined *= atmosphereTransmission 

if opticsTransmission is not None: 

combined *= opticsTransmission 

if filterTransmission is not None: 

combined *= filterTransmission 

detector = exposure.getDetector() 

fpToPix = detector.getTransform(fromSys=camGeom.FOCAL_PLANE, 

toSys=camGeom.PIXELS) 

combined = combined.transformedBy(fpToPix) 

if sensorTransmission is not None: 

combined *= sensorTransmission 

exposure.getInfo().setTransmissionCurve(combined) 

return combined