Skip to content

Commit

Permalink
Removing some unnecessary imports
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandergagliano committed Oct 25, 2023
1 parent f4a87ea commit db1338f
Show file tree
Hide file tree
Showing 4 changed files with 47,227 additions and 35 deletions.
74 changes: 41 additions & 33 deletions astro_ghost/DLR.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
from astropy.coordinates import SkyCoord, Angle, Distance
from astropy.wcs import WCS
from astropy.cosmology import FlatLambdaCDM, z_at_value
from astropy.utils.data import get_pkg_data_filename
from astroquery.vizier import Vizier

#from astropy.utils.data import get_pkg_data_filename
#from astroquery.vizier import Vizier
from astroquery.ipac.ned import Ned

def choose_band_SNR(host_df):
"""Gets the PS1 band (of grizy) with the highest SNR in PSF mag.
Expand Down Expand Up @@ -376,7 +376,7 @@ def chooseByDLR(path, hosts, transients, fn, orig_dict, todo="s"):
elif todo =="r":
return hosts, dict_mod, noHosts, GA_SN

def chooseByGladeDLR(path, fn, snDF, verbose=False, todo='r'):
def chooseByGladeDLR(path, fn, snDF, verbose=False, todo='r', GWGC=None):
"""The wrapper function for selecting hosts by the DLR method (Gupta et al., 2013).
Here, candidate hosts are taken from the GLADE (Dalya et al., 2021; arXiv:2110.06184) catalog.
Expand All @@ -390,6 +390,8 @@ def chooseByGladeDLR(path, fn, snDF, verbose=False, todo='r'):
:param todo: If todo == \\'s\\', save the dictionary and the list of remaining sources.
If todo == \\'r\\', return them.
:type todo: str
:param GWGC: DataFrame of local galaxies with shape information, from GWGC (White et al., 2011).
:type GWGC: Pandas DataFrame
:return: The dataframe of properties for GLADE host galaxies found by DLR.
:rtype: Pandas DataFrame
:return: List of transients for which no reliable GLADE host galaxy was found.
Expand All @@ -406,12 +408,22 @@ def chooseByGladeDLR(path, fn, snDF, verbose=False, todo='r'):
foundHostDF = []
noGladeHosts = []

if GWGC:
GWGC_coords = SkyCoord(GWGC['RAJ2000'].values, GWGC['DEJ200'].values, unit=(u.deg, u.deg))

#assume standard cosmology for distance estimates
cosmo = FlatLambdaCDM(H0=70, Om0=0.3, Tcmb0=2.725)

for idx, row in snDF.iterrows():
name = str(row['Name'])
ra_SN = float(row['RA'])
dec_SN = float(row['DEC'])
class_SN = str(row['Obj. Type'])

#broad cone search of GWGC galaxies:
seps = SkyCoord(ra=ra_SN, dec=dec_SN,unit=(u.deg, u.deg),frame='icrs').separation(GWGC_coords).deg
hosts = GWGC[seps < 0.2] #within 0.2 deg

# TODO fix this
#query the glade catalog
#Vizier.ROW_LIMIT = -1
Expand All @@ -421,40 +433,39 @@ def chooseByGladeDLR(path, fn, snDF, verbose=False, todo='r'):
# hosts = result[0].to_pandas()
#else:
# hosts = pd.DataFrame({'a_b':[np.nan], 'maj':[np.nan], 'min':[np.nan]})

# query NED for GLADE sources and get their radius
GLADE_rad = hosts.dropna(subset=['a_b', 'maj', 'min'])
GLADE_norad = hosts[~hosts.index.isin(GLADE_rad.index)]

from astroquery.ipac.ned import Ned
badRadCount = 0
for idx, row in GLADE_norad.iterrows():
try:
result_table = Ned.query_region(SkyCoord(ra=row.RAJ2000*u.degree, dec=row.DEJ2000*u.degree, frame='icrs'), radius=(2/3600)*u.deg, equinox='J2000.0')
diameters = Ned.get_table(result_table.to_pandas()['Object Name'].values[0], table='diameters')
tempDF = diameters.to_pandas()
tempMaj_arcsec = np.nanmedian(tempDF.loc[(tempDF['Major Axis Unit'] == 'arcsec') & (tempDF['Major Axis Flag'] == '(a)'), 'Major Axis'])
AxisRatio = np.nanmedian(tempDF.loc[(tempDF['Axis Ratio Flag'] == '(b/a)'), 'Axis Ratio'])
tempMin_arcsec = tempMaj_arcsec*AxisRatio

