예제 #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
파일: camera.py 프로젝트: phsilva/chimera
    def _saveImage(self, imageRequest, imageData, extra):

        (mode, binning, top, left, width,
         height) = self._getReadoutModeInfo(imageRequest["binning"],
                                            imageRequest["window"])

        binFactor = extra.get("binning_factor", 1.0)

        pix_w, pix_h = self.getPixelSize()
        focal_length = self["telescope_focal_length"]

        scale_x = binFactor * (((180 / pi) / focal_length) * (pix_w * 0.001))
        scale_y = binFactor * (((180 / pi) / focal_length) * (pix_h * 0.001))

        full_width, full_height = self.getPhysicalSize()
        CRPIX1 = ((int(full_width / 2.0)) - left) - 1
        CRPIX2 = ((int(full_height / 2.0)) - top) - 1

        t0 = time.time()
        img = Image.create(imageData, imageRequest)

        img += [
            ('DATE-OBS',
             ImageUtil.formatDate(
                 extra.get("frame_start_time",
                           dt.datetime.utcnow())), 'Date exposure started'),
            ('CCD-TEMP', extra.get("frame_temperature", -275.0),
             'CCD Temperature at Exposure Start [deg. C]'),
            ("EXPTIME", float(imageRequest['exptime'])
             or -1, "exposure time in seconds"),
            ('IMAGETYP', imageRequest['type'].strip(), 'Image type'),
            ('SHUTTER', str(imageRequest['shutter']),
             'Requested shutter state'),
            ("CRPIX1", CRPIX1, "coordinate system reference pixel"),
            ("CRPIX2", CRPIX2, "coordinate system reference pixel"),
            ("CD1_1", scale_x, "transformation matrix element (1,1)"),
            ("CD1_2", 0.0, "transformation matrix element (1,2)"),
            ("CD2_1", 0.0, "transformation matrix element (2,1)"),
            ("CD2_2", scale_y, "transformation matrix element (2,2)"),
            ('CAMERA', str(self['camera_model']), 'Camera Model'),
            ('CCD', str(self['ccd_model']), 'CCD Model'),
            ('CCD_DIMX', self.getPhysicalSize()[0], 'CCD X Dimension Size'),
            ('CCD_DIMY', self.getPhysicalSize()[1], 'CCD Y Dimension Size'),
            ('CCDPXSZX', self.getPixelSize()[0],
             'CCD X Pixel Size [micrometer]'),
            ('CCDPXSZY', self.getPixelSize()[1],
             'CCD Y Pixel Size [micrometer]')
        ]

        # register image on ImageServer
        server = getImageServer(self.getManager())
        proxy = server.register(img)

        # and finally compress the image
        img.compress(multiprocess=True)

        return proxy
예제 #5
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")
예제 #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()

        print
        for n in names: print n
예제 #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)
    def _saveImage(self, imageRequest, imageData, extra):

        (mode, binning, top, left, width, height) = self._getReadoutModeInfo(
            imageRequest["binning"], imageRequest["window"]
        )

        binFactor = extra.get("binning_factor", 1.0)

        pix_w, pix_h = self.getPixelSize()
        focal_length = self["telescope_focal_length"]

        scale_x = binFactor * (((180 / pi) / focal_length) * (pix_w * 0.001))
        scale_y = binFactor * (((180 / pi) / focal_length) * (pix_h * 0.001))

        full_width, full_height = self.getPhysicalSize()
        CRPIX1 = ((int(full_width / 2.0)) - left) - 1
        CRPIX2 = ((int(full_height / 2.0)) - top) - 1

        t0 = time.time()
        img = Image.create(imageData, imageRequest)

        img += [
            (
                "DATE-OBS",
                ImageUtil.formatDate(extra.get("frame_start_time", dt.datetime.utcnow())),
                "Date exposure started",
            ),
            ("CCD-TEMP", extra.get("frame_temperature", -275.0), "CCD Temperature at Exposure Start [deg. C]"),
            ("EXPTIME", float(imageRequest["exptime"]) or -1, "exposure time in seconds"),
            ("IMAGETYP", imageRequest["type"].strip(), "Image type"),
            ("SHUTTER", str(imageRequest["shutter"]), "Requested shutter state"),
            ("CRPIX1", CRPIX1, "coordinate system reference pixel"),
            ("CRPIX2", CRPIX2, "coordinate system reference pixel"),
            ("CD1_1", scale_x, "transformation matrix element (1,1)"),
            ("CD1_2", 0.0, "transformation matrix element (1,2)"),
            ("CD2_1", 0.0, "transformation matrix element (2,1)"),
            ("CD2_2", scale_y, "transformation matrix element (2,2)"),
            ("CAMERA", str(self["camera_model"]), "Camera Model"),
            ("CCD", str(self["ccd_model"]), "CCD Model"),
            ("CCD_DIMX", self.getPhysicalSize()[0], "CCD X Dimension Size"),
            ("CCD_DIMY", self.getPhysicalSize()[1], "CCD Y Dimension Size"),
            ("CCDPXSZX", self.getPixelSize()[0], "CCD X Pixel Size [micrometer]"),
            ("CCDPXSZY", self.getPixelSize()[1], "CCD Y Pixel Size [micrometer]"),
        ]

        # register image on ImageServer
        server = getImageServer(self.getManager())
        proxy = server.register(img)

        # and finally compress the image
        img.compress(multiprocess=True)

        return proxy
예제 #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()

        for name in names:
            assert os.path.exists(name)
            os.unlink(name)
예제 #10
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")
    def getMetadata(self, request):

        try:
            return [('ENVMOD', str(self['model']), 'Weather station Model'),
                    ('ENVTEM', self.temperature(unit_out=units.deg_C).value, '[degC] Weather station temperature'),
                    ('ENVDEW', self.dew_point(unit_out=units.deg_C).value, '[degC] Weather station dew point temperature'),
                    ('ENVHUM', self.humidity(unit_out=units.pct).value, '[%] Weather station relative humidity'),
                    ('ENVWIN', self.wind_speed(unit_out=units.m / units.s).value, '[m/s] Weather station wind speed'),
                    ('ENVDIR', self.wind_direction(unit_out=units.deg).value, '[deg] Weather station wind direction'),
                    ('ENVPRE', self.pressure(unit_out=units.cds.mmHg).value, '[mmHg] Weather station air pressure'),
                    ('ENVDAT', ImageUtil.formatDate(self._results['utctime']), 'UT time of the meteo observation')
                    ]
        except AttributeError:
            return []
예제 #12
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
예제 #13
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")
예제 #14
0
파일: camera.py 프로젝트: tribeiro/chimera
    def getMetadata(self, request):
        # Check first if there is metadata from an metadata override method.
        md = self.getMetadataOverride(request)
        if md is not None:
            return md
        # If not, just go on with the instrument's default metadata.
        md = [('DATE-OBS', ImageUtil.formatDate(self.extra_header_info.get("frame_start_time", dt.datetime.utcnow())),
               'Date exposure started'),
              ("EXPTIME", float(request['exptime']), "exposure time in seconds"),
              ('IMAGETYP', request['type'].strip(), 'Image type'),
              ('SHUTTER', str(request['shutter']), 'Requested shutter state'),
              ('INSTRUME', str(self['camera_model']), 'Name of instrument'),
              ('CCD',    str(self['ccd_model']), 'CCD Model'),
              ('CCD_DIMX', self.getPhysicalSize()[0], 'CCD X Dimension Size'),
              ('CCD_DIMY', self.getPhysicalSize()[1], 'CCD Y Dimension Size'),
              ('CCDPXSZX', self.getPixelSize()[0], 'CCD X Pixel Size [micrometer]'),
              ('CCDPXSZY', self.getPixelSize()[1], 'CCD Y Pixel Size [micrometer]')]

        if "frame_temperature" in self.extra_header_info.keys():
              md += [('CCD-TEMP', self.extra_header_info["frame_temperature"],
                      'CCD Temperature at Exposure Start [deg. C]')]

        focal_length = self["telescope_focal_length"]
        if focal_length is not None:  # If there is no telescope_focal_length defined, don't store WCS
            mode, binning, top, left, width, height = self._getReadoutModeInfo(request["binning"], request["window"])
            binFactor = self.extra_header_info.get("binning_factor", 1.0)
            pix_w, pix_h = self.getPixelSize()
            focal_length = self["telescope_focal_length"]

            scale_x = binFactor * (((180 / pi) / focal_length) * (pix_w * 0.001))
            scale_y = binFactor * (((180 / pi) / focal_length) * (pix_h * 0.001))

            full_width, full_height = self.getPhysicalSize()
            CRPIX1 = ((int(full_width / 2.0)) - left) - 1
            CRPIX2 = ((int(full_height / 2.0)) - top) - 1

            # Adding WCS coordinates according to FITS standard.
            # Quick sheet: http://www.astro.iag.usp.br/~moser/notes/GAi_FITSimgs.html
            # http://adsabs.harvard.edu/abs/2002A%26A...395.1061G
            # http://adsabs.harvard.edu/abs/2002A%26A...395.1077C
            md += [("CRPIX1", CRPIX1, "coordinate system reference pixel"),
                   ("CRPIX2", CRPIX2, "coordinate system reference pixel"),
                   ("CD1_1",  scale_x * cos(self["rotation"]*pi/180.), "transformation matrix element (1,1)"),
                   ("CD1_2", -scale_y * sin(self["rotation"]*pi/180.), "transformation matrix element (1,2)"),
                   ("CD2_1", scale_x * sin(self["rotation"]*pi/180.), "transformation matrix element (2,1)"),
                   ("CD2_2", scale_y * cos(self["rotation"]*pi/180.), "transformation matrix element (2,2)")]

        return md
    def getMetadata(self, request):

        if not self._check():
            return []

        return [('ENVMOD', str(self['model']), 'Weather station Model'),
                ('ENVTEM', self.temperature(unit_out=units.deg_C).value,
                 '[degC] Weather station temperature'),
                ('ENVDEW', self.dew_point(unit_out=units.deg_C).value,
                 '[degC] Weather station dew point temperature'),
                ('ENVHUM', self.humidity(unit_out=units.pct).value,
                 '[%] Weather station relative humidity'),
                ('ENVWIN', self.wind_speed(unit_out=units.m / units.s).value,
                 '[m/s] Weather station wind speed'),
                ('ENVDIR', self.wind_direction(unit_out=units.deg).value,
                 '[deg] Weather station wind direction'),
                ('ENVPRE', self.pressure(unit_out=units.cds.mmHg).value,
                 '[mmHg] Weather station air pressure'),
                ('ENVDAT', ImageUtil.formatDate(self.obs_time()),
                 'UT time of the meteo observation')]
    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")
예제 #18
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")
예제 #19
0
                except Exception, e:
                    self.log.warning("MakekFlat error: " + str(e))

        #Last resort if nothing else could make a picture
        if (pix == None):
            pix = N.zeros((100, 100), dtype=N.int32)

        imageRequest.fetchPostHeaders(self.getManager())

        img = Image.create(pix, imageRequest)

        # update image request
        imageRequest["filename"] = img.filename()

        img += [('DATE-OBS',
                 ImageUtil.formatDate(
                     dt.datetime.fromtimestamp(self.__lastFrameStart)))]

        server = getImageServer(self.getManager())
        proxy = server.register(img)

        self.readoutComplete(proxy)

        return proxy

    def abortExposure(self):

        if not self.isExposing(): return

        self.__abort.set()

        # busy waiting for exposure/readout stops
예제 #20
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()))
예제 #21
0
        imageRequest.addPostHeaders(self.getManager())

        binFactor = self._binning_factors[binning]
        scale_x = binFactor * (((180 / pi) / cam["telescope_focal_length"]) *
                               (self.getPixelSize()[0] * 0.001))
        scale_y = binFactor * (((180 / pi) / cam["telescope_focal_length"]) *
                               (self.getPixelSize()[1] * 0.001))

        fullsize = self.drv.readoutModes[self.ccd][0]

        CRPIX1 = ((int(fullsize.width / 2)) - left) - 1
        CRPIX2 = ((int(fullsize.height / 2)) - top) - 1

        img = Image.create(img, imageRequest)

        img += [('DATE-OBS', ImageUtil.formatDate(self.lastFrameStartTime),
                 'Date exposure started'),
                ('CCD-TEMP', self.lastFrameTemp,
                 'CCD Temperature at Exposure Start [deg. C]'),
                ("EXPTIME", float(imageRequest['exptime'])
                 or -1, "exposure time in seconds"),
                ('IMAGETYP', imageRequest['type'].strip(), 'Image type'),
                ('SHUTTER', str(imageRequest['shutter']),
                 'Requested shutter state'),
                ("CRPIX1", CRPIX1, "coordinate system reference pixel"),
                ("CRPIX2", CRPIX2, "coordinate system reference pixel"),
                ("CD1_1", scale_x, "transformation matrix element (1,1)"),
                ("CD1_2", 0.0, "transformation matrix element (1,2)"),
                ("CD2_1", 0.0, "transformation matrix element (2,1)"),
                ("CD2_2", scale_y, "transformation matrix element (2,2)")]
예제 #22
0
파일: camera.py 프로젝트: rayshifu/chimera
    def getMetadata(self, request):
        # Check first if there is metadata from an metadata override method.
        md = self.getMetadataOverride(request)
        if md is not None:
            return md
        # If not, just go on with the instrument's default metadata.
        md = [("EXPTIME", float(request['exptime']), "exposure time in seconds"),
              ('IMAGETYP', request['type'].strip(), 'Image type'),
              ('SHUTTER', str(request['shutter']), 'Requested shutter state'),
              ('INSTRUME', str(self['camera_model']), 'Name of instrument'),
              ('CCD',    str(self['ccd_model']), 'CCD Model'),
              ('CCD_DIMX', self.getPhysicalSize()[0], 'CCD X Dimension Size'),
              ('CCD_DIMY', self.getPhysicalSize()[1], 'CCD Y Dimension Size'),
              ('CCDPXSZX', self.getPixelSize()[0], 'CCD X Pixel Size [micrometer]'),
              ('CCDPXSZY', self.getPixelSize()[1], 'CCD Y Pixel Size [micrometer]')]

        if request['window'] is not None:
            md += [('DETSEC', request['window'],
                    'Detector coodinates of the image')]

        if "frame_temperature" in self.extra_header_info.keys():
              md += [('CCD-TEMP', self.extra_header_info["frame_temperature"],
                      'CCD Temperature at Exposure Start [deg. C]')]

        if "frame_start_time" in self.extra_header_info.keys():
            md += [('DATE-OBS', ImageUtil.formatDate(self.extra_header_info.get("frame_start_time")),
                    'Date exposure started')]

        mode, binning, top, left, width, height = self._getReadoutModeInfo(request["binning"], request["window"])
        # Binning keyword: http://iraf.noao.edu/projects/ccdmosaic/imagedef/mosaic/MosaicV1.html
        #    CCD on-chip summing given as two or four integer numbers.  These define
        # the summing of CCD pixels in the amplifier readout order.  The first
        # two numbers give the number of pixels summed in the serial and parallel
        # directions respectively.  If the first pixel read out consists of fewer
        # unbinned pixels along either direction the next two numbers give the
        # number of pixels summed for the first serial and parallel pixels.  From
        # this it is implicit how many pixels are summed for the last pixels
        # given the size of the CCD section (CCDSEC).  It is highly recommended
        # that controllers read out all pixels with the same summing in which
        # case the size of the CCD section will be the summing factors times the
        # size of the data section.
        md += [("CCDSUM", binning.replace("x", " "), "CCD on-chip summing")]

        focal_length = self["telescope_focal_length"]
        if focal_length is not None:  # If there is no telescope_focal_length defined, don't store WCS
            binFactor = self.extra_header_info.get("binning_factor", 1.0)
            pix_w, pix_h = self.getPixelSize()
            focal_length = self["telescope_focal_length"]

            scale_x = binFactor * (((180 / pi) / focal_length) * (pix_w * 0.001))
            scale_y = binFactor * (((180 / pi) / focal_length) * (pix_h * 0.001))

            full_width, full_height = self.getPhysicalSize()
            CRPIX1 = ((int(full_width / 2.0)) - left) - 1
            CRPIX2 = ((int(full_height / 2.0)) - top) - 1

            # Adding WCS coordinates according to FITS standard.
            # Quick sheet: http://www.astro.iag.usp.br/~moser/notes/GAi_FITSimgs.html
            # http://adsabs.harvard.edu/abs/2002A%26A...395.1061G
            # http://adsabs.harvard.edu/abs/2002A%26A...395.1077C
            md += [("CRPIX1", CRPIX1, "coordinate system reference pixel"),
                   ("CRPIX2", CRPIX2, "coordinate system reference pixel"),
                   ("CD1_1",  scale_x * cos(self["rotation"]*pi/180.), "transformation matrix element (1,1)"),
                   ("CD1_2", -scale_y * sin(self["rotation"]*pi/180.), "transformation matrix element (1,2)"),
                   ("CD2_1", scale_x * sin(self["rotation"]*pi/180.), "transformation matrix element (2,1)"),
                   ("CD2_2", scale_y * cos(self["rotation"]*pi/180.), "transformation matrix element (2,2)")]

        return md
