Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_search_tiles_kamchatka(self):
"""
Tests the tile searching over Kamchatka in far east Sibiria;
This test is especially nice, as it contains also a tile that covers both,
the ROI and the continental zone, but the intersection of the tile and
the ROI is outside of the zone.
Furthermore, it also covers Equi7Grid subgrids that consist of a multipolygon,
as they overspan the 180deg/dateline.
"""
grid = Equi7Grid(500)
kamchatka_geom = setup_geom_kamchatka()
kamchatka_geom_tiles = sorted(['AS500M_E072N078T6', 'AS500M_E078N078T6',
'AS500M_E078N084T6', 'NA500M_E036N078T6',
'NA500M_E036N084T6', 'NA500M_E042N078T6',
'NA500M_E042N084T6'])
tiles = grid.search_tiles_in_roi(kamchatka_geom, coverland=False)
assert sorted(tiles) == sorted(kamchatka_geom_tiles)
- interpret correctly longitudes higher than 180 degrees
"""
grid = Equi7Grid(500)
geom_siberia_tiles = sorted(['AS500M_E066N090T6', 'AS500M_E072N090T6'])
poly_siberia_antim_180plus = setup_test_geom_siberia_antimeridian_180plus()
tiles = sorted(grid.search_tiles_in_roi(poly_siberia_antim_180plus, coverland=False))
assert sorted(tiles) == sorted(geom_siberia_tiles)
geom_siberia_alaska_tiles = sorted(['AS500M_E066N090T6', 'AS500M_E072N090T6',
'AS500M_E072N096T6',
'NA500M_E054N072T6', 'NA500M_E054N078T6',
'NA500M_E060N078T6'])
poly_siberia_alaska = setup_test_geom_siberia_alaska()
tiles = sorted(grid.search_tiles_in_roi(poly_siberia_alaska, coverland=True))
assert sorted(tiles) == sorted(geom_siberia_alaska_tiles)
def test_search_tiles_siberia_antimeridian(self):
"""
Tests the tile searching over Siberia and Alaska in the polar zone; ROI defined
by a 4-corner polygon over high latitudes (is much curved on the globe).
Comprises:
- do not return tiles when not intersecting the zone
- interpret correctly longitudes higher than 180 degrees
"""
grid = Equi7Grid(500)
geom_siberia_tiles = sorted(['AS500M_E066N090T6', 'AS500M_E072N090T6'])
poly_siberia_antim_180plus = setup_test_geom_siberia_antimeridian_180plus()
tiles = sorted(grid.search_tiles_in_roi(poly_siberia_antim_180plus, coverland=False))
assert sorted(tiles) == sorted(geom_siberia_tiles)
geom_siberia_alaska_tiles = sorted(['AS500M_E066N090T6', 'AS500M_E072N090T6',
'AS500M_E072N096T6',
'NA500M_E054N072T6', 'NA500M_E054N078T6',
'NA500M_E060N078T6'])
poly_siberia_alaska = setup_test_geom_siberia_alaska()
tiles = sorted(grid.search_tiles_in_roi(poly_siberia_alaska, coverland=True))
assert sorted(tiles) == sorted(geom_siberia_alaska_tiles)
def test_search_tiles_spitzbergen(self):
"""
Tests the tile searching over Spitzbergen in the polar zone; ROI defined
by a 4-corner polygon over high latitudes (is much curved on the globe).
"""
grid = Equi7Grid(500)
spitzbergen_geom = setup_test_geom_spitzbergen()
spitzbergen_geom_tiles = sorted(['EU500M_E054N042T6', 'EU500M_E054N048T6',
'EU500M_E060N042T6', 'EU500M_E060N048T6'])
tiles = sorted(grid.search_tiles_in_roi(spitzbergen_geom,
coverland=False))
assert sorted(tiles) == sorted(spitzbergen_geom_tiles)
Initialises an Equi7Subgrid class for a specified continent.
Parameters
----------
core : TPSCoreProperty
defines core parameters of the (sub-) grid
continent : str
acronym of the continent, e.g. 'EU' or 'SA'.
"""
# load WKT string and extent shape
data = Equi7Grid._static_data[continent]
_core = copy.copy(core)
_core.tag = continent
_core.projection = TPSProjection(wkt=data['wkt'])
# holds core parameters of the (sub-) grid
self.core = _core
# holds name of the subgrid
self.name = ''.join(('EQUI7_', continent, Equi7Grid.encode_sampling(core.sampling), 'M'))
# holds the extent of the subgrid in the lonlat-space
self.polygon_geog = create_geometry_from_wkt(data['zone_extent'], epsg=4326)
# defines the tilingsystem of the subgrid
self.tilesys = Equi7TilingSystem(self.core, self.polygon_geog)
super(Equi7Subgrid, self).__init__(self.core, self.polygon_geog, self.tilesys)
def __init__(self, core, continent):
_core = copy.copy(core)
_core.tag = continent
_core.projection = TPSProjection(epsg=4326)
self.core = _core
self.polygon_geog = bbox2polygon([(-179.9999999, -90.0), (179.9999999, 90.0)],
self.core.projection.osr_spref)
self.tilesys = CopernicusTilingSystem(self.core, self.polygon_geog)
super(CopernicusSubgrid, self).__init__(self.core, self.polygon_geog, self.tilesys)
def decode_tilename(self, name):
pass
def identify_tiles_overlapping_xybbox(self, bbox):
return
def get_congruent_tiles_from_tilename(self, tilename,
target_sampling=None,
target_tiletype=None):
return
class CopernicusTile(Tile):
"""
Equi7 Tile class
A tile in the Equi7 grid system.
"""
def __init__(self, core, name):
super(CopernicusTile, self).__init__(core, name, -180, -90)
def list_tiles_covering_land(self):
"""
Returns a list of all tiles in the subgrid covering land
Returns
-------
list
list containing land tiles
"""
land_tiles = Equi7Grid._static_data[
self.core.tag]["coverland"][self.core.tiletype]
return list(land_tiles)
class Equi7Tile(Tile):
"""
The Equi7Tile class, inheriting Tile() from pytileproj.
A tile in the Equi7Grid system, holding characteristics of the tile.
"""
def __init__(self, core, name, xll, yll, covers_land):
super(Equi7Tile, self).__init__(core, name, xll, yll)
self.covers_land = covers_land
@property
def shortname(self):
return self.name[7:]
long form of the tilename containing the lon-lat position
i : integer
pixel column number; starts with 0
j : integer
pixel row number; starts with 0
"""
# get the xy-coordinates
subgrid, x, y = self._lonlat2xy(lon, lat)
tilename, i, j = self.subgrids[str(subgrid)].tilesys.xy2ij_in_tile(x, y, lowerleft=lowerleft)
return tilename, i, j
class Equi7Subgrid(TiledProjection):
"""
Equi7Subgrid class object, inheriting TiledProjection() from pytileproj.
"""
def __init__(self, core, continent):
"""
Initialises an Equi7Subgrid class for a specified continent.
Parameters
----------
core : TPSCoreProperty
defines core parameters of the (sub-) grid
continent : str
acronym of the continent, e.g. 'EU' or 'SA'.
"""
msg += " Supported resolutions: {}".format(
str(CopernicusGrid._static_res))
raise ValueError(msg)
return tile_code
def get_tilesize(self, sampling):
xsize = {'T10': 10.0, 'GLOBAL': 360.0}[self.get_tiletype(sampling)]
ysize = {'T10': 10.0, 'GLOBAL': 180.0}[self.get_tiletype(sampling)]
return xsize, ysize
def create_tile(self, name):
pass
class CopernicusSubgrid(TiledProjection):
def __init__(self, core, continent):
_core = copy.copy(core)
_core.tag = continent
_core.projection = TPSProjection(epsg=4326)
self.core = _core
self.polygon_geog = bbox2polygon([(-179.9999999, -90.0), (179.9999999, 90.0)],
self.core.projection.osr_spref)
self.tilesys = CopernicusTilingSystem(self.core, self.polygon_geog)
super(CopernicusSubgrid, self).__init__(self.core, self.polygon_geog, self.tilesys)
def get_polygon(self):