Exemplo n.º 1
0
    def get_catalog(self,
                    query=None,
                    query_fields=None,
                    print_query=False,
                    **kwargs):
        """
        Grab a catalog of sources around the input coordinate to the search radius

        Args:
            query: Not used
            query_fields (list, optional): Over-ride list of items to query
            print_query (bool): Print the SQL query generated
            grab_wise (bool): Attempt to grab WISE data too.
                This is not recommended.

        Returns:
            astropy.table.Table:  Catalog of sources returned.  Includes WISE
            photometry for matched sources.
        """
        # Main DES query
        main_cat = super(DES_Survey,
                         self).get_catalog(query_fields=query_fields,
                                           print_query=print_query,
                                           **kwargs)
        if len(main_cat) == 0:
            main_cat = catalog_utils.clean_cat(main_cat, photom['DES'])
            return main_cat
        main_cat = catalog_utils.clean_cat(main_cat, photom['DES'])
        ## Finish
        self.catalog = main_cat
        self.validate_catalog()
        return self.catalog
Exemplo n.º 2
0
    def get_catalog(self,
                    query=None,
                    query_fields=_DEFAULT_query_fields,
                    print_query=False,
                    system='AB'):
        """
        Grab a catalog of sources around the input coordinate to the search radius

        Args:
            query: Not used
            query_fields (list, optional): Over-ride list of items to query
            print_query (bool): Print the SQL query generated
            system (str): Magnitude system ['AB', 'Vega']

        Returns:
            astropy.table.Table:  Catalog of sources returned.  Includes WISE
            photometry for matched sources.

            Magnitudes are in AB by default
        """
        # Main WISE query
        if query is None:
            self._gen_cat_query(query_fields)
        if print_query:
            print(self.query)
        main_cat = self.service.run_async(self.query).to_table()
        main_cat.meta['radius'] = self.radius
        main_cat.meta['survey'] = self.survey
        if len(main_cat) == 0:
            main_cat = catalog_utils.clean_cat(main_cat,
                                               photom['WISE'],
                                               fill_mask=-999.)
            return main_cat

        main_cat = catalog_utils.clean_cat(main_cat,
                                           photom['WISE'],
                                           fill_mask=-999.)

        # Convert to AB mag
        if system == 'AB':
            fnu0 = {
                'WISE_W1': 309.54,
                'WISE_W2': 171.787,
                'WISE_W3': 31.674,
                'WISE_W4': 8.363
            }
            for item in ['1', '2', '3', '4']:
                filt = 'WISE_W' + item
                main_cat[filt] -= 2.5 * np.log10(fnu0[filt] / 3631.)
        elif system == 'Vega':
            pass

        # Finish
        self.catalog = main_cat
        self.validate_catalog()
        return self.catalog.copy()
Exemplo n.º 3
0
    def get_catalog(self,
                    query=None,
                    query_fields=None,
                    print_query=False,
                    **kwargs):
        """
        Grab a catalog of sources around the input coordinate to the search radius

        Args:
            query: Not used
            query_fields (list, optional): Over-ride list of items to query
            print_query (bool): Print the SQL query generated

        Returns:
            astropy.table.Table:  Catalog of sources returned.  Includes WISE
            photometry for matched sources.
        """
        # Main DES query
        main_cat = super(DES_Survey,
                         self).get_catalog(query_fields=query_fields,
                                           print_query=print_query,
                                           **kwargs)
        if len(main_cat) == 0:
            main_cat = catalog_utils.clean_cat(main_cat, photom['DES'])
            return main_cat
        main_cat = catalog_utils.clean_cat(main_cat, photom['DES'])

        # WISE
        wise_query = self._gen_cat_query(qtype='wise')
        wise_cat = super(DES_Survey, self).get_catalog(query=wise_query,
                                                       print_query=print_query,
                                                       **kwargs)
        wise_cat = catalog_utils.clean_cat(wise_cat,
                                           photom['DES-WISE'],
                                           fill_mask=-999.)
        # Match em up
        if len(wise_cat) > 0:
            idx = catalog_utils.match_ids(wise_cat['DES_ID'],
                                          main_cat['DES_ID'],
                                          require_in_match=False)
            # Fill me
            for band in DES_WISE_bands:
                main_cat['WISE_{:s}'.format(band)] = -999.
                main_cat['WISE_{:s}'.format(band)][idx] = wise_cat[
                    band.replace("W", "WISE")]
                main_cat['WISE_{:s}_err'.format(band)] = -999.
                main_cat['WISE_{:s}_err'.format(band)][idx] = wise_cat[
                    '{:s}_err'.format(band.replace("W", "WISE"))]

        # Finish
        self.catalog = main_cat
        self.validate_catalog()
        return self.catalog
