-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from KateMoreva/tests
Tests
- Loading branch information
Showing
14 changed files
with
896 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
src/main/java/de/embl/cba/n5/ome/zarr/writers/imgplus/WriteImgPlusToN5BdvOmeZarr.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
package de.embl.cba.n5.ome.zarr.writers.imgplus; | ||
|
||
import bdv.export.ExportMipmapInfo; | ||
import bdv.export.ProgressWriter; | ||
import bdv.export.ProposeMipmaps; | ||
import bdv.export.SubTaskProgressWriter; | ||
import bdv.spimdata.SequenceDescriptionMinimal; | ||
import bdv.spimdata.SpimDataMinimal; | ||
import bdv.spimdata.XmlIoSpimDataMinimal; | ||
import de.embl.cba.n5.ome.zarr.loaders.N5OMEZarrImageLoader; | ||
import de.embl.cba.n5.util.DownsampleBlock; | ||
import de.embl.cba.n5.util.ExportScalePyramid; | ||
import de.embl.cba.n5.util.writers.WriteImgPlusToN5; | ||
import de.embl.cba.n5.ome.zarr.readers.N5OmeZarrReader; | ||
import ij.IJ; | ||
import ij.ImagePlus; | ||
import mpicbg.spim.data.SpimDataException; | ||
import mpicbg.spim.data.generic.sequence.BasicViewSetup; | ||
import mpicbg.spim.data.registration.ViewRegistration; | ||
import mpicbg.spim.data.registration.ViewRegistrations; | ||
import mpicbg.spim.data.sequence.FinalVoxelDimensions; | ||
import net.imglib2.FinalDimensions; | ||
import net.imglib2.realtransform.AffineTransform3D; | ||
import org.janelia.saalfeldlab.n5.Compression; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Map; | ||
|
||
import static de.embl.cba.n5.util.writers.WriteImgPlusToN5Helper.*; | ||
|
||
public class WriteImgPlusToN5BdvOmeZarr extends WriteImgPlusToN5 { | ||
|
||
@Override | ||
public void export(ImagePlus imp, int[][] resolutions, int[][] subdivisions, String xmlPath, | ||
AffineTransform3D sourceTransform, DownsampleBlock.DownsamplingMethod downsamplingMethod, | ||
Compression compression, String[] viewSetupNames) { | ||
if (resolutions.length == 0) { | ||
IJ.showMessage("Invalid resolutions - length 0"); | ||
return; | ||
} | ||
|
||
if (subdivisions.length == 0) { | ||
IJ.showMessage(" Invalid subdivisions - length 0"); | ||
return; | ||
} | ||
|
||
if (resolutions.length != subdivisions.length) { | ||
IJ.showMessage("Subsampling factors and chunk sizes must have the same number of elements"); | ||
return; | ||
} | ||
|
||
String seqFilename = xmlPath; | ||
if (!seqFilename.endsWith(".xml")) | ||
seqFilename += ".xml"; | ||
final File seqFile = getSeqFileFromPath(seqFilename); | ||
if (seqFile == null) { | ||
return; | ||
} | ||
|
||
final File zarrFile = getOmeZarrFileFromXmlPath(seqFilename); | ||
|
||
// TODO - check transform and downsampling mode | ||
|
||
Parameters exportParameters = new Parameters(resolutions, subdivisions, seqFile, zarrFile, sourceTransform, | ||
downsamplingMethod, compression, viewSetupNames); | ||
|
||
export(imp, exportParameters); | ||
} | ||
|
||
// TODO - split some of this into common functions | ||
@Override | ||
protected Parameters generateDefaultParameters(ImagePlus imp, String xmlPath, AffineTransform3D sourceTransform, | ||
DownsampleBlock.DownsamplingMethod downsamplingMethod, Compression compression, | ||
String[] viewSetupNames) { | ||
FinalVoxelDimensions voxelSize = getVoxelSize(imp); | ||
FinalDimensions size = getSize(imp); | ||
|
||
// propose reasonable mipmap settings | ||
final int maxNumElements = 64 * 64 * 64; | ||
final ExportMipmapInfo autoMipmapSettings = ProposeMipmaps.proposeMipmaps( | ||
new BasicViewSetup(0, "", size, voxelSize), | ||
maxNumElements); | ||
|
||
int[][] resolutions = autoMipmapSettings.getExportResolutions(); | ||
int[][] subdivisions = autoMipmapSettings.getSubdivisions(); | ||
|
||
if (resolutions.length == 0 || subdivisions.length == 0 || resolutions.length != subdivisions.length) { | ||
IJ.showMessage("Error with calculating default subdivisions and resolutions"); | ||
return null; | ||
} | ||
|
||
String seqFilename = xmlPath; | ||
if (!seqFilename.endsWith(".xml")) | ||
seqFilename += ".xml"; | ||
final File seqFile = getSeqFileFromPath(seqFilename); | ||
if (seqFile == null) { | ||
return null; | ||
} | ||
|
||
final File zarrFile = getOmeZarrFileFromXmlPath(seqFilename); | ||
|
||
return new Parameters(resolutions, subdivisions, seqFile, zarrFile, sourceTransform, | ||
downsamplingMethod, compression, viewSetupNames); | ||
} | ||
|
||
@Override | ||
protected void writeFiles(SequenceDescriptionMinimal seq, Map<Integer, ExportMipmapInfo> perSetupExportMipmapInfo, | ||
Parameters params, ExportScalePyramid.LoopbackHeuristic loopbackHeuristic, | ||
ExportScalePyramid.AfterEachPlane afterEachPlane, int numCellCreatorThreads, | ||
ProgressWriter progressWriter, int numTimepoints, int numSetups) throws IOException, SpimDataException { | ||
WriteSequenceToN5OmeZarr.writeOmeZarrFile(seq, perSetupExportMipmapInfo, | ||
params.downsamplingMethod, | ||
params.compression, params.n5File, | ||
loopbackHeuristic, afterEachPlane, numCellCreatorThreads, | ||
new SubTaskProgressWriter(progressWriter, 0, 0.95)); | ||
|
||
// write xml sequence description | ||
final N5OMEZarrImageLoader zarrLoader = new N5OMEZarrImageLoader( | ||
new N5OmeZarrReader(params.n5File.getAbsolutePath()), seq); | ||
final SequenceDescriptionMinimal seqh5 = new SequenceDescriptionMinimal(seq, zarrLoader); | ||
|
||
final ArrayList<ViewRegistration> registrations = new ArrayList<>(); | ||
for (int t = 0; t < numTimepoints; ++t) | ||
for (int s = 0; s < numSetups; ++s) | ||
registrations.add(new ViewRegistration(t, s, params.sourceTransform)); | ||
|
||
final File basePath = params.seqFile.getParentFile(); | ||
final SpimDataMinimal spimData = new SpimDataMinimal(basePath, seqh5, new ViewRegistrations(registrations)); | ||
|
||
new XmlIoSpimDataMinimal().save(spimData, params.seqFile.getAbsolutePath()); | ||
|
||
progressWriter.setProgress(1.0); | ||
} | ||
} |
130 changes: 130 additions & 0 deletions
130
src/main/java/de/embl/cba/n5/ome/zarr/writers/imgplus/WriteImgPlusToN5OmeZarr.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
package de.embl.cba.n5.ome.zarr.writers.imgplus; | ||
|
||
import bdv.export.ExportMipmapInfo; | ||
import bdv.export.ProgressWriter; | ||
import bdv.export.ProposeMipmaps; | ||
import bdv.export.SubTaskProgressWriter; | ||
import bdv.spimdata.SequenceDescriptionMinimal; | ||
import de.embl.cba.n5.util.DownsampleBlock; | ||
import de.embl.cba.n5.util.ExportScalePyramid; | ||
import de.embl.cba.n5.util.writers.WriteImgPlusToN5; | ||
import ij.IJ; | ||
import ij.ImagePlus; | ||
import mpicbg.spim.data.SpimDataException; | ||
import mpicbg.spim.data.generic.sequence.BasicViewSetup; | ||
import mpicbg.spim.data.sequence.FinalVoxelDimensions; | ||
import net.imglib2.FinalDimensions; | ||
import net.imglib2.realtransform.AffineTransform3D; | ||
import org.janelia.saalfeldlab.n5.Compression; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
import static de.embl.cba.n5.util.writers.WriteImgPlusToN5Helper.getSize; | ||
import static de.embl.cba.n5.util.writers.WriteImgPlusToN5Helper.getVoxelSize; | ||
|
||
public class WriteImgPlusToN5OmeZarr extends WriteImgPlusToN5 { | ||
|
||
// TODO - deal with transforms properly - is there somewhere in ome-zarr this can be written? | ||
|
||
// export, generating default source transform, and default resolutions / subdivisions | ||
@Override | ||
public void export( ImagePlus imp, String zarrPath, DownsampleBlock.DownsamplingMethod downsamplingMethod, | ||
Compression compression ) { | ||
super.export( imp, zarrPath, downsamplingMethod, compression ); | ||
} | ||
|
||
// export, generating default resolutions / subdivisions | ||
@Override | ||
public void export(ImagePlus imp, String zarPath, AffineTransform3D sourceTransform, | ||
DownsampleBlock.DownsamplingMethod downsamplingMethod, Compression compression ) { | ||
super.export( imp, zarPath, sourceTransform, downsamplingMethod, compression ); | ||
} | ||
|
||
|
||
// export, generating default resolutions / subdivisions | ||
@Override | ||
public void export(ImagePlus imp, String zarrPath, AffineTransform3D sourceTransform, | ||
DownsampleBlock.DownsamplingMethod downsamplingMethod, Compression compression, | ||
String[] viewSetupNames ) { | ||
super.export( imp, zarrPath, sourceTransform, downsamplingMethod, compression, viewSetupNames ); | ||
} | ||
|
||
@Override | ||
public void export( ImagePlus imp, int[][] resolutions, int[][] subdivisions, String zarrPath, | ||
AffineTransform3D sourceTransform, DownsampleBlock.DownsamplingMethod downsamplingMethod, | ||
Compression compression ) { | ||
export( imp, resolutions, subdivisions, zarrPath, sourceTransform, downsamplingMethod, compression, null ); | ||
} | ||
|
||
@Override | ||
public void export( ImagePlus imp, int[][] resolutions, int[][] subdivisions, String zarrPath, | ||
AffineTransform3D sourceTransform, DownsampleBlock.DownsamplingMethod downsamplingMethod, | ||
Compression compression, String[] viewSetupNames ) { | ||
if ( resolutions.length == 0 ) { | ||
IJ.showMessage( "Invalid resolutions - length 0" ); | ||
return; | ||
} | ||
|
||
if ( subdivisions.length == 0 ) { | ||
IJ.showMessage( " Invalid subdivisions - length 0" ); | ||
return; | ||
} | ||
|
||
if ( resolutions.length != subdivisions.length ) { | ||
IJ.showMessage( "Subsampling factors and chunk sizes must have the same number of elements" ); | ||
return; | ||
} | ||
|
||
final File zarrFile = new File( zarrPath ); | ||
|
||
// TODO - check transform and downsampling mode | ||
|
||
Parameters exportParameters = new Parameters( resolutions, subdivisions, null, zarrFile, sourceTransform, | ||
downsamplingMethod, compression, viewSetupNames ); | ||
|
||
export( imp, exportParameters ); | ||
} | ||
|
||
@Override | ||
protected Parameters generateDefaultParameters(ImagePlus imp, String zarrPath, AffineTransform3D sourceTransform, | ||
DownsampleBlock.DownsamplingMethod downsamplingMethod, Compression compression, | ||
String[] viewSetupNames ) { | ||
FinalVoxelDimensions voxelSize = getVoxelSize( imp ); | ||
FinalDimensions size = getSize( imp ); | ||
|
||
// propose reasonable mipmap settings | ||
final int maxNumElements = 64 * 64 * 64; | ||
final ExportMipmapInfo autoMipmapSettings = ProposeMipmaps.proposeMipmaps( | ||
new BasicViewSetup(0, "", size, voxelSize), | ||
maxNumElements); | ||
|
||
int[][] resolutions = autoMipmapSettings.getExportResolutions(); | ||
int[][] subdivisions = autoMipmapSettings.getSubdivisions(); | ||
|
||
if ( resolutions.length == 0 || subdivisions.length == 0 || resolutions.length != subdivisions.length ) { | ||
IJ.showMessage( "Error with calculating default subdivisions and resolutions"); | ||
return null; | ||
} | ||
|
||
final File zarrFile = new File( zarrPath ); | ||
|
||
return new Parameters( resolutions, subdivisions, null, zarrFile, sourceTransform, | ||
downsamplingMethod, compression, viewSetupNames ); | ||
} | ||
|
||
@Override | ||
protected void writeFiles(SequenceDescriptionMinimal seq, Map<Integer, ExportMipmapInfo> perSetupExportMipmapInfo, | ||
Parameters params, ExportScalePyramid.LoopbackHeuristic loopbackHeuristic, | ||
ExportScalePyramid.AfterEachPlane afterEachPlane, int numCellCreatorThreads, | ||
ProgressWriter progressWriter, int numTimepoints, int numSetups ) throws IOException, SpimDataException { | ||
WriteSequenceToN5OmeZarr.writeOmeZarrFile( seq, perSetupExportMipmapInfo, | ||
params.downsamplingMethod, | ||
params.compression, params.n5File, | ||
loopbackHeuristic, afterEachPlane, numCellCreatorThreads, | ||
new SubTaskProgressWriter( progressWriter, 0, 0.95 ) ); | ||
|
||
progressWriter.setProgress( 1.0 ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../zarr/projectcreator/DownsampleBlock.java → .../de/embl/cba/n5/util/DownsampleBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package de.embl.cba.n5.ome.zarr.projectcreator; | ||
package de.embl.cba.n5.util; | ||
|
||
/*- | ||
* #%L | ||
|
2 changes: 1 addition & 1 deletion
2
...rr/projectcreator/ExportScalePyramid.java → .../embl/cba/n5/util/ExportScalePyramid.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package de.embl.cba.n5.ome.zarr.projectcreator; | ||
package de.embl.cba.n5.util; | ||
|
||
/* | ||
* #%L | ||
|
Oops, something went wrong.