Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FakeReader: add support for populating channel wavelengths and instrument #4272

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

sbesson
Copy link
Member

@sbesson sbesson commented Feb 6, 2025

See discussion at ome/omero-py#443

This extends the FakeReader logic to be able to populate additional metadata:

  • channel wavelengths (both emission & excitation): using a set of channel specific keys similar to how channel colors and channel names are set
  • instrument: using a single boolean withInstrument key

With these changes, the following fake file should include channel wavelengths and an instrument

showinf "test&sizeC=3&emission_0=457nm&emission_1=528nm&excitation_0=360nm&excitation_1=490nm&withInstrument=true.fake" -omexml-only -nopix 

Up for discussion is the naming of the wavelength key as we have a mixture of supported styles - see https://bio-formats.readthedocs.io/en/latest/developers/generating-test-images.html#key-value-pairs. I started with a minimal version, alternatives would be:

  • emissionWavelength_x / excitationWavelength_x (like physicalSizeX)
  • EmissionWavelength_x / ExcitationWavelength_x (like PositionX_x)
  • ChannelEmissionWavelength_x / ChannelExcitationWavelength_x (like ChannelName_x)

Similarly to channel colors, this introduces new indexed key/value
pairs allowing to fill arrays and set the emission and excitation
wavelength of the channels in the OME metadata
This metadata is already populated in the case of SPW fake files.
Adds a new boolean key withInstrument allowing to use
XMLMockObjects.createInstrument() to add an instrument to the
OME metadata
@jburel
Copy link
Member

jburel commented Feb 6, 2025

I ran several tests successfully

No unit

