Skip to content

Commit

Permalink
custom perturbation in Edistr bug solve
Browse files Browse the repository at this point in the history
  • Loading branch information
Bengoechea Aitor authored and Bengoechea Aitor committed Jun 22, 2022
1 parent 5d7d2ba commit 7b767ae
Showing 1 changed file with 10 additions and 20 deletions.
30 changes: 10 additions & 20 deletions sandy/pfns.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,18 +445,8 @@ def custom_perturbation(self, pert):
Parameters
----------
pert : `sandy.Pert` or `pd.DataFrame`
Tabulated perturbation.
mat : `int`, optional
MAT number. The default is None.
mt : `int`
MT number. The default is None.
k : `int`
subsection. The default is None.
ein_low : `float`, optional
lower energy boundary in eV. The default is None.
ein_high : `float`, optional
upper energy boundary in eV. The default is None.
pert : `sandy.Pert` or `pd.Series`
perturbation object.
Returns
-------
Expand All @@ -481,11 +471,11 @@ def custom_perturbation(self, pert):
>>> pert_ = sandy.Pert(df)
>>> orig.custom_perturbation(pert_)
MAT MT K EIN EOUT VALUE
0 9437 18 0 1.00000e+00 1.00000e-05 4.00000e-01
1 9437 18 0 1.00000e+00 2.00000e+07 6.00000e-01
2 9437 18 0 2.00000e+00 1.00000e-04 2.60000e-01
3 9437 18 0 2.00000e+00 1.00000e+00 7.00000e-01
4 9437 18 0 2.00000e+00 1.00000e+07 1.00000e-01
0 9437 18 0 1.00000e+00 1.00000e-05 4.00000e-08
1 9437 18 0 1.00000e+00 2.00000e+07 6.00000e-08
2 9437 18 0 2.00000e+00 1.00000e-04 3.75000e-07
3 9437 18 0 2.00000e+00 1.00000e+00 1.75000e-07
4 9437 18 0 2.00000e+00 1.00000e+07 2.50000e-08
"""
pert_ = sandy.Pert(pert) if not isinstance(pert, sandy.Pert) else pert

Expand All @@ -495,7 +485,7 @@ def custom_perturbation(self, pert):
enew = enew[(enew <= energy_grid.max()) & (enew >= energy_grid.min())]

# Reshape to new energy grid and columns estructure:
u_pert = pert.reshape(enew).right
u_pert = pert.reshape(enew, right_values=0).right

# Apply the perturbation:
def foo(df, pert):
Expand All @@ -512,11 +502,11 @@ def foo(df, pert):
pert_ = pert_.iloc[:, [0]]\
.reindex(index=df.loc[:, "EOUT"].values)\
.values.flatten()
df["VALUE"] = df['VALUE'].values * pert_
df["VALUE"] = df['VALUE'].values + pert_
return df
pert_edistr = self.data.groupby(['MAT', 'MT', 'K', 'EIN'])\
.apply(foo, u_pert)
return self.__class__(pert_edistr)
return self.__class__(pert_edistr).normalize()

def _perturb(self, pert, method=2, normalize=True, **kwargs):
"""Perturb energy distributions given a set of perturbations.
Expand Down

0 comments on commit 7b767ae

Please sign in to comment.