예제 #1
0
def ConvertToCbsdGrantInfo(cbsds, min_freq_mhz, max_freq_mhz, chunks_mhz=-1):
  """Converts |Cbsd| into |data.CbsdGrantInfo| lists.

  Args:
    cbsds: an iterable of |Cbsd|.
    min_freq_mhz: The minimum grant frequency (MHz).
    max_freq_mhz: The maximum grant frequency (MHz).
    chunks_mhz: The chunking size of the grants (MHz). If -1, no chunking done.
  Returns:
    A list of |data.CbsdGrantInfo| namedtuple.
  """
  reg_requests = []
  grant_requests = []
  for cbsd in cbsds:
    req_request = GetCbsdRegistrationRequest(cbsd)
    if chunks_mhz < 0:
      grant_request = GetCbsdGrantRequest(cbsd, min_freq_mhz, max_freq_mhz)
      reg_requests.append(req_request)
      grant_requests.append(grant_request)
    else:
      for min_freq in np.arange(min_freq_mhz, max_freq_mhz, chunks_mhz):
        max_freq = min(max_freq_mhz, min_freq + chunks_mhz)
        grant_request = GetCbsdGrantRequest(cbsd, min_freq, max_freq)
        reg_requests.append(req_request)
        grant_requests.append(grant_request)

  return data.getGrantsFromRequests(reg_requests, grant_requests)
 def test_computeMoveListAndCheckInterf(self):
   protection_points = [ProtectionPoint(latitude=36.9400, longitude=-75.9989),
                        ProtectionPoint(latitude=37.7579, longitude=-75.4105),
                        ProtectionPoint(latitude=36.1044, longitude=-73.3147),
                        ProtectionPoint(latitude=36.1211, longitude=-75.5939)]
   regs = [json.load(open(os.path.join(TEST_DIR, 'RegistrationRequest_%d.json' % k)))
           for k in range(1, 7)]
   grants = [json.load(open(os.path.join(TEST_DIR, 'GrantRequest_%d.json' % k)))
             for k in range(1, 7)]
   grants_uut = data.getGrantsFromRequests(regs[:4], grants[:4])
   grants_th = data.getGrantsFromRequests(regs[4:], grants[4:])
   channel = (3600, 3610)
   dpa = dpa_mgr.Dpa(protection_points,
                     geometry=sgeo.Polygon([(pt.longitude, pt.latitude)
                                            for pt in protection_points]),
                     name='test(East1)',
                     threshold=-144,
                     beamwidth=3,
                     radar_height=50,
                     neighbor_distances=(150, 190, 0, 25),
                     freq_ranges_mhz=[channel])
   dpa.SetGrantsFromList(grants_uut + grants_th)
   expected_grants = set(grants_uut[0:3] + grants_th[0:1])
   # Testing move list
   dpa.ComputeMoveLists()
   self.assertSetEqual(dpa.GetMoveList(channel),
                       expected_grants)
   # Testing interference calculation
   interf = dpa.CalcKeepListInterference(channel)
   self.assertLess(max(interf), -144)
   # Testing check
   result = dpa.CheckInterference([grants_uut[3], grants_th[1]],
                                   margin_db=0.01,
                                   do_abs_check_single_uut=True,
                                   extensive_print=False)
   self.assertEqual(result, True)
   result = dpa.CheckInterference([grants_uut[2], grants_th[1]],
                                   margin_db=0.01,
                                   do_abs_check_single_uut=True,
                                   extensive_print=True)
   self.assertEqual(result, False)
    reg_request = json.load(open(os.path.join(_BASE_DATA_DIR, reg_file)))
    reg_request_list.append(reg_request)

  # Populate a list of grant requests
  grant_request_filename = ['GrantRequest_1.json',
                            'GrantRequest_2.json',
                            'GrantRequest_3.json',
                            'GrantRequest_4.json',
                            'GrantRequest_5.json',
                            'GrantRequest_6.json']
  grant_request_list = []
  for grant_file in grant_request_filename:
    grant_request = json.load(open(os.path.join(_BASE_DATA_DIR, grant_file)))
    grant_request_list.append(grant_request)

  grants_uut = data.getGrantsFromRequests(reg_request_list[:4], grant_request_list[:4])
  grants_th = data.getGrantsFromRequests(reg_request_list[4:], grant_request_list[4:],
                                         is_managing_sas=False)
  # Set the grants
  dpa_ref.SetGrantsFromList(grants_uut + grants_th)

  # Determine which CBSD grants are on the move list
  start_time = time.time()
  dpa_ref.ComputeMoveLists()
  end_time = time.time()
  print '-- Reference model --'
  print 'Move list output: ' + str(dpa_ref.GetMoveListMask(channel))
  print 'Computation time: ' + str(end_time - start_time)

  # Compute the resulting interference
  interf = dpa_ref.CalcKeepListInterference(channel)
예제 #4
0
def findMoveList(protection_specs,
                 protection_points,
                 registration_requests,
                 grant_requests,
                 num_iter,
                 num_processes,
                 pool=None):
    """Main routine to find CBSD indices on the move list.

  Inputs:
    protection_specs:   protection specifications, an object with attributes
                        'lowFreq' (in Hz), 'highFreq' (in Hz),
                        'antHeight' (in meters), 'beamwidth' (in degrees),
                        'threshold' (in dBm/10MHz), 'neighbor_distances' (km),
                        'min_azimuth', 'max_azimuth' (degrees)
                        where `neighbor_distances` are the neighborhood
                        distances (km) as a sequence:
                          [cata_dist, catb_dist, cata_oob_dist, catb_oob_dist]
    protection_points:  a list of protection points, each one being an object
                        providing attributes 'latitude' and 'longitude'
    registration_requests: a list of CBSD registration requests, each one being
                           a dictionary containing CBSD registration information
    grant_requests:     a list of grant requests, each one being a dictionary
                        containing grant information; there is a one-to-one
                        mapping between items in registration_requests and
                        grant_requests; a CBSD with more than one grant will
                        have corresponding duplicate items in registration_requests
    num_iter:           number of Monte Carlo iterations
    num_processes:      number of parallel processes to use
    pool:               optional |multiprocessing.Pool| to use

  Returns:
    result:             a Boolean list (same size as registration_requests/
                        grant_requests) with TRUE elements at indices having
                        grants on the move list
  """
    grants = data.getGrantsFromRequests(registration_requests, grant_requests)
    # Find the move list of each protection constraint with a pool of parallel processes.
    if pool is None:
        mpool.Configure(num_processes)
        pool = mpool.Pool()

    neighbor_distances = protection_specs.neighbor_distances
    try:
        min_azimuth = protection_specs.min_azimuth
        max_azimuth = protection_specs.max_azimuth
    except AttributeError:
        min_azimuth, max_azimuth = 0, 360

    moveListC = partial(moveListConstraint,
                        low_freq=protection_specs.lowFreq,
                        high_freq=protection_specs.highFreq,
                        grants=grants,
                        inc_ant_height=protection_specs.antHeight,
                        num_iter=num_iter,
                        threshold=protection_specs.threshold,
                        beamwidth=protection_specs.beamwidth,
                        min_azimuth=min_azimuth,
                        max_azimuth=max_azimuth,
                        neighbor_distances=neighbor_distances)
    M_c, _ = zip(*pool.map(moveListC, protection_points))

    # Find the unique CBSD indices in the M_c list of lists.
    M = set().union(*M_c)

    # Set to TRUE the elements of the output Boolean array that have grant_index in
    # the move list.
    result = np.zeros(len(grants), bool)
    for k, grant in enumerate(grants):
        if grant in M:
            result[k] = True
    output = result.tolist()
    return output
