From 0cd5c7282542156e50d309020ea66907abd8fe49 Mon Sep 17 00:00:00 2001 From: Arne Wouters Date: Sat, 16 Apr 2022 09:43:10 +0200 Subject: [PATCH 1/2] Rename T to temperature --- tardis/analysis/opacities.py | 6 +++--- tardis/montecarlo/base.py | 4 ++-- .../montecarlo/montecarlo_numba/formal_integral.py | 6 +++--- .../montecarlo_numba/formal_integral_cuda.py | 8 ++++---- .../tests/test_cuda_formal_integral.py | 12 ++++++------ .../tests/test_numba_formal_integral.py | 8 ++++---- tardis/montecarlo/packet_source.py | 14 ++++++-------- tardis/util/base.py | 6 +++--- 8 files changed, 31 insertions(+), 33 deletions(-) diff --git a/tardis/analysis/opacities.py b/tardis/analysis/opacities.py index 09d4f04c8db..6aaf9b21ed0 100644 --- a/tardis/analysis/opacities.py +++ b/tardis/analysis/opacities.py @@ -372,14 +372,14 @@ def _calc_planck_mean_opacity(self): for i in range(self.nshells): delta_nu = self.nu_bins[1:] - self.nu_bins[:-1] - T = self.mdl.plasma.t_rad[i] + temperature = self.mdl.plasma.t_rad[i] tmp = ( - blackbody_nu(self.nu_bins[:-1], T) + blackbody_nu(self.nu_bins[:-1], temperature) * delta_nu * self.kappa_tot[:, 0] ).sum() - tmp /= (blackbody_nu(self.nu_bins[:-1], T) * delta_nu).sum() + tmp /= (blackbody_nu(self.nu_bins[:-1], temperature) * delta_nu).sum() kappa_planck_mean[i] = tmp diff --git a/tardis/montecarlo/base.py b/tardis/montecarlo/base.py index a4d4d35b831..39156ae7871 100644 --- a/tardis/montecarlo/base.py +++ b/tardis/montecarlo/base.py @@ -203,7 +203,7 @@ def _initialize_geometry_arrays(self, model): self.r_outer_cgs = model.r_outer.to("cm").value self.v_inner_cgs = model.v_inner.to("cm/s").value - def _initialize_packets(self, T, no_of_packets, iteration, radius): + def _initialize_packets(self, temperature, no_of_packets, iteration, radius): # the iteration is added each time to preserve randomness # across different simulations with the same temperature, # for example. We seed the random module instead of the numpy module @@ -213,7 +213,7 @@ def _initialize_packets(self, T, no_of_packets, iteration, radius): rng = np.random.default_rng(seed=seed) seeds = rng.choice(MAX_SEED_VAL, no_of_packets, replace=True) radii, nus, mus, energies = self.packet_source.create_packets( - T, no_of_packets, rng, radius + temperature, no_of_packets, rng, radius ) mc_config_module.packet_seeds = seeds self.input_r = radii diff --git a/tardis/montecarlo/montecarlo_numba/formal_integral.py b/tardis/montecarlo/montecarlo_numba/formal_integral.py index 70f82ef626d..81efffbf124 100644 --- a/tardis/montecarlo/montecarlo_numba/formal_integral.py +++ b/tardis/montecarlo/montecarlo_numba/formal_integral.py @@ -697,12 +697,12 @@ def trapezoid_integration(array, h): @njit(**njit_dict_no_parallel) -def intensity_black_body(nu, T): +def intensity_black_body(nu, temperature): """Get the black body intensity at frequency nu - and temperature T""" + and temperature""" if nu == 0: return np.nan # to avoid ZeroDivisionError - beta_rad = 1 / (KB_CGS * T) + beta_rad = 1 / (KB_CGS * temperature) coefficient = 2 * H_CGS * C_INV * C_INV return coefficient * nu * nu * nu / (np.exp(H_CGS * nu * beta_rad) - 1) diff --git a/tardis/montecarlo/montecarlo_numba/formal_integral_cuda.py b/tardis/montecarlo/montecarlo_numba/formal_integral_cuda.py index 5ecb1d38444..c9abfccff03 100644 --- a/tardis/montecarlo/montecarlo_numba/formal_integral_cuda.py +++ b/tardis/montecarlo/montecarlo_numba/formal_integral_cuda.py @@ -474,15 +474,15 @@ def trapezoid_integration_cuda(arr, dx): @cuda.jit(device=True) -def intensity_black_body_cuda(nu, T): +def intensity_black_body_cuda(nu, temperature): """ Get the black body intensity at frequency nu - and temperature T + and temperature Parameters ---------- nu : float64 - T : float64 + temperature : float64 Returns ------- @@ -490,7 +490,7 @@ def intensity_black_body_cuda(nu, T): """ if nu == 0: return np.nan # to avoid ZeroDivisionError - beta_rad = 1 / (KB_CGS * T) + beta_rad = 1 / (KB_CGS * temperature) coefficient = 2 * H_CGS * C_INV * C_INV return coefficient * nu * nu * nu / (math.exp(H_CGS * nu * beta_rad) - 1) diff --git a/tardis/montecarlo/montecarlo_numba/tests/test_cuda_formal_integral.py b/tardis/montecarlo/montecarlo_numba/tests/test_cuda_formal_integral.py index 054a444d0a6..f091e6c1166 100644 --- a/tardis/montecarlo/montecarlo_numba/tests/test_cuda_formal_integral.py +++ b/tardis/montecarlo/montecarlo_numba/tests/test_cuda_formal_integral.py @@ -31,14 +31,14 @@ not GPUs_available, reason="No GPU is available to test CUDA function" ) @pytest.mark.parametrize( - ["nu", "T"], + ["nu", "temperature"], [ (1e14, 1e4), (0, 1), (1, 1), ], ) -def test_intensity_black_body_cuda(nu, T): +def test_intensity_black_body_cuda(nu, temperature): """ Initializes the test of the cuda version against the numba implementation of the @@ -46,21 +46,21 @@ def test_intensity_black_body_cuda(nu, T): is done as both results have 15 digits of precision. """ actual = np.zeros(3) - black_body_caller[1, 3](nu, T, actual) + black_body_caller[1, 3](nu, temperature, actual) - expected = formal_integral_numba.intensity_black_body(nu, T) + expected = formal_integral_numba.intensity_black_body(nu, temperature) ntest.assert_allclose(actual, expected, rtol=1e-14) @cuda.jit -def black_body_caller(nu, T, actual): +def black_body_caller(nu, temperature, actual): """ This calls the CUDA function and fills out the array """ x = cuda.grid(1) - actual[x] = formal_integral_cuda.intensity_black_body_cuda(nu, T) + actual[x] = formal_integral_cuda.intensity_black_body_cuda(nu, temperature) @pytest.mark.skipif( diff --git a/tardis/montecarlo/montecarlo_numba/tests/test_numba_formal_integral.py b/tardis/montecarlo/montecarlo_numba/tests/test_numba_formal_integral.py index a20657a3d7c..559d05e1c7b 100644 --- a/tardis/montecarlo/montecarlo_numba/tests/test_numba_formal_integral.py +++ b/tardis/montecarlo/montecarlo_numba/tests/test_numba_formal_integral.py @@ -10,18 +10,18 @@ from tardis.montecarlo.montecarlo_numba.numba_interface import NumbaModel @pytest.mark.parametrize( - ["nu", "T"], + ["nu", "temperature"], [ (1e14, 1e4), (0, 1), (1, 1), ], ) -def test_intensity_black_body(nu, T): +def test_intensity_black_body(nu, temperature): func = formal_integral.intensity_black_body - actual = func(nu, T) + actual = func(nu, temperature) print(actual, type(actual)) - expected = intensity_black_body(nu, T) + expected = intensity_black_body(nu, temperature) ntest.assert_almost_equal(actual, expected) diff --git a/tardis/montecarlo/packet_source.py b/tardis/montecarlo/packet_source.py index d801f3e39bb..a8a4a1191b0 100644 --- a/tardis/montecarlo/packet_source.py +++ b/tardis/montecarlo/packet_source.py @@ -53,7 +53,7 @@ def create_uniform_packet_energies(no_of_packets, rng): return np.ones(no_of_packets) / no_of_packets @staticmethod - def create_blackbody_packet_nus(T, no_of_packets, rng, l_samples=1000): + def create_blackbody_packet_nus(temperature, no_of_packets, rng, l_samples=1000): """ Create packet :math:`\\nu` distributed using the algorithm described in Bjorkman & Wood 2001 (page 4) which references @@ -76,8 +76,7 @@ def create_blackbody_packet_nus(T, no_of_packets, rng, l_samples=1000): Parameters ---------- - T : float - temperature + temperature : float no_of_packets : int l_samples : int number of l_samples needed in the algorithm @@ -100,7 +99,7 @@ def create_blackbody_packet_nus(T, no_of_packets, rng, l_samples=1000): xis_prod = np.prod(xis[1:], 0) x = ne.evaluate("-log(xis_prod)/l") - return x * (const.k_B.cgs.value * T) / const.h.cgs.value + return x * (const.k_B.cgs.value * temperature) / const.h.cgs.value class BlackBodySimpleSource(BasePacketSource): @@ -109,13 +108,12 @@ class BlackBodySimpleSource(BasePacketSource): part. """ - def create_packets(self, T, no_of_packets, rng, radius): + def create_packets(self, temperature, no_of_packets, rng, radius): """Generate black-body packet properties as arrays Parameters ---------- - T : float64 - Temperature + temperature : float64 no_of_packets : int Number of packets rng : numpy random number generator @@ -134,7 +132,7 @@ def create_packets(self, T, no_of_packets, rng, radius): Packet energies """ radii = np.ones(no_of_packets) * radius - nus = self.create_blackbody_packet_nus(T, no_of_packets, rng) + nus = self.create_blackbody_packet_nus(temperature, no_of_packets, rng) mus = self.create_zero_limb_darkening_packet_mus(no_of_packets, rng) energies = self.create_uniform_packet_energies(no_of_packets, rng) diff --git a/tardis/util/base.py b/tardis/util/base.py index cd2a3f326ac..9481384d182 100644 --- a/tardis/util/base.py +++ b/tardis/util/base.py @@ -285,7 +285,7 @@ def create_synpp_yaml(radial1d_mdl, fname, shell_no=0, lines_db=None): yaml.dump(yaml_reference, stream=f, explicit_start=True) -def intensity_black_body(nu, T): +def intensity_black_body(nu, temperature): """ Calculate the intensity of a black-body according to the following formula @@ -297,7 +297,7 @@ def intensity_black_body(nu, T): ---------- nu : float Frequency of light - T : float + temperature : float Temperature in kelvin Returns @@ -305,7 +305,7 @@ def intensity_black_body(nu, T): Intensity : float Returns the intensity of the black body """ - beta_rad = 1 / (k_B_cgs * T) + beta_rad = 1 / (k_B_cgs * temperature) coefficient = 2 * h_cgs / c_cgs**2 intensity = ne.evaluate( "coefficient * nu**3 / " "(exp(h_cgs * nu * beta_rad) -1 )" From daec056a6fecaf10673f0964941624b7f4f94ecb Mon Sep 17 00:00:00 2001 From: Arne Wouters Date: Sat, 16 Apr 2022 21:04:30 +0200 Subject: [PATCH 2/2] Rename T to temperature --- tardis/montecarlo/montecarlo_numba/interaction.py | 4 ++-- tardis/plasma/properties/continuum_processes.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tardis/montecarlo/montecarlo_numba/interaction.py b/tardis/montecarlo/montecarlo_numba/interaction.py index 0b96f7ab508..f1a94e3c066 100644 --- a/tardis/montecarlo/montecarlo_numba/interaction.py +++ b/tardis/montecarlo/montecarlo_numba/interaction.py @@ -113,9 +113,9 @@ def sample_nu_free_free(numba_plasma, shell): Frequency of the free-free emission process """ - T = numba_plasma.t_electrons[shell] + temperature = numba_plasma.t_electrons[shell] zrand = np.random.random() - return -K_B * T / H * np.log(zrand) + return -K_B * temperature / H * np.log(zrand) @njit(**njit_dict_no_parallel) def sample_nu_free_bound(numba_plasma, shell, continuum_id): diff --git a/tardis/plasma/properties/continuum_processes.py b/tardis/plasma/properties/continuum_processes.py index b7262426be3..5928a0b8dd2 100644 --- a/tardis/plasma/properties/continuum_processes.py +++ b/tardis/plasma/properties/continuum_processes.py @@ -988,9 +988,9 @@ def calculate(self, t_electrons): @njit(error_model="numpy", fastmath=True) def nu_ff(shell): - T = t_electrons[shell] + temperature = t_electrons[shell] zrand = np.random.random() - return -K_B * T / H * np.log(zrand) + return -K_B * temperature / H * np.log(zrand) return nu_ff