Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem during checking the key of the alien_mask/flatfield #66

Open
Abd-zak opened this issue Jul 22, 2024 · 0 comments
Open

Problem during checking the key of the alien_mask/flatfield #66

Abd-zak opened this issue Jul 22, 2024 · 0 comments
Milestone

Comments

@Abd-zak
Copy link

Abd-zak commented Jul 22, 2024

Two suggstions:

  • 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"
    )

def _check_load(data_or_path: np.ndarray | str) -> np.ndarray:

@clatlan clatlan added this to the 0.2.0 release milestone Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants