def testCameraGeomUtils(self): for cw in self.cameraList: camera = cw.camera cameraGeomUtils.showCamera( camera, referenceDetectorName=camera[0].getName()) ds9.incrDefaultFrame() for det in (camera[0], camera[1]): cameraGeomUtils.showCcd(det, isTrimmed=True, inCameraCoords=False) ds9.incrDefaultFrame() cameraGeomUtils.showCcd(det, isTrimmed=True, inCameraCoords=True) ds9.incrDefaultFrame() cameraGeomUtils.showCcd(det, isTrimmed=False, inCameraCoords=False) ds9.incrDefaultFrame() cameraGeomUtils.showCcd(det, isTrimmed=False, inCameraCoords=True) ds9.incrDefaultFrame() for amp in det: cameraGeomUtils.showAmp(amp) ds9.incrDefaultFrame()
def testRaw(self): """Test retrieval of raw image""" if display: global frame frame += 1 cameraGeomUtils.showCamera(self.butler.mapper.camera, frame=frame) for ccd in range(36): raw = self.butler.get("raw", self.dataId, ccd=ccd, immediate=True) self.assertExposure(raw, ccd) visitInfo = raw.getInfo().getVisitInfo() self.assertAlmostEqual(visitInfo.getDate().get(), self.dateAvg.get()) self.assertAnglesAlmostEqual(visitInfo.getEra(), self.era, maxDiff=0.1*degrees) self.assertAlmostEqual(visitInfo.getExposureTime(), self.exposureTime) self.assertAlmostEqual(visitInfo.getDarkTime(), self.darkTime) self.assertSpherePointsAlmostEqual(visitInfo.getBoresightRaDec(), self.boresightRaDec) self.assertSpherePointsAlmostEqual(visitInfo.getBoresightAzAlt(), self.boresightAzAlt) self.assertAlmostEqual(visitInfo.getBoresightAirmass(), self.boresightAirmass) self.assertTrue(math.isnan(visitInfo.getBoresightRotAngle())) self.assertEqual(visitInfo.getRotType(), self.rotType) observatory = visitInfo.getObservatory() self.assertAnglesAlmostEqual(observatory.getLongitude(), self.obs_longitude) self.assertAnglesAlmostEqual(observatory.getLatitude(), self.obs_latitude) self.assertAlmostEqual(observatory.getElevation(), self.obs_elevation) weather = visitInfo.getWeather() self.assertAlmostEqual(weather.getAirTemperature(), self.weath_airTemperature) self.assertAlmostEqual(weather.getAirPressure(), self.weath_airPressure) self.assertAlmostEqual(weather.getHumidity(), self.weath_humidity)
def displayCamera(args): """Display camera element according to command-line arguments @param[in] args: argparse.Namespace list of command-line arguments """ mapper = obs_hsc.HscMapper() camera = mapper.camera frame = 0 if args.showAmp: frame = 0 for ampStr in args.showAmp: if checkStr(ampStr, 'amp'): ccd, amp = ampStr.split() detector = camera[ccd] amplifier = detector[amp] cameraGeomUtils.showAmp(amplifier, frame=frame) frame += 1 if args.showCcd: frame = 0 for ccdStr in args.showCcd: if checkStr(ccdStr, 'ccd'): detector = camera[ccdStr] cameraGeomUtils.showCcd(detector, frame=frame) frame += 1 raftMap = {'0': [], '1': []} for det in camera: dName = det.getName() if dName.startswith('1'): raftMap['1'].append(dName) elif dName.startswith('0'): raftMap['0'].append(dName) else: raise RuntimeError("Did not recognize detector name") if args.showRaft: frame = 0 for raftStr in args.showRaft: if checkStr(raftStr, 'raft'): detectorList = [] for detector in camera: detName = detector.getName() if detName in raftMap[raftStr.lower()]: detectorList.append(detector) tmpCamera = Camera(raftStr, detectorList, camera._transformMap) cameraGeomUtils.showCamera(tmpCamera, frame=frame, binSize=1) frame += 1 if args.showCamera: cameraGeomUtils.showCamera(camera, frame=frame, binSize=args.cameraBinSize) if args.plotFocalPlane: cameraGeomUtils.plotFocalPlane(camera, 2., 2.)
def testCamera(self): """Test if we can build a Camera out of Rafts""" #print >> sys.stderr, "Skipping testCamera"; return cameraInfo = {"ampSerial" : CameraGeomTestCase.ampSerial} camera = cameraGeomUtils.makeCamera(self.geomPolicy, cameraInfo=cameraInfo) if display: cameraGeomUtils.showCamera(camera, ) ds9.incrDefaultFrame() if False: print cameraGeomUtils.describeCamera(camera) self.assertEqual(camera.getAllPixels().getWidth(), cameraInfo["width"]) self.assertEqual(camera.getAllPixels().getHeight(), cameraInfo["height"]) for rx, ry, cx, cy, serial, cen in [(0, 0, 0, 0, 4, (-3.12, -2.02)), (0, 0, 150, 250, 20, (-3.12, 0.00)), (600, 300, 0, 0, 52, ( 1.10, -2.02)), (600, 300, 150, 250, 68, ( 1.10, 0.00)), ]: raft = cameraGeom.cast_Raft(camera.findDetectorPixel(afwGeom.PointD(rx, ry))) ccd = cameraGeom.cast_Ccd(raft.findDetectorPixel(afwGeom.Point2D(cx, cy))) if False: self.assertEqual(ccd.findAmp(afwGeom.PointI(153, 152), True).getId().getSerial(), serial) for i in range(2): self.assertAlmostEqual(ccd.getCenter()[i], cen[i]) name = "R:1,0" self.assertEqual(camera.findDetector(cameraGeom.Id(name)).getId().getName(), name) self.assertEqual(camera.getSize()[0], cameraInfo["widthMm"]) self.assertEqual(camera.getSize()[1], cameraInfo["heightMm"]) ps = raft.getPixelSize() # # Test mapping pixel <--> mm # for ix, iy, x, y in [(102, 500, -3.12, 2.02), (152, 525, -2.62, 2.27), (714, 500, 3.12, 2.02), ]: pix = afwGeom.PointD(ix, iy) # wrt raft LLC pos = afwGeom.PointD(x, y) # center of pixel wrt raft center posll = afwGeom.PointD(x, y) # llc of pixel wrt raft center self.assertEqual(camera.getPixelFromPosition(pos), pix) self.assertEqual(camera.getPositionFromPixel(pix), posll) # Check that we can find an Amp in the bowels of the camera ccdName = "C:0,0" amp = cameraGeomUtils.findAmp(camera, cameraGeom.Id(ccdName), 1, 2) self.assertEqual(amp.getId().getName(), "ID6") self.assertEqual(amp.getParent().getId().getName(), ccdName)
def displayCamera(args): """Display camera element according to command-line arguments @param[in] args: argparse.Namespace list of command-line arguments """ mapper = obs_hsc.HscMapper() camera = mapper.camera frame = 0 if args.showAmp: frame = 0 for ampStr in args.showAmp: if checkStr(ampStr, "amp"): ccd, amp = ampStr.split() detector = camera[ccd] amplifier = detector[amp] cameraGeomUtils.showAmp(amplifier, frame=frame) frame += 1 if args.showCcd: frame = 0 for ccdStr in args.showCcd: if checkStr(ccdStr, "ccd"): detector = camera[ccdStr] cameraGeomUtils.showCcd(detector, frame=frame) frame += 1 raftMap = {"0": [], "1": []} for det in camera: dName = det.getName() if dName.startswith("1"): raftMap["1"].append(dName) elif dName.startswith("0"): raftMap["0"].append(dName) else: raise RuntimeError("Did not recognize detector name") if args.showRaft: frame = 0 for raftStr in args.showRaft: if checkStr(raftStr, "raft"): detectorList = [] for detector in camera: detName = detector.getName() if detName in raftMap[raftStr.lower()]: detectorList.append(detector) tmpCamera = Camera(raftStr, detectorList, camera._transformMap) cameraGeomUtils.showCamera(tmpCamera, frame=frame, binSize=1) frame += 1 if args.showCamera: cameraGeomUtils.showCamera(camera, frame=frame, binSize=args.cameraBinSize) if args.plotFocalPlane: cameraGeomUtils.plotFocalPlane(camera, 2.0, 2.0)
def testRaw(self): """Test retrieval of raw image""" if display: global frame frame += 1 cameraGeomUtils.showCamera(self.butler.mapper.camera, frame=frame) for ccd in range(36): raw = self.butler.get("raw", self.dataId, ccd=ccd, immediate=True) self.assertExposure(raw, ccd)
def testCamera(self): """Test if we can build a Camera out of Rafts""" #print >> sys.stderr, "Skipping testCamera"; return cameraInfo = {"ampSerial" : CameraGeomTestCase.ampSerial} camera = cameraGeomUtils.makeCamera(self.geomPolicy, cameraInfo=cameraInfo) if display: cameraGeomUtils.showCamera(camera, ) ds9.incrDefaultFrame() if False: print cameraGeomUtils.describeCamera(camera) self.assertEqual(camera.getAllPixels().getWidth(), cameraInfo["width"]) self.assertEqual(camera.getAllPixels().getHeight(), cameraInfo["height"]) name = "R:1,0" self.assertEqual(camera.findDetector(cameraGeom.Id(name)).getId().getName(), name) self.assertEqual(camera.getSize().getMm()[0], cameraInfo["widthMm"]) self.assertEqual(camera.getSize().getMm()[1], cameraInfo["heightMm"]) # # Test mapping pixel <--> mm # for ix, iy, x, y in [(102, 500, -3.12, 2.02), (152, 525, -2.62, 2.27), (714, 500, 3.12, 2.02), ]: pix = afwGeom.PointD(ix, iy) # wrt raft LLC pos = cameraGeom.FpPoint(x, y) # center of pixel wrt raft center posll = cameraGeom.FpPoint(x, y) # llc of pixel wrt raft center # may need to restructure this since adding FpPoint if False: self.assertEqual(camera.getPixelFromPosition(pos), pix) # there is no unique mapping from a pixel to a focal plane position # ... the pixel could be on any ccd if False: self.assertEqual(camera.getPositionFromPixel(pix).getMm(), posll.getMm()) # Check that we can find an Amp in the bowels of the camera ccdName = "C:1,0" amp = cameraGeomUtils.findAmp(camera, cameraGeom.Id(ccdName), 1, 2) self.assertFalse(amp is None) self.assertEqual(amp.getId().getName(), "ID7") self.assertEqual(amp.getParent().getId().getName(), ccdName)
def makeMos(butler, mos, frame0=0, bin=32, nJob=20, visits=[]): if not visits: visits = [904288, 904320, 904330, 904520, 904534, 904536, 904538, 904670, 904672, 904674, 904676, 904678, 904786, 904788, 904790, 904792, 904794, 905034, 905036] frame = frame0 for visit in visits: if mos.has_key(visit): continue if bad.has_key(visit): print "Skipping bad visit %d: %s" % (visit, bad[visit]) continue global labels try: md = butler.get("raw_md", visit=visit, ccd=10) labels[visit] = afwImage.Filter(md).getName() except RuntimeError as e: print e mos[visit] = cgUtils.showCamera(butler.get("camera"), cgUtils.ButlerImage(butler, visit=visit, callback=utils.trimRemoveCrCallback, verbose=True), nJob=nJob, frame=frame, bin=bin, title=visit, overlay=True, names=False) frame += 1
def makeMos(butler, mos, frame0=0, bin=32, nJob=20, visits=[]): if not visits: visits = [904288, 904320, 904330, 904520, 904534, 904536, 904538, 904670, 904672, 904674, 904676, 904678, 904786, 904788, 904790, 904792, 904794, 905034, 905036] frame = frame0 for visit in visits: if visit in mos: continue if visit in bad: print("Skipping bad visit %d: %s" % (visit, bad[visit])) continue global labels try: md = butler.get("raw_md", visit=visit, ccd=10) labels[visit] = afwImage.Filter(md).getName() except RuntimeError as e: print(e) mos[visit] = cgUtils.showCamera(butler.get("camera"), cgUtils.ButlerImage(butler, visit=visit, callback=utils.trimRemoveCrCallback, verbose=True), nJob=nJob, frame=frame, bin=bin, title=visit, overlay=True, names=False) frame += 1
def testCameraGeomUtils(self): for cw in self.cameraList: camera = cw.camera disp = afwDisplay.Display() cameraGeomUtils.showCamera(camera, display=disp) disp.incrDefaultFrame() for det in (camera[10], camera[20]): cameraGeomUtils.showCcd(det, inCameraCoords=False) disp.incrDefaultFrame() cameraGeomUtils.showCcd(det, inCameraCoords=True) disp.incrDefaultFrame() cameraGeomUtils.showCcd(det, inCameraCoords=False) disp.incrDefaultFrame() cameraGeomUtils.showCcd(det, inCameraCoords=True) disp.incrDefaultFrame() for amp in det: cameraGeomUtils.showAmp(amp, display=disp, imageFactory=afwImage.ImageF) disp.incrDefaultFrame()
def testRaw(self): """Test retrieval of raw image""" if display: global frame frame += 1 cameraGeomUtils.showCamera(self.butler.mapper.camera, frame=frame) for ccd in range(36): raw = self.butler.get("raw", self.dataId, ccd=ccd, immediate=True) self.assertExposure(raw, ccd) visitInfo = raw.getInfo().getVisitInfo() self.assertAlmostEqual(visitInfo.getDate().get(), self.dateAvg.get()) self.assertAnglesAlmostEqual(visitInfo.getEra(), self.era, maxDiff=0.1 * degrees) self.assertAlmostEqual(visitInfo.getExposureTime(), self.exposureTime) self.assertAlmostEqual(visitInfo.getDarkTime(), self.darkTime) self.assertSpherePointsAlmostEqual(visitInfo.getBoresightRaDec(), self.boresightRaDec) self.assertSpherePointsAlmostEqual(visitInfo.getBoresightAzAlt(), self.boresightAzAlt) self.assertAlmostEqual(visitInfo.getBoresightAirmass(), self.boresightAirmass) self.assertTrue(visitInfo.getBoresightRotAngle(), self.boresightRotAngle) self.assertEqual(visitInfo.getRotType(), self.rotType) observatory = visitInfo.getObservatory() self.assertAnglesAlmostEqual(observatory.getLongitude(), self.obs_longitude) self.assertAnglesAlmostEqual(observatory.getLatitude(), self.obs_latitude) self.assertAlmostEqual(observatory.getElevation(), self.obs_elevation) weather = visitInfo.getWeather() self.assertAlmostEqual(weather.getAirTemperature(), self.weath_airTemperature) self.assertAlmostEqual(weather.getAirPressure(), self.weath_airPressure) self.assertAlmostEqual(weather.getHumidity(), self.weath_humidity)
def testCameraGeomUtils(self): if not display: print "display variable not set; skipping cameraGeomUtils test" return for cw in self.cameraList: camera = cw.camera cameraGeomUtils.showCamera(camera, referenceDetectorName=camera[0].getName()) ds9.incrDefaultFrame() for det in (camera[0], camera[1]): cameraGeomUtils.showCcd(det, isTrimmed=True, inCameraCoords=False) ds9.incrDefaultFrame() cameraGeomUtils.showCcd(det, isTrimmed=True, inCameraCoords=True) ds9.incrDefaultFrame() cameraGeomUtils.showCcd(det, isTrimmed=False, inCameraCoords=False) ds9.incrDefaultFrame() cameraGeomUtils.showCcd(det, isTrimmed=False, inCameraCoords=True) ds9.incrDefaultFrame() for amp in det: cameraGeomUtils.showAmp(amp) ds9.incrDefaultFrame()
def testRaw(self): """Test retrieval of raw image""" frame = 0 if display: cameraGeomUtils.showCamera(self.butler.mapper.camera, frame=frame) for side in ("N", "S"): for ccd in range(1, 32, 1): raw = self.butler.get("raw", self.dataId, side=side, ccd=ccd) self.assertExposure(raw, side, ccd) if display: frame += 1 ccd = cameraGeom.cast_Ccd(raw.getDetector()) for amp in ccd: amp = cameraGeom.cast_Amp(amp) print ccd.getId(), amp.getId(), amp.getDataSec().toString(), \ amp.getBiasSec().toString(), amp.getElectronicParams().getGain() cameraGeomUtils.showCcd(ccd, ccdImage=raw, frame=frame)
def run(self, expRef, butler): """Make summary plots of full focalplane images. """ sbi = SimButlerImage(butler, type=expRef.butlerSubset.datasetType, visit=expRef.dataId['visit']) # Get the per ccd images def parse_name_to_dataId(name_str): raft, sensor = name_str.split() return {'raft': raft[-3:], 'sensor': sensor[-3:]} for ccd in butler.get('camera'): data_id = parse_name_to_dataId(ccd.getName()) data_id.update(expRef.dataId) try: binned_im = sbi.getCcdImage(ccd, binSize=self.config.sensorBinSize, as_masked_image=True)[0] binned_im = rotateImageBy90(binned_im, ccd.getOrientation().getNQuarter()) if self.config.putFullSensors: butler.put(binned_im, 'binned_sensor_fits', **data_id) except (TypeError, RuntimeError): # butler couldn't put the image or there was no image to put continue (x, y) = binned_im.getDimensions() boxes = { 'A': afwGeom.Box2I(afwGeom.PointI(0, y / 2), afwGeom.ExtentI(x, y / 2)), 'B': afwGeom.Box2I(afwGeom.PointI(0, 0), afwGeom.ExtentI(x, y / 2)) } for half in ('A', 'B'): box = boxes[half] butler.put(afwImage.MaskedImageF(binned_im, box), 'binned_sensor_fits_halves', half=half, **data_id) im = cgu.showCamera(butler.get('camera'), imageSource=sbi, binSize=self.config.binSize) expRef.put(im, 'focalplane_summary_fits') im = flipImage(im, False, True) zmap = ZScaleMapping(im, contrast=self.config.contrast) rgb = zmap.makeRgbImage(im, im, im) file_name = expRef.get('focalplane_summary_png_filename') writeRGB(file_name[0], rgb)
def make_fp_mosaic(repo, expId, det_names=None, outfile=None, bin_size=10, verbose=False): """ Function to make a mosaic of raw image data in the LSST focal plane. Parameters ---------- repo: str Path to the data repo containing the raw images. expId: int The expId to use. det_names: list-like [None] List of detectors to render, e.g., ['R22_S11', 'R22_S12', ...]. If None, the all detectors in the focal plane will be plotted. outfile: str [None] Name of FITS file to write with the mosaicked data. If None, then no file will be written. bin_size: int [10] Rebinning size in pixels. verbose: bool [False] Flag to print dots indicating progress of CCD processing. Returns ------- lsst.afw.ImageF: Image containing the mosaic. """ butler = dp.Butler(repo) camera = butler.get('camera') callback = lambda *args, **kwds: raw_callback( *args, verbose=verbose, **kwds) image_source = cgu.ButlerImage(butler, 'raw', expId=expId, callback=callback, verbose=verbose) image = cgu.showCamera(camera, imageSource=image_source, binSize=bin_size, detectorNameList=det_names) if outfile is not None: image.writeFits(outfile) return image
def displayCamera(args): """Display camera element according to command-line arguments. Parameters ---------- args : `argparse.Namespace` Command-line arguments to parse. """ hsc = HyperSuprimeCam() camera = hsc.getCamera() frame = 0 if args.showAmp: frame = 0 for ampStr in args.showAmp: if checkStr(ampStr, 'amp'): ccd, amp = ampStr.split() detector = camera[ccd] amplifier = detector[amp] disp = afwDisplay.Display(frame=frame) cameraGeomUtils.showAmp(amplifier, display=disp) frame += 1 if args.showCcd: frame = 0 for ccdStr in args.showCcd: if checkStr(ccdStr, 'ccd'): detector = camera[ccdStr] disp = afwDisplay.Display(frame=frame) cameraGeomUtils.showCcd(detector, display=disp) frame += 1 raftMap = {'0': [], '1': []} for det in camera: dName = det.getName() if dName.startswith('1'): raftMap['1'].append(dName) elif dName.startswith('0'): raftMap['0'].append(dName) else: raise RuntimeError("Did not recognize detector name") if args.showRaft: frame = 0 for raftStr in args.showRaft: disp = afwDisplay.Display(frame) if checkStr(raftStr, 'raft'): detectorNameList = [] for detector in camera: detName = detector.getName() if detName in raftMap[raftStr.lower()]: detectorNameList.append(detName) cameraGeomUtils.showCamera(camera, detectorNameList=detectorNameList, display=disp, binSize=4) frame += 1 if args.showCamera: disp = afwDisplay.Display(frame) cameraGeomUtils.showCamera(camera, display=disp, binSize=args.cameraBinSize) if args.plotFocalPlane: cameraGeomUtils.plotFocalPlane(camera, 2., 2.)
def plot_cameraGeom(repo_dir=os.path.join( '/project/scichris/aos/images/lsstCam/letter_lsstCam_entire_tiledF/DATA/'), detectorNameList=[ "R04_SW0", "R04_SW1", "R44_SW0", "R44_SW1", "R00_SW0", "R00_SW1", "R40_SW0", "R40_SW1", ], instrument='LSSTCam', binSize=16): afwDisplay.setDefaultBackend("matplotlib") #repo_dir = os.path.join('/project/scichris/aos/images/lsstCam/letter_lsstCam_entire_tiledF/DATA/') # need to specify the calib collections to be able to access the camera butler = dafButler.Butler(repo_dir, collections=[ f'{instrument}/raw/all', f'{instrument}/calib', 'run1', f'{instrument}/calib/unbounded' ]) dataId0 = dict(instrument=instrument) dataset = next( iter( butler.registry.queryDatasets(datasetType='postISRCCD', collections=['run1'], dataId=dataId0))) exposure = dataset.dataId["exposure"] camera = butler.get("camera", instrument=instrument, exposure=exposure) fig = plt.figure(figsize=(15, 15)) fig.subplots_adjust( hspace=0., wspace=0.0, ) ax = fig.add_subplot(1, 1, 1) disp = afwDisplay.Display(fig) disp.scale('asinh', 'zscale', Q=2) #disp.scale('linear', 'minmax') #disp.scale('asinh', 5, 7000, Q=2) disp.setImageColormap('viridis' if True else 'gray') dataType = "postISRCCD" # use that to limit what's shown #detectorNameList = ['R22_S11', 'R22_S20', 'R22_S10']# , 'R34_S20'] # set to None to plot everything mos = cameraGeomUtils.showCamera(camera, cameraGeomUtils.ButlerImage( butler, dataType, instrument=instrument, exposure=exposure, verbose=True), binSize=binSize, detectorNameList=detectorNameList, display=disp, overlay=True, title=f'{instrument}') disp.show_colorbar(False) ax.axis("off") #plt.savefig('LsstCam_letter_entire_tiledF_wfs.png', bbox_inches='tight') return mos
amplifier = detector[ampMap[amp.lower()]] cameraGeomUtils.showAmp(amplifier, frame=frame) frame += 1 if args.showCcd: for ccdStr in args.showCcd: if checkStr(ccdStr, 'ccd'): detector = camera[ccdStr] cameraGeomUtils.showCcd(detector, frame=frame) frame += 1 raftMap = {'north':['ccd%02d'%val for val in range(18)], 'south':['ccd%02d'%val for val in range(18, 36)]} if args.showRaft: for raftStr in args.showRaft: if checkStr(raftStr, 'raft'): detectorList = [] for detector in camera: detName = detector.getName() if detName in raftMap[raftStr.lower()]: detectorList.append(detector) tmpCamera = Camera(raftStr, detectorList, camera._transformMap) cameraGeomUtils.showCamera(tmpCamera, frame=frame, binSize=1) frame += 1 if args.showCamera: cameraGeomUtils.showCamera(camera, frame=frame, binSize=args.cameraBinSize) if args.plotFocalPlane: cameraGeomUtils.plotFocalPlane(camera, 2., 2.)
frame += 1 disp = afwDisplay.Display(frame=frame) if args.showCcd: for ccdStr in args.showCcd: if checkStr(ccdStr, 'ccd'): detector = camera[ccdStr] cameraGeomUtils.showCcd(detector, display=disp) frame += 1 disp = afwDisplay.Display(frame=frame) raftMap = {'north': ['ccd%02d'%val for val in range(18)], 'south': ['ccd%02d'%val for val in range(18, 36)]} if args.showRaft: for raftStr in args.showRaft: if checkStr(raftStr, 'raft'): detectorNameList = [] for detector in camera: detName = detector.getName() if detName in raftMap[raftStr.lower()]: detectorNameList.append(detName) cameraGeomUtils.showCamera(camera, detectorNameList=detectorNameList, display=disp, binSize=4) frame += 1 disp = afwDisplay.Display(frame=frame) if args.showCamera: cameraGeomUtils.showCamera(camera, display=disp, binSize=args.cameraBinSize) if args.plotFocalPlane: cameraGeomUtils.plotFocalPlane(camera, 2., 2.)
def runDataRef(self, expRefList, butler): """Make summary plots of full focalplane images. """ if len(expRefList) == 0: return pipeBase.Struct(exitStatus=1) lsst.afw.fits.setAllowImageCompression( self.config.allowFitsCompression) dstype = expRefList[0].butlerSubset.datasetType if dstype == "raw": def callback(im, ccd, imageSource): return cgu.rawCallback(im, ccd, imageSource, correctGain=True, subtractBias=True) elif dstype == "eimage": callback = eimageCallback elif self.config.doApplySkyCorr: callback = skyCorrCallback else: callback = None for visit in set([er.dataId["visit"] for er in expRefList]): self.log.info("Processing visit %d", visit) expRefListForVisit = [ er for er in expRefList if er.dataId["visit"] == visit ] dataId = expRefListForVisit[0].dataId bi = cgu.ButlerImage(butler, dstype, visit=visit, callback=callback, verbose=True) if self.config.doSensorImages: for dataId in (er.dataId for er in expRefListForVisit): ccd = butler.get('calexp_detector', **dataId) try: md = butler.get('calexp_md', **dataId) except RuntimeError: md = None if md: afwGeom.makeSkyWcs( md, strip=True ) # strip WCS cards; they're invalidated by binning try: binned_im = bi.getCcdImage( ccd, binSize=self.config.sensorBinSize, asMaskedImage=True)[0] binned_im = rotateImageBy90( binned_im, ccd.getOrientation().getNQuarter()) if self.config.putFullSensors: binned_exp = afwImage.ExposureF(binned_im) binned_exp.setMetadata(md) butler.put(binned_exp, 'binned_sensor_fits', **dataId, dstype=dstype) except (TypeError, RuntimeError) as e: # butler couldn't put the image or there was no image to put self.log.warn("Unable to make binned image: %s", e) continue (x, y) = binned_im.getDimensions() boxes = { 'A': afwGeom.Box2I(afwGeom.PointI(0, y / 2), afwGeom.ExtentI(x, y / 2)), 'B': afwGeom.Box2I(afwGeom.PointI(0, 0), afwGeom.ExtentI(x, y / 2)) } for half in ('A', 'B'): box = boxes[half] binned_exp = afwImage.ExposureF(binned_im[box]) binned_exp.setMetadata(md) butler.put(binned_exp, 'binned_sensor_fits_halves', half=half, **dataId, dstype=dstype) im = cgu.showCamera(butler.get('camera'), imageSource=bi, binSize=self.config.binSize) dstypeName = "%s-%s" % ( dstype, self.config.fpId) if self.config.fpId else dstype butler.put(im, 'focal_plane_fits', visit=visit, dstype=dstypeName) # Compute the zscale stretch for just the CCDs that have data. detectorNameList = [ "%s_%s" % (er.dataId["raftName"], er.dataId["detectorName"]) for er in expRefListForVisit ] im_scaling = cgu.showCamera(butler.get('camera'), imageSource=bi, binSize=self.config.binSize, detectorNameList=detectorNameList) zmap = ZScaleMapping(im_scaling, contrast=self.config.contrast) im = flipImage(im, False, True) rgb = zmap.makeRgbImage(im, im, im) file_name = butler.get('focal_plane_png_filename', visit=visit, dstype=dstypeName) writeRGB(file_name[0], rgb) return pipeBase.Struct(exitStatus=0)
def displayCamera(args): """Display camera element according to command-line arguments. Parameters ---------- args : `argparse.Namespace` Command-line arguments to parse. """ mapper = obs_hsc.HscMapper(root=".") camera = mapper.camera frame = 0 if args.showAmp: frame = 0 for ampStr in args.showAmp: if checkStr(ampStr, 'amp'): ccd, amp = ampStr.split() detector = camera[ccd] amplifier = detector[amp] disp = afwDisplay.Display(frame=frame) cameraGeomUtils.showAmp(amplifier, display=disp) frame += 1 if args.showCcd: frame = 0 for ccdStr in args.showCcd: if checkStr(ccdStr, 'ccd'): detector = camera[ccdStr] disp = afwDisplay.Display(frame=frame) cameraGeomUtils.showCcd(detector, display=disp) frame += 1 raftMap = {'0': [], '1': []} for det in camera: dName = det.getName() if dName.startswith('1'): raftMap['1'].append(dName) elif dName.startswith('0'): raftMap['0'].append(dName) else: raise RuntimeError("Did not recognize detector name") if args.showRaft: frame = 0 for raftStr in args.showRaft: disp = afwDisplay.Display(frame) if checkStr(raftStr, 'raft'): detectorNameList = [] for detector in camera: detName = detector.getName() if detName in raftMap[raftStr.lower()]: detectorNameList.append(detName) cameraGeomUtils.showCamera(camera, detectorNameList=detectorNameList, display=disp, binSize=4) frame += 1 if args.showCamera: disp = afwDisplay.Display(frame) cameraGeomUtils.showCamera(camera, display=disp, binSize=args.cameraBinSize) if args.plotFocalPlane: cameraGeomUtils.plotFocalPlane(camera, 2., 2.)
def plotShowCamera(butler, expId, dataType, dataType2=None, butler2=None, expId2=None, dataType3=None, butler3=None, expId3=None, binSize=10, cmap="viridis", doVariance=False, doSignalToNoise=False, doDiffIm=False, doPercentDiffIm=False, doAddIm=False, doAddThenSubtractIm=False, fileUsedDir=None, fileUsedDir2=None, figureSideSize=12): subTypeStr = "" camera = butler.get("camera") plt.figure(figsize=(figureSideSize, figureSideSize)) disp = afwDisplay.Display(1, "matplotlib") disp.scale("linear", "zscale") disp.setImageColormap(cmap) callback = None if doVariance: subTypeStr = " variance" imageSource = cameraGeomUtils.ButlerImage(butler, dataType, expId=expId, verbose=True, callback=lambda im, ccd, imageSource: varianceOrSignalToNoiseCallback(im, ccd, imageSource, dataType=dataType, butler=butler, expId=expId, doVariance=True)) elif doSignalToNoise: subTypeStr = " S/N" imageSource = cameraGeomUtils.ButlerImage(butler, dataType, expId=expId, verbose=True, callback=lambda im, ccd, imageSource: varianceOrSignalToNoiseCallback(im, ccd, imageSource, dataType=dataType, butler=butler, expId=expId, doSignalToNoise=True)) elif doDiffIm: subTypeStr = " Absolute Difference Image" imageSource = cameraGeomUtils.ButlerImage(butler, dataType, expId=expId, verbose=True, callback=lambda im, ccd, imageSource: diffImCallback(im, ccd, imageSource, dataType=dataType, butler=butler, expId=expId, butler2=butler2, expId2=expId2, doAbsoluteDiff=doDiffIm)) elif doPercentDiffIm: subTypeStr = " Percent Difference Image" imageSource = cameraGeomUtils.ButlerImage(butler, dataType, expId=expId, verbose=True, callback=lambda im, ccd, imageSource: diffImCallback(im, ccd, imageSource, dataType=dataType, butler=butler, expId=expId, butler2=butler2, expId2=expId2, doPercentDiff=doPercentDiffIm)) elif doAddIm: subTypeStr = " Addition of two Images" imageSource = cameraGeomUtils.ButlerImage(butler, dataType, expId=expId, verbose=True, callback=lambda im, ccd, imageSource: addImCallback(im, ccd, imageSource, dataType=dataType, butler=butler, expId=expId, dataType2=dataType2, butler2=butler2, expId2=expId2)) elif doAddThenSubtractIm: subTypeStr = " Addition of two Images and Subtraction of a Third" imageSource = cameraGeomUtils.ButlerImage(butler, dataType, expId=expId, verbose=True, callback=lambda im, ccd, imageSource: addThenSubtractImCallback(im, ccd, imageSource, dataType=dataType, butler=butler, expId=expId, dataType2=dataType2, butler2=butler2, expId2=expId2, dataType3=dataType3, butler3=butler3, expId3=expId3)) else: imageSource = cameraGeomUtils.ButlerImage(butler, dataType, expId=expId, verbose=True) if "Difference" in subTypeStr: titleStr = ("{}{} source1: {} source2: {} BinSize={}". format(dataType, subTypeStr, fileUsedDir, fileUsedDir2, binSize)) else: titleStr = ("{}{} source: {} expId: {} BinSize={}". format(dataType, subTypeStr, fileUsedDir, expId, binSize)) mos = cameraGeomUtils.showCamera(camera, imageSource=imageSource, detectorNameList=None, binSize=binSize, display=disp, title=titleStr, ctype=afwDisplay.GREEN, textSize=3)
if args.showCcd: for ccdStr in args.showCcd: if checkStr(ccdStr, 'ccd'): detector = camera[ccdStr] cameraGeomUtils.showCcd(detector, frame=frame) frame += 1 raftMap = { 'north': ['ccd%02d' % val for val in range(18)], 'south': ['ccd%02d' % val for val in range(18, 36)] } if args.showRaft: for raftStr in args.showRaft: if checkStr(raftStr, 'raft'): detectorList = [] for detector in camera: detName = detector.getName() if detName in raftMap[raftStr.lower()]: detectorList.append(detector) tmpCamera = Camera(raftStr, detectorList, camera._transformMap) cameraGeomUtils.showCamera(tmpCamera, frame=frame, binSize=1) frame += 1 if args.showCamera: cameraGeomUtils.showCamera(camera, frame=frame, binSize=args.cameraBinSize) if args.plotFocalPlane: cameraGeomUtils.plotFocalPlane(camera, 2., 2.)