Skip to content

Fix npy channel#1441

Draft
mrariden wants to merge 4 commits intomainfrom
fix_npy_channel
Draft

Fix npy channel#1441
mrariden wants to merge 4 commits intomainfrom
fix_npy_channel

Conversation

@mrariden
Copy link
Copy Markdown
Collaborator

@mrariden mrariden commented May 1, 2026

Changing the MainW.color from int to str caused loading/saving .npy files to fail when loading 'current_channel'. Added backwards-compatible check that allows old .npy files to be opened with new cellpose versions. In that case, the behavior is to set default 'current_channel' to RGB.

Also ensured GUI loads image with update_plot() when loading .npy file.

  • GUI testing protocol
  • GH tests
  • Mac/ubuntu tests

@carsen-stringer
Copy link
Copy Markdown
Member

Thanks Michael, so seg.npy files will still open the same exact way as before?

Comment thread cellpose/gui/io.py Outdated
@mrariden
Copy link
Copy Markdown
Collaborator Author

mrariden commented May 7, 2026

use this script to fix intermediate _seg.npy files:

import click
import numpy as np
from pathlib import Path


@click.command()
@click.argument('filename')
def main(filename: str|Path):
    filename = Path(filename)

    file_data = np.load(filename, allow_pickle=True).item()
    color = file_data['current_channel']
    if isinstance(color, str):
        click.echo(f'found incorrect `color` type: ({str(color)}), changing to int')
        file_data['current_channel'] = 0
    else:
        click.echo('file seems okay, exiting...')
        return 
    
    new_fn = filename.resolve().with_name(filename.stem[:-4] + '_fixed_seg.npy')
    click.echo(f'{">" * 5} Saving fixed file to \t{str(new_fn)}')
    np.save(new_fn, file_data)
    click.echo('done.')
    click.echo('You will have to rename the `_fixed_seg.npy` to end in `_seg.npy` (remove `_fixed_seg.npy`)')


if __name__ == "__main__":
    main()

@mrariden
Copy link
Copy Markdown
Collaborator Author

mrariden commented May 7, 2026

Now the .color attribute is always saved as an int. All behavior is backwards compatible

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

Successfully merging this pull request may close these issues.

2 participants