예제 #1
0
def test_metallicity():
    """
    Test isochrone generation at different metallicities
    """
    # Define isochrone parameters
    logAge = np.log10(5 * 10**6.)
    AKs = 0.8
    dist = 4000
    evo_model = evolution.MISTv1()
    atm_func = atmospheres.get_phoenixv16_atmosphere
    red_law = reddening.RedLawHosek18b()
    filt_list = ['wfc3,ir,f127m', 'wfc3,ir,f139m', 'wfc3,ir,f153m']

    # Start with a solar metallicity isochrone
    metallicity = 0.0

    # Make Isochrone object, with high mass_sampling to decrease compute time
    my_iso = synthetic.IsochronePhot(logAge,
                                     AKs,
                                     dist,
                                     metallicity=metallicity,
                                     evo_model=evo_model,
                                     atm_func=atm_func,
                                     red_law=red_law,
                                     filters=filt_list,
                                     mass_sampling=10)

    # Test isochrone properties
    assert my_iso.points.meta['METAL_IN'] == 0.0
    assert os.path.exists('iso_6.70_0.80_04000_p00.fits')

    # Now for non-solar metallicity
    metallicity = -1.5

    # Make Isochrone object, with high mass_sampling to decrease compute time
    my_iso = synthetic.IsochronePhot(logAge,
                                     AKs,
                                     dist,
                                     metallicity=metallicity,
                                     evo_model=evo_model,
                                     atm_func=atm_func,
                                     red_law=red_law,
                                     filters=filt_list,
                                     mass_sampling=10)

    metal_act = np.log10(0.00047 / 0.0142)  # For Mist isochrones

    # Test isochrone properties
    assert my_iso.points.meta['METAL_IN'] == -1.5
    assert my_iso.points.meta['METAL_ACT'] == metal_act
    assert os.path.exists('iso_6.70_0.80_04000_m15.fits')

    return
예제 #2
0
import numpy as np
import pandas as pd
from astropy.io import ascii
from astropy.io import fits
import matplotlib.pyplot as plt
from popstar import synthetic, evolution, atmospheres, reddening, ifmr
from popstar.imf import imf, multiplicity


# Define isochrone parameters
logAge = 9.6   # Age in log(years)
AKs = 0  # extinction in mags
dist = 1000  # distance in parsec
metallicities = [-1]  # Metallicity in [M/H]

# Define evolution/atmosphere models and extinction law
evo_model = evolution.MISTv1()
atm_func = atmospheres.get_merged_atmosphere
red_law = reddening.RedLawHosek18b()

# Also specify filters for synthetic photometry (optional). Here we use
# the HST WFC3-IR F127M, F139M, and F153M filters
filt_list = ['wfc3,ir,f127m', 'wfc3,ir,f139m', 'wfc3,ir,f153m']

# Make Isochrone object. Note that is calculation will take a few minutes, unless the
# isochrone has been generated previously.
for metallicity in metallicities:
    my_iso = synthetic.IsochronePhot(logAge, AKs, dist, metallicity=metallicity,
                                     evo_model=evo_model, atm_func=atm_func, red_law=red_law, filters=filt_list)
    print(my_iso.save_file)
예제 #3
0
def test_IsochronePhot(plot=False):
    from popstar import synthetic as syn
    from popstar import evolution, atmospheres, reddening

    logAge = 6.7
    AKs = 2.7
    distance = 4000
    filt_list = ['wfc3,ir,f127m', 'nirc2,J']
    mass_sampling = 1
    iso_dir = 'iso/'

    evo_model = evolution.MISTv1()
    atm_func = atmospheres.get_merged_atmosphere
    redlaw = reddening.RedLawNishiyama09()

    startTime = time.time()
    iso = syn.IsochronePhot(logAge,
                            AKs,
                            distance,
                            evo_model=evo_model,
                            atm_func=atm_func,
                            red_law=redlaw,
                            filters=filt_list,
                            mass_sampling=mass_sampling,
                            iso_dir=iso_dir)
    endTime = time.time()
    print('IsochronePhot generated in: %d seconds' % (endTime - startTime))
    # Typically takes 120 seconds if file is regenerated.
    # Limited by pysynphot.Icat call in atmospheres.py

    assert iso.points.meta['LOGAGE'] == logAge
    assert iso.points.meta['AKS'] == AKs
    assert iso.points.meta['DISTANCE'] == distance
    assert len(iso.points) > 100

    assert 'm_nirc2_J' in iso.points.colnames

    if plot:
        plt.figure(1)
        iso.plot_CMD('mag814w', 'mag160w')

        plt.figure(2)
        iso.plot_mass_magnitude('mag160w')

    # Finally, let's test the isochronePhot file generation
    assert os.path.exists('{0}/iso_{1:.2f}_{2:4.2f}_{3:4s}_p00.fits'.format(
        iso_dir, logAge, AKs,
        str(distance).zfill(5)))

    # Check 1: If we try to remake the isochrone, does it read the file rather than
    # making a new one
    iso_new = syn.IsochronePhot(logAge,
                                AKs,
                                distance,
                                evo_model=evo_model,
                                atm_func=atm_func,
                                red_law=redlaw,
                                filters=filt_list,
                                mass_sampling=mass_sampling,
                                iso_dir=iso_dir)

    assert iso_new.recalc == False

    # Check 2: If we change evo model, atmo model, or redlaw,
    # does IsochronePhot regenerate the isochrone and overwrite the existing one?
    evo2 = evolution.MergedBaraffePisaEkstromParsec()
    mass_sampling = 20

    iso_new = syn.IsochronePhot(logAge,
                                AKs,
                                distance,
                                evo_model=evo2,
                                atm_func=atm_func,
                                red_law=redlaw,
                                filters=filt_list,
                                mass_sampling=mass_sampling,
                                iso_dir=iso_dir)

    assert iso_new.recalc == True

    redlaw2 = reddening.RedLawHosek18b()
    iso_new = syn.IsochronePhot(logAge,
                                AKs,
                                distance,
                                evo_model=evo2,
                                atm_func=atm_func,
                                red_law=redlaw2,
                                filters=filt_list,
                                mass_sampling=mass_sampling,
                                iso_dir=iso_dir)

    assert iso_new.recalc == True

    atm2 = atmospheres.get_castelli_atmosphere
    iso_new = syn.IsochronePhot(logAge,
                                AKs,
                                distance,
                                evo_model=evo2,
                                atm_func=atm2,
                                red_law=redlaw2,
                                filters=filt_list,
                                mass_sampling=mass_sampling,
                                iso_dir=iso_dir)

    assert iso_new.recalc == True

    return
예제 #4
0
def test_iso_wave():
    """
    Test to make sure isochrones generated have spectra with the proper 
    wavelength range, and that the user has control over that wavelength
    range (propagated through IsochronePhot)
    """
    # Define isochrone parameters
    logAge = np.log10(5 * 10**6.)  # Age in log(years)
    AKs = 0.8  # extinction in mags
    dist = 4000  # distance in parsec

    # Define evolution/atmosphere models and extinction law (optional)
    evo_model = evolution.MergedBaraffePisaEkstromParsec()
    atm_func = atmospheres.get_merged_atmosphere
    red_law = reddening.RedLawHosek18b()

    # Also specify filters for synthetic photometry (optional). Here we use
    # the HST WFC3-IR F127M, F139M, and F153M filters
    filt_list = ['wfc3,ir,f127m']

    # First, let's make sure the vega spectrum has the proper limits
    vega = synthetic.Vega()

    assert np.min(vega.wave) == 995
    assert np.max(vega.wave) == 100200

    # Make Isochrone object. Will use wave_range = [3000,52000].
    # Make sure range matches to resolution of atmosphere.
    wave_range1 = [3000, 52000]
    my_iso = synthetic.IsochronePhot(logAge,
                                     AKs,
                                     dist,
                                     evo_model=evo_model,
                                     atm_func=atm_func,
                                     red_law=red_law,
                                     filters=filt_list,
                                     mass_sampling=10,
                                     wave_range=wave_range1,
                                     recomp=True)

    test = my_iso.spec_list[0]

    assert np.min(test.wave) == 3010
    assert np.max(test.wave) == 51900

    # Now let's try changing the wave range. Is it carried through
    # properly?
    wave_range2 = [1200, 90000]
    my_iso = synthetic.IsochronePhot(logAge,
                                     AKs,
                                     dist,
                                     evo_model=evo_model,
                                     atm_func=atm_func,
                                     red_law=red_law,
                                     filters=filt_list,
                                     mass_sampling=10,
                                     wave_range=wave_range2,
                                     recomp=True)

    test2 = my_iso.spec_list[0]

    assert np.min(test2.wave) == 1205
    assert np.max(test2.wave) == 89800

    # Does the error exception catch the bad wave_range?
    wave_range3 = [1200, 1000000]
    try:
        my_iso = synthetic.IsochronePhot(logAge,
                                         AKs,
                                         dist,
                                         evo_model=evo_model,
                                         atm_func=atm_func,
                                         red_law=red_law,
                                         filters=filt_list,
                                         mass_sampling=10,
                                         wave_range=wave_range3,
                                         recomp=True)
        print(
            'WAVE TEST FAILED!!! Should have crashed here, wavelength range out of bounds'
        )
        pdb.set_trace()
    except:
        print('Wavelength out of bound condition passed. Test is good')
        pass
    return
예제 #5
0
def test_cluster_mass():
    from popstar import synthetic as syn
    from popstar import atmospheres as atm
    from popstar import evolution
    from popstar import reddening
    from popstar import ifmr
    from popstar.imf import imf
    from popstar.imf import multiplicity

    # Define cluster parameters
    logAge = 6.7
    AKs = 2.4
    distance = 4000
    cluster_mass = 10**5.
    mass_sampling = 5

    # Test filters
    filt_list = ['nirc2,J', 'nirc2,Kp']

    startTime = time.time()

    # Define evolution/atmosphere models and extinction law
    evo = evolution.MISTv1()
    atm_func = atmospheres.get_merged_atmosphere
    red_law = reddening.RedLawHosek18b()

    iso = syn.IsochronePhot(logAge,
                            AKs,
                            distance,
                            evo_model=evo,
                            atm_func=atm_func,
                            red_law=red_law,
                            filters=filt_list,
                            mass_sampling=mass_sampling)

    print('Constructed isochrone: %d seconds' % (time.time() - startTime))

    # Now to create the cluster.
    imf_mass_limits = np.array([0.2, 0.5, 1, 120.0])
    imf_powers = np.array([-1.3, -2.3, -2.3])

    # IFMR
    my_ifmr = ifmr.IFMR()

    ##########
    # Start without multiplicity
    ##########
    my_imf1 = imf.IMF_broken_powerlaw(imf_mass_limits,
                                      imf_powers,
                                      multiplicity=None)
    print('Constructed IMF: %d seconds' % (time.time() - startTime))

    cluster1 = syn.ResolvedCluster(iso, my_imf1, cluster_mass, ifmr=my_ifmr)
    clust1 = cluster1.star_systems
    print('Constructed cluster: %d seconds' % (time.time() - startTime))

    # Check that the total mass is within tolerance of input mass
    cluster_mass_out = clust1['systemMass'].sum()
    assert np.abs(cluster_mass_out -
                  cluster_mass) < 200.0  # within 200 Msun of desired mass.
    print('Cluster Mass: IN = ', cluster_mass, " OUT = ", cluster_mass_out)

    ##########
    # Test with multiplicity
    ##########
    multi = multiplicity.MultiplicityUnresolved()
    my_imf2 = imf.IMF_broken_powerlaw(imf_mass_limits,
                                      imf_powers,
                                      multiplicity=multi)
    print('Constructed IMF with multiples: %d seconds' %
          (time.time() - startTime))

    cluster2 = syn.ResolvedCluster(iso, my_imf2, cluster_mass, ifmr=my_ifmr)
    clust2 = cluster2.star_systems
    print('Constructed cluster with multiples: %d seconds' %
          (time.time() - startTime))

    # Check that the total mass is within tolerance of input mass
    cluster_mass_out = clust2['systemMass'].sum()
    assert np.abs(cluster_mass_out -
                  cluster_mass) < 200.0  # within 200 Msun of desired mass.
    print('Cluster Mass: IN = ', cluster_mass, " OUT = ", cluster_mass_out)

    return