code: def _histogram_equalization_helper(
      valid_data, number_of_bins, clip_limit=None, slope_limit=None
  ):
      """Calculate the simplest possible histogram equalization, using only valid data.
  
      Returns:
          cumulative distribution function and bin information
  
      """
      # bucket all the selected data using np's histogram function
      temp_histogram, temp_bins = np.histogram(
          valid_data, number_of_bins
      )
  
      # if we have a clip limit and we should do our clipping before building
      # the cumulative distribution function, clip off our histogram
      if clip_limit is not None:
          # clip our histogram and remember how much we removed
          pixels_to_clip_at = int(
              clip_limit * (valid_data.size / float(number_of_bins))
          )
          mask_to_clip = temp_histogram > clip_limit
          # num_bins_clipped = sum(mask_to_clip)
          # num_pixels_clipped = sum(temp_histogram[mask_to_clip]) - (num_bins_clipped * pixels_to_clip_at)
          temp_histogram[mask_to_clip] = pixels_to_clip_at
  
      # calculate the cumulative distribution function
      cumulative_dist_function = temp_histogram.cumsum()
  
      # if we have a clip limit and we should do our clipping after building the
      # cumulative distribution function, clip off our cdf
      if slope_limit is not None:
          # clip our cdf and remember how much we removed
          pixel_height_limit = int(
              slope_limit * (valid_data.size / float(number_of_bins))
          )
          cumulative_excess_height = 0
          num_clipped_pixels = 0
          weight_metric = np.zeros(
              cumulative_dist_function.shape, dtype=float
          )
  
          for pixel_index in range(1, cumulative_dist_function.size):
              current_pixel_count = cumulative_dist_function[
                  pixel_index
              ]
  
              diff_from_acceptable = (
                  current_pixel_count
                  - cumulative_dist_function[pixel_index - 1]
                  - pixel_height_limit
                  - cumulative_excess_height
              )
              if diff_from_acceptable < 0:
                  weight_metric[pixel_index] = abs(diff_from_acceptable)
              cumulative_excess_height += max(diff_from_acceptable, 0)
              cumulative_dist_function[pixel_index] = (
                  current_pixel_count - cumulative_excess_height
              )
              num_clipped_pixels = (
                  num_clipped_pixels + cumulative_excess_height
              )
  
      # now normalize the overall distribution function
      cumulative_dist_function = (
          (number_of_bins - 1)
          * cumulative_dist_function
          / cumulative_dist_function[-1]
      )
  
      # return what someone else will need in order to apply the equalization later
      return cumulative_dist_function, temp_bins
  
imports: from __future__ import annotations
  import logging
  import math
  from datetime import datetime
  import dask
  import dask.array
  import numpy
  import xarray
  from satpy.composites import CompositeBase, GenericCompositor
  from satpy.dataset import combine_metadata
label_desc: Use image node_id 8 for calling a global function with example usage: _histogram_equalization_helper(valid_data, number_of_bins, clip_limit, slope_limit) and returns: cumulative_dist_function,  temp_bins