Skill Tracer
Skills › Scientific Agent Skills › omero-integration › data_access.md

data_access.md

369 lines · skills/omero-integration/references/data_access.md at 5f2bc03

Open on GitHub

Most marks come from matching words in the file, so treat them as pointers.

1# Data Access, Hierarchies, and Transfers
2
3Use this reference for bounded reads and explicit import/export scopes. Read
4[`connection.md`](connection.md) first.
5

Data Access, Hierarchies, and Transfers

Use this reference for bounded reads and explicit import/export scopes. Read [connection.md](connection.md) first.

Raw lines 1 to 5
6## Object Hierarchies
7
8Common container paths are:
9
10```text
11Project -> Dataset -> Image
12Screen -> Plate -> Well -> WellSample -> Image
13Image -> Pixels -> Channel
14Image -> Fileset -> OriginalFile(s)
15```
17Links are model objects and may be many-to-many. Do not assume an image has
18exactly one dataset or a dataset exactly one project. Traverse links returned
19by the server instead of synthesizing parent paths.
21Common BlitzGateway object names documented by OME include:
23- `Project`, `Dataset`, `Image`
24- `Screen`, `Plate`, `PlateAcquisition`, `Well`
25- `Roi`, `Shape`
26- `Experimenter`, `ExperimenterGroup`
27- `OriginalFile`, `Fileset`
28- `Annotation` and specific annotation subtypes
30Object-name support is not permission. A returned `None` may mean nonexistent
31or inaccessible.

Object Hierarchies

Common container paths are:

Project -> Dataset -> Image
Screen -> Plate -> Well -> WellSample -> Image
Image -> Pixels -> Channel
Image -> Fileset -> OriginalFile(s)

Links are model objects and may be many-to-many. Do not assume an image has exactly one dataset or a dataset exactly one project. Traverse links returned by the server instead of synthesizing parent paths.

Common BlitzGateway object names documented by OME include:

  • Project, Dataset, Image
  • Screen, Plate, PlateAcquisition, Well
  • Roi, Shape
  • Experimenter, ExperimenterGroup
  • OriginalFile, Fileset
  • Annotation and specific annotation subtypes

Object-name support is not permission. A returned None may mean nonexistent or inaccessible.

Raw lines 6 to 32
33## One Object by ID
35Use explicit IDs whenever possible:
37```python
38image_id = 123
39image = conn.getObject("Image", image_id)
40if image is None:
41 raise LookupError("Image was not found or is not accessible")
43print(image.getId())
44print(image.getSizeX(), image.getSizeY())
45```
47Do not print names, descriptions, owner names, or acquisition metadata unless
48the requested output includes them.
50For multiple explicit IDs:
52```python
53requested_ids = [101, 102, 103]
54for image in conn.getObjects(
55 "Image",
56 requested_ids,
57 respect_order=True,
58):
59 print(image.getId())
60```
62Keep the input list bounded. Check whether inaccessible IDs were omitted.

One Object by ID

Use explicit IDs whenever possible:

image_id = 123
image = conn.getObject("Image", image_id)
if image is None:
    raise LookupError("Image was not found or is not accessible")

print(image.getId())
print(image.getSizeX(), image.getSizeY())

Do not print names, descriptions, owner names, or acquisition metadata unless the requested output includes them.

For multiple explicit IDs:

requested_ids = [101, 102, 103]
for image in conn.getObjects(
    "Image",
    requested_ids,
    respect_order=True,
):
    print(image.getId())

Keep the input list bounded. Check whether inaccessible IDs were omitted.

Raw lines 33 to 63
64## Bounded Pagination
66`getObjects()` returns a generator. Use both an overall cap and page size:
68```python
69def iter_bounded(conn, object_type, *, limit=100, page_size=25):
70 if not 1 <= limit <= 1000:
71 raise ValueError("limit must be between 1 and 1000")
72 if not 1 <= page_size <= min(limit, 200):
73 raise ValueError("page_size must be between 1 and min(limit, 200)")
75 emitted = 0
76 offset = 0
77 while emitted < limit:
78 size = min(page_size, limit - emitted)
79 page = list(
80 conn.getObjects(
81 object_type,
82 opts={
83 "limit": size,
84 "offset": offset,
85 "order_by": "obj.id",
86 },
87 )
88 )
89 if not page:
90 return
92 for obj in page:
93 yield obj
94 emitted += 1
96 if len(page) < size:
97 return
98 offset += len(page)
99```
101Do not write `list(conn.getObjects(...))` without server-side limits. If
102another process changes rows during offset paging, results may shift; record
103the extraction time and selected group.
105The bundled inventory helper implements a cap of 1000 and page cap of 200:
107```bash
108python -B scripts/inventory.py \
109 --object-type Image \
110 --limit 50 \
111 --page-size 25
113# Review the dry-run JSON, then explicitly connect:
114python -B scripts/inventory.py \
115 --object-type Image \
116 --limit 50 \
117 --page-size 25 \
118 --execute \
119 --output ./image-inventory.json
120```
122Names are redacted unless `--include-names` is requested.

Bounded Pagination

getObjects() returns a generator. Use both an overall cap and page size:

def iter_bounded(conn, object_type, *, limit=100, page_size=25):
    if not 1 <= limit <= 1000:
        raise ValueError("limit must be between 1 and 1000")
    if not 1 <= page_size <= min(limit, 200):
        raise ValueError("page_size must be between 1 and min(limit, 200)")

    emitted = 0
    offset = 0
    while emitted < limit:
        size = min(page_size, limit - emitted)
        page = list(
            conn.getObjects(
                object_type,
                opts={
                    "limit": size,
                    "offset": offset,
                    "order_by": "obj.id",
                },
            )
        )
        if not page:
            return

        for obj in page:
            yield obj
            emitted += 1

        if len(page) < size:
            return
        offset += len(page)

Do not write list(conn.getObjects(...)) without server-side limits. If another process changes rows during offset paging, results may shift; record the extraction time and selected group.

The bundled inventory helper implements a cap of 1000 and page cap of 200:

python -B scripts/inventory.py \
  --object-type Image \
  --limit 50 \
  --page-size 25

# Review the dry-run JSON, then explicitly connect:
python -B scripts/inventory.py \
  --object-type Image \
  --limit 50 \
  --page-size 25 \
  --execute \
  --output ./image-inventory.json

Names are redacted unless --include-names is requested.

Raw lines 64 to 123
Runs code scripts/inventory.py :108
124## Group and Owner Filters
126Prefer one selected group:
128```python
129group_id = 42
130conn.SERVICE_OPTS.setOmeroGroup(str(group_id))
132for project in conn.getObjects(
133 "Project",
134 opts={"limit": 20, "offset": 0, "order_by": "obj.id"},
135):
136 print(project.getId())
137```
139Filters can further narrow a query:
141```python
142owner_id = conn.getUser().getId()
143conn.SERVICE_OPTS.setOmeroGroup(str(group_id))
144projects = conn.getObjects(
145 "Project",
146 opts={
147 "owner": owner_id,
148 "limit": 20,
149 "offset": 0,
150 "order_by": "obj.id",
151 },
153```
155Cross-group context (`-1`) must be separately approved and paired with a hard
156limit. Never use it as a fallback when an object is not found.

Group and Owner Filters

Prefer one selected group:

group_id = 42
conn.SERVICE_OPTS.setOmeroGroup(str(group_id))

for project in conn.getObjects(
    "Project",
    opts={"limit": 20, "offset": 0, "order_by": "obj.id"},
):
    print(project.getId())

Filters can further narrow a query:

owner_id = conn.getUser().getId()
conn.SERVICE_OPTS.setOmeroGroup(str(group_id))
projects = conn.getObjects(
    "Project",
    opts={
        "owner": owner_id,
        "limit": 20,
        "offset": 0,
        "order_by": "obj.id",
    },
)

