def calculatePostIapAggregateInterference(q_p, num_sas, iap_interfs):
  """Computes post IAP allowed aggregate interference.

  Routine to calculate aggregate interference from all the CBSDs managed by the
  SAS at protected entity.

  Args:
    q_p: Pre IAP threshold value for protection type (mW)
    num_sas: Number of SASs in the peer group
    iap_interfs: A list of tuple
      (latitude, longitude, asas_interference, agg_interference) where:
        asas_interference: a list of interference (per channel) for managing SAS.
        agg_interference: a list of total interference (per channel).
      The interference is in mW/IAPBW.

  Returns:
    ap_iap_ref: The post-IAP allowed interference, as a dict formatted as:
        {latitude : {longitude : [interference(mW/IAPBW), .., interference(mW/IAPBW)]}}
      where the list holds all values per channel of that protection point.
  """
  if not isinstance(iap_interfs, list):
    iap_interfs = [iap_interfs]

  ap_iap_ref = {}
  for lat, lon, asas_interfs, agg_interfs in iap_interfs:
    if lat not in ap_iap_ref: ap_iap_ref[lat] = {}
    ap_iap_ref[lat][lon] = [
        (float(q_p - aggr_interf) / num_sas + asas_interf)
        for asas_interf, aggr_interf in zip(asas_interfs, agg_interfs)]

  return ap_iap_ref