-
Notifications
You must be signed in to change notification settings - Fork 0
add loading of an example dataset with image and seed layers #7
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
3689f4c
remove unnecessary reader/writer
romainGuiet 8aceab6
add seed_Chicken1.csv with seed points to test on chicken.gif
romainGuiet 6a2a035
modify _sample_data.py to load chicken gif and seed_chicken1.csv
romainGuiet c3ff665
modify napari.yaml to remove reader/writer and add example data loading
romainGuiet a2ceb82
Update src/napari_cotcotcot/_sample_data.py
romainGuiet 3b29d1e
Update src/napari_cotcotcot/_sample_data.py
romainGuiet 88b7711
Update src/napari_cotcotcot/_sample_data.py
romainGuiet 2d10807
Update src/napari_cotcotcot/_sample_data.py
romainGuiet 10faf9a
add auto-init to ease start
romainGuiet 4737952
add expected output
romainGuiet 98eb3b9
remove test raeder/writer
romainGuiet 6875791
update github url
romainGuiet a776bfc
update comments
romainGuiet 3e7f449
simnplify test_widget.py
romainGuiet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,85 @@ | ||
| """ | ||
| This module is an example of a barebones sample data provider for napari. | ||
|
|
||
| It implements the "sample data" specification. | ||
| see: https://napari.org/stable/plugins/building_a_plugin/guides.html#sample-data | ||
| from pathlib import Path | ||
| from typing import List | ||
|
|
||
| Replace code below according to your needs. | ||
| """ | ||
| import numpy as np | ||
| import pandas as pd | ||
| from skimage.io import imread | ||
| from napari.types import LayerData | ||
|
|
||
| from __future__ import annotations | ||
| def _load_seed_from_csv_standalone(csv_path: str) -> np.ndarray: | ||
| """ | ||
| Load seed points from a CSV file. | ||
|
|
||
| import numpy | ||
| Parameters | ||
| ---------- | ||
| csv_path : str | ||
| Path to the CSV file containing seed point coordinates. | ||
|
|
||
| Returns | ||
| ------- | ||
| np.ndarray | ||
| Array of shape (n_points, 3) containing seed point coordinates. | ||
|
|
||
| def make_sample_data(): | ||
| """Generates an image""" | ||
| # Return list of tuples | ||
| # [(data1, add_image_kwargs1), (data2, add_image_kwargs2)] | ||
| # Check the documentation for more information about the | ||
| # add_image_kwargs | ||
| # https://napari.org/stable/api/napari.Viewer.html#napari.Viewer.add_image | ||
| return [(numpy.random.rand(512, 512), {})] | ||
| Raises | ||
| ------ | ||
| ValueError | ||
| If the CSV format is invalid (missing required columns). | ||
| """ | ||
| df = pd.read_csv(csv_path) | ||
|
|
||
| required_cols = ["axis-0", "axis-1", "axis-2"] | ||
| if not all(col in df.columns for col in required_cols): | ||
| if all(col in df.columns for col in ["t", "y", "x"]): | ||
| df = df.rename(columns={"t": "axis-0", "y": "axis-1", "x": "axis-2"}) | ||
| else: | ||
| raise ValueError("CSV must contain columns: axis-0, axis-1, axis-2 (or t, y, x)") | ||
|
|
||
| return df[["axis-0", "axis-1", "axis-2"]].values | ||
|
|
||
| def load_sample_data() -> List[LayerData]: | ||
| """ | ||
| Loads sample data for demonstration in napari. | ||
|
|
||
| This function loads: | ||
| - A GIF image ("chicken-run.gif") from a remote URL: | ||
| https://raw.githubusercontent.com/BIOP/napari-cotcotcot/refs/heads/main/src/napari_cotcotcot/data/Gallus_gallus_domesticus/chicken-run.gif | ||
| - Seed points from a local CSV file ("seed_Chicken1.csv") if available at: | ||
| <package_dir>/data/Gallus_gallus_domesticus/seed_Chicken1.csv | ||
|
|
||
| Returns | ||
| ------- | ||
| List[LayerData] | ||
| A list of tuples (data, metadata, layer_type) suitable for napari, where: | ||
| - The first tuple contains the image data, metadata with name "cotcotcot", and layer_type "image". | ||
| - The second tuple (if CSV is found and loaded) contains the seed points, metadata with name "seed_Chicken1", and layer_type "points". | ||
|
|
||
| Data Sources | ||
| ----------- | ||
| - GIF image: downloaded from the above URL. | ||
| - Seed points: loaded from a local CSV file. | ||
|
|
||
| Exceptions | ||
| ---------- | ||
| - If the CSV file is missing, empty, or malformed, an error is printed and only the image is returned. | ||
| - If the GIF image cannot be downloaded or read, an exception may be raised by skimage.io.imread. | ||
| """ | ||
| URL = "https://raw.githubusercontent.com/BIOP/napari-cotcotcot/refs/heads/main/src/napari_cotcotcot/data/Gallus_gallus_domesticus/chicken-run.gif" | ||
| print(f"Downloading sample data from {URL}...") | ||
| try: | ||
| gif_data = imread(URL) | ||
| print("Downloading completed!") | ||
| sample_datasets = [(gif_data, {"name": "cotcotcot"}, "image")] | ||
| except (IOError, ValueError, Exception) as e: | ||
| print(f"Error downloading or reading image from {URL}: {e}") | ||
| sample_datasets = [] | ||
| # Load CSV | ||
| csv_data_path = Path(__file__).parent / "data" / "Gallus_gallus_domesticus" / "seed_Chicken1.csv" | ||
| if csv_data_path.exists(): | ||
| try: | ||
| csv_data = _load_seed_from_csv_standalone(str(csv_data_path)) | ||
| sample_datasets.append((csv_data, {"name": "seed_Chicken1"}, "points")) | ||
| except (FileNotFoundError, ValueError, pd.errors.EmptyDataError, pd.errors.ParserError) as e: | ||
| print(f"Error loading CSV data: {e}") | ||
|
|
||
| return sample_datasets | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Binary file added
BIN
+6.49 MB
src/napari_cotcotcot/data/Gallus_gallus_domesticus/cotcotcot_output.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions
5
src/napari_cotcotcot/data/Gallus_gallus_domesticus/seed_Chicken1.csv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| index,axis-0,axis-1,axis-2 | ||
| 0.0,0.0,92.83061471930142,59.76071319110557 | ||
| 1.0,23.0,163.09295583101897,78.5809831317442 | ||
| 2.0,10.0,93.00985538540276,73.9207258131099 | ||
| 3.0,18.0,128.6787479395655,85.57136910969572 | ||
romainGuiet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.