예제 #5
0
def _McpConfigRead(config):
    """Extracts DPA and grants from MCP config JSON.

  Note: returns all grants involved in the test irrespective of iteration
  process.

  Args:
    config: A JSON dictionary.

  Returns:
    A tuple (dpas, grants) where:
      dpas:  a list of objects of type |dpa_mgr.Dpa|.
      grants: a list of |data.CbsdGrantInfo|.
  """
    if ('iterationData' not in config or 'dpas' not in config
            or 'initialCbsdRequestsWithDomainProxies' not in config):
        raise ValueError(
            'Unsupported config file. Please use a MCP1 config file')

    # Build the DPAs.
    dpas = []
    for dpa_id, dpa_data in config['dpas'].items():
        dpa = dpa_mgr.BuildDpa(
            dpa_id, protection_points_method=dpa_data['points_builder'])
        # - add extra properties for the geometry and margin.
        dpa.margin_db = dpa_data['movelistMargin']
        try:
            dpa_zone = zones.GetCoastalDpaZones()[dpa_id]
        except KeyError:
            dpa_zone = zones.GetPortalDpaZones(kml_path=dpa_kml_file)[dpa_id]
        dpa.geometry = dpa_zone.geometry

        # - read also the activation list and freq range.
        dpa.activation = None
        for iter_data in config['iterationData']:
            for activation in iter_data['dpaActivationList']:
                if activation['dpaId'] == dpa_id:
                    dpa.activation = activation['frequencyRange']
                    break

        dpas.append(dpa)

    # Read the CBSDs, assuming all granted, into list of |CbsdGrantInfo|.
    # - initial stuff into SAS UUT
    grants = []
    for records in config['initialCbsdRequestsWithDomainProxies']:
        grant_requests = records['grantRequests']
        reg_requests = MergeConditionalData(
            records['registrationRequests'],
            records['conditionalRegistrationData'])
        grants.extend(
            data.getGrantsFromRequests(reg_requests,
                                       grant_requests,
                                       is_managing_sas=True))
    for record in config['initialCbsdRecords']:
        grant_request = [record['grantRequest']]
        reg_request = MergeConditionalData(
            [record['registrationRequest']],
            [record['conditionalRegistrationData']])
        grants.append(
            data.getGrantsFromRequests(reg_requests,
                                       grant_requests,
                                       is_managing_sas=True))

    # - then iterations for TH and UUT
    for iter_data in config['iterationData']:
        for th_data in iter_data['sasTestHarnessData']:
            th_grants = data.getAllGrantInfoFromCbsdDataDump(
                th_data['cbsdRecords'], is_managing_sas=False)
            grants.extend([g for g in th_grants])

        for records in iter_data['cbsdRequestsWithDomainProxies']:
            grant_requests = records['grantRequests']
            reg_requests = MergeConditionalData(
                records['registrationRequests'],
                records['conditionalRegistrationData'])
            uut_grants = data.getGrantsFromRequests(reg_requests,
                                                    grant_requests,
                                                    is_managing_sas=True)
            grants.extend([g for g in uut_grants])

        for record in iter_data['cbsdRecords']:
            grant_request = [record['grantRequest']]
            reg_request = MergeConditionalData(
                [record['registrationRequest']],
                [record['conditionalRegistrationData']])
            uut_grant = data.getGrantsFromRequests(reg_requests,
                                                   grant_requests,
                                                   is_managing_sas=True)
            grants.append(uut_grant)

    return grants, dpas