./showinf "test&sizeC=3&emission_0=457nm&emission_1=528nm&excitation_0=360nm&excitation_1=490&withInstrument=true.fake" -omexml-only -nopix  
<?xml version="1.0" encoding="UTF-8"?>
<OME xmlns="http://www.openmicroscopy.org/Schemas/OME/2016-06" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openmicroscopy.org/Schemas/OME/2016-06 http://www.openmicroscopy.org/Schemas/OME/2016-06/ome.xsd">
   <Instrument ID="Instrument:0">
      <Microscope LotNumber="9876543210" Manufacturer="Manufacturer" Model="Model" SerialNumber="0123456789" Type="Upright"/>
      <Laser FrequencyMultiplication="30" ID="LightSource:0" LaserMedium="Alexandrite" LotNumber="9876543210" Manufacturer="Manufacturer" Model="Model" PockelCell="false" Power="200.0" PowerUnit="mW" RepetitionRate="30.0" RepetitionRateUnit="aHz" SerialNumber="0123456789" Tuneable="false" Type="Dye" Wavelength="200.0" WavelengthUnit="nm"/>
      <Arc ID="LightSource:1" LotNumber="9876543210" Manufacturer="Manufacturer" Model="Model" Power="200.0" PowerUnit="mW" SerialNumber="0123456789" Type="HgXe"/>
      <Filament ID="LightSource:2" LotNumber="9876543210" Manufacturer="Manufacturer" Model="Model" Power="200.0" PowerUnit="mW" SerialNumber="0123456789" Type="Halogen"/>
      <LightEmittingDiode ID="LightSource:3" LotNumber="9876543210" Manufacturer="Manufacturer" Model="Model" Power="200.0" PowerUnit="mW" SerialNumber="0123456789"/>
      <Laser FrequencyMultiplication="30" ID="LightSource:4" LaserMedium="Alexandrite" LotNumber="9876543210" Manufacturer="Manufacturer" Model="Model" PockelCell="false" Power="200.0" PowerUnit="mW" RepetitionRate="30.0" RepetitionRateUnit="aHz" SerialNumber="0123456789" Tuneable="false" Type="Dye" Wavelength="200.0" WavelengthUnit="nm"/>
      <Detector AmplificationGain="0.0" Gain="1.0" ID="Detector:0" LotNumber="9876543210" Manufacturer="Manufacturer" Model="Model" Offset="2.0" SerialNumber="0123456789" Type="CCD" Voltage="100" VoltageUnit="V" Zoom="3.0"/>
      <Objective CalibratedMagnification="1.0" Correction="UV" ID="Objective:0" Immersion="Oil" Iris="true" LensNA="0.5" LotNumber="9876543210" Manufacturer="Manufacturer" Model="Model" NominalMagnification="1.5" SerialNumber="0123456789" WorkingDistance="1.0" WorkingDistanceUnit="µm"/>
      <FilterSet ID="FilterSet:0" LotNumber="9876543210" Manufacturer="Manufacturer" Model="Model" SerialNumber="0123456789"/>
      <Filter ID="Filter:0" LotNumber="9876543210" Manufacturer="Manufacturer" Model="Model" SerialNumber="0123456789" Type="LongPass">
         <TransmittanceRange CutIn="200.0" CutInTolerance="1.0" CutInToleranceUnit="nm" CutInUnit="nm" CutOut="300.0" CutOutTolerance="1.0" CutOutToleranceUnit="nm" CutOutUnit="nm" Transmittance="0.5"/>
      </Filter>
      <Filter ID="Filter:1" LotNumber="9876543210" Manufacturer="Manufacturer" Model="Model" SerialNumber="0123456789" Type="LongPass">
         <TransmittanceRange CutIn="200.0" CutInTolerance="1.0" CutInToleranceUnit="nm" CutInUnit="nm" CutOut="300.0" CutOutTolerance="1.0" CutOutToleranceUnit="nm" CutOutUnit="nm" Transmittance="0.5"/>
      </Filter>
      <Dichroic ID="Dichroic:0" LotNumber="9876543210" Manufacturer="Manufacturer" Model="Model" SerialNumber="0123456789"/>
   </Instrument>
   <Image ID="Image:0" Name="test">
      <Pixels BigEndian="false" DimensionOrder="XYZCT" ID="Pixels:0" Interleaved="false" SignificantBits="8" SizeC="3" SizeT="1" SizeX="512" SizeY="512" SizeZ="1" Type="uint8">
         <Channel EmissionWavelength="457.0" EmissionWavelengthUnit="nm" ExcitationWavelength="360.0" ExcitationWavelengthUnit="nm" ID="Channel:0:0" SamplesPerPixel="1">
            <LightPath/>
         </Channel>
         <Channel EmissionWavelength="528.0" EmissionWavelengthUnit="nm" ExcitationWavelength="490.0" ExcitationWavelengthUnit="nm" ID="Channel:0:1" SamplesPerPixel="1">
            <LightPath/>
         </Channel>
         <Channel ID="Channel:0:2" SamplesPerPixel="1">
            <LightPath/>
         </Channel>
         <MetadataOnly/>
      </Pixels>
   </Image>
</OME>

Different unit

./showinf "test&sizeC=3&emission_0=457nm&emission_1=528nm&excitation_0=360nm&excitation_1=490Å&withInstrument=true.fake" -omexml-only -nopix 
<?xml version="1.0" encoding="UTF-8"?>
<OME xmlns="http://www.openmicroscopy.org/Schemas/OME/2016-06" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openmicroscopy.org/Schemas/OME/2016-06 http://www.openmicroscopy.org/Schemas/OME/2016-06/ome.xsd">
   <Instrument ID="Instrument:0">
      <Microscope LotNumber="9876543210" Manufacturer="Manufacturer" Model="Model" SerialNumber="0123456789" Type="Upright"/>
      <Laser FrequencyMultiplication="30" ID="LightSource:0" LaserMedium="Alexandrite" LotNumber="9876543210" Manufacturer="Manufacturer" Model="Model" PockelCell="false" Power="200.0" PowerUnit="mW" RepetitionRate="30.0" RepetitionRateUnit="aHz" SerialNumber="0123456789" Tuneable="false" Type="Dye" Wavelength="200.0" WavelengthUnit="nm"/>
      <Arc ID="LightSource:1" LotNumber="9876543210" Manufacturer="Manufacturer" Model="Model" Power="200.0" PowerUnit="mW" SerialNumber="0123456789" Type="HgXe"/>
      <Filament ID="LightSource:2" LotNumber="9876543210" Manufacturer="Manufacturer" Model="Model" Power="200.0" PowerUnit="mW" SerialNumber="0123456789" Type="Halogen"/>
      <LightEmittingDiode ID="LightSource:3" LotNumber="9876543210" Manufacturer="Manufacturer" Model="Model" Power="200.0" PowerUnit="mW" SerialNumber="0123456789"/>
      <Laser FrequencyMultiplication="30" ID="LightSource:4" LaserMedium="Alexandrite" LotNumber="9876543210" Manufacturer="Manufacturer" Model="Model" PockelCell="false" Power="200.0" PowerUnit="mW" RepetitionRate="30.0" RepetitionRateUnit="aHz" SerialNumber="0123456789" Tuneable="false" Type="Dye" Wavelength="200.0" WavelengthUnit="nm"/>
      <Detector AmplificationGain="0.0" Gain="1.0" ID="Detector:0" LotNumber="9876543210" Manufacturer="Manufacturer" Model="Model" Offset="2.0" SerialNumber="0123456789" Type="CCD" Voltage="100" VoltageUnit="V" Zoom="3.0"/>
      <Objective CalibratedMagnification="1.0" Correction="UV" ID="Objective:0" Immersion="Oil" Iris="true" LensNA="0.5" LotNumber="9876543210" Manufacturer="Manufacturer" Model="Model" NominalMagnification="1.5" SerialNumber="0123456789" WorkingDistance="1.0" WorkingDistanceUnit="µm"/>
      <FilterSet ID="FilterSet:0" LotNumber="9876543210" Manufacturer="Manufacturer" Model="Model" SerialNumber="0123456789"/>
      <Filter ID="Filter:0" LotNumber="9876543210" Manufacturer="Manufacturer" Model="Model" SerialNumber="0123456789" Type="LongPass">
         <TransmittanceRange CutIn="200.0" CutInTolerance="1.0" CutInToleranceUnit="nm" CutInUnit="nm" CutOut="300.0" CutOutTolerance="1.0" CutOutToleranceUnit="nm" CutOutUnit="nm" Transmittance="0.5"/>
      </Filter>
      <Filter ID="Filter:1" LotNumber="9876543210" Manufacturer="Manufacturer" Model="Model" SerialNumber="0123456789" Type="LongPass">
         <TransmittanceRange CutIn="200.0" CutInTolerance="1.0" CutInToleranceUnit="nm" CutInUnit="nm" CutOut="300.0" CutOutTolerance="1.0" CutOutToleranceUnit="nm" CutOutUnit="nm" Transmittance="0.5"/>
      </Filter>
      <Dichroic ID="Dichroic:0" LotNumber="9876543210" Manufacturer="Manufacturer" Model="Model" SerialNumber="0123456789"/>
   </Instrument>
   <Image ID="Image:0" Name="test">
      <Pixels BigEndian="false" DimensionOrder="XYZCT" ID="Pixels:0" Interleaved="false" SignificantBits="8" SizeC="3" SizeT="1" SizeX="512" SizeY="512" SizeZ="1" Type="uint8">
         <Channel EmissionWavelength="457.0" EmissionWavelengthUnit="nm" ExcitationWavelength="360.0" ExcitationWavelengthUnit="nm" ID="Channel:0:0" SamplesPerPixel="1">
            <LightPath/>
         </Channel>
         <Channel EmissionWavelength="528.0" EmissionWavelengthUnit="nm" ExcitationWavelength="490.0" ExcitationWavelengthUnit="Å" ID="Channel:0:1" SamplesPerPixel="1">
            <LightPath/>
         </Channel>
         <Channel ID="Channel:0:2" SamplesPerPixel="1">
            <LightPath/>
         </Channel>
         <MetadataOnly/>
      </Pixels>
   </Image>
</OME>

Invalid unit

./showinf "test&sizeC=3&emission_0=457nm&emission_1=528nm&excitation_0=360nm&excitation_1=490kkk&withInstrument=true.fake" -omexml-only -nopix 
Exception in thread "main" java.lang.RuntimeException: Invalid wavelength: 490kkk
	at loci.formats.in.FakeReader.parseWavelength(FakeReader.java:1527)
	at loci.formats.in.FakeReader.initFile(FakeReader.java:776)
	at loci.formats.FormatReader.setId(FormatReader.java:1480)
	at loci.formats.ImageReader.setId(ImageReader.java:864)
	at loci.formats.ReaderWrapper.setId(ReaderWrapper.java:692)
	at loci.formats.tools.ImageInfo.testRead(ImageInfo.java:1048)
	at loci.formats.tools.ImageInfo.main(ImageInfo.java:1159)

invalid value

./showinf "test&sizeC=3&emission_0=457nm&emission_1=528nm&excitation_0=360nm&excitation_1=-10k&withInstrument=true.fake" -omexml-only -nopix 
Exception in thread "main" java.lang.RuntimeException: Invalid wavelength: -10k
	at loci.formats.in.FakeReader.parseWavelength(FakeReader.java:1527)
	at loci.formats.in.FakeReader.initFile(FakeReader.java:776)
	at loci.formats.FormatReader.setId(FormatReader.java:1480)
	at loci.formats.ImageReader.setId(ImageReader.java:864)
	at loci.formats.ReaderWrapper.setId(ReaderWrapper.java:692)
	at loci.formats.tools.ImageInfo.testRead(ImageInfo.java:1048)
	at loci.formats.tools.ImageInfo.main(ImageInfo.java:1159)

@jburel
Copy link
Member

jburel commented Feb 6, 2025

Due to the number of parameters potentially added to generate a fake file, I will vote to keep the name as short as possible while being clear. The current keys used are explicit enough

@jburel
Copy link
Member

jburel commented Feb 6, 2025

Without instrument (default is false)

./showinf "test&sizeC=3&emission_0=457nm&emission_1=528nm&excitation_0=360nm&excitation_1=20km&withInstrument=false.fake" -omexml-only -nopix 
<?xml version="1.0" encoding="UTF-8"?>
<OME xmlns="http://www.openmicroscopy.org/Schemas/OME/2016-06" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openmicroscopy.org/Schemas/OME/2016-06 http://www.openmicroscopy.org/Schemas/OME/2016-06/ome.xsd">
   <Image ID="Image:0" Name="test">
      <Pixels BigEndian="false" DimensionOrder="XYZCT" ID="Pixels:0" Interleaved="false" SignificantBits="8" SizeC="3" SizeT="1" SizeX="512" SizeY="512" SizeZ="1" Type="uint8">
         <Channel EmissionWavelength="457.0" EmissionWavelengthUnit="nm" ExcitationWavelength="360.0" ExcitationWavelengthUnit="nm" ID="Channel:0:0" SamplesPerPixel="1">
            <LightPath/>
         </Channel>
         <Channel EmissionWavelength="528.0" EmissionWavelengthUnit="nm" ExcitationWavelength="20.0" ExcitationWavelengthUnit="km" ID="Channel:0:1" SamplesPerPixel="1">
            <LightPath/>
         </Channel>
         <Channel ID="Channel:0:2" SamplesPerPixel="1">
            <LightPath/>
         </Channel>
         <MetadataOnly/>
      </Pixels>
   </Image>
</OME>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants