Package sc.fiji.snt.io
Class SpimDataUtils
java.lang.Object
sc.fiji.snt.io.SpimDataUtils
Utilities for working with
AbstractSpimData and BigDataViewer XML
descriptors.- Author:
- Tiago Ferreira
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classSpimDataUtils.CalibratedSource<T extends net.imglib2.type.numeric.NumericType<T>>Wraps aRandomAccessibleIntervalSourceand overridesSpimDataUtils.CalibratedSource.getVoxelDimensions()to carry the physical unit (e.g.static final recordA single channel of a dataset at its highest resolution, as returned byopenChannel(java.lang.String, int, int).static final recordHolds the sources produced by opening an N5 or OME-Zarr container vian5-ij/n5-universe/n5-viewer_fiji(seeresolvePathToSource(String)). -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanisRemoteUrl(String path) Whetherpathis a remote URL (e.g.static <T extends mpicbg.spim.data.generic.AbstractSpimData<?>>
TlockImarisReads(T spimData) Serializes all HDF5 reads of an Imaris-backedspimData.static SpimDataUtils.ChannelDataopenChannel(String path, int channelIdx, int timepoint) Opens one channel of a dataset at full resolution, whatever its format: BDV.xmlor Imaris.imsfiles (opened in memory, no XML sidecar is written), or N5/OME-Zarr containers (local or remote).static voidpatchImsXml(String xmlPath, String base) Patches an IMS XML sidecar file, replacing all"(name not specified)"placeholders with sequential channel names derived from the base name.static SpimDataUtils.N5SourcesresolveN5Selection(org.janelia.saalfeldlab.n5.ui.DataSelection selection, String name) BuildsSpimDataUtils.N5Sourcesfrom a user-madeDataSelection(e.g.static ObjectresolvePathToSource(String filePathOrUrl) Resolves a file path to anAbstractSpimData(for.imsand.xmlfiles), anSpimDataUtils.N5Sources(for.n5/.zarrcontainers), or anImgPlus(fallback).static StringrestoreUrlScheme(String url) Restores a URL's "://" scheme separator ifFile's path normalization collapsed it to a single slash (seeisRemoteUrl(String)).static voidwriteBdvN5Xml(File xmlFile, String n5DirName, long[][] levelDims, double[] voxelSize, String unit, int nTimepoints, String setupName) Writes a BDV-compatible XML descriptor for an N5 dataset.static voidwriteBdvN5Xml(File xmlFile, String n5DirName, long[][] levelDims, double[] voxelSize, String unit, int nTimepoints, String setupName, int nChannels)
-
Method Details
-
openChannel
public static SpimDataUtils.ChannelData openChannel(String path, int channelIdx, int timepoint) throws IOException Opens one channel of a dataset at full resolution, whatever its format: BDV.xmlor Imaris.imsfiles (opened in memory, no XML sidecar is written), or N5/OME-Zarr containers (local or remote). Channels are in the order they are displayed by the viewers. Intended for scripts that operate on the full volume (seeChannelUnmixing.groovy).- Parameters:
path- path or URL of the datasetchannelIdx- index of the channel (0-based)timepoint- index of the timepoint (0-based)- Returns:
- the channel
- Throws:
IOException- if the dataset cannot be openedIllegalArgumentException- if the format is unsupported or the indices are out of range
-
resolvePathToSource
Resolves a file path to anAbstractSpimData(for.imsand.xmlfiles), anSpimDataUtils.N5Sources(for.n5/.zarrcontainers), or anImgPlus(fallback).- Parameters:
filePathOrUrl- path or URL to the image file- Returns:
- an
AbstractSpimData,SpimDataUtils.N5Sources, orImgPlus - Throws:
IllegalArgumentException- if the file cannot be opened
-
isRemoteUrl
Whetherpathis a remote URL (e.g.https://.../dataset.ome.zarr,s3://bucket/key,gs://bucket/key) rather than a local filesystem path. Also recognizes the same URLs after their scheme separator has been collapsed from "://" to ":/" byFile's own path normalization (seerestoreUrlScheme(String)) -- this happens whenever a URL is round-tripped through aFile-typed SciJava parameter, e.g. a user typing a URL intoBigDataLoaderCmd's "Main volume" field. Neither Windows drive letters (C:\...) nor UNC paths (\\server\share) match either form, so local paths are never misidentified -
restoreUrlScheme
Restores a URL's "://" scheme separator ifFile's path normalization collapsed it to a single slash (seeisRemoteUrl(String)). A no-op if the separator is already intact. -
patchImsXml
Patches an IMS XML sidecar file, replacing all"(name not specified)"placeholders with sequential channel names derived from the base name.- Parameters:
xmlPath- path to the XML sidecarbase- base name to use (typically the IMS filename without extension)- Throws:
IOException- if the file cannot be read or written
-
resolveN5Selection
public static SpimDataUtils.N5Sources resolveN5Selection(org.janelia.saalfeldlab.n5.ui.DataSelection selection, String name) BuildsSpimDataUtils.N5Sourcesfrom a user-madeDataSelection(e.g. from an interactiveDatasetSelectorDialog), reusing the same source-building logic as the automatic discovery inresolvePathToSource(String). Intended as a fallback UI for containers whose structureresolvePathToSource(String)could not resolve on its own.- Parameters:
selection- the user's dataset selectionname- display name for the resultingSpimDataUtils.N5Sources- Returns:
- the resolved sources
- Throws:
IllegalArgumentException- if no displayable sources are found
-
writeBdvN5Xml
public static void writeBdvN5Xml(File xmlFile, String n5DirName, long[][] levelDims, double[] voxelSize, String unit, int nTimepoints, String setupName) throws IOException Writes a BDV-compatible XML descriptor for an N5 dataset. The resulting XML can be opened by BigDataViewer, BigVolumeViewer, or any BDV-based tool viaXmlIoSpimDataMinimal.load().The descriptor references the N5 container using a relative path (assumes the XML sits next to the N5 directory). A single ViewSetup (id 0) is created with the supplied voxel size and calibration unit.
- Parameters:
xmlFile- the XML file to write (will be overwritten if it exists)n5DirName- name of the N5 container directory (relative to the XML file's parent; e.g.,"dataset_unmixed")levelDims- per-level dimensions:levelDims[level] = {x, y, z}voxelSize- physical voxel size at level 0:{sx, sy, sz}unit- calibration unit (e.g.,"um","pixel")nTimepoints- number of timepoints in the datasetsetupName- display name for the single ViewSetup (e.g.,"unmixed")- Throws:
IOException- if the file cannot be written
-
writeBdvN5Xml
public static void writeBdvN5Xml(File xmlFile, String n5DirName, long[][] levelDims, double[] voxelSize, String unit, int nTimepoints, String setupName, int nChannels) throws IOException - Throws:
IOException
-
lockImarisReads
public static <T extends mpicbg.spim.data.generic.AbstractSpimData<?>> T lockImarisReads(T spimData) Serializes all HDF5 reads of an Imaris-backedspimData. BDV'sHDF5AccessHackonly synchronizes its byte reads: the short and float reads share a mutable hyperslab selection, so concurrent cell loads (e.g., a parallel crop copy plus viewer fetcher threads) can return cells holding data from the wrong chunk. The loader opens lazily and captures its array loader when an image is first requested, so this must be called before any image is obtained fromspimData. Does nothing for other loaders, and leavesspimDatauntouched if reflection fails- Type Parameters:
T- the dataset type- Parameters:
spimData- the dataset (typically freshly opened)- Returns:
spimData, for chaining
-