def METHOD_NAME(
    cope_files: list[Path],
    var_cope_files: list[Path] | None,
    mask_files: list[Path],
    quiet: bool | None = None,
) -> tuple[nib.nifti1.Nifti1Image, nib.nifti1.Nifti1Image]:
    if len(cope_files) != len(mask_files):
        raise ValueError(
            f"Number of cope files ({len(cope_files)}) does not match number of mask files ({len(mask_files)})"
        )
    # Load cope images.
    cope_imgs = [
        nib.funcs.squeeze_image(nib.loadsave.load(cope_file))
        for cope_file in cope_files
    ]
    (volume_shape,) = set(img.shape[:3] for img in cope_imgs)
    shape = volume_shape + (len(mask_files),)
    cope_data = np.empty(shape, dtype=float)
    for i, cope_img in enumerate(
        tqdm(cope_imgs, desc="loading cope images", leave=False, disable=quiet)
    ):
        cope_data[..., i] = cope_img.get_fdata()
    # Load mask images.
    mask_data = np.empty(shape, dtype=bool)
    for i, mask_file in enumerate(
        tqdm(mask_files, desc="loading mask images", leave=False, disable=quiet)
    ):
        mask_img = nib.funcs.squeeze_image(nib.loadsave.load(mask_file))
        mask_data[..., i] = np.asanyarray(mask_img.dataobj).astype(bool)
    # Load varcope images.
    var_cope_data = np.full(shape, np.nan, dtype=float)
    if var_cope_files is not None:
        if len(var_cope_files) != len(cope_files):
            raise ValueError(
                f"Number of var_cope files ({len(var_cope_files)}) does not match number of cope files ({len(cope_files)})"
            )
        for i, var_cope_file in enumerate(
            tqdm(
                var_cope_files,
                desc="loading var_cope images",
                leave=False,
                disable=quiet,
            )
        ):
            if var_cope_file is None:
                raise ValueError(
                    f'Missing var_cope file corresponding to "{cope_files[i]}"'
                )
            var_cope_img = nib.funcs.squeeze_image(nib.loadsave.load(var_cope_file))
            var_cope_data[..., i] = var_cope_img.get_fdata()
    # Update the masks.
    mask_data &= np.isfinite(cope_data)
    if var_cope_files is not None:
        mask_data &= np.isfinite(var_cope_data)
    # Zero out voxels that are not in the mask.
    cope_data[~mask_data] = np.nan
    var_cope_data[~mask_data] = np.nan
    # Create image objects.
    copes_img = new_img_like(cope_imgs[0], cope_data)
    var_copes_img = new_img_like(cope_imgs[0], var_cope_data)
    return copes_img, var_copes_img