@@ -1149,31 +1149,20 @@ def fetch_landmask(
11491149 # Use existing local file
11501150 return str (local_path )
11511151
1152- # Query hash from landmasks DataFrame for verification if lon/lat provided
1152+ # Query hash from landmasks index for verification if lon/lat provided
11531153 file_hash = None
11541154 if (
11551155 self .verify_hashes
11561156 and self ._landmasks_df is not None
11571157 and lon is not None
11581158 and lat is not None
11591159 ):
1160- # Use pre-computed integer grid indices for robust comparison
11611160 lon_i = coord_to_grid_int (lon )
11621161 lat_i = coord_to_grid_int (lat )
1163-
1164- # Use dictionary index for O(1) lookup - more reliable than DataFrame filtering
11651162 key = (int (lon_i ), int (lat_i ))
1166- if hasattr ( self , "_landmask_index" ) and key in self ._landmask_index :
1163+ if key in self ._landmask_index :
11671164 idx = self ._landmask_index [key ]
11681165 file_hash = self ._landmasks_df .iloc [idx ]["hash" ]
1169- else :
1170- # Fallback to DataFrame filtering
1171- matches = self ._landmasks_df [
1172- (self ._landmasks_df ["lon_i" ] == lon_i )
1173- & (self ._landmasks_df ["lat_i" ] == lat_i )
1174- ]
1175- if len (matches ) > 0 :
1176- file_hash = matches .iloc [0 ]["hash" ]
11771166
11781167 # Download to embeddings_dir
11791168 url = f"{ TESSERA_BASE_URL } /{ self .version } /{ LANDMASKS_DIR_NAME } /{ filename } "
@@ -1260,29 +1249,18 @@ def get_tile_file_size(self, year: int, lon: float, lat: float) -> int:
12601249 "Please update your registry to include file size metadata."
12611250 )
12621251
1263- # Use pre-computed integer grid indices for robust comparison
1252+ # Use dictionary index for O(1) lookup
12641253 lon_i = coord_to_grid_int (lon )
12651254 lat_i = coord_to_grid_int (lat )
1266-
1267- # Use dictionary index for O(1) lookup - more reliable than DataFrame filtering
12681255 key = (int (year ), int (lon_i ), int (lat_i ))
1269- if hasattr (self , "_tile_index" ) and key in self ._tile_index :
1270- idx = self ._tile_index [key ]
1271- return int (self ._registry_gdf .iloc [idx ]["file_size" ])
1272-
1273- # Fallback to DataFrame filtering for compatibility
1274- matches = self ._registry_gdf [
1275- (self ._registry_gdf ["year" ] == year )
1276- & (self ._registry_gdf ["lon_i" ] == lon_i )
1277- & (self ._registry_gdf ["lat_i" ] == lat_i )
1278- ]
12791256
1280- if len ( matches ) == 0 :
1257+ if key not in self . _tile_index :
12811258 raise ValueError (
12821259 f"Tile not found in registry: year={ year } , lon={ lon :.2f} , lat={ lat :.2f} "
12831260 )
12841261
1285- return int (matches .iloc [0 ]["file_size" ])
1262+ idx = self ._tile_index [key ]
1263+ return int (self ._registry_gdf .iloc [idx ]["file_size" ])
12861264
12871265 def get_scales_file_size (self , year : int , lon : float , lat : float ) -> int :
12881266 """Get the file size of a scales file from the registry.
@@ -1304,29 +1282,18 @@ def get_scales_file_size(self, year: int, lon: float, lat: float) -> int:
13041282 "Please update your registry to include scales file size metadata."
13051283 )
13061284
1307- # Use pre-computed integer grid indices for robust comparison
1285+ # Use dictionary index for O(1) lookup
13081286 lon_i = coord_to_grid_int (lon )
13091287 lat_i = coord_to_grid_int (lat )
1310-
1311- # Use dictionary index for O(1) lookup - more reliable than DataFrame filtering
13121288 key = (int (year ), int (lon_i ), int (lat_i ))
1313- if hasattr (self , "_tile_index" ) and key in self ._tile_index :
1314- idx = self ._tile_index [key ]
1315- return int (self ._registry_gdf .iloc [idx ]["scales_size" ])
1316-
1317- # Fallback to DataFrame filtering for compatibility
1318- matches = self ._registry_gdf [
1319- (self ._registry_gdf ["year" ] == year )
1320- & (self ._registry_gdf ["lon_i" ] == lon_i )
1321- & (self ._registry_gdf ["lat_i" ] == lat_i )
1322- ]
13231289
1324- if len ( matches ) == 0 :
1290+ if key not in self . _tile_index :
13251291 raise ValueError (
13261292 f"Tile not found in registry: year={ year } , lon={ lon :.2f} , lat={ lat :.2f} "
13271293 )
13281294
1329- return int (matches .iloc [0 ]["scales_size" ])
1295+ idx = self ._tile_index [key ]
1296+ return int (self ._registry_gdf .iloc [idx ]["scales_size" ])
13301297
13311298 def get_landmask_file_size (self , lon : float , lat : float ) -> int :
13321299 """Get the file size of a landmask tile from the registry.
@@ -1353,28 +1320,18 @@ def get_landmask_file_size(self, lon: float, lat: float) -> int:
13531320 "Please update your landmasks registry to include file size metadata."
13541321 )
13551322
1356- # Use pre-computed integer grid indices for robust comparison
1323+ # Use dictionary index for O(1) lookup
13571324 lon_i = coord_to_grid_int (lon )
13581325 lat_i = coord_to_grid_int (lat )
1359-
1360- # Use dictionary index for O(1) lookup - more reliable than DataFrame filtering
13611326 key = (int (lon_i ), int (lat_i ))
1362- if hasattr (self , "_landmask_index" ) and key in self ._landmask_index :
1363- idx = self ._landmask_index [key ]
1364- return int (self ._landmasks_df .iloc [idx ]["file_size" ])
1365-
1366- # Fallback to DataFrame filtering for compatibility
1367- matches = self ._landmasks_df [
1368- (self ._landmasks_df ["lon_i" ] == lon_i )
1369- & (self ._landmasks_df ["lat_i" ] == lat_i )
1370- ]
13711327
1372- if len ( matches ) == 0 :
1328+ if key not in self . _landmask_index :
13731329 raise ValueError (
13741330 f"Landmask not found in registry: lon={ lon :.2f} , lat={ lat :.2f} "
13751331 )
13761332
1377- return int (matches .iloc [0 ]["file_size" ])
1333+ idx = self ._landmask_index [key ]
1334+ return int (self ._landmasks_df .iloc [idx ]["file_size" ])
13781335
13791336 def calculate_download_requirements (
13801337 self ,
0 commit comments