Skip to content

Commit

Permalink
Support labels in OME-Zarr HCS
Browse files Browse the repository at this point in the history
  • Loading branch information
tischi committed Nov 28, 2023
1 parent d279089 commit 5c2576f
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 26 deletions.
6 changes: 3 additions & 3 deletions src/main/java/org/embl/mobie/MoBIE.java
Original file line number Diff line number Diff line change
Expand Up @@ -728,17 +728,17 @@ private void initDataSource( DataSource dataSource, String log )
{
// the whole plate is already initialised as one big SpimData
// note that channel <=> setupID
return new SpimDataImage( site.getSpimData(), site.channel, name, false );
return new SpimDataImage( site.getSpimData(), site.channelIndex, name, false );
}

if ( site.getImageDataFormat().equals( ImageDataFormat.OmeZarr ) )
{
return new SpimDataImage( ImageDataFormat.OmeZarr, site.absolutePath, site.channel, name, ThreadHelper.sharedQueue, false );
return new SpimDataImage( ImageDataFormat.OmeZarr, site.absolutePath, site.channelIndex, name, ThreadHelper.sharedQueue, false );
}

if ( site.getImageDataFormat().equals( ImageDataFormat.OmeZarrS3 ) )
{
return new SpimDataImage( ImageDataFormat.OmeZarrS3, site.absolutePath, site.channel, name, ThreadHelper.sharedQueue, false );
return new SpimDataImage( ImageDataFormat.OmeZarrS3, site.absolutePath, site.channelIndex, name, ThreadHelper.sharedQueue, false );
}

return new SpimDataImage( site, name, ThreadHelper.sharedQueue );
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/org/embl/mobie/lib/hcs/Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ public class Channel
private final String name;
private String color;
private double[] contrastLimits;
private final int channelIndex;

public Channel( String name )
public Channel( String name, int channelIndex )
{
this.name = name;
this.channelIndex = channelIndex; // main use-case is loading from multi-channel files
}

public String getColor()
Expand All @@ -63,4 +65,9 @@ public String getName()
{
return name;
}

public int getChannelIndex()
{
return channelIndex;
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/embl/mobie/lib/hcs/HCSDataAdder.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public void addData( Dataset dataset )
{
// the one site is the well
//
ImageDataSource imageDataSource = createImageDataSource( channel, site, site.getId() );
ImageDataSource imageDataSource = createImageDataSource( channel, site, wellID );
dataset.addDataSource( imageDataSource );
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/embl/mobie/lib/hcs/HCSPattern.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public String getZ()
return "1";
}

public void setChannels( List< String > channels )
public void setChannelNames( List< String > channels )
{
this.channels = channels;
}
Expand Down
23 changes: 8 additions & 15 deletions src/main/java/org/embl/mobie/lib/hcs/Plate.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,14 @@
import ij.ImagePlus;
import ij.io.Opener;
import ij.measure.Calibration;
import mpicbg.spim.data.SpimDataException;
import mpicbg.spim.data.generic.AbstractSpimData;
import mpicbg.spim.data.generic.sequence.AbstractSequenceDescription;
import mpicbg.spim.data.generic.sequence.BasicViewSetup;
import mpicbg.spim.data.sequence.FinalVoxelDimensions;
import mpicbg.spim.data.sequence.ViewSetup;
import mpicbg.spim.data.sequence.VoxelDimensions;
import mpicbg.spim.data.generic.base.Entity;
import org.embl.mobie.DataStore;
import org.embl.mobie.io.ImageDataFormat;
import org.embl.mobie.io.SpimDataOpener;
import org.embl.mobie.io.toml.TPosition;
import org.embl.mobie.io.util.IOHelper;
import org.embl.mobie.lib.MoBIEHelper;
Expand All @@ -63,7 +60,6 @@
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Plate
{
Expand Down Expand Up @@ -110,7 +106,7 @@ public Plate( String hcsDirectory ) throws IOException
AbstractSpimData< ? > spimData = DataStore.fetchSpimData( firstImagePath, imageDataFormat, ThreadHelper.sharedQueue );
List< ViewSetup > viewSetupsOrdered = ( List< ViewSetup > ) spimData.getSequenceDescription().getViewSetupsOrdered();
List< String > channels = viewSetupsOrdered.stream().map( vs -> vs.getChannel().getName() ).collect( Collectors.toList() );
hcsPattern.setChannels( channels );
hcsPattern.setChannelNames( channels );
}
else
{
Expand Down Expand Up @@ -149,24 +145,22 @@ private void buildPlateMap( List< String > sitePaths )
hcsPattern.setMatcher( sitePath );

// some formats contain multiple channels in one file
List< String > channelIDs = hcsPattern.getChannels();
List< String > channelNames = hcsPattern.getChannels();

// FIXME: For labels, it can be that they are not present for all sites
// Thus the site should not be instantiated in this case.
for ( String channelName : channelIDs ) // this could also be labels
for ( String channelName : channelNames )
{
Channel channel = getChannel( channelWellSites, channelName );

if ( channel == null )
{
// configure channel properties
//
channel = new Channel( channelName );
channel = new Channel( channelName, channelNames.indexOf( channelName ) );
channelWellSites.put( channel, new HashMap<>() );

// FIXME Replace with MoBIEHelper.getMetadataFromImageFile
IJ.log( "Fetching metadata for setup " + channelName + " from " + sitePath + "..." );
ImagePlus singleChannelImagePlus = operettaMetadata == null ? openImagePlus( sitePath, channelName ) : null;
ImagePlus singleChannelImagePlus = operettaMetadata == null ? openImagePlus( sitePath, channel.getChannelIndex() ) : null;

// set channel metadata
//
Expand Down Expand Up @@ -269,7 +263,7 @@ private void buildPlateMap( List< String > sitePaths )
if ( hcsPattern.equals( hcsPattern.OMEZarr ) )
{
site.absolutePath = sitePath;
site.channel = Integer.parseInt( channelName );
site.channelIndex = channel.getChannelIndex();
}
else
{
Expand All @@ -288,7 +282,7 @@ private void buildPlateMap( List< String > sitePaths )
IJ.log( "Channels: " + channelWellSites.keySet().size() );
}

private ImagePlus openImagePlus( String path, String channelName )
private ImagePlus openImagePlus( String path, int channelID )
{
if ( this.imageDataFormat.equals( ImageDataFormat.Tiff ) )
{
Expand All @@ -298,8 +292,7 @@ private ImagePlus openImagePlus( String path, String channelName )
else if ( this.imageDataFormat.equals( ImageDataFormat.OmeZarr )
|| this.imageDataFormat.equals( ImageDataFormat.OmeZarrS3 ) )
{
final int setupID = Integer.parseInt( channelName );
return MoBIEHelper.openAsImagePlus( path, setupID, imageDataFormat );
return MoBIEHelper.openAsImagePlus( path, channelID, imageDataFormat );
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/embl/mobie/lib/hcs/Site.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ public Site( String id, ImageDataFormat imageDataFormat )
{
this.id = id;
this.imageDataFormat = imageDataFormat;
this.channel = 0;
this.channelIndex = 0;
}

public Site( String id, ImageDataFormat imageDataFormat, AbstractSpimData< ? > spimData, int imageIndex )
{
this.id = id;
this.imageDataFormat = imageDataFormat;
this.spimData = spimData;
this.channel = imageIndex;
this.channelIndex = imageIndex;
}

public String getId()
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/embl/mobie/lib/io/StorageLocation.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ public class StorageLocation
// historically, we only had fluorescence channels,
// and thus the name of the variable is "channel" and cannot
// readily be changed because we use in the MoBIE JSON spec
public Integer channel; // only for images, will default to zero if not set
public Integer channelIndex; // only for images, will default to zero if not set

public Integer getChannel()
{
return channel == null ? 0 : channel;
return channelIndex == null ? 0 : channelIndex;
}

public void setChannel( Integer channel )
{
this.channel = channel;
this.channelIndex = channel;
}
}

0 comments on commit 5c2576f

Please sign in to comment.