Ejemplo n.º 1
0
def choose_filter(desi_footprint,
                  desi_footprint_pixel,
                  desi_footprint_pixel_plus,
                  desimodel_installed,
                  N_side=16,
                  pixel_list=None):

    if np.sum(
        (desi_footprint, desi_footprint_pixel, desi_footprint_pixel_plus)) > 1:
        raise ValueError('Please choose only 1 type of DESI footprint.')

    if desimodel_installed:
        from desimodel.footprint import tiles2pix, is_point_in_desi
        if desi_footprint:

            def QSO_filter(RA, DEC):
                return is_point_in_desi(tiles, RA, DEC)
        elif desi_footprint_pixel:
            QSO_filter = tiles2pix(N_side)
        elif desi_footprint_pixel_plus:
            QSO_filter = tiles2pix(N_side)
            QSO_filter = add_pixel_neighbours(QSO_filter)
        else:
            QSO_filter = None
    else:
        if desi_footprint or desi_footprint_pixel:
            QSO_filter = np.loadtxt('input_files/DESI_pixels.txt', dtype=int)
        elif desi_footprint_pixel_plus:
            QSO_filter = np.loadtxt('input_files/DESI_pixels_plus.txt',
                                    dtype=int)
        else:
            QSO_filter = None

    return QSO_filter
Ejemplo n.º 2
0
def find_gaia_files_tiles(tiles=None, neighbors=True):
    """
    Parameters
    ----------
    tiles : :class:`~numpy.ndarray`
        Array of tiles, or ``None`` to use all DESI tiles from
        :func:`desimodel.io.load_tiles`.
    neighbors : :class:`bool`, optional, defaults to ``True``
        Also return all neighboring pixels that touch the files of interest
        in order to prevent edge effects (e.g. if a Gaia source is 1 arcsec
        away from a primary source and so in an adjacent pixel).

    Returns
    -------
    :class:`list`
        A list of all Gaia files that touch the passed tiles.

    Notes
    -----
        - The environment variables $GAIA_DIR and $DESIMODEL must be set.
    """
    # ADM check that the DESIMODEL environement variable is set.
    if os.environ.get('DESIMODEL') is None:
        msg = "DESIMODEL environment variable must be set!!!"
        log.critical(msg)
        raise ValueError(msg)

    # ADM the resolution at which the healpix files are stored.
    nside = _get_gaia_nside()

    # ADM check that the GAIA_DIR is set and retrieve it.
    gaiadir = _get_gaia_dir()
    hpxdir = os.path.join(gaiadir, 'healpix')

    # ADM determine the pixels that touch the tiles.
    from desimodel.footprint import tiles2pix
    pixnum = tiles2pix(nside, tiles=tiles)

    # ADM if neighbors was sent, then retrieve all pixels that touch each
    # ADM pixel covered by the provided locations, to prevent edge effects...
    if neighbors:
        pixnum = add_hp_neighbors(nside, pixnum)

    # ADM reformat in the Gaia healpix format used by desitarget.
    gaiafiles = [
        os.path.join(hpxdir, 'healpix-{:05d}.fits'.format(pn)) for pn in pixnum
    ]

    return gaiafiles
Ejemplo n.º 3
0
isin, index    = is_point_in_desi(tiles, gcs['ra'], gcs['dec'], return_tile_index=True)

gcs['TILEID']       = -99
gcs['TILEID'][isin] = tiles['TILEID'][index[isin]]

gcs            = gcs[gcs['name'] == 'NGC5904']
gcs['RA']      = gcs['ra']
gcs['DEC']     = gcs['dec']
gcs            = gcs['RA', 'DEC', 'name', 'TILEID']

tiles          = tiles[tiles['TILEID'] == gcs['TILEID']]

gcs.pprint()
tiles.pprint()

pix            = tiles2pix(nside=2, tiles=tiles)

for p in pix:
  targets                 = Table(fits.open('/project/projectdirs/desi/target/catalogs/dr8/0.32.0/targets/main/resolve/bright/targets-dr8-hp-{}.fits'.format(p))[1].data)
  targets                 = targets[(targets['DESI_TARGET'] & 2 ** desi_mask.bitnum('BGS_ANY')) != 0]
  isin, index             = is_point_in_desi(tiles, targets['RA'], targets['DEC'], return_tile_index=True)
  targets['TILEID']       = -99
  targets['TILEID'][isin] = tiles['TILEID'][index[isin]]

  targets         = vstack([gcs, targets])
  targets['name'] = ''
  targets         = targets['RA', 'DEC', 'TILEID', 'name']
  targets         = targets[targets['TILEID'] > 0]
  
  print(targets)
Ejemplo n.º 4
0
def make_QSO_filter(footprint, N_side=16, pixel_list=None):

    #See if we can use desimodel. This is preferable as it will be the most
    #up-do-date footprint.
    try:
        from desimodel.footprint import tiles2pix, is_point_in_desi
        from desimodel.io import load_tiles
        desimodel_installed = True
    except ModuleNotFoundError:
        print(
            'WARN: desimodel is not installed; footprint pixel data will be read from file.'
        )
        desimodel_installed = False

    #If we have desimodel and want to replicate the footprint precisely, use
    #function "is_point_in_desi".
    if desimodel_installed and footprint == 'desi':
        tiles = load_tiles()

        def QSO_filter(RA, DEC):
            return is_point_in_desi(tiles, RA, DEC)

    #If not, but we still want to filter...
    elif footprint in ['desi', 'desi_pixel', 'desi_pixel_plus']:

        #If desimodel is installed, then we use "tiles2pix" to determine which
        #pixels to include.
        if desimodel_installed:
            from desimodel.footprint import tiles2pix
            if footprint == 'desi_pixel':
                valid_pixels = tiles2pix(N_side)
            elif footprint == 'desi_pixel_plus':
                valid_pixels = tiles2pix(N_side)
                valid_pixels = add_pixel_neighbours(valid_pixels)

        #Otherwise, we load pixel lists from file. Note: using desimodel is
        #preferable to loading from file as the footprint could change, and
        #desimodel will be more up to date than the lists in this case.
        else:
            if footprint == 'desi':
                print(
                    'WARN: desimodel is not installed; footprint pixel data will be read from file.'
                )
                valid_pixels = np.loadtxt(
                    'input_files/pixel_footprints/DESI_pixels.txt', dtype=int)
            elif footprint == 'desi_pixel':
                valid_pixels = np.loadtxt(
                    'input_files/pixel_footprints/DESI_pixels.txt', dtype=int)
            elif footprint == 'desi_pixel_plus':
                valid_pixels = np.loadtxt(
                    'input_files/pixel_footprints/DESI_pixels_plus.txt',
                    dtype=int)

        #With a list of valid pixels, we now can make a filter.

        def QSO_filter(RA, DEC):
            theta = (np.pi / 180.0) * (90.0 - DEC)
            phi = (np.pi / 180.0) * RA
            pix = hp.ang2pix(N_side, theta, phi, nest=True)
            w = np.in1d(pix, valid_pixels)
            return w

    #Else if we don't want to filter at all, set the filter to "None".
    elif footprint == 'full_sky':

        def QSO_filter(RA, DEC):
            return np.ones(RA.shape).astype('bool')

    else:
        print('Footprint not recognised; no filter applied.')

        def QSO_filter(RA, DEC):
            return np.ones(RA.shape).astype('bool')

    return QSO_filter