Skip to content

Commit

Permalink
Merge pull request #1769 from HEXRD/scaling-fix
Browse files Browse the repository at this point in the history
fix scaling when dealing with masked arrays
  • Loading branch information
saransh13 authored Dec 19, 2024
2 parents 95e7586 + 6ee0d51 commit ca87363
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions hexrdgui/scaling.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
#####################


def none(x):
def none(x: np.ndarray) -> np.ndarray:
return x


def sqrt(x):
def sqrt(x: np.ndarray) -> np.ndarray:
return np.sqrt(x - np.nanmin(x))


def log(x):
def log(x: np.ndarray) -> np.ndarray:
return np.log(x - np.nanmin(x) + 1)


def log_log_sqrt(x):
def log_log_sqrt(x: np.ndarray) -> np.ndarray:
return np.log(np.log(np.sqrt(x - np.nanmin(x)) + 1) + 1)


Expand All @@ -31,9 +31,14 @@ def rescale_to_old(new, old):
old_range = (np.nanmin(old), np.nanmax(old))
return np.interp(new, new_range, old_range)

def fill_masked(x, fill_value=np.nan):
if isinstance(x, np.ma.masked_array):
return x.filled(fill_value)
return x

@functools.wraps(func)
def wrapper(old):
new = func(old)
new = func(fill_masked(old))
return rescale_to_old(new, old)

return wrapper
Expand Down

0 comments on commit ca87363

Please sign in to comment.