예제 #6
0
def _IprConfigRead(config):
    """Extracts DPA and grants from IPR config JSON.

  Note: All IPT suppprted except IPR1.

  Args:
    config: A JSON dictionary.

  Returns:
    A tuple (dpas, grants) where:
      dpas:  a list of objects of type |dpa_mgr.Dpa|.
      grants: a list of |data.CbsdGrantInfo|.
  """
    dpa_cfgs = None
    if 'portalDpa' in config:
        dpa_cfgs = [config['portalDpa']]
    elif 'escDpa' in config:
        dpa_cfgs = [config['escDpa']]
    if dpa_cfgs is None:
        if 'dpas' in config:
            dpa_cfgs = config['dpas']
        elif 'dpa' in config:
            dpa_cfgs = [config['dpa']]
    if dpa_cfgs is None or ('domainProxies' not in config
                            and 'registrationRequest' not in config):
        raise ValueError(
            'Unsupported config file. Please use a IPR config file')

    # Build the DPAs
    dpas = []
    for dpa_cfg in dpa_cfgs:
        dpa_id = dpa_cfg['dpaId']
        try:
            dpa_kml_file = config['dpaDatabaseConfig']['filePath']
        except KeyError:
            dpa_kml_file = None
        try:
            points_builder = dpa_cfg['points_builder']
        except KeyError:
            points_builder = None
        try:
            dpa = dpa_mgr.BuildDpa(dpa_id,
                                   protection_points_method=points_builder,
                                   portal_dpa_filename=dpa_kml_file)
        except IOError:
            print('Portal KML File not found: %s ' % dpa_kml_file)
            raise
        try:
            freq_range_mhz = (dpa_cfg['frequencyRange']['lowFrequency'] / 1.e6,
                              dpa_cfg['frequencyRange']['highFrequency'] /
                              1.e6)
            dpa.ResetFreqRange([freq_range_mhz])
        except KeyError:
            pass
        # - add extra properties for the geometry and margin
        try:
            dpa.margin_db = dpa_cfg['movelistMargin']
        except KeyError:
            dpa_margin_db = 'linear(1.5)'
        try:
            dpa_zone = zones.GetCoastalDpaZones()[dpa_id]
        except KeyError:
            dpa_zone = zones.GetPortalDpaZones(kml_path=dpa_kml_file)[dpa_id]
        dpa.geometry = dpa_zone.geometry
        dpas.append(dpa)

    # Read the CBSDs, assuming all granted, into list of |CbsdGrantInfo|.
    grants = []
    if 'domainProxies' in config:
        #  - first the SAS UUT
        for domain_proxy_config in config['domainProxies']:
            grant_requests = domain_proxy_config['grantRequests']
            reg_requests = MergeConditionalData(
                domain_proxy_config['registrationRequests'],
                domain_proxy_config['conditionalRegistrationData'])
            grants.extend(
                data.getGrantsFromRequests(reg_requests,
                                           grant_requests,
                                           is_managing_sas=True))

        #  - now the peer SASes.
        if 'sasTestHarnessConfigs' in config:
            for th_config in config['sasTestHarnessConfigs']:
                dump_records = th_config['fullActivityDumpRecords'][0]
                grants.extend(
                    data.getAllGrantInfoFromCbsdDataDump(
                        dump_records, is_managing_sas=False))

    elif 'registrationRequest' in config:
        grants.extend(
            data.getGrantsFromRequests(
                MergeConditionalData([config['registrationRequest']],
                                     [config['conditionalRegistrationData']]),
                [config['grantRequest']],
                is_managing_sas=True))

    return grants, dpas
예제 #7
0
#--------------------------------------------------
# The simulation
if __name__ == '__main__':
    # reset the random seed
    np.random.seed(12345)

    # Configure the global pool of processes
    mpool.Configure(num_processes)
    num_workers = mpool.GetNumWorkerProcesses()

    (all_cbsds, reg_requests, grant_requests, protection_zone,
     (n_a_indoor, n_a_outdoor, n_b), ax) = PrepareSimulation()

    # Build the grants
    grants = data.getGrantsFromRequests(reg_requests, grant_requests)

    # Build the DPA manager
    dpa = dpa_mgr.BuildDpa(
        dpa_name, 'default (%d,%d,%d,%d,%d)' %
        (npts_front_dpa_contour, npts_back_dpa_contour, npts_within_dpa_front,
         npts_within_dpa_back, front_usborder_buffer_km))
    dpa.ResetFreqRange([(fmin, fmax)])

    # Plot the protection points
    ax.scatter([pt.longitude for pt in dpa.protected_points],
               [pt.latitude for pt in dpa.protected_points],
               color='k',
               marker='*')
    plt.show(block=False)