Пример #1
0
 def test_mcat_sources(self):
     band = self.NUV
     bandflag = 1 if band == 'NUV' else 2
     query = (
         str(self.baseURL) +
         'select ra, dec, nuv_mag, fuv_mag, fov_radius, nuv_skybg, fuv_skybg,'
         ' nuv_fwhm_world, fuv_fwhm_world, fuv_mag_aper_1, fuv_mag_aper_2,'
         ' fuv_mag_aper_3, fuv_mag_aper_4, fuv_mag_aper_5, fuv_mag_aper_6,'
         ' fuv_mag_aper_7, nuv_mag_aper_1, nuv_mag_aper_2, nuv_mag_aper_3,'
         ' nuv_mag_aper_4, nuv_mag_aper_5, nuv_mag_aper_6, nuv_mag_aper_7'
         ' fuv_magerr_aper_1, fuv_magerr_aper_2, fuv_magerr_aper_3,'
         ' fuv_magerr_aper_4, fuv_magerr_aper_5, fuv_magerr_aper_6,'
         ' fuv_magerr_aper_7, nuv_magerr_aper_1, nuv_magerr_aper_2,'
         ' nuv_magerr_aper_3, nuv_magerr_aper_4, nuv_magerr_aper_5,'
         ' nuv_magerr_aper_6, nuv_magerr_aper_7'
         ' from ' + str(self.MCATDB) + '.photoobjall as p inner join ' +
         str(self.MCATDB) +
         '.photoextract as pe on p.photoextractid=pe.photoextractid inner join '
         + str(self.MCATDB) + '.fgetnearbyobjeq(' + repr(float(self.ra0)) +
         ', ' + repr(float(self.dec0)) + ', ' + str(self.radius * 60.) +
         ') as nb on p.objid=nb.objid and (band=3 or band=' +
         str(bandflag) + ') and ' + str(band) + '_mag<' +
         str(self.maglimit) + str(self.formatURL))
     self.assertEqual(
         gq.mcat_sources(self.NUV,
                         self.ra0,
                         self.dec0,
                         self.radius,
                         maglimit=self.maglimit), query)
Пример #2
0
def avg_sources(band,
                skypos,
                radius=0.001,
                maglimit=20.0,
                verbose=0,
                catalog='MCAT'):
    """
    Return the mean position of sources within the search radius.

    :param band: The band to use, either 'FUV' or 'NUV'.

    :type band: str

    :param skypos: The right ascension and declination, in degrees.

    :type skypos: list

    :param radius: The radius within which to search for MCAT sources,
        in degrees?

    :type radius: float

    :param maglimit: The NUV faint limit to return unique sources for.

    :type maglimit: float

    :param verbose: Verbosity level, a value of 0 is minimum verbosity.

    :type verbose: int

    :param catalog: The name of the catalog to query.

    :type catalog: str

    :returns: tuple -- A three-element tuple containing the mean RA, mean DEC,
        and mean FWHM of sources within the search radius.
    """

    out = np.array(
        gQuery.getArray(gQuery.mcat_sources(band,
                                            skypos[0],
                                            skypos[1],
                                            radius,
                                            maglimit=maglimit),
                        verbose=verbose))

    ix = np.where(out[:, -2] > 0) if band == 'NUV' else np.where(
        out[:, -1] > 0)

    fwhm = out[ix, -2].mean() if band == 'NUV' else out[ix, -1].mean()

    return out[ix, 0].mean(), out[ix, 1].mean(), round(fwhm, 4)
Пример #3
0
def nearest_distinct_source(band,
                            skypos,
                            radius=0.1,
                            maglimit=20.0,
                            verbose=0,
                            catalog='MCAT'):
    """
    Return parameters for the nearest non-targeted source.

    :param band: The band to use, either 'FUV' or 'NUV'.

    :type band: str

    :param skypos: The right ascension and declination, in degrees.

    :type skypos: list

    :param radius: The radius within which to search for the nearest MCAT
        source, in degrees.

    :type radius: float

    :param maglimit: The NUV faint limit to return unique sources for.

    :type maglimit: float

    :param verbose: Verbosity level, a value of 0 is minimum verbosity.

    :type verbose: int

    :param catalog: The name of the catalog to query.

    :type catalog: str

    :returns: numpy.ndarray -- Catalog values for the nearest non-targeted
        source.
    """

    out = np.array(
        gQuery.getArray(gQuery.mcat_sources(band,
                                            skypos[0],
                                            skypos[1],
                                            radius,
                                            maglimit=maglimit),
                        verbose=verbose))

    dist = angularSeparation(out[:, 0], out[:, 1], skypos[0], skypos[1])

    ix = np.where(dist > 0.005)

    return np.array(out)[ix][np.where(dist[ix] == dist[ix].min())][0]
Пример #4
0
def nearest_distinct_source(band, skypos, radius=0.1, maglimit=20.0, verbose=0,
                            catalog='MCAT'):
    """
    Return parameters for the nearest non-targeted source.

    :param band: The band to use, either 'FUV' or 'NUV'.

    :type band: str

    :param skypos: The right ascension and declination, in degrees.

    :type skypos: list

    :param radius: The radius within which to search for the nearest MCAT
        source, in degrees.

    :type radius: float

    :param maglimit: The NUV faint limit to return unique sources for.

    :type maglimit: float

    :param verbose: Verbosity level, a value of 0 is minimum verbosity.

    :type verbose: int

    :param catalog: The name of the catalog to query.

    :type catalog: str

    :returns: numpy.ndarray -- Catalog values for the nearest non-targeted
        source.
    """

    out = np.array(gQuery.getArray(gQuery.mcat_sources(band, skypos[0],
                                                       skypos[1], radius,
                                                       maglimit=maglimit),
                                   verbose=verbose))

    dist = angularSeparation(out[:, 0], out[:, 1], skypos[0], skypos[1])

    ix = np.where(dist > 0.005)

    return np.array(out)[ix][np.where(dist[ix] == dist[ix].min())][0]
Пример #5
0
def avg_sources(band, skypos, radius=0.001, maglimit=20.0, verbose=0,
                catalog='MCAT'):
    """
    Return the mean position of sources within the search radius.

    :param band: The band to use, either 'FUV' or 'NUV'.

    :type band: str

    :param skypos: The right ascension and declination, in degrees.

    :type skypos: list

    :param radius: The radius within which to search for MCAT sources,
        in degrees?

    :type radius: float

    :param maglimit: The NUV faint limit to return unique sources for.

    :type maglimit: float

    :param verbose: Verbosity level, a value of 0 is minimum verbosity.

    :type verbose: int

    :param catalog: The name of the catalog to query.

    :type catalog: str

    :returns: tuple -- A three-element tuple containing the mean RA, mean DEC,
        and mean FWHM of sources within the search radius.
    """

    out = np.array(gQuery.getArray(gQuery.mcat_sources(band, skypos[0],
                                                       skypos[1], radius,
                                                       maglimit=maglimit),
                                   verbose=verbose))

    ix = np.where(out[:, -2] > 0) if band == 'NUV' else np.where(out[:, -1] > 0)

    fwhm = out[ix, -2].mean() if band == 'NUV' else out[ix, -1].mean()

    return out[ix, 0].mean(), out[ix, 1].mean(), round(fwhm, 4)
Пример #6
0
 def test_mcat_sources(self):
     band = self.NUV
     bandflag = 1 if band=='NUV' else 2
     query = (str(self.baseURL)+
         'select ra, dec, nuv_mag, fuv_mag, fov_radius, nuv_skybg, fuv_skybg,'
         ' nuv_fwhm_world, fuv_fwhm_world, fuv_mag_aper_1, fuv_mag_aper_2,'
         ' fuv_mag_aper_3, fuv_mag_aper_4, fuv_mag_aper_5, fuv_mag_aper_6,'
         ' fuv_mag_aper_7, nuv_mag_aper_1, nuv_mag_aper_2, nuv_mag_aper_3,'
         ' nuv_mag_aper_4, nuv_mag_aper_5, nuv_mag_aper_6, nuv_mag_aper_7'
         ' fuv_magerr_aper_1, fuv_magerr_aper_2, fuv_magerr_aper_3,'
         ' fuv_magerr_aper_4, fuv_magerr_aper_5, fuv_magerr_aper_6,'
         ' fuv_magerr_aper_7, nuv_magerr_aper_1, nuv_magerr_aper_2,'
         ' nuv_magerr_aper_3, nuv_magerr_aper_4, nuv_magerr_aper_5,'
         ' nuv_magerr_aper_6, nuv_magerr_aper_7'
         ' from '+str(self.MCATDB)+'.photoobjall as p inner join '+str(self.MCATDB)+
         '.photoextract as pe on p.photoextractid=pe.photoextractid inner join '+
         str(self.MCATDB)+'.fgetnearbyobjeq('+repr(float(self.ra0))+', '+
         repr(float(self.dec0))+', '+
         str(self.radius*60.)+') as nb on p.objid=nb.objid and (band=3 or band='+
         str(bandflag)+') and '+str(band)+'_mag<'+str(self.maglimit)+
         str(self.formatURL))
     self.assertEqual(gq.mcat_sources(self.NUV,self.ra0,self.dec0,self.radius,maglimit=self.maglimit),query)
Пример #7
0
def get_mags(band, ra0, dec0, radius, maglimit, mode='coadd',
             zpmag={'NUV':20.08, 'FUV':18.82}, verbose=1):
    """
    Given RA, Dec and search radius, searches the coadd MCAT for sources.
        Returns a dict() which contains magnitudes for all of the APER settings.
        Note: Visit mode returns a lot more sources, more slowly than coadd mode
        given the same search parameters. You should probably use smaller search
        radii in visit mode. If you're just trying to find unique sources in a
        large region, use coadd mode and then pass the result through the
        parse_unique_sources() function contained in this module.

    :param band: The band to use, either 'FUV' or 'NUV'.

    :type band: str

    :param ra0: The right ascension, in degrees, around which to search.

    :type ra0: float

    :param dec0: The declination, in degrees, around which to search.

    :type dec0: float

    :param radius: The size of the search radius for MCAT sources in degrees.

    :type radius: float

    :param maglimit: The NUV faint limit to return MCAT sources for.

    :type maglimit: float

    :param mode: Specify whether to return MCAT sources from the 'visit' or
        'coadd' catalog.

    :type mode: str

    :param zpmag: The zero-point magnitude in FUV and NUV.

    :type zpmag: dict

    :param verbose: Verbosity level, a value of 0 is minimum verbosity.

    :type verbose: int

    :returns: dict -- The set of magnitudes from different apertures for sources
        in the MCAT, centered around the specified coordinate.
    """

    zpf, zpn = zpmag['FUV'], zpmag['NUV']

    if mode == 'coadd':
        out = np.array(gQuery.getArray(gQuery.mcat_sources(band, ra0, dec0,
                                                           radius,
                                                           maglimit=maglimit),
                                       verbose=verbose))
        if not len(out):
            if verbose:
                print("Warning: No sources found!")
            return None
        return {'ra':out[:, 0], 'dec':out[:, 1],
                'FUV':{'mag':out[:, 3], 1:out[:, 9]+zpf, 2:out[:, 10]+zpf,
                       3:out[:, 11]+zpf, 4:out[:, 12]+zpf, 5:out[:, 13]+zpf,
                       6:out[:, 14], 7:out[:, 15]+zpf},
                'NUV':{'mag':out[:, 2], 1:out[:, 16]+zpn, 2:out[:, 17]+zpn,
                       3:out[:, 18]+zpn, 4:out[:, 19]+zpn, 5:out[:, 20]+zpn,
                       6:out[:, 21]+zpn, 7:out[:, 22]+zpn}}
    elif mode == 'visit':
        return get_mcat_data([ra0, dec0], radius)
    else:
        print("mode must be in [coadd,visit]")
        return None
Пример #8
0
def nearest_source(band, skypos, radius=0.01, maglimit=20.0, verbose=0,
                   catalog='MCAT'):
    """
    Return targeting parameters for the nearest MCAT source to a position.

    :param band: The band to use, either 'FUV' or 'NUV'.

    :type band: str

    :param skypos: The right ascension and declination, in degrees.

    :type skypos: list

    :param radius: The radius within which to search for the nearest MCAT
        source, in degrees.

    :type radius: float

    :param maglimit: The NUV faint limit to return unique sources for.

    :type maglimit: float

    :param verbose: Verbosity level, a value of 0 is minimum verbosity.

    :type verbose: int

    :param catalog: The name of the catalog to query.

    :type catalog: str

    :returns: tuple -- A three-element tuple containing the mean RA, mean DEC,
        and mean FWHM of the nearest sources within the search radius.
    """

    out = np.array(gQuery.getArray(gQuery.mcat_sources(band, skypos[0],
                                                       skypos[1], radius,
                                                       maglimit=maglimit),
                                   verbose=verbose))

    if not len(out) and band == 'FUV':
        if verbose:
            print("No nearby MCAT source found in FUV. Trying NUV...")
        band = 'NUV'
        out = np.array(gQuery.getArray(gQuery.mcat_sources(band, skypos[0],
                                                           skypos[1], radius,
                                                           maglimit=maglimit),
                                       verbose=verbose))

    if not len(out) and band == 'NUV':
        if verbose:
            print("No nearby MCAT source found. Using input sky position.")
        return skypos[0], skypos[1], 0.01

    dist = angularSeparation(out[:, 0], out[:, 1], skypos[0], skypos[1])

    if verbose > 1:
        print("Finding nearest among "+str(len(dist))+" nearby sources.")

    # Note that this doesn't cope with multiple entries for the same source.
    s = out[np.where(dist == dist.min())][0]

    return avg_sources(band, [s[0], s[1]], verbose=verbose)
Пример #9
0
def nearest_source(band,
                   skypos,
                   radius=0.01,
                   maglimit=20.0,
                   verbose=0,
                   catalog='MCAT'):
    """
    Return targeting parameters for the nearest MCAT source to a position.

    :param band: The band to use, either 'FUV' or 'NUV'.

    :type band: str

    :param skypos: The right ascension and declination, in degrees.

    :type skypos: list

    :param radius: The radius within which to search for the nearest MCAT
        source, in degrees.

    :type radius: float

    :param maglimit: The NUV faint limit to return unique sources for.

    :type maglimit: float

    :param verbose: Verbosity level, a value of 0 is minimum verbosity.

    :type verbose: int

    :param catalog: The name of the catalog to query.

    :type catalog: str

    :returns: tuple -- A three-element tuple containing the mean RA, mean DEC,
        and mean FWHM of the nearest sources within the search radius.
    """

    out = np.array(
        gQuery.getArray(gQuery.mcat_sources(band,
                                            skypos[0],
                                            skypos[1],
                                            radius,
                                            maglimit=maglimit),
                        verbose=verbose))

    if not len(out) and band == 'FUV':
        if verbose:
            print("No nearby MCAT source found in FUV. Trying NUV...")
        band = 'NUV'
        out = np.array(
            gQuery.getArray(gQuery.mcat_sources(band,
                                                skypos[0],
                                                skypos[1],
                                                radius,
                                                maglimit=maglimit),
                            verbose=verbose))

    if not len(out) and band == 'NUV':
        if verbose:
            print("No nearby MCAT source found. Using input sky position.")
        return skypos[0], skypos[1], 0.01

    dist = angularSeparation(out[:, 0], out[:, 1], skypos[0], skypos[1])

    if verbose > 1:
        print("Finding nearest among " + str(len(dist)) + " nearby sources.")

    # Note that this doesn't cope with multiple entries for the same source.
    s = out[np.where(dist == dist.min())][0]

    return avg_sources(band, [s[0], s[1]], verbose=verbose)
Пример #10
0
def get_mags(band,
             ra0,
             dec0,
             radius,
             maglimit,
             mode='coadd',
             zpmag={
                 'NUV': 20.08,
                 'FUV': 18.82
             },
             verbose=1):
    """
    Given RA, Dec and search radius, searches the coadd MCAT for sources.
        Returns a dict() which contains magnitudes for all of the APER settings.
        Note: Visit mode returns a lot more sources, more slowly than coadd mode
        given the same search parameters. You should probably use smaller search
        radii in visit mode. If you're just trying to find unique sources in a
        large region, use coadd mode and then pass the result through the
        parse_unique_sources() function contained in this module.

    :param band: The band to use, either 'FUV' or 'NUV'.

    :type band: str

    :param ra0: The right ascension, in degrees, around which to search.

    :type ra0: float

    :param dec0: The declination, in degrees, around which to search.

    :type dec0: float

    :param radius: The size of the search radius for MCAT sources in degrees.

    :type radius: float

    :param maglimit: The NUV faint limit to return MCAT sources for.

    :type maglimit: float

    :param mode: Specify whether to return MCAT sources from the 'visit' or
        'coadd' catalog.

    :type mode: str

    :param zpmag: The zero-point magnitude in FUV and NUV.

    :type zpmag: dict

    :param verbose: Verbosity level, a value of 0 is minimum verbosity.

    :type verbose: int

    :returns: dict -- The set of magnitudes from different apertures for sources
        in the MCAT, centered around the specified coordinate.
    """

    zpf, zpn = zpmag['FUV'], zpmag['NUV']

    if mode == 'coadd':
        out = np.array(
            gQuery.getArray(gQuery.mcat_sources(band,
                                                ra0,
                                                dec0,
                                                radius,
                                                maglimit=maglimit),
                            verbose=verbose))
        if not len(out):
            if verbose:
                print("Warning: No sources found!")
            return None
        return {
            'ra': out[:, 0],
            'dec': out[:, 1],
            'FUV': {
                'mag': out[:, 3],
                1: out[:, 9] + zpf,
                2: out[:, 10] + zpf,
                3: out[:, 11] + zpf,
                4: out[:, 12] + zpf,
                5: out[:, 13] + zpf,
                6: out[:, 14],
                7: out[:, 15] + zpf
            },
            'NUV': {
                'mag': out[:, 2],
                1: out[:, 16] + zpn,
                2: out[:, 17] + zpn,
                3: out[:, 18] + zpn,
                4: out[:, 19] + zpn,
                5: out[:, 20] + zpn,
                6: out[:, 21] + zpn,
                7: out[:, 22] + zpn
            }
        }
    elif mode == 'visit':
        return get_mcat_data([ra0, dec0], radius)
    else:
        print("mode must be in [coadd,visit]")
        return None