コード例 #1
0
def test_absorption_spectrum_cosmo_sph():
    """
    This test generates an absorption spectrum from a compound light ray on a
    particle dataset
    """
    # Set up in a temp dir
    tmpdir = tempfile.mkdtemp()
    curdir = os.getcwd()
    os.chdir(tmpdir)

    lr = LightRay(GIZMO_PLUS, 'Gadget', 0.0, 0.01)

    lr.make_light_ray(seed=1234567,
                      fields=[('gas', 'temperature'),
                              ('gas', 'H_number_density')],
                      data_filename='lightray.h5')

    sp = AbsorptionSpectrum(900.0, 1800.0, 10000)

    my_label = 'HI Lya'
    field = ('gas', 'H_number_density')
    wavelength = 1215.6700  # Angstroms
    f_value = 4.164E-01
    gamma = 6.265e+08
    mass = 1.00794

    sp.add_line(my_label,
                field,
                wavelength,
                f_value,
                gamma,
                mass,
                label_threshold=1.e10)

    my_label = 'HI Lya'
    field = ('gas', 'H_number_density')
    wavelength = 912.323660  # Angstroms
    normalization = 1.6e17
    index = 3.0

    sp.add_continuum(my_label, field, wavelength, normalization, index)

    wavelength, flux = sp.make_spectrum('lightray.h5',
                                        output_file='spectrum.h5',
                                        line_list_file='lines.txt',
                                        use_peculiar_velocity=True)

    # load just-generated hdf5 file of spectral data (for consistency)
    data = h5.File('spectrum.h5', 'r')

    for key in data.keys():
        func = lambda x=key: data[x][:]
        func.__name__ = "{}_cosmo_sph".format(key)
        test = GenericArrayTest(None, func)
        test_absorption_spectrum_cosmo_sph.__name__ = test.description
        yield test

    # clean up
    os.chdir(curdir)
    shutil.rmtree(tmpdir)
コード例 #2
0
def test_absorption_spectrum_with_continuum():
    """
    This test generates an absorption spectrum from a simple light ray on a
    grid dataset and adds Lyman alpha and Lyman continuum to it
    """

    # Set up in a temp dir
    tmpdir = tempfile.mkdtemp()
    curdir = os.getcwd()
    os.chdir(tmpdir)

    ds = load(ISO_GALAXY)
    lr = LightRay(ds)

    ray_start = ds.domain_left_edge
    ray_end = ds.domain_right_edge
    lr.make_light_ray(start_position=ray_start, end_position=ray_end,
                      fields=['temperature', 'density', 'H_number_density'],
                      data_filename='lightray.h5')

    sp = AbsorptionSpectrum(800.0, 1300.0, 5001)

    my_label = 'HI Lya'
    field = 'H_number_density'
    wavelength = 1215.6700  # Angstromss
    f_value = 4.164E-01
    gamma = 6.265e+08
    mass = 1.00794

    sp.add_line(my_label, field, wavelength, f_value,
                gamma, mass, label_threshold=1.e10)

    my_label = 'Ly C'
    field = 'H_number_density'
    wavelength = 912.323660  # Angstroms
    normalization = 1.6e17
    index = 3.0

    sp.add_continuum(my_label, field, wavelength, normalization, index)

    wavelength, flux = sp.make_spectrum('lightray.h5',
                                        output_file='spectrum.h5',
                                        line_list_file='lines.txt',
                                        use_peculiar_velocity=True)

    # load just-generated hdf5 file of spectral data (for consistency)
    data = h5.File('spectrum.h5', 'r')
    
    for key in data.keys():
        func = lambda x=key: data[x][:]
        func.__name__ = "{}_continuum".format(key)
        test = GenericArrayTest(None, func)
        test_absorption_spectrum_with_continuum.__name__ = test.description
        yield test

    # clean up
    os.chdir(curdir)
    shutil.rmtree(tmpdir)
コード例 #3
0
def test_absorption_spectrum_fits():
    """
    This test is simply following the description in the docs for how to
    generate an absorption spectrum from a cosmological light ray for one
    of the sample datasets.  Outputs to fits file if astropy is installed.
    """

    # Set up in a temp dir
    tmpdir = tempfile.mkdtemp()
    curdir = os.getcwd()
    os.chdir(tmpdir)

    lr = LightRay(COSMO_PLUS, 'Enzo', 0.0, 0.1)

    lr.make_light_ray(seed=1234567,
                      fields=['temperature', 'density', 'H_number_density'],
                      get_los_velocity=True,
                      data_filename='lightray.h5')

    sp = AbsorptionSpectrum(900.0, 1800.0, 10000)

    my_label = 'HI Lya'
    field = 'H_number_density'
    wavelength = 1215.6700  # Angstromss
    f_value = 4.164E-01
    gamma = 6.265e+08
    mass = 1.00794

    sp.add_line(my_label,
                field,
                wavelength,
                f_value,
                gamma,
                mass,
                label_threshold=1.e10)

    my_label = 'HI Lya'
    field = 'H_number_density'
    wavelength = 912.323660  # Angstroms
    normalization = 1.6e17
    index = 3.0

    sp.add_continuum(my_label, field, wavelength, normalization, index)

    wavelength, flux = sp.make_spectrum('lightray.h5',
                                        output_file='spectrum.fits',
                                        line_list_file='lines.txt',
                                        use_peculiar_velocity=True)

    # clean up
    os.chdir(curdir)
    shutil.rmtree(tmpdir)
コード例 #4
0
def test_absorption_spectrum_fits():
    """
    This test generates an absorption spectrum and saves it as a fits file.
    """

    # Set up in a temp dir
    tmpdir = tempfile.mkdtemp()
    curdir = os.getcwd()
    os.chdir(tmpdir)

    lr = LightRay(COSMO_PLUS_SINGLE)

    ray_start = [0, 0, 0]
    ray_end = [1, 1, 1]
    lr.make_light_ray(start_position=ray_start,
                      end_position=ray_end,
                      fields=['temperature', 'density', 'H_number_density'],
                      data_filename='lightray.h5')

    sp = AbsorptionSpectrum(900.0, 1800.0, 10000)

    my_label = 'HI Lya'
    field = 'H_number_density'
    wavelength = 1215.6700  # Angstroms
    f_value = 4.164E-01
    gamma = 6.265e+08
    mass = 1.00794

    sp.add_line(my_label,
                field,
                wavelength,
                f_value,
                gamma,
                mass,
                label_threshold=1.e10)

    my_label = 'HI Lya'
    field = 'H_number_density'
    wavelength = 912.323660  # Angstroms
    normalization = 1.6e17
    index = 3.0

    sp.add_continuum(my_label, field, wavelength, normalization, index)

    wavelength, flux = sp.make_spectrum('lightray.h5',
                                        output_file='spectrum.fits',
                                        line_list_file='lines.txt',
                                        use_peculiar_velocity=True)

    # clean up
    os.chdir(curdir)
    shutil.rmtree(tmpdir)
コード例 #5
0
def test_absorption_spectrum_fits():
    """
    This test is simply following the description in the docs for how to
    generate an absorption spectrum from a cosmological light ray for one
    of the sample datasets.  Outputs to fits file if astropy is installed.
    """

    # Set up in a temp dir
    tmpdir = tempfile.mkdtemp()
    curdir = os.getcwd()
    os.chdir(tmpdir)

    lr = LightRay(COSMO_PLUS, 'Enzo', 0.0, 0.1)

    lr.make_light_ray(seed=1234567,
                      fields=['temperature', 'density', 'H_number_density'],
                      get_los_velocity=True,
                      data_filename='lightray.h5')

    sp = AbsorptionSpectrum(900.0, 1800.0, 10000)

    my_label = 'HI Lya'
    field = 'H_number_density'
    wavelength = 1215.6700  # Angstromss
    f_value = 4.164E-01
    gamma = 6.265e+08
    mass = 1.00794

    sp.add_line(my_label, field, wavelength, f_value,
                gamma, mass, label_threshold=1.e10)

    my_label = 'HI Lya'
    field = 'H_number_density'
    wavelength = 912.323660  # Angstroms
    normalization = 1.6e17
    index = 3.0

    sp.add_continuum(my_label, field, wavelength, normalization, index)

    wavelength, flux = sp.make_spectrum('lightray.h5',
                                        output_file='spectrum.fits',
                                        line_list_file='lines.txt',
                                        use_peculiar_velocity=True)

    # clean up
    os.chdir(curdir)
    shutil.rmtree(tmpdir)