예제 #23
0
파일: camera.py 프로젝트: ankanaan/chimera
    def _saveImage(self, imageRequest, imageData, extra):

        (mode, binning, top, left,
         width, height) = self._getReadoutModeInfo(imageRequest["binning"],
                                                   imageRequest["window"])

        binFactor = extra.get("binning_factor", 1.0)

        pix_w, pix_h = self.getPixelSize()

        img = Image.create(imageData, imageRequest)

        if self["telescope_focal_length"] is not None:  # If there is no telescope_focal_length defined, don't store WCS
            focal_length = self["telescope_focal_length"]

            scale_x = binFactor * (((180 / pi) / focal_length) * (pix_w * 0.001))
            scale_y = binFactor * (((180 / pi) / focal_length) * (pix_h * 0.001))

            full_width, full_height = self.getPhysicalSize()
            CRPIX1 = ((int(full_width / 2.0)) - left) - 1
            CRPIX2 = ((int(full_height / 2.0)) - top) - 1

            # Adding WCS coordinates according to FITS standard.
            # Quick sheet: http://www.astro.iag.usp.br/~moser/notes/GAi_FITSimgs.html
            # http://adsabs.harvard.edu/abs/2002A%26A...395.1061G
            # http://adsabs.harvard.edu/abs/2002A%26A...395.1077C
            img += [("CRPIX1", CRPIX1, "coordinate system reference pixel"),
                ("CRPIX2", CRPIX2, "coordinate system reference pixel"),
                ("CD1_1",  scale_x * cos(self["rotation"]*pi/180.), "transformation matrix element (1,1)"),
                ("CD1_2", -scale_y * sin(self["rotation"]*pi/180.), "transformation matrix element (1,2)"),
                ("CD2_1", scale_x * sin(self["rotation"]*pi/180.), "transformation matrix element (2,1)"),
                ("CD2_2", scale_y * cos(self["rotation"]*pi/180.), "transformation matrix element (2,2)")]

        img += [('DATE-OBS',
                 ImageUtil.formatDate(
                     extra.get("frame_start_time", dt.datetime.utcnow())),
                 'Date exposure started'),

                ('CCD-TEMP', extra.get("frame_temperature", -275.0),
                 'CCD Temperature at Exposure Start [deg. C]'),

                ("EXPTIME", float(imageRequest['exptime']) or -1,
                 "exposure time in seconds"),

                ('IMAGETYP', imageRequest['type'].strip(),
                 'Image type'),

                ('SHUTTER', str(imageRequest['shutter']),
                 'Requested shutter state'),

                ('INSTRUME', str(self['camera_model']), 'Name of instrument'),
                ('CCD',    str(self['ccd_model']), 'CCD Model'),
                ('CCD_DIMX', self.getPhysicalSize()
                 [0], 'CCD X Dimension Size'),
                ('CCD_DIMY', self.getPhysicalSize()
                 [1], 'CCD Y Dimension Size'),
                ('CCDPXSZX', self.getPixelSize()[0],
                 'CCD X Pixel Size [micrometer]'),
                ('CCDPXSZY', self.getPixelSize()[1],
                 'CCD Y Pixel Size [micrometer]')]

        # register image on ImageServer
        server = getImageServer(self.getManager())
        proxy = server.register(img)

        # and finally compress the image if asked
        if imageRequest['compress_format'].lower() != 'no':
            img.compress(format=imageRequest['compress_format'], multiprocess=True)

        return proxy
예제 #24
0
    def getMetadata(self, request):
        # Check first if there is metadata from an metadata override method.
        md = self.getMetadataOverride(request)
        if md is not None:
            return md
        # If not, just go on with the instrument's default metadata.
        md = [('DATE-OBS',
               ImageUtil.formatDate(
                   self.extra_header_info.get("frame_start_time",
                                              dt.datetime.utcnow())),
               'Date exposure started'),
              ("EXPTIME", float(request['exptime']),
               "exposure time in seconds"),
              ('IMAGETYP', request['type'].strip(), 'Image type'),
              ('SHUTTER', str(request['shutter']), 'Requested shutter state'),
              ('INSTRUME', str(self['camera_model']), 'Name of instrument'),
              ('CCD', str(self['ccd_model']), 'CCD Model'),
              ('CCD_DIMX', self.getPhysicalSize()[0], 'CCD X Dimension Size'),
              ('CCD_DIMY', self.getPhysicalSize()[1], 'CCD Y Dimension Size'),
              ('CCDPXSZX', self.getPixelSize()[0],
               'CCD X Pixel Size [micrometer]'),
              ('CCDPXSZY', self.getPixelSize()[1],
               'CCD Y Pixel Size [micrometer]')]

        if "frame_temperature" in self.extra_header_info.keys():
            md += [('CCD-TEMP', self.extra_header_info["frame_temperature"],
                    'CCD Temperature at Exposure Start [deg. C]')]

        focal_length = self["telescope_focal_length"]
        if focal_length is not None:  # If there is no telescope_focal_length defined, don't store WCS
            mode, binning, top, left, width, height = self._getReadoutModeInfo(
                request["binning"], request["window"])
            binFactor = self.extra_header_info.get("binning_factor", 1.0)
            pix_w, pix_h = self.getPixelSize()
            focal_length = self["telescope_focal_length"]

            scale_x = binFactor * (((180 / pi) / focal_length) *
                                   (pix_w * 0.001))
            scale_y = binFactor * (((180 / pi) / focal_length) *
                                   (pix_h * 0.001))

            full_width, full_height = self.getPhysicalSize()
            CRPIX1 = ((int(full_width / 2.0)) - left) - 1
            CRPIX2 = ((int(full_height / 2.0)) - top) - 1

            # Adding WCS coordinates according to FITS standard.
            # Quick sheet: http://www.astro.iag.usp.br/~moser/notes/GAi_FITSimgs.html
            # http://adsabs.harvard.edu/abs/2002A%26A...395.1061G
            # http://adsabs.harvard.edu/abs/2002A%26A...395.1077C
            md += [("CRPIX1", CRPIX1, "coordinate system reference pixel"),
                   ("CRPIX2", CRPIX2, "coordinate system reference pixel"),
                   ("CD1_1", scale_x * cos(self["rotation"] * pi / 180.),
                    "transformation matrix element (1,1)"),
                   ("CD1_2", -scale_y * sin(self["rotation"] * pi / 180.),
                    "transformation matrix element (1,2)"),
                   ("CD2_1", scale_x * sin(self["rotation"] * pi / 180.),
                    "transformation matrix element (2,1)"),
                   ("CD2_2", scale_y * cos(self["rotation"] * pi / 180.),
                    "transformation matrix element (2,2)")]

        return md