Skip to content

Commit

Permalink
Keep negative entries by default. Solves #119.
Browse files Browse the repository at this point in the history
Keep negative entries in Ensemble, Unfolder and Fristgen by default.
  • Loading branch information
fzeiser committed Sep 8, 2020
1 parent 414a1a8 commit cf32991
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 25 deletions.
2 changes: 0 additions & 2 deletions ompy/ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@ def subtract_bg(self, step: int, matrix: Matrix, bg: Matrix) -> Matrix:
if raw is None:
LOG.debug("Raw matrix")
raw = matrix - self.bg_ratio * bg
raw.remove_negative()
raw.save(path)
self.action_raw.act_on(raw)
return raw
Expand Down Expand Up @@ -431,7 +430,6 @@ def generate_gaussian(self, state: str,
std = np.sqrt(np.where(mat.values > 0, mat.values, 0))
perturbed = rstate.normal(size=mat.shape, loc=mat.values,
scale=std)
perturbed[perturbed < 0] = 0
return perturbed

def generate_poisson(self, state: str,
Expand Down
2 changes: 1 addition & 1 deletion ompy/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def decompose(self, matrix: Matrix,
"""
if np.any(matrix.values < 0):
raise ValueError("input matrix has to have positive entries only.")
LOG.debug("input matrix has negative entries.")
if std is not None:
std = std.copy()
if np.any(std.values < 0):
Expand Down
14 changes: 1 addition & 13 deletions ompy/firstgeneration.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def apply(self, unfolded: Matrix) -> Matrix:
raise ValueError("input matrix has to have positive Ex entries"
"only. Consider using `matrix.cut('Ex', Emin=0)`")
if np.any(matrix.values < 0):
raise ValueError("input matrix has to have positive entries only.")
LOG.debug("input matrix has negative counts.")

valley_correction = self.cut_valley_correction(matrix)

Expand All @@ -105,7 +105,6 @@ def apply(self, unfolded: Matrix) -> Matrix:

final = Matrix(values=H, Eg=matrix.Eg, Ex=matrix.Ex)
final.state = "firstgen"
self.remove_negative(final)
return final

def setup(self, matrix: Matrix) -> Tuple[Matrix, Matrix, Matrix]:
Expand Down Expand Up @@ -367,17 +366,6 @@ def allgen_from_primary(fg: Matrix,

return ag

def remove_negative(self, matrix: Matrix):
""" Wrapper for Matrix.remove_negative()
Put in as an extra method to facilitate replacing this by eg.
`fill_and_remove_negatve`
Args:
matrix: Input matrix
"""
matrix.remove_negative()


def normalize_rows(array: np.ndarray) -> np.ndarray:
""" Normalize each row to unity """
Expand Down
9 changes: 4 additions & 5 deletions ompy/unfolder.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,12 @@ def update_values(self):
raise ValueError("Must have equal energy binning.")

LOG.debug("Check for negative counts.")
if np.any(self.raw.values < 0) or np.any(self.R.values < 0):
raise ValueError("Raw and response cannot have negative counts."
if np.any(self.R.values < 0):
raise ValueError("Response cannot have negative counts."
"Consider using fill_negatives and "
"remove_negatives on the input matixes.")

if np.any(self.raw.values < 0):
LOG.debug("Raw matrix has negative counts.")
self.r = self.raw.values

def apply(self, raw: Matrix,
Expand Down Expand Up @@ -182,8 +183,6 @@ def apply(self, raw: Matrix,

unfolded = Matrix(unfolded, Eg=self.raw.Eg, Ex=self.raw.Ex)
unfolded.state = "unfolded"

self.remove_negative(unfolded)
return unfolded

def step(self, unfolded: np.ndarray, folded: np.ndarray,
Expand Down
14 changes: 11 additions & 3 deletions release_note.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
# Release notes for OMpy

## [Unreleased]
Changes:
- Fixed a bug where the `std` attribute of `Vector` was not saved to file.
## v.1.2.0
Most important changes:
Changed:
- No removal of negative counts in Ensemble generation, Unfolder and Firstgen
any longer. These can de applied, if wanted, through actions, see #119.

Fixed:
- Fixed a bug where the `std` attribute of `Vector` was not saved to file.

Added:
- New response matrixes of OSCAR

## v.1.1.0
Most important changes:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

# Version rutine taken from numpy
MAJOR = 1
MINOR = 1
MINOR = 2
MICRO = 0
VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO)

Expand Down

0 comments on commit cf32991

Please sign in to comment.