Skip to content

Commit c36d1b1

Browse files
committed
bump: v0.1.10; change: better token instruction; better README
1 parent b7a4739 commit c36d1b1

File tree

4 files changed

+94
-67
lines changed

4 files changed

+94
-67
lines changed

README.md

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
# flatone
22

3-
A command-line tool to (1) download one EyeWire II neuron mesh as `.obj`, (2) skeletonize it as `.swc` and (3) flatten it automatically.
3+
A command-line tool that automatically (1) downloads the mesh of an EyeWire II neuron as `.obj` with [CaveClient/CloudVolume](https://github.com/seung-lab/cloud-volume), (2) skeletonizes it as an `.swc` with [skeliner](https://github.com/berenslab/skeliner) and (3) flattens it with [pywarper](https://github.com/berenslab/pywarper).
4+
5+
## Installation
6+
7+
__NOTE__: `flatone` relies on SuiteSparse, which does **NOT** run on native Windows. Use it on Unix-like enviroment or Windows Subsystem for Linux (WSL 2) instead.
48

5-
## Installation and Usage
69

710
```bash
811
# prerequisites
912
## mac
1013
brew update
1114
brew install suite-sparse
1215

13-
## debian/ubuntu/WSL
16+
## debian/ubuntu/WSL
1417
sudo apt-get update
1518
sudo apt-get install build-essential # if not already installed
1619
sudo apt-get install libsuitesparse-dev
@@ -27,23 +30,53 @@ pip install -e .
2730

2831
# but it's highly recommended to install it within a venv env
2932
# here we use uv again but of course you can run python -m venv
30-
uv venv .venv --python 3.13
33+
uv venv .venv --python 3.13 # any versions>=3.10 should work
3134
source .venv/bin/activate
3235
uv pip install -e .
3336

3437
# now you can check if it works
3538
flatone -v
3639
```
3740

38-
Assuming you have a CAVEClient token stored in your environment, you can run the full pipeline in one line:
41+
## Usage
42+
43+
> DISCLAIMER
44+
>
45+
> `flatone` is designed for quick, exploratory inspection. Skeletons and warps are generated with the default parameters of `skeliner` and `pywarper`, most of them cannot be tuned directly in `flatone`, so results might not be optimal for some cells. For higher-precision results, run `skeliner` and `pywarper` directly and fine-tune the parameters.
46+
47+
All you need to do is provide the segment ID of an EW2 neuron you'd like to preview:
3948

4049
```bash
4150
flatone SEGMENT_ID
4251
```
4352

44-
(If you don't have a CAVEClient token yet, `flatone` will call `CAVEclient().auth.get_new_token()` automatically, which will guide you to a website to get a new token (you don't need to follow all the steps from the CAVEClient, you only need to go to the link, and get the token). After that, you can run `flatone add-token YOUR-NEW-TOKEN` to save it to the environment and then run `flatone SEGMENT_ID` again.)
53+
If you don't have a CAVEClient token stored in the system yet, `flatone` will call `CAVEclient().auth.get_new_token()` internally, and prints something like:
4554

46-
This creates an `output` directory in the working directory:
55+
```
56+
No CAVEclient token found.
57+
58+
New Tokens need to be acquired by hand. Please follow the following steps:
59+
1) Go to: https://<URL>
60+
2) Log in with your Google account and copy the token shown.
61+
3) Add it to Flatone with:
62+
flatone add-token <TOKEN>
63+
Note: ...
64+
Warning! ...
65+
```
66+
67+
Just follow the link, copy the token, and register it with:
68+
69+
```bash
70+
flatone add-token <TOKEN>
71+
```
72+
73+
The token is stored in `~/.cloudvolume/secrets`. Now you can rerun the command:
74+
75+
```bash
76+
flatone SEGMENT_ID
77+
```
78+
79+
This will create an `output` directory in the same directory:
4780

4881
```bash
4982
output
@@ -70,4 +103,3 @@ You can also warp the mesh, but it's not in the default as it's a much slower pr
70103
`flatone` also has a (limited) interactive 3d viewer, which you can activate via `flatone view3d`. You can append a SEGMENT_ID after it to just view this cell, or without it, to view all cells within the `output/` folder. By default, it will view the unwarped meshes and skeletons together, if you warped the mesh already, you can also view the warped meshes and skeletons with `flatone view3d --warped`. You can also curate a different set of cells in another folder, then view them with `flatone view3d --warped --output-dir="path/to/another/folder".
71104

72105
Check `flatone -h` for more details.
73-

flatone/cli.py

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#!/usr/bin/env python3
22
import argparse
3+
import io
34
import re
45
import sys
6+
from contextlib import redirect_stdout
57
from importlib import resources
68
from importlib.metadata import PackageNotFoundError, version
79
from pathlib import Path
@@ -99,6 +101,44 @@ def _build_token_parser() -> argparse.ArgumentParser:
99101
p.add_argument("token", help="token string obtained from the DAF portal")
100102
return p
101103

104+
def _prompt_for_token(client) -> None:
105+
"""
106+
If the user has no token, show CaveClient’s instructions *minus* steps 3a/3b
107+
and inject a Flatone-specific step 3. Exits the program afterward.
108+
"""
109+
if client.auth.token is not None:
110+
return
111+
112+
print("No CAVEclient token found.\n")
113+
# Capture CaveClient’s standard instructions without hard-coding them
114+
buf = io.StringIO()
115+
with redirect_stdout(buf):
116+
client.auth.get_new_token()
117+
cave_text = buf.getvalue().splitlines()
118+
119+
# Drop CaveClient’s “3a” and “3b” lines
120+
filtered = [
121+
ln for ln in cave_text
122+
if not re.match(r'\s*3[ab]\)', ln) # remove 3a/3b
123+
and not re.match(r'\s*or\s*$', ln, re.I) # remove “or”
124+
]
125+
126+
# Insert our own single step 3 right after step 2
127+
for idx, ln in enumerate(filtered):
128+
if re.match(r'\s*2\)', ln):
129+
filtered.insert(idx + 1,
130+
" 3) Add it to `flatone` with:"
131+
)
132+
filtered.insert(idx + 2,
133+
" flatone add-token <TOKEN>"
134+
)
135+
break
136+
137+
# Re-print the modified message and quit
138+
print("\n".join(filtered))
139+
raise SystemExit
140+
141+
102142
# ---------- pure functions ------------------------------------------------- #
103143

104144
def fetch_mesh(seg_id: int, outdir: Path, verbose: bool, overwrite: bool) -> Path:
@@ -107,12 +147,8 @@ def fetch_mesh(seg_id: int, outdir: Path, verbose: bool, overwrite: bool) -> Pat
107147
# check caveclient credentials before proceeding
108148
from caveclient import CAVEclient
109149
client = CAVEclient()
110-
111-
if client.auth.token is None:
112-
print("No CAVEclient token found.\n")
113-
_ = client.auth.get_new_token()
114-
raise SystemExit("\nRun `flatone add-token xxxxx` to add a token.")
115-
150+
_prompt_for_token(client)
151+
116152
mesh_path = outdir / "mesh.obj"
117153
if not overwrite and mesh_path.exists():
118154
if verbose:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "flatone"
7-
version = "0.1.9"
7+
version = "0.1.10"
88
description = "A command-line tool to flatten one Eyewire2 neuron automatically."
99
authors = []
1010
requires-python = ">=3.10.0"

uv.lock

Lines changed: 11 additions & 52 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)