docs: def build_hazard_stats(pgetter, N, hstats, individual_curves, monitor):
      """
      :param pgetter: an :class:`openquake.commonlib.getters.PmapGetter`
      :param N: the total number of sites
      :param hstats: a list of pairs (statname, statfunc)
      :param individual_curves: if True, also build the individual curves
      :param monitor: instance of Monitor
      :returns: a dictionary kind -> ProbabilityMap
  
      The "kind" is a string of the form 'rlz-XXX' or 'mean' of 'quantile-XXX'
      used to specify the kind of output.
      """
      with monitor('combine pmaps'):
          pgetter.init()  # if not already initialized
          try:
              pmaps = pgetter.get_pmaps()
          except IndexError:  # no data
              return {}
          if sum(len(pmap) for pmap in pmaps) == 0:  # no data
              return {}
      R = len(pmaps)
      imtls, poes, weights = pgetter.imtls, pgetter.poes, pgetter.weights
      pmap_by_kind = {}
      hmaps_stats = []
      hcurves_stats = []
      with monitor('compute stats'):
          for statname, stat in hstats.items():
              pmap = compute_pmap_stats(pmaps, [stat], weights, imtls)
              hcurves_stats.append(pmap)
              if pgetter.poes:
                  hmaps_stats.append(
                      calc.make_hmap(pmap, pgetter.imtls, pgetter.poes))
              if statname == 'mean' and R > 1 and N <= FEWSITES:
                  pmap_by_kind['rlz_by_sid'] = rlz = {}
                  for sid, pcurve in pmap.items():
                      rlz[sid] = util.closest_to_ref(
                          [pm.setdefault(sid, 0).array for pm in pmaps],
                          pcurve.array)['rlz']
      if hcurves_stats:
          pmap_by_kind['hcurves-stats'] = hcurves_stats
      if hmaps_stats:
          pmap_by_kind['hmaps-stats'] = hmaps_stats
      if R > 1 and individual_curves or not hstats:
          pmap_by_kind['hcurves-rlzs'] = pmaps
          if pgetter.poes:
              with monitor('build individual hmaps'):
                  pmap_by_kind['hmaps-rlzs'] = [
                      calc.make_hmap(pmap, imtls, poes) for pmap in pmaps]
      return pmap_by_kind