From de4d8727239db47100b90632916ced19e9df6f05 Mon Sep 17 00:00:00 2001 From: Atharva Arya <55894364+atharva-2001@users.noreply.github.com> Date: Wed, 25 Sep 2024 22:54:00 +0530 Subject: [PATCH] Ruff `tardis/transport` (#2829) * ruff autofix tardis/transport safe fixes * ruff autofix tardis/transport unsafe fixes * fix ruff unsafe rule PIE790 * black 2 files --------- Co-authored-by: Andrew Fullard --- tardis/transport/frame_transformations.py | 1 - .../transport/geometry/calculate_distances.py | 9 +-------- tardis/transport/montecarlo/__init__.py | 6 +++--- tardis/transport/montecarlo/base.py | 8 ++++---- .../transport/montecarlo/configuration/base.py | 7 +++---- .../estimators/radfield_estimator_calcs.py | 8 ++++---- tardis/transport/montecarlo/interaction.py | 10 +++++----- tardis/transport/montecarlo/macro_atom.py | 5 +++-- .../transport/montecarlo/nonhomologous_grid.py | 11 ++++++----- tardis/transport/montecarlo/numba_interface.py | 7 +++---- tardis/transport/montecarlo/packet_source.py | 9 ++++----- tardis/transport/montecarlo/packet_trackers.py | 17 ++++++++--------- tardis/transport/montecarlo/r_packet.py | 12 +++++------- .../transport/montecarlo/single_packet_loop.py | 2 +- tardis/transport/montecarlo/tests/test_base.py | 4 ---- .../montecarlo/tests/test_interaction.py | 5 +++-- .../montecarlo/tests/test_macro_atom.py | 2 +- .../montecarlo/tests/test_montecarlo.py | 11 +++++------ .../tests/test_montecarlo_main_loop.py | 2 +- .../montecarlo/tests/test_numba_interface.py | 7 ++++--- .../montecarlo/tests/test_opacities.py | 2 +- .../transport/montecarlo/tests/test_packet.py | 10 ++-------- .../montecarlo/tests/test_packet_source.py | 6 +----- .../test_rpacket_last_interaction_tracker.py | 4 ++-- .../montecarlo/tests/test_rpacket_tracker.py | 5 ++--- .../montecarlo/tests/test_single_packet_loop.py | 7 +++---- .../montecarlo/tests/test_tracker_utils.py | 5 ++--- .../transport/montecarlo/tests/test_vpacket.py | 6 ++---- .../tests/test_weighted_packet_source.py | 7 +------ tardis/transport/montecarlo/utils.py | 1 + .../montecarlo/weighted_packet_source.py | 5 ----- tardis/transport/tests/test_doppler_factor.py | 7 ++----- 32 files changed, 83 insertions(+), 125 deletions(-) diff --git a/tardis/transport/frame_transformations.py b/tardis/transport/frame_transformations.py index 9813664b98a..cb81684580c 100644 --- a/tardis/transport/frame_transformations.py +++ b/tardis/transport/frame_transformations.py @@ -5,7 +5,6 @@ from tardis.transport.montecarlo import ( njit_dict_no_parallel, ) - from tardis.transport.montecarlo.configuration.constants import C_SPEED_OF_LIGHT diff --git a/tardis/transport/geometry/calculate_distances.py b/tardis/transport/geometry/calculate_distances.py index 02b1c13cb2b..ed5e29c93ad 100644 --- a/tardis/transport/geometry/calculate_distances.py +++ b/tardis/transport/geometry/calculate_distances.py @@ -5,18 +5,13 @@ from tardis.transport.montecarlo import ( njit_dict_no_parallel, ) - from tardis.transport.montecarlo.configuration.constants import ( C_SPEED_OF_LIGHT, + CLOSE_LINE_THRESHOLD, MISS_DISTANCE, SIGMA_THOMSON, - CLOSE_LINE_THRESHOLD, ) - from tardis.transport.montecarlo.utils import MonteCarloException -from tardis.transport.montecarlo.r_packet import ( - print_r_packet_properties, -) @njit(**njit_dict_no_parallel) @@ -35,7 +30,6 @@ def calculate_distance_boundary(r, mu, r_inner, r_outer): r_outer : float outer radius of current shell """ - delta_shell = 0 if mu > 0.0: # direction outward @@ -88,7 +82,6 @@ def calculate_distance_line( Returns ------- """ - nu = r_packet.nu if is_last_line: diff --git a/tardis/transport/montecarlo/__init__.py b/tardis/transport/montecarlo/__init__.py index 23913353290..8cb07e87401 100644 --- a/tardis/transport/montecarlo/__init__.py +++ b/tardis/transport/montecarlo/__init__.py @@ -1,9 +1,9 @@ """ -Faciliating the MonteCarlo iterations. +Faciliating the MonteCarlo iterations. During a simulation run, a number of MonteCarlo iterations specified in the configuration are run using the numba compiler. -Most of the iterations are used to calculate the steady-state plasma +Most of the iterations are used to calculate the steady-state plasma properties and with the last iteration, the spectrum is determined. """ @@ -21,7 +21,7 @@ "parallel": False, } -from tardis.transport.montecarlo.r_packet import RPacket from tardis.transport.montecarlo.packet_collections import ( PacketCollection, ) +from tardis.transport.montecarlo.r_packet import RPacket diff --git a/tardis/transport/montecarlo/base.py b/tardis/transport/montecarlo/base.py index d366e09b448..5fac3521335 100644 --- a/tardis/transport/montecarlo/base.py +++ b/tardis/transport/montecarlo/base.py @@ -7,6 +7,9 @@ from tardis import constants as const from tardis.io.logger import montecarlo_tracking as mc_tracker from tardis.io.util import HDFWriterMixin +from tardis.opacities.opacity_state import ( + opacity_state_to_numba, +) from tardis.transport.montecarlo.configuration.base import ( MonteCarloConfiguration, configuration_initialize, @@ -23,12 +26,9 @@ from tardis.transport.montecarlo.montecarlo_transport_state import ( MonteCarloTransportState, ) -from tardis.opacities.opacity_state import ( - opacity_state_to_numba, -) from tardis.transport.montecarlo.packet_trackers import ( - generate_rpacket_tracker_list, generate_rpacket_last_interaction_tracker_list, + generate_rpacket_tracker_list, rpacket_trackers_to_dataframe, ) from tardis.util.base import ( diff --git a/tardis/transport/montecarlo/configuration/base.py b/tardis/transport/montecarlo/configuration/base.py index 6a90fce53cf..0d5d7c409b3 100644 --- a/tardis/transport/montecarlo/configuration/base.py +++ b/tardis/transport/montecarlo/configuration/base.py @@ -1,10 +1,9 @@ +import numpy as np from astropy import units as u -from numba import float64, int64, boolean +from numba import boolean, float64, int64 from numba.experimental import jitclass -import numpy as np from tardis.transport.montecarlo.configuration import montecarlo_globals -from tardis.transport.montecarlo import montecarlo_main_loop from tardis.transport.montecarlo.numba_interface import ( LineInteractionType, ) @@ -29,7 +28,7 @@ @jitclass(numba_config_spec) -class MonteCarloConfiguration(object): +class MonteCarloConfiguration: def __init__(self): self.ENABLE_FULL_RELATIVITY = False self.TEMPORARY_V_PACKET_BINS = 0 diff --git a/tardis/transport/montecarlo/estimators/radfield_estimator_calcs.py b/tardis/transport/montecarlo/estimators/radfield_estimator_calcs.py index 6be62d7af0c..0e20f3a15bb 100644 --- a/tardis/transport/montecarlo/estimators/radfield_estimator_calcs.py +++ b/tardis/transport/montecarlo/estimators/radfield_estimator_calcs.py @@ -2,14 +2,14 @@ from numba import njit -from tardis.transport.montecarlo import ( - njit_dict_no_parallel, -) -from tardis.transport.montecarlo.configuration.constants import KB, H from tardis.transport.frame_transformations import ( calc_packet_energy, calc_packet_energy_full_relativity, ) +from tardis.transport.montecarlo import ( + njit_dict_no_parallel, +) +from tardis.transport.montecarlo.configuration.constants import KB, H @njit(**njit_dict_no_parallel) diff --git a/tardis/transport/montecarlo/interaction.py b/tardis/transport/montecarlo/interaction.py index 677780fda54..78b852e8012 100644 --- a/tardis/transport/montecarlo/interaction.py +++ b/tardis/transport/montecarlo/interaction.py @@ -3,6 +3,11 @@ import tardis.transport.montecarlo.configuration.montecarlo_globals as montecarlo_globals from tardis import constants as const +from tardis.transport.frame_transformations import ( + angle_aberration_CMF_to_LF, + get_doppler_factor, + get_inverse_doppler_factor, +) from tardis.transport.montecarlo import njit_dict_no_parallel from tardis.transport.montecarlo.macro_atom import ( MacroAtomTransitionType, @@ -15,11 +20,6 @@ PacketStatus, ) from tardis.transport.montecarlo.utils import get_random_mu -from tardis.transport.frame_transformations import ( - angle_aberration_CMF_to_LF, - get_doppler_factor, - get_inverse_doppler_factor, -) K_B = const.k_B.cgs.value H = const.h.cgs.value diff --git a/tardis/transport/montecarlo/macro_atom.py b/tardis/transport/montecarlo/macro_atom.py index c1864486bd8..81c2ab528a4 100644 --- a/tardis/transport/montecarlo/macro_atom.py +++ b/tardis/transport/montecarlo/macro_atom.py @@ -1,8 +1,9 @@ -import numpy as np from enum import IntEnum +import numpy as np from numba import njit -from tardis.transport.montecarlo import njit_dict, njit_dict_no_parallel + +from tardis.transport.montecarlo import njit_dict_no_parallel class MacroAtomError(ValueError): diff --git a/tardis/transport/montecarlo/nonhomologous_grid.py b/tardis/transport/montecarlo/nonhomologous_grid.py index 05b681a91f7..bcefebcf633 100644 --- a/tardis/transport/montecarlo/nonhomologous_grid.py +++ b/tardis/transport/montecarlo/nonhomologous_grid.py @@ -17,7 +17,7 @@ def velocity_dvdr(r_packet, geometry): geometry: Geometry Returns - ----------- + ------- v: float, current velocity frac: float, dv/dr for current shell """ @@ -37,16 +37,16 @@ def tau_sobolev_factor(r_packet, geometry): The angle and velocity dependent Tau Sobolev factor component. Is called when ENABLE_NONHOMOLOGOUS_EXPANSION is set to True. Note: to get Tau Sobolev, this needs to be multiplied by tau_sobolevs found from plasma + Parameters ---------- r_packet: RPacket geometry: Geometry Returns - ----------- + ------- factor = 1.0 / ((1 - mu * mu) * v / r + mu * mu * dvdr) """ - v, dvdr = velocity_dvdr(r_packet, geometry) r = r_packet.r mu = r_packet.mu @@ -61,11 +61,12 @@ def quartic_roots(a, b, c, d, e, threshold): Uses: https://en.wikipedia.org/wiki/Quartic_function#General_formula_for_roots Parameters - ----------- + ---------- a, b, c, d, e: coefficients of the equations ax^4 + bx^3 + cx^2 + dx + e = 0, float threshold: lower needed limit on roots, float + Returns - ----------- + ------- roots: real positive roots of ax^4 + bx^3 + cx^2 + dx + e = 0 """ diff --git a/tardis/transport/montecarlo/numba_interface.py b/tardis/transport/montecarlo/numba_interface.py index d6db1e12e3e..d6f54d8c8d9 100644 --- a/tardis/transport/montecarlo/numba_interface.py +++ b/tardis/transport/montecarlo/numba_interface.py @@ -37,7 +37,7 @@ @jitclass(opacity_state_spec) -class OpacityState(object): +class OpacityState: def __init__( self, electron_density, @@ -80,7 +80,6 @@ def __init__( transition_line_id : numpy.ndarray bf_threshold_list_nu : numpy.ndarray """ - self.electron_density = electron_density self.t_electrons = t_electrons self.line_list_nu = line_list_nu @@ -118,7 +117,8 @@ def __getitem__(self, i: slice): Args: i (slice): shell slice. Will fail if slice is int since class only supports array types - Returns: + Returns + ------- OpacityState : a shallow copy of the current instance """ # NOTE: This currently will not work with continuum processes since it does not slice those arrays @@ -161,7 +161,6 @@ def opacity_state_initialize( plasma : tardis.plasma.BasePlasma line_interaction_type : enum """ - electron_densities = plasma.electron_densities.values t_electrons = plasma.t_electrons line_list_nu = plasma.atomic_data.lines.nu.values diff --git a/tardis/transport/montecarlo/packet_source.py b/tardis/transport/montecarlo/packet_source.py index 9d0b3088522..9e9410e3a4c 100644 --- a/tardis/transport/montecarlo/packet_source.py +++ b/tardis/transport/montecarlo/packet_source.py @@ -1,13 +1,14 @@ import abc -import numpy as np import numexpr as ne +import numpy as np +from astropy import units as u + from tardis import constants as const +from tardis.io.util import HDFWriterMixin from tardis.transport.montecarlo.packet_collections import ( PacketCollection, ) -from tardis.io.util import HDFWriterMixin -from astropy import units as u class BasePacketSource(abc.ABC): @@ -239,7 +240,6 @@ def create_packet_mus(self, no_of_packets): Directions for packets numpy.ndarray """ - # For testing purposes if self.legacy_mode_enabled: return np.sqrt(np.random.random(no_of_packets)) @@ -269,7 +269,6 @@ def set_temperature_from_luminosity(self, luminosity: u.Quantity): Parameters ---------- - luminosity : u.Quantity """ diff --git a/tardis/transport/montecarlo/packet_trackers.py b/tardis/transport/montecarlo/packet_trackers.py index 20db5244de6..baf0167e605 100644 --- a/tardis/transport/montecarlo/packet_trackers.py +++ b/tardis/transport/montecarlo/packet_trackers.py @@ -1,9 +1,8 @@ -from numba import float64, int64, njit, from_dtype -from numba.experimental import jitclass -from numba.typed import List import numpy as np import pandas as pd - +from numba import float64, from_dtype, int64, njit +from numba.experimental import jitclass +from numba.typed import List boundary_interaction_dtype = np.dtype( [ @@ -33,9 +32,10 @@ @jitclass(rpacket_tracker_spec) -class RPacketTracker(object): +class RPacketTracker: """ Numba JITCLASS for storing the information for each interaction a RPacket instance undergoes. + Parameters ---------- length : int @@ -200,7 +200,7 @@ def rpacket_trackers_to_dataframe(rpacket_trackers): rpacket_tracker_ndarray[column_name][ prev_index:cur_index ] = getattr(rpacket_tracker, column_name) - index_array[0][prev_index:cur_index] = getattr(rpacket_tracker, "index") + index_array[0][prev_index:cur_index] = rpacket_tracker.index index_array[1][prev_index:cur_index] = range(cur_index - prev_index) return pd.DataFrame( rpacket_tracker_ndarray, @@ -220,9 +220,10 @@ def rpacket_trackers_to_dataframe(rpacket_trackers): @jitclass(rpacket_last_interaction_tracker_spec) -class RPacketLastInteractionTracker(object): +class RPacketLastInteractionTracker: """ Numba JITCLASS for storing the last interaction the RPacket undergoes. + Parameters ---------- index : int @@ -265,14 +266,12 @@ def finalize_array(self): """ Added to make RPacketLastInteractionTracker compatible with RPacketTracker """ - pass # To make it compatible with RPacketTracker def track_boundary_interaction(self, current_shell_id, next_shell_id): """ Added to make RPacketLastInteractionTracker compatible with RPacketTracker """ - pass @njit diff --git a/tardis/transport/montecarlo/r_packet.py b/tardis/transport/montecarlo/r_packet.py index 038468afcac..55c28ae6504 100644 --- a/tardis/transport/montecarlo/r_packet.py +++ b/tardis/transport/montecarlo/r_packet.py @@ -1,17 +1,15 @@ from enum import IntEnum import numpy as np -import pandas as pd -from numba import int64, float64, njit, objmode +from numba import float64, int64, njit, objmode from numba.experimental import jitclass -from tardis.transport.montecarlo import ( - njit_dict_no_parallel, -) from tardis.transport.frame_transformations import ( get_doppler_factor, ) -from tardis.transport.montecarlo import njit_dict_no_parallel +from tardis.transport.montecarlo import ( + njit_dict_no_parallel, +) class InteractionType(IntEnum): @@ -48,7 +46,7 @@ class PacketStatus(IntEnum): @jitclass(rpacket_spec) -class RPacket(object): +class RPacket: def __init__(self, r, mu, nu, energy, seed, index=0): self.r = r self.mu = mu diff --git a/tardis/transport/montecarlo/single_packet_loop.py b/tardis/transport/montecarlo/single_packet_loop.py index 2871a5bac48..73ab86d3599 100644 --- a/tardis/transport/montecarlo/single_packet_loop.py +++ b/tardis/transport/montecarlo/single_packet_loop.py @@ -9,7 +9,6 @@ get_doppler_factor, get_inverse_doppler_factor, ) -from tardis.transport.montecarlo.r_packet import RPacket from tardis.transport.montecarlo.configuration import montecarlo_globals from tardis.transport.montecarlo.estimators.radfield_estimator_calcs import ( update_bound_free_estimators, @@ -22,6 +21,7 @@ from tardis.transport.montecarlo.r_packet import ( InteractionType, PacketStatus, + RPacket, ) from tardis.transport.montecarlo.r_packet_transport import ( move_packet_across_shell_boundary, diff --git a/tardis/transport/montecarlo/tests/test_base.py b/tardis/transport/montecarlo/tests/test_base.py index 876aaffb10d..495fb3a5088 100644 --- a/tardis/transport/montecarlo/tests/test_base.py +++ b/tardis/transport/montecarlo/tests/test_base.py @@ -1,10 +1,6 @@ -import os import pandas as pd -import numpy as np import pytest -from astropy import units as u from numpy.testing import assert_almost_equal -from pathlib import Path ### # Save and Load diff --git a/tardis/transport/montecarlo/tests/test_interaction.py b/tardis/transport/montecarlo/tests/test_interaction.py index bd6d04422cf..152a0663b2a 100644 --- a/tardis/transport/montecarlo/tests/test_interaction.py +++ b/tardis/transport/montecarlo/tests/test_interaction.py @@ -1,6 +1,7 @@ -import pytest -import numpy.testing as npt import numpy as np +import numpy.testing as npt +import pytest + import tardis.transport.montecarlo.interaction as interaction from tardis.transport.montecarlo.numba_interface import ( LineInteractionType, diff --git a/tardis/transport/montecarlo/tests/test_macro_atom.py b/tardis/transport/montecarlo/tests/test_macro_atom.py index 5ef26f16b49..d0d6f38ff32 100644 --- a/tardis/transport/montecarlo/tests/test_macro_atom.py +++ b/tardis/transport/montecarlo/tests/test_macro_atom.py @@ -1,6 +1,6 @@ import pytest + import tardis.transport.montecarlo.macro_atom as macro_atom -import numpy as np @pytest.mark.parametrize( diff --git a/tardis/transport/montecarlo/tests/test_montecarlo.py b/tardis/transport/montecarlo/tests/test_montecarlo.py index eb6d97cd406..05079075718 100644 --- a/tardis/transport/montecarlo/tests/test_montecarlo.py +++ b/tardis/transport/montecarlo/tests/test_montecarlo.py @@ -6,18 +6,18 @@ import tardis.spectrum.formal_integral as formal_integral import tardis.transport.montecarlo.r_packet as r_packet -import tardis.transport.montecarlo.utils as utils import tardis.transport.montecarlo.r_packet_transport as r_packet_transport +import tardis.transport.montecarlo.utils as utils from tardis import constants as const -from tardis.transport.montecarlo.estimators.radfield_mc_estimators import ( - RadiationFieldMCEstimators, -) -from tardis.transport.montecarlo.packet_trackers import RPacketTracker from tardis.transport.frame_transformations import ( angle_aberration_CMF_to_LF, angle_aberration_LF_to_CMF, get_doppler_factor, ) +from tardis.transport.montecarlo.estimators.radfield_mc_estimators import ( + RadiationFieldMCEstimators, +) +from tardis.transport.montecarlo.packet_trackers import RPacketTracker C_SPEED_OF_LIGHT = const.c.to("cm/s").value @@ -589,7 +589,6 @@ def test_frame_transformations(mu, r, inv_t_exp, full_relativity): (-0.7, 7.5e14, 1 / 5.2e5), (0.3, 7.5e14, 1 / 2.2e5), (0.0, 7.5e14, 1 / 2.2e5), - (-0.7, 7.5e14, 1 / 5.2e5), ], ) def test_angle_transformation_invariance(mu, r, inv_t_exp): diff --git a/tardis/transport/montecarlo/tests/test_montecarlo_main_loop.py b/tardis/transport/montecarlo/tests/test_montecarlo_main_loop.py index bcbfd4f7ea2..4a7070b5fe4 100644 --- a/tardis/transport/montecarlo/tests/test_montecarlo_main_loop.py +++ b/tardis/transport/montecarlo/tests/test_montecarlo_main_loop.py @@ -8,7 +8,7 @@ @pytest.mark.xfail(reason="To be implemented") def test_montecarlo_radial1d(): - assert False + raise AssertionError() def test_montecarlo_main_loop( diff --git a/tardis/transport/montecarlo/tests/test_numba_interface.py b/tardis/transport/montecarlo/tests/test_numba_interface.py index 5e73894549f..01679cb6e9f 100644 --- a/tardis/transport/montecarlo/tests/test_numba_interface.py +++ b/tardis/transport/montecarlo/tests/test_numba_interface.py @@ -1,7 +1,8 @@ +import numpy as np +import numpy.testing as npt import pytest + import tardis.opacities.opacity_state as numba_interface -import numpy.testing as npt -import numpy as np @pytest.mark.parametrize( @@ -77,7 +78,7 @@ def test_opacity_state_initialize( @pytest.mark.xfail(reason="To be implemented") def test_configuration_initialize(): - assert False + raise AssertionError() def test_VPacketCollection_add_packet(verysimple_3vpacket_collection): diff --git a/tardis/transport/montecarlo/tests/test_opacities.py b/tardis/transport/montecarlo/tests/test_opacities.py index 5cda6b97f82..07096d6e0c6 100644 --- a/tardis/transport/montecarlo/tests/test_opacities.py +++ b/tardis/transport/montecarlo/tests/test_opacities.py @@ -1,8 +1,8 @@ import numpy.testing as npt import pytest -from tardis.opacities.opacities import compton_opacity_calculation from tardis.opacities.opacities import ( + compton_opacity_calculation, kappa_calculation, pair_creation_opacity_calculation, photoabsorption_opacity_calculation, diff --git a/tardis/transport/montecarlo/tests/test_packet.py b/tardis/transport/montecarlo/tests/test_packet.py index ce8b756123f..c473e09d2a1 100644 --- a/tardis/transport/montecarlo/tests/test_packet.py +++ b/tardis/transport/montecarlo/tests/test_packet.py @@ -1,20 +1,14 @@ import numpy as np import pytest -import tardis.opacities.opacities as opacities -import tardis.transport.frame_transformations as frame_transformations -import tardis.transport.geometry.calculate_distances as calculate_distances -import tardis.transport.montecarlo.estimators.radfield_mc_estimators import tardis.opacities.opacities as opacities import tardis.transport.frame_transformations as frame_transformations import tardis.transport.geometry.calculate_distances as calculate_distances import tardis.transport.montecarlo.configuration.montecarlo_globals as montecarlo_globals -import tardis.transport.montecarlo.numba_interface as numba_interface +import tardis.transport.montecarlo.estimators.radfield_mc_estimators import tardis.transport.montecarlo.r_packet as r_packet -import tardis.transport.montecarlo.utils as utils -import tardis.transport.frame_transformations as frame_transformations -import tardis.transport.geometry.calculate_distances as calculate_distances import tardis.transport.montecarlo.r_packet_transport as r_packet_transport +import tardis.transport.montecarlo.utils as utils from tardis import constants as const from tardis.model.geometry.radial1d import NumbaRadial1DGeometry from tardis.transport.montecarlo.estimators.radfield_estimator_calcs import ( diff --git a/tardis/transport/montecarlo/tests/test_packet_source.py b/tardis/transport/montecarlo/tests/test_packet_source.py index a34dd2c0b71..462c75a5811 100644 --- a/tardis/transport/montecarlo/tests/test_packet_source.py +++ b/tardis/transport/montecarlo/tests/test_packet_source.py @@ -1,16 +1,12 @@ -import os - -from astropy import units as u import numpy as np -import pandas as pd import pytest +from astropy import units as u from numpy.testing import assert_allclose from tardis.transport.montecarlo.packet_source import ( BlackBodySimpleSource, BlackBodySimpleSourceRelativistic, ) -from tardis.tests.fixtures.regression_data import RegressionData class TestBlackBodySimpleSource: diff --git a/tardis/transport/montecarlo/tests/test_rpacket_last_interaction_tracker.py b/tardis/transport/montecarlo/tests/test_rpacket_last_interaction_tracker.py index 338b326583c..b2c449cadab 100644 --- a/tardis/transport/montecarlo/tests/test_rpacket_last_interaction_tracker.py +++ b/tardis/transport/montecarlo/tests/test_rpacket_last_interaction_tracker.py @@ -1,11 +1,11 @@ -import pytest import numpy as np import numpy.testing as npt +import pytest -from tardis.transport.montecarlo.r_packet import InteractionType from tardis.transport.montecarlo.packet_trackers import ( RPacketLastInteractionTracker, ) +from tardis.transport.montecarlo.r_packet import InteractionType @pytest.fixture(scope="module") diff --git a/tardis/transport/montecarlo/tests/test_rpacket_tracker.py b/tardis/transport/montecarlo/tests/test_rpacket_tracker.py index b9bafae3a0a..57d42bfc897 100644 --- a/tardis/transport/montecarlo/tests/test_rpacket_tracker.py +++ b/tardis/transport/montecarlo/tests/test_rpacket_tracker.py @@ -1,13 +1,12 @@ +import numpy as np import numpy.testing as npt import pytest -import numpy as np -from tardis.transport.montecarlo.r_packet import InteractionType from tardis.transport.montecarlo.packet_trackers import ( RPacketTracker, rpacket_trackers_to_dataframe, ) - +from tardis.transport.montecarlo.r_packet import InteractionType pytestmark = pytest.mark.rpacket_tracking diff --git a/tardis/transport/montecarlo/tests/test_single_packet_loop.py b/tardis/transport/montecarlo/tests/test_single_packet_loop.py index 065b694c5f4..a2ae1d6c117 100644 --- a/tardis/transport/montecarlo/tests/test_single_packet_loop.py +++ b/tardis/transport/montecarlo/tests/test_single_packet_loop.py @@ -1,6 +1,5 @@ -import pytest - import numpy.testing as npt +import pytest from tardis.transport.montecarlo import RPacket from tardis.transport.montecarlo.single_packet_loop import ( @@ -49,9 +48,9 @@ def test_verysimple_single_packet_loop( @pytest.mark.xfail(reason="To be implemented") def test_set_packet_props_partial_relativity(): - assert False + raise AssertionError() @pytest.mark.xfail(reason="To be implemented") def test_set_packet_props_full_relativity(): - assert False + raise AssertionError() diff --git a/tardis/transport/montecarlo/tests/test_tracker_utils.py b/tardis/transport/montecarlo/tests/test_tracker_utils.py index 0d3bc6a4d46..92ddc5b3cf7 100644 --- a/tardis/transport/montecarlo/tests/test_tracker_utils.py +++ b/tardis/transport/montecarlo/tests/test_tracker_utils.py @@ -1,12 +1,11 @@ -import pytest import numpy as np from numba import typeof from tardis.transport.montecarlo.packet_trackers import ( - RPacketTracker, RPacketLastInteractionTracker, - generate_rpacket_tracker_list, + RPacketTracker, generate_rpacket_last_interaction_tracker_list, + generate_rpacket_tracker_list, ) diff --git a/tardis/transport/montecarlo/tests/test_vpacket.py b/tardis/transport/montecarlo/tests/test_vpacket.py index e081abe7670..51a8e31dd78 100644 --- a/tardis/transport/montecarlo/tests/test_vpacket.py +++ b/tardis/transport/montecarlo/tests/test_vpacket.py @@ -1,10 +1,8 @@ -import os -import pytest import numpy as np -import pandas as pd +import pytest + import tardis.transport.montecarlo.vpacket as vpacket from tardis import constants as const - from tardis.transport.frame_transformations import ( get_doppler_factor, ) diff --git a/tardis/transport/montecarlo/tests/test_weighted_packet_source.py b/tardis/transport/montecarlo/tests/test_weighted_packet_source.py index 34b8f4599b7..8b8a27ff034 100644 --- a/tardis/transport/montecarlo/tests/test_weighted_packet_source.py +++ b/tardis/transport/montecarlo/tests/test_weighted_packet_source.py @@ -1,15 +1,10 @@ -import os - -from astropy import units as u -import numpy as np -import pandas as pd import pytest +from astropy import units as u from numpy.testing import assert_allclose from tardis.transport.montecarlo.weighted_packet_source import ( BlackBodyWeightedSource, ) -from tardis.tests.fixtures.regression_data import RegressionData class TestBlackBodyWeightedSource: diff --git a/tardis/transport/montecarlo/utils.py b/tardis/transport/montecarlo/utils.py index 1bc4e1a6ccb..2de622d21b4 100644 --- a/tardis/transport/montecarlo/utils.py +++ b/tardis/transport/montecarlo/utils.py @@ -1,5 +1,6 @@ import numpy as np from numba import njit + from tardis.transport.montecarlo import ( njit_dict_no_parallel, ) diff --git a/tardis/transport/montecarlo/weighted_packet_source.py b/tardis/transport/montecarlo/weighted_packet_source.py index dbdbb85efd3..1ac91405e06 100644 --- a/tardis/transport/montecarlo/weighted_packet_source.py +++ b/tardis/transport/montecarlo/weighted_packet_source.py @@ -1,11 +1,6 @@ -import numexpr as ne -import numpy as np -from astropy import constants as const from astropy import units as u from tardis.transport.montecarlo.packet_source import ( - BasePacketSource, - HDFWriterMixin, BlackBodySimpleSource, ) from tardis.util.base import intensity_black_body diff --git a/tardis/transport/tests/test_doppler_factor.py b/tardis/transport/tests/test_doppler_factor.py index f057e1686f8..addf4e407d5 100644 --- a/tardis/transport/tests/test_doppler_factor.py +++ b/tardis/transport/tests/test_doppler_factor.py @@ -1,13 +1,10 @@ import pytest -import numpy as np - -import tardis.transport.frame_transformations as frame_transformations -import tardis.transport.montecarlo.r_packet as r_packet - from numpy.testing import ( assert_almost_equal, ) +import tardis.transport.frame_transformations as frame_transformations + @pytest.mark.parametrize( ["mu", "r", "inv_t_exp", "expected"],