Skip to content

Commit

Permalink
Implement reading pixel calibration from OME-XML
Browse files Browse the repository at this point in the history
  • Loading branch information
tischi committed Mar 4, 2024
1 parent 097db94 commit 7692bf2
Show file tree
Hide file tree
Showing 28 changed files with 141 additions and 79 deletions.
14 changes: 5 additions & 9 deletions src/main/java/org/embl/mobie/MoBIE.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import loci.common.DebugTools;
import mpicbg.spim.data.generic.AbstractSpimData;
import mpicbg.spim.data.sequence.ImgLoader;
import mpicbg.spim.data.sequence.VoxelDimensions;
import net.imagej.ImageJ;
import org.embl.mobie.io.ImageDataFormat;
import org.embl.mobie.io.ome.zarr.loaders.N5OMEZarrImageLoader;
Expand Down Expand Up @@ -118,11 +119,6 @@ public class MoBIE
private HashMap< String, ImgLoader > sourceNameToImgLoader;
private final ArrayList< String > projectCommands = new ArrayList<>();

public MoBIE( String projectLocation ) throws IOException
{
this( projectLocation, new MoBIESettings() );
}

public MoBIE( String projectLocation, MoBIESettings settings ) throws IOException
{
this.settings = settings;
Expand All @@ -144,7 +140,7 @@ public static MoBIE getInstance()
return moBIE;
}

public MoBIE( String hcsDataLocation, MoBIESettings settings, double relativeWellMargin, double relativeSiteMargin ) throws IOException
public MoBIE( String hcsDataLocation, MoBIESettings settings, double relativeWellMargin, double relativeSiteMargin, @Nullable VoxelDimensions voxelDimensions ) throws IOException
{
this.settings = settings;
this.projectLocation = hcsDataLocation;
Expand All @@ -154,7 +150,7 @@ public MoBIE( String hcsDataLocation, MoBIESettings settings, double relativeWel
IJ.log("\n# MoBIE" );
IJ.log("Opening: " + hcsDataLocation );

openHCSDataset( relativeWellMargin, relativeSiteMargin );
openHCSDataset( relativeWellMargin, relativeSiteMargin, voxelDimensions );
}

public MoBIE( List< String > imagePaths, List< String > labelPaths, List< String > labelTablePaths, String root, GridType grid, MoBIESettings settings ) throws IOException
Expand Down Expand Up @@ -261,10 +257,10 @@ private void initImageJAndMoBIE()
moBIE = this;
}

