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


Populating the interactive namespace from numpy and matplotlib

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
Now checking a fake file and maybe making a completeness plot.

In [5]:
cd ~/research/TP-AGBcalib/SNAP/data/angst_no_trim/


/home/phil/research/TP-AGBcalib/SNAP/data/angst_no_trim

In [14]:
reload(rsp.match_utils)


Out[14]:
<module 'ResolvedStellarPops.match_utils' from '/home/phil/research/python/ResolvedStellarPops/match_utils.py'>

In [21]:
axs = match_phot_trgb_exclude_gates()


wrote exclude_gates_8.png
/home/phil/research/TP-AGBcalib/SNAP/data/angst_no_trim/hlsp_angst_hst_acs-wfc_10915-ngc2976-deep_f606w-f814w_v1_gst.fits /home/phil/research/TP-AGBcalib/SNAP/data/angst_no_trim/10915_NGC2976-DEEP_F475W_F606W_F814W_gst.matchfake {'nexclude_gates': 1, 'exclude_gates': ' -0.40 23.15 2.90 26.65 2.90 21.10 -0.40 21.10'}
/home/phil/research/TP-AGBcalib/code/TPAGB-calib/notebooks
ngc2976-deep-f606w
/home/phil/research/TP-AGBcalib/SNAP/data/angst_no_trim/hlsp_angst_hst_acs-wfc_9884-ddo71_f606w-f814w_v1_gst.fits /home/phil/research/TP-AGBcalib/SNAP/data/angst_no_trim/9884_DDO71_F606W_F814W_gst.fake.fits.matchfake {'nexclude_gates': 1, 'exclude_gates': ' -0.40 23.10 2.90 26.60 2.90 21.10 -0.40 21.10'}
/home/phil/research/TP-AGBcalib/code/TPAGB-calib/notebooks
ddo71-f606w
/home/phil/research/TP-AGBcalib/SNAP/data/angst_no_trim/hlsp_angst_hst_acs-wfc_10915-ddo78_f475w-f814w_v1_gst.fits /home/phil/research/TP-AGBcalib/SNAP/data/angst_no_trim/10915_DDO78_F475W_F814W_gst.fake.fits.matchfake {'nexclude_gates': 1, 'exclude_gates': ' -0.40 23.20 3.90 27.70 3.90 21.45 -0.40 21.45'}
/home/phil/research/TP-AGBcalib/code/TPAGB-calib/notebooks
ddo78-f475w
/home/phil/research/TP-AGBcalib/SNAP/data/angst_no_trim/hlsp_angst_hst_acs-wfc_10915-kkh37_f475w-f814w_v1_gst.fits /home/phil/research/TP-AGBcalib/SNAP/data/angst_no_trim/10915_KKH37_F475W_F814W_gst.matchfake {'nexclude_gates': 1, 'exclude_gates': ' -0.40 22.95 3.90 27.45 3.90 21.25 -0.40 21.25'}
/home/phil/research/TP-AGBcalib/code/TPAGB-calib/notebooks
kkh37-f475w
/home/phil/research/TP-AGBcalib/SNAP/data/angst_no_trim/hlsp_angst_hst_acs-wfc_9771-hs117_f606w-f814w_v1_gst.fits /home/phil/research/TP-AGBcalib/SNAP/data/angst_no_trim/9771_HS117_F606W_F814W_gst.fake.fits.matchfake {'nexclude_gates': 1, 'exclude_gates': ' -0.40 23.25 1.90 25.75 1.90 23.10 -0.40 23.10'}
/home/phil/research/TP-AGBcalib/code/TPAGB-calib/notebooks
hs117-f606w
/home/phil/research/TP-AGBcalib/SNAP/data/angst_no_trim/hlsp_angst_hst_wfpc2_10915-ngc404-deep_f606w-f814w_v1_gst.fits /home/phil/research/TP-AGBcalib/SNAP/data/angst_no_trim/10915_NGC404-DEEP_F606W_F814W_gst.matchfake {'nexclude_gates': 1, 'exclude_gates': ' -0.40 22.85 2.90 26.35 2.90 20.90 -0.40 20.90'}
/home/phil/research/TP-AGBcalib/code/TPAGB-calib/notebooks
ngc404-deep-f606w
/home/phil/research/TP-AGBcalib/SNAP/data/angst_no_trim/hlsp_angst_hst_acs-wfc_10503-scl-de1_f606w-f814w_v1_gst.fits /home/phil/research/TP-AGBcalib/SNAP/data/angst_no_trim/10503_SCL-DE1_F606W_F814W_gst.matchfake {'nexclude_gates': 1, 'exclude_gates': ' -0.40 23.50 2.90 27.00 2.90 19.70 -0.40 19.70'}
/home/phil/research/TP-AGBcalib/code/TPAGB-calib/notebooks
scl-de1-f606w
/home/phil/research/TP-AGBcalib/SNAP/data/angst_no_trim/hlsp_angst_hst_acs-wfc_10915-kdg73_f475w-f814w_v1_gst.fits /home/phil/research/TP-AGBcalib/SNAP/data/angst_no_trim/10915_KDG73_F475W_F814W_gst.fake.fits.matchfake {'nexclude_gates': 1, 'exclude_gates': ' -0.40 23.40 3.90 27.90 3.90 21.90 -0.40 21.90'}
/home/phil/research/TP-AGBcalib/code/TPAGB-calib/notebooks
kdg73-f475w

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


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-3-c23d21eb5f84> in <module>()
----> 1 thisdir = os.listdir('.')
      2 phots = [l for l in thisdir if l.endswith('gst.fits')]

NameError: name 'os' is not defined

In [348]:
fig, ax = plt.subplots()
ax.plot(mag_arr, comp1, linestyle='steps')
ax.plot(mag_arr, comp2, linestyle='steps')


Out[348]:
[<matplotlib.lines.Line2D at 0x116a5bf50>]

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]:
(29.193099999969704, 28.593099999971102)

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]:
[<matplotlib.lines.Line2D at 0x10fabfd50>]