def prepare_mosaic(self, image, fov_deg, name=None): """Prepare a new (blank) mosaic image based on the pointing of the parameter image """ header = image.get_header() ra_deg, dec_deg = header['CRVAL1'], header['CRVAL2'] data_np = image.get_data() #dtype = data_np.dtype dtype = None self.bg_ref = iqcalc.get_median(data_np) # TODO: handle skew (differing rotation for each axis)? skew_limit = self.settings.get('skew_limit', 0.1) (rot_deg, cdelt1, cdelt2) = wcs.get_rotation_and_scale(header, skew_threshold=skew_limit) self.logger.debug("image0 rot=%f cdelt1=%f cdelt2=%f" % (rot_deg, cdelt1, cdelt2)) # TODO: handle differing pixel scale for each axis? px_scale = math.fabs(cdelt1) cdbase = [numpy.sign(cdelt1), numpy.sign(cdelt2)] reuse_image = self.settings.get('reuse_image', False) if (not reuse_image) or (self.img_mosaic is None): self.logger.debug("creating blank image to hold mosaic") self.fv.gui_do(self._prepare_mosaic1, "Creating blank image...") # GC old mosaic self.img_mosaic = None img_mosaic = dp.create_blank_image(ra_deg, dec_deg, fov_deg, px_scale, rot_deg, cdbase=cdbase, logger=self.logger, pfx='mosaic', dtype=dtype) if name is not None: img_mosaic.set(name=name) imname = img_mosaic.get('name', image.get('name', "NoName")) # avoid making a thumbnail of this if seed image is also that way nothumb = not self.settings.get('make_thumbs', False) if nothumb: img_mosaic.set(nothumb=True) else: # image is not on disk, set indication for other plugins img_mosaic.set(path=None) # TODO: fill in interesting/select object headers from seed image self.img_mosaic = img_mosaic self.fv.gui_call(self.fv.add_image, imname, img_mosaic, chname=self.mosaic_chname) else: # <-- reuse image (faster) self.logger.debug("Reusing previous mosaic image") self.fv.gui_do(self._prepare_mosaic1, "Reusing previous mosaic image...") img_mosaic = dp.recycle_image(self.img_mosaic, ra_deg, dec_deg, fov_deg, px_scale, rot_deg, cdbase=cdbase, logger=self.logger, pfx='mosaic') header = img_mosaic.get_header() (rot, cdelt1, cdelt2) = wcs.get_rotation_and_scale(header, skew_threshold=skew_limit) self.logger.debug("mosaic rot=%f cdelt1=%f cdelt2=%f" % (rot, cdelt1, cdelt2)) return img_mosaic
def prepare_mosaic(self, image, fov_deg, name=None): """Prepare a new (blank) mosaic image based on the pointing of the parameter image """ header = image.get_header() ra_deg, dec_deg = header['CRVAL1'], header['CRVAL2'] data_np = image.get_data() #dtype = data_np.dtype dtype = None self.bg_ref = iqcalc.get_median(data_np) # TODO: handle skew (differing rotation for each axis)? skew_limit = self.settings.get('skew_limit', 0.1) (rot_deg, cdelt1, cdelt2) = wcs.get_rotation_and_scale(header, skew_threshold=skew_limit) self.logger.debug("image0 rot=%f cdelt1=%f cdelt2=%f" % ( rot_deg, cdelt1, cdelt2)) # TODO: handle differing pixel scale for each axis? px_scale = math.fabs(cdelt1) cdbase = [numpy.sign(cdelt1), numpy.sign(cdelt2)] reuse_image = self.settings.get('reuse_image', False) if (not reuse_image) or (self.img_mosaic is None): self.logger.debug("creating blank image to hold mosaic") self.fv.gui_do(self._prepare_mosaic1, "Creating blank image...") # GC old mosaic self.img_mosaic = None img_mosaic = dp.create_blank_image(ra_deg, dec_deg, fov_deg, px_scale, rot_deg, cdbase=cdbase, logger=self.logger, pfx='mosaic', dtype=dtype) if name is not None: img_mosaic.set(name=name) imname = img_mosaic.get('name', image.get('name', "NoName")) # avoid making a thumbnail of this if seed image is also that way nothumb = not self.settings.get('make_thumbs', False) if nothumb: img_mosaic.set(nothumb=True) else: # image is not on disk, set indication for other plugins img_mosaic.set(path=None) # TODO: fill in interesting/select object headers from seed image self.img_mosaic = img_mosaic self.fv.gui_call(self.fv.add_image, imname, img_mosaic, chname=self.mosaic_chname) else: # <-- reuse image (faster) self.logger.debug("Reusing previous mosaic image") self.fv.gui_do(self._prepare_mosaic1, "Reusing previous mosaic image...") img_mosaic = dp.recycle_image(self.img_mosaic, ra_deg, dec_deg, fov_deg, px_scale, rot_deg, cdbase=cdbase, logger=self.logger, pfx='mosaic') header = img_mosaic.get_header() (rot, cdelt1, cdelt2) = wcs.get_rotation_and_scale(header, skew_threshold=skew_limit) self.logger.debug("mosaic rot=%f cdelt1=%f cdelt2=%f" % ( rot, cdelt1, cdelt2)) return img_mosaic