Parameters & Pickers
Parameters declared with nexus.add_parameters become editable controls in the Parameters section of the Selection panel. The type chooses the control.
Basic parameter types
| Type | Control | Value in Python |
|---|---|---|
number |
Number field (honours min, max, step, unit) |
int / float |
string |
Text field | str |
boolean |
On/off toggle | bool |
enum |
Dropdown of options |
str |
color |
Colour picker | str (hex, e.g. "#4ECDC4") |
params = nexus.add_parameters({
"threshold": {"type": "number", "title": "Threshold", "default": 0.5, "min": 0, "max": 1, "step": 0.05},
"method": {"type": "enum", "title": "Method", "default": "mean", "options": ["mean", "median", "max"]},
"invert": {"type": "boolean", "title": "Invert", "default": False},
})
Pickers
For values you’d rather read off the data than type, four picker parameter types let you sample directly from a viewer or the timeline.
| Type | Control | Value in Python |
|---|---|---|
coordinate |
Crosshair — click a point on a 2D viewer | "x,y" pixel string |
intensity |
Pipette — click a pixel to sample its value | float intensity |
timestamp |
Clock — click the timeline, a graph, or a 2D viewer | float seconds |
roi (+ subtypes) |
Dropdown of drawn annotations | annotation id string |
Choosing the right type
Pick the type that matches what the value means, not the shape it happens to have in Python. An intensity and a pixel count are both numbers, but only one of them is a value you can judge by looking at the image — and declaring it intensity is what puts the pipette beside the field.
| The value is | Use | Rather than |
|---|---|---|
| A pixel or greyscale value — threshold, cutoff, background level, contrast limit | intensity |
number |
| A position in an image — centre, origin, beam position, seed point | coordinate |
two numbers |
| A moment in time — when to sample, the start of an event, a reference frame | timestamp |
number |
| A region you have drawn — ROI, box, area, line, point | roi (+ subtypes) |
hard-coded coordinates |
| A signal to read | an input signal | string |
| A count, a size in pixels, a window length, a factor, a tolerance | number |
— |
number and string are the fallbacks, not the defaults. A threshold typed as number leaves whoever runs the script guessing a brightness into an empty box; typed as intensity, they click the pixel they mean and the value follows.
There is no “time range” type. For a start and an end, declare two timestamp parameters — each end is picked separately anyway.
How to pick
To pick, click the button next to the field, then click the target. The cursor becomes a crosshair over everything that can answer the pick:
| Picking | Click | You get |
|---|---|---|
coordinate / intensity |
A 2D Image Viewer | The pixel you clicked |
timestamp |
The timeline — the time ruler or the signal lanes | The time at that point |
timestamp |
A time-series graph or spectrogram | The time at that point |
timestamp |
A 2D Image Viewer | The timestamp of the frame on screen — click anywhere, since a pixel has no time of its own |
Picked coordinates are drawn on the viewer as labelled crosshairs while the script’s panel is open.
Press Esc to cancel a pick, or click anywhere that can’t supply the value you’re picking (an XY graph or a spectrum, for instance, whose horizontal axis isn’t time).
params = nexus.add_parameters({
"centre": {"type": "coordinate", "title": "Beam centre", "default": "0,0"},
"peak": {"type": "timestamp", "title": "Peak time", "default": 0},
"floor": {"type": "intensity", "title": "Noise floor", "default": 0},
})
x, y = (int(v) for v in params["centre"].split(","))
A timestamp value is seconds — but which clock it sits on depends on how it was set. Picking a time (timeline, graph, or 2D viewer), or typing a wall-clock date, gives an absolute Unix-epoch value (e.g. 1.76e9), shown as a UTC date-and-time in the field. Typing an elapsed duration (MM:SS or HH:MM:SS) gives relative seconds. The script receives the raw number either way.
A signal’s own times — sig.timestamps — are on the signal’s relative time scale (not wall-clock time). A picked timestamp is absolute Unix-epoch seconds (~1.6e9), so comparing it directly against sig.timestamps silently matches nothing. Put the picked value on the same scale first by subtracting the experiment start, which is on the signal’s metadata as experiment_start_unix_time, and the signal’s sync offset sig.time_offset (zero unless the user synced it):
EPOCH_2000 = 946684800.0 # values >= this are absolute Unix seconds (2000-01-01)
def picked_time_to_relative(t_picked, sig):
"""Align a `timestamp` parameter with sig.timestamps (relative seconds).
A picked value (or a typed wall-clock date) is absolute Unix seconds; a
typed elapsed duration is already relative. Returns None if unresolvable."""
if t_picked is None or t_picked <= 0:
return None
if t_picked < EPOCH_2000:
return float(t_picked) # already relative (typed elapsed, e.g. MM:SS)
start = (sig.metadata.get("experiment_start_unix_time")
or sig.metadata.get("experiment_start_unix"))
# A synced signal is drawn time_offset later than its own clock (NXE-815), so a time
# picked off the timeline is shifted by it too.
return float(t_picked) - float(start) - sig.time_offset if start is not None else None
# e.g. the frame nearest a picked time:
rel = picked_time_to_relative(params["peak"], signal)
if rel is not None:
idx = min(range(len(signal.timestamps)),
key=lambda i: abs(signal.timestamps[i] - rel))
Region-of-interest (ROI) parameters
An ROI parameter offers a dropdown of the geometric annotations you’ve drawn. The subtype restricts which shapes are offered:
| Type | Offers |
|---|---|
roi |
Any geometric annotation |
roi_rectangle |
Rectangles |
roi_circle |
Circles |
roi_line |
Lines and arrows |
roi_point |
Points |
The value is the annotation’s id; resolve its geometry with nexus.get_annotation.
Reading an annotation
nexus.get_annotation(id) returns a dict describing a drawn annotation. Every result has id, type, name, source_signal_id, color, a roi_type, and the raw corner coordinates x1, y1, x2, y2. Shape-specific geometry keys are also included:
| Shape | Geometry keys |
|---|---|
| Rectangle | center_x, center_y, width, height, rotation |
| Circle | center_x, center_y, radius_x, radius_y, rotation |
| Line / Arrow | start_x, start_y, end_x, end_y |
| Point | x, y |
Coordinates are in pixels; rotation is in degrees.
inp = nexus.add_inputs({"img": {"title": "Image", "signal_type": "2Dts", "default": ""}})
params = nexus.add_parameters({"region": {"type": "roi_rectangle", "title": "Region", "default": ""}})
roi = nexus.get_annotation(params["region"])
x0 = int(roi["center_x"] - roi["width"] / 2)
y0 = int(roi["center_y"] - roi["height"] / 2)
frame = nexus.get_signal(inp["img"]).get_frame(0)
patch = frame[y0:y0 + int(roi["height"]), x0:x0 + int(roi["width"])]
nexus.set_signal("region_mean", [float(patch.mean())])