def set_naxis_cb(self, w, n): idx = int(w.get_value()) - 1 self.logger.debug("naxis %d index is %d" % (n+1, idx+1)) image = AstroImage() image.set(path=self.path) try: hdu = self.fits_f[self.curhdu] data = hdu.data self.logger.debug("HDU #%d has naxis=%s" % ( self.curhdu+1, str(data.shape))) # invert index m = len(data.shape) - (n+1) self.naxispath[m] = idx self.logger.debug("m=%d naxispath=%s" % (m, str(self.naxispath))) image.load_hdu(hdu, naxispath=self.naxispath) self.fitsimage.set_image(image) self.logger.debug("NAXIS%d slice %d loaded." % (n+1, idx+1)) except Exception, e: errmsg = "Error loading NAXIS%d slice %d: %s" % ( n+1, idx+1, str(e)) self.logger.error(errmsg) self.fv.error(errmsg)
def _make_image(self, data_np, oldimage, name): """Generate new image object.""" image = AstroImage() image.set_data(data_np) image.update_keywords(oldimage.get_header()) image.set(name=name, path=None) return image
def set_naxis_cb(self, idx, n): self.logger.debug("naxis %d index is %d" % (n + 1, idx + 1)) image = AstroImage() image.set(path=self.path) try: hdu = self.fits_f[self.curhdu] data = hdu.data self.logger.debug("HDU #%d has naxis=%s" % (self.curhdu, str(data.shape))) # invert index m = len(data.shape) - (n + 1) self.naxispath[m] = idx self.logger.debug("m=%d naxispath=%s" % (m, str(self.naxispath))) self.logger.info("loading image from pyfits") start_time = time.time() image.load_hdu(hdu, fobj=self.fits_f, naxispath=self.naxispath) end_time = time.time() self.logger.info("loading image time %.3f sec" % (end_time - start_time)) start_time = end_time self.fitsimage.set_image(image) end_time = time.time() self.logger.debug("NAXIS%d slice %d loaded (%.3f sec)." % (n + 1, idx + 1, end_time - start_time)) except Exception, e: errmsg = "Error loading NAXIS%d slice %d: %s" % (n + 1, idx + 1, str(e)) self.logger.error(errmsg) self.fv.error(errmsg)
def _make_image(self, data_np, oldimage, name): """Generate new image object.""" image = AstroImage() image.set_data(data_np) image.update_keywords(oldimage.get_header()) image.set(name=name, path=None) return image
def set_naxis_cb(self, w, n): idx = int(w.get_value()) - 1 self.logger.debug("naxis %d index is %d" % (n + 1, idx + 1)) image = AstroImage() image.set(path=self.path) try: hdu = self.fits_f[self.curhdu] data = hdu.data self.logger.debug("HDU #%d has naxis=%s" % (self.curhdu + 1, str(data.shape))) # invert index m = len(data.shape) - (n + 1) self.naxispath[m] = idx self.logger.debug("m=%d naxispath=%s" % (m, str(self.naxispath))) image.load_hdu(hdu, naxispath=self.naxispath) self.fitsimage.set_image(image) self.logger.debug("NAXIS%d slice %d loaded." % (n + 1, idx + 1)) except Exception, e: errmsg = "Error loading NAXIS%d slice %d: %s" % (n + 1, idx + 1, str(e)) self.logger.error(errmsg) self.fv.error(errmsg)
def set_naxis_cb(self, idx, n): self.logger.debug("naxis %d index is %d" % (n+1, idx+1)) image = AstroImage() image.set(path=self.path) try: hdu = self.fits_f[self.curhdu] data = hdu.data self.logger.debug("HDU #%d has naxis=%s" % ( self.curhdu, str(data.shape))) # invert index m = len(data.shape) - (n+1) self.naxispath[m] = idx self.logger.debug("m=%d naxispath=%s" % (m, str(self.naxispath))) self.logger.info("loading image from pyfits") start_time = time.time() image.load_hdu(hdu, fobj=self.fits_f, naxispath=self.naxispath) end_time = time.time() self.logger.info("loading image time %.3f sec" % (end_time - start_time)) start_time = end_time self.fitsimage.set_image(image) end_time = time.time() self.logger.debug("NAXIS%d slice %d loaded (%.3f sec)." % ( n+1, idx+1, end_time-start_time)) except Exception, e: errmsg = "Error loading NAXIS%d slice %d: %s" % ( n+1, idx+1, str(e)) self.logger.error(errmsg) self.fv.error(errmsg)
def fetch_cache_hdu(self, idx): with self._hdu_cache_lock: if self.hdu_cache.has_key(idx): self.logger.debug("HDU cache hit for index %d" % (idx)) image, dims = self.hdu_cache[idx] return dims, image else: hdu = self.fits_f[idx] path = self.path image = AstroImage() image.set(path=path) dims = list(hdu.data.shape) dims.reverse() image.load_hdu(hdu, fobj=self.fits_f) # TODO: when we've added cache size limiting #self.add_cache_hdu(idx, (image, dims)) return dims, image
def set_hdu(self, idx): self.logger.debug("Loading fits hdu #%d" % (idx)) image = AstroImage() image.set(path=self.path) try: hdu = self.fits_f[idx - 1] dims = list(hdu.data.shape) dims.reverse() image.load_hdu(hdu) self.fitsimage.set_image(image) self.build_naxis(dims) self.curhdu = idx - 1 self.logger.debug("hdu #%d loaded." % (idx)) except Exception, e: errmsg = "Error loading fits hdu #%d: %s" % (idx, str(e)) self.logger.error(errmsg) self.fv.error(errmsg)
def fetch_cache_hdu(self, idx): with self._hdu_cache_lock: if self.hdu_cache.has_key(idx): self.logger.debug("HDU cache hit for index %d" % (idx)) image, dims = self.hdu_cache[idx] return dims, image else: hdu = self.fits_f[idx] path = self.path image = AstroImage() image.set(path=path) dims = list(hdu.data.shape) dims.reverse() image.load_hdu(hdu, fobj=self.fits_f) # TODO: when we've added cache size limiting #self.add_cache_hdu(idx, (image, dims)) return dims, image
def set_hdu(self, idx): self.logger.debug("Loading fits hdu #%d" % (idx)) image = AstroImage() image.set(path=self.path) try: hdu = self.fits_f[idx-1] dims = list(hdu.data.shape) dims.reverse() image.load_hdu(hdu) self.fitsimage.set_image(image) self.build_naxis(dims) self.curhdu = idx-1 self.logger.debug("hdu #%d loaded." % (idx)) except Exception, e: errmsg = "Error loading fits hdu #%d: %s" % ( idx, str(e)) self.logger.error(errmsg) self.fv.error(errmsg)
def quick_reduce(self): image = self.fitsimage.get_image() if image is None: # Nothing to do return path = image.get('path', None) if path is None: return self.q_image.onscreen_message("Working ...") try: #img_data = image.get_data().astype(np.float32) with fits.open(path, 'readonly') as in_f: n = len(in_f) - 1 img_data = in_f[n].data.astype(np.float32) if self.sb_hdu1: # get HDU 1 from the file and subtract it if path != self.hdu1_path: # if not cached then we have to re-fetch it self.hdu1_path = path self.hdu1_data = in_f[1].data sbr_data = img_data - self.hdu1_data else: sbr_data = img_data # create a new image metadata = dict(header=image.get_header()) new_img = AstroImage(data_np=sbr_data, metadata=metadata, logger=self.logger) # no thumbnails presently new_img.set(nothumb=True, path=None, name=image.get('name')) self.q_image.set_image(new_img) finally: self.q_image.onscreen_message(None)