You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
for npz file sometimes when chacking the file.keys() don't give the keys so better to hadle it as dict
--> if possible_key in dict(file).keys():
The second is on the testing of the possible keys you raise after the first iteration of the possible keys(). It must be after testing all the possible keys()
below the function with the suggestions.
def _check_load(data_or_path: np.ndarray | str) -> np.ndarray:
"""
Private method to load mask or alien np.ndarray.
Args:
data_or_path (np.ndarray | str): the data or the path of the
data.
Raises:
ValueError: If path or np.ndarray is not provided.
Returns:
np.ndarray: the numpy array.
"""
if isinstance(data_or_path, str):
if data_or_path.endswith(".npy"):
return np.load(data_or_path)
if data_or_path.endswith(".npz"):
with np.load(data_or_path, "r") as file:
for possible_key in (
"arr_0", "data", "mask", "flatfield", "flat_field"
):
if possible_key in dict(file).keys():
return file[possible_key]
raise KeyError(
f"Unvalid file provided containing {file.keys()}."
)
elif data_or_path is None or isinstance(data_or_path, np.ndarray):
return data_or_path
raise ValueError(
"[ERROR] wrong value for flat_field and/or alien_mask "
"parameter provide a path, np.ndarray or leave it to None"
)
Two suggstions:
--> if possible_key in dict(file).keys():
below the function with the suggestions.
def _check_load(data_or_path: np.ndarray | str) -> np.ndarray:
"""
Private method to load mask or alien np.ndarray.
cdiutils/cdiutils/load/loader.py
Line 80 in 9a96ae4
The text was updated successfully, but these errors were encountered: