Skip to content

Commit

Permalink
Change name of blackbody function. Hook up RadiationField.source_func…
Browse files Browse the repository at this point in the history
…tion to raytrace.
  • Loading branch information
jvshields committed Aug 17, 2023
1 parent 1073f45 commit 3961af2
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 20 deletions.
10 changes: 5 additions & 5 deletions stardis/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ def run_stardis(config_fname, tracing_lambdas_or_nus):

if True: # change to checking source function from config
from stardis.radiation_field.source_functions.blackbody import (
bb_nu,
blackbody_flux_at_nu,
)

stellar_radiation_field = RadiationField(tracing_nus, bb_nu, stellar_model)
stellar_radiation_field = RadiationField(tracing_nus, blackbody_flux_at_nu, stellar_model)

calc_alphas(
stellar_plasma=stellar_plasma,
Expand All @@ -92,9 +92,9 @@ def run_stardis(config_fname, tracing_lambdas_or_nus):
return STARDISOutput(
stellar_plasma,
stellar_model,
stellar_radiation_field.opacities.opacities,
stellar_radiation_field.opacities.opacities["alpha_line_at_nu_gammas"],
stellar_radiation_field.opacities.opacities["alpha_line_at_nu_doppler_widths"],
stellar_radiation_field.opacities.opacities_dict,
stellar_radiation_field.opacities.opacities_dict["alpha_line_at_nu_gammas"],
stellar_radiation_field.opacities.opacities_dict["alpha_line_at_nu_doppler_widths"],
stellar_radiation_field.F_nu,
stellar_radiation_field.frequencies,
)
Expand Down
1 change: 1 addition & 0 deletions stardis/radiation_field/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class RadiationField:
"""
Class containing information about the radiation field.
###TODO Radiation field temperature should be a separate attribute, for the case of differing gas and radiation.
###TODO Implement a source function class. Doesn't need to be done until we have another source function than just blackbody.
Parameters
----------
Expand Down
7 changes: 3 additions & 4 deletions stardis/radiation_field/opacities/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@ class Opacities:
"""
Holds opacity information.
###TODO: Change to dict that holds each of the sources of opacity separately. Then have a method that combines them all to return the total opacity.
Paramaters
----------
opacities : dict
opacities_dict : dict
Python dictionary to contain each of the sources of opacity by name as well as their contribution at each frequency specified in the radiation field.
total_alphas : numpy.ndarray
Array of the total opacity at each frequency specified in the radiation field at each depth points.
Added as an attribute when calc_total_alphas() is called.
"""

def __init__(self):
self.opacities = {}
self.opacities_dict = {}

###TODO: Better implementation for this
def calc_total_alphas(self):
for i, item in enumerate(self.opacities.items()):
for i, item in enumerate(self.opacities_dict.items()):
if "gammas" not in item[0] and "doppler" not in item[0]:
if i == 0:
self.total_alphas = item[1]
Expand Down
16 changes: 8 additions & 8 deletions stardis/radiation_field/opacities/opacities_solvers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,49 +560,49 @@ def calc_alphas(
stellar_radiation_field.frequencies,
opacity_config.file,
)
stellar_radiation_field.opacities.opacities["alpha_file"] = alpha_file
stellar_radiation_field.opacities.opacities_dict["alpha_file"] = alpha_file

alpha_bf = calc_alpha_bf(
stellar_plasma,
stellar_model,
stellar_radiation_field.frequencies,
opacity_config.bf,
)
stellar_radiation_field.opacities.opacities["alpha_bf"] = alpha_bf
stellar_radiation_field.opacities.opacities_dict["alpha_bf"] = alpha_bf

alpha_ff = calc_alpha_ff(
stellar_plasma,
stellar_model,
stellar_radiation_field.frequencies,
opacity_config.ff,
)
stellar_radiation_field.opacities.opacities["alpha_ff"] = alpha_ff
stellar_radiation_field.opacities.opacities_dict["alpha_ff"] = alpha_ff

alpha_rayleigh = calc_alpha_rayleigh(
stellar_plasma,
stellar_model,
stellar_radiation_field.frequencies,
opacity_config.rayleigh,
)
stellar_radiation_field.opacities.opacities["alpha_rayleigh"] = alpha_rayleigh
stellar_radiation_field.opacities.opacities_dict["alpha_rayleigh"] = alpha_rayleigh

alpha_electron = calc_alpha_electron(
stellar_plasma,
stellar_model,
stellar_radiation_field.frequencies,
opacity_config.disable_electron_scattering,
)
stellar_radiation_field.opacities.opacities["alpha_electron"] = alpha_electron
stellar_radiation_field.opacities.opacities_dict["alpha_electron"] = alpha_electron

alpha_line_at_nu, gammas, doppler_widths = calc_alpha_line_at_nu(
stellar_plasma,
stellar_model,
stellar_radiation_field.frequencies,
opacity_config.line,
)
stellar_radiation_field.opacities.opacities["alpha_line_at_nu"] = alpha_line_at_nu
stellar_radiation_field.opacities.opacities["alpha_line_at_nu_gammas"] = gammas
stellar_radiation_field.opacities.opacities[
stellar_radiation_field.opacities.opacities_dict["alpha_line_at_nu"] = alpha_line_at_nu
stellar_radiation_field.opacities.opacities_dict["alpha_line_at_nu_gammas"] = gammas
stellar_radiation_field.opacities.opacities_dict[
"alpha_line_at_nu_doppler_widths"
] = doppler_widths
alphas = stellar_radiation_field.opacities.calc_total_alphas()
Expand Down
7 changes: 5 additions & 2 deletions stardis/radiation_field/radiation_field_solvers/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numba
import numpy as np
from stardis.radiation_field.source_functions.blackbody import bb_nu
# from stardis.radiation_field.source_functions.blackbody import blackbody_flux_at_nu


@numba.njit
Expand Down Expand Up @@ -41,6 +41,7 @@ def single_theta_trace(
alphas,
tracing_nus,
theta,
source_function
):
"""
Performs ray tracing at an angle following van Noort 2001 eq 14.
Expand Down Expand Up @@ -71,7 +72,8 @@ def single_theta_trace(
taus = mean_alphas.T * geometry_dist_to_next_depth_point / np.cos(theta)
no_of_depth_gaps = len(geometry_dist_to_next_depth_point)

source = bb_nu(tracing_nus, temps)
###TODO: Generalize this for source functions other than blackbody that may require args other than frequency and temperature
source = source_function(tracing_nus, temps)
delta_source = source[1:] - source[:-1]
I_nu_theta = np.ones((no_of_depth_gaps + 1, len(tracing_nus))) * np.nan
I_nu_theta[0] = source[0] # the innermost depth point is the photosphere
Expand Down Expand Up @@ -145,6 +147,7 @@ def raytrace(stellar_model, stellar_radiation_field, no_of_thetas=20):
stellar_radiation_field.opacities.total_alphas,
stellar_radiation_field.frequencies,
theta,
stellar_radiation_field.source_function
)

return stellar_radiation_field.F_nu
2 changes: 1 addition & 1 deletion stardis/radiation_field/source_functions/blackbody.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


@numba.njit
def bb_nu(tracing_nus, temps):
def blackbody_flux_at_nu(tracing_nus, temps):
"""
Planck blackbody intensity distribution w.r.t. frequency.
Expand Down

0 comments on commit 3961af2

Please sign in to comment.