def trilegal_metals(chi2_location='draft_run', band='opt', dry_run=False,
                    model='nov13', model_src='default', old=False, feh=False):
    if chi2_location == 'draft_run':
        chi2_location = snap_src + '/models/varysfh/match-hmc/'

    chi2files = rsp.fileIO.get_files(chi2_location, '*%s_*chi2.dat' % model)
    # I do gaussian chi2 too, not just poisson...
    chi2files = [c for c in chi2files if not 'gauss' in c][::-1]

    # get the tpagb masses
    (mhs, norm) = zip(*[tpagb_masses(c, band=band, dry_run=dry_run,
                                        model_src=model_src, mass=False,
                                        old=old) for c in chi2files])
    ts = [os.path.split(c)[1].split('_')[3] for c in chi2files]
    targets = galaxy_tests.ancients()
    tinds = [ts.index(t.lower()) for t in targets]
    targets = np.array(ts)[tinds]
    from ResolvedStellarPops.convertz import convertz
    if feh is True:
        ind = 4
    else:
        ind = 1
    zs = np.array([convertz(mh=i)[ind] for i in mhs])
    for i, target in enumerate(targets):
        print '%.4f %.4f %.4f %s ' % (np.min(zs[i]), np.median(zs[i]),
                                      np.max(zs[i]), target)
Beispiel #2
0
    def _make_trilegal_sfh(self, random_sfr=True, random_z=False,
                          zdisp=True, random_mass=True, outfile='default'):

        if outfile == 'default':
            outfile = os.path.join(self.base,
                                   self.name.replace('dat', '.sfr'))

        if random_z is False:
            feh = self.data.feh
        else:
            feh = self.random_draw_within_uncertainty('feh')

        z = convertz.convertz(feh=feh)[1]

        # this could be done better...
        # even dispersions
        zmin = convertz.convertz(feh=self.data.feh_errm)[1]
        zmax = convertz.convertz(feh=self.data.feh_errp)[1]
        zdisp = [np.mean([(zmax[i] - z[i]),
                          (z[i] - zmin[i])]) for i in range(len(z))]
        
        half_zbin = np.diff(z)/2.
        half_zbin = np.append(half_zbin, half_zbin[-1])
        z1 = z - half_zbin 
        z2 = z + half_zbin

        age1a = 10 ** (self.data.lagei)
        age1p = 1.0 * 10 ** (self.data.lagei + 0.0001)
        age2a = 1.0 * 10 ** self.data.lagef
        age2p = 1.0 * 10 ** (self.data.lagef + 0.0001)

        if random_sfr is False:
            sfr = self.data.sfr
        else:
            sfr = self.random_draw_within_uncertainty('sfr')

        if zdisp is True:
            zdisp = z * np.median(zdisp[np.nonzero(zdisp)])
            #zdisp = self.data.mh_disp
            fmt = '%.4e %.3e %.4f %.4f \n'
        else:
            zdisp = [''] * len(z)
            fmt = '%.4e %.3e %.4f %s\n'


        fmt = '%.4e %.3f %.4f %.4f\n'
        with open(outfile, 'w') as out:
            for i in range(len(sfr)):        
                out.write(fmt % (age1a[i], 0.0, z1[i], zdisp[i]))
                out.write(fmt % (age1p[i], sfr[i], z1[i], zdisp[i]))
                out.write(fmt % (age2a[i], sfr[i], z2[i], zdisp[i]))
                out.write(fmt % (age2p[i], 0.0, z2[i], zdisp[i]))
                out.write(fmt % (age1a[i], 0.0, z2[i], zdisp[i]))
                out.write(fmt % (age1p[i], sfr[i], z2[i], zdisp[i]))
                out.write(fmt % (age2a[i], sfr[i], z1[i], zdisp[i]))
                out.write(fmt % (age2p[i], 0.0, z1[i], zdisp[i]))
    
        mass = self.random_draw_within_uncertainty('mass')

        object_mass = scipy.integrate.simps(mass, self.data.lagei)
        return outfile, object_mass