Exemplo n.º 4
0
Arquivo: wise.py Projeto: starlism/FRB
    def get_catalog(self, query=None, query_fields=None, print_query=False):
        """
        Grab a catalog of sources around the input coordinate to the search radius

        Args:
            query: Not used
            query_fields (list, optional): Over-ride list of items to query
            print_query (bool): Print the SQL query generated

        Returns:
            astropy.table.Table:  Catalog of sources returned.  Includes WISE
            photometry for matched sources.
        """
        # Main DES query
        main_cat = super(WISE_Survey,
                         self).get_catalog(query_fields=query_fields,
                                           print_query=print_query)
        if len(main_cat) == 0:
            return main_cat
        main_cat = catalog_utils.clean_cat(main_cat,
                                           photom['WISE'],
                                           fill_mask=-999.)

        # Finish
        self.catalog = main_cat
        self.validate_catalog()
        return self.catalog
Exemplo n.º 5
0
    def get_catalog(self,
                    query=None,
                    query_fields=None,
                    print_query=False,
                    **kwargs):
        """
        Grab a catalog of sources around the input coordinate to the search radius

        Args:
            query: Not used
            query_fields (list, optional): Over-ride list of items to query
            print_query (bool): Print the SQL query generated

        Returns:
            astropy.table.Table:  Catalog of sources returned.  Includes WISE
            photometry for matched sources.
        """
        # Main DES query
        if query == None:
            self.query = self._gen_cat_query(query_fields=query_fields)
        else:
            self.query = query
        main_cat = super(VISTA_Survey,
                         self).get_catalog(query=self.query,
                                           print_query=print_query,
                                           photomdict=photom['VISTA'],
                                           **kwargs)
        if len(main_cat) == 0:
            main_cat = catalog_utils.clean_cat(main_cat, photom['VISTA'])
            return main_cat
        main_cat = catalog_utils.clean_cat(main_cat, photom['VISTA'])
        for col in main_cat.colnames:
            if main_cat[col].dtype == float:
                mask = np.isnan(main_cat[col]) + (main_cat[col] == 99.99)
                main_cat[col] = np.where(~mask, main_cat[col], -999.0)

        # Finish
        self.catalog = main_cat
        self.validate_catalog()
        return self.catalog
Exemplo n.º 6
0
    def get_catalog(self,
                    query=None,
                    query_fields=None,
                    print_query=False,
                    exclude_gaia=False,
                    **kwargs):
        """
        Grab a catalog of sources around the input coordinate to the search radius
        
        Args:
            query: SQL query
            query_fields (list, optional): Over-ride list of items to query
            exclude_gaia (bool,optional): If the field 'gaia_pointsource' is present and is 1,
                                         remove those objects from the output catalog.
            print_query (bool): Print the SQL query generated 

        Returns:
            astropy.table.Table:  Catalog of sources returned

        """
        # Query
        main_cat = super(DECaL_Survey,
                         self).get_catalog(query_fields=query_fields,
                                           print_query=print_query,
                                           **kwargs)
        main_cat = Table(main_cat, masked=True)
        #
        for col in main_cat.colnames:
            main_cat[col].mask = np.isnan(main_cat[col])
        #Convert SNR to mag error values.
        snr_cols = [
            colname for colname in main_cat.colnames if "snr" in colname
        ]
        for col in snr_cols:
            main_cat[col].mask = main_cat[col] < 0
            main_cat[col] = 2.5 * np.log10(1 + 1 / main_cat[col])

        main_cat = main_cat.filled(-99.0)
        #Remove gaia objects if necessary
        if exclude_gaia:
            self.catalog = main_cat[main_cat['gaia_pointsource'] == 0]
        else:
            self.catalog = main_cat
        # Clean
        main_cat = catalog_utils.clean_cat(main_cat, photom['DECaL'])
        self.validate_catalog()
        # Return
        return self.catalog
Exemplo n.º 7
0
Arquivo: dlsurvey.py Projeto: FRBs/FRB
    def get_catalog(self,
                    query=None,
                    query_fields=None,
                    print_query=False,
                    timeout=120,
                    photomdict=None):
        """
        Get catalog sources around the given coordinates
        within self.radius.
        
        Args:
            query (str, optional): SQL query to generate the catalog
            query_fields (list, optional): Over-ride list of items to query
            print_query (bool): Print the SQL query generated 
        
        Returns:
            astropy.table.Table:  Catalog of sources obtained from the SQL query.
        """
        qc.set_profile(self.qc_profile)
        # Generate the query
        if query is None:
            self._gen_cat_query(query_fields)
            query = self.query
        if print_query:
            print(query)
        # Do it while silencing print statements
        result = qc.query(self.token, sql=query, timeout=timeout)
        self.catalog = convert(result, outfmt="table")

        if photomdict:
            self.catalog = catalog_utils.clean_cat(self.catalog, photomdict)

        self.catalog.meta['radius'] = self.radius
        self.catalog.meta['survey'] = self.survey
        # Validate
        self.validate_catalog()
        # Return
        return self.catalog.copy()
Exemplo n.º 8
0
    def get_catalog(self, query_fields=None, release="dr2", table="stack"):
        """
        Query a catalog in the VizieR database for
        photometry.

        Args:
            query_fields: list, optional
                A list of query fields to
                get.
            release: str, optional
                "dr1" or "dr2" (default: "dr2").
                Data release version.
            table: str, optional
                "mean","stack" or "detection"
                (default: "stack"). The data table to
                search within.
        
        Returns:
            catalog: astropy.table.Table
                Contains all query results
        """
        assert self.radius <= 0.5 * u.deg, "Cone serches have a maximum radius"
        #Validate table and release input
        _check_legal(table, release)
        url = "https://catalogs.mast.stsci.edu/api/v0.1/panstarrs/{:s}/{:s}.csv".format(
            release, table)
        if query_fields is None:
            query_fields = [
                'objID', 'raStack', 'decStack', 'objInfoFlag', 'qualityFlag'
            ]
            query_fields += [
                '{:s}PSFmag'.format(band) for band in PanSTARRS_bands
            ]
            query_fields += [
                '{:s}PSFmagErr'.format(band) for band in PanSTARRS_bands
            ]
        #Validate columns
        _check_columns(query_fields, table, release)
        data = {}
        data['ra'] = self.coord.ra.value
        data['dec'] = self.coord.dec.value
        data['radius'] = self.radius.to(u.deg).value
        data['columns'] = query_fields
        ret = requests.get(url, params=data)
        ret.raise_for_status()
        if len(ret.text) == 0:
            self.catalog = Table()
            self.catalog.meta['radius'] = self.radius
            self.catalog.meta['survey'] = self.survey
            # Validate
            self.validate_catalog()
            return self.catalog.copy()
        photom_catalog = Table.read(ret.text, format="ascii.csv")
        pdict = photom['Pan-STARRS']
        photom_catalog = catalog_utils.clean_cat(photom_catalog, pdict)
        #
        self.catalog = catalog_utils.sort_by_separation(photom_catalog,
                                                        self.coord,
                                                        radec=('ra', 'dec'),
                                                        add_sep=True)
        # Meta
        self.catalog.meta['radius'] = self.radius
        self.catalog.meta['survey'] = self.survey

        #Validate
        self.validate_catalog()

        #Return
        return self.catalog.copy()
Exemplo n.º 9
0
Arquivo: sdss.py Projeto: FRBs/FRB
    def get_catalog(self, photoobj_fields=None, timeout=120, print_query=False):
        """
        Query SDSS for all objects within a given
        radius of the input coordinates.

        Merges photometry with photo-z

        TODO -- Expand to include spectroscopy
        TODO -- Consider grabbing all of the photometry fields

        Args:
            coord: astropy.coordiantes.SkyCoord
            radius: Angle, optional
              Search radius
            photoobj_fields: list
              Fields for querying
            timeout: float, optional
              Default value - 120 s.
            print_query: bool, optional
              Print the SQL query for the photo-z values

        Returns:
            catalog: astropy.table.Table
              Contains all measurements retieved
              *WARNING* :: The SDSS photometry table frequently has multiple entries for a given
              source, with unique objid values

        """
        if photoobj_fields is None:
            photoobj_fs = ['ra', 'dec', 'objid', 'run', 'rerun', 'camcol', 'field','type']
            mags = ['modelMag_'+band for band in SDSS_bands]
            magsErr = ['modelMagErr_'+band for band in SDSS_bands]
            extinct = ["extinction_"+band for band in SDSS_bands]
            photoobj_fields = photoobj_fs+mags+magsErr+extinct

        # Call
        photom_catalog = SDSS.query_region(self.coord, radius=self.radius, timeout=timeout,
                                           photoobj_fields=photoobj_fields)
        if photom_catalog is None:
            self.catalog = Table()
            self.catalog.meta['radius'] = self.radius
            self.catalog.meta['survey'] = self.survey
            # Validate
            self.validate_catalog()
            return

        # Now query for photo-z
        query = "SELECT GN.distance, "
        query += "p.objid, "

        query += "pz.z as redshift, pz.zErr as redshift_error\n"
        query += "FROM PhotoObj as p\n"
        query += "JOIN dbo.fGetNearbyObjEq({:f},{:f},{:f}) AS GN\nON GN.objID=p.objID\n".format(
            self.coord.ra.value,self.coord.dec.value,self.radius.to('arcmin').value)
        query += "JOIN Photoz AS pz ON pz.objID=p.objID\n"
        query += "ORDER BY distance"

        if print_query:
            print(query)

        # SQL command
        photz_cat = SDSS.query_sql(query,timeout=timeout)

        # Match em up
        if photz_cat is not None:
            matches = catalog_utils.match_ids(photz_cat['objid'], photom_catalog['objid'], require_in_match=False)
        else:
            matches = -1 * np.ones(len(photom_catalog), dtype=int)
        gdz = matches > 0
        # Init
        photom_catalog['photo_z'] = -9999.
        photom_catalog['photo_zerr'] = -9999.
        # Fill
        if np.any(gdz):
            photom_catalog['photo_z'][matches[gdz]] = photz_cat['redshift'][np.where(gdz)]
            photom_catalog['photo_zerr'][matches[gdz]] = photz_cat['redshift_error'][np.where(gdz)]

        # Trim down catalog
        trim_catalog = trim_down_catalog(photom_catalog, keep_photoz=True)

        # Clean up
        trim_catalog = catalog_utils.clean_cat(trim_catalog, photom['SDSS'])

        # Spectral info
        spec_fields = ['ra', 'dec', 'z', 'run2d', 'plate', 'fiberID', 'mjd', 'instrument']
        spec_catalog = SDSS.query_region(self.coord,spectro=True, radius=self.radius,
                                         timeout=timeout, specobj_fields=spec_fields) # Duplicates may exist
        if spec_catalog is not None:
            trim_spec_catalog = trim_down_catalog(spec_catalog)
            # Match
            spec_coords = SkyCoord(ra=trim_spec_catalog['ra'], dec=trim_spec_catalog['dec'], unit='deg')
            phot_coords = SkyCoord(ra=trim_catalog['ra'], dec=trim_catalog['dec'], unit='deg')
            idx, d2d, d3d = match_coordinates_sky(spec_coords, phot_coords, nthneighbor=1)
            # Check
            if np.max(d2d).to('arcsec').value > 1.5:
                raise ValueError("Bad match in SDSS")
            # Fill me
            zs = -1 * np.ones_like(trim_catalog['ra'].data)
            zs[idx] = trim_spec_catalog['z']
            trim_catalog['z_spec'] = zs
        else:
            trim_catalog['z_spec'] = -1.

        # Sort by offset
        catalog = trim_catalog.copy()
        self.catalog = catalog_utils.sort_by_separation(catalog, self.coord, radec=('ra','dec'), add_sep=True)

        # Meta
        self.catalog.meta['radius'] = self.radius
        self.catalog.meta['survey'] = self.survey

        # Validate
        self.validate_catalog()

        # Return
        return self.catalog.copy()
Exemplo n.º 10
0
    def get_catalog(self,
                    query_fields=None,
                    release="dr2",
                    table="stack",
                    print_query=False,
                    use_psf=False):
        """
        Query a catalog in the MAST Pan-STARRS database for
        photometry.

        Args:
            query_fields: list, optional
                A list of query fields to
                get in addition to the
                default fields.
            release: str, optional
                "dr1" or "dr2" (default: "dr2").
                Data release version.
            table: str, optional
                "mean","stack" or "detection"
                (default: "stack"). The data table to
                search within.
            use_psf: bool, optional
                If True, use PSFmag instead of KronMag
        
        Returns:
            catalog: astropy.table.Table
                Contains all query results
        """
        #assert self.radius <= 0.5*u.deg, "Cone serches have a maximum radius"
        #Validate table and release input
        _check_legal(table, release)
        url = "https://catalogs.mast.stsci.edu/api/v0.1/panstarrs/{:s}/{:s}.csv".format(
            release, table)
        if query_fields is None:
            query_fields = _DEFAULT_query_fields
        else:
            query_fields = _DEFAULT_query_fields + query_fields

        #Validate columns
        _check_columns(query_fields, table, release)
        data = {}
        data['ra'] = self.coord.ra.value
        data['dec'] = self.coord.dec.value
        data['radius'] = self.radius.to(u.deg).value
        data['columns'] = query_fields
        if print_query:
            print(url)
        ret = requests.get(url, params=data)
        ret.raise_for_status()
        if len(ret.text) == 0:
            self.catalog = Table()
            self.catalog.meta['radius'] = self.radius
            self.catalog.meta['survey'] = self.survey
            # Validate
            self.validate_catalog()
            return self.catalog.copy()
        photom_catalog = Table.read(ret.text, format="ascii.csv")
        pdict = photom['Pan-STARRS'].copy()

        # Allow for PSF
        if use_psf:
            for band in PanSTARRS_bands:
                pdict["Pan-STARRS" +
                      '_{:s}'.format(band)] = '{:s}PSFmag'.format(band.lower())
                pdict["Pan-STARRS" +
                      '_{:s}_err'.format(band)] = '{:s}PSFmagErr'.format(
                          band.lower())

        photom_catalog = catalog_utils.clean_cat(photom_catalog, pdict)

        #Remove bad positions because Pan-STARRS apparently decided
        #to flag some positions with large negative numbers. Why even keep
        #them?
        bad_ra = (photom_catalog['ra'] < 0) + (photom_catalog['ra'] > 360)
        bad_dec = (photom_catalog['dec'] < -90) + (photom_catalog['dec'] > 90)
        bad_pos = bad_ra + bad_dec  # bad_ra OR bad_dec
        photom_catalog = photom_catalog[~bad_pos]

        # Remove duplicate entries.
        photom_catalog = catalog_utils.remove_duplicates(
            photom_catalog, "Pan-STARRS_ID")

        self.catalog = catalog_utils.sort_by_separation(photom_catalog,
                                                        self.coord,
                                                        radec=('ra', 'dec'),
                                                        add_sep=True)
        # Meta
        self.catalog.meta['radius'] = self.radius
        self.catalog.meta['survey'] = self.survey

        #Validate
        self.validate_catalog()

        #Return
        return self.catalog.copy()