GLADE_norad.loc[GLADE_norad.index == idx, 'maj'] = tempMaj_arcsec*2./60
GLADE_norad.loc[GLADE_norad.index == idx, 'min'] = tempMin_arcsec*2./60
GLADE_norad.loc[GLADE_norad.index == idx, 'a_b'] = 1/AxisRatio
except:
badRadCount +=1
#GLADE_rad = hosts.dropna(subset=['a_b', 'maj', 'min'])
#GLADE_norad = hosts[~hosts.index.isin(GLADE_rad.index)]

#badRadCount = 0
#for idx, row in GLADE_norad.iterrows():
# try:
# result_table = Ned.query_region(SkyCoord(ra=row.RAJ2000*u.degree, dec=row.DEJ2000*u.degree, frame='icrs'), radius=(2/3600)*u.deg, equinox='J2000.0')
# diameters = Ned.get_table(result_table.to_pandas()['Object Name'].values[0], table='diameters')
# tempDF = diameters.to_pandas()
# tempMaj_arcsec = np.nanmedian(tempDF.loc[(tempDF['Major Axis Unit'] == 'arcsec') & (tempDF['Major Axis Flag'] == '(a)'), 'Major Axis'])
# AxisRatio = np.nanmedian(tempDF.loc[(tempDF['Axis Ratio Flag'] == '(b/a)'), 'Axis Ratio'])
# tempMin_arcsec = tempMaj_arcsec*AxisRatio

# GLADE_norad.loc[GLADE_norad.index == idx, 'maj'] = tempMaj_arcsec*2./60
# GLADE_norad.loc[GLADE_norad.index == idx, 'min'] = tempMin_arcsec*2./60
# GLADE_norad.loc[GLADE_norad.index == idx, 'a_b'] = 1/AxisRatio
# except:
# badRadCount +=1

#recombine
if verbose:
print("No NED radius found for %i GLADE galaxies."%badRadCount, file=f)
#if verbose:
# print("No NED radius found for %i GLADE galaxies."%badRadCount, file=f)

hosts = pd.concat([GLADE_rad, GLADE_norad], ignore_index=True)
#hosts = pd.concat([GLADE_rad, GLADE_norad], ignore_index=True)
#hosts.dropna(subset=['a_b', 'maj', 'min'], inplace=True)

hosts.dropna(subset=['a_b', 'maj', 'min'], inplace=True)
if len(hosts)<1:
noGladeHosts.append(name)
continue
hosts['MajorRad'] = hosts['maj']*60./2 #in arcsec, to radius
hosts['MinorRad'] = hosts['min']*60./2 #in arcsec, to radius
hosts['MajorRad'] = hosts['maj']*60./2 # diameter to radius in arcsec
hosts['MinorRad'] = hosts['min']*60./2 # diameter to radius in arcsec

#get names for the galaxies that match
hosts.rename(columns={'RAJ2000':'raMean','DEJ2000':'decMean'}, inplace=True)
Expand Down Expand Up @@ -516,9 +527,6 @@ def chooseByGladeDLR(path, fn, snDF, verbose=False, todo='r'):
foundHostDF['GLADE_redshift'] = np.nan
foundHostDF['GLADE_redshift_flag'] = ''

#assume standard cosmology
cosmo = FlatLambdaCDM(H0=70, Om0=0.3, Tcmb0=2.725)

for idx, row in foundHostDF.iterrows():
if row['Dist'] == row['Dist']:
dist = Distance(value=row['Dist'], unit=u.Mpc)
Expand Down
8 changes: 7 additions & 1 deletion astro_ghost/ghostHelperFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,8 +693,14 @@ def findNewHosts(transientName, snCoord, snClass, verbose=False, starcut='gentle

#new low-z method (beta) - before we do anything else, find and associate with GLADE
if GLADE:
# snag the GWGC, which we'll use to get radii
stream = importlib_resources.files(__name__).joinpath('gwgc_good.csv')
GWGC = pd.read_csv(stream)
if verbose:
print("Successfully read in GWGC catalog.\n")

fn_glade = "gladeDLR.txt"
foundGladeHosts, noGladeHosts = chooseByGladeDLR(path, fn_glade, snDF, verbose=verbose, todo="r")
foundGladeHosts, noGladeHosts = chooseByGladeDLR(path, fn_glade, snDF, verbose=verbose, todo="r", GWGC=GWGC)

#open transients df and drop the transients already found in GLADE. We'll add these back in at the end
snDF = snDF[snDF['Name'].isin(noGladeHosts)]
Expand Down
Loading

0 comments on commit db1338f

Please sign in to comment.