Ejemplo n.º 1
0
 def to_operation(self, **kwargs):
     proc = AccumulatorProc(self.values['text'])
     node = gn.Accumulator(name=self.name() + "_accumulated",
                           **kwargs,
                           res_factor=proc.res_factory,
                           reduction=proc)
     return node
Ejemplo n.º 2
0
    def to_operation(self, inputs, conditions={}):
        outputs = self.output_vars()
        map_outputs = [
            self.name() + "_xbins",
            self.name() + "_ybins",
            self.name() + "_counts"
        ]
        nxbins = self.values['x bins']
        nybins = self.values['y bins']
        xmin = self.values['range x min']
        xmax = self.values['range x max']
        ymin = self.values['range y min']
        ymax = self.values['range y max']
        density = self.values['density']

        if self.x_type == float and self.y_type == float:

            def bin(x, y):
                counts, xbins, ybins = np.histogram2d([x], [y],
                                                      bins=[nxbins, nybins],
                                                      range=[[xmin, xmax],
                                                             [ymin, ymax]],
                                                      density=density)
                return xbins, ybins, counts
        else:

            def bin(x, y):
                counts, xbins, ybins = np.histogram2d(x,
                                                      y,
                                                      bins=[nxbins, nybins],
                                                      range=[[xmin, xmax],
                                                             [ymin, ymax]],
                                                      density=density)
                return xbins, ybins, counts

        def reduction(res, *rest):
            res[0] = rest[0]
            res[1] = rest[1]
            res[2] = res[2] + rest[2]
            return res

        node = [
            gn.Map(name=self.name() + "_map",
                   condition_needs=conditions,
                   inputs=inputs,
                   outputs=map_outputs,
                   func=bin,
                   parent=self.name()),
            gn.Accumulator(name=self.name() + "_accumulated",
                           inputs=map_outputs,
                           outputs=outputs,
                           res_factory=lambda: [None, None, 0],
                           reduction=reduction,
                           parent=self.name())
        ]
        return node
Ejemplo n.º 3
0
    def to_operation(self, inputs, conditions={}):
        outputs = self.output_vars()

        axis = self.values['axis']
        accumulated_outputs = [self.name() + '_accumulated_events']

        if self.values['infinite']:

            def reduction(res, *rest):
                if type(rest[0]) is list:
                    res[0] = np.sum([res[0], rest[0][0]], axis=axis)
                    res[1] += rest[0][1]
                else:
                    res[0] = np.sum([res[0], rest[0]], axis=axis)
                    res[1] = res[1] + 1
                return res

            def avg(*args, **kwargs):
                return args[0][0] / args[0][1]

            nodes = [
                gn.Accumulator(name=self.name() + "_accumulated",
                               inputs=inputs,
                               outputs=accumulated_outputs,
                               condition_needs=conditions,
                               res_factory=lambda: [0, 0],
                               reduction=reduction,
                               parent=self.name()),
                gn.Map(name=self.name() + "_map",
                       inputs=accumulated_outputs,
                       outputs=outputs,
                       func=avg,
                       parent=self.name())
            ]

        else:

            def func(arrs):
                return np.sum(arrs, axis=axis) / len(arrs)

            nodes = [
                gn.PickN(name=self.name() + "_accumulated",
                         inputs=inputs,
                         outputs=accumulated_outputs,
                         condition_needs=conditions,
                         N=self.values['N'],
                         parent=self.name()),
                gn.Map(name=self.name() + "_map",
                       inputs=accumulated_outputs,
                       outputs=outputs,
                       func=func,
                       parent=self.name())
            ]

        return nodes
Ejemplo n.º 4
0
    def to_operation(self, inputs, outputs, **kwargs):
        accumulated_outputs = [self.name() + '_accumulated_events']

        if self.values['infinite']:

            def reduction(res, *rest):
                if type(rest[0]) is list:
                    res[0] += rest[0][0]
                    res[1] += rest[0][1]
                else:
                    res[0] = res[0] + rest[0]
                    res[1] = res[1] + 1
                return res

            def avg(*args, **kwargs):
                return args[0][0] / args[0][1]

            nodes = [
                gn.Accumulator(name=self.name() + "_accumulated",
                               inputs=inputs,
                               outputs=accumulated_outputs,
                               res_factory=lambda: [0, 0],
                               reduction=reduction,
                               **kwargs),
                gn.Map(name=self.name() + "_map",
                       inputs=accumulated_outputs,
                       outputs=outputs,
                       func=avg,
                       **kwargs)
            ]
        else:

            def func(arrs):
                return np.average(arrs)

            nodes = [
                gn.PickN(name=self.name() + "_accumulated",
                         inputs=inputs,
                         outputs=accumulated_outputs,
                         N=self.values['N'],
                         **kwargs),
                gn.Map(name=self.name() + "_map",
                       inputs=accumulated_outputs,
                       outputs=outputs,
                       func=func,
                       **kwargs)
            ]

        return nodes
Ejemplo n.º 5
0
    def to_operation(self, inputs, conditions={}):
        outputs = self.output_vars()
        map_outputs = [self.name() + "_bins", self.name() + "_counts"]
        nbins = self.values['bins']
        density = self.values['density']

        range = None
        if not self.values['auto range']:
            range = (self.values['range min'], self.values['range max'])

        def bin(arr, weights=None):
            counts, bins = np.histogram(arr,
                                        bins=nbins,
                                        range=range,
                                        density=density,
                                        weights=weights)
            return bins, counts

        def reduction(res, *rest):
            res[0] = rest[0]
            res[1] = res[1] + rest[1]
            return res

        node = [
            gn.Map(name=self.name() + "_map",
                   condition_needs=conditions,
                   inputs=inputs,
                   outputs=map_outputs,
                   func=bin,
                   parent=self.name()),
            gn.Accumulator(name=self.name() + "_accumulated",
                           inputs=map_outputs,
                           outputs=outputs,
                           res_factory=lambda: [None, 0],
                           reduction=reduction,
                           parent=self.name())
        ]
        return node