1010import asyncio
1111import aiohttp
1212from requests .exceptions import HTTPError
13- from deprecated .sphinx import deprecated
1413from .dto .annotation_dto import CreateAnnotationDto , LineGeometry , BoxGeometry , CoordinateSystem , AnnotationType
1514import pydicom
1615import json
@@ -237,7 +236,7 @@ async def _upload_single_frame_segmentation_async(self,
237236 async def _upload_volume_segmentation_async (self ,
238237 resource_id : str ,
239238 file_path : str | np .ndarray ,
240- name : dict [int , str ] | dict [tuple , str ],
239+ name : str | dict [int , str ] | dict [tuple , str ] | None ,
241240 imported_from : Optional [str ] = None ,
242241 author_email : Optional [str ] = None ,
243242 worklist_id : Optional [str ] = None ,
@@ -263,6 +262,13 @@ async def _upload_volume_segmentation_async(self,
263262 Raises:
264263 ValueError: If name is not a string or file format is unsupported for volume upload.
265264 """
265+
266+ if isinstance (name , str ):
267+ raise NotImplementedError ("`name=string` is not supported yet for volume segmentation." )
268+ if isinstance (name , dict ):
269+ if any (isinstance (k , tuple ) for k in name .keys ()):
270+ raise NotImplementedError ("For volume segmentations, `name` must be a dictionary with integer keys only." )
271+
266272 # Prepare file for upload
267273 if isinstance (file_path , str ):
268274 if file_path .endswith ('.nii' ) or file_path .endswith ('.nii.gz' ):
@@ -275,7 +281,8 @@ async def _upload_volume_segmentation_async(self,
275281 form .add_field ('model_id' , model_id ) # Add model_id if provided
276282 if worklist_id is not None :
277283 form .add_field ('annotation_worklist_id' , worklist_id )
278- form .add_field ('segmentation_map' , json .dumps (name ), content_type = 'application/json' )
284+ if name is not None :
285+ form .add_field ('segmentation_map' , json .dumps (name ), content_type = 'application/json' )
279286
280287 request_params = dict (
281288 method = 'POST' ,
@@ -449,30 +456,27 @@ def upload_segmentations(self,
449456 if isinstance (file_path , str ) and not os .path .exists (file_path ):
450457 raise FileNotFoundError (f"File { file_path } not found." )
451458
452- name = AnnotationAPIHandler .standardize_segmentation_names (name )
453-
454459 # Handle NIfTI files specially - upload as single volume
455460 if isinstance (file_path , str ) and (file_path .endswith ('.nii' ) or file_path .endswith ('.nii.gz' )):
456461 _LOGGER .info (f"Uploading NIfTI segmentation file: { file_path } " )
457462 if frame_index is not None :
458463 raise ValueError ("Do not provide frame_index for NIfTI segmentations." )
459464 loop = asyncio .get_event_loop ()
460- task = self ._upload_segmentations_async (
465+ task = self ._upload_volume_segmentation_async (
461466 resource_id = resource_id ,
462- frame_index = None ,
463467 file_path = file_path ,
464468 name = name ,
465469 imported_from = imported_from ,
466470 author_email = author_email ,
467- discard_empty_segmentations = False ,
468471 worklist_id = worklist_id ,
469472 model_id = model_id ,
470- transpose_segmentation = transpose_segmentation ,
471- upload_volume = True
473+ transpose_segmentation = transpose_segmentation
472474 )
473475 return loop .run_until_complete (task )
474476 # All other file types are converted to multiple PNGs and uploaded frame by frame.
475477
478+ name = AnnotationAPIHandler .standardize_segmentation_names (name )
479+
476480 to_run = []
477481 # Generate IOs for the segmentations.
478482 nframes , fios = AnnotationAPIHandler ._generate_segmentations_ios (file_path ,
0 commit comments