def setUp(self): np.random.seed(1) self.bbox = Box2I(Point2I(1000, 2000), Extent2I(200, 100)) self.filters = ["G", "R", "I"] self.imgValue = 10 images = [ImageF(self.bbox, self.imgValue) for f in self.filters] mImage = MultibandImage.fromImages(self.filters, images) self.Mask = Mask[MaskPixel] # Store the default mask planes for later use maskPlaneDict = self.Mask().getMaskPlaneDict() self.defaultMaskPlanes = sorted(maskPlaneDict, key=maskPlaneDict.__getitem__) # reset so tests will be deterministic self.Mask.clearMaskPlaneDict() for p in ("BAD", "SAT", "INTRP", "CR", "EDGE"): self.Mask.addMaskPlane(p) self.maskValue = self.Mask.getPlaneBitMask("BAD") singles = [self.Mask(self.bbox) for f in range(len(self.filters))] for n in range(len(singles)): singles[n].set(self.maskValue) mMask = MultibandMask.fromMasks(self.filters, singles) self.varValue = 1e-2 images = [ImageF(self.bbox, self.varValue) for f in self.filters] mVariance = MultibandImage.fromImages(self.filters, images) self.maskedImage = MultibandMaskedImage(self.filters, image=mImage, mask=mMask, variance=mVariance)
def setUp(self): np.random.seed(1) self.bbox1 = Box2I(Point2I(1000, 2000), Extent2I(200, 100)) self.filters = ["G", "R", "I", "Z", "Y"] self.value1, self.value2 = 10, 100 images = [ImageF(self.bbox1, self.value1) for f in self.filters] self.mImage1 = MultibandImage.fromImages(self.filters, images) self.bbox2 = Box2I(Point2I(1100, 2025), Extent2I(30, 50)) images = [ImageF(self.bbox2, self.value2) for f in self.filters] self.mImage2 = MultibandImage.fromImages(self.filters, images)
def _testMaskedmageModification(testCase, maskedImage): images = [ ImageF(testCase.bbox, 10 * testCase.imgValue) for f in testCase.filters ] mImage = MultibandImage.fromImages(testCase.filters, images) maskedImage.image.array = mImage.array testCase.assertFloatsEqual(maskedImage.image["G"].array, mImage.array[0]) testCase.assertFloatsEqual(maskedImage["G"].image.array, mImage.array[0]) singles = [ testCase.Mask(testCase.bbox) for f in range(len(testCase.filters)) ] for n in range(len(singles)): singles[n].set(testCase.maskValue * 2) mMask = MultibandMask.fromMasks(testCase.filters, singles) maskedImage.mask.array = mMask.array testCase.assertFloatsEqual(maskedImage.mask["G"].array, mMask.array[0]) testCase.assertFloatsEqual(maskedImage["G"].mask.array, mMask.array[0]) images = [ ImageF(testCase.bbox, .1 * testCase.varValue) for f in testCase.filters ] mVariance = MultibandImage.fromImages(testCase.filters, images) maskedImage.variance.array = mVariance.array testCase.assertFloatsEqual(maskedImage.variance["G"].array, mVariance.array[0]) testCase.assertFloatsEqual(maskedImage["G"].variance.array, mVariance.array[0]) subBox = Box2I(Point2I(1100, 2025), Extent2I(30, 50)) maskedImage.image[:, subBox].array = 12 testCase.assertFloatsEqual(maskedImage.image["G", subBox].array, 12) testCase.assertFloatsEqual(maskedImage["G", subBox].image.array, 12) maskedImage["R", subBox].image[:] = 15 testCase.assertFloatsEqual(maskedImage.image["R", subBox].array, 15) testCase.assertFloatsEqual(maskedImage["R", subBox].image.array, 15) maskedImage.mask[:, subBox].array = 64 testCase.assertFloatsEqual(maskedImage.mask["G", subBox].array, 64) testCase.assertFloatsEqual(maskedImage["G", subBox].mask.array, 64) maskedImage["R", subBox].mask[:] = 128 testCase.assertFloatsEqual(maskedImage.mask["R", subBox].array, 128) testCase.assertFloatsEqual(maskedImage["R", subBox].mask.array, 128) maskedImage.variance[:, subBox].array = 1e-6 testCase.assertFloatsEqual(maskedImage.variance["G", subBox].array, 1e-6) testCase.assertFloatsEqual(maskedImage["G", subBox].variance.array, 1e-6) maskedImage["R", subBox].variance[:] = 1e-7 testCase.assertFloatsEqual(maskedImage.variance["R", subBox].array, 1e-7) testCase.assertFloatsEqual(maskedImage["R", subBox].variance.array, 1e-7)
def projectSpans(radius, value, bbox, asArray): ss = SpanSet.fromShape(radius, Stencil.CIRCLE, offset=(10, 10)) image = ImageF(bbox) ss.setImage(image, value) if asArray: return image.array else: return image
def mean_overscans(imagefile, nexp=7, plots=None, verbose=False): if nexp is None: nexp = 7 result = [ ] # decay constant, amplitude, flux of image, residue of first overscan, sensor number, segment, run number for segment in range(1, 16 + 1): header = getheader(imagefile) info = [ header['LSST_NUM'], 'Segment {}'.format(segment), header['RUNNUM'].split()[0] ] image_untrimmed = ImageF(imagefile, segment) amp = makeAmplifierGeometry(imagefile) flat_mean = np.mean( imutils.trim(image_untrimmed, imaging=amp.imaging).array[:, -1]) # mean value of the last column of the image image = imutils.trim(image_untrimmed, imaging=amp.serial_overscan) overscans_mean = [ np.mean([image.array[i, j] for i in np.arange(len(image.array))]) for j in range(len(image.array[0])) ] bias = np.mean(overscans_mean[5:-2]) over_mean_subfit = overscans_mean[:nexp] params, cov = curve_fit(exp_fit, np.arange(nexp), over_mean_subfit, p0=(10, 10, 20000), bounds=([.1, 0, 0], [20, 300, 50000])) residue = params[1] / (flat_mean - bias) result.append([params[0], params[1], flat_mean, residue, *info]) if verbose: print('Segment {seg}:\n Decay : {p[0]:<10.03g} pixels\n Amplitude: {p[1]:<10.03g} '\ 'ADU\n Offset : {p[2]:<10.03g} ADU'.format(seg=segment, p=params)) if plots is None: continue fig = plt.figure(figsize=(10, 10)) plt.plot(over_mean_subfit, ls='none', marker='.') xfit = np.linspace(0, nexp - 1, 50) plt.plot(xfit, [exp_fit(x, *params) for x in xfit]) plt.title( 'Superflat Mean Serial Overscan in {0} {1} Run {2}'.format(*info)) plt.figtext(0.5,0.5,('Decay constant: {p[0]:.03g} pixels \nAmplitude: {p[1]:.03g}'\ ' ADU\nImage flux: {0:.00f} ADU\nResidue in first overscan pixel: {1:.03%}').format(flat_mean,residue,p=params)) plt.ylabel('ADU') plt.xlabel('Pixel') plt.legend(['Data', 'Fit']) fig.patch.set_facecolor('white') plt.savefig(('{0}/{1}_{2}_run{3}.png'.format(plots, *info)).replace(" ", "")) plt.close(fig) return result
def flats(imagefile, verbose=False): result = {} ccd = makeAmplifierGeometry(imagefile) for segment in range(1, 16 + 1): image_untrimmed = ImageF(imagefile, segment) #imutils.dm_hdu(segment)) amp = ccd[segment] flatmean = imutils.mean(imutils.unbias_and_trim \ (image_untrimmed, overscan=ccd.serial_overscan, imaging=ccd.imaging)) result[segment] = flatmean return result
def setUp(self): np.random.seed(1) self.spans = SpanSet.fromShape(2, Stencil.CIRCLE) self.footprint = Footprint(self.spans) self.footprint.addPeak(3, 4, 10) self.footprint.addPeak(8, 1, 2) fp = Footprint(self.spans) for peak in self.footprint.getPeaks(): fp.addPeak(peak["f_x"], peak["f_y"], peak["peakValue"]) self.peaks = fp.getPeaks() self.bbox = self.footprint.getBBox() self.filters = ("G", "R", "I") singles = [] images = [] for n, f in enumerate(self.filters): image = ImageF(self.spans.getBBox()) image.set(n) images.append(image.array) maskedImage = MaskedImageF(image) heavy = makeHeavyFootprint(self.footprint, maskedImage) singles.append(heavy) self.image = np.array(images) self.mFoot = MultibandFootprint(self.filters, singles)