Skip to content

Commit

Permalink
FakeReader: add support for populating instrument metadata
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sbesson committed Feb 6, 2025
1 parent 1f3a5e3 commit 0f47e17
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
13 changes: 13 additions & 0 deletions components/formats-bsd/src/loci/formats/in/FakeReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ protected void initFile(String id) throws FormatException, IOException {
boolean metadataComplete = true;
boolean thumbnail = false;
boolean withMicrobeam = false;
boolean withInstrument = false;

int seriesCount = 1;
int resolutionCount = 1;
Expand Down Expand Up @@ -720,6 +721,7 @@ else if (key.equals("pixelType")) {
else if (key.equals("fields")) fields = intValue;
else if (key.equals("plateAcqs")) plateAcqs = intValue;
else if (key.equals("withMicrobeam")) withMicrobeam = boolValue;
else if (key.equals("withInstrument")) withInstrument = boolValue;
else if (key.equals("annLong")) annLong = intValue;
else if (key.equals("annDouble")) annDouble = intValue;
else if (key.equals("annMap")) annMap = intValue;
Expand Down Expand Up @@ -852,6 +854,8 @@ else if (dimOrder == null) {
populateSPW(store, screens, plates, plateRows, plateCols, fields, plateAcqs, withMicrobeam);
if (imageCount > 0) seriesCount = imageCount;
else hasSPW = false; // failed to generate SPW metadata
} else if (withInstrument) {
populateInstrument(store);
}

// populate core metadata
Expand Down Expand Up @@ -1400,6 +1404,15 @@ private int populateSPW(MetadataStore store, int screens, int plates, int rows,
return ome.sizeOfImageList();
}

private void populateInstrument(MetadataStore store)
{
final XMLMockObjects xml = new XMLMockObjects();
OME ome = xml.getRoot();
ome.addInstrument(xml.createInstrument(true));
getOmeXmlMetadata().setRoot(new OMEXMLMetadataRoot(ome));
getOmeXmlService().convertMetadata(omeXmlMetadata, store);
}

/** Creates a mapping between indices and color values. */
private void createIndexMap(int num) {
int sizeC = core.get(0).sizeC;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -761,4 +761,13 @@ public void testEmissionWavelengths() throws Exception {
assertEquals(m.getChannelEmissionWavelength(0, 4), new Length(5020.0, UNITS.ANGSTROM));
reader.close();
}

@Test
public void testInstrument() throws Exception {
reader.setId("test&withInstrument=true.fake");
m = service.asRetrieve(reader.getMetadataStore());
assertTrue(service.validateOMEXML(service.getOMEXML(m)));
assertEquals(m.getInstrumentCount(), 1);
reader.close();
}
}

0 comments on commit 0f47e17

Please sign in to comment.