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

Cloud #176

Merged
merged 6 commits into from
Jul 31, 2024
Merged

Cloud #176

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.scijava</groupId>
<artifactId>pom-scijava</artifactId>
<version>37.0.0</version>
<version>38.0.1</version>
<relativePath />
</parent>

Expand Down Expand Up @@ -146,7 +146,8 @@
<imglib2.version>7.0.3</imglib2.version>
<imglib2-realtransform.version>4.0.3</imglib2-realtransform.version>
<imglib2-cache.version>1.0.0-beta-18</imglib2-cache.version>
<imglib2-algorithm.version>0.15.2</imglib2-algorithm.version>
<imglib2-algorithm.version>0.15.3</imglib2-algorithm.version>
<spim_data.version>2.3.0</spim_data.version>

<!-- NB: Deploy releases to the SciJava Maven repository. -->
<releaseProfiles>sign,deploy-to-scijava</releaseProfiles>
Expand Down
38 changes: 30 additions & 8 deletions src/main/java/bdv/img/n5/N5ImageLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -80,7 +81,7 @@

public class N5ImageLoader implements ViewerImgLoader, MultiResolutionImgLoader
{
private final File n5File;
private final URI n5URI;

// TODO: it would be good if this would not be needed
// find available setups from the n5
Expand All @@ -89,17 +90,33 @@ public class N5ImageLoader implements ViewerImgLoader, MultiResolutionImgLoader
/**
* Maps setup id to {@link SetupImgLoader}.
*/
private final Map< Integer, SetupImgLoader > setupImgLoaders = new HashMap<>();
private final Map< Integer, SetupImgLoader< ?, ? > > setupImgLoaders = new HashMap<>();

public N5ImageLoader( final File n5File, final AbstractSequenceDescription< ?, ?, ? > sequenceDescription )
public N5ImageLoader( final URI n5URI, final AbstractSequenceDescription< ?, ?, ? > sequenceDescription )
{
this.n5File = n5File;
this.n5URI = n5URI;
this.seq = sequenceDescription;
}

public N5ImageLoader( final File n5File, final AbstractSequenceDescription< ?, ?, ? > sequenceDescription )
{
this( n5File.toURI(), sequenceDescription );
}

public N5ImageLoader( final N5Reader n5Reader, final URI n5URI, final AbstractSequenceDescription< ?, ?, ? > sequenceDescription )
{
this( n5URI, sequenceDescription );
n5 = n5Reader;
}

public URI getN5URI()
{
return n5URI;
}

public File getN5File()
{
return n5File;
return new File( n5URI );
}

private volatile boolean isOpen = false;
Expand Down Expand Up @@ -134,14 +151,17 @@ private void open()

try
{
this.n5 = new N5FSReader( n5File.getAbsolutePath() );
if ( n5 == null )
{
n5 = new N5FSReader( getN5File().getAbsolutePath() );
}

int maxNumLevels = 0;
final List< ? extends BasicViewSetup > setups = seq.getViewSetupsOrdered();
for ( final BasicViewSetup setup : setups )
{
final int setupId = setup.getId();
final SetupImgLoader setupImgLoader = createSetupImgLoader( setupId );
final SetupImgLoader< ?, ? > setupImgLoader = createSetupImgLoader( setupId );
setupImgLoaders.put( setupId, setupImgLoader );
maxNumLevels = Math.max( maxNumLevels, setupImgLoader.numMipmapLevels() );
}
Expand Down Expand Up @@ -190,7 +210,7 @@ public void close()
}

@Override
public SetupImgLoader getSetupImgLoader( final int setupId )
public SetupImgLoader< ?, ? > getSetupImgLoader( final int setupId )
{
open();
return setupImgLoaders.get( setupId );
Expand Down Expand Up @@ -405,6 +425,8 @@ public A loadArray( final long[] gridPosition, final int[] cellDimensions ) thro
return new N5CacheArrayLoader<>( n5, pathName, attributes, DataTypeProperties.of( attributes.getDataType() ) );
}

// TODO: replace ndArrayCopy(...) below with new SubArrayCopy from imglib2 core ???

/**
* Like `System.arrayCopy()` but for flattened nD arrays.
*
Expand Down
50 changes: 44 additions & 6 deletions src/main/java/bdv/img/n5/XmlIoN5ImageLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,22 @@
*/
package bdv.img.n5;

import static mpicbg.spim.data.XmlKeys.IMGLOADER_FORMAT_ATTRIBUTE_NAME;

import java.io.File;
import java.net.URI;
import java.util.regex.Pattern;

import org.janelia.saalfeldlab.n5.N5FSReader;
import org.jdom2.Element;

import mpicbg.spim.data.SpimDataInstantiationException;
import mpicbg.spim.data.XmlHelpers;
import mpicbg.spim.data.generic.sequence.AbstractSequenceDescription;
import mpicbg.spim.data.generic.sequence.ImgLoaderIo;
import mpicbg.spim.data.generic.sequence.ImgLoaders;
import mpicbg.spim.data.generic.sequence.XmlIoBasicImgLoader;
import org.jdom2.Element;

import static mpicbg.spim.data.XmlHelpers.loadPath;
import static mpicbg.spim.data.XmlKeys.IMGLOADER_FORMAT_ATTRIBUTE_NAME;
import net.imglib2.util.Cast;

@ImgLoaderIo( format = "bdv.n5", type = N5ImageLoader.class )
public class XmlIoN5ImageLoader implements XmlIoBasicImgLoader< N5ImageLoader >
Expand All @@ -53,9 +60,40 @@ public Element toXml( final N5ImageLoader imgLoader, final File basePath )

@Override
public N5ImageLoader fromXml( final Element elem, final File basePath, final AbstractSequenceDescription< ?, ?, ? > sequenceDescription )
{
return fromXml( elem, basePath.toURI(), sequenceDescription );
}

@Override
public N5ImageLoader fromXml( final Element elem, final URI basePathURI, final AbstractSequenceDescription< ?, ?, ? > sequenceDescription )
{
// final String version = elem.getAttributeValue( "version" );
final File path = loadPath( elem, "n5", basePath );
return new N5ImageLoader( path, sequenceDescription );
final URI uri = XmlHelpers.loadPathURI( elem, "n5", basePathURI );

// try to open with N5FSReader if URI is a file
try
{
final String scheme = uri.getScheme();
final boolean hasScheme = scheme != null;
if ( !hasScheme || FILE_SCHEME.asPredicate().test( scheme ) )
{
final N5FSReader n5 = new N5FSReader( new File( uri ).getAbsolutePath() );
return new N5ImageLoader( n5, uri, sequenceDescription );
}
}
catch ( Exception e ) {}

// try to open with "bdv.n5.cloud" format, if XmlIo for that can be discovered
try
{
final XmlIoBasicImgLoader< ? > io = ImgLoaders.createXmlIoForFormat( "bdv.n5.cloud" );
return Cast.unchecked( io.fromXml( elem, basePathURI, sequenceDescription ) );
}
catch ( SpimDataInstantiationException e )
{
return null;
}
}

private final static Pattern FILE_SCHEME = Pattern.compile("file", Pattern.CASE_INSENSITIVE);
}
Loading