Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
binMins = None
binMaxs = None
if i == 0:
binMins = np.unique(pars[columns[0]])
binMaxs = np.unique(pars[columns[1]])
if np.all(binMins[1:] == binMaxs[:-1]):
bins[layout[i + offset_name]] = np.union1d(binMins, binMaxs)
else:
warnings.warn('binning for file for %s is malformed in variable %s' % (name, layout[i + offset_name]))
bins[layout[i + offset_name]] = np.union1d(binMins, binMaxs[-1:])
else:
counts = np.zeros(0, dtype=np.int)
allBins = np.zeros(0, dtype=np.double)
for binMin in bins[bin_order[0]][:-1]:
binMins = np.unique(pars[np.where(pars[columns[0]] == binMin)][columns[i + offset_col]])
binMaxs = np.unique(pars[np.where(pars[columns[0]] == binMin)][columns[i + offset_col + 1]])
theBins = None
if np.all(binMins[1:] == binMaxs[:-1]):
theBins = np.union1d(binMins, binMaxs)
else:
warnings.warn('binning for file for %s is malformed in variable %s' % (name, layout[i + offset_name]))
theBins = np.union1d(binMins, binMaxs[-1:])
allBins = np.append(allBins, theBins)
counts = np.append(counts, theBins.size)
bins[layout[i + offset_name]] = awkward.JaggedArray.fromcounts(counts, allBins)
bin_order.append(layout[i + offset_name])
offset_col += 1
# skip nvars to the variable columns
# the columns here define clamps for the variables defined in columns[]
# ----> clamps can be different from bins
# ----> if there is more than one binning variable this array is jagged
def masked_bin_eval(dim1_indices, dimN_bins, dimN_vals):
dimN_indices = np.empty_like(dim1_indices)
for i in np.unique(dim1_indices):
idx = np.where(dim1_indices == i)
dimN_indices[idx] = np.clip(np.searchsorted(dimN_bins[i],
dimN_vals[idx],
side='right') - 1,
0, len(dimN_bins[i]) - 2)
return dimN_indices
def masked_bin_eval(dim1_indices, dimN_bins, dimN_vals):
dimN_indices = np.empty_like(dim1_indices)
for i in np.unique(dim1_indices):
idx = np.where(dim1_indices == i)
dimN_indices[idx] = np.clip(np.searchsorted(dimN_bins[i],
dimN_vals[idx],
side='right') - 1,
0, len(dimN_bins[i]) - 2)
return dimN_indices
def masked_bin_eval(dim1_indices, dimN_bins, dimN_vals):
dimN_indices = np.empty_like(dim1_indices)
for i in np.unique(dim1_indices):
idx = np.where(dim1_indices == i)
dimN_indices[idx] = np.clip(np.searchsorted(dimN_bins[i],
dimN_vals[idx],
side='right') - 1,
0, len(dimN_bins[i]) - 2)
return dimN_indices
for i in range(nBinnedVars):
binMins = None
binMaxs = None
if i == 0:
binMins = np.unique(pars[columns[0]])
binMaxs = np.unique(pars[columns[1]])
if np.all(binMins[1:] == binMaxs[:-1]):
bins[layout[i + offset_name]] = np.union1d(binMins, binMaxs)
else:
warnings.warn('binning for file for %s is malformed in variable %s' % (name, layout[i + offset_name]))
bins[layout[i + offset_name]] = np.union1d(binMins, binMaxs[-1:])
else:
counts = np.zeros(0, dtype=np.int)
allBins = np.zeros(0, dtype=np.double)
for binMin in bins[bin_order[0]][:-1]:
binMins = np.unique(pars[np.where(pars[columns[0]] == binMin)][columns[i + offset_col]])
binMaxs = np.unique(pars[np.where(pars[columns[0]] == binMin)][columns[i + offset_col + 1]])
theBins = None
if np.all(binMins[1:] == binMaxs[:-1]):
theBins = np.union1d(binMins, binMaxs)
else:
warnings.warn('binning for file for %s is malformed in variable %s' % (name, layout[i + offset_name]))
theBins = np.union1d(binMins, binMaxs[-1:])
allBins = np.append(allBins, theBins)
counts = np.append(counts, theBins.size)
bins[layout[i + offset_name]] = awkward.JaggedArray.fromcounts(counts, allBins)
bin_order.append(layout[i + offset_name])
offset_col += 1
# skip nvars to the variable columns
# the columns here define clamps for the variables defined in columns[]
# ----> clamps can be different from bins
dtype=None,
names=tuple(columns),
converters={1: lambda s: s.strip(),
2: lambda s: s.strip(),
10: lambda s: s.strip(' "')},
delimiter=',',
skip_header=1,
unpack=True,
encoding='ascii'
)
all_names = corrections[[columns[i] for i in range(4)]]
labels = np.unique(corrections[[columns[i] for i in range(4)]])
wrapped_up = {}
for label in labels:
etaMins = np.unique(corrections[np.where(all_names == label)][columns[4]])
etaMaxs = np.unique(corrections[np.where(all_names == label)][columns[5]])
etaBins = np.union1d(etaMins, etaMaxs).astype(np.double)
ptMins = np.unique(corrections[np.where(all_names == label)][columns[6]])
ptMaxs = np.unique(corrections[np.where(all_names == label)][columns[7]])
ptBins = np.union1d(ptMins, ptMaxs).astype(np.double)
discrMins = np.unique(corrections[np.where(all_names == label)][columns[8]])
discrMaxs = np.unique(corrections[np.where(all_names == label)][columns[9]])
discrBins = np.union1d(discrMins, discrMaxs).astype(np.double)
vals = np.zeros(shape=(len(discrBins) - 1, len(ptBins) - 1, len(etaBins) - 1),
dtype=corrections.dtype[10])
for i, eta_bin in enumerate(etaBins[:-1]):
for j, pt_bin in enumerate(ptBins[:-1]):
for k, discr_bin in enumerate(discrBins[:-1]):
this_bin = np.where((all_names == label) &
(corrections[columns[4]] == eta_bin) &
(corrections[columns[6]] == pt_bin) &