From 5e4f6f955b84ecbe4aef06f6dc5b6e0fe925c2b7 Mon Sep 17 00:00:00 2001 From: tomrink <rink@ssec.wisc.edu> Date: Thu, 30 Sep 2021 09:19:38 -0500 Subject: [PATCH] minor... --- modules/util/util.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/modules/util/util.py b/modules/util/util.py index 1c3f2a92..7cb5e43d 100644 --- a/modules/util/util.py +++ b/modules/util/util.py @@ -324,4 +324,30 @@ def make_times(dt_str_0, dt_str_1=None, format_code='%Y-%m-%d_%H:%M', num_steps= def make_histogram(values, edges): h = np.histogram(values, bins=edges) - return h \ No newline at end of file + return h + + +def normalize(data, param, mean_std_dict, add_noise=False, noise_scale=1.0, seed=None): + + if mean_std_dict.get(param) is None: + return data + + shape = data.shape + data = data.flatten() + + mean, std, lo, hi = mean_std_dict.get(param) + data -= mean + data /= std + + if add_noise: + if seed is not None: + np.random.seed(seed) + rnd = np.random.normal(loc=0, scale=noise_scale, size=data.size) + data += rnd + + not_valid = np.isnan(data) + data[not_valid] = 0 + + data = np.reshape(data, shape) + + return data \ No newline at end of file -- GitLab