pythonpandasastropyhealpycross-match

In python how to cross match sources with a given mask?


I have a dataframe that is a catalogue of astronomical sources (galaxies) spread across most of the sky. I also have a .fits binary mask that covers only some parts of the sky (see below). I want to cross-match the catalogue with the mask to get only the galaxies that fall within the mask. How can I do this, e.g. with healpy?

enter image description here


Solution

  • One way to do this is the following:

    df_cat = pd.read_csv('file_path_cat.txt', names=['ra', 'dec', 'z', 'flag', 'var1', 'var2'])
    
    nside = 64 #the value here depends on the mask you are using, it's mostly contained
    # in the name of the mask and is usually 64, 128 or 512
    N = 12*nside**2
    # convert to HEALPix indices and subsample the PS data
    indices = hp.ang2pix(nside, df_cat.ra.values, df_cat.dec.values, lonlat=True)
    mask = hp.read_map('mask_file_path.fits')
    df_cat['sky_mask'] = np.array(mask[indices]).byteswap().newbyteorder()
    # eventually, keep only the sources in df_cat with 'sky_mask'==1, since they are within the mask
    df_cross_matched = df_cat[df_cat.sky_mask==1]
    

    Notebooks I have used this approach in are data_exploration_20220825.ipynb and Joining_and_processing_pyhod_bins_to_one_population.ipynb