def setup_sources(model, model_name, sky_model, spectral_type=None):

    global sky_loaded

    # Read in SKY model maps
    if sky_model in sky_loaded:
        print "[%s] Reading %s (cached)" % (model_name, sky_model)
        hdulist = sky_loaded[sky_model]
    else:
        print "[%s] Reading %s" % (model_name, sky_model)
        hdulist = pyfits.open(sky_model)
        sky_loaded[sky_model] = hdulist

    # Set cylindrical grid parameters
    r_wall = hdulist[1].data * kpc
    z_wall = hdulist[2].data * kpc
    p_wall = hdulist[3].data
    model.set_cylindrical_polar_grid(r_wall, z_wall, p_wall)

    # Loop through spectral types
    for ispec in range(n_spec):

        if spectral_type is not None and t_default['Type'][ispec].strip().upper() != spectral_type:
            continue
        else:
            spec_type = t_default['Type'][ispec].strip().upper()

        # Check if full spectrum exists
        if spec_type in ts.tables:
            nu = ts[spec_type]['nu']
            fnu = ts[spec_type]['fnu']
        else:
            nu = c / (filt_wav * 1.e-4)
            fnu = np.array([t_default[band][ispec] for band in filt_name])

        # Sort spectrum
        order = np.argsort(nu)
        nu, fnu = nu[order], fnu[order]

        # Find total luminosity of single object
        l_single = integrate_loglog(nu, fnu)

        # Find number of sources in each cell
        number = hdulist[0].data[ispec, :, :, :]

        # Set up source
        source = model.add_map_source()
        source.luminosity = np.sum(number) * l_single
        source.spectrum = (nu.astype(np.float64), fnu.astype(np.float64))
        source.map = number

    return model
Exemple #2
0
from hyperion.model import ModelOutput
from hyperion.util.integrate import integrate_loglog

# Use LaTeX for plots
plt.rc('text', usetex=True)

# Open the output file
m = ModelOutput('example_isrf.rtout')

# Get an all-sky flux map
image = m.get_image(units='ergs/cm^2/s/Hz', inclination=0)

# Compute the frequency-integrated flux
fint = np.zeros(image.val.shape[:-1])
for (j, i) in np.ndindex(fint.shape):
    fint[j, i] = integrate_loglog(image.nu, image.val[j, i, :])

# Find the area of each pixel
l = np.radians(np.linspace(180., -180., fint.shape[1] + 1))
b = np.radians(np.linspace(-90., 90., fint.shape[0] + 1))
dl = l[1:] - l[:-1]
db = np.sin(b[1:]) - np.sin(b[:-1])
DL, DB = np.meshgrid(dl, db)
area = np.abs(DL * DB)

# Compute the intensity
intensity = fint / area

# Intitialize plot
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection='aitoff')
from hyperion.model import ModelOutput
from hyperion.util.integrate import integrate_loglog

# Use LaTeX for plots
plt.rc('text', usetex=True)

# Open the output file
m = ModelOutput('example_isrf.rtout')

# Get an all-sky flux map
image = m.get_image(units='ergs/cm^2/s/Hz', inclination=0)

# Compute the frequency-integrated flux
fint = np.zeros(image.val.shape[:-1])
for (j, i) in np.ndindex(fint.shape):
    fint[j, i] = integrate_loglog(image.nu, image.val[j, i, :])

# Find the area of each pixel
l = np.radians(np.linspace(180., -180., fint.shape[1] + 1))
b = np.radians(np.linspace(-90., 90., fint.shape[0] + 1))
dl = l[1:] - l[:-1]
db = np.sin(b[1:]) - np.sin(b[:-1])
DL, DB = np.meshgrid(dl, db)
area = np.abs(DL * DB)

# Compute the intensity
intensity = fint / area

# Intitialize plot
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection='aitoff')
from hyperion.util.integrate import integrate_loglog

# Use LaTeX for plots
plt.rc('text', usetex=True)

# Open the output file
m = ModelOutput('example_isrf.rtout')

# Get an all-sky flux map
wav, fnu = m.get_image(units='ergs/cm^2/s/Hz', inclination=0)
nu = c / (wav * 1.e-4)

# Compute the frequency-integrated flux
fint = np.zeros(fnu.shape[:-1])
for (j, i) in np.ndindex(fint.shape):
    fint[j, i] = integrate_loglog(nu, fnu[j, i, :])

# Find the area of each pixel
l = np.radians(np.linspace(180., -180., fint.shape[1] + 1))
b = np.radians(np.linspace(-90., 90., fint.shape[0] + 1))
dl = l[1:] - l[:-1]
db = np.sin(b[1:]) - np.sin(b[:-1])
DL, DB = np.meshgrid(dl, db)
area = np.abs(DL * DB)

# Compute the intensity
intensity = fint / area

# Intitialize plot
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection='aitoff')