From e50d41eac989a8ab2718b4311f32740f865923af Mon Sep 17 00:00:00 2001
From: tomrink <rink@ssec.wisc.edu>
Date: Thu, 20 Oct 2022 11:48:20 -0500
Subject: [PATCH] copy incoming array by default: normalize, scale

---
 modules/util/util.py | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/modules/util/util.py b/modules/util/util.py
index f8269454..4aed787e 100644
--- a/modules/util/util.py
+++ b/modules/util/util.py
@@ -435,7 +435,9 @@ def make_histogram(values, edges):
     return h
 
 
-def normalize(data, param, mean_std_dict, add_noise=False, noise_scale=0.01, seed=None):
+def normalize(data, param, mean_std_dict, add_noise=False, noise_scale=0.01, seed=None, copy=True):
+    if copy:
+        data = data.copy()
 
     if mean_std_dict.get(param) is None:
         return data
@@ -462,7 +464,9 @@ def normalize(data, param, mean_std_dict, add_noise=False, noise_scale=0.01, see
     return data
 
 
-def denormalize(data, param, mean_std_dict):
+def denormalize(data, param, mean_std_dict, copy=True):
+    if copy:
+        data = data.copy()
 
     if mean_std_dict.get(param) is None:
         return data
@@ -479,7 +483,9 @@ def denormalize(data, param, mean_std_dict):
     return data
 
 
-def scale(data, param, mean_std_dict):
+def scale(data, param, mean_std_dict, copy=True):
+    if copy:
+        data = data.copy()
 
     if mean_std_dict.get(param) is None:
         return data
@@ -487,10 +493,6 @@ def scale(data, param, mean_std_dict):
     shape = data.shape
     data = data.flatten()
 
-    if mean_std_dict is None:
-        lo = np.nanmin(data)
-        hi = np.nanmax(data)
-
     _, _, lo, hi = mean_std_dict.get(param)
 
     data -= lo
-- 
GitLab