Histogramming, grouping, and binning

Overview

Histogramming (see sc.histogram), grouping (using sc.groupby), and binning (see Binned data) all serve similar but slightly different purposes. Picking the optimal one of the three for a particular application may yield more natural code and better performance. Let us start by an example. Consider a table of scattered measurements:

[1]:
import numpy as np
import scipp as sc
N = 5000
values = 10*np.random.rand(N)
data = sc.DataArray(
    data=sc.Variable(dims=['position'], unit=sc.units.counts, values=values, variances=values),
    coords={
        'x':sc.Variable(dims=['position'], unit=sc.units.m, values=np.random.rand(N)),
        'y':sc.Variable(dims=['position'], unit=sc.units.m, values=np.random.rand(N))
    })
data.values *= 1.0/np.exp(5.0*data.coords['x'].values)
sc.table(data['position', :5])

We may now be interested in the total intensity (counts) as a function of 'x'. There are three ways to do this:

[2]:
xbins = sc.Variable(dims=['x'], unit=sc.units.m, values=np.linspace(0,1,num=40))
ds = sc.Dataset()
ds['histogram'] = sc.histogram(data, bins=xbins)
ds['groupby']   = sc.groupby(data, group='x', bins=xbins).sum('position')
ds['bin']       = sc.bin(data, edges=[xbins]).bins.sum()
ds.plot()

In the above plot we can only see a single line, since the three solutions yield exactly the same result (neglecting floating-point rounding errors):

  • histogram sorts data points into ‘x’ bins, summing immediately.

  • groupby groups by ‘x’ and then sums (on-the-fly) all data points falling in the same ‘x’ bin.

  • bin sorts data points into ‘x’ bins. Summing all rows in a bin yields the same result as grouping and summing directly.

So in this case we get equivalent results, but the application areas differ, as described in more detail in the following sections.

Histogramming

histogram directly sums the data and is efficient. Limitations are:

  • Can currently only histogram along a single dimension.

  • Can currently only apply the “sum” to accumulate into a bin. Support for more operations, such as “mean”, is considered for the future.

While histogramming is only supported along a single dimension, we can histogram binned data (since binning preserves the 'y' coord), to create 2-D (or N-D) histograms:

[3]:
binned = sc.bin(data, edges=[xbins])
ybins = sc.linspace(dim='y', unit='m', start=0, stop=1, num=30)
hist = sc.histogram(binned, bins=ybins)
hist.plot()
[4]:
hist
[4]:
Show/Hide data repr Show/Hide attributes
scipp.DataArray (18.22 KB)
    • x: 39
    • y: 29
    • x
      (x [bin-edge])
      float64
      m
      0.0, 0.03, ..., 0.97, 1.0
      Values:
      array([0. , 0.02564103, 0.05128205, 0.07692308, 0.1025641 , 0.12820513, 0.15384615, 0.17948718, 0.20512821, 0.23076923, 0.25641026, 0.28205128, 0.30769231, 0.33333333, 0.35897436, 0.38461538, 0.41025641, 0.43589744, 0.46153846, 0.48717949, 0.51282051, 0.53846154, 0.56410256, 0.58974359, 0.61538462, 0.64102564, 0.66666667, 0.69230769, 0.71794872, 0.74358974, 0.76923077, 0.79487179, 0.82051282, 0.84615385, 0.87179487, 0.8974359 , 0.92307692, 0.94871795, 0.97435897, 1. ])
    • y
      (y [bin-edge])
      float64
      m
      0.0, 0.03, ..., 0.97, 1.0
      Values:
      array([0. , 0.03448276, 0.06896552, 0.10344828, 0.13793103, 0.17241379, 0.20689655, 0.24137931, 0.27586207, 0.31034483, 0.34482759, 0.37931034, 0.4137931 , 0.44827586, 0.48275862, 0.51724138, 0.55172414, 0.5862069 , 0.62068966, 0.65517241, 0.68965517, 0.72413793, 0.75862069, 0.79310345, 0.82758621, 0.86206897, 0.89655172, 0.93103448, 0.96551724, 1. ])
    • (x, y)
      float64
      counts
      36.56, 23.47, ..., 0.21, 0.23
      σ = 6.19, 4.99, ..., 5.47, 5.58
      Values:
      array([[3.65565421e+01, 2.34689934e+01, 0.00000000e+00, ..., 3.34702492e+01, 0.00000000e+00, 3.04828108e+01], [2.50260064e+01, 1.17834918e+01, 1.46020992e+01, ..., 1.62260050e+01, 2.39036096e+01, 1.61040146e+01], [4.51913400e+00, 1.13787482e+01, 1.14782046e+01, ..., 2.28836685e+01, 9.55604565e+00, 1.63983247e+01], ..., [6.62619600e-02, 2.72249986e-01, 2.19418871e-01, ..., 2.35440321e-01, 1.39397474e-01, 4.16564203e-01], [3.46530977e-01, 1.23382073e-01, 2.39315819e-01, ..., 3.37676450e-02, 5.66369129e-02, 2.66311119e-01], [1.78126867e-01, 1.52096416e-01, 1.08415320e-01, ..., 2.04936021e-01, 2.07783049e-01, 2.26295194e-01]])

      Variances (σ²):
      array([[38.29300532, 24.91875283, 0. , ..., 35.92754098, 0. , 32.25454601], [30.47149832, 14.98954442, 17.83869372, ..., 19.82007877, 29.49106068, 19.85056479], [ 6.21044843, 15.62442485, 15.8749918 , ..., 31.78217891, 12.91967606, 23.18640503], ..., [ 6.91698978, 28.52005618, 23.12772874, ..., 25.19200267, 15.01614439, 44.61795035], [42.29234754, 14.38870963, 29.05967382, ..., 3.95742622, 6.95014403, 32.4038284 ], [24.47985073, 21.50720756, 14.90918764, ..., 28.61325549, 29.89732782, 31.09675623]])

Another capability of histogram is to histogram a dimension that has previously been binned with a different or higher resolution, i.e. different bin edges. Compare to the plot of the initial example:

[5]:
binned = sc.bin(data, edges=[xbins])
xbins_fine = sc.linspace(dim='x', unit='m', start=0, stop=1, num=100)
sc.histogram(binned, bins=xbins_fine).plot()

Grouping

groupby is more flexible in terms of operations than can be applied and may be the go-to solution when a quick one-liner is required. Limitations are:

  • Can only group along a single dimension.

  • Works best for small to medium-sized data, or if data is already mostly sorted along the grouping dimension. Slow if millions of small input slices contribute to each group.

groupby can also operate on binned data, combining bin contents by concatenation:

[6]:
binned = sc.bin(data, edges=[xbins])
binned.coords['param'] = sc.Variable(dims=['x'], values=(np.random.random(39)*4).astype(np.int32))
grouped = binned.groupby('param').bins.concatenate('x')
grouped
[6]:
Show/Hide data repr Show/Hide attributes
scipp.DataArray (156.33 KB)
    • param: 4
    • param
      (param)
      int32
      0, 1, 2, 3
      Values:
      array([0, 1, 2, 3], dtype=int32)
    • (param)
      DataArrayView
      binned data [len=1002, len=1398, len=1340, len=1260]
      Values:
      [<scipp.DataArray> Dimensions: Sizes[position:1002, ] Coordinates: x float64 [m] (position) [0.115011, 0.113265, 0.106668, 0.112191, ..., 0.813354, 0.797692, 0.809248, 0.795349] y float64 [m] (position) [0.647243, 0.382919, 0.265850, 0.104158, ..., 0.818611, 0.947364, 0.174000, 0.327012] Data: float64 [counts] (position) [4.161373, 2.968900, 0.789557, 5.237783, ..., 0.117981, 0.159927, 0.146811, 0.110577] [7.395720, 5.230554, 1.345892, 9.178418, ..., 6.886309, 8.631541, 8.394949, 5.898502] , <scipp.DataArray> Dimensions: Sizes[position:1398, ] Coordinates: x float64 [m] (position) [0.021783, 0.012782, 0.008679, 0.016268, ..., 0.961252, 0.958867, 0.969270, 0.967580] y float64 [m] (position) [0.226486, 0.390161, 0.454753, 0.732683, ..., 0.300333, 0.329639, 0.663253, 0.397887] Data: float64 [counts] (position) [0.088361, 7.186757, 1.866541, 3.711400, ..., 0.035522, 0.046561, 0.025743, 0.078692] [0.098528, 7.661075, 1.949322, 4.025894, ..., 4.343382, 5.625648, 3.276376, 9.931303] , <scipp.DataArray> Dimensions: Sizes[position:1340, ] Coordinates: x float64 [m] (position) [0.156350, 0.156763, 0.174665, 0.169697, ..., 0.976851, 0.985939, 0.978140, 0.989804] y float64 [m] (position) [0.410647, 0.727342, 0.016929, 0.545156, ..., 0.644278, 0.930408, 0.656594, 0.759053] Data: float64 [counts] (position) [2.519453, 1.021454, 0.006006, 2.479796, ..., 0.068052, 0.039182, 0.044036, 0.034753] [5.505748, 2.236789, 0.014383, 5.793051, ..., 8.995980, 5.420403, 5.858798, 4.901436] , <scipp.DataArray> Dimensions: Sizes[position:1260, ] Coordinates: x float64 [m] (position) [0.042447, 0.030081, 0.037600, 0.041584, ..., 0.857000, 0.862359, 0.846909, 0.854185] y float64 [m] (position) [0.404295, 0.304289, 0.338609, 0.869768, ..., 0.102776, 0.696358, 0.996170, 0.983874] Data: float64 [counts] (position) [3.626714, 2.940578, 2.971683, 3.823744, ..., 0.130473, 0.090159, 0.014547, 0.021638] [4.484202, 3.417856, 3.586335, 4.707468, ..., 9.472659, 6.723552, 1.004178, 1.548998] ]

Each output bin is a combination of multiple input bins:

[7]:
grouped.values[0]
[7]:
Show/Hide data repr Show/Hide attributes
scipp.DataArray (31.31 KB out of 156.25 KB)
    • position: 1002
    • x
      (position)
      float64
      m
      0.12, 0.11, ..., 0.81, 0.8
      Values:
      array([0.11501127, 0.11326512, 0.10666793, ..., 0.79769219, 0.80924849, 0.79534912])
    • y
      (position)
      float64
      m
      0.65, 0.38, ..., 0.17, 0.33
      Values:
      array([0.64724307, 0.38291879, 0.26585029, ..., 0.94736353, 0.17400033, 0.32701174])
    • (position)
      float64
      counts
      4.16, 2.97, ..., 0.15, 0.11
      σ = 2.72, 2.29, ..., 2.9, 2.43
      Values:
      array([4.16137297, 2.96890021, 0.78955724, ..., 0.15992698, 0.14681055, 0.11057655])

      Variances (σ²):
      array([7.39571951, 5.23055383, 1.34589161, ..., 8.63154057, 8.39494856, 5.89850181])

Binning

bin actually reorders data and meta data such that all data contributing to a bin is in a contiguous block. Binning along multiple dimensions is supported. Of the three options it is the only solution that supports modifying data in the grouped/binned layout. A variety of operations on such binned data is available. Limitations are:

  • Requires copying and reordering the input data and can thus become expensive.

In the above example the 'y' information is dropped by histogram and groupby, but bin preserves it:

