Пример #1
0
    def prepare_mosaic(self, image, fov_deg):
        """Prepare a new (blank) mosaic image based on the pointing of
        the parameter image
        """
        header = image.get_header()
        ra_deg, dec_deg = header['CRVAL1'], header['CRVAL2']

        data_np = image.get_data()
        self.bg_ref = iqcalc.get_median(data_np)
            
        # TODO: handle skew (differing rotation for each axis)?
        
        skew_limit = self.settings.get('skew_limit', 0.1)
        (rot_deg, cdelt1, cdelt2) = wcs.get_rotation_and_scale(header,
                                                               skew_threshold=skew_limit)
        self.logger.debug("image0 rot=%f cdelt1=%f cdelt2=%f" % (
            rot_deg, cdelt1, cdelt2))

        # TODO: handle differing pixel scale for each axis?
        px_scale = math.fabs(cdelt1)
        cdbase = [numpy.sign(cdelt1), numpy.sign(cdelt2)]
        #cdbase = [1, 1]

        self.logger.debug("creating blank image to hold mosaic")
        self.fv.gui_do(self._prepare_mosaic1)

        img_mosaic = dp.create_blank_image(ra_deg, dec_deg,
                                           fov_deg, px_scale,
                                           rot_deg, 
                                           cdbase=cdbase,
                                           logger=self.logger,
                                           pfx='mosaic')

        ## imname = 'mosaic%d' % (self.mosaic_count)
        ## img_mosaic.set(name=imname)
        ## self.mosaic_count += 1
        imname = img_mosaic.get('name', image.get('name', "NoName"))

        # avoid making a thumbnail of this if seed image is also that way
        nothumb = not self.settings.get('make_thumbs', False)
        img_mosaic.set(nothumb=image.get('nothumb', nothumb))

        # TODO: fill in interesting/select object headers from seed image

        header = img_mosaic.get_header()
        (rot, cdelt1, cdelt2) = wcs.get_rotation_and_scale(header,
                                                           skew_threshold=skew_limit)
        self.logger.debug("mosaic rot=%f cdelt1=%f cdelt2=%f" % (
            rot, cdelt1, cdelt2))

        self.img_mosaic = img_mosaic
        self.fv.gui_call(self.fv.add_image, imname, img_mosaic,
                         chname=self.mosaic_chname)
        return img_mosaic
Пример #2
0
    def prepare_mosaic(self, image, fov_deg):
        """Prepare a new (blank) mosaic image based on the pointing of
        the parameter image
        """
        header = image.get_header()
        ra_deg, dec_deg = header['CRVAL1'], header['CRVAL2']

        data_np = image.get_data()
        self.bg_ref = iqcalc.get_median(data_np)

        # TODO: handle skew (differing rotation for each axis)?

        skew_limit = self.settings.get('skew_limit', 0.1)
        (rot_deg, cdelt1,
         cdelt2) = wcs.get_rotation_and_scale(header,
                                              skew_threshold=skew_limit)
        self.logger.debug("image0 rot=%f cdelt1=%f cdelt2=%f" %
                          (rot_deg, cdelt1, cdelt2))

        # TODO: handle differing pixel scale for each axis?
        px_scale = math.fabs(cdelt1)
        cdbase = [numpy.sign(cdelt1), numpy.sign(cdelt2)]
        #cdbase = [1, 1]

        self.logger.debug("creating blank image to hold mosaic")
        self.fv.gui_do(self._prepare_mosaic1)

        img_mosaic = dp.create_blank_image(ra_deg,
                                           dec_deg,
                                           fov_deg,
                                           px_scale,
                                           rot_deg,
                                           cdbase=cdbase,
                                           logger=self.logger,
                                           pfx='mosaic')

        ## imname = 'mosaic%d' % (self.mosaic_count)
        ## img_mosaic.set(name=imname)
        ## self.mosaic_count += 1
        imname = img_mosaic.get('name', "NoName")

        header = img_mosaic.get_header()
        (rot, cdelt1,
         cdelt2) = wcs.get_rotation_and_scale(header,
                                              skew_threshold=skew_limit)
        self.logger.debug("mosaic rot=%f cdelt1=%f cdelt2=%f" %
                          (rot, cdelt1, cdelt2))

        self.img_mosaic = img_mosaic
        self.fv.gui_call(self.fv.add_image,
                         imname,
                         img_mosaic,
                         chname=self.mosaic_chname)
Пример #3
0
    def prepare_mosaic(self, image, fov_deg, name=None, skew_limit=0.1):
        """Prepare a new (blank) mosaic image based on the pointing of
        the parameter image
        """
        header = image.get_header()
        ra_deg, dec_deg = header['CRVAL1'], header['CRVAL2']

        data_np = image.get_data()
        #dtype = data_np.dtype
        dtype = None

        # handle skew (differing rotation for each axis)?
        (rot_deg, cdelt1, cdelt2) = wcs.get_rotation_and_scale(header,
                                                               skew_threshold=skew_limit)
        self.logger.debug("image0 rot=%f cdelt1=%f cdelt2=%f" % (
            rot_deg, cdelt1, cdelt2))

        # TODO: handle differing pixel scale for each axis?
        px_scale = math.fabs(cdelt1)
        cdbase = [numpy.sign(cdelt1), numpy.sign(cdelt2)]

        self.logger.debug("creating blank image to hold mosaic")

        mosaic_img = dp.create_blank_image(ra_deg, dec_deg,
                                           fov_deg, px_scale,
                                           rot_deg,
                                           cdbase=cdbase,
                                           logger=self.logger,
                                           pfx='mosaic',
                                           dtype=dtype)

        if name is not None:
            mosaic_img.set(name=name)
        imname = mosaic_img.get('name', image.get('name', "NoName"))

        # avoid making a thumbnail of this
        mosaic_img.set(nothumb=True, path=None)

        header = mosaic_img.get_header()
        (rot, cdelt1, cdelt2) = wcs.get_rotation_and_scale(header,
                                                           skew_threshold=skew_limit)
        self.logger.debug("mosaic rot=%f cdelt1=%f cdelt2=%f" % (
            rot, cdelt1, cdelt2))

        mosaic_img.set(nothumb=True)

        return mosaic_img
Пример #4
0
 def get_wcs_rotation_deg(self):
     warnings.warn(
         "This function has been deprecated--"
         "use get_rotation_and_scale in ginga.util.wcs",
         PendingDeprecationWarning)
     header = self.get_header()
     (rot, cdelt1, cdelt2) = wcs.get_rotation_and_scale(header)
     return rot
Пример #5
0
    def prepare_mosaic(self, image, fov_deg):
        """Prepare a new (blank) mosaic image based on the pointing of
        the parameter image
        """
        header = image.get_header()
        ra_deg, dec_deg = header['CRVAL1'], header['CRVAL2']

        data_np = image.get_data()
        self.bg_ref = iqcalc.get_median(data_np)
            
        # TODO: handle skew (differing rotation for each axis)?
        (rot_deg, cdelt1, cdelt2) = wcs.get_rotation_and_scale(header)
        self.logger.debug("image0 rot=%f cdelt1=%f cdelt2=%f" % (
            rot_deg, cdelt1, cdelt2))

        # TODO: handle differing pixel scale for each axis?
        px_scale = math.fabs(cdelt1)
        cdbase = [numpy.sign(cdelt1), numpy.sign(cdelt2)]
        #cdbase = [1, 1]

        self.logger.debug("creating blank image to hold mosaic")
        self.fv.gui_do(self._prepare_mosaic1)

        img_mosaic = dp.create_blank_image(ra_deg, dec_deg,
                                           fov_deg, px_scale,
                                           rot_deg, 
                                           cdbase=cdbase,
                                           logger=self.logger,
                                           pfx='mosaic')

        ## imname = 'mosaic%d' % (self.mosaic_count)
        ## img_mosaic.set(name=imname)
        ## self.mosaic_count += 1
        imname = img_mosaic.get('name', "NoName")

        header = img_mosaic.get_header()
        (rot, cdelt1, cdelt2) = wcs.get_rotation_and_scale(header)
        self.logger.debug("mosaic rot=%f cdelt1=%f cdelt2=%f" % (
            rot, cdelt1, cdelt2))

        self.img_mosaic = img_mosaic
        self.fv.gui_call(self.fv.add_image, imname, img_mosaic,
                         chname=self.mosaic_chname)
Пример #6
0
def mosaic(logger, itemlist, fov_deg=None):
    """
    Parameters
    ----------
    logger : logger object
        a logger object passed to created AstroImage instances
    itemlist : sequence like
        a sequence of either filenames or AstroImage instances
    """

    if isinstance(itemlist[0], AstroImage.AstroImage):
        image0 = itemlist[0]
        name = image0.get('name', 'image0')
    else:
        # Assume it is a file and load it
        filepath = itemlist[0]
        logger.info("Reading file '%s' ..." % (filepath))
        image0 = AstroImage.AstroImage(logger=logger)
        image0.load_file(filelist[0])
        name = filepath

    ra_deg, dec_deg = image0.get_keywords_list('CRVAL1', 'CRVAL2')
    header = image0.get_header()
    (rot_deg, cdelt1, cdelt2) = wcs.get_rotation_and_scale(header)
    logger.debug("image0 rot=%f cdelt1=%f cdelt2=%f" % (rot_deg,
                                                        cdelt1, cdelt2))

    px_scale = math.fabs(cdelt1)
    if fov_deg == None:
        # TODO: calculate fov!
        fov_deg = 1.0
        
    cdbase = [numpy.sign(cdelt1), numpy.sign(cdelt2)]
    img_mosaic = dp.create_blank_image(ra_deg, dec_deg,
                                       fov_deg, px_scale, rot_deg,
                                       cdbase=cdbase,
                                       logger=logger)
    header = img_mosaic.get_header()
    (rot, cdelt1, cdelt2) = wcs.get_rotation_and_scale(header)
    logger.debug("mosaic rot=%f cdelt1=%f cdelt2=%f" % (rot, cdelt1, cdelt2))

    logger.debug("Processing '%s' ..." % (name))
    tup = img_mosaic.mosaic_inline([ image0 ])
    logger.debug("placement %s" % (str(tup)))

    count = 1
    for item in itemlist[1:]:
        if isinstance(item, AstroImage.AstroImage):
            image = item
            name = image.get('name', 'image%d' % (count))
        else:
            # Create and load the image
            filepath = item
            logger.info("Reading file '%s' ..." % (filepath))
            image = AstroImage.AstroImage(logger=logger)
            image.load_file(filepath)

        logger.debug("Inlining '%s' ..." % (name))
        tup = img_mosaic.mosaic_inline([ image ])
        logger.debug("placement %s" % (str(tup)))
        count += 1

    logger.info("Done.")
    return img_mosaic
Пример #7
0
    def prepare_mosaic(self, image, fov_deg, name=None):
        """Prepare a new (blank) mosaic image based on the pointing of
        the parameter image
        """
        header = image.get_header()
        ra_deg, dec_deg = header['CRVAL1'], header['CRVAL2']

        data_np = image.get_data()
        #dtype = data_np.dtype
        dtype = None
        self.bg_ref = iqcalc.get_median(data_np)

        # TODO: handle skew (differing rotation for each axis)?

        skew_limit = self.settings.get('skew_limit', 0.1)
        (rot_deg, cdelt1,
         cdelt2) = wcs.get_rotation_and_scale(header,
                                              skew_threshold=skew_limit)
        self.logger.debug("image0 rot=%f cdelt1=%f cdelt2=%f" %
                          (rot_deg, cdelt1, cdelt2))

        # TODO: handle differing pixel scale for each axis?
        px_scale = math.fabs(cdelt1)
        cdbase = [numpy.sign(cdelt1), numpy.sign(cdelt2)]

        reuse_image = self.settings.get('reuse_image', False)
        if (not reuse_image) or (self.img_mosaic is None):
            self.logger.debug("creating blank image to hold mosaic")
            self.fv.gui_do(self._prepare_mosaic1, "Creating blank image...")

            # GC old mosaic
            self.img_mosaic = None

            img_mosaic = dp.create_blank_image(ra_deg,
                                               dec_deg,
                                               fov_deg,
                                               px_scale,
                                               rot_deg,
                                               cdbase=cdbase,
                                               logger=self.logger,
                                               pfx='mosaic',
                                               dtype=dtype)

            if name is not None:
                img_mosaic.set(name=name)
            imname = img_mosaic.get('name', image.get('name', "NoName"))

            # avoid making a thumbnail of this if seed image is also that way
            nothumb = not self.settings.get('make_thumbs', False)
            if nothumb:
                img_mosaic.set(nothumb=True)
            else:
                # image is not on disk, set indication for other plugins
                img_mosaic.set(path=None)

            # TODO: fill in interesting/select object headers from seed image

            self.img_mosaic = img_mosaic
            self.fv.gui_call(self.fv.add_image,
                             imname,
                             img_mosaic,
                             chname=self.mosaic_chname)

        else:
            # <-- reuse image (faster)
            self.logger.debug("Reusing previous mosaic image")
            self.fv.gui_do(self._prepare_mosaic1,
                           "Reusing previous mosaic image...")

            img_mosaic = dp.recycle_image(self.img_mosaic,
                                          ra_deg,
                                          dec_deg,
                                          fov_deg,
                                          px_scale,
                                          rot_deg,
                                          cdbase=cdbase,
                                          logger=self.logger,
                                          pfx='mosaic')

        header = img_mosaic.get_header()
        (rot, cdelt1,
         cdelt2) = wcs.get_rotation_and_scale(header,
                                              skew_threshold=skew_limit)
        self.logger.debug("mosaic rot=%f cdelt1=%f cdelt2=%f" %
                          (rot, cdelt1, cdelt2))

        return img_mosaic
Пример #8
0
 def get_wcs_rotation_deg(self):
     header = self.get_header()
     (rot, cdelt1, cdelt2) = wcs.get_rotation_and_scale(header)
     return rot
Пример #9
0
 def get_wcs_rotation_deg(self):
     header = self.get_header()
     (rot, cdelt1, cdelt2) = wcs.get_rotation_and_scale(header)
     return rot
Пример #10
0
    def prepare_mosaic(self, image, fov_deg, name=None):
        """Prepare a new (blank) mosaic image based on the pointing of
        the parameter image
        """
        header = image.get_header()
        ra_deg, dec_deg = header['CRVAL1'], header['CRVAL2']

        data_np = image.get_data()
        #dtype = data_np.dtype
        dtype = None
        self.bg_ref = iqcalc.get_median(data_np)

        # TODO: handle skew (differing rotation for each axis)?

        skew_limit = self.settings.get('skew_limit', 0.1)
        (rot_deg, cdelt1, cdelt2) = wcs.get_rotation_and_scale(header,
                                                               skew_threshold=skew_limit)
        self.logger.debug("image0 rot=%f cdelt1=%f cdelt2=%f" % (
            rot_deg, cdelt1, cdelt2))

        # TODO: handle differing pixel scale for each axis?
        px_scale = math.fabs(cdelt1)
        cdbase = [numpy.sign(cdelt1), numpy.sign(cdelt2)]

        reuse_image = self.settings.get('reuse_image', False)
        if (not reuse_image) or (self.img_mosaic is None):
            self.logger.debug("creating blank image to hold mosaic")
            self.fv.gui_do(self._prepare_mosaic1, "Creating blank image...")

            # GC old mosaic
            self.img_mosaic = None

            img_mosaic = dp.create_blank_image(ra_deg, dec_deg,
                                               fov_deg, px_scale,
                                               rot_deg,
                                               cdbase=cdbase,
                                               logger=self.logger,
                                               pfx='mosaic',
                                               dtype=dtype)

            if name is not None:
                img_mosaic.set(name=name)
            imname = img_mosaic.get('name', image.get('name', "NoName"))

            # avoid making a thumbnail of this if seed image is also that way
            nothumb = not self.settings.get('make_thumbs', False)
            if nothumb:
                img_mosaic.set(nothumb=True)
            else:
                # image is not on disk, set indication for other plugins
                img_mosaic.set(path=None)

            # TODO: fill in interesting/select object headers from seed image

            self.img_mosaic = img_mosaic
            self.fv.gui_call(self.fv.add_image, imname, img_mosaic,
                             chname=self.mosaic_chname)

        else:
            # <-- reuse image (faster)
            self.logger.debug("Reusing previous mosaic image")
            self.fv.gui_do(self._prepare_mosaic1, "Reusing previous mosaic image...")

            img_mosaic = dp.recycle_image(self.img_mosaic,
                                          ra_deg, dec_deg,
                                          fov_deg, px_scale,
                                          rot_deg,
                                          cdbase=cdbase,
                                          logger=self.logger,
                                          pfx='mosaic')

        header = img_mosaic.get_header()
        (rot, cdelt1, cdelt2) = wcs.get_rotation_and_scale(header,
                                                           skew_threshold=skew_limit)
        self.logger.debug("mosaic rot=%f cdelt1=%f cdelt2=%f" % (
            rot, cdelt1, cdelt2))

        return img_mosaic
Пример #11
0
    def multimos(self, filename):
        hdulist = fits.open(filename)
        files = np.sum([
            1 for hdu in hdulist if
            type(hdu) in [fits.hdu.image.PrimaryHDU, fits.hdu.image.ImageHDU]
            and hdu.data is not None
        ])
        k = 0
        j = 0

        ra_deg = 0.5
        dec_deg = 0.5
        fov_deg = 0.2
        header = hdulist[1].header
        (rot_deg, cdelt1,
         cdelt2) = wcs.get_rotation_and_scale(header, skew_threshold=1)
        px_scale = math.fabs(cdelt1)
        cdbase = [np.sign(cdelt1), np.sign(cdelt2)]

        ###Sorting Images###
        imagesort = [[0 for x in range(4)] for y in range(files)]
        for i in range(1, files + 1):
            imagesort[i - 1][0] = hdulist[i]
            df = hdulist[i].header['DETSEC']
            cpos = df.index(':')
            epos = df.index(',')
            dflow = ''.join(df[1:cpos])
            dflow = int(dflow)
            dfhigh = ''.join(df[cpos + 1:epos])
            dfhigh = int(dfhigh)
            imagesort[i - 1][1] = dflow + dfhigh
            ncpos = df.index(':', cpos + 1)
            nepos = df.index(']')
            yflow = ''.join(df[epos + 1:ncpos])
            yflow = int(yflow)
            yhigh = ''.join(df[ncpos + 1:nepos])
            yhigh = int(yhigh)
            imagesort[i - 1][2] = yflow + yhigh
            ccd = hdulist[i].header['CCDNAME']
            imagesort[i - 1][3] = ccd

        sortedim = sorted(imagesort, key=lambda x: x[1])

        ###Putting images together###

        #2D#

        if sortedim[0][1] == sortedim[1][1]:
            for i in range(1, files + 1):
                dr = sortedim[i - 1][0].header['DATASEC']
                colpos = dr.index(':')
                endpos = dr.index(',')
                drlow = ''.join(dr[1:colpos])
                drlow = int(drlow)
                drhigh = ''.join(dr[colpos + 1:endpos])
                drhigh = int(drhigh)
                imdata = sortedim[i - 1][0].data[:, drlow:drhigh]
                gapxdim = np.size(imdata, 0)
                gapx = np.zeros((gapxdim, 30))
                gapx[:, :] = np.nan
                gapydim = np.size(imdata, 1) + 30
                gapy = np.zeros((20, gapydim))
                gapy[:, :] = np.nan
                fgapy = np.zeros((20, gapydim - 30))
                fgapy[:, :] = np.nan
                #image flips#
                df = sortedim[i - 1][0].header['DETSEC']
                cpos = df.index(':')
                epos = df.index(',')
                dflow = ''.join(df[1:cpos])
                dflow = int(dflow)
                dfhigh = ''.join(df[cpos + 1:epos])
                dfhigh = int(dfhigh)
                ncpos = df.index(':', cpos + 1)
                nepos = df.index(']')
                yflow = ''.join(df[epos + 1:ncpos])
                yflow = int(yflow)
                yhigh = ''.join(df[ncpos + 1:nepos])
                yhigh = int(yhigh)
                if dflow > dfhigh:
                    findatx = np.fliplr(imdata)
                else:
                    findatx = imdata

                if yflow > yhigh:
                    findat = np.flipud(findatx)
                else:
                    findat = findatx
                fm = files - 1
                if i != files:
                    if i != fm:
                        if sortedim[i - 1][3] != sortedim[i][3]:
                            findat = np.column_stack((findat, gapx))

                if i == 1:
                    vert = findat

                elif sortedim[i - 1][1] == sortedim[i - 2][1]:
                    if sortedim[i - 1][2] > sortedim[i - 2][2]:
                        if i == files:
                            vert = np.vstack((vert, fgapy))
                            vert = np.vstack((vert, findat))
                            if i == files:
                                final = np.column_stack((final, vert))
                        else:
                            vert = np.vstack((vert, gapy))
                            vert = np.vstack((vert, findat))
                            if i == files:
                                final = np.column_stack((final, vert))
                    else:
                        findat = np.vstack((findat, gapy))
                        vert = np.vstack((findat, vert))
                        if i == files:
                            final = np.column_stack((final, vert))

                else:
                    k = k + 1
                    if k == 1:
                        final = vert
                        vert = findat
                    else:
                        final = np.column_stack((final, vert))
                        vert = findat

        else:
            #1d#
            for i in range(1, files + 1):
                #data ranges#
                dr = sortedim[i - 1][0].header['DATASEC']
                colpos = dr.index(':')
                endpos = dr.index(',')
                drlow = ''.join(dr[1:colpos])
                drlow = int(drlow)
                drhigh = ''.join(dr[colpos + 1:endpos])
                drhigh = int(drhigh)
                imdata = sortedim[i - 1][0].data[:, drlow:drhigh]
                gapxdim = np.size(imdata, 0)
                gapx = np.zeros((gapxdim, 30))
                gapx[:, :] = np.nan
                #image flips#
                df = sortedim[i - 1][0].header['DETSEC']
                cpos = df.index(':')
                epos = df.index(',')
                dflow = ''.join(df[1:cpos])
                dflow = int(dflow)
                dfhigh = ''.join(df[cpos + 1:epos])
                dfhigh = int(dfhigh)
                ncpos = df.index(':', cpos + 1)
                nepos = df.index(']')
                yflow = ''.join(df[epos + 1:ncpos])
                yflow = int(yflow)
                yhigh = ''.join(df[ncpos + 1:nepos])
                yhigh = int(yhigh)

                if dflow > dfhigh:
                    findatx = np.fliplr(imdata)
                else:
                    findatx = imdata

                if yflow > yhigh:
                    findat = np.flipud(findatx)
                else:
                    findat = findatx
                #final image
                if i == 1:
                    final = findat
                else:
                    final = np.append(final, findat, axis=1)

                if i != files and sortedim[i - 1][3] != sortedim[i][3]:
                    final = np.append(final, gapx, axis=1)

        #finalimage#
        #plt.imshow(final)
        #plt.show()
        #finalimage = fits.ImageHDU()
        #finalimage.data = final
        oldim = dp.create_blank_image(ra_deg,
                                      dec_deg,
                                      fov_deg,
                                      px_scale,
                                      rot_deg,
                                      cdbase=cdbase,
                                      logger=None)
        finalimage = dp.make_image(final, oldim, {}, pfx='mosaic')
        name = dp.get_image_name(finalimage)
        self.fv.add_image(name, finalimage, chname='Mosaic')