9
9
from operator import itemgetter
10
10
from typing import (
11
11
Any ,
12
+ Callable ,
12
13
Dict ,
13
14
Generic ,
14
15
Iterator ,
41
42
42
43
from .. import ATTR_NAME
43
44
from ..helpers import (
45
+ MetadataCallbackError ,
44
46
ReadWriteGroup ,
45
47
compute_channel_minmax ,
46
48
get_axes_mapper ,
@@ -324,7 +326,7 @@ def to_tiledb(
324
326
preserve_axes : bool = False ,
325
327
chunked : bool = False ,
326
328
max_workers : int = 0 ,
327
- exclude_metadata : bool = False ,
329
+ exclude_metadata : Union [ bool , Callable [[ str ], str ], None ] = None ,
328
330
experimental_reader : bool = False ,
329
331
experimental_queue_limit : Tuple [int , int ] = (10 , 20 ),
330
332
compressor : Optional [Union [Mapping [int , Any ], Any ]] = None ,
@@ -350,7 +352,14 @@ def to_tiledb(
350
352
original ones.
351
353
:param max_workers: Maximum number of threads that can be used for conversion.
352
354
Applicable only if chunked=True.
353
- :param exclude_metadata: If true, drop original metadata of the images and exclude them from being ingested.
355
+ :param exclude_metadata: An optional argument that specifies how to transform the original metadata.
356
+ It can be one of the following:
357
+ * A callable (function, method, etc.) that takes an OME-XML string and returns it as a string, while removing
358
+ some of the original metadata and excluding them from being ingested.
359
+ * A boolean value:
360
+ * ``True``: Indicates a specific built-in transformation should be applied. see: `remove_ome_image_metadata`
361
+ * ``False``: Indicates no transformation should be applied.
362
+ * ``None``: Indicates no transformation should be applied (same as ``False``).
354
363
:param experimental_reader: If true, use the experimental tiff reader optimized for s3 reads.
355
364
Experimental feature, use with caution
356
365
:param experimental_queue_limit: When using the experimental reader, define the minimum and maximum number of
@@ -536,7 +545,15 @@ def to_tiledb(
536
545
original_metadata = reader .original_metadata
537
546
else :
538
547
if ome_xml := reader .original_metadata .get ("ome_metadata" ):
539
- pruned_metadata = remove_ome_image_metadata (ome_xml )
548
+ if isinstance (exclude_metadata , bool ):
549
+ pruned_metadata = remove_ome_image_metadata (ome_xml )
550
+ elif callable (exclude_metadata ):
551
+ try :
552
+ pruned_metadata = exclude_metadata (ome_xml )
553
+ except Exception as exc :
554
+ raise MetadataCallbackError (str (exc ))
555
+ else :
556
+ raise TypeError ("exclude_metadata must be bool or callable" )
540
557
original_metadata = (
541
558
{"ome_metadata" : pruned_metadata } if pruned_metadata else {}
542
559
)
0 commit comments