在Python中如何与给定的掩码交叉匹配来源?

huangapple go评论88阅读模式
英文:

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

问题

我有一个数据框,其中记录了遍布天空大部分地区的天文源(星系)的目录。我还有一个 .fits 二进制掩膜,只覆盖天空的某些部分(见下图)。我想要将目录与掩膜进行交叉匹配,以获取仅位于掩膜内的星系。我应该如何实现这一目标,例如使用 healpy?

英文:

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?

在Python中如何与给定的掩码交叉匹配来源?

答案1

得分: 1

以下是翻译好的部分:

一种方法是以下内容

    df_cat = pd.read_csv('file_path_cat.txt', names=['ra', 'dec', 'z', 'flag', 'var1', 'var2'])

    nside = 64 #这里的值取决于你使用的掩模,通常包含在掩模的名称中,通常为64、128或512
    N = 12*nside**2
    # 转换为HEALPix索引并对PS数据进行子采样
    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()
    # 最终,仅保留df_cat中'sky_mask'等于1的源,因为它们位于掩模内
    df_cross_matched = df_cat[df_cat.sky_mask==1]

我在以下笔记本中使用了这种方法'data_exploration_20220825.ipynb''Joining_and_processing_pyhod_bins_to_one_population.ipynb'
英文:

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

huangapple
  • 本文由 发表于 2023年5月21日 21:04:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76300038.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定