How to use the coffea.util.numpy.union1d function in coffea

To help you get started, we’ve selected a few coffea examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CoffeaTeam / coffea / coffea / lookup_tools / txt_converters.py View on Github external
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
    # ----> just make it jagged all the time
    clamp_mins = {}
    clamp_maxs = {}
    var_order = []
    offset_col = 2 * nBinnedVars + 1
    offset_name = nBinnedVars + 2
github CoffeaTeam / coffea / coffea / lookup_tools / txt_converters.py View on Github external
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
    # ----> just make it jagged all the time
    clamp_mins = {}
    clamp_maxs = {}
github CoffeaTeam / coffea / coffea / lookup_tools / csv_converters.py View on Github external
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) &
                                        (corrections[columns[8]] == discr_bin))
                    vals[k, j, i] = corrections[this_bin][columns[10]][0]
github CoffeaTeam / coffea / coffea / lookup_tools / txt_converters.py View on Github external
# the next bins may vary in number, so they're jagged arrays... yay
    bins = {}
    offset_col = 0
    offset_name = 1
    bin_order = []
    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])
github CoffeaTeam / coffea / coffea / lookup_tools / txt_converters.py View on Github external
offset_name = 1
    bin_order = []
    for i in range(nBinnedVars):
        binMins = None
        binMaxs = None
        if i == 0:
            binMins = np.unique(pars[columns[0]])
            binMaxs = np.unique(pars[columns[1]])
            bins[layout[i + offset_name]] = np.union1d(binMins, binMaxs)
        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 = np.union1d(binMins, binMaxs)
                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

    # again this is only for one dimension of binning, fight me
    # we can figure out a 2D EA when we get there
    offset_name += 1
    wrapped_up = {}
    lookup_type = 'dense_lookup'
    dims = bins[layout[1]]
    for i in range(nEvalVars):
        ea_name = '_'.join([name, columns[offset_name + i]])
        values = pars[columns[offset_name + i]]
        wrapped_up[(ea_name, lookup_type)] = (values, dims)
github CoffeaTeam / coffea / coffea / lookup_tools / txt_converters.py View on Github external
nEvalVars, formula, nParms, columns, dtypes,
                               interpolatedFunc=False):
    # the first bin is always usual for JECs
    # the next bins may vary in number, so they're jagged arrays... yay
    bins = {}
    offset_col = 0
    offset_name = 1
    bin_order = []
    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)