docs: def get_completeness_adjusted_table(catalogue, completeness, dmag,
                                      offset=1.0E-5, end_year=None, plot=False,
                                      figure_size=(8, 6), filename=None,
                                      filetype='png', dpi=300, ax=None):
      """
      Counts the number of earthquakes in each magnitude bin and normalises
      the rate to annual rates, taking into account the completeness
      """
      if not end_year:
          end_year = catalogue.end_year
      # Find the natural bin limits
      mag_bins = _get_catalogue_bin_limits(catalogue, dmag)
      obs_time = end_year - completeness[:, 0] + 1.
      obs_rates = np.zeros_like(mag_bins)
      durations = np.zeros_like(mag_bins)
      n_comp = np.shape(completeness)[0]
      for iloc in range(n_comp):
          low_mag = completeness[iloc, 1]
          comp_year = completeness[iloc, 0]
          if iloc == (n_comp - 1):
              idx = np.logical_and(
                  catalogue.data['magnitude'] >= low_mag - offset,
                  catalogue.data['year'] >= comp_year)
              high_mag = mag_bins[-1]
              obs_idx = mag_bins >= (low_mag - offset)
          else:
              high_mag = completeness[iloc + 1, 1]
              mag_idx = np.logical_and(
                  catalogue.data['magnitude'] >= low_mag - offset,
                  catalogue.data['magnitude'] < (high_mag - offset))
  
              idx = np.logical_and(mag_idx,
                                   catalogue.data['year'] >= (comp_year - offset))
              obs_idx = np.logical_and(mag_bins >= (low_mag - offset),
                                       mag_bins < (high_mag + offset))
          temp_rates = np.histogram(catalogue.data['magnitude'][idx],
                                    mag_bins[obs_idx])[0]
          temp_rates = temp_rates.astype(float) / obs_time[iloc]
          obs_rates[obs_idx[:-1]] = temp_rates
          durations[obs_idx[:-1]] = obs_time[iloc]
      selector = np.where(obs_rates > 0.)[0]
      mag_bins = mag_bins[selector]
      obs_rates = obs_rates[selector]
      durations = durations[selector]
      # Get cumulative rates
      cum_rates = np.array([sum(obs_rates[iloc:])
                            for iloc in range(0, len(obs_rates))])
      if plot:
          plt.figure(figsize=figure_size)
          plt.semilogy(mag_bins + dmag / 2., obs_rates, "bo",
                       label="Incremental")
          plt.semilogy(mag_bins + dmag / 2., cum_rates, "rs",
                       label="Cumulative")
          plt.xlabel("Magnitude (M)", fontsize=16)
          plt.ylabel("Annual Rate", fontsize=16)
          plt.grid(True)
          plt.legend(fontsize=16)
          if filename:
              plt.savefig(filename, format=filetype, dpi=dpi,
                          bbox_inches="tight")
      return np.column_stack([mag_bins, durations, obs_rates, cum_rates,
                              np.log10(cum_rates)])