private void openHCSDataset( double wellMargin, double siteMargin ) throws IOException
private void openHCSDataset( double wellMargin, double siteMargin, @Nullable VoxelDimensions voxelDimensions ) throws IOException
{
initProject( "HCS" );
final Plate plate = new Plate( projectLocation );
final Plate plate = new Plate( projectLocation, voxelDimensions );
new HCSDataAdder( plate, wellMargin, siteMargin ).addData( dataset );
initUIandShowView( dataset.views().keySet().iterator().next() );
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/embl/mobie/cmd/HCSCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public Void call() throws Exception {
.openedFromCLI( true )
.removeSpatialCalibration( removeSpatialCalibration );

new MoBIE( hcs, settings, wellMargin, siteMargin );
new MoBIE( hcs, settings, wellMargin, siteMargin, null );

return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,18 @@
*/
package org.embl.mobie.command.open;

import mpicbg.spim.data.sequence.VoxelDimensions;
import org.embl.mobie.MoBIE;
import org.embl.mobie.MoBIESettings;
import org.embl.mobie.command.CommandConstants;
import org.embl.mobie.io.util.IOHelper;
import org.embl.mobie.lib.hcs.OMEXMLParser;
import org.scijava.command.Command;
import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin;
import org.scijava.widget.Button;

import java.io.File;
import java.io.IOException;


Expand All @@ -57,16 +60,42 @@ public class OpenHCSDatasetCommand implements Command
@Parameter ( label = "Help", callback = "help")
public Button help;

public enum VoxelDimensionFetching
{
FromImageFiles,
FromOMEXML
}

@Parameter ( label = "Voxel Dimensions" )
public VoxelDimensionFetching voxelDimensionFetching = VoxelDimensionFetching.FromImageFiles;

@Parameter ( label = "OME-XML (optional)", required = false )
public File omeXML;

@Override
public void run()
{
VoxelDimensions voxelDimensions = initVoxelDimensions();

try
{
new MoBIE( hcsDirectory, new MoBIESettings(), wellMargin, siteMargin );
new MoBIE( hcsDirectory, new MoBIESettings(), wellMargin, siteMargin, voxelDimensions );
}
catch ( IOException e )
{
e.printStackTrace();
throw new RuntimeException( e );
}
}

private VoxelDimensions initVoxelDimensions()
{
if ( voxelDimensionFetching.equals( VoxelDimensionFetching.FromOMEXML ) )
{
return OMEXMLParser.readVoxelDimensions( omeXML );
}
else
{
return null;
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/embl/mobie/lib/ThreadHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ public class ThreadHelper

public static ExecutorService ioExecutorService = Executors.newFixedThreadPool( N_IO_THREADS );

public static final SharedQueue sharedQueue = new SharedQueue( N_IO_THREADS );
public static final int NUM_PRIORITIES = 6; // https://imagesc.zulipchat.com/#narrow/stream/327326-BigDataViewer/topic/SharedQueue

public static final SharedQueue sharedQueue = new SharedQueue( N_IO_THREADS, NUM_PRIORITIES );

public static ExecutorService executorService = Executors.newFixedThreadPool( N_THREADS );

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/embl/mobie/lib/hcs/OMEXMLParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@

public class OMEXMLParser
{
public static VoxelDimensions readVoxelDimensions( String filePath )
public static VoxelDimensions readVoxelDimensions( File omeXml )
{
try {
File inputFile = new File(filePath);
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(inputFile);
Document doc = dBuilder.parse(omeXml);
doc.getDocumentElement().normalize();

// Assuming VoxelDimensions is a class you have that can store these values
Expand Down
58 changes: 32 additions & 26 deletions src/main/java/org/embl/mobie/lib/hcs/Plate.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import ch.epfl.biop.bdv.img.bioformats.entity.SeriesIndex;
import org.embl.mobie.lib.hcs.omezarr.OMEZarrHCSHelper;

import javax.annotation.Nullable;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
Expand Down Expand Up @@ -82,14 +83,16 @@ public class Plate
private boolean siteIDsAreOneBased = true;
private boolean is2d = true;
private int numSlices;
private boolean fetchSpatialMetadata = true;


public Plate( String hcsDirectory ) throws IOException
public Plate( String hcsDirectory, @Nullable VoxelDimensions voxelDimensions ) throws IOException
{
this.hcsDirectory = hcsDirectory;
this.voxelDimensions = voxelDimensions;

// FIXME: fetch operetta paths from XML?!
// FIXME: fetch OME-Zarr paths entry point JSON?!
// TODO: fetch operetta paths from XML?!
// TODO: fetch OME-Zarr paths entry point JSON?!

IJ.log( "Looking for image files..." );
long start = System.currentTimeMillis();
Expand Down Expand Up @@ -217,10 +220,10 @@ private void buildPlateMap( List< String > imagePaths )
channel.setContrastLimits( contrastLimits );
}

// determine spatial metadata (for all channels the same)
//
if ( voxelDimensions == null )
if ( fetchSpatialMetadata )
{
fetchSpatialMetadata= false; // should be the same for all files and channels

if ( operettaMetadata != null )
{
voxelDimensions = operettaMetadata.getVoxelDimensions( imagePath );
Expand All @@ -230,27 +233,30 @@ private void buildPlateMap( List< String > imagePaths )
{
final Calibration calibration = singleChannelImagePlus.getCalibration();

if ( hcsPattern.hasZ() )
{
/*
If the z-positions are distributed over multiple files
typically the z-calibration metadata in the individual files is wrong.
We thus just put something sensible here such that browsing in BDV along the
z-axis is convenient
*/
voxelDimensions = new FinalVoxelDimensions(
calibration.getUnit(),
calibration.pixelWidth,
calibration.pixelHeight,
10 * calibration.pixelHeight );
}
else
if ( voxelDimensions == null )
{
voxelDimensions = new FinalVoxelDimensions(
calibration.getUnit(),
calibration.pixelWidth,
calibration.pixelHeight,
calibration.pixelDepth );
if ( hcsPattern.hasZ() )
{
/*
If the z-positions are distributed over multiple files
typically the z-calibration metadata in the individual files is wrong.
We thus just put something sensible here such that browsing in BDV along the
z-axis is convenient
*/
voxelDimensions = new FinalVoxelDimensions(
calibration.getUnit(),
calibration.pixelWidth,
calibration.pixelHeight,
10 * calibration.pixelHeight );
}
else
{
voxelDimensions = new FinalVoxelDimensions(
calibration.getUnit(),
calibration.pixelWidth,
calibration.pixelHeight,
calibration.pixelDepth );
}
}

siteDimensions = new int[]{ singleChannelImagePlus.getWidth(), singleChannelImagePlus.getHeight() };
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/develop/MergedGrid3D.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import net.imagej.ImageJ;
import org.embl.mobie.MoBIE;
import org.embl.mobie.MoBIESettings;

import java.io.IOException;

Expand All @@ -41,7 +42,7 @@ public static void main( String[] args )
imageJ.ui().showUI();

try {
new MoBIE("/Users/tischer/Downloads/example/mobie-example-project" );//.getViewManager().show( "cell-segmentation" );
new MoBIE("/Users/tischer/Downloads/example/mobie-example-project", new MoBIESettings() );//.getViewManager().show( "cell-segmentation" );
} catch ( IOException e) {
e.printStackTrace();
}
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/develop/hcs/HCS.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ public static void main( String[] args ) throws SpimDataException, IOException
{
new ImageJ().ui().showUI();

//new MoBIE( "/Users/tischer/Downloads/Operetta", new MoBIESettings(), 0.1, 0.0 );
//new MoBIE( "/Users/tischer/Downloads/Operetta", new MoBIESettings(), 0.1, 0.0, null );

//new MoBIE( "/Users/tischer/Downloads/IncuCyte", new MoBIESettings(), 0.1, 0.0 );
//new MoBIE( "/Users/tischer/Downloads/IncuCyte", new MoBIESettings(), 0.1, 0.0, null );

//new MoBIE( "/Users/tischer/Downloads/incu2/", new MoBIESettings(), 0.1, 0.0 );
//new MoBIE( "/Users/tischer/Downloads/incu2/", new MoBIESettings(), 0.1, 0.0, null );

//new MoBIE( "/g/cba/exchange/mobie-data/incucyte-drug-screen/images", new MoBIESettings(), 0.1, 0.0 );
//new MoBIE( "/g/cba/exchange/mobie-data/incucyte-drug-screen/images", new MoBIESettings(), 0.1, 0.0, null );

//new MoBIE( "/Users/tischer/Documents/faim-hcs/resources/MIP-2P-2sub/2022-07-05/1075", new MoBIESettings(), 0.1, 0.0 );
//new MoBIE( "/Users/tischer/Documents/faim-hcs/resources/MIP-2P-2sub/2022-07-05/1075", new MoBIESettings(), 0.1, 0.0, null );

new MoBIE( "/Volumes/cba/exchange/hcs-test/Samples", new MoBIESettings(), 0.1, 0.0 );
new MoBIE( "/Volumes/cba/exchange/hcs-test/Samples", new MoBIESettings(), 0.1, 0.0, null );
}
}
2 changes: 1 addition & 1 deletion src/test/java/develop/hcs/HCSInCellAnalyzer6000.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ public static void main( String[] args ) throws SpimDataException, IOException
{
new ImageJ().ui().showUI();

new MoBIE( "/Users/tischer/Downloads/incell", new MoBIESettings(), 0.1, 0.0 );
new MoBIE( "/Users/tischer/Downloads/incell", new MoBIESettings(), 0.1, 0.0, null );
}
}
12 changes: 6 additions & 6 deletions src/test/java/develop/hcs/HCSIncuyte.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ public static void main( String[] args ) throws SpimDataException, IOException
{
new ImageJ().ui().showUI();

//new MoBIE( "/Users/tischer/Downloads/Operetta", new MoBIESettings(), 0.1, 0.0 );
//new MoBIE( "/Users/tischer/Downloads/Operetta", new MoBIESettings(), 0.1, 0.0, null );

//new MoBIE( "/Users/tischer/Downloads/IncuCyte", new MoBIESettings(), 0.1, 0.0 );
//new MoBIE( "/Users/tischer/Downloads/IncuCyte", new MoBIESettings(), 0.1, 0.0, null );

//new MoBIE( "/Users/tischer/Downloads/incu2/", new MoBIESettings(), 0.1, 0.0 );
//new MoBIE( "/Users/tischer/Downloads/incu2/", new MoBIESettings(), 0.1, 0.0, null );

//new MoBIE( "/g/cba/exchange/mobie-data/incucyte-drug-screen/images", new MoBIESettings(), 0.1, 0.0 );
//new MoBIE( "/g/cba/exchange/mobie-data/incucyte-drug-screen/images", new MoBIESettings(), 0.1, 0.0, null );

//new MoBIE( "/Users/tischer/Documents/faim-hcs/resources/MIP-2P-2sub/2022-07-05/1075", new MoBIESettings(), 0.1, 0.0 );
//new MoBIE( "/Users/tischer/Documents/faim-hcs/resources/MIP-2P-2sub/2022-07-05/1075", new MoBIESettings(), 0.1, 0.0, null );

new MoBIE( "/Volumes/cba/exchange/hcs-test/Samples", new MoBIESettings(), 0.1, 0.0 );
new MoBIE( "/Volumes/cba/exchange/hcs-test/Samples", new MoBIESettings(), 0.1, 0.0, null );
}
}
4 changes: 2 additions & 2 deletions src/test/java/develop/hcs/HCSIncuyteRaw.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class HCSIncuyteRaw
public static void main( String[] args ) throws SpimDataException, IOException
{
new ImageJ().ui().showUI();
//new MoBIE( "/Users/tischer/Downloads/incu-test-data/2207/19", new MoBIESettings(), 0.1, 0.0 );
new MoBIE( "https://s3.embl.de/i2k-2020/incu-test-data/2207/19", new MoBIESettings(), 0.1, 0.0 );
//new MoBIE( "/Users/tischer/Downloads/incu-test-data/2207/19", new MoBIESettings(), 0.1, 0.0, null );
new MoBIE( "https://s3.embl.de/i2k-2020/incu-test-data/2207/19", new MoBIESettings(), 0.1, 0.0, null );
}
}
6 changes: 3 additions & 3 deletions src/test/java/develop/hcs/HCSOMEZarr.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public static void main( String[] args ) throws SpimDataException, IOException
{
new ImageJ().ui().showUI();

//new MoBIE( "/Volumes/cba/exchange/ome-zarr/bugra/HCS/testdata.zarr", new MoBIESettings(), 0.1, 0.0 );
//new MoBIE( "/Users/tischer/Downloads/20200812-CardiomyocyteDifferentiation14-Cycle1.zarr", new MoBIESettings(), 0.1, 0.0 );
new MoBIE( "/Users/tischer/Downloads/test-plate.zarr", new MoBIESettings(), 0.1, 0.0 );
//new MoBIE( "/Volumes/cba/exchange/ome-zarr/bugra/HCS/testdata.zarr", new MoBIESettings(), 0.1, 0.0, null );
//new MoBIE( "/Users/tischer/Downloads/20200812-CardiomyocyteDifferentiation14-Cycle1.zarr", new MoBIESettings(), 0.1, 0.0, null );
new MoBIE( "/Users/tischer/Downloads/test-plate.zarr", new MoBIESettings(), 0.1, 0.0, null );
}
}
6 changes: 3 additions & 3 deletions src/test/java/develop/hcs/HCSOMEZarrS3.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public static void main( String[] args ) throws SpimDataException, IOException
{
new ImageJ().ui().showUI();

//new MoBIE( "https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.1/plates/5966.zarr", new MoBIESettings(), 0.1, 0.0 );
//new MoBIE( "https://radosgw.public.os2.wwu.de/ngff/test.zarr", new MoBIESettings(), 0.1, 0.0 );
new MoBIE( "https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.1/plates/2551.zarr", new MoBIESettings(), 0.1, 0.0 );
//new MoBIE( "https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.1/plates/5966.zarr", new MoBIESettings(), 0.1, 0.0, null );
//new MoBIE( "https://radosgw.public.os2.wwu.de/ngff/test.zarr", new MoBIESettings(), 0.1, 0.0, null );
new MoBIE( "https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.1/plates/2551.zarr", new MoBIESettings(), 0.1, 0.0, null );
}
}
2 changes: 1 addition & 1 deletion src/test/java/develop/hcs/HCSOperetta4.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ class HCSOperetta4
public static void main( String[] args ) throws SpimDataException, IOException
{
new ImageJ().ui().showUI();
new MoBIE( "/Volumes/cba/exchange/hcs-test/operetta4/Samples", new MoBIESettings(), 0.1, 0.0 );
new MoBIE( "/Volumes/cba/exchange/hcs-test/operetta4/Samples", new MoBIESettings(), 0.1, 0.0, null );
}
}
2 changes: 1 addition & 1 deletion src/test/java/develop/hcs/HCSOperetta5.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ class HCSOperetta5
public static void main( String[] args ) throws SpimDataException, IOException
{
new ImageJ().ui().showUI();
new MoBIE( "/Volumes/cba/exchange/hcs-test/operetta5/CLSsamples", new MoBIESettings(), 0.1, 0.0 );
new MoBIE( "/Volumes/cba/exchange/hcs-test/operetta5/CLSsamples", new MoBIESettings(), 0.1, 0.0, null );
}
}
2 changes: 1 addition & 1 deletion src/test/java/develop/hcs/HCSYokogawaCQ1.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ public static void main( String[] args ) throws SpimDataException, IOException
new MoBIE( "/Users/tischer/Desktop/moritz/CQ1_testfiles",
new MoBIESettings().removeSpatialCalibration( true ), // TODO: what is the z-spacing, how to add this?
0.1,
0.0 );
0.0, null );
}
}
3 changes: 2 additions & 1 deletion src/test/java/projects/OpenLocalJulianNoTables.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import net.imagej.ImageJ;
import org.embl.mobie.MoBIE;
import org.embl.mobie.MoBIESettings;

import java.io.IOException;

Expand All @@ -39,7 +40,7 @@ public static void main( String[] args ) throws IOException
{
final ImageJ imageJ = new ImageJ();
imageJ.ui().showUI();
final MoBIE moBIE = new MoBIE("/Volumes/emcf/hennies/for_constantin/mobie_no_table_test/" );
final MoBIE moBIE = new MoBIE("/Volumes/emcf/hennies/for_constantin/mobie_no_table_test/", new MoBIESettings() );
moBIE.getViewManager().show( "seg-test" );
}
}
Loading

0 comments on commit 7692bf2

Please sign in to comment.