@@ -45,19 +45,21 @@ def to_events(
4545 edge_sizes = {dim : da .sizes [dim ] for dim in edge_dims }
4646 for dim in edge_dims :
4747 coord = da .coords [dim ]
48- low = sc .broadcast (coord [dim , :- 1 ], sizes = edge_sizes ).values
49- high = sc .broadcast (coord [dim , 1 :], sizes = edge_sizes ).values
48+ left = sc .broadcast (coord [dim , :- 1 ], sizes = edge_sizes ).values
49+ right = sc .broadcast (coord [dim , 1 :], sizes = edge_sizes ).values
5050
5151 # The numpy.random.uniform function below does not support NaNs, so we need to
5252 # replace them with zeros, and then replace them back after the random numbers
5353 # have been generated.
54- nans = np .isnan (low ) | np .isnan (high )
55- low = np .where (nans , 0.0 , low )
56- high = np .where (nans , 0.0 , high )
54+ nans = np .isnan (left ) | np .isnan (right )
55+ left = np .where (nans , 0.0 , left )
56+ right = np .where (nans , 0.0 , right )
57+ # Ensure left <= right
58+ left , right = np .minimum (left , right ), np .maximum (left , right )
5759
5860 # In each bin, we generate a number of events with a uniform distribution.
5961 events = rng .uniform (
60- low , high , size = (events_per_bin , * list (edge_sizes .values ()))
62+ left , right , size = (events_per_bin , * list (edge_sizes .values ()))
6163 )
6264 events [..., nans ] = np .nan
6365 event_coords [dim ] = sc .array (
@@ -77,20 +79,20 @@ def to_events(
7779 data = da .data
7880 if event_masks :
7981 inv_mask = (~ reduce (lambda a , b : a | b , event_masks .values ())).to (dtype = int )
80- inv_mask .unit = ''
82+ inv_mask .unit = ""
8183 data = data * inv_mask
8284
8385 # Create the data counts, which are the original counts divided by the number of
8486 # events per bin
8587 sizes = {event_dim : events_per_bin } | da .sizes
8688 val = sc .broadcast (sc .values (data ) / float (events_per_bin ), sizes = sizes )
87- kwargs = {' dims' : sizes .keys (), ' values' : val .values , ' unit' : data .unit }
89+ kwargs = {" dims" : sizes .keys (), " values" : val .values , " unit" : data .unit }
8890 if data .variances is not None :
8991 # Note here that all the events are correlated.
9092 # If we later histogram the events with different edges than the original
9193 # histogram, then neighboring bins will be correlated, and the error obtained
9294 # will be too small. It is however not clear what can be done to improve this.
93- kwargs [' variances' ] = sc .broadcast (
95+ kwargs [" variances" ] = sc .broadcast (
9496 sc .variances (data ) / float (events_per_bin ), sizes = sizes
9597 ).values
9698 new_data = sc .array (** kwargs )
0 commit comments