docs: def extract_agg_losses(dstore, what):
      """
      Aggregate losses of the given loss type and tags. Use it as
      /extract/agg_losses/structural?taxonomy=RC&zipcode=20126
      /extract/agg_losses/structural?taxonomy=RC&zipcode=*
  
      :returns:
          an array of shape (T, R) if one of the tag names has a `*` value
          an array of shape (R,), being R the number of realizations
          an array of length 0 if there is no data for the given tags
      """
      loss_type, tags = get_loss_type_tags(what)
      if not loss_type:
          raise ValueError('loss_type not passed in agg_losses/<loss_type>')
      l = dstore['oqparam'].lti[loss_type]
      if 'losses_by_asset' in dstore:  # scenario_risk
          stats = None
          losses = dstore['losses_by_asset'][:, :, l]['mean']
      elif 'avg_losses-stats' in dstore:  # event_based_risk, classical_risk
          stats = dstore['avg_losses-stats'].attrs['stats']
          losses = dstore['avg_losses-stats'][:, :, l]
      elif 'avg_losses-rlzs' in dstore:  # event_based_risk, classical_risk
          stats = [b'mean']
          losses = dstore['avg_losses-rlzs'][:, :, l]
      else:
          raise KeyError('No losses found in %s' % dstore)
      return _filter_agg(dstore['assetcol'], losses, tags, stats)