Cross-group context (-1) must be separately approved and paired with a hard limit. Never use it as a fallback when an object is not found.

Raw lines 124 to 157
158## Traversing Containers
160Downward traversal lazily loads children:
162```python
163project = conn.getObject("Project", project_id)
164if project is None:
165 raise LookupError("Project unavailable")
167dataset_limit = 10
168for dataset_index, dataset in enumerate(project.listChildren()):
169 if dataset_index >= dataset_limit:
170 break
171 print(dataset.getId())
173 image_limit = 25
174 for image_index, image in enumerate(dataset.listChildren()):
175 if image_index >= image_limit:
176 break
177 print(image.getId())
178```
180`listChildren()` can materialize the child collection before yielding; these
181loop caps bound output, not the query or memory. Prefer paged `getObjects()`
182with `project`, `dataset`, or `plate` filters for large containers.
183`countChildren()` can help plan a cap but does not replace one. A count may
184change before retrieval.
186For a direct dataset image query, prefer a server filter:
188```python
189images = conn.getObjects(
190 "Image",
191 opts={
192 "dataset": dataset_id,
193 "limit": 50,
194 "offset": 0,
195 "order_by": "obj.id",
196 },
198```

Traversing Containers

Downward traversal lazily loads children:

project = conn.getObject("Project", project_id)
if project is None:
    raise LookupError("Project unavailable")

dataset_limit = 10
for dataset_index, dataset in enumerate(project.listChildren()):
    if dataset_index >= dataset_limit:
        break
    print(dataset.getId())

    image_limit = 25
    for image_index, image in enumerate(dataset.listChildren()):
        if image_index >= image_limit:
            break
        print(image.getId())

listChildren() can materialize the child collection before yielding; these loop caps bound output, not the query or memory. Prefer paged getObjects() with project, dataset, or plate filters for large containers. countChildren() can help plan a cap but does not replace one. A count may change before retrieval.

For a direct dataset image query, prefer a server filter:

images = conn.getObjects(
    "Image",
    opts={
        "dataset": dataset_id,
        "limit": 50,
        "offset": 0,
        "order_by": "obj.id",
    },
)
Raw lines 158 to 199
200## Screening Data
202Bound each hierarchy level:
204```python
205plate = conn.getObject("Plate", plate_id)
206if plate is None:
207 raise LookupError("Plate unavailable")
209for well_index, well in enumerate(plate.listChildren()):
210 if well_index >= 96:
211 break
212 print(well.getId())
214 field_count = min(well.countWellSample(), 10)
215 for field_index in range(field_count):
216 image = well.getImage(field_index)
217 if image is not None:
218 print(image.getId())
219```
221A Well may load all WellSamples before `countWellSample()` or `getImage()`
222returns. The field cap above limits output, not the loaded graph.
224Well rows/columns and field counts can reveal experiment design. Include them
225only when requested.

Screening Data

Bound each hierarchy level:

plate = conn.getObject("Plate", plate_id)
if plate is None:
    raise LookupError("Plate unavailable")

for well_index, well in enumerate(plate.listChildren()):
    if well_index >= 96:
        break
    print(well.getId())

    field_count = min(well.countWellSample(), 10)
    for field_index in range(field_count):
        image = well.getImage(field_index)
        if image is not None:
            print(image.getId())

A Well may load all WellSamples before countWellSample() or getImage() returns. The field cap above limits output, not the loaded graph.

Well rows/columns and field counts can reveal experiment design. Include them only when requested.

Raw lines 200 to 226
227## Image Metadata
229Basic dimensions do not retrieve pixel planes:
231```python
232summary = {
233 "id": image.getId(),
234 "size_x": image.getSizeX(),
235 "size_y": image.getSizeY(),
236 "size_z": image.getSizeZ(),
237 "size_c": image.getSizeC(),
238 "size_t": image.getSizeT(),
239 "pixels_type": image.getPixelsType(),
241```
243Physical sizes may be absent:
245```python
246size_x = image.getPixelSizeX(units=True)
247if size_x is not None:
248 print(size_x.getValue(), size_x.getSymbol())
249```
251Names, descriptions, acquisition dates, owner names, group names, and channel
252labels are potentially sensitive metadata. Redact by default in broad reports.

