Esempio n. 1
0
 def get_header_data_list(self):
     try:
         header = self.get_current_astrom_header()
         hlist = [(key, value) for key, value in header.iteritems()]
     except AttributeError as e:
         logger.error(str(e))
         hlist = [
             ("NONE", "NONE"),
         ]
     return hlist
Esempio n. 2
0
File: core.py Progetto: OSSOS/MOP
    def from_string(cls, rawstr):
        """
        Creates an ApcorData record from the raw string format.

        Expected string format:
        ap_in ap_out   ap_cor  apcor_err
        """
        try:
            args = map(float, rawstr.split())
        except Exception as ex:
            import sys
            logger.error("Failed to convert aperture correction: {}".format(ex))
            raise ex
        return cls(*args)
Esempio n. 3
0
File: core.py Progetto: ijiraq/MOP
    def from_string(cls, rawstr):
        """
        Creates an ApcorData record from the raw string format.

        Expected string format:
        ap_in ap_out   ap_cor  apcor_err
        """
        try:
            args = list(map(float, rawstr.split()))
        except Exception as ex:
            import sys
            logger.error(
                "Failed to convert aperture correction: {}".format(ex))
            raise ex
        return cls(*args)
Esempio n. 4
0
    def handle_general_download_error(self, error_message, download_request):
        logger.warning("A problem occurred while downloading: %s" % error_message)
        logger.error("-" * 60)
        logger.error(traceback.format_exc())
        logger.error("-" * 60)

        self._failed_downloads.append(download_request)
        self.app.get_view().show_retry_download_dialog(self, error_message)
Esempio n. 5
0
    def handle_general_download_error(self, error_message, download_request):
        logger.warning("A problem occurred while downloading: %s" % error_message)
        logger.error("-" * 60)
        logger.error(traceback.format_exc())
        logger.error("-" * 60)

        self._failed_downloads.append(download_request)
        self.app.get_view().show_retry_download_dialog(self, error_message)
Esempio n. 6
0
    def download_cutout(self, reading, focus=None, needs_apcor=False):
        """
        Downloads a cutout of the FITS image for a given source reading.

        Args:
          source_reading: ossos.astrom.SourceReading
            The reading which will be the focus of the downloaded image.
          focus: tuple(int, int)
            The x, y coordinates that should be the focus of the downloaded
            image.  These coordinates should be in terms of the
            source_reading parameter's coordinate system.
            Default value is None, in which case the source reading's x, y
            position is used as the focus.
          needs_apcor: bool
            If True, the apcor file with data needed for photometry
            calculations is downloaded in addition to the image.
            Defaults to False.

        Returns:
          cutout: ossos.downloads.data.SourceCutout
        """
        if focus is None:
            focus = reading.source_point

        assert isinstance(reading, SourceReading)
        dx = dy = 2 * max(reading.dra, reading.ddec)
        dx = max(reading.dx, dx)
        dy = max(reading.dy, dy)

        (NAXIS1, NAXIS2) = reading.get_original_image_size()

        cutout_str, converter = self.cutout_calculator.build_cutout_str(
            reading.get_extension(),
            focus, (NAXIS1, NAXIS2),
            dx=dx,
            dy=dy,
            inverted=reading.is_inverted)

        image_uri = reading.get_image_uri()
        cutout = re.findall(r'(\d+)', cutout_str)
        y2 = int(cutout[-1])
        y1 = int(cutout[-2])
        logger.debug("Calculated cutout: %s for %s" % (cutout_str, image_uri))

        hdulist = storage.get_image(expnum=reading.get_exposure_number(),
                                    ccd=reading.get_ccd_num(),
                                    cutout=cutout_str,
                                    version=reading.get_observation().ftype,
                                    prefix=reading.get_observation().fk,
                                    return_file=False)

        #hdulist = self.download_hdulist(image_uri, view="cutout",
        #                                cutout=cutout_str)
        # modify the DATASEC to account for possible flip/flop and changes in dimensions of the image.
        DATASEC = hdulist[0].header.get('DATASEC', None)
        if DATASEC is not None:
            datasec = re.findall(r'(\d+)', DATASEC)
            if y2 < y1:
                x2 = int(NAXIS1) - int(datasec[0]) + 1
                x1 = int(NAXIS1) - int(datasec[1]) + 1
                y2 = int(NAXIS2) - int(datasec[2]) + 1
                y1 = int(NAXIS2) - int(datasec[3]) + 1
                logger.debug(
                    "Flip/Flopped DATASEC from {} to [{}:{}:{}:{}]".format(
                        DATASEC, x1, x2, y1, y2))
                datasec = (x1, x2, y1, y2)
            (x1, y1) = converter.convert((int(datasec[0]), int(datasec[2])))
            x1 = max(1, x1)
            y1 = max(1, y1)
            (x2, y2) = converter.convert((int(datasec[1]), int(datasec[3])))
            x2 = min(x2, int(hdulist[0].header['NAXIS1']))
            y2 = min(y2, int(hdulist[0].header['NAXIS2']))
            datasec = "[{}:{},{}:{}]".format(x1, x2, y1, y2)
            logger.debug("Trimmed and offset DATASEC from {} to {}".format(
                DATASEC, datasec))

            hdulist[0].header['DATASEC'] = datasec

        apcor = None
        if needs_apcor:
            try:
                apcor = self.download_apcor(reading.get_apcor_uri())
            except Exception as e:
                logger.error(str(e))
                apcor = None
        zmag = None
        try:
            zmag = self.download_zmag(reading.get_zmag_uri())
        except Exception as e:
            logger.error(str(e))
            pass

        return SourceCutout(reading, hdulist, converter, apcor, zmag=zmag)