diff --git a/docs/source/classes/Jetscape/index.rst b/docs/source/classes/Jetscape/index.rst index 08ccc923..f72c0483 100644 --- a/docs/source/classes/Jetscape/index.rst +++ b/docs/source/classes/Jetscape/index.rst @@ -8,4 +8,3 @@ Jetscape :members: :inherited-members: -.. automethod:: Jetscape.create_loader diff --git a/docs/source/classes/Oscar/index.rst b/docs/source/classes/Oscar/index.rst index 9be3b934..f728d5ca 100644 --- a/docs/source/classes/Oscar/index.rst +++ b/docs/source/classes/Oscar/index.rst @@ -8,5 +8,3 @@ Oscar :members: :inherited-members: - -.. automethod:: Oscar.create_loader diff --git a/docs/source/classes/loader/JetscapeLoader/index.rst b/docs/source/classes/loader/JetscapeLoader/index.rst index 51693ad6..690fb33e 100644 --- a/docs/source/classes/loader/JetscapeLoader/index.rst +++ b/docs/source/classes/loader/JetscapeLoader/index.rst @@ -7,6 +7,3 @@ JetscapeLoader .. autoclass:: JetscapeLoader :members: :inherited-members: - -.. automethod:: JetscapeLoader._get_num_skip_lines -.. automethod:: JetscapeLoader.event_end_lines \ No newline at end of file diff --git a/docs/source/classes/loader/OscarLoader/index.rst b/docs/source/classes/loader/OscarLoader/index.rst index 4c4e905c..97d24edb 100644 --- a/docs/source/classes/loader/OscarLoader/index.rst +++ b/docs/source/classes/loader/OscarLoader/index.rst @@ -8,6 +8,3 @@ OscarLoader :members: :inherited-members: - -.. automethod:: OscarLoader.oscar_format -.. automethod:: OscarLoader.event_end_lines diff --git a/src/sparkx/BaseStorer.py b/src/sparkx/BaseStorer.py index 05cb2f1c..acfc54cc 100644 --- a/src/sparkx/BaseStorer.py +++ b/src/sparkx/BaseStorer.py @@ -10,6 +10,7 @@ from sparkx.Filter import * import numpy as np from abc import ABC, abstractmethod +from sparkx.Particle import Particle from typing import List, Union, Tuple, Optional from sparkx.loader.BaseLoader import BaseLoader @@ -74,7 +75,7 @@ class BaseStorer(ABC): """ def __init__( - self, path: Union[str, List[List["Particle"]]], **kwargs + self, path: Union[str, List[List[Particle]]], **kwargs ) -> None: """ Parameters @@ -94,7 +95,7 @@ def __init__( self.loader_: Optional[BaseLoader] = None self.num_output_per_event_: Optional[np.ndarray] = None self.num_events_: Optional[int] = None - self.particle_list_: Optional[List] = None + self.particle_list_: List[List[Particle]] = [[]] self.create_loader(path) if self.loader_ is not None: ( @@ -229,7 +230,6 @@ def uncharged_particles(self) -> "BaseStorer": self : BaseStorer object Containing uncharged particles in every event only """ - self.particle_list_ = uncharged_particles(self.particle_list_) self._update_num_output_per_event_after_filter() diff --git a/src/sparkx/EventCharacteristics.py b/src/sparkx/EventCharacteristics.py index 4d7785d7..cb158616 100644 --- a/src/sparkx/EventCharacteristics.py +++ b/src/sparkx/EventCharacteristics.py @@ -397,8 +397,8 @@ def generate_eBQS_densities_Milne_from_OSCAR_IC(self, raise TypeError( "The smearing function only works with EventCharacteristics derived from particles." ) - if not isinstance(self.event_data_, (list, np.ndarray)): - raise TypeError("The input is not a list nor a numpy.ndarray.") + if not isinstance(self.event_data_, list): + raise TypeError("The input is not a list.") energy_density = Lattice3D( x_min, @@ -628,8 +628,8 @@ def generate_eBQS_densities_Minkowski_from_OSCAR_IC( raise TypeError( "The smearing function only works with EventCharacteristics derived from particles." ) - if not isinstance(self.event_data_, (list, np.ndarray)): - raise TypeError("The input is not a list nor a numpy.ndarray.") + if not isinstance(self.event_data_, list): + raise TypeError("The input is not a list.") energy_density = Lattice3D( x_min, diff --git a/src/sparkx/Filter.py b/src/sparkx/Filter.py index 21103579..3af5dd63 100644 --- a/src/sparkx/Filter.py +++ b/src/sparkx/Filter.py @@ -457,10 +457,10 @@ def spacetime_cut(particle_list: List[List[Particle]], dim: str, return updated_particle_list -def pt_cut(particle_list: List[List[Particle]], +def pT_cut(particle_list: List[List[Particle]], cut_value_tuple: Tuple[Optional[float], Optional[float]]) -> List[List[Particle]]: """ - Apply p_t cut to all events by passing an acceptance range by + Apply p_T cut to all events by passing an acceptance range by ::code`cut_value_tuple`. All particles outside this range will be removed. diff --git a/src/sparkx/Histogram.py b/src/sparkx/Histogram.py index e65d3d7c..faa22099 100755 --- a/src/sparkx/Histogram.py +++ b/src/sparkx/Histogram.py @@ -655,7 +655,7 @@ def average_weighted(self, weights: np.ndarray) -> 'Histogram': np.average(self.systematic_error_**2.0, axis=0, weights=weights) ) self.histogram_raw_count_ = np.sum(self.histograms_raw_count_, axis=0) - self.scaling_ = self.scaling_[0] + self.scaling_ = np.asarray(self.scaling_[0]) if self.scaling_.ndim == 1: self.scaling_ = self.scaling_.reshape(1, -1) @@ -716,7 +716,7 @@ def average_weighted_by_error(self) -> 'Histogram': np.average(self.systematic_error_**2.0, axis=0, weights=weights) ) self.histogram_raw_count_ = np.sum(self.histograms_raw_count_, axis=0) - self.scaling_ = self.scaling_[0] + self.scaling_ = np.asarray(self.scaling_[0]) if self.scaling_.ndim == 1: self.scaling_ = self.scaling_.reshape(1, -1) diff --git a/src/sparkx/JetAnalysis.py b/src/sparkx/JetAnalysis.py index d5af1c20..d7844665 100755 --- a/src/sparkx/JetAnalysis.py +++ b/src/sparkx/JetAnalysis.py @@ -143,12 +143,12 @@ def __init__(self) -> None: self.hadron_data_: Optional[List[List[Particle]]] = None self.jet_R_: Optional[float] = None self.jet_eta_range_: Optional[tuple] = None - self.jet_pt_range_: Optional[tuple] = None + self.jet_pT_range_: Optional[tuple] = None self.jet_data_: Optional[List[List[Any]]] = None def __initialize_and_check_parameters(self, hadron_data: List[List[Particle]], jet_R: float, jet_eta_range: Tuple[Optional[float], Optional[float]], - jet_pt_range: Tuple[Optional[float], Optional[float]]) -> None: + jet_pT_range: Tuple[Optional[float], Optional[float]]) -> None: """ Initialize and check the parameters for jet analysis. @@ -207,16 +207,16 @@ def __initialize_and_check_parameters(self, hadron_data: List[List[Particle]], j "upper one. They are interchanged automatically.") # check the jet pt range - if not isinstance(jet_pt_range, tuple): - raise TypeError("jet_pt_range is not a tuple. " + + if not isinstance(jet_pT_range, tuple): + raise TypeError("jet_pT_range is not a tuple. " + "It must contain either values or None.") - if len(jet_pt_range) != 2: - raise ValueError("jet_pt_range must contain exactly two values.") - if any(pt is not None and pt < 0 for pt in jet_pt_range): - raise ValueError("All values in jet_pt_range must be non-negative.") + if len(jet_pT_range) != 2: + raise ValueError("jet_pT_range must contain exactly two values.") + if any(pT is not None and pT < 0 for pT in jet_pT_range): + raise ValueError("All values in jet_pT_range must be non-negative.") - lower_cut = 0. if jet_pt_range[0] is None else jet_pt_range[0] - upper_cut = float('inf') if jet_pt_range[1] is None else jet_pt_range[1] + lower_cut = 0. if jet_pT_range[0] is None else jet_pT_range[0] + upper_cut = float('inf') if jet_pT_range[1] is None else jet_pT_range[1] if lower_cut < upper_cut: self.jet_pT_range_ = (lower_cut, upper_cut) else: @@ -359,8 +359,8 @@ def write_jet_output(self, output_filename: str, jet: fj.PseudoJet, bool False if successful. """ - if self.jet_pt_range_ is None: - raise TypeError("'jet_pt_range_' is None. It must be initialized before calling the 'write_jet_output' function.") + if self.jet_pT_range_ is None: + raise TypeError("'jet_pT_range_' is None. It must be initialized before calling the 'write_jet_output' function.") # jet data from reconstruction jet_status = 10 @@ -408,7 +408,7 @@ def write_jet_output(self, output_filename: str, jet: fj.PseudoJet, def perform_jet_finding(self, hadron_data: List[List[Particle]], jet_R: float, jet_eta_range: Tuple[Optional[float], Optional[float]], - jet_pt_range: Tuple[Optional[float], Optional[float]], + jet_pT_range: Tuple[Optional[float], Optional[float]], output_filename: str, assoc_only_charged: bool = True, jet_algorithm: fj = fj.antikt_algorithm) -> None: """ @@ -448,16 +448,16 @@ def perform_jet_finding(self, hadron_data: List[List[Particle]], jet_R: float, package is fixed here. """ + self.__initialize_and_check_parameters( + hadron_data, jet_R, jet_eta_range, jet_pT_range + ) if self.hadron_data_ is None: raise TypeError("'hadron_data_' is None. It must be initialized before calling the 'perform_jet_finding' function.") if self.jet_eta_range_ is None: raise TypeError("'jet_eta_range_' is None. It must be initialized before calling the 'perform_jet_finding' function.") - if self.jet_pt_range_ is None: - raise TypeError("'jet_pt_range_' is None. It must be initialized before calling the 'perform_jet_finding' function.") + if self.jet_pT_range_ is None: + raise TypeError("'jet_pT_range_' is None. It must be initialized before calling the 'perform_jet_finding' function.") - self.__initialize_and_check_parameters( - hadron_data, jet_R, jet_eta_range, jet_pT_range - ) for event, hadron_data_event in enumerate(self.hadron_data_): new_file = False event_PseudoJets = self.create_fastjet_PseudoJets(hadron_data_event) @@ -516,9 +516,6 @@ def read_jet_data(self, input_filename: str) -> None: input_filename: str Filename of the CSV file containing the jet data. """ - if self.jet_data_ is None: - raise TypeError("'jet_data_' is None. It must be initialized before calling the 'read_jet_data' function.") - jet_data = [] current_jet: List[List[Any]] = [] with open(input_filename, 'r', newline='') as f: diff --git a/src/sparkx/Jetscape.py b/src/sparkx/Jetscape.py index 42b5d0ab..4c716620 100644 --- a/src/sparkx/Jetscape.py +++ b/src/sparkx/Jetscape.py @@ -10,6 +10,7 @@ from sparkx.Filter import * import numpy as np from sparkx.loader.JetscapeLoader import JetscapeLoader +from sparkx.Particle import Particle from sparkx.BaseStorer import BaseStorer from typing import List, Tuple, Union, Dict, Optional @@ -181,18 +182,19 @@ def __init__( ) self.last_line_: str = self.loader_.get_last_line(JETSCAPE_FILE) del self.loader_ + def create_loader( - self, JETSCAPE_FILE: Union[str, List[List["Particle"]]] + self, JETSCAPE_FILE: Union[str, List[List[Particle]]] ) -> None: """ Creates a new JetscapeLoader object. This method initializes a new JetscapeLoader object with the specified JETSCAPE file - and assigns it to the loader_ attribute. + and assigns it to the loader attribute. Parameters ---------- - JETSCAPE_FILE : Union[str, List[List["Particle"]]] + JETSCAPE_FILE : Union[str, List[List[Particle]]] The path to the JETSCAPE file to be loaded. Must be a string. Raises @@ -210,7 +212,7 @@ def create_loader( # PRIVATE CLASS METHODS def _particle_as_list( - self, particle: "Particle" + self, particle: Particle ) -> List[Union[int, float]]: particle_list: List[Union[int, float]] = [0.0] * 7 particle_list[0] = int(particle.ID) diff --git a/src/sparkx/Lattice3D.py b/src/sparkx/Lattice3D.py index 31a6919e..5a41f830 100644 --- a/src/sparkx/Lattice3D.py +++ b/src/sparkx/Lattice3D.py @@ -266,8 +266,6 @@ def __get_index(self, value: Union[int, float], The value for which the index is to be determined. values : list or numpy.ndarray The list or array containing the range of values, sorted ascending. - num_points : int - The number of points in the range. Returns ------- @@ -1230,7 +1228,7 @@ def interpolate_to_lattice_new_extent(self, num_points_x: int, num_points_y: int or z < self.z_min_ or z > self.z_max_ ): - value = 0 + value = 0.0 else: value = self.interpolate_value(x, y, z) new_lattice.set_value_by_index(i, j, k, value) @@ -1277,6 +1275,8 @@ def add_same_spaced_grid(self, other: 'Lattice3D', center_x: float, center_y: fl raise TypeError( "Unsupported operand type. The operand must be of type 'Lattice3D'." ) + if self.spacing_x_ is None or self.spacing_y_ is None or self.spacing_z_ is None: + raise TypeError("At least one of the 'spacing' is None.") # Check if both lattices have the same spacing if ( ( diff --git a/src/sparkx/MultiParticlePtCorrelations.py b/src/sparkx/MultiParticlePtCorrelations.py index f162822e..56218d5a 100644 --- a/src/sparkx/MultiParticlePtCorrelations.py +++ b/src/sparkx/MultiParticlePtCorrelations.py @@ -343,7 +343,7 @@ def _compute_mean_pT_correlations( return sum_numerator / sum_denominator - def mean_pt_correlations(self, + def mean_pT_correlations(self, particle_list_all_events: List[List[Particle]], compute_error: bool = True, delete_fraction: float = 0.4, diff --git a/src/sparkx/Oscar.py b/src/sparkx/Oscar.py index 54572e97..62b7a6b2 100644 --- a/src/sparkx/Oscar.py +++ b/src/sparkx/Oscar.py @@ -172,7 +172,7 @@ def __init__(self, OSCAR_FILE: str, **kwargs: Any) -> None: self.PATH_OSCAR_: str = OSCAR_FILE if not isinstance(self.loader_, OscarLoader): raise TypeError("The loader must be an instance of OscarLoader.") - self.oscar_format_: Union[str | None] = self.loader_.oscar_format() + self.oscar_format_: Union[str, None] = self.loader_.oscar_format() self.event_end_lines_: List[str] = self.loader_.event_end_lines() del self.loader_ @@ -181,7 +181,7 @@ def create_loader(self, OSCAR_FILE: str) -> None: # type: ignore[override] Creates a new OscarLoader object. This method initializes a new OscarLoader object with the specified OSCAR file - and assigns it to the loader_ attribute. + and assigns it to the loader attribute. Parameters ---------- diff --git a/src/sparkx/flow/EventPlaneFlow.py b/src/sparkx/flow/EventPlaneFlow.py index 157c3cac..d01e8904 100644 --- a/src/sparkx/flow/EventPlaneFlow.py +++ b/src/sparkx/flow/EventPlaneFlow.py @@ -98,7 +98,7 @@ class EventPlaneFlow(FlowInterface.FlowInterface): """ - def __init__(self, n: int = 2, weight: str = "pt2", pseudorapidity_gap: float = 0.) -> None: + def __init__(self, n: int = 2, weight: str = "pT2", pseudorapidity_gap: float = 0.) -> None: """ Initialize the ScalarProductFlow object. @@ -107,7 +107,7 @@ def __init__(self, n: int = 2, weight: str = "pt2", pseudorapidity_gap: float = n : int, optional The value of the harmonic. Default is 2. weight : str, optional - The weight used for calculating the flow. Default is "pt2". + The weight used for calculating the flow. Default is "pT2". pseudorapidity_gap : float, optional The pseudorapidity gap used for dividing the particles into sub-events. Default is 0.0. @@ -123,7 +123,7 @@ def __init__(self, n: int = 2, weight: str = "pt2", pseudorapidity_gap: float = self.n_ = n if not isinstance(weight, str): raise TypeError('weight has to be a string') - elif weight not in ["pt", "pt2", "ptn", "rapidity", "pseudorapidity"]: + elif weight not in ["pT", "pT2", "pTn", "rapidity", "pseudorapidity"]: raise ValueError( "Invalid weight given, choose one of the following: 'pT', 'pT2', 'pTn', 'rapidity', 'pseudorapidity'" ) @@ -495,7 +495,7 @@ def differential_flow( raise TypeError('bins has to be list or np.ndarray') if not isinstance(flow_as_function_of, str): raise TypeError('flow_as_function_of is not a string') - if flow_as_function_of not in ["pt", "rapidity", "pseudorapidity"]: + if flow_as_function_of not in ["pT", "rapidity", "pseudorapidity"]: raise ValueError( "flow_as_function_of must be either 'pT', 'rapidity', 'pseudorapidity'" ) diff --git a/src/sparkx/flow/GenerateFlow.py b/src/sparkx/flow/GenerateFlow.py index 503f27cf..50f1f53b 100644 --- a/src/sparkx/flow/GenerateFlow.py +++ b/src/sparkx/flow/GenerateFlow.py @@ -188,7 +188,7 @@ def __thermal_distribution(self, temperature: float, mass: float) -> float: momentum_radial: float The magnitude of the momentum. """ - momentum_radial = 0 + momentum_radial = 0.0 energy = 0.0 if temperature > 0.6 * mass: while True: @@ -364,7 +364,7 @@ def __artificial_flow_pT_shape(self, pT: float, pT0_bis: float, pT_sat: float, v return value - def __distribution_function_pT_differential(self, phi: float, vn_pt_list: List[float]) -> float: + def __distribution_function_pT_differential(self, phi: float, vn_pT_list: List[float]) -> float: """ Calculates the pT-differential distribution function for a given azimuthal angle. @@ -433,7 +433,7 @@ def __create_k_particle_correlations( self.py_ = py self.pz_ = pz - def __generate_flow_realistic_pt_distribution( + def __generate_flow_realistic_pT_distribution( self, multiplicity: int, reaction_plane_angle: float) -> None: pTmax = 4.5 pTmin = 0.1 @@ -568,7 +568,7 @@ def generate_dummy_JETSCAPE_file( output.write("# sigmaGen 0.0 sigmaErr 0.0") - def generate_dummy_JETSCAPE_file_realistic_pt_shape( + def generate_dummy_JETSCAPE_file_realistic_pT_shape( self, output_path: str, number_events: int, @@ -761,7 +761,7 @@ def generate_dummy_JETSCAPE_file_multi_particle_correlations( output.write("# sigmaGen 0.0 sigmaErr 0.0") - def generate_dummy_JETSCAPE_file_realistic_pt_shape_multi_particle_correlations( + def generate_dummy_JETSCAPE_file_realistic_pT_shape_multi_particle_correlations( self, output_path: str, number_events: int, @@ -962,7 +962,7 @@ def generate_dummy_OSCAR_file( output.write( f"# event {event} end 0 impact -1.000 scattering_projectile_target no\n") - def generate_dummy_OSCAR_file_realistic_pt_shape( + def generate_dummy_OSCAR_file_realistic_pT_shape( self, output_path: str, number_events: int, @@ -1172,7 +1172,7 @@ def generate_dummy_OSCAR_file_multi_particle_correlations( output.write( f"# event {event} end 0 impact -1.000 scattering_projectile_target no\n") - def generate_dummy_OSCAR_file_realistic_pt_shape_multi_particle_correlations( + def generate_dummy_OSCAR_file_realistic_pT_shape_multi_particle_correlations( self, output_path: str, number_events: int, diff --git a/src/sparkx/loader/JetscapeLoader.py b/src/sparkx/loader/JetscapeLoader.py index 472c570f..c0e8ce71 100644 --- a/src/sparkx/loader/JetscapeLoader.py +++ b/src/sparkx/loader/JetscapeLoader.py @@ -441,7 +441,7 @@ def set_particle_list( line_list = ( line.replace("\n", "").replace("\t", " ").split(" ") ) - particle = Particle("JETSCAPE", line_list) + particle = Particle("JETSCAPE", np.asarray(line_list)) data.append(particle) # Correct num_output_per_event and num_events diff --git a/src/sparkx/loader/OscarLoader.py b/src/sparkx/loader/OscarLoader.py index d0a8f817..9e36df62 100644 --- a/src/sparkx/loader/OscarLoader.py +++ b/src/sparkx/loader/OscarLoader.py @@ -9,6 +9,7 @@ from sparkx.loader.BaseLoader import BaseLoader from sparkx.Filter import * +from sparkx.Particle import Particle import os from typing import Dict, List, Tuple, Optional, Union, Any @@ -98,7 +99,7 @@ def __init__(self, OSCAR_FILE: str): def load( self, **kwargs: Dict[str, Any] - ) -> Tuple[List[List["Particle"]], int, np.ndarray]: + ) -> Tuple[List[List[Particle]], int, np.ndarray]: """ Loads the OSCAR data from the specified file. @@ -359,8 +360,8 @@ def __get_num_read_lines(self) -> int: return cumulated_lines def __apply_kwargs_filters( - self, event: List[List["Particle"]], filters_dict: Dict[str, Any] - ) -> List[List["Particle"]]: + self, event: List[List[Particle]], filters_dict: Dict[str, Any] + ) -> List[List[Particle]]: """ Applies the specified filters to the given event. @@ -522,7 +523,7 @@ def set_particle_list(self, kwargs: Dict[str, Any]) -> List[List[Particle]]: elif "#" in line: raise ValueError("Comment line unexpectedly found: " + line) else: - line_list = line.replace("\n", "").split(" ") + line_list = np.asarray(line.replace("\n", "").split(" ")) particle = Particle(self.oscar_format_, line_list) data.append(particle) @@ -575,7 +576,7 @@ def set_num_output_per_event_and_event_footers(self) -> None: with open(self.PATH_OSCAR_, "r") as oscar_file: line_counter: int - event: int | str + event: Union[int, str] line_str: List[str] if ( self.oscar_format_ != "Oscar2013Extended_IC" diff --git a/tests/test_Lattice3D.py b/tests/test_Lattice3D.py index 423ab463..aa56f378 100644 --- a/tests/test_Lattice3D.py +++ b/tests/test_Lattice3D.py @@ -77,23 +77,23 @@ def test_get_value_by_index_invalid_indices(sample_lattice): def test_get_index_within_range(sample_lattice): values = np.linspace(0, 1, 10) - assert sample_lattice._Lattice3D__get_index(0.3, values, 10) == 2 + assert sample_lattice._Lattice3D__get_index(0.3, values) == 2 def test_get_index_at_lower_bound(sample_lattice): values = np.linspace(0, 1, 10) - assert sample_lattice._Lattice3D__get_index(0, values, 10) == 0 + assert sample_lattice._Lattice3D__get_index(0, values) == 0 def test_get_index_at_upper_bound(sample_lattice): values = np.linspace(0, 1, 10) - assert sample_lattice._Lattice3D__get_index(1, values, 10) == 9 + assert sample_lattice._Lattice3D__get_index(1, values) == 9 def test_get_index_outside_range_raises_error(sample_lattice): values = np.linspace(0, 1, 10) with pytest.raises(ValueError): - sample_lattice._Lattice3D__get_index(2, values, 10) + sample_lattice._Lattice3D__get_index(2, values) def test_get_index_nearest_neighbor_within_range(sample_lattice):