def plant(expnums, ccd, rmin, rmax, ang, width, number=10, mmin=21.0, mmax=25.5, version='s', dry_run=False): """Plant artificial sources into the list of images provided. :param expnums: list of MegaPrime exposure numbers to add artificial KBOs to :param ccd: which ccd to work on. :param rmin: The minimum rate of motion to add sources at (''/hour) :param rmax: The maximum rate of motion to add sources at (''/hour) :param ang: The mean angle of motion to add sources :param width: The +/- range of angles of motion :param version: Add sources to the 'o', 'p' or 's' images :param dry_run: don't push results to VOSpace. """ # Construct a list of artificial KBOs with positions in the image # and rates of motion within the bounds given by the caller. filename = storage.get_image(expnums[0], ccd=ccd, version=version) header = fits.open(filename)[0].header bounds = util.get_pixel_bounds_from_datasec_keyword(header.get('DATASEC', '[33:2080,1:4612]')) # generate a set of artificial KBOs to add to the image. kbos = KBOGenerator.get_kbos(n=number, rate=(rmin, rmax), angle=(ang - width, ang + width), mag=(mmin, mmax), x=(bounds[0][0], bounds[0][1]), y=(bounds[1][0], bounds[1][1]), filename='Object.planted') for expnum in expnums: filename = storage.get_image(expnum, ccd, version) psf = storage.get_file(expnum, ccd, version, ext='psf.fits') plant_kbos(filename, psf, kbos, get_shifts(expnum, ccd, version), "fk") if dry_run: return uri = storage.get_uri('Object', ext='planted', version='', subdir=str( expnums[0]) + "/ccd%s" % (str(ccd).zfill(2))) storage.copy('Object.planted', uri) for expnum in expnums: uri = storage.get_uri(expnum, ccd=ccd, version=version, ext='fits', prefix='fk') filename = os.path.basename(uri) storage.copy(filename, uri) return
def test_KBOGenerator(self): filename = storage.get_file(self.expnum, self.ccd, self.version, ext='fits') shifts = storage.get_file(self.expnum, self.ccd, self.version, ext='shifts') psf = storage.get_file(self.expnum, self.ccd, self.version, ext='psf.fits') header = fits.open(filename)[0].header bounds = util.get_pixel_bounds_from_datasec_keyword(header.get('DATASEC', '[33:2080,1:4612]')) outfile = NamedTemporaryFile() shifts = json.loads(open(shifts, 'rb').read()) kbos = KBOGenerator.get_kbos(n=self.number, rate=(self.rmin, self.rmax), angle=(self.ang - self.rmax, self.rmax + self.rmin), mag=(self.mmin, self.mmax), x=(bounds[0][0], bounds[0][1]), y=(bounds[1][0], bounds[1][1]), filename=outfile.name) plant.plant_kbos(filename, psf, kbos, shifts, "fk") self.assertEqual(len(kbos), self.number)
def crpix(self): """ The location of the reference coordinate in the pixel frame. First simple respond with the header values, if they don't exist try usnig the DETSEC values @rtype: float, float """ try: return self.wcs.crpix1, self.wcs.crpix2 except Exception as ex: logging.debug("Couldn't get CRPIX from WCS: {}".format(ex)) logging.debug("Switching to use DATASEC for CRPIX value computation.") try: (x1, x2), (y1, y2) = util.get_pixel_bounds_from_datasec_keyword(self['DETSEC']) dx = float(self['NAXIS1']) dy = float(self['NAXIS2']) except KeyError as ke: raise KeyError("Header missing keyword: {}, required for CRPIX[12] computation".format(ke.args[0])) crpix1 = self._DET_X_CEN - (x1 + x2) / 2. + dx / 2. crpix2 = self._DET_Y_CEN - (y1 + y2) / 2. + dy / 2. return crpix1, crpix2
def plant(expnums, ccd, rmin, rmax, ang, width, number=10, mmin=21.0, mmax=25.5, version='s', dry_run=False, force=True): """Plant artificial sources into the list of images provided. @param dry_run: don't push results to VOSpace. @param width: The +/- range of angles of motion @param ang: The mean angle of motion to add sources @param rmax: The maximum rate of motion to add sources at (''/hour) @param rmin: The minimum rate of motion to add sources at (''/hour) @param expnums: list of MegaPrime exposure numbers to add artificial KBOs to @param ccd: which ccd to work on. @param mmax: Maximum magnitude to plant sources at @param version: Add sources to the 'o', 'p' or 's' images @param mmin: Minimum magnitude to plant sources at @param number: number of sources to plant. @param force: Run, even if we already succeeded at making a fk image. """ message = storage.SUCCESS if storage.get_status(task, "", expnums[0], version, ccd) and not force: logging.info("{} completed successfully for {}{}{}{:02d}".format( task, "", expnums[0], version, ccd)) return with storage.LoggingManager(task, "", expnums[0], ccd, version, dry_run): try: # Construct a list of artificial KBOs with positions in the image # and rates of motion within the bounds given by the caller. filename = storage.get_image(expnums[0], ccd=ccd, version=version) header = fits.open(filename)[0].header bounds = util.get_pixel_bounds_from_datasec_keyword( header.get('DATASEC', '[33:2080,1:4612]')) # generate a set of artificial KBOs to add to the image. kbos = KBOGenerator.get_kbos(n=number, rate=(rmin, rmax), angle=(ang - width, ang + width), mag=(mmin, mmax), x=(bounds[0][0], bounds[0][1]), y=(bounds[1][0], bounds[1][1]), filename='Object.planted') for expnum in expnums: filename = storage.get_image(expnum, ccd, version) psf = storage.get_file(expnum, ccd, version, ext='psf.fits') plant_kbos(filename, psf, kbos, get_shifts(expnum, ccd, version), "fk") if dry_run: return uri = storage.get_uri('Object', ext='planted', version='', subdir=f"{expnums[0]}/ccd{int(ccd):02d}") storage.copy('Object.planted', uri) for expnum in expnums: uri = storage.get_uri(expnum, ccd=ccd, version=version, ext='fits', prefix='fk') filename = os.path.basename(uri) storage.copy(filename, uri) except Exception as ex: message = str(ex) logging.error(message) storage.set_status(task, "", expnums[0], version, ccd, status=message) return
def plant(expnums, ccd, rmin, rmax, ang, width, number=10, version='s', dry_run=False): """Plant artificial sources into the list of images provided. :param expnums: list of MegaPrime exposure numbers to add artificial KBOs to :param ccd: which ccd to work on. :param rmin: The minimum rate of motion to add sources at (''/hour) :param rmax: The maximum rate of motion to add sources at (''/hour) :param ang: The mean angle of motion to add sources :param width: The +/- range of angles of motion :param version: Add sources to the 'o', 'p' or 's' images :param dry_run: don't push results to VOSpace. """ # Construct a list of artificial KBOs with positions in the image # and rates of motion within the bounds given by the caller. filename = storage.get_image(expnums[0], ccd=ccd, version=version) header = fits.open(filename)[0].header bounds = util.get_pixel_bounds_from_datasec_keyword( header.get('DATASEC', '[33:2080,1:4612]')) # generate a set of artifical KBOs to add to the image. kbos = Table(names=('x', 'y', 'mag', 'sky_rate', 'angle', 'id')) for kbo in KBOGenerator(n=number, x=Range(bounds[0][0], bounds[0][1]), y=Range(bounds[1][0], bounds[1][1]), rate=Range(rmin, rmax), angle=Range(ang - width, ang + width), mag=Range(21.0, 25.0)): kbos.add_row(kbo) fd = open('Object.planted', 'w') fd.write("# ") kbos.write(fd, format='ascii.fixed_width', delimiter=None) fd.close() for expnum in expnums: filename = storage.get_image(expnum, ccd, version) psf = storage.get_file(expnum, ccd, version, ext='psf.fits') plant_kbos(filename, psf, kbos, get_shifts(expnum, ccd, version), "fk") if dry_run: return uri = storage.get_uri('Object', ext='planted', version='', subdir=str(expnums[0]) + "/ccd%s" % (str(ccd).zfill(2))) storage.copy('Object.planted', uri) for expnum in expnums: uri = storage.get_uri(expnum, ccd=ccd, version=version, ext='fits', prefix='fk') filename = os.path.basename(uri) storage.copy(filename, uri) return