def digitize(self, quantity: Quantity) -> int: """ Does the same as numpy.digitize, which is not compatible with pint.Quantity """ if quantity.dimensionality != self.dimensionality: raise BinningError('Incompatible dimensionality') value = quantity.to_base_units().magnitude return int(np.digitize(value, self.unitless_bin_boundaries))
def exposure( start: int, end: int, exposure_time: pint.Quantity = None, num_images: int = None ) -> (pint.Quantity, int, int): if exposure_time: exposure_time = exposure_time.to_base_units().to_compact() exposure_cycles = (exposure_time * clock_frequency).to_base_units().magnitude num_images = int((end - start) // exposure_cycles) else: # Because they are expected to be mutually exclusive, if there is no # exposure_time, there must be a num_images. exposure_cycles = int((end - start) / num_images) exposure_time = seconds(exposure_cycles) return exposure_time, exposure_cycles, num_images