Exemplo n.º 1
0
def cmd():
    synFile = 'syn_nir_d389.0_a600.dat'
    results = synthetic.load_nearIR_dict(synFile)

    # Lets trim down to the extinction value of interest.
    AKs_AV = 0.062  # from Nishiyama+ 2008... GC, but good enough?
    AKs = AV * AKs_AV

    idx = np.argmin(np.abs(results['AKs'] - AKs))

    numAKs = len(results['AKs'])
    numTeff = len(results['Teff'])

    for key in results.keys():
        if ((len(results[key].shape) == 2)
                and (results[key].shape[1] == numAKs)):

            results[key] = results[key][:, idx]
        else:
            if len(results[key]) == numAKs:
                results[key] = results[key][idx]

    HKp = results['H'] - results['Kp']
    KpLp = results['Kp'] - results['Lp']

    # Fetch a few points at specific masses
    massPoints = np.array([30, 10, 5, 2, 1, 0.5])
    massIndices = np.zeros(len(massPoints))
    massLabels = []
    for mm in range(len(massPoints)):
        mdx = np.argmin(np.abs(results['mass'] - massPoints[mm]))

        massIndices[mm] = mdx
        massPoints[mm] = results['mass'][mdx]
        massLabels.append('{0:4.1f} Msun'.format(massPoints[mm]))

    # Plots
    py.clf()
    py.plot(HKp, results['H'])
    rng = py.axis()
    py.xlim(0, 2)
    py.ylim(rng[3], rng[2])
    py.xlabel('H - Kp')
    py.ylabel('H')
    py.title('Orion BN/KL Region')
    for mm, mmLab in zip(massIndices, massLabels):
        py.plot(HKp[mm], results['H'][mm], 'kx')
        py.text(HKp[mm], results['H'][mm], mmLab)
    py.savefig('orion_cmd_hkp_h.png')

    py.clf()
    py.plot(HKp, results['Kp'])
    rng = py.axis()
    py.xlim(0, 2)
    py.ylim(rng[3], rng[2])
    py.xlabel('H - Kp')
    py.ylabel('Kp')
    py.title('Orion BN/KL Region')
    for mm, mmLab in zip(massIndices, massLabels):
        py.plot(HKp[mm], results['Kp'][mm], 'kx')
        py.text(HKp[mm], results['Kp'][mm], mmLab)
    py.savefig('orion_cmd_hkp_kp.png')

    py.clf()
    py.plot(KpLp, results['Kp'])
    rng = py.axis()
    py.xlim(0, 2)
    py.ylim(rng[3], rng[2])
    py.xlabel('Kp - Lp')
    py.ylabel('Kp')
    py.title('Orion BN/KL Region')
    for mm, mmLab in zip(massIndices, massLabels):
        py.plot(KpLp[mm], results['Kp'][mm], 'kx')
        py.text(KpLp[mm], results['Kp'][mm], mmLab)
    py.savefig('orion_cmd_kplp_kp.png')

    py.clf()
    py.semilogx(results['Teff'], results['logL'])
    rng = py.axis()
    py.xlim(rng[1], rng[0])
    py.xlabel('Teff')
    py.ylabel('log(L)')
    py.title('Orion BN/KL Region')
    for mm, mmLab in zip(massIndices, massLabels):
        py.plot(results['Teff'][mm], results['logL'][mm], 'kx')
        py.text(results['Teff'][mm], results['logL'][mm], mmLab)
    py.savefig('orion_hr.png')

    # Print to a text file for Breann
    _out = open('orion_model_isochrone.dat', 'w')

    fmt = '#{0:>9s}  {1:>10s}  {2:>10s}  {3:>10s}  {4:>10s} {5:>10s} {6:>10s} {7:>10s}\n'
    _out.write('# AKs = {0:.2f}   age = 1 Myr   d = 389 pc\n'.format(AKs))
    _out.write(fmt.format('Teff', 'mass', 'logL', 'logg', 'J', 'H', 'Kp',
                          'Lp'))
    for ii in range(len(results['Teff'])):
        fmt1 = '{0:10.1f}  {1:10.3f}  {2:10.4f}  {3:10.4f}  '
        fmt2 = '{0:10.2f} {1:10.2f} {2:10.2f} {3:10.2f}\n'
        _out.write(
            fmt1.format(results['Teff'][ii], results['mass'][ii],
                        results['logL'][ii], results['logg'][ii]))
        _out.write(
            fmt2.format(results['J'][ii], results['H'][ii], results['Kp'][ii],
                        results['Lp'][ii]))
def plot_cluster_isochrones(redo_iso=False):
    """
    Plot isochrones and mass-luminosity functions for M17, Wd 2, Wd 1, and RSGC 1.
    """
    # Cluster Info
    name = ['M17', 'Wd 2', 'Wd 1', 'RSGC 1', 'RSGC 2']
    dist = np.array([2100, 4160, 3600, 6000, 6000])
    age = np.array([1., 2., 5., 12., 17.]) * 1.0e6
    AV = np.array([5., 6.5, 10., 23., 10.])

    # Derived properties
    logage = np.log10(age)
    AKs = AV / 10.0

    iso_all = []

    # Loop through the clusters and make the isochrones.
    for ii in range(len(name)):
        pickleFile = 'syn_nir_d' + str(dist[ii]).zfill(5) + '_a' \
            + str(int(round(logage[ii]*100))).zfill(3) + '.dat'

        if (not os.path.exists(pickleFile)) or (redo_iso == True):
                AKsGrid = np.array([AKs[ii]])
                syn.nearIR(dist[ii], logage[ii], AKsGrid=AKsGrid)
                
        iso_all.append( syn.load_nearIR_dict(pickleFile) )


    ##########
    # Plot CMDs
    ##########
    py.figure(1)
    py.clf()
    py.subplots_adjust(left=0.15)
    colors = ['green', 'cyan', 'blue', 'red', 'purple']
    for ii in range(len(iso_all)):
        iso = iso_all[ii]
        
        py.plot(iso['J'] - iso['K'], iso['K'], label=name[ii],
                linewidth=2, color=colors[ii])

        idx1 = np.argmin( np.abs(iso['mass'] - 1.0) )
        py.plot(iso['J'][idx1] - iso['K'][idx1], iso['K'][idx1], 'ks', 
                color=colors[ii], mew=0, ms=8)

    py.gca().invert_yaxis()
    py.xlabel("J - K color")
    py.ylabel("K magnitude")
    py.text(iso['J'][idx1] - iso['K'][idx1], iso['K'][idx1],
            r'1 M$_\odot$', color=colors[ii],
        horizontalalignment='right', verticalalignment='top')
    py.legend(loc="lower left")
    py.savefig('clusters_cmd_jk.png')

    ##########
    # Plot mass-luminosity relations for each of the filters.
    ##########
    py.figure(2, figsize=(12,4))
    py.clf()
    py.subplots_adjust(left=0.06, bottom=0.15, wspace=0.22, right=0.97)

    py.subplot(1, 3, 1)
    for ii in range(len(iso_all)):
        iso = iso_all[ii]
        py.plot(iso['mass'], iso['J'], linewidth=2,
                color=colors[ii], label=name[ii])
    py.xlabel(r'Stellar Mass (M$_\dot$)')
    py.ylabel('J magnitude')
    py.xlim(0, 20)
    py.ylim(26, 9)


    py.subplot(1, 3, 2)
    for ii in range(len(iso_all)):
        iso = iso_all[ii]
        py.plot(iso['mass'], iso['H'], linewidth=2,
                color=colors[ii], label=name[ii])
    py.legend(mode="expand", bbox_to_anchor=(-0.5, 0.99, 2.0, 0.08),
              loc=3, ncol=4, frameon=False)
    py.xlabel(r'Stellar Mass (M$_\dot$)')
    py.ylabel('H magnitude')
    py.xlim(0, 20)
    py.ylim(26, 9)

    py.subplot(1, 3, 3)
    for ii in range(len(iso_all)):
        iso = iso_all[ii]
        py.plot(iso['mass'], iso['K'], linewidth=2,
                color=colors[ii], label=name[ii])
    py.xlabel(r'Stellar Mass (M$_\dot$)')
    py.ylabel('K magnitude')
    py.xlim(0, 20)
    py.ylim(26, 9)

    py.savefig('clusters_mass_luminosity_jhk.png')


    ##########
    # Print out 0.1 Msun, 1 Msun, 10 Msun
    # photometry table.
    ##########

    for ii in range(len(iso_all)):
        iso = iso_all[ii]

        print('')
        print('Cluster: ' + name[ii])
        print('')

        hdr = '{0:6s} {1:6s} {2:6s} {3:6s}'
        dat = '{0:6.1f} {1:6.2f} {2:6.2f} {3:6.2f}'
        print(hdr.format('  Mass', '   J', '   H', '   K'))
        print(hdr.format('  ----', '  ---', '  ---', '  ---'))

        idx01 = np.argmin( np.abs(iso['mass'] - 0.1) )
        print(dat.format(iso['mass'][idx01], iso['J'][idx01][0],
                         iso['H'][idx01][0], iso['K'][idx01][0]))

        idx1 = np.argmin( np.abs(iso['mass'] - 1.0) )
        print(dat.format(iso['mass'][idx1], iso['J'][idx1][0],
                         iso['H'][idx1][0], iso['K'][idx1][0]))

        idx10 = np.argmin( np.abs(iso['mass'] - 10.0) )
        print(dat.format(iso['mass'][idx10], iso['J'][idx10][0],
                         iso['H'][idx10][0], iso['K'][idx10][0]))
Exemplo n.º 3
0
def cmd():
    synFile = 'syn_nir_d389.0_a600.dat'
    results = synthetic.load_nearIR_dict(synFile)

    # Lets trim down to the extinction value of interest.
    AKs_AV = 0.062 # from Nishiyama+ 2008... GC, but good enough?
    AKs = AV * AKs_AV

    idx = np.argmin(np.abs(results['AKs'] - AKs))

    numAKs = len(results['AKs'])
    numTeff = len(results['Teff'])

    for key in results.keys():
        if ((len(results[key].shape) == 2) and 
            (results[key].shape[1] == numAKs)):

            results[key] = results[key][:,idx]
        else:
            if len(results[key]) == numAKs:
                results[key] = results[key][idx]

    HKp = results['H'] - results['Kp']
    KpLp = results['Kp'] - results['Lp']

    # Fetch a few points at specific masses
    massPoints = np.array([30, 10, 5, 2, 1, 0.5])
    massIndices = np.zeros(len(massPoints))
    massLabels = []
    for mm in range(len(massPoints)):
        mdx = np.argmin(np.abs(results['mass'] - massPoints[mm]))

        massIndices[mm] = mdx
        massPoints[mm] = results['mass'][mdx]
        massLabels.append('{0:4.1f} Msun'.format(massPoints[mm]))
        

    # Plots
    py.clf()
    py.plot(HKp, results['H'])
    rng = py.axis()
    py.xlim(0, 2)
    py.ylim(rng[3], rng[2])
    py.xlabel('H - Kp')
    py.ylabel('H')
    py.title('Orion BN/KL Region')
    for mm, mmLab in zip(massIndices, massLabels):
        py.plot(HKp[mm], results['H'][mm], 'kx')
        py.text(HKp[mm], results['H'][mm], mmLab)
    py.savefig('orion_cmd_hkp_h.png')

    py.clf()
    py.plot(HKp, results['Kp'])
    rng = py.axis()
    py.xlim(0, 2)
    py.ylim(rng[3], rng[2])
    py.xlabel('H - Kp')
    py.ylabel('Kp')
    py.title('Orion BN/KL Region')
    for mm, mmLab in zip(massIndices, massLabels):
        py.plot(HKp[mm], results['Kp'][mm], 'kx')
        py.text(HKp[mm], results['Kp'][mm], mmLab)
    py.savefig('orion_cmd_hkp_kp.png')

    py.clf()
    py.plot(KpLp, results['Kp'])
    rng = py.axis()
    py.xlim(0, 2)
    py.ylim(rng[3], rng[2])
    py.xlabel('Kp - Lp')
    py.ylabel('Kp')
    py.title('Orion BN/KL Region')
    for mm, mmLab in zip(massIndices, massLabels):
        py.plot(KpLp[mm], results['Kp'][mm], 'kx')
        py.text(KpLp[mm], results['Kp'][mm], mmLab)
    py.savefig('orion_cmd_kplp_kp.png')

    py.clf()
    py.semilogx(results['Teff'], results['logL'])
    rng = py.axis()
    py.xlim(rng[1], rng[0])
    py.xlabel('Teff')
    py.ylabel('log(L)')
    py.title('Orion BN/KL Region')
    for mm, mmLab in zip(massIndices, massLabels):
        py.plot(results['Teff'][mm], results['logL'][mm], 'kx')
        py.text(results['Teff'][mm], results['logL'][mm], mmLab)
    py.savefig('orion_hr.png')
    
    
    # Print to a text file for Breann
    _out = open('orion_model_isochrone.dat', 'w')
    
    fmt = '#{0:>9s}  {1:>10s}  {2:>10s}  {3:>10s}  {4:>10s} {5:>10s} {6:>10s} {7:>10s}\n'
    _out.write('# AKs = {0:.2f}   age = 1 Myr   d = 389 pc\n'.format(AKs))
    _out.write(fmt.format('Teff', 'mass', 'logL', 'logg',
                          'J', 'H', 'Kp', 'Lp'))
    for ii in range(len(results['Teff'])):
        fmt1 = '{0:10.1f}  {1:10.3f}  {2:10.4f}  {3:10.4f}  '
        fmt2 = '{0:10.2f} {1:10.2f} {2:10.2f} {3:10.2f}\n'
        _out.write(fmt1.format(results['Teff'][ii], results['mass'][ii],
                               results['logL'][ii], results['logg'][ii]))
        _out.write(fmt2.format(results['J'][ii], results['H'][ii],
                               results['Kp'][ii], results['Lp'][ii]))