5858from ._utils .from_images import guess_if_segmentation_path
5959from ._utils .infer_bounding_box_existing_files import infer_bounding_box_existing_files
6060from .layer import (
61+ DTypeLike ,
6162 Layer ,
6263 SegmentationLayer ,
6364 _dtype_per_channel_to_element_class ,
@@ -738,8 +739,8 @@ def add_layer(
738739 self ,
739740 layer_name : str ,
740741 category : LayerCategoryType ,
741- dtype_per_layer : Optional [Union [ str , np . dtype , type ] ] = None ,
742- dtype_per_channel : Optional [Union [ str , np . dtype , type ] ] = None ,
742+ dtype_per_layer : Optional [DTypeLike ] = None ,
743+ dtype_per_channel : Optional [DTypeLike ] = None ,
743744 num_channels : Optional [int ] = None ,
744745 data_format : Union [str , DataFormat ] = DEFAULT_DATA_FORMAT ,
745746 ** kwargs : Any ,
@@ -846,8 +847,8 @@ def get_or_add_layer(
846847 self ,
847848 layer_name : str ,
848849 category : LayerCategoryType ,
849- dtype_per_layer : Optional [Union [ str , np . dtype , type ] ] = None ,
850- dtype_per_channel : Optional [Union [ str , np . dtype , type ] ] = None ,
850+ dtype_per_layer : Optional [DTypeLike ] = None ,
851+ dtype_per_channel : Optional [DTypeLike ] = None ,
851852 num_channels : Optional [int ] = None ,
852853 data_format : Union [str , DataFormat ] = DEFAULT_DATA_FORMAT ,
853854 ** kwargs : Any ,
@@ -975,17 +976,19 @@ def add_layer_from_images(
975976 chunk_shape : Optional [Union [Vec3IntLike , int ]] = None ,
976977 chunks_per_shard : Optional [Union [int , Vec3IntLike ]] = None ,
977978 compress : bool = False ,
979+ * ,
978980 ## other arguments
981+ topleft : Vec3IntLike = Vec3Int .zeros (), # in Mag(1)
979982 swap_xy : bool = False ,
980983 flip_x : bool = False ,
981984 flip_y : bool = False ,
982985 flip_z : bool = False ,
986+ dtype : Optional [DTypeLike ] = None ,
983987 use_bioformats : bool = False ,
984988 channel : Optional [int ] = None ,
985989 timepoint : Optional [int ] = None ,
986990 batch_size : Optional [int ] = None , # defaults to shard-size z
987991 executor : Optional [Executor ] = None ,
988- * ,
989992 chunk_size : Optional [Union [Vec3IntLike , int ]] = None , # deprecated
990993 ) -> Layer :
991994 """
@@ -1005,8 +1008,10 @@ def add_layer_from_images(
10051008 * `data_format`: by default wkw files are written, may be set to "zarr"
10061009 * `mag`: magnification to use for the written data
10071010 * `chunk_shape`, `chunks_per_shard`, `compress`: adjust how the data is stored on disk
1011+ * `topleft`: set an offset in Mag(1) to start writing the data, only affecting the output
10081012 * `swap_xy`: set to `True` to interchange x and y axis before writing to disk
1009- * `flip_x`, `flip_y`, `flip_z`: set to `True` to flip the respective axis before writing to disk
1013+ * `flip_x`, `flip_y`, `flip_z`: set to `True` to reverse the respective axis before writing to disk
1014+ * `dtype`: the read image data will be convertoed to this dtype using `numpy.ndarray.astype`
10101015 * `use_bioformats`: set to `True` to use the [pims bioformats adapter](https://soft-matter.github.io/pims/v0.6.1/bioformats.html), needs a JVM
10111016 * `channel`: may be used to select a single channel, if multiple are available,
10121017 * `timepoint`: for timeseries, select a timepoint to use by specifying it as an int, starting from 0
@@ -1041,7 +1046,7 @@ def add_layer_from_images(
10411046 layer_name = layer_name ,
10421047 category = category ,
10431048 data_format = data_format ,
1044- dtype_per_channel = pims_images .dtype ,
1049+ dtype_per_channel = pims_images .dtype if dtype is None else dtype ,
10451050 num_channels = pims_images .num_channels ,
10461051 ** add_layer_kwargs , # type: ignore[arg-type]
10471052 )
@@ -1052,9 +1057,11 @@ def add_layer_from_images(
10521057 compress = compress ,
10531058 )
10541059 mag = mag_view .mag
1055- layer .bounding_box = BoundingBox (
1056- (0 , 0 , 0 ), pims_images .expected_shape
1057- ).from_mag_to_mag1 (mag )
1060+ layer .bounding_box = (
1061+ BoundingBox ((0 , 0 , 0 ), pims_images .expected_shape )
1062+ .from_mag_to_mag1 (mag )
1063+ .offset (topleft )
1064+ )
10581065
10591066 if batch_size is None :
10601067 if compress :
@@ -1074,6 +1081,7 @@ def add_layer_from_images(
10741081 pims_images .copy_to_view ,
10751082 mag_view = mag_view ,
10761083 is_segmentation = category == "segmentation" ,
1084+ dtype = dtype ,
10771085 )
10781086
10791087 args = []
@@ -1109,8 +1117,10 @@ def add_layer_from_images(
11091117 max_id = max (max_ids )
11101118 cast (SegmentationLayer , layer ).largest_segment_id = max_id
11111119 actual_size = Vec3Int (dimwise_max (shapes ) + (pims_images .expected_shape .z ,))
1112- layer .bounding_box = BoundingBox ((0 , 0 , 0 ), actual_size ).from_mag_to_mag1 (
1113- mag
1120+ layer .bounding_box = (
1121+ BoundingBox ((0 , 0 , 0 ), actual_size )
1122+ .from_mag_to_mag1 (mag )
1123+ .offset (topleft )
11141124 )
11151125 if pims_images .expected_shape != actual_size :
11161126 warnings .warn (
0 commit comments