Image Metadata

Basic dimensions do not retrieve pixel planes:

summary = {
    "id": image.getId(),
    "size_x": image.getSizeX(),
    "size_y": image.getSizeY(),
    "size_z": image.getSizeZ(),
    "size_c": image.getSizeC(),
    "size_t": image.getSizeT(),
    "pixels_type": image.getPixelsType(),
}

Physical sizes may be absent:

size_x = image.getPixelSizeX(units=True)
if size_x is not None:
    print(size_x.getValue(), size_x.getSymbol())

Names, descriptions, acquisition dates, owner names, group names, and channel labels are potentially sensitive metadata. Redact by default in broad reports.

Raw lines 227 to 253
254## Filesets and Original Files
256A fileset groups original imported files and may represent several images.
257Inspect metadata before downloading:
259```python
260fileset = image.getFileset()
261if fileset is not None:
262 print(fileset.getId())
263```
265Downloading an `Image` or `Fileset` may retrieve several original files and
266their directory structure. Estimate scope first; never use a container-wide
267download merely because it is convenient.
269The current CLI supports:
271```bash
272# One OriginalFile:
273omero download OriginalFile:123 ./explicit-local-file
275# Original files linked to one image:
276omero download Image:123 ./explicit-empty-directory
278# Original files in one fileset:
279omero download Fileset:456 ./explicit-empty-directory
280```
282The current `omero download` plugin sets cross-group context internally for
283Image/Fileset lookups. Verify the selected object’s group before using it; the
284CLI session group alone does not constrain these lookups.
286Authenticate through an already prompted CLI session. Do not add `-w`,
287`--password`, or `-k` to reusable command text. Reject symlinked destinations
288and collisions; never derive a local path directly from an untrusted remote
289filename.

Filesets and Original Files

A fileset groups original imported files and may represent several images. Inspect metadata before downloading:

fileset = image.getFileset()
if fileset is not None:
    print(fileset.getId())

Downloading an Image or Fileset may retrieve several original files and their directory structure. Estimate scope first; never use a container-wide download merely because it is convenient.

The current CLI supports:

# One OriginalFile:
omero download OriginalFile:123 ./explicit-local-file

# Original files linked to one image:
omero download Image:123 ./explicit-empty-directory

# Original files in one fileset:
omero download Fileset:456 ./explicit-empty-directory

The current omero download plugin sets cross-group context internally for Image/Fileset lookups. Verify the selected object’s group before using it; the CLI session group alone does not constrain these lookups.

Authenticate through an already prompted CLI session. Do not add -w, --password, or -k to reusable command text. Reject symlinked destinations and collisions; never derive a local path directly from an untrusted remote filename.

Raw lines 254 to 290
291## Import Planning and Import
293The OMERO importer can scan without a running server:
295```bash
296omero import -f ./explicit-input
297omero import --depth 4 -f ./explicit-directory
298```
300`-f` lists files that would be imported, grouped into filesets, then exits.
301This is the correct first pass; it is not a remote import.
303The bundled local planner is even more conservative and does not invoke OMERO:
305```bash
306python -B scripts/plan_transfer.py import \
307 --target Dataset:id:42 \
308 --max-files 100 \
309 ./explicit-input
310```
312After review and a prompted `omero login`, an actual scoped import is:
314```bash
315omero import -T Dataset:id:42 ./explicit-input
316```
318Important:
320- The target must be in the current session group.
321- Import needs compatible importer Java libraries; set `OMERODIR` to the
322 matching extracted server distribution.
323- `--parallel-fileset` and `--parallel-upload` are documented as experimental;
324 high values can crash the client or make the server unresponsive.
325- `--report --upload` can send broken source files and logs to the OME team.
326 Never use it without explicit authorization to disclose that data.
327- In-place imports change repository assumptions and are administrator
328 workflows, not a routine client optimization.

Import Planning and Import

The OMERO importer can scan without a running server:

omero import -f ./explicit-input
omero import --depth 4 -f ./explicit-directory

-f lists files that would be imported, grouped into filesets, then exits. This is the correct first pass; it is not a remote import.

The bundled local planner is even more conservative and does not invoke OMERO:

python -B scripts/plan_transfer.py import \
  --target Dataset:id:42 \
  --max-files 100 \
  ./explicit-input

After review and a prompted omero login, an actual scoped import is:

omero import -T Dataset:id:42 ./explicit-input

Important:

  • The target must be in the current session group.
  • Import needs compatible importer Java libraries; set OMERODIR to the matching extracted server distribution.
  • --parallel-fileset and --parallel-upload are documented as experimental; high values can crash the client or make the server unresponsive.
  • --report --upload can send broken source files and logs to the OME team. Never use it without explicit authorization to disclose that data.
  • In-place imports change repository assumptions and are administrator workflows, not a routine client optimization.
Raw lines 291 to 329
Runs code scripts/plan_transfer.py :306
330## OME-TIFF and XML Export
332The documented `omero export` command currently supports:
334```bash
335omero export --file ./image-123.ome.tiff Image:123
336omero export --file ./image-123.ome.xml --type XML Image:123
337```
339This is not the same as downloading original files:
341- export serializes an OMERO image as OME-TIFF or its metadata as XML;
342- download retrieves original files associated with an OriginalFile,
343 FileAnnotation, Image, or Fileset.
345Dataset iteration exists only as an experimental export mode. Do not use it
346for broad exports by default. Plan explicit image IDs instead:
348```bash
349python -B scripts/plan_transfer.py export \
350 --format ome-tiff \
351 --output-dir ./reviewed-output \
352 Image:123 Image:124
353```
355The planner does not connect or export. Review file collisions, image count,
356and available storage before running each proposed command.

OME-TIFF and XML Export

The documented omero export command currently supports:

omero export --file ./image-123.ome.tiff Image:123
omero export --file ./image-123.ome.xml --type XML Image:123

This is not the same as downloading original files:

  • export serializes an OMERO image as OME-TIFF or its metadata as XML;
  • download retrieves original files associated with an OriginalFile, FileAnnotation, Image, or Fileset.

Dataset iteration exists only as an experimental export mode. Do not use it for broad exports by default. Plan explicit image IDs instead:

python -B scripts/plan_transfer.py export \
  --format ome-tiff \
  --output-dir ./reviewed-output \
  Image:123 Image:124

The planner does not connect or export. Review file collisions, image count, and available storage before running each proposed command.

Raw lines 330 to 357
Runs code scripts/plan_transfer.py :349
358## Transfer Checklist
360Before any import, export, or download:
3621. Confirm current session group.
3632. Confirm explicit source paths or object IDs.
3643. Cap file/object count and directory scan depth.
3654. Distinguish derived OME-TIFF/XML export from original-file download.
3665. Estimate bytes and review data-sharing authorization.
3676. Use a dedicated existing output directory with no symlinks/collisions.
3687. Never use credential flags.
3698. Do not upload diagnostics or broken files without separate consent.

Transfer Checklist

Before any import, export, or download:

  1. Confirm current session group.
  2. Confirm explicit source paths or object IDs.
  3. Cap file/object count and directory scan depth.
  4. Distinguish derived OME-TIFF/XML export from original-file download.
  5. Estimate bytes and review data-sharing authorization.
  6. Use a dedicated existing output directory with no symlinks/collisions.
  7. Never use credential flags.
  8. Do not upload diagnostics or broken files without separate consent.
Raw lines 358 to 369