def testOtherAliases(self): with self.assertWarns(FutureWarning): self.assertIsInstance(afwGeom.BoxI(), lsst.geom.BoxI) with self.assertWarns(FutureWarning): self.assertIsInstance(afwGeom.BoxI(), lsst.geom.Box2I) with self.assertWarns(FutureWarning): self.assertIsInstance(afwGeom.BoxD(), lsst.geom.BoxD) with self.assertWarns(FutureWarning): self.assertIsInstance(afwGeom.BoxD(), lsst.geom.Box2D) with self.assertWarns(FutureWarning): self.assertIsInstance(afwGeom.SpherePoint(), lsst.geom.SpherePoint) with self.assertWarns(FutureWarning): self.assertIsInstance(afwGeom.AffineTransform(), lsst.geom.AffineTransform) with self.assertWarns(FutureWarning): self.assertIsInstance(afwGeom.LinearTransform(), lsst.geom.LinearTransform)
def ccdPixelToAmpPixel(xy, detector): r"""Given an position within a detector return position within an amplifier Parameters ---------- xy : `lsst.afw.geom.PointD` pixel position within detector detector : `lsst.afw.cameraGeom.Detector` The requested detector N.b. all pixel coordinates have the centre of the bottom-left pixel at (0.0, 0.0) Returns ------- amp : `lsst.afw.table.AmpInfoRecord` The amplifier that the pixel lies in ampXY : `lsst.afw.geom.PointI` The pixel coordinate relative to the corner of the single-amp image Raises ------ RuntimeError If the requested pixel doesn't lie on the detector """ found = False for amp in detector: if afwGeom.BoxD(amp.getBBox()).contains(xy): found = True xy = afwGeom.PointI(xy) # pixel coordinates as ints break if not found: raise RuntimeError("Point (%g, %g) does not lie on detector %s" % (xy[0], xy[1], detector.getName())) x, y = xy - amp.getBBox().getBegin( ) # offset from origin of amp's data segment # Allow for flips (due e.g. to physical location of the amplifiers) w, h = amp.getRawDataBBox().getDimensions() if amp.getRawFlipX(): x = w - x - 1 if amp.getRawFlipY(): y = h - y - 1 dxy = amp.getRawBBox().getBegin() - amp.getRawDataBBox().getBegin( ) # correction for overscan etc. xy = afwGeom.ExtentI(x, y) - dxy return amp, xy
def __init__(self, ident, patchInnerDimensions, patchBorder, ctrCoord, radius, tractOverlap, wcs): # We don't want TractInfo setting the bbox on the basis of vertices, but on the radius. vertexList = [] self._radius = radius super(ExplicitTractInfo, self).__init__(ident, patchInnerDimensions, patchBorder, ctrCoord, vertexList, tractOverlap, wcs) # Shrink the box slightly to make sure the vertices are in the tract bboxD = afwGeom.BoxD(self.getBBox()) bboxD.grow(-0.001) finalWcs = self.getWcs() self._vertexCoordList = finalWcs.pixelToSky(bboxD.getCorners())
def std_raw(self, image, dataId): """Standardize a raw dataset by converting it to an Exposure instead of an Image""" if isinstance(image, afwImage.DecoratedImageU) or isinstance(image, afwImage.DecoratedImageI) or \ isinstance(image, afwImage.DecoratedImageF) or isinstance(image, afwImage.DecoratedImageD): exposure = afwImage.makeExposure(afwImage.makeMaskedImage(image.getImage())) else: exposure = image md = image.getMetadata() if True: wcs = afwImage.makeWcs(md, True) # The CASU WCSes use ZPN; our stuff wants TAN # This won't work near the pole, but should be decent away from it. box = afwGeom.BoxD(image.getImage().getBBox()) refPix = box.getCenter() refSky = wcs.pixelToSky(refPix) refSkyOffsetX = wcs.pixelToSky(refPix + afwGeom.Extent2D(1.0, 0.0)) refSkyOffsetY = wcs.pixelToSky(refPix + afwGeom.Extent2D(0.0, 1.0)) xPixelScale = refSky.angularSeparation(refSkyOffsetX).asDegrees() yPixelScale = refSky.angularSeparation(refSkyOffsetY).asDegrees() xPixelScale = yPixelScale = wcs.pixelScale().asDegrees() else: refPix = afwGeom.Point2D(md.get("CRPIX1"), md.get("CRPIX2")) refSky = afwCoord.IcrsCoord(md.get("CRVAL1")*afwGeom.degrees, md.get("CRVAL2")*afwGeom.degrees) xPixelScale = yPixelScale = (0.2*afwGeom.arcseconds).asDegrees() # import pdb;pdb.set_trace() exposure.setMetadata(md) #newWcs = afwImage.makeWcs(refSky, refPix, xPixelScale, 0.0, 0.0, yPixelScale) #wcs = afwImage.makeWcs(md, True) #exposure.setWcs(newWcs) exposure.setWcs(wcs) """ Set up exposure time """ pathId = self._transformId(dataId) expTime = pathId['expTime'] exposure.getCalib().setExptime(expTime) return self._standardizeExposure(self.exposures['raw'], exposure, dataId, trimmed=False)
def focalMmToCcdPixel(camera, focalPlaneXY): r"""Given an position in the focal plane, return the position on a detector Parameters ---------- camera : `lsst.afw.cameraGeom.Camera` The object describing a/the LSST Camera focalPlaneXY : `lsst.afw.geom.PointD` The focal plane position (mm) relative to the centre of the camera N.b. all pixel coordinates have the centre of the bottom-left pixel at (0.0, 0.0) and CCD columns are taken to be vertical, with "R00" in the bottom left of the image Returns ------- detector : `lsst.afw.cameraGeom.Detector` The requested detector ccdPos : `lsst.afw.geom.Point2D` The pixel position relative to the corner of the detector Raises ------ RuntimeError If the requested position doesn't lie on a detector """ for detector in camera: ccdXY = detector.transform(focalPlaneXY, cameraGeom.FOCAL_PLANE, cameraGeom.PIXELS) if afwGeom.BoxD(detector.getBBox()).contains(ccdXY): return detector, ccdXY raise RuntimeError( "Failed to map focal plane position (%.3f, %.3f) to a detector" % (focalPlaneXY))
def makeDeblendFamilyMosaic(mi, parent, kids, mapperInfo=None, background=-10, maskbit=False, imBbox=None): """Create a mosaic of an object's children """ aa = {} if maskbit: aa.update(mask=True) parent_im = footprintToImage(parent.getFootprint(), mi, **aa) bbox = afwGeom.BoxD(parent.getFootprint().getBBox()) pext = (bbox.getMinX(), bbox.getMaxX(), bbox.getMinY(), bbox.getMaxY()) pks = parent.getFootprint().getPeaks() pix = [pk.getIx() for pk in pks] piy = [pk.getIy() for pk in pks] pfx = [pk.getFx() for pk in pks] pfy = [pk.getFy() for pk in pks] N = 1 + len(kids) S = np.ceil(np.sqrt(N)) C = S R = np.ceil(float(N) / C) Rx, Ry = [], [] tts = [] stys = [] xys = [] # # Find how large an image we need to display the parent and all the children # kidImages, kim = {}, None for kid in kids: kim = footprintToImage(kid.getFootprint(), mi, **aa) kidImages[kid] = kim if not kim: kim = parent_im.clone() if not imBbox: imBbox = parent_im.getBBox(afwImage.PARENT) for kid in kids: imBbox.include(kidImages[kid].getBBox(afwImage.PARENT)) mos = displayUtils.Mosaic(background=background) bbox = afwGeom.Box2I( afwGeom.Point2I(kim.getX0() - imBbox.getMinX(), kim.getY0() - imBbox.getMinY()), kim.getDimensions()) kidImages[parent] = parent_im # not strictly a kid for kid in [parent] + kids: kim = kidImages[kid] # # Put the child into the correct place in the parent image. We have to do this for # the parent too if some of the children extended outside its BBox # bbox = afwGeom.Box2I( afwGeom.Point2I(kim.getX0() - imBbox.getMinX(), kim.getY0() - imBbox.getMinY()), kim.getDimensions()) _kim = parent_im.Factory(imBbox) if kid.getFootprint().getBBox().isEmpty(): _kim[:] = 0 pass else: _kim[bbox] = kim mos.append( _kim, '%d%s' % (mapperInfo.getId(kid) if mapperInfo else (kid.getId() & 0xfff), "P" if kid == parent else "C")) del _kim return mos