66
77import math
88from copy import deepcopy
9+ from pathlib import Path
910from typing import Union
1011
1112import blosc2
1920@register_writer ("mask" , ".b2nd" , backend = "blosc2" )
2021def save_blosc2 (
2122 data : np .ndarray ,
22- file : str ,
23+ file : str | Path ,
2324 patch_size : Union [tuple [int , int ], tuple [int , int , int ]] | None = None ,
2425 clevel : int = 8 ,
2526 nthreads : int = 8 ,
@@ -42,11 +43,7 @@ def save_blosc2(
4243 _is_float = np .issubdtype (data .dtype .type , np .floating )
4344 _is_2d = data .ndim == 2
4445
45- # if _is_2d:
4646 base_patch_size = (512 if _is_float else 1024 ) if _is_2d else (64 if _is_float else 96 )
47- # else:
48- # base_patch_size = 64 if _is_float else 96
49-
5047 patch_size = tuple ([min (s , base_patch_size ) for s in data .shape ])
5148
5249 blocks , chunks = comp_blosc2_params (data .shape , patch_size , data .itemsize )
@@ -60,12 +57,12 @@ def save_blosc2(
6057 mmap_mode = "w+" ,
6158 meta = metadata ,
6259 )
63- return [file ]
60+ return [str ( file ) ]
6461
6562
6663@register_loader ("image" , ".b2nd" , backend = "blosc2" )
6764@register_loader ("mask" , ".b2nd" , backend = "blosc2" )
68- def load_blosc2 (file : str , nthreads : int = 1 ) -> tuple [blosc2 .NDArray , dict ]:
65+ def load_blosc2 (file : str | Path , nthreads : int = 1 ) -> tuple [blosc2 .NDArray , dict ]:
6966 """Reads a Blosc2 file and returns the data and metadata.
7067
7168 Args:
@@ -86,7 +83,7 @@ def load_blosc2(file: str, nthreads: int = 1) -> tuple[blosc2.NDArray, dict]:
8683@register_writer ("mask" , ".b2nd" , backend = "blosc2pkl" )
8784def save_blosc2pkl (
8885 data : np .ndarray ,
89- file : str ,
86+ file : str | Path ,
9087 patch_size : Union [tuple [int , int ], tuple [int , int , int ]] | None = None ,
9188 clevel : int = 8 ,
9289 nthreads : int = 8 ,
@@ -112,7 +109,7 @@ def save_blosc2pkl(
112109
113110@register_loader ("image" , ".b2nd" , backend = "blosc2pkl" )
114111@register_loader ("mask" , ".b2nd" , backend = "blosc2pkl" )
115- def load_blosc2pkl (file : str , nthreads : int = 1 ) -> tuple [blosc2 .NDArray , dict ]:
112+ def load_blosc2pkl (file : str | Path , nthreads : int = 1 ) -> tuple [blosc2 .NDArray , dict ]:
116113 """Reads a Blosc2 file and returns the data and metadata.
117114
118115 Args:
0 commit comments