コード例 #1
0
 def test_gmos(self):
     ra = 200.0
     dec = -60.0
     radius = 0.02
     center = SkyCoord(ra, dec, unit='deg')
     ret = get_fits_table('gmos', ra, dec, radius)
     assert len(ret) == 8
     assert all(center.separation(SkyCoord(ret['RAJ2000'],
                     ret['DEJ2000'], unit='deg')) < Angle(radius * u.deg))
コード例 #2
0
def test_get_fits_table_vizier(catalog, ra, dec, radius, nres):
    """Tests the same requests but on Vizier this time, specifying explicitly
    the server.
    """
    ret = get_fits_table(catalog, ra, dec, radius, server=f'{catalog}_vizier')
    assert len(ret) == nres

    center = SkyCoord(ra, dec, unit='deg')
    coord = SkyCoord(ret['RAJ2000'], ret['DEJ2000'], unit='deg')
    assert all(center.separation(coord) < Angle(radius * u.deg))
コード例 #3
0
def test_get_fits_table_gmos():
    ra = 200.0
    dec = -60.0
    radius = 0.02
    center = SkyCoord(ra, dec, unit='deg')
    ret = get_fits_table('gmos', ra, dec, radius)
    assert len(ret) == 8
    assert all(
        center.separation(SkyCoord(ret['RAJ2000'], ret['DEJ2000'], unit='deg'))
        < Angle(radius * u.deg))
コード例 #4
0
def test_get_fits_table_sdss9():
    ra = 160.0
    dec = 30.0
    radius = 0.02
    center = SkyCoord(ra, dec, unit='deg')
    ret = get_fits_table('sdss9', ra, dec, radius)
    assert len(ret) == 9
    assert all(
        center.separation(SkyCoord(ret['RAJ2000'], ret['DEJ2000'], unit='deg'))
        < Angle(radius * u.deg))
コード例 #5
0
 def test_2mass(self):
     ra = 180.0
     dec = 0.0
     radius = 0.02
     center = SkyCoord(ra, dec, unit='deg')
     ret = get_fits_table('2mass', ra, dec, radius)
     assert len(ret) == 5
     assert all(
         center.separation(
             SkyCoord(ret['RAJ2000'], ret['DEJ2000'], unit='deg')) < Angle(
                 radius * u.deg))
コード例 #6
0
def test_get_fits_table(catalog, ra, dec, radius, nres):
    """Test some requests with get_fits_table, which by default will use the
    internal server. So we skip the test if this server is no reachable.
    """
    # Test if internal server is available
    try:
        resp = urllib.request.urlopen("http://mkocatalog2")
        if resp.status != 200:
            raise Exception
    except Exception:
        pytest.skip('Internal server cannot be reached')

    ret = get_fits_table(catalog, ra, dec, radius)
    assert len(ret) == nres

    center = SkyCoord(ra, dec, unit='deg')
    coord = SkyCoord(ret['RAJ2000'], ret['DEJ2000'], unit='deg')
    assert all(center.separation(coord) < Angle(radius * u.deg))
コード例 #7
0
    def addReferenceCatalog(self, adinputs=None, **params):
        """
        This primitive calls the gemini_catalog_client module to query a
        catalog server and construct a fits table containing the catalog data

        That module will query either gemini catalog servers or vizier.
        Currently, sdss9 and 2mass (point source catalogs are supported.

        For example, with sdss9, the FITS table has the following columns:

        - 'Id'       : Unique ID. Simple running number
        - 'Cat-id'   : SDSS catalog source name
        - 'RAJ2000'  : RA as J2000 decimal degrees
        - 'DEJ2000'  : Dec as J2000 decimal degrees
        - 'umag'     : SDSS u band magnitude
        - 'e_umag'   : SDSS u band magnitude error estimage
        - 'gmag'     : SDSS g band magnitude
        - 'e_gmag'   : SDSS g band magnitude error estimage
        - 'rmag'     : SDSS r band magnitude
        - 'e_rmag'   : SDSS r band magnitude error estimage
        - 'imag'     : SDSS i band magnitude
        - 'e_imag'   : SDSS i band magnitude error estimage
        - 'zmag'     : SDSS z band magnitude
        - 'e_zmag'   : SDSS z band magnitude error estimage

        With 2mass, the first 4 columns are the same, but the photometry
        columns reflect the J H and K bands.

        This primitive then adds the fits table catalog to the Astrodata
        object as 'REFCAT'

        Parameters
        ----------
        suffix: str
            suffix to be added to output files
        radius: float
            search radius (in degrees)
        source: str
            identifier for server to be used for catalog search
        """
        log = self.log
        log.debug(gt.log_message("primitive", self.myself(), "starting"))
        timestamp_key = self.timestamp_keys[self.myself()]
        source = params["source"]
        radius = params["radius"]

        for ad in adinputs:
            try:
                ra = ad.wcs_ra()
                dec = ad.wcs_dec()
                if type(ra) is not float:
                    raise ValueError("wcs_ra descriptor did not return a float.")
                if type(ra) is not float:
                    raise ValueError("wcs_dec descriptor did not return a float.")
            except:
                if "qa" in self.mode:
                    log.warning("No RA/Dec in header of {}; cannot find "
                                "reference sources".format(ad.filename))
                    continue
                else:
                    raise

            log.fullinfo("Querying {} for reference catalog".format(source))
            import warnings
            with warnings.catch_warnings():
                warnings.simplefilter("ignore")
                refcat = get_fits_table(source, ra, dec, radius)

            if refcat is None:
               log.stdinfo("No reference catalog sources found for {}".
                            format(ad.filename))
            else:
                log.stdinfo("Found {} reference catalog sources for {}".
                            format(len(refcat), ad.filename))
                filter_name = ad.filter_name(pretty=True)
                colterm_dict = color_corrections.colorTerms
                try:
                    formulae = colterm_dict[filter_name]
                except KeyError:
                    log.warning("Filter {} not in catalogs - unable to flux "
                                "calibrate".format(filter_name))
                    formulae = []
                ad.REFCAT = _calculate_magnitudes(refcat, formulae)

            # Timestamp and update filename
            gt.mark_history(ad, primname=self.myself(), keyword=timestamp_key)
            ad.update_filename(suffix=params["suffix"], strip=True)
        return adinputs
コード例 #8
0
    def addReferenceCatalog(self, adinputs=None, **params):
        """
        This primitive calls the gemini_catalog_client module to query a
        catalog server and construct a fits table containing the catalog data

        That module will query either gemini catalog servers or vizier.
        Currently, sdss9 and 2mass (point source catalogs are supported.

        For example, with sdss9, the FITS table has the following columns:

        - 'Id'       : Unique ID. Simple running number
        - 'Cat-id'   : SDSS catalog source name
        - 'RAJ2000'  : RA as J2000 decimal degrees
        - 'DEJ2000'  : Dec as J2000 decimal degrees
        - 'umag'     : SDSS u band magnitude
        - 'e_umag'   : SDSS u band magnitude error estimage
        - 'gmag'     : SDSS g band magnitude
        - 'e_gmag'   : SDSS g band magnitude error estimage
        - 'rmag'     : SDSS r band magnitude
        - 'e_rmag'   : SDSS r band magnitude error estimage
        - 'imag'     : SDSS i band magnitude
        - 'e_imag'   : SDSS i band magnitude error estimage
        - 'zmag'     : SDSS z band magnitude
        - 'e_zmag'   : SDSS z band magnitude error estimage

        With 2mass, the first 4 columns are the same, but the photometry
        columns reflect the J H and K bands.

        This primitive then adds the fits table catalog to the Astrodata
        object as 'REFCAT'

        Parameters
        ----------
        suffix: str
            suffix to be added to output files
        radius: float
            search radius (in degrees)
        source: str
            identifier for server to be used for catalog search
        """
        log = self.log
        log.debug(gt.log_message("primitive", self.myself(), "starting"))
        timestamp_key = self.timestamp_keys[self.myself()]
        source = params["source"]
        radius = params["radius"]

        for ad in adinputs:
            try:
                ra = ad.wcs_ra()
                dec = ad.wcs_dec()
                if type(ra) is not float:
                    raise ValueError(
                        "wcs_ra descriptor did not return a float.")
                if type(dec) is not float:
                    raise ValueError(
                        "wcs_dec descriptor did not return a float.")
            except Exception:
                if "qa" in self.mode:
                    log.warning("No RA/Dec in header of {}; cannot find "
                                "reference sources".format(ad.filename))
                    continue
                else:
                    raise

            log.fullinfo("Querying {} for reference catalog".format(source))
            with warnings.catch_warnings():
                warnings.simplefilter("ignore")
                refcat = get_fits_table(source, ra, dec, radius)

            if refcat is None:
                log.stdinfo("No reference catalog sources found for {}".format(
                    ad.filename))
            else:
                log.stdinfo("Found {} reference catalog sources for {}".format(
                    len(refcat), ad.filename))
                filter_name = ad.filter_name(pretty=True)
                colterm_dict = color_corrections.colorTerms
                try:
                    formulae = colterm_dict[filter_name]
                except KeyError:
                    log.warning("Filter {} not in catalogs - unable to flux "
                                "calibrate".format(filter_name))
                    formulae = []
                ad.REFCAT = _calculate_magnitudes(refcat, formulae)

            # Timestamp and update filename
            gt.mark_history(ad, primname=self.myself(), keyword=timestamp_key)
            ad.update_filename(suffix=params["suffix"], strip=True)
        return adinputs
コード例 #9
0
    def addReferenceCatalog(self, adinputs=None, **params):
        """
        This primitive attaches a reference catalog to each AstroData input
        as a top-level Table called "REFCAT'. The user can supply the name
        of a file on disk or one of a specific list of catalogs (2mass, gmos,
        sdss9, or ukidss9) for which a query will be made via the
        gemini_catalog_client module.

        If a catalog server is queried, sources within a circular region of
        the sky will be added. If a file on disk is used as the reference
        catalog, it is attached in full to each file.

        For example, with sdss9, the FITS table has the following columns:

        - 'Id'       : Unique ID. Simple running number
        - 'Cat-id'   : SDSS catalog source name
        - 'RAJ2000'  : RA as J2000 decimal degrees
        - 'DEJ2000'  : Dec as J2000 decimal degrees
        - 'umag'     : SDSS u band magnitude
        - 'e_umag'   : SDSS u band magnitude error estimage
        - 'gmag'     : SDSS g band magnitude
        - 'e_gmag'   : SDSS g band magnitude error estimage
        - 'rmag'     : SDSS r band magnitude
        - 'e_rmag'   : SDSS r band magnitude error estimage
        - 'imag'     : SDSS i band magnitude
        - 'e_imag'   : SDSS i band magnitude error estimage
        - 'zmag'     : SDSS z band magnitude
        - 'e_zmag'   : SDSS z band magnitude error estimage

        With 2mass, the first 4 columns are the same, but the photometry
        columns reflect the J H and K bands.

        Parameters
        ----------
        suffix: str
            suffix to be added to output files
        radius: float
            search radius (in degrees)
        source: str/None
            identifier for server to be used for catalog search or filename
        format: str/None
            format of catalog on disk (passed to Table.read())
        """
        log = self.log
        log.debug(gt.log_message("primitive", self.myself(), "starting"))
        timestamp_key = self.timestamp_keys[self.myself()]
        source = params["source"]
        radius = params["radius"]
        format = params["format"]

        if source is None:
            log.stdinfo("No source provided for reference catalog.")
            return adinputs

        if os.path.isfile(source):
            try:
                user_refcat = Table.read(source, format=format)
                log.stdinfo(f"Successfully read reference catalog {source}")
                # Allow raw SExtractor catalog to be used
                if not {'RAJ2000', 'DEJ2000'}.issubset(user_refcat.colnames):
                    if {'X_WORLD', 'Y_WORLD'}.issubset(user_refcat.colnames):
                        log.stdinfo(
                            "Renaming X_WORLD, Y_WORLD to RAJ2000, DEJ2000")
                        user_refcat.rename_column('X_WORLD', 'RAJ2000')
                        user_refcat.rename_column('Y_WORLD', 'DEJ2000')
            except:
                log.warning(
                    f"File {source} exists but cannot be read - continuing")
                return adinputs
        else:
            user_refcat = None

        for ad in adinputs:
            try:
                try:
                    ra = float(ad.wcs_ra())
                except TypeError:
                    raise ValueError(
                        "wcs_ra descriptor did not return a float.")
                try:
                    dec = float(ad.wcs_dec())
                except TypeError:
                    raise ValueError(
                        "wcs_dec descriptor did not return a float.")
            except Exception:
                if "qa" in self.mode:
                    log.warning("No RA/Dec in header of {}; cannot find "
                                "reference sources".format(ad.filename))
                    continue
                else:
                    raise

            if user_refcat:
                refcat = user_refcat.copy()
            else:
                log.fullinfo(f"Querying {source} for reference catalog, "
                             f"ra={ra:.6f}, dec={dec:.6f}, radius={radius}")
                with warnings.catch_warnings():
                    warnings.simplefilter("ignore")
                    refcat = get_fits_table(source, ra, dec, radius)

            if refcat is None:
                log.stdinfo("No reference catalog sources found for {}".format(
                    ad.filename))
            else:
                log.stdinfo("Found {} reference catalog sources for {}".format(
                    len(refcat), ad.filename))
                filter_name = ad.filter_name(pretty=True)
                colterm_dict = color_corrections.colorTerms
                try:
                    formulae = colterm_dict[filter_name]
                except KeyError:
                    log.warning("Filter {} not in catalogs - unable to flux "
                                "calibrate".format(filter_name))
                    formulae = []
                ad.REFCAT = _calculate_magnitudes(refcat, formulae)

            # Timestamp and update filename
            gt.mark_history(ad, primname=self.myself(), keyword=timestamp_key)
            ad.update_filename(suffix=params["suffix"], strip=True)
        return adinputs