Skip to content
Snippets Groups Projects
Commit cec156ed authored by Nikolai.Hartmann's avatar Nikolai.Hartmann
Browse files

option to use a maximum number of events for get_ranges

parent cc9eda10
No related branches found
No related tags found
No related merge requests found
...@@ -45,14 +45,19 @@ def create_random_event(ranges, mask_probs=None, mask_value=None): ...@@ -45,14 +45,19 @@ def create_random_event(ranges, mask_probs=None, mask_value=None):
return random_event return random_event
def get_ranges(x, quantiles, weights, mask_value=None, filter_index=None): def get_ranges(x, quantiles, weights, mask_value=None, filter_index=None, max_evts=None):
"Get ranges for plotting or random event generation based on quantiles" "Get ranges for plotting or random event generation based on quantiles"
ranges = [] ranges = []
mask_probs = [] mask_probs = []
if max_evts is not None:
rnd_idx = np.random.permutation(np.arange(len(x)))
rnd_idx = rnd_idx[:max_evts]
for var_index in range(x.shape[1]): for var_index in range(x.shape[1]):
if (filter_index is not None) and (var_index != filter_index): if (filter_index is not None) and (var_index != filter_index):
continue continue
x_var = x[:,var_index] x_var = x[:,var_index]
if max_evts is not None:
x_var = x_var[rnd_idx]
not_masked = np.where(x_var != mask_value)[0] not_masked = np.where(x_var != mask_value)[0]
masked = np.where(x_var == mask_value)[0] masked = np.where(x_var == mask_value)[0]
ranges.append(weighted_quantile(x_var[not_masked], quantiles, sample_weight=weights[not_masked])) ranges.append(weighted_quantile(x_var[not_masked], quantiles, sample_weight=weights[not_masked]))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment