Last Updated: Bryce Kalmbach, December 2018
This is a notebook to produce the host AGN and SN catalogs that are used to created FITS postage stamps of the lensed systems. The goal here is to associate the lens and host information into a single catalog so that Nan Li can use it properly model the host galaxy shapes and we include them as fits files with the instance catalogs. PhoSim is able to take these fits files as input for the given line in the instance catalog so that we have properly shaped host galaxies in our lensed systems.
In [1]:
import pandas as pd
from astropy.io import fits
import numpy as np
from desc.sims.GCRCatSimInterface import InstanceCatalogWriter
from lsst.sims.utils import SpecMap
import matplotlib.pyplot as plt
from lsst.utils import getPackageDir
from lsst.sims.photUtils import Sed, BandpassDict, Bandpass
from lsst.sims.catUtils.matchSED import matchBase
import os
%matplotlib inline
In [2]:
base_columns = ['prefix', 'uniqueId', 'raPhoSim', 'decPhoSim',
'phosimMagNorm', 'sedFilepath', 'redshift',
'shear1', 'shear2', 'kappa', 'raOffset', 'decOffset',
'spatialmodel']
In [3]:
df_galaxy = pd.read_csv(os.path.join(os.environ['SCRATCH'],
'bulge_gal_cat_197356.txt.gz'),
delimiter=' ', header=None,
names=base_columns+['majorAxis', 'minorAxis',
'positionAngle', 'sindex',
'internalExtinctionModel',
'internalAv', 'internalRv',
'galacticExtinctionModel',
'galacticAv', 'galacticRv'])
In [4]:
df_disk = pd.read_csv(os.path.join(os.environ['SCRATCH'],
'disk_gal_cat_197356.txt.gz'),
delimiter=' ', header=None,
names=base_columns+['majorAxis', 'minorAxis',
'positionAngle', 'sindex',
'internalExtinctionModel',
'internalAv', 'internalRv',
'galacticExtinctionModel',
'galacticAv', 'galacticRv'])
In [5]:
df_agn = pd.read_csv(os.path.join(os.environ['SCRATCH'],
'agn_gal_cat_197356.txt.gz'),
delimiter=' ', header=None,
names=base_columns+['internalExtinctionModel',
'galacticExtinctionModel',
'galacticAv', 'galacticRv'])
In [6]:
df_agn['galaxy_id'] = np.right_shift(df_agn['uniqueId'], 10)
In [7]:
df_agn.head()
Out[7]:
In [8]:
df_galaxy['galaxy_id'] = np.right_shift(df_galaxy['uniqueId'], 10)
In [9]:
df_galaxy.head()
Out[9]:
In [10]:
df_disk['galaxy_id'] = np.right_shift(df_disk['uniqueId'], 10)
In [11]:
df_disk.head()
Out[11]:
What we are going to do is take the information on the unlensed bulge and disks from the instance catalog above and combine it with information on the lens that will be sprinkled in front of it so that we can accurately model the appearance of the lensed hosts in a fits postage stamp to include with the instance catalogs and give us properly modeled host galaxy images. We first do it for the AGN here and then repeat for the SNe below.
The cache file associates the galaxy_id
values with the twinklesId
values in the lensed system catalog. The file cosmoDC2_vX.X_matched_AGN.fits
contains the information on the lensed systems.
In [12]:
catalog_version = 'cosmoDC2_v1.1.4'
In [13]:
hdulist = fits.open('../../data/%s_matched_AGN.fits' % catalog_version)
twinkles_lenses = hdulist[1].data
In [14]:
agn_cache_df = pd.read_csv('../../data/%s_agn_cache.csv' % catalog_version)
Next we add in the lens properties to go with each of the images.
In [15]:
#TwinklesId can range from 0 - 1099
ra_images = []
dec_images = []
num_images = []
twinkles_system_images = []
unique_id_lens = []
unique_id_bulge = []
unique_id_disk = []
bulge_index = []
disk_index = []
disk_valid = []
i = 0
for twinkles_system in range(len(twinkles_lenses)):
if twinkles_system % 100 == 0:
print(twinkles_system)
cache_info = agn_cache_df.query('twinkles_system == %i' % twinkles_system)
gal_id = cache_info['galtileid'].values[0]
lens_info = twinkles_lenses[np.where(twinkles_lenses['twinklesId'] == twinkles_system)]
bulge_info = df_galaxy.query('galaxy_id == %i' % gal_id)
disk_info = df_disk.query('galaxy_id == %i' % gal_id)
#print(bulge_info, disk_info)
for lens_image in range(lens_info[0]['NIMG']):
ra_shift = np.radians(lens_info[0]['XIMG'][lens_image] / 3600.) / np.cos(np.radians(bulge_info['decPhoSim']))
dec_shift = np.radians(lens_info[0]['YIMG'][lens_image] / 3600.)
image_ra = np.radians(bulge_info['raPhoSim']) + ra_shift
image_dec = np.radians(bulge_info['decPhoSim'] + dec_shift)
ra_images.append(np.degrees(image_ra).values[0])
dec_images.append(np.degrees(image_dec).values[0])
num_images.append(lens_image)
unique_id_lens.append(bulge_info['uniqueId'].values[0])
twinkles_system_images.append(twinkles_system)
base_id = (gal_id + int(1.5e10))*10000 + twinkles_system*4 + lens_image
unique_id_bulge.append(np.left_shift(base_id, 10) + 97)
unique_id_disk.append(np.left_shift(base_id, 10) + 107)
bulge_index.append(bulge_info.index[0])
if len(disk_info) == 0:
print(twinkles_system)
else:
disk_index.append(disk_info.index[0])
disk_valid.append(i)
i += 1
In [16]:
host_bulge = df_galaxy.iloc[bulge_index]
In [17]:
host_bulge = host_bulge.reset_index(drop=True)
In [18]:
host_bulge['twinkles_system'] = twinkles_system_images
In [19]:
host_bulge['image_number'] = num_images
In [20]:
host_bulge['uniqueId_lens'] = unique_id_lens
In [21]:
host_bulge['uniqueId'] = unique_id_bulge
In [22]:
host_bulge['raPhoSim_lens'] = host_bulge['raPhoSim']
host_bulge['decPhoSim_lens'] = host_bulge['decPhoSim']
In [23]:
host_bulge['raPhoSim'] = ra_images
host_bulge['decPhoSim'] = dec_images
In [24]:
host_bulge.head()
Out[24]:
In [25]:
host_disk = df_disk.iloc[disk_index]
In [26]:
host_disk = host_disk.reset_index(drop=True)
In [27]:
host_disk['twinkles_system'] = np.array(twinkles_system_images)[disk_valid]
In [28]:
host_disk['image_number'] = np.array(num_images)[disk_valid]
In [29]:
host_disk['uniqueId_lens'] = np.array(unique_id_lens)[disk_valid]
In [30]:
host_disk['uniqueId'] = np.array(unique_id_disk)[disk_valid]
In [31]:
host_disk['raPhoSim_lens'] = host_disk['raPhoSim']
host_disk['decPhoSim_lens'] = host_disk['decPhoSim']
In [32]:
host_disk['raPhoSim'] = np.array(ra_images)[disk_valid]
host_disk['decPhoSim'] = np.array(dec_images)[disk_valid]
In [33]:
host_disk.head()
Out[33]:
In [34]:
host_bulge.to_csv('../../data/%s_bulge_agn_host.csv' % catalog_version)
host_disk.to_csv('../../data/%s_disk_agn_host.csv' % catalog_version)
We do the same as we did for the lensed AGN systems with the lensed SNe systems below.
The cache file associates the galaxy_id
values with the twinklesId
values in the lensed system catalog. The file cosmoDC2_vX.X_sne_cat.csv
contains the information on the images.
In [35]:
sne_df = pd.read_csv('../../data/%s_sne_cat.csv' % catalog_version)
In [36]:
sne_cache_df = pd.read_csv('../../data/%s_sne_cache.csv' % catalog_version)
In [37]:
sne_df.head()
Out[37]:
Next we add in the lens properties to go with each of the images.
In [38]:
#TwinklesId ranges from 1100 - 1100+number of cached SNe
ra_images = []
dec_images = []
num_images = []
twinkles_system_images = []
unique_id_lens = []
unique_id_bulge = []
unique_id_disk = []
bulge_index = []
disk_index = []
disk_valid = []
i = 0
for twinkles_system in range(1100, 1100+len(sne_cache_df)):
if twinkles_system % 100 == 0:
print(twinkles_system)
cache_info = sne_cache_df.query('twinkles_system == %i' % twinkles_system)
gal_id = cache_info['galtileid'].values[0]
lens_info = sne_df.iloc[np.where(sne_df['twinkles_sysno'] == twinkles_system)]
bulge_info = df_galaxy.query('galaxy_id == %i' % gal_id)
disk_info = df_disk.query('galaxy_id == %i' % gal_id)
#print(bulge_info, disk_info)
for lens_image in lens_info['imno'].values:
ra_shift = np.radians(lens_info['x'].iloc[lens_image] / 3600.) / np.cos(np.radians(bulge_info['decPhoSim']))
dec_shift = np.radians(lens_info['y'].iloc[lens_image] / 3600.)
image_ra = np.radians(bulge_info['raPhoSim']) + ra_shift
image_dec = np.radians(bulge_info['decPhoSim'] + dec_shift)
ra_images.append(np.degrees(image_ra).values[0])
dec_images.append(np.degrees(image_dec).values[0])
num_images.append(lens_image)
unique_id_lens.append(bulge_info['uniqueId'].values[0])
twinkles_system_images.append(twinkles_system)
base_id = (gal_id + int(1.5e10))*10000 + twinkles_system*4 + lens_image
unique_id_bulge.append(np.left_shift(base_id, 10) + 97)
unique_id_disk.append(np.left_shift(base_id, 10) + 107)
bulge_index.append(bulge_info.index[0])
if len(disk_info) == 0:
print(twinkles_system)
else:
disk_index.append(disk_info.index[0])
disk_valid.append(i)
i += 1
In [39]:
host_bulge = df_galaxy.iloc[bulge_index]
In [40]:
host_bulge = host_bulge.reset_index(drop=True)
In [41]:
host_bulge['twinkles_system'] = twinkles_system_images
In [42]:
host_bulge['image_number'] = num_images
In [43]:
host_bulge['uniqueId_lens'] = unique_id_lens
In [44]:
host_bulge['uniqueId'] = unique_id_bulge
In [45]:
host_bulge['raPhoSim_lens'] = host_bulge['raPhoSim']
host_bulge['decPhoSim_lens'] = host_bulge['decPhoSim']
In [46]:
host_bulge['raPhoSim'] = ra_images
host_bulge['decPhoSim'] = dec_images
In [47]:
host_bulge.head()
Out[47]:
In [48]:
host_disk = df_disk.iloc[disk_index]
In [49]:
host_disk = host_disk.reset_index(drop=True)
In [50]:
host_disk['twinkles_system'] = np.array(twinkles_system_images)[disk_valid]
In [51]:
host_disk['image_number'] = np.array(num_images)[disk_valid]
In [52]:
host_disk['uniqueId_lens'] = np.array(unique_id_lens)[disk_valid]
In [53]:
host_disk['uniqueId'] = np.array(unique_id_disk)[disk_valid]
In [54]:
host_disk['raPhoSim_lens'] = host_disk['raPhoSim']
host_disk['decPhoSim_lens'] = host_disk['decPhoSim']
In [55]:
host_disk['raPhoSim'] = np.array(ra_images)[disk_valid]
host_disk['decPhoSim'] = np.array(dec_images)[disk_valid]
In [56]:
host_disk.head()
Out[56]:
In [57]:
host_bulge.to_csv('../../data/%s_bulge_sne_host.csv' % catalog_version)
host_disk.to_csv('../../data/%s_disk_sne_host.csv' % catalog_version)
In [ ]: