5353
5454FILTER_EXISTING_BATCH_SIZE = 1000
5555
56-
5756if TYPE_CHECKING :
5857 from kili .client import Kili
5958
@@ -63,6 +62,7 @@ class BatchParams(NamedTuple):
6362
6463 is_asynchronous : bool
6564 is_hosted : bool
65+ input_type : Optional [InputType ] = None
6666
6767
6868class ProcessingParams (NamedTuple ):
@@ -103,7 +103,9 @@ def __init__(
103103 self .logger = logging .getLogger (__name__ )
104104 self .logger .setLevel (logging .INFO )
105105
106- def import_batch (self , assets : ListOrTuple [AssetLike ], verify : bool ) -> List [str ]:
106+ def import_batch ( # pylint: disable=unused-argument
107+ self , assets : ListOrTuple [AssetLike ], verify : bool , input_type : Optional [InputType ] = None
108+ ) -> List [str ]:
107109 """Base actions to import a batch of asset.
108110
109111 Returns:
@@ -236,7 +238,7 @@ def are_native_videos(assets) -> bool:
236238
237239 def _async_import_to_kili (self , assets : List [KiliResolverAsset ]):
238240 """Import assets with asynchronous resolver."""
239- if self .input_type == "IMAGE" :
241+ if self .input_type in [ "IMAGE" , "GEOSPATIAL" ] :
240242 upload_type = "GEO_SATELLITE"
241243 elif self .input_type in ("VIDEO" , "VIDEO_LEGACY" ):
242244 upload_type = "NATIVE_VIDEO" if self .are_native_videos (assets ) else "FRAME_VIDEO"
@@ -297,7 +299,9 @@ def import_to_kili(self, assets: List[KiliResolverAsset]):
297299class ContentBatchImporter (BaseBatchImporter ):
298300 """Class defining the methods to import a batch of assets with content."""
299301
300- def import_batch (self , assets : List [AssetLike ], verify : bool ):
302+ def import_batch (
303+ self , assets : List [AssetLike ], verify : bool , input_type : Optional [InputType ] = None
304+ ):
301305 """Method to import a batch of asset with content."""
302306 assets = self .add_ids (assets )
303307 if not self .is_hosted :
@@ -312,7 +316,7 @@ def import_batch(self, assets: List[AssetLike], verify: bool):
312316 if not asset .get ("content" ) and not asset .get ("multi_layer_content" )
313317 ]
314318 if len (assets_with_content ) > 0 :
315- assets += self .upload_local_content_to_bucket (assets_with_content )
319+ assets += self .upload_local_content_to_bucket (assets_with_content , input_type )
316320 return super ().import_batch (assets , verify )
317321
318322 def get_content_type_and_data_from_content (
@@ -332,7 +336,9 @@ def get_type_and_data_from_content_array(
332336 """Returns the data of the content (path) and its content type for each element in the array."""
333337 return list (map (self .get_content_type_and_data_from_content , content_array ))
334338
335- def upload_local_content_to_bucket (self , assets : List [AssetLike ]):
339+ def upload_local_content_to_bucket (
340+ self , assets : List [AssetLike ], input_type : Optional [InputType ] = None
341+ ):
336342 """Upload local content to a bucket."""
337343 project_bucket_path = self .generate_project_bucket_path ()
338344 # tuple containing (bucket_path, file_path, asset_index, content_index)
@@ -343,12 +349,14 @@ def upload_local_content_to_bucket(self, assets: List[AssetLike]):
343349 if multi_layer_content :
344350 for j , item in enumerate (multi_layer_content ):
345351 bucket_path = BaseBatchImporter .build_url_from_parts (
346- project_bucket_path , asset_id , "content" , str ( j )
352+ project_bucket_path , asset_id , "content" , f" { j !s } .tif"
347353 )
348354 to_upload .append ((bucket_path , item .get ("path" ), i , j ))
349355 else :
350356 bucket_path = BaseBatchImporter .build_url_from_parts (
351- project_bucket_path , asset_id , "content"
357+ project_bucket_path ,
358+ asset_id ,
359+ "content.tif" if input_type == "GEOSPATIAL" else "content" ,
352360 )
353361 to_upload .append ((bucket_path , asset .get ("content" ), i , None ))
354362 signed_urls = bucket .request_signed_urls (
@@ -418,7 +426,9 @@ def upload_json_content_to_bucket(self, assets: List[AssetLike]):
418426 )
419427 return [AssetLike (** {** asset , "json_content" : url }) for asset , url in zip (assets , url_gen )] # type: ignore
420428
421- def import_batch (self , assets : List [AssetLike ], verify : bool ):
429+ def import_batch (
430+ self , assets : List [AssetLike ], verify : bool , input_type : Optional [InputType ] = None
431+ ):
422432 """Method to import a batch of asset with json content."""
423433 assets = self .add_ids (assets )
424434 assets = self .loop_on_batch (self .stringify_json_content )(assets )
@@ -443,7 +453,7 @@ def __init__(
443453 self .pbar = tqdm (disable = logger_params .disable_tqdm )
444454
445455 @abc .abstractmethod
446- def import_assets (self , assets : List [AssetLike ]) -> List [str ]:
456+ def import_assets (self , assets : List [AssetLike ], input_type : InputType ) -> List [str ]:
447457 """Import assets into Kili.
448458
449459 Returns:
@@ -611,6 +621,7 @@ def import_assets_by_batch(
611621 assets : List [AssetLike ],
612622 batch_importer : BaseBatchImporter ,
613623 batch_size = IMPORT_BATCH_SIZE ,
624+ input_type : Optional [InputType ] = None ,
614625 ):
615626 """Split assets by batch and import them with a given batch importer."""
616627 batch_generator = batcher (assets , batch_size )
@@ -622,5 +633,5 @@ def import_assets_by_batch(
622633 for i , batch_assets in enumerate (batch_generator ):
623634 # check last batch only
624635 verify = i == (nb_batch - 1 ) and self .verify
625- created_asset_ids += batch_importer .import_batch (batch_assets , verify )
636+ created_asset_ids += batch_importer .import_batch (batch_assets , verify , input_type )
626637 return created_asset_ids
0 commit comments