You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: labelbox/data/annotation_types/data/tiled_image.py
+84-24Lines changed: 84 additions & 24 deletions
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,13 @@
1
1
fromenumimportEnum
2
-
fromtypingimportOptional, List
2
+
fromtypingimportOptional, List, Any, Dict
3
3
4
4
frompydanticimportBaseModel, validator
5
+
importnumpyasnp
6
+
frompyprojimportTransformer, transform
5
7
6
8
from ..geometryimportPoint
7
9
from .base_dataimportBaseData
10
+
from .rasterimportRasterData
8
11
9
12
10
13
classEPSG(Enum):
@@ -15,9 +18,9 @@ class EPSG(Enum):
15
18
>>> epsg = EPSG()
16
19
"""
17
20
SIMPLEPIXEL=1
18
-
EPSG4326=2
19
-
EPSG3857=3
20
-
EPSG3395=4
21
+
EPSG4326=4326
22
+
EPSG3857=3857
23
+
EPSG3395=3395
21
24
22
25
23
26
classTiledBounds(BaseModel):
@@ -71,38 +74,95 @@ class TiledImageData(BaseData):
71
74
""" Represents tiled imagery
72
75
73
76
If specified version is 2, converts bounds from [lng,lat] to [lat,lng]
77
+
78
+
Requires the following args:
79
+
tile_layer: TileLayer
80
+
tile_bounds: TiledBounds
81
+
zoom_levels: List[int]
82
+
Optional args:
83
+
max_native_zoom: int = None
84
+
tile_size: Optional[int]
85
+
version: int = 2
86
+
alternative_layers: List[TileLayer]
74
87
"""
75
88
tile_layer: TileLayer
76
-
alternative_layers: List[TileLayer]
77
89
tile_bounds: TiledBounds
90
+
alternative_layers: List[TileLayer] =None
78
91
zoom_levels: List[int]
79
-
max_native_zoom: int=zoom_levels[1]
92
+
max_native_zoom: int=None
80
93
tile_size: Optional[int]
81
94
version: int=2
82
95
83
-
# @property #TODO
84
-
# def value(self):
85
-
# Return self._as_raster(self.min_zoom).value()
86
-
87
-
# def _as_raster(zoom): #TODO
88
-
# stitched together tiles as a RasterData object
89
-
# Return result
90
-
91
-
@property
92
-
deftile_layer_url(self):
93
-
returnself.tile_layer.url
94
-
95
-
@property
96
-
defbounds(self):
97
-
returnself.tile_bounds.bounds
98
-
96
+
def__post_init__(self):
97
+
ifself.max_native_zoomisNone:
98
+
self.max_native_zoom=zoom_levels[1]
99
+
100
+
#TODO: look further into Matt's code and how to reference the monorepo ?
101
+
def_as_raster(zoom):
102
+
# stitched together tiles as a RasterData object
103
+
# TileData.get_image(target_hw) ← we will be using this from Matt's precomputed embeddings
104
+
# more info found here: https://github.com/Labelbox/python-monorepo/blob/baac09cb89e083209644c9bdf1bc3d7cb218f147/services/precomputed_embeddings/precomputed_embeddings/tiled.py
105
+
image_as_np=None
106
+
returnRasterData(arr=image_as_np)
107
+
108
+
@property#TODO
109
+
defvalue(self) ->np.ndarray:
110
+
returnself._as_raster(self.min_zoom).value()
111
+
112
+
#TODO: maybe not necessary, can remove
113
+
# @property
114
+
# def tile_layer_url(self) -> str:
115
+
# return self.tile_layer.url
116
+
117
+
#TODO: maybe not necessary, can remove
118
+
# @property
119
+
# def bounds(self) -> List[Point]:
120
+
# return self.tile_bounds.bounds
121
+
122
+
#TODO: wondering to keep this or not since epsg may be something of interest
123
+
# and they dont want to go through TiledImageData.tile_bounds.epsg?
124
+
# then can call TiledimageData.epsg
99
125
@property
100
-
defepsg(self):
126
+
defepsg(self)->EPSG:
101
127
returnself.tile_bounds.epsg
102
128
103
129
@validator('zoom_levels')
104
130
defvalidate_zooms(cls, zoom_levels):
105
131
iflen(zoom_levels) !=2:
106
132
raiseAssertionError(
107
-
f"zoom_levels should only contain min and max, found {len(zoom_levels)}"
133
+
f"zoom_levels should contain 2 values [min,max], found {len(zoom_levels)}"
134
+
)
135
+
136
+
137
+
#TODO: we will need to update the [data] package to also require pyproj
138
+
classEPSGTransformer(BaseModel):
139
+
"""Transformer class between different EPSG's. Useful when wanting to project
0 commit comments