Skip to content

Make load_spectrum() easier to use #223

@chummels

Description

@chummels

Currently, the way to load a spectrum into trident isn't very friendly, and it requires units on the wavelength array. This should be cleaned up a bit, certainly enough that one can just re-load a saved HDF ray file without specifying the arrays manually. Better treatment of velocity datasets would be useful too. Example script currently.

import trident
import h5py as h5
from unyt import km, s, angstrom
import numpy as np

# Load your spectrum
spec_fn = 'spec_raw.h5'
f = h5.File(spec_fn)

# Read the velocity field from your HDF5 file, but ensure it's in appropriate units
velocity_field = f['wavelength'][()] * km/s

# Read your tau field and convert to a flux field e^-tau
tau_field = f['tau'][()]
flux_field = np.exp(-tau_field)

# Initialize SpectrumGenerator
sg = trident.SpectrumGenerator()

# Load your spectrum into trident
sg.load_spectrum(lambda_field=velocity_field, tau_field=tau_field, flux_field=flux_field)

# Apply gaussian line spread function to spectrum
sg.apply_lsf('gaussian', 50)

# Add gaussian noise at a SNR=100 to spectrum
sg.add_gaussian_noise(100)

# Save spectrum as hdf5 file
sg.save_spectrum('spec_final.h5')

# Plot spectrum as hdf5 file
sg.plot_spectrum('spec_final.png')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions