From 8910d9f4c7c7486848aa4881b0714e4ee36e3570 Mon Sep 17 00:00:00 2001 From: Aitor Bengoetxea Date: Mon, 27 Jun 2022 11:56:32 +0200 Subject: [PATCH] Update doctring and reconstruction --- sandy/core/lpc.py | 9 ++------- sandy/core/xs.py | 4 ---- sandy/pert.py | 9 ++++++--- sandy/pfns.py | 26 ++++++++++++++------------ sandy/shared.py | 6 ++++++ 5 files changed, 28 insertions(+), 26 deletions(-) diff --git a/sandy/core/lpc.py b/sandy/core/lpc.py index 756e2e17..8b7d294e 100644 --- a/sandy/core/lpc.py +++ b/sandy/core/lpc.py @@ -188,14 +188,8 @@ def custom_perturbation(self, pert): Parameters ---------- - pert : `sandy.Pert` + pert : `sandy.Pert` or pd.Dataframe tabulated perturbations - mat : `int`, optional - MAT material number. The default is None. - mt : `int`, optional - MT reaction number. The default is None. - p : `int`, optional - order of the Legendre polynomial coefficient. The default is None. Returns ------- @@ -224,6 +218,7 @@ def custom_perturbation(self, pert): Name: 1, dtype: float64 """ pert_ = sandy.Pert(pert) if not isinstance(pert, sandy.Pert) else pert + # Endf6 mf=34 incosistency solver: if 'L' in pert_.data.columns.names: pert_.data.columns = pert_.data.columns.set_names('P', level='L') diff --git a/sandy/core/xs.py b/sandy/core/xs.py index 9da849d3..b236990f 100644 --- a/sandy/core/xs.py +++ b/sandy/core/xs.py @@ -165,10 +165,6 @@ def custom_perturbation(self, pert, **kwargs): pert : `sandy.Pert` or `pd.Dataframe` tabulated perturbations with the index representing the energy grid and the columns representing MT. - mat : `int`, optional - MAT number. The default is None. - mt : `int`, optional - MT number. The default is None. **kwargs : `dict` keyword argument to pass to `sandy.Xs._recontruct_sums`. diff --git a/sandy/pert.py b/sandy/pert.py index 049029b0..8f3dd9b5 100644 --- a/sandy/pert.py +++ b/sandy/pert.py @@ -29,8 +29,8 @@ class Pert(): Attributes ---------- - data : `pandas.Series` - series of groupwise perturbation coefficients + data : `pandas.DataFrame` + DataFrame of groupwise perturbation coefficients left : `pandas.Series` perturbation coefficients with left-bounds of the energy intervals as index @@ -114,7 +114,7 @@ def right(self): Returns ------- - `pandas.Series` + `pandas.DataFrame` perturbations Examples @@ -240,6 +240,9 @@ def reshape(self, eg, inplace=False, right_values=1): monotonic energy grid with non-negative values inplace : `bool`, optional, default is `False` apply changes **inplace** and return `None` + right_values: `float`, optional, default is 1 + This value will be used to fill in for requested points outside of + the data range at the upper limit. Returns ------- diff --git a/sandy/pfns.py b/sandy/pfns.py index 280b47b8..5ba84066 100644 --- a/sandy/pfns.py +++ b/sandy/pfns.py @@ -423,17 +423,17 @@ def normalize(self): 1 9437 18 0 2.00000e+00 1.00000e+00 """ integrals = self.get_integrals() - data = self.data.copy() - keys = ["MAT", "MT", "K", "EIN"] - out = [] - for (mat, mt, k, ein), chi in data.groupby(keys): - mask = (integrals.MAT == mat) & \ - (integrals.MT == mt) & \ - (integrals.K == k) & \ - (integrals.EIN == ein) - chi.loc[:, "VALUE"] /= integrals[mask].INTEGRAL.squeeze() - out.append(chi) - df = pd.concat(out) + + def foo(df, integrals): + data = df.iloc[0] + mask = (integrals.MAT == data.MAT) & \ + (integrals.MT == data.MT) & \ + (integrals.K == data.K) & \ + (integrals.EIN == data.EIN) + df.loc[:, "VALUE"] /= integrals[mask].INTEGRAL.squeeze() + return df + + df = self.data.groupby(["MAT", "MT", "K", "EIN"]).apply(foo, integrals) return self.__class__(df) def custom_perturbation(self, pert): @@ -445,7 +445,7 @@ def custom_perturbation(self, pert): Parameters ---------- - pert : `sandy.Pert` or `pd.Series` + pert : `sandy.Pert` or `pd.DataFrame` perturbation object. Returns @@ -504,8 +504,10 @@ def foo(df, pert): .values.flatten() 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).normalize() def _perturb(self, pert, method=2, normalize=True, **kwargs): diff --git a/sandy/shared.py b/sandy/shared.py index 4d005e9a..c95754ee 100644 --- a/sandy/shared.py +++ b/sandy/shared.py @@ -306,6 +306,12 @@ def reshape_bfill(x, y, xnew, left_values="first", right_values=0): new energy grid y : `numpy.ndarray` with at least two entries and same length as `x` array to interpolate + left_values:`str` or `float` + This value will be used to fill in for requested points outside of the + data range at the lower limit.รง + right_values:`str` or `float` + This value will be used to fill in for requested points outside of the + data range at the upper limit. Returns -------