def chip_footprint_polygon(header, hdulist): """Create a Mongo-compatible polygon representing the chip footprint in equatorial cordinates. The polygon is a length-4 list, populated with length-2 lists of RA, Dec vertices. """ wcs = astropy.wcs.WCS(header=header, fobj=hdulist) footprint = wcs.calc_footprint(header=header) footprint_lst = footprint.tolist() # cast as a list of floats return footprint_lst
def add_footprint_from_wcs(self, mosaic_name, wcs): """Create a footprint from the WCS embedded in a ``astropy.io.fits`` header for the named (pre-existing) mosaic document. The footprint is stored under the field ``footprint`` in the mosaic's document. In a sense, this is an attempt to persist a WCS instance. Note that we only save a subset of the astropy.wcs data; that is, we're built around simple WCS with no PV, etc. This could be fixed though... .. note:: By default astropy.wcs is 1 based (ie, origins of CRPIX are 1 and not zero; may need to subtract 1 from crpix when used in numpy arrays Parameters ---------- mosaic_name : str Name of the mosaic (the ``_id`` field for the document). wcs : :class:`astropy.wcs.WCS` instance WCS for the mosaic. """ doc = {} doc['naxis'] = (wcs._naxis1, wcs._naxis2) doc['crpix'] = tuple(wcs.wcs.crpix) # (CRPIX1, CRPIX2) doc['crval'] = tuple(wcs.wcs.crval) # (CRVAL1, CRVAL2) doc['ctype'] = tuple(wcs.wcs.ctype) if wcs.wcs.has_cd(): cd = [] for (cdi, cdj) in wcs.wcs.cd: cd.append([cdi, cdj]) doc['cd'] = cd try: doc['cdelt'] = tuple(wcs.wcs.cdelt) except: pass try: doc['crota'] = tuple(wcs.wcs.crota) except: pass # Make footprint polygon, cast to a list raDecFootprintArray = wcs.calc_footprint() raDecFootprint = [] for (ra, dec) in raDecFootprintArray: raDecFootprint.append([ra, dec]) doc['radec_poly'] = raDecFootprint # Add footprint to mosaic document self.set(mosaic_name, "footprint", doc)
def get_image_corners(wcs): """ Return the image corners as a list, given a valid WCS object, extracted from the image. Corners are listed clockwise from the lower left corner. """ return list(wcs.calc_footprint())