Skip to main content

ome-types: OME dataclasses for python

autogenerated dataclasses for a pythonic interface into the OME data model: http://www.openmicroscopy.org/Schemas/OME/2016-06

It converts the ome.xsd schema into a set of python dataclasses and types.

As an example, the OME/Image model will be rendered as the following dataclass in ome_types/model/image.py

from dataclasses import field
from datetime import datetime
from typing import List, Optional

from pydantic.dataclasses import dataclass

from .annotation_ref import AnnotationRef
from .experiment_ref import ExperimentRef
from .experimenter_group_ref import ExperimenterGroupRef
from .experimenter_ref import ExperimenterRef
from .imaging_environment import ImagingEnvironment
from .instrument_ref import InstrumentRef
from .microbeam_manipulation_ref import MicrobeamManipulationRef
from .objective_settings import ObjectiveSettings
from .pixels import Pixels
from .roi_ref import ROIRef
from .simple_types import ImageID
from .stage_label import StageLabel


@dataclass
class Image:
    id: ImageID
    pixels: Pixels
    acquisition_date: Optional[datetime] = None
    annotation_ref: List[AnnotationRef] = field(default_factory=list)
    description: Optional[str] = None
    experiment_ref: Optional[ExperimentRef] = None
    experimenter_group_ref: Optional[ExperimenterGroupRef] = None
    experimenter_ref: Optional[ExperimenterRef] = None
    imaging_environment: Optional[ImagingEnvironment] = None
    instrument_ref: Optional[InstrumentRef] = None
    microbeam_manipulation_ref: List[MicrobeamManipulationRef] = field(default_factory=list)
    name: Optional[str] = None
    objective_settings: Optional[ObjectiveSettings] = None
    roi_ref: List[ROIRef] = field(default_factory=list)
    stage_label: Optional[StageLabel] = None

ome_autogen.convert_schema(url, target) is the main function. It accepts an xsd file path (only test on an ome.xsd), and a target directory, and writes a human-readable module, that will validate OME XML, provide pythonic method naming, and provides full typing support for IDEs, etc...

Install

from pip

pip install ome-types

the autogenerated model is already included, but, to include dependencies required for re-generating the model, use the [autogen] extra

pip install ome-types[autogen]

or, to install from source

git clone https://github.com/tlambert03/ome-types.git
cd ome-types
pip install -e .

Usage

The model is not checked into source, but it is included when you pip install the package (and it will be built automatically at ome_types/model if it doesn't exist the first time you import the package.)

from ome_types import OME  # the root class

# or specific objects
from ome_types.model import Image, Pixels, Plate  # etc...

There is a convenience function that accepts xml, and outputs a validated OME model (if it fails validation, an exception is raised):

from ome_types import from_xml

metadata = from_xml(xml)

where xml in that example can be a path to a file, a URI of a resource, an opened file-like object, an Element instance, an ElementTree instance, or a literal string containing the XML data.

all attributes and variable names follow the OME data model, but camelCaseNames have been replaced with pythonic snake_case_names

Work in progress!

This is a work in progress and will absolutely need refining. Feel free to submit an issue or a PR if you try it out and have requests.

Metadata

Release files for ome-types 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ome-types 0.0.1
File Size Uploaded
ome-types-0.0.1.tar.gz 66.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ome-types 0.0.1
File Interpreter ABI Platform
ome_types-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 125.5 kB

Release files / ome-types-0.0.1.tar.gz

Download URL ome-types-0.0.1.tar.gz
Size 66.5 kB
Tags Source
SHA-256 checksum
How to use checksums
4e83fb2fd54f8d9cf1ee6ee5629923132340b85efa16f0f6559fcfaa4f95a4a8
BLAKE2b-256 checksum
How to use checksums
fcc6c30c2a2a7218dcefc99e5579c56d808eebfb92b53934e040787fa6020bb1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7

Release files / ome_types-0.0.1-py3-none-any.whl

Download URL ome_types-0.0.1-py3-none-any.whl
Size 59.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c36d4ee5a62c0870190175a7799cb9dd279a0ce5f3cd2b8f2d9a8d4eff8dc0e0
BLAKE2b-256 checksum
How to use checksums
5577ae84660c6b08dc5b6e4596e228f00969fe30df540d627d7c4c4693bbb659
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7

Release history Release notifications | RSS feed

0.6.3

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.5

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.10

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page