def _takeImage(self): cam = self.getCam() if self.filter: filter = self.getFilter() filter.setFilter(self.filter) self.imageRequest["filename"] = os.path.basename(ImageUtil.makeFilename("align-$DATE")) frames = cam.expose(self.imageRequest) if frames: image = frames[0] image_path = image.filename() if not os.path.exists(image_path): # If image is on a remote server, donwload it. # If remote is windows, image_path will be c:\...\image.fits, so use ntpath instead of os.path. if ':\\' in image_path: modpath = ntpath else: modpath = os.path image_path = ImageUtil.makeFilename(os.path.join(getImageServer(self.getManager()).defaultNightDir(), modpath.basename(image_path))) t0 = time.time() self.log.debug('Downloading image from server to %s' % image_path) if not ImageUtil.download(image, image_path): raise ChimeraException('Error downloading image %s from %s' % (image_path, image.http())) self.log.debug('Finished download. Took %3.2f seconds' % (time.time() - t0)) image = Image.fromFile(image_path) return image #image_path #, image else: raise Exception("Could not take an image")
def _takeImage(self, exptime, filter): cam = self._getCam() if self["filterwheel"] is not None: fw = self._getFilterWheel() fw.setFilter(filter) self.log.debug("Start frame") frames = cam.expose(exptime=exptime, frames=1, shutter=Shutter.OPEN, filename=os.path.basename(ImageUtil.makeFilename("skyflat-$DATE"))) self.log.debug("End frame") if frames: image = frames[0] image_path = image.filename() if not os.path.exists(image_path): # If image is on a remote server, donwload it. # If remote is windows, image_path will be c:\...\image.fits, so use ntpath instead of os.path. if ':\\' in image_path: modpath = ntpath else: modpath = os.path image_path = ImageUtil.makeFilename(os.path.join(getImageServer(self.getManager()).defaultNightDir(), modpath.basename(image_path))) t0 = time.time() self.log.debug('Downloading image from server to %s' % image_path) if not ImageUtil.download(image, image_path): raise ChimeraException('Error downloading image %s from %s' % (image_path, image.http())) self.log.debug('Finished download. Took %3.2f seconds' % (time.time() - t0)) return image_path, image else: raise Exception("Could not take an image")
def _takeImage(self): if self._debugging: try: frame = self._debug_images[self._debug_image] self._debug_image += 1 img = Image.fromFile(frame) srv = getImageServer(self.getManager()) return srv.register(img) except IndexError: raise ChimeraException("Cannot find debug images") self.imageRequest["filename"] = os.path.basename( ImageUtil.makeFilename("focus-$DATE")) cam = self.getCam() if self.filter: filter = self.getFilter() filter.setFilter(self.filter) frames = cam.expose(self.imageRequest) if frames: image = frames[0] image_path = image.filename() if not os.path.exists( image_path ): # If image is on a remote server, donwload it. # If remote is windows, image_path will be c:\...\image.fits, so use ntpath instead of os.path. if ':\\' in image_path: modpath = ntpath else: modpath = os.path image_path = ImageUtil.makeFilename( os.path.join( getImageServer(self.getManager()).defaultNightDir(), modpath.basename(image_path))) t0 = time.time() self.log.debug('Downloading image from server to %s' % image_path) if not ImageUtil.download(image, image_path): raise ChimeraException( 'Error downloading image %s from %s' % (image_path, image.http())) self.log.debug('Finished download. Took %3.2f seconds' % (time.time() - t0)) return image_path, image else: raise Exception("Could not take an image")
def _takeImage(self): if self._debugging: try: frame = self._debug_images[self._debug_image] self._debug_image += 1 img = Image.fromFile(frame) srv = getImageServer(self.getManager()) return srv.register(img) except IndexError: raise ChimeraException("Cannot find debug images") self.imageRequest["filename"] = os.path.basename(ImageUtil.makeFilename("focus-$DATE")) cam = self.getCam() if self.filter: filter = self.getFilter() filter.setFilter(self.filter) frames = cam.expose(self.imageRequest) if frames: image = frames[0] image_path = image.filename() if not os.path.exists(image_path): # If image is on a remote server, donwload it. # If remote is windows, image_path will be c:\...\image.fits, so use ntpath instead of os.path. if ":\\" in image_path: modpath = ntpath else: modpath = os.path image_path = ImageUtil.makeFilename( os.path.join(getImageServer(self.getManager()).defaultNightDir(), modpath.basename(image_path)) ) t0 = time.time() self.log.debug("Downloading image from server to %s" % image_path) if not ImageUtil.download(image, image_path): raise ChimeraException("Error downloading image %s from %s" % (image_path, image.http())) self.log.debug("Finished download. Took %3.2f seconds" % (time.time() - t0)) return image_path, image else: raise Exception("Could not take an image")
def _takeImage(self, exptime, filter, download=False): cam = self._getCam() if self["filterwheel"] is not None: fw = self._getFilterWheel() fw.setFilter(filter) self.log.debug("Start frame") request = ImageRequest(exptime=exptime, frames=1, shutter=Shutter.OPEN, filename=os.path.basename(ImageUtil.makeFilename("skyflat-$DATE-$TIME")), type='sky-flat') self.log.debug('ImageRequest: {}'.format(request)) frames = cam.expose(request) self.log.debug("End frame") # checking for aborting signal if self._abort.isSet(): self.log.warning('Aborting exposure!') raise ProgramExecutionAborted() if frames: image = frames[0] image_path = image.filename() if download and not os.path.exists(image_path): # If image is on a remote server, donwload it. # If remote is windows, image_path will be c:\...\image.fits, so use ntpath instead of os.path. if ':\\' in image_path: modpath = ntpath else: modpath = os.path image_path = ImageUtil.makeFilename(os.path.join(getImageServer(self.getManager()).defaultNightDir(), modpath.basename(image_path))) t0 = time.time() self.log.debug('Downloading image from server to %s' % image_path) if not ImageUtil.download(image, image_path): raise ChimeraException('Error downloading image %s from %s' % (image_path, image.http())) self.log.debug('Finished download. Took %3.2f seconds' % (time.time() - t0)) return image_path, image else: raise Exception("Could not take an image")
def _takeImage(self): cam = self.getCam() if cam["telescope_focal_length"] is None: raise ChimeraException("telescope_focal_length parameter must be set on camera instrument configuration") if self["filterwheel"] is not None: fw = self.getFilterWheel() fw.setFilter(self["filter"]) frames = cam.expose( exptime=self["exptime"], frames=1, shutter=Shutter.OPEN, filename=os.path.basename(ImageUtil.makeFilename("pointverify-$DATE")), ) if frames: image = frames[0] image_path = image.filename() if not os.path.exists(image_path): # If image is on a remote server, donwload it. # If remote is windows, image_path will be c:\...\image.fits, so use ntpath instead of os.path. if ":\\" in image_path: modpath = ntpath else: modpath = os.path image_path = ImageUtil.makeFilename( os.path.join(getImageServer(self.getManager()).defaultNightDir(), modpath.basename(image_path)) ) t0 = time.time() self.log.debug("Downloading image from server to %s" % image_path) if not ImageUtil.download(image, image_path): raise ChimeraException("Error downloading image %s from %s" % (image_path, image.http())) self.log.debug("Finished download. Took %3.2f seconds" % (time.time() - t0)) return image_path, image else: raise Exception("Could not take an image")
def run_stats(self, proxy, status): if status == CameraStatus.OK and proxy["IMAGETYP"].upper().rstrip() == "OBJECT" and \ proxy["SHUTTER"].upper().rstrip() == "OPEN": self.log.debug('%s [status:%s]@[%s]' % (proxy.filename(), status, proxy.http())) image_path = proxy.filename() if not os.path.exists( image_path ): # If image is on a remote server, donwload it. # If remote is windows, image_path will be c:\...\image.fits, so use ntpath instead of os.path. if ':\\' in image_path: modpath = ntpath else: modpath = os.path image_path = ImageUtil.makeFilename( os.path.join( getImageServer(self.getManager()).defaultNightDir(), modpath.basename(image_path))) t0 = time.time() self.log.debug('Downloading image from server to %s' % image_path) if not ImageUtil.download(proxy, image_path): raise ChimeraException( 'Error downloading image %s from %s' % (image_path, image.http())) self.log.debug('Finished download. Took %3.2f seconds' % (time.time() - t0)) img = Image.fromFile(image_path) else: img = Image.fromFile(image_path) tmpfile = mktemp() p = self._sex_params p.update({"CATALOG_NAME": mktemp()}) extract = img.extract(p) # os.unlink(tmpfile) # else: # extract = proxy.extract(self.sex_params) if len(extract ) > 0: # Only go ahead if at least one object was detected # stats = np.array( # [[data["CLASS_STAR"], data["FLAGS"], data["FWHM_IMAGE"], data["BACKGROUND"]] for data in # extract]) stats = np.array([[ data["NUMBER"], data["X_IMAGE"], data["Y_IMAGE"], data["XWIN_IMAGE"], data["YWIN_IMAGE"], data["ALPHA_J2000"], data["DELTA_J2000"], data["MAG_AUTO"], data["FLUX_AUTO"], data["BACKGROUND"], data["FWHM_IMAGE"], data["FLAGS"], data["CLASS_STAR"], ] for data in extract]) mask = np.bitwise_and(stats[:, 12] > 0.8, stats[:, 11] == 0) fff = "CLEAR" if "FILTER" in proxy.keys(): fff = proxy["FILTER"] # fff = "R" session = Session() try: log = ImageStatistics( date_obs=datetime.datetime.strptime( proxy["DATE-OBS"], "%Y-%m-%dT%H:%M:%S.%f"), filename=proxy.filename(), filter=fff, fwhm_avg=np.average(stats[:, 10][mask]), fwhm_std=np.std(stats[:, 10][mask]), background=np.average(stats[:, 9][mask]), npts=mask.sum(), exptime=proxy["EXPTIME"]) session.add(log) session.flush() session.refresh(log) # Now add stars to the star catalog # Todo: Solve astrometry cat = [] mag_sort = np.argsort(stats[:, 7])[:self['max_stars_catalog']] for data in stats[mag_sort]: cat.append( ImageCatalog( image_statistics_id=log.id, NUMBER=data[0], X_IMAGE=data[1], Y_IMAGE=data[2], XWIN_IMAGE=data[3], YWIN_IMAGE=data[4], ALPHA_J2000=data[5], DELTA_J2000=data[6], MAG_AUTO=data[7], FLUX_AUTO=data[8], BACKGROUND=data[9], FWHM_IMAGE=data[10], FLAGS=data[11], CLASS_STAR=data[12], )) session.add_all(cat) finally: session.commit() # self.stats.append(s) # print "fwhm stats:", s # self.stats[-1] else: self.log.debug( 'Image %s not good for statistics. [status:%s]@[%s]' % (proxy.filename(), status, proxy.http()))