Back to Article
N5-Tutorial.ipynb
Download Notebook
In [15]:
%mavenRepo scijava.public https://maven.scijava.org/content/groups/public
%maven org.scijava:scijava-common:2.97.0
%maven net.imglib2:imglib2:6.2.0
%maven org.janelia.saalfeldlab:n5:3.1.2
%maven org.janelia.saalfeldlab:n5-imglib2:7.0.0
%maven org.janelia.saalfeldlab:n5-universe:1.3.1
In [16]:
import org.janelia.saalfeldlab.n5.*;
import org.janelia.saalfeldlab.n5.universe.*;
In [17]:
// N5Factory can make N5Readers and N5Writers
var factory = new N5Factory();

// trying to open a container does not yet exist will throw an error 
// var n5Reader = factory.openReader("my-container.n5");

// creating a writer creates a container at the given location
// if it does not already exist
var n5Writer = factory.openWriter("my-container.n5");

// now we can make a reader
var n5Reader = factory.openReader("my-container.n5");

// test if the container exists
n5Reader.exists(""); // true
true
In [12]:
// "" and "/" both refer to the root of the container
n5Reader.exists("/"); // true
true
In [11]:
factory.openWriter("my-container.h5").getClass();    // class org.janelia.saalfeldlab.n5.hdf5.N5HDF5Writer
factory.openWriter("my-container.n5").getClass();    // class org.janelia.saalfeldlab.n5.N5FSWriter
factory.openWriter("my-container.zarr").getClass();  // class org.janelia.saalfeldlab.n5.zarr.N5ZarrWriter
class org.janelia.saalfeldlab.n5.zarr.N5ZarrWriter
In [1]:
n5Writer.createGroup("foo");
n5Writer.createGroup("foo/bar");
n5Writer.createGroup("lorum/ipsum/dolor/sit/amet");

n5Writer.exists("lorum/ipsum");      // true
n5Writer.exists("not/a/real/group"); // false
In [2]:
Arrays.toString(n5Writer.list(""));     // [lorum, foo]
Arrays.toString(n5Writer.list("foo"));  // [bar]
In [3]:
Arrays.toString(n5Writer.deepList(""));
In [4]:

n5Reader.getAttribute(groupName, attributeName, String.class)

// create a group inside the container (think: "folder")
var groupName = "put-data-in-me";
n5Writer.createGroup(groupName);

// attributes have names and values
// make an attribute called "date" with a String value
var attributeName = "date";
n5Writer.setAttribute(groupName, attributeName, "2024-Jan-01");

// get the value of the "date" attribute

n5Writer.getAttribute(groupName, attributeName, String.class)
In [5]:
%%bash
ls my-container.n5

The line below is causing problems for some reason relating to google cloud dependencies

%maven org.janelia.saalfeldlab:n5-ij:4.0.2