-
Notifications
You must be signed in to change notification settings - Fork 6
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
feat: add io and cli #21
Open
tlambert03
wants to merge
7
commits into
pyapp-kit:main
Choose a base branch
from
tlambert03:cli
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+206
−10
Open
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7ddad44
wip cli
tlambert03 3f09c39
wip
tlambert03 e2e89fd
Merge branch 'main' into cli
tlambert03 884be07
Merge branch 'main' into cli
tlambert03 1045325
stuff
tlambert03 6804414
style(pre-commit.ci): auto fixes [...]
pre-commit-ci[bot] d517f6d
negative levels
tlambert03 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
There are no files selected for viewing
This file contains 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 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 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,20 @@ | ||
"""command-line program.""" | ||
|
||
import argparse | ||
|
||
from ndv.util import imshow | ||
|
||
|
||
def _parse_args() -> argparse.Namespace: | ||
parser = argparse.ArgumentParser(description="ndv: ndarray viewer") | ||
parser.add_argument("path", type=str, help="The filename of the numpy file to view") | ||
return parser.parse_args() | ||
|
||
|
||
def main() -> None: | ||
"""Run the command-line program.""" | ||
from ndv import io | ||
|
||
args = _parse_args() | ||
|
||
imshow(io.imread(args.path)) | ||
This file contains 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,43 @@ | ||
"""All the io we can think of.""" | ||
|
||
from __future__ import annotations | ||
|
||
from textwrap import indent, wrap | ||
from typing import TYPE_CHECKING, Any | ||
|
||
import numpy as np | ||
|
||
if TYPE_CHECKING: | ||
from pathlib import Path | ||
|
||
import xarray as xr | ||
|
||
|
||
def imread(path: str | Path) -> Any: | ||
"""Just read the thing already.""" | ||
path_str = str(path) | ||
if path_str.endswith(".npy"): | ||
return np.load(path_str) | ||
errors = {} | ||
try: | ||
return _read_aicsimageio(path) | ||
except Exception as e: | ||
errors["aicsimageio"] = e | ||
|
||
raise ValueError(_format_error_message(errors)) | ||
|
||
|
||
def _format_error_message(errors: dict[str, Exception]) -> str: | ||
lines = ["Could not read file. Here are all the things we tried", ""] | ||
for _key, value in errors.items(): | ||
lines.append(f"{_key}:") | ||
wrapped = wrap(str(value), width=120) | ||
indented = indent("\n".join(wrapped), " ") | ||
lines.append(indented) | ||
return "\n".join(lines) | ||
|
||
|
||
def _read_aicsimageio(path: str | Path) -> xr.DataArray: | ||
from aicsimageio import AICSImage | ||
|
||
return AICSImage(str(path)).xarray_dask_data | ||
This file contains 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 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😂