Skip to content

Commit

Permalink
Merge pull request #72 from saalfeldlab/dev
Browse files Browse the repository at this point in the history
4.1.0 release candidate
  • Loading branch information
bogovicj authored Mar 6, 2024
2 parents d44052a + a08a95b commit ad9987f
Show file tree
Hide file tree
Showing 15 changed files with 428 additions and 192 deletions.
12 changes: 5 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,11 @@
<!-- NB: Deploy releases to the SciJava Maven repository. -->
<releaseProfiles>sign,deploy-to-scijava</releaseProfiles>

<n5.version>3.1.1</n5.version>
<n5-universe.version>1.3.0</n5-universe.version>
<n5-zarr.version>1.2.0</n5-zarr.version>
<n5.version>3.2.0</n5.version>
<n5-hdf5.version>2.2.0</n5-hdf5.version>
<n5-google-cloud.version>4.1.0</n5-google-cloud.version>
<n5-universe.version>1.4.0</n5-universe.version>
<n5-zarr.version>1.3.1</n5-zarr.version>
<n5-zstandard.version>1.0.2</n5-zstandard.version>
</properties>

Expand All @@ -101,10 +103,6 @@
<groupId>org.janelia.saalfeldlab</groupId>
<artifactId>n5-blosc</artifactId>
</dependency>
<dependency>
<groupId>org.janelia.saalfeldlab</groupId>
<artifactId>n5-google-cloud</artifactId>
</dependency>
<dependency>
<groupId>org.janelia.saalfeldlab</groupId>
<artifactId>n5-imglib2</artifactId>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/janelia/saalfeldlab/n5/ij/N5IJUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ void save(
* @param <T> the image data type
* @param <M> the image data type
* @param <W> the metadata writer type
* @param <I> the ImageplusMetadata that extracts the N5DatasetMetadata from the ImagePlus
* @param imp the ImagePlus
* @param n5 the writer
* @param datasetName the dataset name
Expand Down Expand Up @@ -333,6 +334,7 @@ void save(
* @param <T> the image data type.
* @param <M> the metadata type.
* @param <W> the metadata writer type.
* @param <I> the ImageplusMetadata that extracts the N5DatasetMetadata from the ImagePlus
* @param imp the ImagePlus
* @param n5 the writer
* @param datasetName the dataset name
Expand Down
60 changes: 39 additions & 21 deletions src/main/java/org/janelia/saalfeldlab/n5/ij/N5Importer.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand All @@ -43,6 +44,7 @@
import org.janelia.saalfeldlab.n5.DataType;
import org.janelia.saalfeldlab.n5.N5Exception;
import org.janelia.saalfeldlab.n5.N5Reader;
import org.janelia.saalfeldlab.n5.N5URI;
import org.janelia.saalfeldlab.n5.converters.LabelMultisetLongConverter;
import org.janelia.saalfeldlab.n5.converters.UnsignedShortLUTConverter;
import org.janelia.saalfeldlab.n5.imglib2.N5LabelMultisets;
Expand Down Expand Up @@ -79,7 +81,6 @@
import org.janelia.saalfeldlab.n5.universe.metadata.ome.ngff.v04.OmeNgffMetadataParser;

import ij.IJ;
import ij.ImageJ;
import ij.ImagePlus;
import ij.Macro;
import ij.Prefs;
Expand All @@ -100,7 +101,6 @@
import net.imglib2.loops.LoopBuilder;
import net.imglib2.parallel.DefaultTaskExecutor;
import net.imglib2.type.NativeType;
import net.imglib2.type.label.LabelMultisetType;
import net.imglib2.type.numeric.ARGBType;
import net.imglib2.type.numeric.NumericType;
import net.imglib2.type.numeric.integer.UnsignedIntType;
Expand All @@ -113,8 +113,7 @@

public class N5Importer implements PlugIn {

// private static final String[] axisNames = new String[] { "x", "y", "c",
// "z", "t" };
// private static final String[] axisNames = new String[] { "x", "y", "c", "z", "t" };
private static final String[] axisNames = new String[]{"dim1", "dim2", "dim3", "dim4", "dim5"};

public static final String n5PathKey = "url";
Expand Down Expand Up @@ -469,6 +468,8 @@ public static void record(final String n5RootAndDataset, final boolean virtual,
* the metadata type
* @param n5
* the n5Reader
* @param exec
* an ExecutorService to manage parallel reading
* @param datasetMeta
* datasetMetadata containing the path
* @param cropIntervalIn
Expand Down Expand Up @@ -735,29 +736,31 @@ public static List<ImagePlus> process(final N5Reader n5,
continue;

final String d = normalPathName(datasetMeta.getPath(), n5.getGroupSeparator());
final String pathToN5Dataset = d.isEmpty() ? rootPath : rootPath + File.separator + d;

final ImageplusMetadata<?> impMeta = impMetaWriterTypes.get(datasetMeta.getClass());
ImagePlus imp;
try {

final String n5Url = N5URI.from(rootPath, d, null).toString();
final ImageplusMetadata<?> impMeta = impMetaWriterTypes.get(datasetMeta.getClass());

// datasetMeta must have absolute path
ImagePlus imp;
imp = N5Importer.read(n5, exec, datasetMeta, cropInterval, asVirtual, impMeta);

FileInfo fileInfo = imp.getOriginalFileInfo();
if (fileInfo == null)
fileInfo = new FileInfo();

fileInfo.url = rootPath + "?" + datasetMeta.getPath();
fileInfo.url = n5Url;
imp.setFileInfo(fileInfo);

record(pathToN5Dataset, asVirtual, cropInterval);
record(n5Url, asVirtual, cropInterval);
imgList.add(imp);
if (show)
imp.show();

} catch (final IOException e) {
IJ.error("failed to read n5");
} catch (URISyntaxException e1) {
IJ.error("unable to parse url: " + rootPath + "?" + d );
}
}
return imgList;
Expand Down Expand Up @@ -814,19 +817,17 @@ public List<ImagePlus> process(final String n5FullPath, final boolean asVirtual,
return result;
}

public List<ImagePlus> process( final String n5FullPath, final List<N5DatasetMetadata> metadataList, final boolean asVirtual, final Interval cropInterval) {
public List<ImagePlus> process(final String n5FullPath, final List<N5DatasetMetadata> metadataList, final boolean asVirtual, final Interval cropInterval) {

n5 = new N5ViewerReaderFun().apply(n5FullPath);
final String dataset = new N5BasePathFun().apply(n5FullPath);

if( metadataList == null || metadataList.size() < 1 )
if (metadataList == null || metadataList.size() < 1)
return null;

final List<ImagePlus> result = process(n5, dataset, exec, metadataList,
asVirtual, cropInterval, show, getImagePlusMetadataWriterMap());

n5.close();

return result;
}

Expand All @@ -848,13 +849,23 @@ public static class N5ViewerReaderFun implements Function<String, N5Reader> {
public String message;

@Override
public N5Reader apply(final String n5PathIn) {
public N5Reader apply(final String n5UriOrPath) {

N5Reader n5;
if (n5PathIn == null || n5PathIn.isEmpty())
if (n5UriOrPath == null || n5UriOrPath.isEmpty())
return null;

final String rootPath = upToLastExtension(n5PathIn);

String rootPath = null ;
if (n5UriOrPath.contains("?")) {
try {
rootPath = new N5URI(n5UriOrPath).getContainerPath();
} catch (URISyntaxException e) {}
}

if (rootPath == null)
rootPath = upToLastExtension(n5UriOrPath);

final N5Factory factory = new N5Factory().cacheAttributes(true).s3RetryWithCredentials();
try {
n5 = factory.openReader(rootPath);
Expand Down Expand Up @@ -906,12 +917,19 @@ public static class N5BasePathFun implements Function<String, String> {
public String message;

@Override
public String apply(final String n5Path) {
public String apply(final String n5UriOrPath) {

if( n5UriOrPath.contains("?") )
{
try {
return new N5URI( n5UriOrPath ).getGroupPath();
} catch (URISyntaxException e) {}
}

if (n5Path.contains(".h5") || n5Path.contains(".hdf5") || n5Path.contains(".hdf"))
return h5DatasetPath(n5Path);
if (n5UriOrPath.contains(".h5") || n5UriOrPath.contains(".hdf5") || n5UriOrPath.contains(".hdf"))
return h5DatasetPath(n5UriOrPath);
else
return afterLastExtension(n5Path);
return afterLastExtension(n5UriOrPath);
}
}

Expand Down
Loading

0 comments on commit ad9987f

Please sign in to comment.