Parameter file attached. This is for a WFPC2 run, which is the filters look like 'f606w' as opposed to 'WFC606W' for ACS.
I'll also include our standard background files, so please make sure to have the last two lines included.
I called the files 'phot.dat', 'fake.dat', and 'param.sfh' and then put them each into their own directory for each field, e.g., /ugc4301-1/phot.dat, etc.
In [1]:
import ResolvedStellarPops as rsp
import numpy as np
import os
%pylab inline
In [20]:
def prep_match(photfile, fakefile, fakename='fake.dat', extra_kw=None):
'''
Make the three input files for match according to Dan's naming scheme.
phot.dat is the photometry input file
fake.dat is the artificial stars file, already in the directory.
param.sfh is the match parameter file.
'''
here = os.getcwd()
print here
gal_kw = {'filetype': 'fitstable', 'hla': True, 'angst':True, 'band': 'opt'}
extra_kw = extra_kw or {}
# load the galaxy
if '7793' in photfile:
# NGC7793 is not in the angst paper, the SNAP paper has the dmod and Av listed, cmd limits are
# just taken at the extreme values.
gal_kw['angst'] = False
gal = rsp.Galaxies.galaxy(photfile, **gal_kw)
gal.dmod = 27.96
gal.Av = 0.060
gal.comp50mag1 = gal.mag1.max()
gal.comp50mag2 = gal.mag2.max()
else:
gal = rsp.Galaxies.galaxy(photfile, **gal_kw)
assert os.path.split(photfile)[1].split('_')[5].split('-')[0] == gal.filter1.lower()
assert os.path.split(photfile)[1].split('_')[5].split('-')[1] == gal.filter2.lower()
if 'hs117' in photfile:
# hs117 has some weird stars around it.
extra_kw = dict({'V-Imin': -.5, 'V-Imax': 2., 'Vmin': 23., 'Imin': 22.}.items() +
extra_kw.items())
if 'scl' in photfile:
# hs117 has some weird stars around it.
extra_kw = dict({'Vmax': 28.9, 'Imax': 28.05}.items() +
extra_kw.items())
# make a directory with the galaxy name
dirname = gal.target.lower() + '-' + gal.filter1.lower()
if not os.path.isdir(dirname):
os.mkdir(dirname)
# place input files in galaxy directory
os.system('cp %s %s/%s' % (os.path.abspath(fakefile), dirname, fakename))
os.chdir(dirname)
# make the input files
rsp.match_utils.make_phot(gal)
param = rsp.match_utils.make_match_param(gal, more_gal_kw=extra_kw)
print dirname
os.chdir(here)
return param
In [3]:
def make_all_matchfiles():
# get all the galaxies and fake files in the directory and prepare them for match
os.chdir('~/research/TP-AGBcalib/SNAP/data/angst_no_trim/')
thisdir = os.listdir('.')
phots = [l for l in thisdir if l.endswith('gst.fits')]
fakes = [l for l in thisdir if l.endswith('fake')]
for p in phots:
pidtarget = '-'.join(p.split('_')[4].split('-')[1:]).upper()
f, = [a for a in fakes if pidtarget in a]
prep_match(p, f, extra_kw=extra_kw)
In [10]:
def match_phot_trgb_exclude_gates():
'''
uses a subset of ancient sf galaxies only.
'''
fits_src='/home/phil/research/TP-AGBcalib/SNAP/data/angst_no_trim'
fits = rsp.fileIO.get_files(fits_src, '*fits')
fakes = rsp.fileIO.get_files(fits_src, '*fake')
ancient_list = ['ddo71', 'kkh37', 'ngc2976', 'ngc404',
'kdg73', 'hs117', 'ddo78', 'scl-de1']
afits = np.concatenate([[f for a in ancient_list if a in f] for f in fits])
afakes = np.concatenate([[f for a in ancient_list if a.upper() in f] for f in fakes])
exclude_gates, axs = rsp.match_utils.make_exclude_gates(afits, trgb=True, make_plot=True)
for i, p in enumerate(afits):
pidtarget = '-'.join(os.path.split(p)[1].split('_')[4].split('-')[1:]).upper()
f, = [a for a in afakes if pidtarget in a]
extra_kw = {'nexclude_gates': 1, 'exclude_gates': exclude_gates[p]}
#print p, f, extra_kw
param = prep_match(p, f, extra_kw=extra_kw).__dict__
[axs[i].vlines(x, *axs[i].get_ylim(), color='black', lw=2) for x in [param['V-Imin'], param['V-Imax']]]
[axs[i].hlines(y, *axs[i].get_xlim(), color='black', lw=2) for y in [param['Vmax'], param['Vmin']]]
return axs
In [5]:
cd ~/research/TP-AGBcalib/SNAP/data/angst_no_trim/
In [14]:
reload(rsp.match_utils)
Out[14]:
In [21]:
axs = match_phot_trgb_exclude_gates()
In [10]:
import matplotlib.pyplot as plt
In [11]:
plt.ion()
In [12]:
plt.show()
In [259]:
ast = rsp.Galaxies.artificial_star_tests(fake)
In [346]:
threshold = 99.
rec1, = np.nonzero(ast.mag1diff < threshold)
rec2, = np.nonzero(ast.mag2diff < threshold)
rec = list(set(rec1) & set(rec2))
ast.bin_asts(binsize=0.5)
In [287]:
import scipy.interpolate
In [347]:
qhist1 = np.array(np.histogram(ast.mag1, bins=ast.ast_bins)[0], dtype=float)
rhist1 = np.array(np.histogram(ast.mag1[rec1], bins=ast.ast_bins)[0], dtype=float)
qhist2 = np.array(np.histogram(ast.mag2, bins=ast.ast_bins)[0], dtype=float)
rhist2 = np.array(np.histogram(ast.mag2[rec2], bins=ast.ast_bins)[0], dtype=float)
qfunc1 = scipy.interpolate.interp1d(ast.ast_bins[1:], qhist1, bounds_error=False)
rfunc1 = scipy.interpolate.interp1d(ast.ast_bins[1:], rhist1, bounds_error=False)
qfunc2 = scipy.interpolate.interp1d(ast.ast_bins[1:], qhist2, bounds_error=False)
rfunc2 = scipy.interpolate.interp1d(ast.ast_bins[1:], rhist2, bounds_error=False)
mag_arr = np.arange(ast.ast_bins[0], ast.ast_bins[-1], 1e-4)
comp1 = rfunc1(mag_arr)/qfunc1(mag_arr)
comp2 = rfunc2(mag_arr)/qfunc2(mag_arr)
In [3]:
for q,r,a in zip(qhist1, rhist1, ast.ast_bins[1:]):
print q, r, a
In [348]:
fig, ax = plt.subplots()
ax.plot(mag_arr, comp1, linestyle='steps')
ax.plot(mag_arr, comp2, linestyle='steps')
Out[348]:
In [328]:
mag_thresh = 20
dims, = np.nonzero(mag_arr > mag_thresh)
ic1 = np.argmin(0.5-comp1[dims])
ic2 = np.argmin(0.5-comp2[dims])
mag_arr[dims][ic1], mag_arr[dims][ic2]
Out[328]:
In [337]:
fig, ax = gal.plot_cmd(gal.color, gal.mag2, scatter_off=True)
ax.plot(ast.mag1[rec]-ast.mag2[rec], ast.mag2[rec], '.')
Out[337]: