This notebook builds from "DECALS low-SB_completeness AnaK overlap"
In [1]:
from __future__ import print_function, division
In [2]:
# This changes the current directory to the base saga directory - make sure to run this first!
# This is necessary to be able to import the py files and use the right directories,
# while keeping all the notebooks in their own directory.
import os
import sys
from time import time
if 'saga_base_dir' not in locals():
saga_base_dir = os.path.abspath('..')
if saga_base_dir not in sys.path:
os.chdir(saga_base_dir)
In [3]:
import hosts
import targeting
import numpy as np
from scipy import interpolate
from astropy import units as u
from astropy.coordinates import SkyCoord
from astropy import table
from astropy.table import Table
from astropy.io import fits
from astropy.utils.console import ProgressBar
from collections import Counter
In [4]:
%matplotlib inline
from matplotlib import style, pyplot as plt
plt.style.use('seaborn-deep')
plt.rcParams['image.cmap'] = 'viridis'
plt.rcParams['image.origin'] = 'lower'
plt.rcParams['figure.figsize'] = (14, 8)
plt.rcParams['axes.titlesize'] = plt.rcParams['axes.labelsize'] = 16
plt.rcParams['xtick.labelsize'] = plt.rcParams['ytick.labelsize'] = 14
In [5]:
from IPython import display
In [6]:
from decals import make_cutout_comparison_table, fluxivar_to_mag_magerr, compute_sb
In [7]:
hsts = hosts.get_saga_hosts_from_google(clientsecretjsonorfn='client_secrets.json', useobservingsummary=False)
anak = [h for h in hsts if h.name=='AnaK']
assert len(anak)==1
anak = anak[0]
In [8]:
bricknames = []
with open('decals_dr3/anakbricks') as f:
for l in f:
l = l.strip()
if l != '':
bricknames.append(l)
print(bricknames)
In [9]:
base_url = 'http://portal.nersc.gov/project/cosmo/data/legacysurvey/dr3/tractor/{first3}/tractor-{brickname}.fits'
for brickname in ProgressBar(bricknames, ipython_widget=True):
url = base_url.format(brickname=brickname, first3=brickname[:3])
target = os.path.join('decals_dr3/catalogs/', url.split('/')[-1])
if not os.path.isfile(target):
!wget $url -O $target
else:
print(target, 'already exists, not downloading')
In [10]:
bricks = Table.read('decals_dr3/survey-bricks.fits.gz')
bricksdr3 = Table.read('decals_dr3/survey-bricks-dr3.fits.gz')
In [11]:
catalog_fns = ['decals_dr3/catalogs/tractor-{}.fits'.format(bnm) for bnm in bricknames]
decals_catalogs = [Table.read(fn) for fn in catalog_fns]
dcatall = table.vstack(decals_catalogs, metadata_conflicts='silent')
In [12]:
sdss_catalog = Table.read('catalogs/base_sql_nsa{}.fits.gz'.format(anak.nsaid))
In [13]:
#cut out the non-overlap region
dsc = SkyCoord(dcatall['ra'], dcatall['dec'], unit=u.deg)
dcutall = dcatall[dsc.separation(anak.coords) < 1*u.deg]
In [14]:
ap_sizes = [0.5,0.75,1.0,1.5,2.0,3.5,5.0,7.0] * u.arcsec
In [15]:
for dcat in [dcutall]:
for magnm, idx in zip('grz', [1, 2, 4]):
mag, mag_err = fluxivar_to_mag_magerr(dcat['decam_flux'][:, 1], dcat['decam_flux_ivar'][:, idx])
dcat[magnm] = mag
dcat[magnm + '_err'] = mag_err
dcat['sb_r_0.5'] = compute_sb(0.5*u.arcsec, dcat['decam_apflux'][:, 2, :])
dcat['sb_r_0.75'] = compute_sb(0.75*u.arcsec, dcat['decam_apflux'][:, 2, :])
dcat['sb_r_1'] = compute_sb(1.0*u.arcsec, dcat['decam_apflux'][:, 2, :])
dcat['sb_r_2'] = compute_sb(2.0*u.arcsec, dcat['decam_apflux'][:, 2, :])
In [16]:
MASK_BITS = {0: 'detector bad pixel/no data',
1: 'saturated',
2: 'interpolated',
4: 'single exposure cosmic ray',
6: 'bleed trail',
7: 'multi-exposure transient',
8: 'edge',
9: 'edge2',
10: 'longthin'}
def maskarr_to_boolarrs(arr):
boolarrs = {}
for bnum, name in MASK_BITS.items():
boolarrs[name] = (arr & 10**bnum)!=0
return boolarrs
In [17]:
anymaskr = maskarr_to_boolarrs(dcutall['decam_anymask'][:, 2])
allmaskr = maskarr_to_boolarrs(dcutall['decam_allmask'][:, 2])
In [18]:
nper = 10
In [19]:
for name, barr in anymaskr.items():
print(name)
idxs = np.random.permutation(np.sum(barr))[:nper]
display.display(make_cutout_comparison_table(dcutall[barr][idxs], doprint=False))
In [20]:
for name, barr in allmaskr.items():
print(name)
idxs = np.random.permutation(np.sum(barr))[:nper]
display.display(make_cutout_comparison_table(dcutall[barr][idxs], doprint=False))