Skip to content

Commit

Permalink
Convert example spectra to MJy / sr (temporary fix)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dries Van De Putte committed May 9, 2024
1 parent 1a3360b commit 4573a35
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions pahfit/helpers.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import os
from importlib import resources

from specutils import Spectrum1D

from pahfit.component_models import BlackBody1D, S07_attenuation
from pahfit import units

from specutils import Spectrum1D
from astropy.modeling.physical_models import Drude1D
from astropy.modeling.functional_models import Gaussian1D
from astropy import units as u
from astropy.nddata import StdDevUncertainty

__all__ = ["read_spectrum", "calculate_compounds"]

Expand Down Expand Up @@ -81,8 +84,18 @@ def read_spectrum(specfile, format=None):
else:
tformat = format

return Spectrum1D.read(specfile, format=tformat)
s = Spectrum1D.read(specfile, format=tformat)

# Convert to intensity units by assuming an arbitrary solid angle
# for now. To be removed when dual unit support (intensity and flux
# density) is supported.
if s.flux.unit.is_equivalent(units.flux_density):
solid_angle = (3 * u.arcsec)**2
alt_flux = (s.flux / solid_angle).to(units.intensity)
alt_unc_array = (s.uncertainty.array * s.flux.unit / solid_angle).to(units.intensity)
s = Spectrum1D(alt_flux, s.spectral_axis, uncertainty=StdDevUncertainty(alt_unc_array))

return s

def calculate_compounds(obsdata, pmodel):
"""
Expand Down

0 comments on commit 4573a35

Please sign in to comment.