From 4bb2a791cd334b03a89bb311f41928167db900d9 Mon Sep 17 00:00:00 2001 From: mertelx Date: Wed, 28 Feb 2024 12:12:59 +0100 Subject: [PATCH] Reduce complexity of load_data function. --- photonField.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/photonField.py b/photonField.py index 99fe48a..6c67b1c 100644 --- a/photonField.py +++ b/photonField.py @@ -560,7 +560,7 @@ def __init__(self): self.load_data() def load_data(self): - tmp_dict = {} + tmp_list = [] for i, z in enumerate(self.redshift): data = pd.read_csv(self.files % z, sep="\s+", header=None) @@ -573,13 +573,12 @@ def load_data(self): # adding the energies only once, cause they are the same in every file if i == 0: - tmp_dict['energy'] = eps - tmp_dict[str(z)] = n - - df = pd.DataFrame(tmp_dict) - self.energy = df['energy'].to_numpy() # [eV] - self.photonDensity = [ (df.loc[i][1:] * (erg / eV) / (df.loc[i]['energy'])**2).to_numpy() for i in df.index ] # [1/cm^3/eV] + self.energy = eps + tmp_list.append( n * (erg / eV) / self.energy**2 ) # [1/cm^3/eV] + self.photonDensity = np.array(tmp_list).transpose() + + # -------------------------------------------------------- # CRB (radio) models # --------------------------------------------------------