Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion connectors/antigravity/agents/register-scripting.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ subagent: true
model: inherit
---

You are an expert neuroanatomist registering one brain with LangSlice: a stack of histology sections from one brain, placed in a BrainGlobe atlas. The first message gives the job: what to do, the tools, and the facts about this stack and atlas. Work the job with the tools and finish with `submit`.
You are an expert neuroanatomist registering one brain with LangSlice: a stack of histology sections from one brain, placed in a BrainGlobe atlas. The first message gives the job: what to do, the tools, and the facts about this stack and atlas. Work the job with the LangSlice tools, your own scripts and any software you judge best, and finish with `submit`.

Run each script on its own with BypassSandbox: it reads the atlas and the images outside the sandbox.
7 changes: 5 additions & 2 deletions connectors/antigravity/skills/placement/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ correct a wrong plane.

## Positions

- **Keep the filename order** unless the anatomy clearly says otherwise.
Sections are usually named in cutting order.
- **Keep the order the filenames' section numbers give** unless the
anatomy clearly says otherwise. Sections are usually numbered in cutting
order; when a name holds several numbers (an image id, then `s0132`),
the section number is the one that steps along the stack, and it can run
backwards.
- **Fit the positions to the file numbers.** Once each section has a first
position (from `deepslice_place` or by eye), list each position beside the
section number in its filename. Real stacks fall on one line: its slope is
Expand Down
2 changes: 1 addition & 1 deletion connectors/claude-code/agents/register-scripting.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ model: inherit
omitClaudeMd: true
---

You are an expert neuroanatomist registering one brain with LangSlice: a stack of histology sections from one brain, placed in a BrainGlobe atlas. The first message gives the job: what to do, the tools, and the facts about this stack and atlas. Work the job with the tools and finish with `submit`.
You are an expert neuroanatomist registering one brain with LangSlice: a stack of histology sections from one brain, placed in a BrainGlobe atlas. The first message gives the job: what to do, the tools, and the facts about this stack and atlas. Work the job with the LangSlice tools, your own scripts and any software you judge best, and finish with `submit`.

Run a script that takes long (one that fits sections) as a Bash command with `run_in_background`: Claude Code's sandbox ends a command that outlasts its time limit, and the script with it.
7 changes: 5 additions & 2 deletions connectors/claude-code/skills/placement/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ correct a wrong plane.

## Positions

- **Keep the filename order** unless the anatomy clearly says otherwise.
Sections are usually named in cutting order.
- **Keep the order the filenames' section numbers give** unless the
anatomy clearly says otherwise. Sections are usually numbered in cutting
order; when a name holds several numbers (an image id, then `s0132`),
the section number is the one that steps along the stack, and it can run
backwards.
- **Fit the positions to the file numbers.** Once each section has a first
position (from `deepslice_place` or by eye), list each position beside the
section number in its filename. Real stacks fall on one line: its slope is
Expand Down
2 changes: 1 addition & 1 deletion connectors/codex/agents/register_scripting.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ description = "Registers ONE brain (one LangSlice job folder) with the LangSlice
sandbox_mode = "workspace-write"

developer_instructions = """
You are an expert neuroanatomist registering one brain with LangSlice: a stack of histology sections from one brain, placed in a BrainGlobe atlas. The first message gives the job: what to do, the tools, and the facts about this stack and atlas. Work the job with the tools and finish with `submit`.
You are an expert neuroanatomist registering one brain with LangSlice: a stack of histology sections from one brain, placed in a BrainGlobe atlas. The first message gives the job: what to do, the tools, and the facts about this stack and atlas. Work the job with the LangSlice tools, your own scripts and any software you judge best, and finish with `submit`.
"""
7 changes: 5 additions & 2 deletions connectors/codex/skills/placement/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ correct a wrong plane.

## Positions

- **Keep the filename order** unless the anatomy clearly says otherwise.
Sections are usually named in cutting order.
- **Keep the order the filenames' section numbers give** unless the
anatomy clearly says otherwise. Sections are usually numbered in cutting
order; when a name holds several numbers (an image id, then `s0132`),
the section number is the one that steps along the stack, and it can run
backwards.
- **Fit the positions to the file numbers.** Once each section has a first
position (from `deepslice_place` or by eye), list each position beside the
section number in its filename. Real stacks fall on one line: its slope is
Expand Down
10 changes: 8 additions & 2 deletions docs/reference/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ Draws pictures of sections and the atlas. Writes nothing.
| `registrations` | none | `{filename: number}`: draw a section under an earlier [registration](#restore_registration) of its own, writing nothing. |
| `resolution` | 0 (job's size) | Long edge in pixels. Offered only when the job's [`image_resolution`](settings.md#pictures) is `auto`. |
| `sheet` | false | Tile the pictures into sheets of up to 16. Agent CLI and library only. |
| `cutting_angles` | the stack's | `{"pitch_deg": number, "yaw_deg": number}`: draw `atlas` mode at `positions_mm` at these angles instead of the stack's, writing nothing; either left out keeps the stack's. Refused with sections or in another mode. |

Atlas borders are drawn as cased lines: a black core with a white edge on
light tissue, a white core with a black edge on dark tissue; the caption
Expand Down Expand Up @@ -436,6 +437,7 @@ Writes nothing.
|---|---|---|
| `regions` | (required) | Regions, descendants included; `"CTX:left"` names one side. |
| `positions_mm` | (required) | Positions; one outside the atlas is clamped into its range. |
| `cutting_angles` | the stack's | `{"pitch_deg": number, "yaw_deg": number}`: draw the planes at these angles instead of the stack's, writing nothing; either left out keeps the stack's. |

**Switch off:** `grep_atlas_view`.

Expand Down Expand Up @@ -690,7 +692,9 @@ agent CLI and in the library only. See
Sets where sections sit along the slicing axis, and the stack's cutting
angles. A value outside the atlas range is clamped into it and reported. The
stack's order follows the positions. A changed position or angle clears the
deformation of each section it moves.
deformation of each section it moves. The reply lists the positions
`written` and, when `cutting_angles` was given, the stack's angles as
`cutting_angles_written` (`pitch_deg`, `yaw_deg`).

| Argument | Default | What it does |
|---|---|---|
Expand Down Expand Up @@ -766,7 +770,9 @@ core count; below 16 cores they are fitted in turn).

A fit that changes the scale along either axis by more than a factor of 0.8
to 1.25 is flagged `SCALE_CHANGED`, one that changes the shear by more than
0.15 `SHEAR`, and one that turns the section more than 45 degrees says so. A
0.15 `SHEAR`, one that scales one axis more than 1.25 times the other
`ANISOTROPIC`, and one that turns the section more than 45 degrees says so.
A flag warns; the fit is written, and `undo` takes it back. A
region too small for Elastix is refused (`BAD_ARGUMENT`).

**In a run when** Linear is on. **Switch off:** `elastix_affine`.
Expand Down
1 change: 1 addition & 0 deletions src/langslice/core/fits/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class FitFlag(TextEnum):
FOLDS = "FOLDS"
REGION_FOLDED = "REGION_FOLDED"
REGION_VANISHED = "REGION_VANISHED"
ANISOTROPIC = "ANISOTROPIC"
SCALE_CHANGED = "SCALE_CHANGED"
SHEAR = "SHEAR"

Expand Down
43 changes: 39 additions & 4 deletions src/langslice/core/pictures/look.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ class LookRequest:
masks: tuple[str, ...] = ()
depth: int = OVERLAY_DEPTH
registrations: tuple[tuple[str, int, bool], ...] = ()
cutting_angles: tuple[float, float] | None = None

def registration_of(self, section: str) -> tuple[int, bool] | None:
"""``(number, held)`` of the registration *section* is drawn under,
Expand Down Expand Up @@ -189,6 +190,11 @@ def args(self) -> dict[str, Any]:
if self.registrations
else {}
),
**(
{"cutting_angles": [float(v) for v in self.cutting_angles]}
if self.cutting_angles is not None
else {}
),
}

@classmethod
Expand Down Expand Up @@ -220,9 +226,17 @@ def from_args(cls, args: dict[str, Any]) -> LookRequest:
(str(name), int(number), bool(held))
for name, number, held in args.get("registrations") or ()
),
cutting_angles=_angle_pair(args.get("cutting_angles")),
)


def _angle_pair(value: Any) -> tuple[float, float] | None:
"""A recipe's ``cutting_angles`` as ``(pitch_deg, yaw_deg)``; None when it has none."""
if not value:
return None
return float(value[0]), float(value[1])


@dataclass(frozen=True)
class LookPicture:
"""One picture: the captioned image, its index caption, its recipe, the
Expand Down Expand Up @@ -718,9 +732,9 @@ def _overlay_picture(
if drawn
else "deformation held but not drawable"
if drawn is False
else "linear placement only"
else f"linear placement only: {LINEAR_MOVES}"
if request.warp == "none" and record.deformation
else "no deformation"
else f"no deformation: {LINEAR_MOVES}"
)
atlas_words = " + ".join(layers) or "none"
if options.atlas_images and options.atlas_opacity > 0:
Expand Down Expand Up @@ -968,6 +982,9 @@ def _mask_words(notes: list[dict[str, Any]], record: Section) -> str:
)


LINEAR_MOVES = "the transform moves the section onto the atlas, which keeps its place"


def _landmark_context(state: Stack, record: Section) -> dict[str, Any]:
from langslice.core.fits.landmarks import context

Expand Down Expand Up @@ -1020,14 +1037,20 @@ def _atlas_picture(
picture = framed_atlas(ws, state, position_mm, options, angles=angles, um_per_px=um)
base = picture.size
section = state.by_id(request.sections[0]) if len(request.sections) == 1 else None
median = state.drawn_at_median(angles) if section is None else False
median = (
state.drawn_at_median(angles)
if section is None and request.cutting_angles is None
else False
)
label = _zoom_tag(request.zoom, base, picture.size) + atlas_caption(
state, position_mm, options, angles=angles, median=median
)
layers_words = " + ".join(layers) or "none"
plane = (
view_angles_label(angles, median=True)
if median
else f"{angles_label(angles)} (the cutting angles asked for, not written)"
if request.cutting_angles is not None
else f"{angles_label(angles)} (the stack's cutting angles)"
)
if section:
Expand Down Expand Up @@ -1191,7 +1214,19 @@ def look(
if request.warp not in WARP_CHOICES:
raise Refused(RefusalCode.BAD_ARGUMENT, f"warp must be one of {', '.join(WARP_CHOICES)}")
long_edge = int(request.long_edge or picture_edge(ws))
plane = angles if angles is not None else state.view_angles
if request.cutting_angles is not None and (request.mode != "atlas" or request.sections):
raise Refused(
RefusalCode.BAD_ARGUMENT,
"cutting_angles draws atlas mode at positions_mm; a section's picture "
"is at its own plane. Nothing was drawn.",
)
plane = (
request.cutting_angles
if request.cutting_angles is not None
else angles
if angles is not None
else state.view_angles
)
if request.mode == "positioning":
return _positioning(ws, state, request, long_edge, plane, zoom_edge)
if request.mode == "atlas":
Expand Down
3 changes: 1 addition & 2 deletions src/langslice/doors/mcp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@
INSTRUCTIONS = (
"LangSlice places histology sections in a brain atlas. The job comes in the message "
"that launched you; call `start_job` with its folder first: it opens the job and gives "
"you its tools. Read every show_stack page before writing. Work only through the "
"LangSlice tools and finish with `submit`."
"you its tools. Read every show_stack page before writing, and finish with `submit`."
)


Expand Down
5 changes: 3 additions & 2 deletions src/langslice/doors/reference_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,9 @@ def card_text(layout: JobLayout) -> str:

## Python
`import langslice; job = langslice.open_job("{layout.folder}")`; the verbs are methods
with the same arguments {example}; `help(job)` lists every one and the handle's own
methods, `help(langslice)` the rest of the library. Each returns, once its pictures are
with the tools' arguments and some only a script has {example}; `help(job)` lists every
one and the handle's own methods, `help(job.NAME)` one's arguments, `help(langslice)`
the rest of the library. Each returns, once its pictures are
on disk, a JSON-safe dict: the tool's reply in full (status rows with every field, null
where unset) plus `artifacts`, the files of its pictures; `reply.images` holds the
pictures as PIL images.
Expand Down
15 changes: 15 additions & 0 deletions src/langslice/job/folder/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
env/ the job's own Python environment, made by
`langslice job FOLDER env`
(langslice.doors.commands.job.environment)
scripts/, scratch/ a coding agent's own scripts and other files
AGENTS.md, CLAUDE.md the reference card for coding agents
TOOLS.md every verb's description and arguments (by `launch`)

Expand Down Expand Up @@ -74,6 +75,8 @@
VIEWS_INDEX = "views.jsonl"
EXPORTS_DIR = "exports"
LOGS_DIR = "logs"
SCRIPTS_DIR = "scripts"
SCRATCH_DIR = "scratch"
EVENTS_FILE = "events.jsonl"
LAUNCHES_DIR = "launches"
TRACE_DIR = "trace"
Expand Down Expand Up @@ -349,6 +352,16 @@ def views_index(self) -> Path:
def exports_dir(self) -> Path:
return self.folder / EXPORTS_DIR

@property
def scripts_dir(self) -> Path:
"""Where a coding agent keeps the scripts it writes for the job."""
return self.folder / SCRIPTS_DIR

@property
def scratch_dir(self) -> Path:
"""Where a coding agent keeps its other files for the job."""
return self.folder / SCRATCH_DIR

@property
def logs_dir(self) -> Path:
return self.folder / LOGS_DIR
Expand Down Expand Up @@ -471,6 +484,8 @@ def ensure(self) -> None:
self.views_dir,
self.exports_dir,
self.logs_dir,
self.scripts_dir,
self.scratch_dir,
):
folder.mkdir(parents=True, exist_ok=True)

Expand Down
8 changes: 8 additions & 0 deletions src/langslice/plugins/frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ class FitFrame:
``inputs.section_image``); ``stain`` is the section's ``preprocessed``
image the same way (``stain=True`` is ``image="preprocessed"``), the
picture the native fits read by default; each None unless asked for.
``position_mm`` and ``angles`` ``(pitch_deg, yaw_deg)`` are the placement
the plane was cut at. ``applied_map`` is the applied deformation as a
``(H, W, 2)`` map giving each ``image`` pixel's native atlas ``(x, y)``;
None without a deformation. ``damage_margin_mm`` is the margin that
widens ``excluded`` into ``damage_zone``. ``atlas_resolved`` maps each
atlas image name asked for to the image it was read as (``"nissl"`` to
``template`` on an atlas whose template is a Nissl), and
``atlas_image_note`` says so in words; None otherwise.
"""

id: str
Expand Down
Loading
Loading