Beispiel #1
0
    def test_star_type_probability_no_Av(self):
        """
        Test for star_type_probability.py
        """
        # download the needed files
        pdf2d_fname = download_rename("beast_example_phat_pdf2d_no_Av.fits")
        star_prob_fname = download_rename(
            "beast_example_phat_startype_no_Av.fits")

        # run star_type_probability
        star_prob = star_type_probability.star_type_probability(
            self.pdf1d_fname_cache,
            pdf2d_fname,
            output_filebase=None,
            ext_O_star_params={
                "min_M_ini": 10,
                "min_Av": 0.5,
                "max_Av": 5
            },
        )

        # expected output table
        expected_star_prob = Table.read(star_prob_fname)

        # compare to new table
        compare_tables(expected_star_prob, Table(star_prob))
Beispiel #2
0
def test_trim_grid():

    # download the needed files
    vega_fname = download_rename('vega.hd5')
    seds_fname = download_rename('beast_example_phat_seds.grid.hd5')
    noise_fname = download_rename('beast_example_phat_noisemodel.hd5')

    # download cached version of noisemodel on the sed grid
    simobs_fname_cache = download_rename('beast_example_phat_simobs.fits')

    ################

    # get the physics model grid - includes priors
    modelsedgrid = FileSEDGrid(seds_fname)

    # read in the noise model - includes bias, unc, and completeness
    noisegrid = noisemodel.get_noisemodelcat(noise_fname)

    table_new = gen_SimObs_from_sedgrid(modelsedgrid,
                                        noisegrid,
                                        nsim=100,
                                        compl_filter="f475w",
                                        ranseed=1234,
                                        vega_fname=vega_fname)

    # check that the simobs files are exactly the same
    table_cache = Table.read(simobs_fname_cache)

    compare_tables(table_cache, table_new)
Beispiel #3
0
    def test_ast_pick_models(self):
        """
        Generate the artifial star test (AST) inputs using a cached version of
        the sed grid and compare the result to a cached version.
        """
        # download files specific to this test
        cached_table_filename = download_rename(
            "phat_small/cache_inputAST.txt")

        mag_cuts = [1.0]

        seds_fname = self.seds_fname_cache
        if self.dset != "phat":
            seds_fname = download_rename(
                "phat_small/beast_example_phat_seds.grid.hd5")
        else:
            seds_fname = self.seds_fname_cache

        outname = tempfile.NamedTemporaryFile(suffix=".txt").name
        make_ast_input_list.pick_models(
            seds_fname,
            self.settings.filters,
            mag_cuts,
            outfile=outname,
            ranseed=1234,
        )

        table_new = Table.read(outname, format="ascii")

        # download cached version of the file and compare it to new file
        table_cache = Table.read(cached_table_filename,
                                 format="csv",
                                 delimiter=" ")
        compare_tables(table_new, table_cache)
Beispiel #4
0
def test_star_type_probability_all_params():
    """
    Test for star_type_probability.py
    """

    # download the needed files
    pdf1d_fname = download_rename("beast_example_phat_pdf1d.fits")
    pdf2d_fname = download_rename("beast_example_phat_pdf2d.fits")
    star_prob_fname = download_rename("beast_example_phat_startype.fits")

    # run star_type_probability
    star_prob = star_type_probability.star_type_probability(
        pdf1d_fname,
        pdf2d_fname,
        output_filebase=None,
        ext_O_star_params={
            'min_M_ini': 10,
            'min_Av': 0.5,
            'max_Av': 5
        })

    # expected output table
    expected_star_prob = Table.read(star_prob_fname)

    # compare to new table
    compare_tables(expected_star_prob, Table(star_prob))
Beispiel #5
0
def test_pick_models():
    # download the needed files
    vega_fname = download_rename("vega.hd5")
    filename = download_rename("beast_example_phat_seds.grid.hd5")

    filters = [
        "HST_WFC3_F275W",
        "HST_WFC3_F336W",
        "HST_ACS_WFC_F475W",
        "HST_ACS_WFC_F814W",
        "HST_WFC3_F110W",
        "HST_WFC3_F160W",
    ]
    mag_cuts = [1.0]

    make_ast_input_list.pick_models(
        filename,
        filters,
        mag_cuts,
        vega_fname=vega_fname,
        outfile="/tmp/test_inputAST.txt",
        ranseed=1234,
    )

    table_new = Table.read("/tmp/test_inputAST.txt", format="ascii")

    # download cached version of the file and compare it to new file
    cached_table_filename = download_rename("cache_inputAST.txt")
    table_cache = Table.read(cached_table_filename,
                             format="csv",
                             delimiter=" ")
    compare_tables(table_new, table_cache)
Beispiel #6
0
def test_make_kurucz_tlusty_spectral_grid():

    # download the needed files
    kurucz_fname = download_rename("kurucz2004.grid.fits")
    tlusty_fname = download_rename("tlusty.lowres.grid.fits")
    filter_fname = download_rename("filters.hd5")
    iso_fname = download_rename("beast_example_phat_iso.csv")

    # download cached version of spectral grid
    spec_fname_cache = download_rename("beast_example_phat_spec_grid.hd5")

    ################
    # generate the same spectral grid from the code

    # read in the cached isochrones
    oiso = ezIsoch(iso_fname)

    # define the distance
    distances = [24.47]
    distance_unit = units.mag

    velocity = -300 * units.km / units.s
    redshift = (velocity / const.c).decompose().value

    # define the spectral libraries to use
    osl = stellib.Tlusty(filename=tlusty_fname) + stellib.Kurucz(
        filename=kurucz_fname)

    # define the extinction curve to use
    extLaw = extinction.Gordon16_RvFALaw()

    filters = [
        "HST_WFC3_F275W",
        "HST_WFC3_F336W",
        "HST_ACS_WFC_F475W",
        "HST_ACS_WFC_F814W",
        "HST_WFC3_F110W",
        "HST_WFC3_F160W",
    ]
    add_spectral_properties_kwargs = dict(filternames=filters)

    spec_fname = "/tmp/beast_example_phat_spec_grid.hd5"
    spec_fname, g = make_spectral_grid(
        "test",
        oiso,
        osl=osl,
        redshift=redshift,
        distance=distances,
        distance_unit=distance_unit,
        spec_fname=spec_fname,
        filterLib=filter_fname,
        extLaw=extLaw,
        add_spectral_properties_kwargs=add_spectral_properties_kwargs,
    )

    # compare the new to the cached version
    compare_hdf5(spec_fname_cache, spec_fname)
Beispiel #7
0
def test_indiv_plot():

    # download cached version of fitting results
    stats_fname_cache = download_rename("phat_small/beast_example_phat_stats.fits")
    pdf1d_fname_cache = download_rename("phat_small/beast_example_phat_pdf1d.fits")

    # make the plot!
    fig = plot_indiv_fit.plot_indiv_fit(
        [stats_fname_cache, pdf1d_fname_cache], 0, plotfig=False
    )

    return fig
Beispiel #8
0
def test_plot_cmd_with_fits():

    # Download example data from phat_small
    fitsfile = download_rename("b15_4band_det_27_A.fits")

    # Download BEAST fits to example data
    beast_fitsfile = download_rename("beast_example_phat_stats.fits")

    # Plot CMD using defaults
    fig = plot_cmd_with_fits.plot(fitsfile, beast_fitsfile)

    return fig
Beispiel #9
0
def test_convert_hd5_to_fits():

    # Pick some random .hd5 file to convert
    data_fname = download_rename("M31-B09-EAST_tinychunk.phot.hdf5")
    data_fname_cache = download_rename("M31-B09-EAST_tinychunk.st.fits")

    # Convert the file
    st_file(data_fname)

    # Compare the contents of the new file to the cached version
    data = Table(fits.getdata(data_fname.replace("phot.hdf5", "st.fits")))
    data_cache = Table(fits.getdata(data_fname_cache))

    compare_tables(data_cache, data)
Beispiel #10
0
def test_make_kurucz_tlusty_spectral_grid():

    # download the needed files
    kurucz_fname = download_rename('kurucz2004.grid.fits')
    tlusty_fname = download_rename('tlusty.lowres.grid.fits')
    filter_fname = download_rename('filters.hd5')
    iso_fname = download_rename('beast_example_phat_iso.csv')

    # download cached version of spectral grid
    spec_fname_cache = download_rename('beast_example_phat_spec_grid.hd5')

    ################
    # generate the same spectral grid from the code

    # read in the cached isochrones
    oiso = ezIsoch(iso_fname)

    # define the distance
    distances = [24.47]
    distance_unit = units.mag

    velocity = -300 * units.km / units.s
    redshift = (velocity / const.c).decompose().value

    # define the spectral libraries to use
    osl = stellib.Tlusty(filename=tlusty_fname) \
        + stellib.Kurucz(filename=kurucz_fname)

    filters = [
        'HST_WFC3_F275W', 'HST_WFC3_F336W', 'HST_ACS_WFC_F475W',
        'HST_ACS_WFC_F814W', 'HST_WFC3_F110W', 'HST_WFC3_F160W'
    ]
    add_spectral_properties_kwargs = dict(filternames=filters)

    spec_fname = '/tmp/beast_example_phat_spec_grid.hd5'
    spec_fname, g = make_spectral_grid(
        'test',
        oiso,
        osl=osl,
        redshift=redshift,
        distance=distances,
        distance_unit=distance_unit,
        spec_fname=spec_fname,
        filterLib=filter_fname,
        add_spectral_properties_kwargs=add_spectral_properties_kwargs)

    # compare the new to the cached version
    compare_hdf5(spec_fname_cache, spec_fname)
Beispiel #11
0
    def test_simobs(self):
        """
        Simulate observations using cached versions of the sed grid and noise model
        and compare the result to a cached version.
        """
        # download files specific to this test
        simobs_fname_cache = download_rename("beast_example_phat_simobs.fits")

        # get the physics model grid - includes priors
        modelsedgrid = SEDGrid(self.seds_fname_cache)

        # read in the noise model - includes bias, unc, and completeness
        noisegrid = noisemodel.get_noisemodelcat(self.noise_fname_cache)

        table_new = gen_SimObs_from_sedgrid(
            modelsedgrid,
            noisegrid,
            nsim=100,
            compl_filter="max",
            ranseed=1234,
        )

        # check that the simobs files are exactly the same
        table_cache = Table.read(simobs_fname_cache)

        # to avoid issues with uppercase vs lowercase column names, make them all
        # the same before comparing
        for col in table_new.colnames:
            table_new[col].name = col.upper()
        for col in table_cache.colnames:
            table_cache[col].name = col.upper()

        compare_tables(table_cache, table_new)
Beispiel #12
0
    def test_compare_spec_type_inFOV(self):
        """
        Test for compare_spec_type.  Inputs and expected outputs created by
        running generate_files_for_tests.py in beast-examples/metal_small.

        In this version, the stars are in the imaging field of view.
        """

        # download cached file
        compare_spec_type_fname = download_rename(
            f"{self.basename}_compare_spec_type.asdf")
        with asdf.open(compare_spec_type_fname) as af:
            compare_spec_type_info = copy.deepcopy(af.tree)

        # run compare_spec_type
        spec_type = compare_spec_type(
            self.obs_fname_cache,
            self.stats_fname_cache,
            **compare_spec_type_info["input"],
        )

        # expected output table
        expected_table = Table(compare_spec_type_info["output"])

        # compare to new table
        compare_tables(expected_table, Table(spec_type), rtol=2e-3)
Beispiel #13
0
    def test_star_type_probability_all_params(self):
        """
        Test for star_type_probability.  Inputs and expected outputs created by
        running generate_files_for_tests.py in beast-examples/metal_small.

        In this version, all required parameters are present.
        """
        # download cached file
        star_prob_fname = download_rename(
            f"{self.basename}_star_type_probability.asdf")
        with asdf.open(star_prob_fname) as af:
            star_prob_info = copy.deepcopy(af.tree)

        # run star_type_probability
        star_prob = star_type_probability.star_type_probability(
            self.pdf1d_fname_cache,
            self.pdf2d_fname_cache,
            **star_prob_info["input"],
        )

        # expected output table
        expected_star_prob = Table(star_prob_info["output"])

        # compare to new table
        compare_tables(expected_star_prob, Table(star_prob))
def test_padova_isochrone_download():
    # download the cached version
    iso_fname_cache = download_rename("beast_example_phat_iso.csv")

    # download the file live from the website
    savename = "/tmp/padova_iso.csv"
    iso_fname, oiso = make_iso_table(
        "test",
        iso_fname=savename,
        logtmin=6.0,
        logtmax=10.13,
        dlogt=1.0,
        z=[0.03, 0.019, 0.008, 0.004],
    )

    # read the cached and new tables using astropy tables
    table_cache = Table.read(iso_fname_cache,
                             format="ascii.csv",
                             comment="#",
                             delimiter=",")
    table_new = Table.read(iso_fname,
                           format="ascii.csv",
                           comment="#",
                           delimiter=",")

    # compare
    compare_tables(table_cache, table_new)
Beispiel #15
0
def test_reduce_grid_info():
    seds_trim_fname = download_rename("beast_example_phat_seds_trim.grid.hd5")
    sub_fnames = subgridding_tools.split_grid(seds_trim_fname, 3)

    complete_g_info = subgridding_tools.subgrid_info(seds_trim_fname)
    cap_unique = 50
    sub_g_info = subgridding_tools.reduce_grid_info(sub_fnames,
                                                    nprocs=3,
                                                    cap_unique=cap_unique)

    for q in complete_g_info:
        if q not in sub_g_info:
            raise AssertionError()
        if not complete_g_info[q]["min"] == sub_g_info[q]["min"]:
            raise AssertionError()
        if not complete_g_info[q]["max"] == sub_g_info[q]["max"]:
            raise AssertionError()
        num_unique = len(complete_g_info[q]["unique"])
        if num_unique > cap_unique:
            # Cpan still be larger if one of the sub results during the
            # reduction is larger. This is as intended.
            if not sub_g_info[q]["num_unique"] >= cap_unique:
                raise AssertionError()
        else:
            if not sub_g_info[q]["num_unique"] == num_unique:
                raise AssertionError()
Beispiel #16
0
def test_make_extinguished_sed_grid():

    # download the needed files
    priors_fname = download_rename("beast_example_phat_spec_w_priors.grid.hd5")
    filter_fname = download_rename("filters.hd5")

    # download cached version of sed grid
    seds_fname_cache = download_rename("beast_example_phat_seds.grid.hd5")

    ################
    # generate the same extinguished SED grid from the code

    # Add in the filters
    filters = [
        "HST_WFC3_F275W",
        "HST_WFC3_F336W",
        "HST_ACS_WFC_F475W",
        "HST_ACS_WFC_F814W",
        "HST_WFC3_F110W",
        "HST_WFC3_F160W",
    ]
    add_spectral_properties_kwargs = dict(filternames=filters)

    g_pspec = grid.FileSpectralGrid(priors_fname, backend="memory")

    # generate the SED grid by integrating the filter response functions
    #   effect of dust extinction applied before filter integration
    #   also computes the dust priors as weights
    seds_fname = "/tmp/beast_example_phat_sed.grid.hd5"
    seds_fname, g_seds = make_extinguished_sed_grid(
        "test",
        g_pspec,
        filters,
        seds_fname=seds_fname,
        filterLib=filter_fname,
        extLaw=extinction.Gordon16_RvFALaw(),
        av=[0.0, 10.055, 1.0],
        rv=[2.0, 6.0, 1.0],
        fA=[0.0, 1.0, 0.25],
        av_prior_model={"name": "flat"},
        rv_prior_model={"name": "flat"},
        fA_prior_model={"name": "flat"},
        add_spectral_properties_kwargs=add_spectral_properties_kwargs,
    )

    # compare the new to the cached version
    compare_hdf5(seds_fname_cache, seds_fname)
def test_get_noisemodelcat():
    noise_fname = download_rename("beast_example_phat_noisemodel.grid.hd5")
    ntable = get_noisemodelcat(noise_fname)

    # check that at least the 3 basic elements are included
    expected_elements = ["error", "bias", "completeness"]
    for cexp in expected_elements:
        assert cexp in ntable.keys(), f"{cexp} values not found in noisemodel"
def test_compare_spec_type_inFOV():
    """
    Test for compare_spec_type.  The spectrally-typed stars aren't real sources,
    they're just invented for the purposes of documenting/testing the code.

    In this version, the stars are in the imaging field of view.
    """

    # download the needed files
    obs_fname = download_rename("b15_4band_det_27_A.fits")
    stats_fname = download_rename("beast_example_phat_stats.fits")

    # run compare_spec_type
    spec_type = compare_spec_type(
        obs_fname,
        stats_fname,
        [11.2335881, 11.23342557],  # RA
        [41.9001895, 41.90006316],  # Dec
        ['A', 'G'],  # Spectral type
        [2, 7],  # Subtype
        ['II', 'II'],  # Luminosity class
        match_radius=0.2  # Match radius (arcsec)
    )

    # expected output table
    expected_table = Table({
        'spec_ra': [11.2335881, 11.23342557],
        'spec_dec': [41.9001895, 41.90006316],
        'spec_type': ['A 2 II', 'G 7 II'],
        'spec_teff': [9000.0, 4916.666666666667],
        'spec_logg': [2.7164474106543732, 1.7184474106543735],
        'phot_cat_ind': [27, 8],
        'stats_cat_ind': [27, 8],
        'beast_teff_p50': [9046.250020338754, 4528.230977991138],
        'beast_teff_p16': [8643.670633196869, 4335.617282355577],
        'beast_teff_p84': [9536.391362054928, 4729.401710221546],
        'beast_logg_p50': [2.714286917261312, 1.7684285714285717],
        'beast_logg_p16': [2.636272525730954, 1.7014832653061227],
        'beast_logg_p84': [2.799534708811963, 1.8353738775510207],
        'teff_sigma': [-0.11488422362383206, 1.9308757510045778],
        'logg_sigma': [0.025343687546173433, -0.7465969411324851]
    })

    # compare to new table
    compare_tables(expected_table, Table(spec_type), rtol=2e-3)
def test_compare_spec_type_notFOV():
    """
    Test for compare_spec_type.  The spectrally-typed stars aren't real sources,
    they're just invented for the purposes of documenting/testing the code.

    In this version, the stars are NOT in the imaging field of view.
    """

    # download the needed files
    obs_fname = download_rename("b15_4band_det_27_A.fits")
    stats_fname = download_rename("beast_example_phat_stats.fits")

    # run compare_spec_type
    spec_type = compare_spec_type(
        obs_fname,
        stats_fname,
        [1.0],  # RA
        [1.0],  # Dec
        ['B'],  # Spectral type
        [4],  # Subtype
        ['V'],  # Luminosity class
        match_radius=0.2  # Match radius (arcsec)
    )

    # expected output table
    expected_table = Table({
        'spec_ra': [1.0],
        'spec_dec': [1.0],
        'spec_type': ['B 4 V'],
        'spec_teff': [None],
        'spec_logg': [None],
        'phot_cat_ind': [None],
        'stats_cat_ind': [None],
        'beast_teff_p50': [None],
        'beast_teff_p16': [None],
        'beast_teff_p84': [None],
        'beast_logg_p50': [None],
        'beast_logg_p16': [None],
        'beast_logg_p84': [None],
        'teff_sigma': [None],
        'logg_sigma': [None],
    })

    # compare to new table
    compare_tables(expected_table, Table(spec_type))
Beispiel #20
0
def test_plot_cmd():

    # Download example data from phat_small
    fitsfile = download_rename("phat_small/b15_4band_det_27_A.fits")

    # Plot CMD using defaults
    fig = plot_cmd.plot_cmd(fitsfile, show_plot=False)

    return fig
Beispiel #21
0
def test_pick_models():
    # download the needed files
    vega_fname = download_rename('vega.hd5')
    filename = download_rename('beast_example_phat_seds.grid.hd5')

    filters = ['HST_WFC3_F275W', 'HST_WFC3_F336W', 'HST_ACS_WFC_F475W',
               'HST_ACS_WFC_F814W', 'HST_WFC3_F110W', 'HST_WFC3_F160W']
    mag_cuts = [1.]

    table_out = make_ast_input_list.pick_models(filename, filters, mag_cuts, vega_fname=vega_fname,
                                                outfile='/tmp/test_inputAST.txt', ranseed=1234)

    table_new = Table.read('/tmp/test_inputAST.txt', format='ascii')

    # download cached version of the file and compare it to new file
    cached_table_filename = download_rename('cache_inputAST.txt')
    table_cache = Table.read(cached_table_filename, format='csv', delimiter=' ')
    compare_tables(table_new, table_cache)
def test_add_stellar_priors_to_spectral_grid():

    # download the needed files
    gspec_fname = download_rename("beast_example_phat_spec_grid.hd5")

    # download cached version of spectral grid with priors
    priors_fname_cache = download_rename("beast_example_phat_spec_w_priors.grid.hd5")

    ###############
    # generate the spectral grid with stellar priors from the code

    gspec_fname = "/tmp/beast_example_phat_spec_grid.hd5"
    specgrid = grid.FileSpectralGrid(gspec_fname, backend="memory")

    priors_fname = "/tmp/beast_example_phat_spec_w_priors.grid.hd5"
    priors_fname, g = add_stellar_priors("test", specgrid, priors_fname=priors_fname)

    # compare the new to the cached version
    compare_hdf5(priors_fname_cache, priors_fname)
Beispiel #23
0
def test_toothpick_noisemodel():

    # download the needed files
    asts_fname = download_rename('fake_stars_b15_27_all.hd5')
    filter_fname = download_rename('filters.hd5')
    vega_fname = download_rename('vega.hd5')
    hst_fname = download_rename('hst_whitedwarf_frac_covar.fits')
    seds_fname = download_rename('beast_example_phat_seds.grid.hd5')

    # download cached version of noisemodel on the sed grid
    noise_fname_cache = download_rename('beast_example_phat_noisemodel.hd5')

    ################
    # get the modesedgrid on which to generate the noisemodel
    modelsedgrid = FileSEDGrid(seds_fname)

    # absflux calibration covariance matrix for HST specific filters (AC)
    filters = [
        'HST_WFC3_F275W', 'HST_WFC3_F336W', 'HST_ACS_WFC_F475W',
        'HST_ACS_WFC_F814W', 'HST_WFC3_F110W', 'HST_WFC3_F160W'
    ]
    absflux_a_matrix = hst_frac_matrix(filters,
                                       hst_fname=hst_fname,
                                       filterLib=filter_fname)

    # generate the AST noise model
    noise_fname = '/tmp/beast_example_phat_noisemodel.hd5'
    noisemodel.make_toothpick_noise_model(noise_fname,
                                          asts_fname,
                                          modelsedgrid,
                                          absflux_a_matrix=absflux_a_matrix,
                                          vega_fname=vega_fname)

    # compare the new to the cached version
    compare_hdf5(noise_fname_cache, noise_fname)
Beispiel #24
0
def test_simobs():

    # download the needed files
    vega_fname = download_rename("vega.hd5")
    seds_fname = download_rename("beast_example_phat_seds.grid.hd5")
    noise_fname = download_rename("beast_example_phat_noisemodel.grid.hd5")

    # download cached version of noisemodel on the sed grid
    simobs_fname_cache = download_rename("beast_example_phat_simobs.fits")

    ################

    # get the physics model grid - includes priors
    modelsedgrid = SEDGrid(seds_fname)

    # read in the noise model - includes bias, unc, and completeness
    noisegrid = noisemodel.get_noisemodelcat(noise_fname)

    table_new = gen_SimObs_from_sedgrid(
        modelsedgrid,
        noisegrid,
        nsim=100,
        compl_filter="f475w",
        ranseed=1234,
        vega_fname=vega_fname,
    )

    # check that the simobs files are exactly the same
    table_cache = Table.read(simobs_fname_cache)

    # to avoid issues with uppercase vs lowercase column names, make them all
    # the same before comparing
    for col in table_new.colnames:
        table_new[col].name = col.upper()
    for col in table_cache.colnames:
        table_cache[col].name = col.upper()

    compare_tables(table_cache, table_new)
Beispiel #25
0
def test_indiv_plot():

    # download cached version of fitting results
    stats_fname_cache = download_rename("beast_example_phat_stats.fits")
    pdf1d_fname_cache = download_rename("beast_example_phat_pdf1d.fits")

    starnum = 0

    # read in the stats
    stats = Table.read(stats_fname_cache)
    # open 1D PDF file
    pdf1d_hdu = fits.open(pdf1d_fname_cache)

    filters = [
        "HST_WFC3_F275W",
        "HST_WFC3_F336W",
        "HST_ACS_WFC_F475W",
        "HST_ACS_WFC_F814W",
        "HST_WFC3_F110W",
        "HST_WFC3_F160W",
    ]
    waves = np.asarray([
        2722.05531502,
        3366.00507206,
        4763.04670013,
        8087.36760191,
        11672.35909295,
        15432.7387546,
    ])

    fig, ax = plt.subplots(figsize=(8, 8))

    # make the plot!
    plot_indiv_fit.plot_beast_ifit(filters, waves, stats, pdf1d_hdu, starnum)

    return fig
Beispiel #26
0
def test_fit_grid():

    # download the needed files
    vega_fname = download_rename('vega.hd5')
    obs_fname = download_rename('b15_4band_det_27_A.fits')
    noise_trim_fname = download_rename(
        'beast_example_phat_noisemodel_trim.grid.hd5')
    seds_trim_fname = download_rename('beast_example_phat_seds_trim.grid.hd5')

    # download cached version of fitting results
    stats_fname_cache = download_rename('beast_example_phat_stats.fits')
    pdf1d_fname_cache = download_rename('beast_example_phat_pdf1d.fits')

    ################

    # read in the the AST noise model
    noisemodel_vals = noisemodel.get_noisemodelcat(noise_trim_fname)

    # read in the observed data
    filters = [
        'HST_WFC3_F275W', 'HST_WFC3_F336W', 'HST_ACS_WFC_F475W',
        'HST_ACS_WFC_F814W', 'HST_WFC3_F110W', 'HST_WFC3_F160W'
    ]
    basefilters = ['F275W', 'F336W', 'F475W', 'F814W', 'F110W', 'F160W']
    obs_colnames = [f.lower() + '_rate' for f in basefilters]

    obsdata = get_obscat(obs_fname,
                         filters,
                         obs_colnames,
                         vega_fname=vega_fname)
    # output files
    stats_fname = '/tmp/beast_example_phat_stats.fits'
    pdf1d_fname = '/tmp/beast_example_phat_pdf1d.fits'
    lnp_fname = '/tmp/beast_example_phat_lnp.hd5'

    fit.summary_table_memory(obsdata,
                             noisemodel_vals,
                             seds_trim_fname,
                             threshold=-10.,
                             save_every_npts=100,
                             lnp_npts=60,
                             stats_outname=stats_fname,
                             pdf1d_outname=pdf1d_fname,
                             lnp_outname=lnp_fname)

    # check that the stats files are exactly the same
    table_cache = Table.read(stats_fname_cache)
    table_new = Table.read(stats_fname)

    compare_tables(table_cache, table_new)

    # lnp files not checked as they are randomly sparsely sampled
    #   hence will be different every time the fitting is run

    # check that the pdf1d files are exactly the same
    compare_fits(pdf1d_fname_cache, pdf1d_fname)
Beispiel #27
0
def test_trim_grid():

    # download the needed files
    vega_fname = download_rename("vega.hd5")
    seds_fname = download_rename("beast_example_phat_seds.grid.hd5")
    noise_fname = download_rename("beast_example_phat_noisemodel.grid.hd5")
    obs_fname = download_rename("b15_4band_det_27_A.fits")

    # download cached version of noisemodel on the sed grid
    noise_trim_fname_cache = download_rename(
        "beast_example_phat_noisemodel_trim.grid.hd5")
    seds_trim_fname_cache = download_rename(
        "beast_example_phat_seds_trim.grid.hd5")

    ################

    # read in the observed data
    filters = [
        "HST_WFC3_F275W",
        "HST_WFC3_F336W",
        "HST_ACS_WFC_F475W",
        "HST_ACS_WFC_F814W",
        "HST_WFC3_F110W",
        "HST_WFC3_F160W",
    ]
    basefilters = ["F275W", "F336W", "F475W", "F814W", "F110W", "F160W"]
    obs_colnames = [f.lower() + "_rate" for f in basefilters]

    obsdata = Observations(obs_fname,
                           filters,
                           obs_colnames,
                           vega_fname=vega_fname)

    # get the modesedgrid
    modelsedgrid = SEDGrid(seds_fname)

    # read in the noise model just created
    noisemodel_vals = noisemodel.get_noisemodelcat(noise_fname)

    # trim the model sedgrid
    seds_trim_fname = "beast_example_phat_seds_trim.grid.hd5"
    noise_trim_fname = seds_trim_fname.replace("_seds", "_noisemodel")

    trim_models(
        modelsedgrid,
        noisemodel_vals,
        obsdata,
        seds_trim_fname,
        noise_trim_fname,
        sigma_fac=3.0,
    )

    # compare the new to the cached version
    compare_hdf5(seds_trim_fname_cache, seds_trim_fname, ctype="seds")
    compare_hdf5(noise_trim_fname_cache, noise_trim_fname, ctype="noise")
Beispiel #28
0
def test_plot_filters():

    filter_names = [
        "HST_WFC3_F225W",
        "HST_WFC3_F275W",
        "HST_WFC3_F336W",
        "HST_ACS_WFC_F475W",
        "HST_ACS_WFC_F550M",
        "HST_ACS_WFC_F814W",
        "HST_WFC3_F110W",
        "HST_WFC3_F160W",
    ]

    filters = download_rename("filters.hd5")

    # Plot filters using above arguments (the defaults)
    fig = plot_filters.plot_filters(filter_names, filterLib=filters, show_plot=False)

    return fig
Beispiel #29
0
def test_trim_grid():

    # download the needed files
    vega_fname = download_rename('vega.hd5')
    seds_fname = download_rename('beast_example_phat_seds.grid.hd5')
    noise_fname = download_rename('beast_example_phat_noisemodel.hd5')
    obs_fname = download_rename('b15_4band_det_27_A.fits')

    # download cached version of noisemodel on the sed grid
    noise_trim_fname_cache = download_rename(
        'beast_example_phat_noisemodel_trim.grid.hd5')
    seds_trim_fname_cache = download_rename(
        'beast_example_phat_seds_trim.grid.hd5')

    ################

    # read in the observed data
    filters = [
        'HST_WFC3_F275W', 'HST_WFC3_F336W', 'HST_ACS_WFC_F475W',
        'HST_ACS_WFC_F814W', 'HST_WFC3_F110W', 'HST_WFC3_F160W'
    ]
    basefilters = ['F275W', 'F336W', 'F475W', 'F814W', 'F110W', 'F160W']
    obs_colnames = [f.lower() + '_rate' for f in basefilters]

    obsdata = get_obscat(obs_fname,
                         filters,
                         obs_colnames,
                         vega_fname=vega_fname)

    # get the modesedgrid
    modelsedgrid = FileSEDGrid(seds_fname)

    # read in the noise model just created
    noisemodel_vals = noisemodel.get_noisemodelcat(noise_fname)

    # trim the model sedgrid
    seds_trim_fname = 'beast_example_phat_sed_trim.grid.hd5'
    noise_trim_fname = seds_trim_fname.replace('_sed', '_noisemodel')

    trim_models(modelsedgrid,
                noisemodel_vals,
                obsdata,
                seds_trim_fname,
                noise_trim_fname,
                sigma_fac=3.)

    # compare the new to the cached version
    compare_hdf5(seds_trim_fname_cache, seds_trim_fname, ctype='seds')
    compare_hdf5(noise_trim_fname_cache, noise_trim_fname, ctype='noise')
def test_reduce_grid_info():
    seds_trim_fname = download_rename('beast_example_phat_seds_trim.grid.hd5')
    sub_fnames = subgridding_tools.split_grid(seds_trim_fname, 3)

    complete_g_info = subgridding_tools.subgrid_info(seds_trim_fname)
    cap_unique = 50
    sub_g_info = subgridding_tools.reduce_grid_info(
        sub_fnames, nprocs=3, cap_unique=cap_unique)

    for q in complete_g_info:
        assert q in sub_g_info
        assert complete_g_info[q]['min'] == sub_g_info[q]['min']
        assert complete_g_info[q]['max'] == sub_g_info[q]['max']
        num_unique = len(complete_g_info[q]['unique'])
        if num_unique > cap_unique:
            # Cpan still be larger if one of the sub results during the
            # reduction is larger. This is as intended.
            assert sub_g_info[q]['num_unique'] >= cap_unique
        else:
            assert sub_g_info[q]['num_unique'] == num_unique