[8]:
binned = sc.bin(data, edges=[xbins])
binned.values[0]
[8]:
Show/Hide data repr Show/Hide attributes
scipp.DataArray (4.12 KB out of 156.25 KB)
    • position: 132
    • x
      (position)
      float64
      m
      0.02, 0.01, ..., 0.01, 0.02
      Values:
      array([0.02178306, 0.01278244, 0.00867888, 0.01626758, 0.00589831, 0.02509273, 0.02246884, 0.0035705 , 0.0066222 , 0.01067784, 0.01118732, 0.0238847 , 0.0164758 , 0.02300164, 0.01698266, 0.01061821, 0.00689803, 0.01592698, 0.02429117, 0.01579005, 0.00863822, 0.01667077, 0.01523587, 0.00732722, 0.02312531, 0.00349351, 0.01803824, 0.0003238 , 0.00465751, 0.00084154, 0.01978679, 0.0153657 , 0.00378088, 0.02467123, 0.00559906, 0.01112219, 0.01365175, 0.02451364, 0.01842751, 0.00153254, 0.0035238 , 0.00926232, 0.02418679, 0.00963281, 0.00954568, 0.01131283, 0.01688852, 0.00662958, 0.01065953, 0.02399149, 0.01390655, 0.00315448, 0.01303279, 0.00930166, 0.01374677, 0.0250414 , 0.01804864, 0.00734133, 0.02479054, 0.0003127 , 0.00570422, 0.01459298, 0.0153132 , 0.02272677, 0.01724122, 0.00623416, 0.01824642, 0.01356302, 0.00999926, 0.00751959, 0.01135626, 0.02210622, 0.00613781, 0.01304452, 0.0093068 , 0.02298528, 0.00228283, 0.02374768, 0.02534153, 0.00294884, 0.01855989, 0.00161276, 0.02044065, 0.0135108 , 0.02081662, 0.01770658, 0.00895592, 0.02451272, 0.02195816, 0.0179274 , 0.0093043 , 0.00974999, 0.00099649, 0.01323932, 0.02438363, 0.01613541, 0.01323367, 0.00571854, 0.01955774, 0.02512959, 0.00372643, 0.02522899, 0.00532544, 0.00221788, 0.0091014 , 0.01273541, 0.01622048, 0.02317457, 0.01079338, 0.01433771, 0.00138594, 0.01773026, 0.01276113, 0.01549566, 0.01768098, 0.00885674, 0.01211113, 0.01947346, 0.00927106, 0.00640016, 0.01038946, 0.01347088, 0.01263304, 0.02453864, 0.00314287, 0.01247619, 0.00510578, 0.01150424, 0.00980332, 0.0240721 , 0.01028192, 0.02172611])
    • y
      (position)
      float64
      m
      0.23, 0.39, ..., 0.38, 0.32
      Values:
      array([0.22648606, 0.39016063, 0.45475273, 0.73268299, 0.39498612, 0.3505011 , 0.80497559, 0.05496476, 0.48732984, 0.98411443, 0.90843795, 0.83930652, 0.84963003, 0.85834242, 0.31772282, 0.44885366, 0.77255721, 0.39323123, 0.90172878, 0.99157585, 0.50351032, 0.30775103, 0.84114414, 0.00419551, 0.64093337, 0.35311926, 0.13163255, 0.51183564, 0.33071612, 0.4505236 , 0.5995874 , 0.61429182, 0.59563348, 0.89658922, 0.03500688, 0.64183528, 0.05341761, 0.52843183, 0.78216187, 0.3299337 , 0.93000828, 0.65010638, 0.59694695, 0.79537277, 0.33236195, 0.73732198, 0.1712498 , 0.38113248, 0.88842057, 0.17758195, 0.00852175, 0.35932251, 0.40629555, 0.84474484, 0.00836039, 0.80745696, 0.03932421, 0.74027841, 0.04845139, 0.81096058, 0.65144269, 0.37097393, 0.86495065, 0.1584794 , 0.31391393, 0.02109952, 0.47347561, 0.59457581, 0.12774281, 0.00529474, 0.88511425, 0.69942065, 0.36264427, 0.45152127, 0.98514586, 0.27916585, 0.99460932, 0.33777428, 0.1689406 , 0.23037044, 0.15354323, 0.32998027, 0.50440555, 0.92929222, 0.16231566, 0.64766406, 0.16579278, 0.56959548, 0.14349143, 0.86018319, 0.04530406, 0.65965885, 0.77977551, 0.85743102, 0.24824908, 0.60538211, 0.97659987, 0.9110473 , 0.00986307, 0.57332198, 0.23209991, 0.23378491, 0.51242767, 0.58719223, 0.62114799, 0.73755961, 0.79761692, 0.23432189, 0.83323214, 0.7538573 , 0.02484017, 0.34475466, 0.59337596, 0.27435848, 0.43294181, 0.56195209, 0.88111845, 0.97367703, 0.99698606, 0.33727333, 0.28663905, 0.80595923, 0.00327039, 0.39247296, 0.11238134, 0.42764292, 0.4858757 , 0.83166349, 0.18154363, 0.81453093, 0.37521487, 0.31617496])
    • (position)
      float64
      counts
      0.09, 7.19, ..., 5.13, 1.87
      σ = 0.31, 2.77, ..., 2.32, 1.44
      Values:
      array([0.08836067, 7.18675746, 1.86654102, 3.7113999 , 4.75883015, 3.14876902, 0.90331982, 4.39071099, 4.0916631 , 3.41383337, 6.15521545, 4.12980758, 3.32237008, 0.53402331, 4.5761727 , 1.2030216 , 7.62444884, 6.57707116, 3.76301474, 0.5945608 , 8.52018797, 5.40677814, 8.92972013, 0.70475784, 6.92549565, 2.1171987 , 3.94156161, 1.64943466, 1.69343908, 7.646043 , 3.17103801, 2.7127022 , 9.24013112, 6.80776161, 8.59905754, 2.24689308, 1.88508176, 3.20495858, 1.13274464, 2.77224711, 7.99664108, 7.28735403, 0.10755925, 0.36081709, 3.8694014 , 7.70409879, 7.61087198, 4.46263019, 4.80825113, 8.68248252, 1.10590475, 1.91088751, 6.20751992, 3.71317785, 5.5183293 , 2.70915905, 3.22632851, 4.33225232, 5.13452709, 3.64924069, 5.20351161, 5.12281737, 1.04939507, 8.67367412, 3.238053 , 6.74126616, 8.74383188, 3.95463759, 5.26610138, 5.07568866, 6.43635763, 4.46543761, 2.88479375, 5.88413246, 2.42994901, 8.13115845, 4.94992551, 7.45696558, 1.70126634, 2.73501719, 3.89765303, 5.13582962, 0.83910354, 8.01276175, 6.76938528, 3.60055567, 3.54617327, 1.24072095, 7.26347109, 7.94612352, 0.23328752, 0.5844533 , 4.57174261, 6.33529111, 0.85278436, 4.79200674, 6.14315713, 0.73485457, 5.0493401 , 1.90297362, 5.07171098, 5.56590609, 0.22781 , 9.77316076, 3.34692817, 1.21827599, 1.29610149, 3.71312652, 0.74855646, 1.21707437, 8.49314674, 1.47105782, 3.33000979, 5.02386663, 6.28608502, 6.14074057, 0.2954764 , 5.99022249, 6.96116254, 3.24363135, 6.76832839, 9.05515083, 3.86810855, 5.41858949, 5.41849494, 2.14010425, 5.93580126, 3.003748 , 2.74491372, 6.19694069, 5.13406847, 1.86619369])

      Variances (σ²):
      array([0.09852815, 7.66107476, 1.94932161, 4.02589416, 4.90126532, 3.56967749, 1.01072269, 4.4698 , 4.22940998, 3.60104843, 6.50932886, 4.65366146, 3.60765293, 0.59911146, 4.9817255 , 1.26861711, 7.89200474, 7.12225515, 4.24896853, 0.64340426, 8.896247 , 5.87676966, 9.63656199, 0.7310562 , 7.77439928, 2.15450583, 4.31358002, 1.65210725, 1.73333793, 7.6782829 , 3.5008049 , 2.92933013, 9.41647175, 7.70153414, 8.84319214, 2.37538458, 2.01824825, 3.62287301, 1.24207222, 2.79357159, 8.13878242, 7.63278001, 0.12138603, 0.37862082, 4.05855998, 8.15243505, 8.28146887, 4.61303612, 5.07147188, 9.78905508, 1.18553783, 1.94126575, 6.62549712, 3.88995027, 5.91096438, 3.07051485, 3.53102439, 4.49422937, 5.81209123, 3.65495072, 5.35405814, 5.5105777 , 1.13289901, 9.71748015, 3.52957797, 6.95470595, 9.57907095, 4.23212419, 5.53607961, 5.27015714, 6.81239745, 4.98731806, 2.9746978 , 6.28070301, 2.54569646, 9.12145946, 5.00674848, 8.3971048 , 1.93108215, 2.77564153, 4.2766672 , 5.17741145, 0.92939829, 8.57275773, 7.51193713, 3.93385976, 3.70857852, 1.40249981, 8.10635745, 8.69128871, 0.24439681, 0.61365129, 4.59457792, 6.76885802, 0.96335775, 5.19463479, 6.56338945, 0.7561693 , 5.56805763, 2.15774924, 5.16709364, 6.31422323, 0.23395742, 9.88214241, 3.50275555, 1.29837537, 1.40559862, 4.16929557, 0.79006366, 1.30752816, 8.55220613, 1.60742421, 3.54940827, 5.42858334, 6.86710999, 6.41878632, 0.31392202, 6.60281349, 7.29144545, 3.34910886, 7.12921722, 9.68606407, 4.12032005, 6.1259188 , 5.50431564, 2.27785794, 6.08928654, 3.18159313, 2.88281207, 6.98955034, 5.40491116, 2.08034019])

If we omit the call to bins.sum in the original example, we can subsequently apply another histogramming or binning operation to the data:

[9]:
binned = sc.bin(binned, edges=[ybins])
binned
[9]:
Show/Hide data repr Show/Hide attributes
scipp.DataArray (174.47 KB)
    • x: 39
    • y: 29
    • x
      (x [bin-edge])
      float64
      m
      0.0, 0.03, ..., 0.97, 1.0
      Values:
      array([0. , 0.02564103, 0.05128205, 0.07692308, 0.1025641 , 0.12820513, 0.15384615, 0.17948718, 0.20512821, 0.23076923, 0.25641026, 0.28205128, 0.30769231, 0.33333333, 0.35897436, 0.38461538, 0.41025641, 0.43589744, 0.46153846, 0.48717949, 0.51282051, 0.53846154, 0.56410256, 0.58974359, 0.61538462, 0.64102564, 0.66666667, 0.69230769, 0.71794872, 0.74358974, 0.76923077, 0.79487179, 0.82051282, 0.84615385, 0.87179487, 0.8974359 , 0.92307692, 0.94871795, 0.97435897, 1. ])
    • y
      (y [bin-edge])
      float64
      m
      0.0, 0.03, ..., 0.97, 1.0
      Values:
      array([0. , 0.03448276, 0.06896552, 0.10344828, 0.13793103, 0.17241379, 0.20689655, 0.24137931, 0.27586207, 0.31034483, 0.34482759, 0.37931034, 0.4137931 , 0.44827586, 0.48275862, 0.51724138, 0.55172414, 0.5862069 , 0.62068966, 0.65517241, 0.68965517, 0.72413793, 0.75862069, 0.79310345, 0.82758621, 0.86206897, 0.89655172, 0.93103448, 0.96551724, 1. ])
    • (x, y)
      DataArrayView
      binned data [len=8, len=6, ..., len=4, len=7]
      Values:
      [<scipp.DataArray> Dimensions: Sizes[position:8, ] Coordinates: x float64 [m] (position) [0.007327, 0.013907, 0.013747, 0.006234, 0.007520, 0.019558, 0.001386, 0.012633] y float64 [m] (position) [0.004196, 0.008522, 0.008360, 0.021100, 0.005295, 0.009863, 0.024840, 0.003270] Data: float64 [counts] (position) [0.704758, 1.105905, 5.518329, 6.741266, 5.075689, 5.049340, 8.493147, 3.868109] [0.731056, 1.185538, 5.910964, 6.954706, 5.270157, 5.568058, 8.552206, 4.120320] , <scipp.DataArray> Dimensions: Sizes[position:6, ] Coordinates: x float64 [m] (position) [0.003570, 0.005599, 0.013652, 0.018049, 0.024791, 0.009304] y float64 [m] (position) [0.054965, 0.035007, 0.053418, 0.039324, 0.048451, 0.045304] Data: float64 [counts] (position) [4.390711, 8.599058, 1.885082, 3.226329, 5.134527, 0.233288] [4.469800, 8.843192, 2.018248, 3.531024, 5.812091, 0.244397] , <scipp.DataArray> Dimensions: Sizes[position:0, ] Coordinates: x float64 [m] (position) [] y float64 [m] (position) [] Data: float64 [counts] (position) [] [] , <scipp.DataArray> Dimensions: Sizes[position:3, ] Coordinates: x float64 [m] (position) [0.018038, 0.009999, 0.003143] y float64 [m] (position) [0.131633, 0.127743, 0.112381] Data: float64 [counts] (position) [3.941562, 5.266101, 5.418495] [4.313580, 5.536080, 5.504316] , ..., <scipp.DataArray> Dimensions: Sizes[position:6, ] Coordinates: x float64 [m] (position) [0.986000, 0.992186, 0.981166, 0.976357, 0.988035, 0.987262] y float64 [m] (position) [0.871655, 0.874669, 0.886983, 0.880220, 0.862629, 0.878080] Data: float64 [counts] (position) [0.037363, 0.005678, 0.008410, 0.030865, 0.019387, 0.001868] [5.170250, 0.810371, 1.136019, 4.070081, 2.710173, 0.260081] , <scipp.DataArray> Dimensions: Sizes[position:6, ] Coordinates: x float64 [m] (position) [0.982854, 0.996907, 0.986477, 0.979046, 0.987911, 0.985939] y float64 [m] (position) [0.922541, 0.901534, 0.906159, 0.926246, 0.906425, 0.930408] Data: float64 [counts] (position) [0.029950, 0.041615, 0.066593, 0.010042, 0.017554, 0.039182] [4.079800, 6.081491, 9.237124, 1.342073, 2.452364, 5.420403] , <scipp.DataArray> Dimensions: Sizes[position:4, ] Coordinates: x float64 [m] (position) [0.991498, 0.996546, 0.992624, 0.994599] y float64 [m] (position) [0.935221, 0.963116, 0.964417, 0.945410] Data: float64 [counts] (position) [0.042415, 0.050269, 0.067304, 0.047795] [6.032968, 7.332903, 9.627071, 6.904386] , <scipp.DataArray> Dimensions: Sizes[position:7, ] Coordinates: x float64 [m] (position) [0.978857, 0.974890, 0.981578, 0.998043, 0.988448, 0.993803, 0.996973] y float64 [m] (position) [0.968493, 0.977071, 0.995732, 0.994631, 0.987703, 0.968193, 0.973333] Data: float64 [counts] (position) [0.034089, 0.068578, 0.027754, 0.032204, 0.031830, 0.015189, 0.016652] [4.551734, 8.977045, 3.756572, 4.732933, 4.458792, 2.185474, 2.434206] ]

As in the 1-D example above, summing the bins is equivalent to histogramming binned data:

[10]:
binned.bins.sum().plot()