Package: ome-types
ome-typesA pure-python implementation of the OME data modelome_typesprovides a set of python dataclasses and utility functions for
parsing theOME-XML
formatinto
fully-typed python objects for interactive or programmatic access in python. It
can also take these python objects and output them into valid OME-XML.ome_typesis apure pythonlibrary and does not require a Java virtual
machine.Note: The generated python code can be seen in thebuiltbranch.
(Read thecode generationsection for details).📖documentationInstallationfrom pippipinstallome-typesWith all optional dependencies:# lxml => if you ...#           - want to use lxml as the XML parser#           - want to validate XML against the ome.xsd schema#           - want to use XML documents older than the 2016-06 schema# pint      => if you want to use object.<field>_quantity properties# xmlschema => if you want to validate XML but DON'T want lxmlpipinstallome-types[lxml,pint]from condacondainstall-cconda-forgeome-typesfrom github (bleeding edge dev version)pipinstallgit+https://github.com/tlambert03/ome-types.gitUsageconvert an XML string or filepath into an instance ofome_types.model.OME(The XML string/file will be validated against theome.xsd
schema)fromome_typesimportfrom_xmlome=from_xml('tests/data/hcs.ome.xml')extract OME metadata from an OME-TIFFfromome_typesimportfrom_tiffome2=from_tiff('tests/data/ome.tiff')manipulate the metadata via python objectsBothfrom_xmlandfrom_tiffreturn an instance ofome_types.model.OME. All
classes inome_types.modelfollow the naming conventions of theOME data
model,
but usesnake_caseattribute names instead ofCamelCase, to be consistent
with the python ecosystem.In[2]:ome=from_xml('tests/data/hcs.ome.xml')In[3]:omeOut[3]:OME(images=[<1Images>],plates=[<1Plates>],)In[4]:ome.plates[0]Out[4]:Plate(id='Plate:1',name='Control Plate',column_naming_convention='letter',columns=12,row_naming_convention='number',rows=8,wells=[<1Wells>],)In[5]:ome.images[0]Out[5]:Image(id='Image:0',name='Series 1',pixels=Pixels(id='Pixels:0',dimension_order='XYCZT',size_c=3,size_t=16,size_x=1024,size_y=1024,size_z=1,type='uint16',bin_data=[<1Bin_Data>],channels=[<3Channels>],physical_size_x=0.207,physical_size_y=0.207,time_increment=120.1302,),acquisition_date=datetime.fromisoformat('2008-02-06T13:43:19'),description='An example OME compliant file, based on Olympus.oib',)Objects can be removed, or changedIn[6]:fromome_types.model.simple_typesimportUnitsLengthIn[7]:fromome_types.model.channelimportAcquisitionModeIn[8]:ome.images[0].description="This is the new description."In[9]:ome.images[0].pixels.physical_size_x=350.0In[10]:ome.images[0].pixels.physical_size_x_unit=UnitsLength.NANOMETERIn[11]:forcinome.images[0].pixels.channels:c.acquisition_mode=AcquisitionMode.SPINNING_DISK_CONFOCALElements can be added by constructing new OME model objectsIn[12]:fromome_types.modelimportInstrument,Microscope,Objective,InstrumentRefIn[13]:microscope_mk4=Microscope(manufacturer='OME Instruments',model='Lab Mk4',serial_number='L4-5678',)In[14]:objective_40x=Objective(manufacturer='OME Objectives',model='40xAir',nominal_magnification=40.0,)In[15]:instrument=Instrument(microscope=microscope_mk4,objectives=[objective_40x],)In[16]:ome.instruments.append(instrument)In[17]:ome.images[0].instrument_ref=InstrumentRef(id=instrument.id)In[18]:ome.instrumentsOut[18]:[Instrument(id='Instrument:1',microscope=Microscope(manufacturer='OME Instruments',model='Lab Mk4',serial_number='L4-5678',),objectives=[<1Objectives>],)]export to an OME-XML stringFinally, you can generate the OME-XML representation of the OME model object,
for writing to a standalone.ome.xmlfile or inserting into the header of an
OME-TIFF file:In[19]:fromome_typesimportto_xmlIn[20]:print(to_xml(ome))<OME...><PlateColumnNamingConvention="letter"Columns="12"ID="Plate:1"...>...</Plate><InstrumentID="Instrument:1"><MicroscopeManufacturer="OME Instruments"Model="Lab Mk4"SerialNumber="L4-5678"/><ObjectiveManufacturer="OME Objectives"Model="40xAir"ID="Objective:1"NominalMagnification="40.0"/></Instrument><ImageID="Image:0"Name="Series 1"><AcquisitionDate>2008-02-06T13:43:19</AcquisitionDate><Description>Thisisthenewdescription.</Description><InstrumentRefID="Instrument:1"/><Pixels...PhysicalSizeX="350.0"PhysicalSizeXUnit="nm"...><ChannelAcquisitionMode="SpinningDiskConfocal"...>...</Pixels></Image></OME>Code generationThe bulk of this library (namely, modules insideome_types._autogenerated) is
generated at install time, and is therefore not checked into source (or visible
in the main branch of this repo).You can see the code generated by the main branch in thebuilt
branchThe package atsrc/ome_autogenconverts theome.xsd
schemainto valid
python code. To run the code generation script in a development environment,
clone this repository and run:python-msrc.ome_autogenThe documentation and types for the full model can be in theAPI ReferenceContributingTo clone and install this repository locally:gitclonehttps://github.com/tlambert03/ome-types.gitcdome-types
pipinstall-e.[test,dev]We usepre-committo run various code-quality checks during continuous
integration. If you'd like to make sure that your code will pass these checks
before you commit your code, you should installpre-commitafter cloning this
repository:pre-commitinstallregenerating the modelsIf you modify anything insrc/ome_autogen, you may need to
regenerate the model with:python-msrc.ome_autogenRunning testsTo run tests:pytest