예제 #1
0
    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")
예제 #2
0
    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")
예제 #3
0
    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")
예제 #4
0
    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")
예제 #5
0
    def test_make_filename (self):

        names = []

        for i in range(10):
            name = ImageUtil.makeFilename(os.path.join(os.path.curdir, "autogen-$OBJECT.fits"), subs={"OBJECT": "M5"})
            names.append(name)
            file(name, "w").close()

        print
        for n in names: print n
예제 #6
0
    def test_make_filename (self):

        names = []

        for i in range(10):
            name = ImageUtil.makeFilename(os.path.join(os.path.curdir, "autogen-$OBJECT.fits"), subs={"OBJECT": "M5"})
            names.append(name)
            file(name, "w").close()

        for name in names:
            assert os.path.exists(name)
            os.unlink(name)
예제 #7
0
    def test_make_filename (self):

        names = []

        for i in range(10):
            name = ImageUtil.makeFilename(os.path.join(os.path.curdir, "autogen-$OBJECT.fits"), subs={"OBJECT": "M5"})
            names.append(name)
            file(name, "w").close()

        for name in names:
            assert os.path.exists(name)
            os.unlink(name)
예제 #8
0
    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")
예제 #9
0
    def test_make_filename(self):

        names = []

        for i in range(10):
            name = ImageUtil.makeFilename(os.path.join(os.path.curdir,
                                                       "autogen-$OBJECT.fits"),
                                          subs={"OBJECT": "M5"})
            names.append(name)
            file(name, "w").close()

        print
        for n in names:
            print n
예제 #10
0
    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 _expose(self, imageRequest):
        self.log.debug("apogee - expose - BEGIN")

        shutterRequest = imageRequest['shutter']

        # '~/images/$LAST_NOON_DATE/$DATE-$TIME.fits')
        filenameRequest = ImageUtil.makeFilename( imageRequest['filename'] )
        file(filenameRequest, "w").close()

        exptimeRequest = imageRequest["exptime"]
        self.log.debug("shutterRequest = %s" % shutterRequest)
        self.log.debug("filenameRequest = %s" % filenameRequest)
        self.log.debug("exptime = %s" % exptimeRequest)

        self.exposeBegin(imageRequest)

        self.__apogee_manager.expose(filenameRequest, int(exptimeRequest), int(shutterRequest) )
        status = CameraStatus.OK

        self.exposeComplete(imageRequest, status)
        self.log.debug("apogee - expose - END")
    def _expose(self, imageRequest):
        self.log.debug("apogee - expose - BEGIN")

        shutterRequest = imageRequest['shutter']

        # '~/images/$LAST_NOON_DATE/$DATE-$TIME.fits')
        filenameRequest = ImageUtil.makeFilename(imageRequest['filename'])
        file(filenameRequest, "w").close()

        exptimeRequest = imageRequest["exptime"]
        self.log.debug("shutterRequest = %s" % shutterRequest)
        self.log.debug("filenameRequest = %s" % filenameRequest)
        self.log.debug("exptime = %s" % exptimeRequest)

        self.exposeBegin(imageRequest)

        self.__apogee_manager.expose(filenameRequest, int(exptimeRequest),
                                     int(shutterRequest))
        status = CameraStatus.OK

        self.exposeComplete(imageRequest, status)
        self.log.debug("apogee - expose - END")
예제 #13
0
파일: apogee.py 프로젝트: agati/chimera
    def _expose(self, imageRequest):
        self.log.debug("apogee - expose - BEGIN")

        shutterRequest = imageRequest['shutter']

        # '~/images/$LAST_NOON_DATE/$DATE-$TIME.fits')
        filenameRequest = ImageUtil.makeFilename(imageRequest['filename'])
        imageRequest['filenameRequest'] = filenameRequest
        file(filenameRequest, "w").close()

        exptimeRequest = imageRequest["exptime"]
        self.log.debug("shutterRequest = %s" % shutterRequest)
        self.log.debug("filenameRequest = %s" % filenameRequest)
        self.log.debug("exptime = %s" % exptimeRequest)

        #  0 = false
        shutter = 0
        if shutterRequest == Shutter.OPEN:
            shutter = 1
        elif shutterRequest == Shutter.CLOSE:
            shutter = 0

        self.log.debug("shutter = %d" % shutter)

        self.exposeBegin(imageRequest)
        self.__apogee_manager.expose(
            filenameRequest, int(exptimeRequest), int(shutterRequest))

        # if any error happens, it will be thrown an exception
        status = CameraStatus.OK

        # save time exposure started
        self.lastFrameStartTime = dt.datetime.utcnow()
        self.lastFrameTemp = self.__apogee_manager.getTemperature()

        self.exposeComplete(imageRequest, status)
        self.log.debug("apogee - expose - END")
예제 #14
0
    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()))