Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TODO] Resolves the chained assignment in level_populations.py #2933

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions tardis/plasma/equilibrium/level_populations.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,19 @@ def solve(self):
dtype=np.float64,
)

# try converting the set of vectors into a single 2D array and then applying index
for species_id in self.rates_matrices.index:
# TODO: resolve the chained assignment here. Maybe an intermediate df
# is needed
species_level_populations = pd.DataFrame(
index=self.levels.index,
columns=self.rates_matrices.columns,
dtype=np.float64,
)

for species_id in self.rates_matrices.index:
solved_matrices = self.rates_matrices.loc[species_id].apply(
lambda rates_matrix: self.__calculate_level_population(
rates_matrix
)
)
normalized_level_populations.loc[species_id, :].update(
np.vstack(solved_matrices.values).T
lambda rates_matrix: self.__calculate_level_population(rates_matrix)
)

species_level_populations.loc[species_id, :] = np.vstack(solved_matrices.values).T

normalized_level_populations.update(species_level_populations)

return normalized_level_populations
Loading