예제 #1
0
def GetPortalDpaZones(kml_path=None):
    """Gets Portal DPA zones.

  Portal DPA zones are Dynamic Protection Area monitored through the use of
  internet portal.

  Args:
    kml_path: Optional path to the Portal DPA KML. If unspecified, use the
      default one from the `data/ntia/` folder.

  Returns:
    A dict of DPA struct keyed by their names, each one holding following
    attributes:
      geometry: A |shapely.Polygon or Point| defining the DPA.
      protectionCritDbmPer10MHz: The protection threshold (dBm/10MHz).
      refHeightMeters: The radar antenna height (meters).
      antennaBeamwidthDeg: The antenna beamwidth (degrees).
      minAzimuthDeg: The radar min azimuth (degrees).
      maxAzimuthDeg: The radar max azimuth (degrees).
      catBNeighborDist: The CatB neighboring distance (km).
  """
    global _portal_dpa_zones
    global _portal_dpa_path
    if _portal_dpa_zones is None or kml_path != _portal_dpa_path:
        _portal_dpa_path = kml_path
        if kml_path is None:
            kml_path = os.path.join(CONFIG.GetNtiaDir(), PORTAL_DPA_ZONE_FILE)
        _portal_dpa_zones = _LoadDpaZones(kml_path,
                                          PORTAL_DPA_PROPERTIES,
                                          fix_invalid=False)
        # fix_invalid to False to auto-detect issues with provided KML.

    return _portal_dpa_zones
예제 #2
0
def GetUsCanadaBorder():
    """Gets the US/Canada border as a |shapely.MultiLineString|."""
    global _uscanada_border
    if _uscanada_border is None:
        kml_file = os.path.join(CONFIG.GetFccDir(), USCANADA_BORDER_FILE)
        lines = _ReadKmlBorder(kml_file)
        _uscanada_border = ops.unary_union(lines.values())
    return _uscanada_border
예제 #3
0
def GetUsBorder():
    """Gets the US border as a |shapely.MultiPolygon|.

  This is a composite US border for simulation purposes only.
  """
    global _border_zone
    if _border_zone is None:
        kml_file = os.path.join(CONFIG.GetFccDir(), USBORDER_FILE)
        zones = _ReadKmlZones(kml_file)
        _border_zone = ops.unary_union(zones.values())
    return _border_zone
예제 #4
0
def GetCoastalProtectionZone():
    """Returns the coastal protection zone as a |shapely.MultiPolygon|.

  The coastal protection zone is optionally used for DPA CatA neighborhood.
  """
    global _coastal_protection_zone
    if _coastal_protection_zone is None:
        kml_file = os.path.join(CONFIG.GetNtiaDir(), PROTECTION_ZONE_FILE)
        zones = _ReadKmlZones(kml_file)
        _coastal_protection_zone = ops.unary_union(
            [zones[name] for name in _COASTAL_PROTECTION_ZONES])
    return _coastal_protection_zone
예제 #5
0
def GetFccOfficeLocations():
    """Gets FCC Office locations.

  14 FCC field offices that require protection are defined.

  Returns:
    A list of locations defined as dict with keys 'latitude' and 'longitude'.
  """
    fcc_file = os.path.join(CONFIG.GetFccDir(), FCC_FIELD_OFFICES_FILE)
    fcc_offices = [{
        'latitude': lat,
        'longitude': lng
    } for lat, lng in np.loadtxt(fcc_file, delimiter=',', usecols=(1, 2))]
    return fcc_offices
예제 #6
0
def GetUrbanAreas(simplify_deg=1e-3):
    """Gets the US urban area as a |shapely.GeometryCollection|.

  Note: Client code should cache it as expensive to load (and not cached here).

  Args:
    simplify_deg: if defined, simplify the zone with given tolerance (degrees).
      Default is 1e-3 which corresponds roughly to 100m in continental US.
  """
    kml_file = os.path.join(CONFIG.GetNtiaDir(), URBAN_AREAS_FILE)
    zones = _ReadKmlZones(kml_file,
                          root_id_zone='Document',
                          simplify=simplify_deg)
    urban_areas = sgeo.GeometryCollection(
        zones.values())  # ops.unary_union(zones.values())
    return urban_areas
예제 #7
0
    def ConfigureDataFile(self, datafile_or_dir, do_load=True):
        """Configure the refractivity data file.

    Inputs:
      datafile_or_dir: the data path or directory.
         If directory, then the datafile is the standard 'n050.txt'.
         If None, then use the standard database location from CONFIG.py.
      do_load: if set (default), load the data, otherwise do lazy loading.
    """
        self._datafile = datafile_or_dir
        if self._datafile is None:
            self._datafile = os.path.join(CONFIG.GetItuDir(), 'n050.txt')
        elif os.path.isdir(self._datafile):
            self._datafile = os.path.join(self._datafile, 'n050.txt')
        self._data = None
        if do_load:
            self._data = np.loadtxt(self._datafile)
예제 #8
0
def _GetAllExclusionZones():
    """Read all exclusion zones."""
    global _exclusion_zones_gbs
    global _exclusion_zones_p90
    if _exclusion_zones_gbs is None:
        kml_file = os.path.join(CONFIG.GetNtiaDir(), EXCLUSION_ZONE_FILE)
        zones = _ReadKmlZones(kml_file, data_fields=['freqRangeMhz'])
        gbs_zones = []
        p90_zones = []
        for name, zone in zones.items():
            freq_range = _SplitFreqRange(zone.freqRangeMhz)
            if (3550, 3650) in freq_range:
                gbs_zones.append(zone.geometry)
            elif (3650, 3700) in freq_range:
                p90_zones.append(zone.geometry)
            else:
                raise ValueError('Zone %s: unsupported freq range %r', name,
                                 freq_range)
        _exclusion_zones_gbs = ops.unary_union(gbs_zones)
        _exclusion_zones_p90 = ops.unary_union(p90_zones)
예제 #9
0
 def SetTerrainDirectory(self, terrain_directory):
     """Configures the terrain data directory."""
     self._terrain_dir = terrain_directory
     if self._terrain_dir is None:
         self._terrain_dir = CONFIG.GetTerrainDir()
예제 #10
0
 def SetCensusTractDirectory(self, census_tract_directory):
   """Configures the Census Tracts data directory."""
   self._census_tract_dir = census_tract_directory
   if self._census_tract_dir is None:
     self._census_tract_dir = CONFIG.GetCensusTractsDir()
예제 #11
0
 def SetNlcdDirectory(self, nlcd_directory):
     """Configures the NLCD data directory."""
     self._nlcd_dir = nlcd_directory
     if self._nlcd_dir is None:
         self._nlcd_dir = CONFIG.GetLandCoverDir()