@@ -482,6 +482,8 @@ def load_raw(file_dir: str | os.PathLike, file_name: str | os.PathLike) -> np.nd
482482 file_name : str or os.PathLike
483483 Name of the file with extension
484484
485+ .. todo:: Add support to overwrite size and bit depth.
486+
485487 Returns
486488 -------
487489 img_arr : np.ndarray
@@ -551,23 +553,7 @@ def load_raw(file_dir: str | os.PathLike, file_name: str | os.PathLike) -> np.nd
551553
552554 data_type : type [Union [np .floating [Any ] | np .integer [Any ] | np .unsignedinteger [Any ]]]
553555 # Set data type according to bit depth
554- match bit_depth :
555- case "8u" | "8" : # "8" is for backwards compatibility
556- data_type = np .ubyte # Set data type to unsigned byte
557- case "16u" | "16" : # "16" is for backwards compatibility
558- data_type = np .ushort # Set data type to unsigned short
559- case "32u" | "32" : # "32" is for backwards compatibility
560- data_type = np .uintc # Set data type to unsigned int
561- case "16f" :
562- data_type = np .half # Set data type to half precision float
563- case "32f" :
564- data_type = np .float32 # Set data type to float32
565- case "64f" :
566- data_type = np .float64 # Set data type to float64
567- case _:
568- raise ValueError (
569- "Bit depth not supported"
570- ) # Raise exception if the bit depth is not supported
556+ data_type = _parse_bitdepth (bit_depth )
571557
572558 data_file_path = os .path .join (file_dir , file_name ) # Get data file path
573559
@@ -1017,3 +1003,25 @@ def _resize_image(img_r, img_m, scaling_order=1):
10171003 )
10181004 img_m = img_m .astype (img_r .dtype )
10191005 return img_m
1006+
1007+
1008+ def _parse_bitdepth (bitdepth ):
1009+ # Set data type according to bit depth
1010+ match bitdepth :
1011+ case "8ubit" | "8bit" : # "8" is for backwards compatibility
1012+ data_type = np .ubyte # Set data type to unsigned byte
1013+ case "16ubit" | "16bit" : # "16" is for backwards compatibility
1014+ data_type = np .ushort # Set data type to unsigned short
1015+ case "32ubit" | "32bit" : # "32" is for backwards compatibility
1016+ data_type = np .uintc # Set data type to unsigned int
1017+ case "16fbit" :
1018+ data_type = np .half # Set data type to half precision float
1019+ case "32fbit" :
1020+ data_type = np .float32 # Set data type to float32
1021+ case "64fbit" :
1022+ data_type = np .float64 # Set data type to float64
1023+ case _:
1024+ raise ValueError (
1025+ "Bit depth not supported"
1026+ ) # Raise exception if the bit depth is not supported
1027+ return data_type
0 commit comments