In [1]:
cd ~/research/TP-AGBcalib/code/TPAGB-calib/


/home/rosenfield/research/TP-AGBcalib/code/TPAGB-calib

In [2]:
import sfh_tests_multi_proc
import ResolvedStellarPops as rsp
import stats
from TPAGBparams import snap_src
import model_plots
import tables
%pylab tk


Warning. Can not find /home/rosenfield/research/TP-AGBcalib/SNAP/models/ast.
Populating the interactive namespace from numpy and matplotlib

In [18]:
# nsfhs dont matter at all here but need to be defined for vsfh...
def full_run():
    targets = ['ddo71', 'hs117', 'kkh37', 'ngc2976-deep', 'scl-de1', 'ddo78']
    targets = ['scl-de1']

    cmd_inputs = ['cmd_input_CAF09_S_NOV13.dat']    
    #cmd_inputs = ['cmd_input_CAF09_S_NOV13.dat',
    #              'cmd_input_CAF09_S_OCT13.dat',
    #              'cmd_input_CAF09_S_NOV13eta0.dat']
    nsfhs = 50
    #outfile_dirs = ['/home/rosenfield/research/TP-AGBcalib/SNAP/models/varysfh/match-hmc/']
    outfile_dirs = ['/home/rosenfield/research/TP-AGBcalib/SNAP/models/varysfh/scl-de1/caf09_s_nov13/mc/']
    extra_str = ''
    return targets, cmd_inputs, nsfhs, outfile_dirs, extra_str
    
def cstar():
    targets = ['ngc2976-deep', 'scl-de1']
    cmd_inputs = ['cmd_input_CAF09_S_NOV13.dat',
                  'cmd_input_CAF09_S_NOV13eta0.dat',
                  'cmd_input_CAF09_S_OCT13.dat']
    nsfhs = 50
    outfile_dirs = ['/home/rosenfield/research/TP-AGBcalib/SNAP/models/cstar_only']
    extra_str = '_cstar'
    return targets, cmd_inputs, nsfhs, outfile_dirs, extra_str

def mstar():
    targets = ['ngc2976-deep', 'scl-de1']
    cmd_inputs = ['cmd_input_CAF09_S_NOV13.dat',
                  'cmd_input_CAF09_S_NOV13eta0.dat',
                  'cmd_input_CAF09_S_OCT13.dat']
    nsfhs = 50
    outfile_dirs = ['/home/rosenfield/research/TP-AGBcalib/SNAP/models/mstar_only']
    extra_str = '_mstar'
    return targets, cmd_inputs, nsfhs, outfile_dirs, extra_str

In [19]:
reload(sfh_tests_multi_proc)
reload(stats)
reload(model_plots)


Out[19]:
<module 'model_plots' from 'model_plots.pyc'>

In [20]:
def lf_figs(targets, cmd_inputs, nsfhs, outfile_dir='default', extra_str='',
            default_kw=None, completeness_correction=False):
    vSFHs, vsfh_kws = sfh_tests_multi_proc.prepare_vsfh_run(targets, cmd_inputs, nsfhs,
                                                            vsfh_kw={'outfile_loc': outfile_dir,
                                                                     'extra_str': extra_str},
                                                            default_kw=default_kw)
    pl = [sfh_tests_multi_proc.Plotting(v) for v in vSFHs]
    if completeness_correction is True:
        extra_str += '_comp'
    _ = [pl[i].compare_to_gal(extra_str=extra_str,
                              completeness_correction=completeness_correction)
         for i in range(len(pl))]
    #plt.close('all')
    return

In [21]:
def lf_figs_all_stages(targets, cmd_inputs, nsfhs, outfile_dir='default', extra_str='', default_kw=None,
                       completeness_correction=False):
    vSFHs, vsfh_kws = sfh_tests_multi_proc.prepare_vsfh_run(targets, cmd_inputs, nsfhs,
                                                            vsfh_kw={'outfile_loc': outfile_dir,
                                                                     'extra_str': extra_str},
                                                            default_kw=default_kw)
    pl = [sfh_tests_multi_proc.Plotting(v) for v in vSFHs]
    _ = [pl[i].compare_to_gal(extra_str=extra_str,
                              completeness_correction=completeness_correction)
         for i in range(len(pl))]

In [22]:
def chi2_stats(targets, cmd_inputs, outfile_dir='default', extra_str=''):
    chi2_files = stats.write_chi2_table(targets, cmd_inputs, outfile_loc=outfile_dir, extra_str=extra_str)
    chi2_dicts = stats.result2dict(chi2_files)
    axs = stats.chi2plot(chi2_dicts, outfile_loc=outfile_dir)
    chi2_files = stats.write_chi2_table(targets, cmd_inputs, outfile_loc=outfile_dir, extra_str=extra_str,
                                        just_gauss=True)
    plt.close('all')
    return

In [23]:
def narratio_table(outfile_dir):
    narratio_files = rsp.fileIO.get_files(outfile_dir, '*narratio*dat')
    stats.narratio_table(narratio_files)
    return

In [24]:
targets, cmd_inputs, nsfhs, outfile_dirs, extra_str = mstar()
default_kw = {'galaxy_input_src': snap_src + '/input/tests/',
              'galaxy_input_search_fmt': '*%s' + '%s.dat' % extra_str}

targets, cmd_inputs, nsfhs, outfile_dirs, extra_str = full_run()
default_kw = None
vsfh_kw = {'extra_str' : extra_str}
completeness_correction = True

In [25]:
for out_dir in outfile_dirs:
    _ = lf_figs(targets, cmd_inputs, nsfhs, outfile_dir=out_dir, extra_str=extra_str,
                default_kw=default_kw, completeness_correction=completeness_correction)
    _ = chi2_stats(targets, cmd_inputs, outfile_dir=out_dir, extra_str=extra_str)
    _ = narratio_table(out_dir)
model_plots.plot_random_sfhs(targets)


---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-25-3c3a0875767c> in <module>()
      2     _ = lf_figs(targets, cmd_inputs, nsfhs, outfile_dir=out_dir, extra_str=extra_str,
      3                 default_kw=default_kw, completeness_correction=completeness_correction)
----> 4     _ = chi2_stats(targets, cmd_inputs, outfile_dir=out_dir, extra_str=extra_str)
      5     _ = narratio_table(out_dir)
      6 model_plots.plot_random_sfhs(targets)

<ipython-input-22-445ee41802a2> in chi2_stats(targets, cmd_inputs, outfile_dir, extra_str)
      2     chi2_files = stats.write_chi2_table(targets, cmd_inputs, outfile_loc=outfile_dir, extra_str=extra_str)
      3     chi2_dicts = stats.result2dict(chi2_files)
----> 4     axs = stats.chi2plot(chi2_dicts, outfile_loc=outfile_dir)
      5     chi2_files = stats.write_chi2_table(targets, cmd_inputs, outfile_loc=outfile_dir, extra_str=extra_str,
      6                                         just_gauss=True)

/home/rosenfield/research/TP-AGBcalib/code/TPAGB-calib/stats.pyc in chi2plot(model_dict, outfile_loc)
    540     fig.subplots_adjust(hspace=0.1)
    541     xlims = ax.get_xlim()
--> 542     off = np.diff(offsets)[0]
    543     ax.set_xlim(xlims[0]-off/2, xlims[1]+off/2)
    544     sym = ['o', 'o', '*']

IndexError: index out of bounds
/home/rosenfield/research/python/ResolvedStellarPops/Galaxies.py:2453: RuntimeWarning: divide by zero encountered in divide
  d = 2. * (m + n * np.log(n / m) - n)
/home/rosenfield/research/python/ResolvedStellarPops/Galaxies.py:2453: RuntimeWarning: invalid value encountered in divide
  d = 2. * (m + n * np.log(n / m) - n)
/home/rosenfield/research/python/ResolvedStellarPops/Galaxies.py:2453: RuntimeWarning: divide by zero encountered in log
  d = 2. * (m + n * np.log(n / m) - n)
/home/rosenfield/research/python/ResolvedStellarPops/Galaxies.py:2453: RuntimeWarning: invalid value encountered in multiply
  d = 2. * (m + n * np.log(n / m) - n)
/home/rosenfield/research/python/ResolvedStellarPops/Galaxies.py:2462: RuntimeWarning: divide by zero encountered in divide
  pct_dif = (m - n) / n
/home/rosenfield/research/python/ResolvedStellarPops/Galaxies.py:2462: RuntimeWarning: invalid value encountered in divide
  pct_dif = (m - n) / n

In [9]:
## don't need to be done for every run... 
#model_plots.compare_mass_loss(masses=[1,2], z=0.001)
#model_plots.agb_lifetimes(['NOV13'], z='all')


Out[9]:
<matplotlib.axes.AxesSubplot at 0x18d8e9d0>

In [14]:
plt.close('all')

In [ ]: