-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CDR to the by component processing
- Loading branch information
1 parent
0dc71ba
commit 51ceae0
Showing
11 changed files
with
328 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,78 @@ | ||
from dataclasses import dataclass | ||
from typing import Dict | ||
from typing import Dict, List | ||
|
||
import pandas as pd | ||
|
||
from f4e_radwaste.constants import KEY_DOSE_1_METER, KEY_CDR | ||
from f4e_radwaste.constants import ( | ||
KEY_DOSE_1_METER, | ||
KEY_CDR, | ||
) | ||
from f4e_radwaste.data_formats.data_mesh_activity import DataMeshActivity | ||
|
||
|
||
@dataclass | ||
class DoseCalculator: | ||
dose_1_m_factors: pd.Series | ||
cdr_factors: pd.DataFrame | ||
material_mixes_by_id: Dict[int, pd.Series] | ||
element_mix_by_material_id: Dict[int, pd.Series] | ||
|
||
def calculate_doses( | ||
self, | ||
data_mesh_activity: DataMeshActivity, | ||
material_proportion: Dict[int, float], | ||
self, comp_activity: DataMeshActivity, cdr_factor_columns: List[pd.Series] | ||
) -> DataMeshActivity: | ||
activity_df = data_mesh_activity.get_filtered_dataframe() | ||
activity_df = comp_activity.get_filtered_dataframe() | ||
|
||
dose_1m_column = (activity_df * self.dose_1_m_factors).sum(axis=1) | ||
|
||
cdr_column = self._calculate_cdr_column(activity_df, material_proportion) | ||
cdr_column = self._calculate_cdr_values(activity_df, cdr_factor_columns) | ||
|
||
updated_df = data_mesh_activity.get_dataframe_with_added_columns( | ||
updated_df = comp_activity.get_dataframe_with_added_columns( | ||
{KEY_DOSE_1_METER: dose_1m_column, KEY_CDR: cdr_column} | ||
) | ||
return DataMeshActivity(updated_df) | ||
|
||
def _calculate_cdr_column(self, activity_df, material_proportion) -> pd.Series: | ||
element_mix = self._calculate_element_mix_from_material_id_proportion( | ||
material_proportion | ||
) | ||
cdr_factors_mix = self._calculate_cdr_factors_for_element_mix(element_mix) | ||
@staticmethod | ||
def _calculate_cdr_values( | ||
activity_df: pd.DataFrame, cdr_factor_columns: List[pd.Series] | ||
) -> pd.Series: | ||
cdr_values = [] | ||
|
||
return (activity_df * cdr_factors_mix).sum(axis=1) | ||
for (_, row), cdr_factors in zip(activity_df.iterrows(), cdr_factor_columns): | ||
cdr_values.append((row * cdr_factors).sum()) | ||
|
||
def _calculate_element_mix_from_material_id_proportion( | ||
self, materials_proportion: Dict[int, float] | ||
) -> pd.Series: | ||
proportioned_mixes = [] | ||
return pd.Series(index=activity_df.index, data=cdr_values) | ||
|
||
material_ids = materials_proportion.keys() | ||
for material_id in material_ids: | ||
material_mix = self.material_mixes_by_id[material_id] | ||
proportion = materials_proportion[material_id] | ||
def calculate_cdr_factors_list( | ||
self, material_id_proportions: List[pd.Series] | ||
) -> List[pd.Series]: | ||
element_mixes = self._calculate_element_mixes(material_id_proportions) | ||
|
||
proportioned_mixes.append(material_mix * proportion) | ||
cdr_factors = [] | ||
for element_mix in element_mixes: | ||
cdr_factors.append((self.cdr_factors * element_mix).sum(axis=1)) | ||
|
||
element_mix = pd.concat(proportioned_mixes, axis=1) | ||
element_mix = element_mix.sum(axis=1) | ||
return element_mix | ||
return cdr_factors | ||
|
||
def _calculate_cdr_factors_for_element_mix( | ||
self, element_mix: pd.Series | ||
) -> pd.Series: | ||
return (self.cdr_factors * element_mix).sum(axis=1) | ||
def _calculate_element_mixes(self, material_id_proportions: List[pd.Series]): | ||
element_mixes = [] | ||
|
||
for mat_id_proportion in material_id_proportions: | ||
proportioned_mixes = [] | ||
|
||
for mat_id, proportion in mat_id_proportion.items(): | ||
if mat_id not in self.element_mix_by_material_id: | ||
continue | ||
|
||
# noinspection PyTypeChecker | ||
proportioned_mixes.append( | ||
self.element_mix_by_material_id[mat_id] * proportion | ||
) | ||
|
||
if len(proportioned_mixes) == 0: | ||
element_mixes.append(pd.Series()) | ||
continue | ||
|
||
element_mix = pd.concat(proportioned_mixes, axis=1) | ||
element_mix = element_mix.sum(axis=1) | ||
element_mixes.append(element_mix) | ||
|
||
return element_mixes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from typing import List | ||
|
||
from f4e_radwaste.data_formats.data_mass import DataMass | ||
from f4e_radwaste.post_processing.calculate_dose_rates import DoseCalculator | ||
|
||
|
||
class ComponentsInfo: | ||
def __init__( | ||
self, | ||
component_ids: List[List], | ||
data_mass: DataMass, | ||
dose_calculator: DoseCalculator, | ||
): | ||
self.names, self.cell_ids = zip(*component_ids) | ||
|
||
mat_id_proportions = data_mass.calculate_material_id_proportions(self.cell_ids) | ||
|
||
self.cdr_factors = dose_calculator.calculate_cdr_factors_list( | ||
material_id_proportions=mat_id_proportions | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.