diff --git a/src/main/java/net/preibisch/mvrecon/fiji/datasetmanager/FileListDatasetDefinition.java b/src/main/java/net/preibisch/mvrecon/fiji/datasetmanager/FileListDatasetDefinition.java index 5c8f1f127..34b3e91f5 100644 --- a/src/main/java/net/preibisch/mvrecon/fiji/datasetmanager/FileListDatasetDefinition.java +++ b/src/main/java/net/preibisch/mvrecon/fiji/datasetmanager/FileListDatasetDefinition.java @@ -103,7 +103,7 @@ import net.preibisch.mvrecon.fiji.plugin.Apply_Transformation; import net.preibisch.mvrecon.fiji.plugin.resave.Generic_Resave_HDF5; import net.preibisch.mvrecon.fiji.plugin.resave.Generic_Resave_HDF5.ParametersResaveHDF5; -import net.preibisch.mvrecon.fiji.plugin.resave.N5Parameters; +import net.preibisch.mvrecon.fiji.plugin.resave.ParametersResaveN5; import net.preibisch.mvrecon.fiji.plugin.resave.PluginHelper; import net.preibisch.mvrecon.fiji.plugin.resave.ProgressWriterIJ; import net.preibisch.mvrecon.fiji.plugin.resave.Resave_HDF5; @@ -1168,6 +1168,18 @@ else if (choice.equals( Z_VARIABLE_CHOICE )) return null; } + if ( !URITools.isKnownScheme( chosenPathDataURI ) ) + { + IOFunctions.println( "The scheme of the image data path you selected '" + chosenPathDataURI + "' is unknown." ); + return null; + } + + if ( !URITools.isKnownScheme( chosenPathXMLURI ) ) + { + IOFunctions.println( "The scheme of the XML path you selected '" + chosenPathXMLURI + "' is unknown." ); + return null; + } + IOFunctions.println( "XML & metadata path: " + chosenPathXMLURI ); IOFunctions.println( "Image data path: " + chosenPathDataURI ); @@ -1289,26 +1301,21 @@ else if (resaveAsN5) final ArrayList< ViewDescription > viewIds = new ArrayList<>( data.getSequenceDescription().getViewDescriptions().values() ); Collections.sort( viewIds ); - final File xmlFile = new File( chosenPath.getAbsolutePath(), xmlFileName ); - final SequenceDescription sd = data.getSequenceDescription(); - final N5Parameters n5params = N5Parameters.getParamtersIJ( - xmlFile.getAbsolutePath(), + final ParametersResaveN5 n5params = ParametersResaveN5.getParamtersIJ( + chosenPathXMLURI, + chosenPathDataURI, viewIds.stream().map( vid -> sd.getViewSetups().get( vid.getViewSetupId() ) ).collect( Collectors.toSet() ), - true ); + false ); // do not ask for paths again if ( n5params == null ) return null; - // n5-filename is same as XML name now (set in N5Parameters.getParamtersIJ) - //n5params.n5File = new File( chosenPath.getAbsolutePath(), "dataset.n5" ); - Resave_N5.resaveN5( data, viewIds, n5params ); // Re-assemble a new SpimData object containing the subset of viewsetups and timepoints selected - final List< String > filesToCopy = new ArrayList< String >(); - final SpimData2 newSpimData = Resave_TIFF.assemblePartialSpimData2( data, viewIds, n5params.n5File.getParentFile(), filesToCopy ); + final SpimData2 newSpimData = Resave_TIFF.assemblePartialSpimData2( data, viewIds, n5params.n5File.getParentFile(), new ArrayList<>() ); // replace imgLoader newSpimData.getSequenceDescription().setImgLoader( new N5ImageLoader( n5params.n5File, newSpimData.getSequenceDescription() ) ); diff --git a/src/main/java/net/preibisch/mvrecon/fiji/plugin/resave/N5Parameters.java b/src/main/java/net/preibisch/mvrecon/fiji/plugin/resave/ParametersResaveN5.java similarity index 71% rename from src/main/java/net/preibisch/mvrecon/fiji/plugin/resave/N5Parameters.java rename to src/main/java/net/preibisch/mvrecon/fiji/plugin/resave/ParametersResaveN5.java index e726c7f0d..f4f33710b 100644 --- a/src/main/java/net/preibisch/mvrecon/fiji/plugin/resave/N5Parameters.java +++ b/src/main/java/net/preibisch/mvrecon/fiji/plugin/resave/ParametersResaveN5.java @@ -23,7 +23,8 @@ package net.preibisch.mvrecon.fiji.plugin.resave; import java.awt.Font; -import java.io.File; +import java.net.URI; +import java.net.URISyntaxException; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; @@ -43,15 +44,15 @@ import mpicbg.spim.data.sequence.ViewSetup; import net.preibisch.legacy.io.IOFunctions; -public class N5Parameters +public class ParametersResaveN5 { public static String[] compressions = new String[]{ "Bzip2", "Gzip", "Lz4", "Raw (no compression)", "Xz" }; public static int defaultBlockSize = 64; public static int defaultBlockSizeXY = 128; public static int defaultCompression = 1; - public static int defaultNumThreads = Math.max( 1, Runtime.getRuntime().availableProcessors() / 2 ); + public static int defaultNumThreads = Math.max( 1, Runtime.getRuntime().availableProcessors() - 1 ); - public File xmlFile, n5File; + public URI xmlURI, n5URI; public int[][] resolutions, subdivisions; public Map< Integer, ExportMipmapInfo > proposedMipmaps; @@ -59,25 +60,29 @@ public class N5Parameters public Compression compression; public int numCellCreatorThreads = 1; - public boolean saveXML = true; // mostly important for cluster-based re-saving - public boolean saveData = true; // mostly important for cluster-based re-saving + //public boolean saveXML = true; // mostly important for cluster-based re-saving + //public boolean saveData = true; // mostly important for cluster-based re-saving - public boolean setFinishedAttributeInN5 = true; // required if double-checking that all ViewId were written - final public static String finishedAttrib = "saved_completely"; // required if double-checking that all ViewId were written + //public boolean setFinishedAttributeInN5 = true; // required if double-checking that all ViewId were written + //final public static String finishedAttrib = "saved_completely"; // required if double-checking that all ViewId were written - public static N5Parameters getParamtersIJ( - final String xmlFileName, + public static ParametersResaveN5 getParamtersIJ( + final URI xmlURI, final Collection< ViewSetup > setupsToProcess, - final boolean localOnly ) + final boolean askForPaths ) { - final N5Parameters n5params = new N5Parameters(); + final URI n5URI = URI.create( xmlURI.toString().subSequence( 0, xmlURI.toString().length() - 4 ) + ".n5" ); - if ( localOnly ) - n5params.xmlFile = new File( xmlFileName ); - else - n5params.xmlFile = new File( xmlFileName.subSequence( 0, xmlFileName.length() - 4 ) + "-n5.xml" ); //.replace( ".xml", "-n5.xml" ) ); + return getParamtersIJ( xmlURI, n5URI, setupsToProcess, askForPaths ); + } - n5params.n5File = new File( xmlFileName.subSequence( 0, xmlFileName.length() - 4 ) + ".n5" ); //.replace( ".xml", ".n5" )); + public static ParametersResaveN5 getParamtersIJ( + final URI xmlURI, + final URI n5URI, + final Collection< ViewSetup > setupsToProcess, + final boolean askForPaths ) + { + final ParametersResaveN5 n5params = new ParametersResaveN5(); final Map< Integer, ExportMipmapInfo > perSetupExportMipmapInfo = Resave_HDF5.proposeMipmaps( setupsToProcess ); //xml.getViewSetupsToProcess() ); final int firstviewSetupId = setupsToProcess.iterator().next().getId();// xml.getData().getSequenceDescription().getViewSetupsOrdered().get( 0 ).getId(); @@ -87,31 +92,25 @@ public static N5Parameters getParamtersIJ( for ( final int[] row : autoMipmapSettings.getSubdivisions() ) { Arrays.fill( row, defaultBlockSize ); - row[ 0 ] = N5Parameters.defaultBlockSizeXY; + row[ 0 ] = ParametersResaveN5.defaultBlockSizeXY; if ( row.length >= 2 ) - row[ 1 ] = N5Parameters.defaultBlockSizeXY; + row[ 1 ] = ParametersResaveN5.defaultBlockSizeXY; } final GenericDialogPlus gdp = new GenericDialogPlus( "Options" ); - if ( !localOnly ) - gdp.addMessage( "N5 saving options", new Font( Font.SANS_SERIF, Font.BOLD, 13 ) ); + gdp.addMessage( "N5 saving options", new Font( Font.SANS_SERIF, Font.BOLD, 13 ) ); gdp.addChoice( "Compression", compressions, compressions[ defaultCompression ] ); gdp.addStringField( "Subsampling_factors", ProposeMipmaps.getArrayString( autoMipmapSettings.getExportResolutions() ), 40 ); gdp.addStringField( "N5_block_sizes", ProposeMipmaps.getArrayString( autoMipmapSettings.getSubdivisions() ), 40 ); + gdp.addNumericField( "Number_of_threads (CPUs:" + Runtime.getRuntime().availableProcessors() + ")", defaultNumThreads, 0 ); - if ( localOnly ) - { - gdp.addNumericField( "Number_of_threads (CPUs:" + Runtime.getRuntime().availableProcessors() + ")", defaultNumThreads, 0 ); - } - else + if ( askForPaths ) { - gdp.addMessage( "Cluster-related options", new Font( Font.SANS_SERIF, Font.BOLD, 13 ) ); - gdp.addFileField( "Output_XML", n5params.xmlFile.getAbsolutePath(), 75 ); - gdp.addFileField( "Output_N5", n5params.n5File.getAbsolutePath(), 75 ); - gdp.addCheckbox( "Write_XML", true ); - gdp.addCheckbox( "Write_data", true ); + gdp.addMessage( "" ); + gdp.addDirectoryField( "XML_path", xmlURI.toString(), 65 ); + gdp.addDirectoryField( "N5_path", n5URI.toString(), 65 ); } gdp.showDialog(); @@ -126,18 +125,26 @@ public static N5Parameters getParamtersIJ( n5params.numCellCreatorThreads = defaultNumThreads = Math.max( 1, (int)Math.round( gdp.getNextNumber() ) ); - if ( localOnly ) + if ( askForPaths ) { - n5params.saveXML = true; - n5params.saveData = true; + try + { + n5params.xmlURI = new URI( gdp.getNextString() ); + n5params.n5URI = new URI( gdp.getNextString() ); + } + catch ( URISyntaxException e ) + { + IOFunctions.println( "Cannot create URIs for provided paths: " + e ); + return null; + } + + IOFunctions.println( "XML & metadata path: " + n5params.xmlURI ); + IOFunctions.println( "Image data path: " + n5params.n5URI ); } else { - n5params.xmlFile = new File(gdp.getNextString()); - n5params.n5File = new File(gdp.getNextString()); - - n5params.saveXML = gdp.getNextBoolean(); - n5params.saveData = gdp.getNextBoolean(); + n5params.xmlURI = xmlURI; + n5params.n5URI = n5URI; } if ( compression == 0 ) // "Bzip2", "Gzip", "Lz4", "Raw (no compression)", "Xz" diff --git a/src/main/java/net/preibisch/mvrecon/fiji/plugin/resave/Resave_N5.java b/src/main/java/net/preibisch/mvrecon/fiji/plugin/resave/Resave_N5.java index 6cab6c4ec..c98f7652c 100644 --- a/src/main/java/net/preibisch/mvrecon/fiji/plugin/resave/Resave_N5.java +++ b/src/main/java/net/preibisch/mvrecon/fiji/plugin/resave/Resave_N5.java @@ -24,32 +24,15 @@ import java.io.File; import java.io.IOException; -import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.regex.Pattern; import java.util.stream.Collectors; -import org.janelia.saalfeldlab.n5.Bzip2Compression; -import org.janelia.saalfeldlab.n5.GzipCompression; -import org.janelia.saalfeldlab.n5.Lz4Compression; -import org.janelia.saalfeldlab.n5.N5FSWriter; -import org.janelia.saalfeldlab.n5.RawCompression; -import org.janelia.saalfeldlab.n5.XzCompression; -import org.kohsuke.args4j.CmdLineException; -import org.kohsuke.args4j.CmdLineParser; -import org.kohsuke.args4j.Option; - import bdv.export.ExportMipmapInfo; import bdv.export.ProgressWriter; -import bdv.export.ProposeMipmaps; import bdv.export.n5.WriteSequenceToN5; -import bdv.img.n5.BdvN5Format; import bdv.img.n5.N5ImageLoader; import ij.ImageJ; import ij.plugin.PlugIn; @@ -57,13 +40,10 @@ import mpicbg.spim.data.sequence.TimePoint; import mpicbg.spim.data.sequence.ViewId; import mpicbg.spim.data.sequence.ViewSetup; -import net.imglib2.multithreading.SimpleMultiThreading; -import net.preibisch.legacy.io.IOFunctions; import net.preibisch.mvrecon.fiji.plugin.queryXML.LoadParseQueryXML; import net.preibisch.mvrecon.fiji.spimdata.SpimData2; import net.preibisch.mvrecon.fiji.spimdata.XmlIoSpimData2; -import net.preibisch.mvrecon.headless.resave.HeadlessParseQueryXML; -import net.preibisch.mvrecon.process.interestpointregistration.pairwise.constellation.grouping.Group; +import util.URITools; public class Resave_N5 implements PlugIn { @@ -75,7 +55,7 @@ public void run(String arg) if ( !xml.queryXML( "Resaving as N5", "Resave", true, true, true, true, true ) ) return; - final N5Parameters n5params = N5Parameters.getParamtersIJ( xml.getXMLFileName(), xml.getViewSetupsToProcess(), false ); + final ParametersResaveN5 n5params = ParametersResaveN5.getParamtersIJ( xml.getXMLURI(), xml.getViewSetupsToProcess(), true ); if ( n5params == null ) return; @@ -92,333 +72,72 @@ public void run(String arg) public static void resaveN5( final SpimData2 data, final Collection vidsToResave, - final N5Parameters n5Params ) + final ParametersResaveN5 n5Params ) { final SpimData2 sdReduced = Resave_HDF5.reduceSpimData2( data, vidsToResave.stream().collect( Collectors.toList() ) ); final ProgressWriter progressWriter = new ProgressWriterIJ(); - progressWriter.out().println( new Date( System.currentTimeMillis() ) + ": Saving " + n5Params.n5File.getAbsolutePath() ); + progressWriter.out().println( new Date( System.currentTimeMillis() ) + ": Saving " + n5Params.n5URI ); - // re-save data always if we have no cluster parameters, otherwise only if we asked for resave - if ( n5Params.saveData ) + //final Map< Integer, ExportMipmapInfo > proposedMipmaps; + if ( n5Params.proposedMipmaps == null ) { - //final Map< Integer, ExportMipmapInfo > proposedMipmaps; - if ( n5Params.proposedMipmaps == null ) - { - // propose downsampling - n5Params.proposedMipmaps = Resave_HDF5.proposeMipmaps( sdReduced.getSequenceDescription().getViewSetupsOrdered() ); - - // crude overwrite of block size (should be bigger than for normal hdf5) - n5Params.proposedMipmaps.keySet().forEach( k -> { - ExportMipmapInfo exportMipmapInfo = n5Params.proposedMipmaps.get( k ); - for (int[] row : exportMipmapInfo.getSubdivisions()) - { - Arrays.fill( row, N5Parameters.defaultBlockSize ); - row[ 0 ] = N5Parameters.defaultBlockSizeXY; - if ( row.length >= 2 ) - row[ 1 ] = N5Parameters.defaultBlockSizeXY; - } - }); - } + // propose downsampling + n5Params.proposedMipmaps = Resave_HDF5.proposeMipmaps( sdReduced.getSequenceDescription().getViewSetupsOrdered() ); - final Map< Integer, ExportMipmapInfo > proposedMipmaps = n5Params.proposedMipmaps; + // crude overwrite of block size (should be bigger than for normal hdf5) + n5Params.proposedMipmaps.keySet().forEach( k -> { + ExportMipmapInfo exportMipmapInfo = n5Params.proposedMipmaps.get( k ); + for (int[] row : exportMipmapInfo.getSubdivisions()) + { + Arrays.fill( row, ParametersResaveN5.defaultBlockSize ); + row[ 0 ] = ParametersResaveN5.defaultBlockSizeXY; + if ( row.length >= 2 ) + row[ 1 ] = ParametersResaveN5.defaultBlockSizeXY; + } + }); + } + // re-save data to file + if ( URITools.isFile( n5Params.n5URI ) ) + { try { WriteSequenceToN5.writeN5File( sdReduced.getSequenceDescription(), - proposedMipmaps, + n5Params.proposedMipmaps, n5Params.compression, //new GzipCompression() - n5Params.n5File, + new File( URITools.removeFilePrefix( n5Params.n5URI ) ), new bdv.export.ExportScalePyramid.DefaultLoopbackHeuristic(), null, n5Params.numCellCreatorThreads, // Runtime.getRuntime().availableProcessors() progressWriter ); - - if ( n5Params.setFinishedAttributeInN5 ) - { - final N5FSWriter n5 = new N5FSWriter( n5Params.n5File.getAbsolutePath() ); - - for (ViewId vid : vidsToResave) - n5.setAttribute( BdvN5Format.getPathName( vid.getViewSetupId(), vid.getTimePointId() ), N5Parameters.finishedAttrib, true); - } } catch ( IOException e ) { e.printStackTrace(); } } - - sdReduced.getSequenceDescription().setImgLoader( new N5ImageLoader( n5Params.n5File, sdReduced.getSequenceDescription() ) ); - sdReduced.setBasePath( n5Params.xmlFile.getParentFile() ); - - if ( n5Params.saveXML ) - { - try - { - new XmlIoSpimData2("").save( sdReduced, n5Params.xmlFile.getAbsolutePath() ); - } - catch ( SpimDataException e ) - { - e.printStackTrace(); - } - } - - progressWriter.setProgress( 1.0 ); - progressWriter.out().println( new Date( System.currentTimeMillis() ) + ": Finished saving " + n5Params.n5File.getAbsolutePath() ); - } - - private static class Arguments implements Serializable - { - private static final long serialVersionUID = -1467734459169624759L; - - @Option(name = "-i", aliases = { "--inputXMLPath" }, required = true, - usage = "Path to an input SpimData XML") - private String inputXMLPath; - - @Option(name = "-x", aliases = { "--outputXMLPath (default: input-n5.xml)" }, required = false, - usage = "Path to an output SpimData XML") - private String outputXMLPath = null; - - @Option(name = "-o", aliases = { "--outputContainerPath" }, required = false, - usage = "Path to an N5 container to store the output datasets (default: input.n5 with xml dropped)") - private String outputContainerPath = null; - - @Option(name = "-c", aliases = { "--compression" }, required = false, - usage = "Compression options bzip2, gzip, lz4, raw, xz (default: gzip)") - private String compression = "gzip"; - - @Option(name = "-t", aliases = { "--numThreads" }, required = false, - usage = "Number of threads used for saving, must be >= 1 (default: 1)") - private int numThreads = 1; - - @Option(name = "-b", aliases = { "--blocksizes" }, required = false, - usage = "Which block sizes to use, e.g. { { {64,64,64}, {64,64,64}, {64,64,64}, {64,64,64} }... (default: proposed by BigDataViewer)") - private String blocksize = null; - - @Option(name = "-s", aliases = { "--subsampling" }, required = false, - usage = "Which subsampling to use, e.g. { {1,1,1}, {2,2,2}, {4,4,4}, {8,8,8} }... (default: proposed by BigDataViewer)") - private String subsampling = null; - - @Option(name = "-v", aliases = { "--viewsToResave" }, required = false, - usage = "Which views to resave (timepoint,viewid),(,)... (default: all views)") - private String viewsToResave = null; - - @Option(name = "-nd", aliases = { "--noResaveData" }, required = false, - usage = "skips actual saving of data, so just XML is generated (default: false)") - private boolean noResaveData = false; - - @Option(name = "-nx", aliases = { "--noResaveXML" }, required = false, - usage = "skips actual saving of XML (default: false)") - private boolean noResaveXML = false; - - @Option(name = "-nfa", aliases = { "--noFinishAttribute" }, required = false, - usage = "skips setting a finish attribute after writing each View to the N5 (default: false)") - private boolean noFinishAttribute = false; - - public Arguments( final String... args ) throws IllegalArgumentException - { - final CmdLineParser parser = new CmdLineParser( this ); - try - { - parser.parseArgument( args ); - } - catch ( final CmdLineException e ) - { - System.err.println( e.getMessage() ); - parser.printUsage( System.err ); - System.exit( 1 ); - } - } - - public N5Parameters getParameters( final List< ViewId > viewIdsToResave ) - { - final N5Parameters n5params = new N5Parameters(); - - // make default paths from XML path if not provided - final String outXML = this.getOutputXMLPath() != null ? this.getOutputXMLPath() : this.getInputXMLPath().replace( ".xml", "-n5.xml" ); - final String outN5 = this.getOutputContainerPath() != null ? this.getOutputContainerPath() : this.getInputXMLPath().replace( ".xml", ".n5" ); - - n5params.n5File = new File(outN5); - n5params.xmlFile = new File(outXML); - - n5params.saveData = !this.isNoResaveData(); - n5params.saveXML = !this.isNoResaveXML(); - - if ( this.getCompression().toLowerCase().trim().equals( "bzip2" ) ) // "Bzip2", "Gzip", "Lz4", "Raw (no compression)", "Xz" - n5params.compression = new Bzip2Compression(); - else if ( this.getCompression().toLowerCase().trim().equals( "gzip" ) ) - n5params.compression = new GzipCompression(); - else if ( this.getCompression().toLowerCase().trim().equals( "lz4" ) ) - n5params.compression = new Lz4Compression(); - else if ( this.getCompression().toLowerCase().trim().equals( "xz" ) ) - n5params.compression = new XzCompression(); - else if ( this.getCompression().toLowerCase().trim().equals( "raw" ) ) - n5params.compression = new RawCompression(); - else - { - IOFunctions.println( "Cannot parse compression argument: " + this.getCompression() ); - return null; - } - - n5params.setFinishedAttributeInN5 = !this.isNoFinishAttrib(); - n5params.numCellCreatorThreads = Math.max( 1, this.getNumThreads() ); - - if ( this.getSubsampling() == null && this.getBlocksize() == null ) - { - n5params.proposedMipmaps = null; - } - else if ( this.getSubsampling() == null || this.getBlocksize() == null ) - { - IOFunctions.println( "You must define either subsampling AND blocksize or nothing of both." ); - IOFunctions.println( "Subsampling: " + this.getSubsampling() ); - IOFunctions.println( "Blocksize: " + this.getBlocksize() ); - - return null; - } - else - { - final int[][] resolutions = PluginHelper.parseResolutionsString( this.getSubsampling() ); - final int[][] subdivisions = PluginHelper.parseResolutionsString( this.getBlocksize() ); - - if ( resolutions.length == 0 ) - { - IOFunctions.println( "Cannot parse subsampling factors " + this.getSubsampling() ); - return null; - } - if ( subdivisions.length == 0 ) - { - IOFunctions.println( "Cannot parse hdf5 chunk sizes " + this.getBlocksize() ); - return null; - } - else if ( resolutions.length != subdivisions.length ) - { - IOFunctions.println( "subsampling factors and hdf5 chunk sizes must have the same number of elements" ); - return null; - } - - //final Hash - n5params.proposedMipmaps = N5Parameters.createProposedMipMaps( resolutions, subdivisions, viewIdsToResave.stream().map( vid -> vid.getViewSetupId() ).collect( Collectors.toSet() ) ); - } - - return n5params; - } - - public List< ViewId > getViewIdsToResave( final Set< ? extends ViewId > allViewDescriptions ) - { - // parse views to resave, or use all if not provided - final List< ViewId > vidsToResave = getViewsToResave() != null ? - parseViewIdString( getViewsToResave() ) : new ArrayList<>( allViewDescriptions ); - - for ( final ViewId v : vidsToResave ) - { - if ( !allViewDescriptions.contains( v ) ) - { - System.out.println( "Cannot resave ViewId " + Group.pvid( v ) + ", it is not part of the XML." ); - System.err.println( "Cannot resave ViewId " + Group.pvid( v ) + ", it is not part of the XML." ); - - return null; - } - } - - return vidsToResave; - } - - public static List parseViewIdString(String input) - { - final ArrayList result = new ArrayList<>(); - for (String vid : input.split( Pattern.quote( ")," ))) - { - String[] vidPair = vid.replace( ")", "" ).replace( "(", "" ).split( "," ); - result.add( new ViewId( Integer.parseInt( vidPair[0] ), Integer.parseInt( vidPair[1] ) ) ); - } - return result; - } - - public String getInputXMLPath() + else if ( URITools.isS3( n5Params.n5URI ) || URITools.isGC( n5Params.n5URI ) ) { - return inputXMLPath; + // TODO: save to cloud } - public String getOutputXMLPath() - { - return outputXMLPath; - } + sdReduced.getSequenceDescription().setImgLoader( new N5ImageLoader( n5Params.n5URI, sdReduced.getSequenceDescription() ) ); + sdReduced.setBasePathURI( n5Params.xmlURI ); - public String getOutputContainerPath() - { - return outputContainerPath; - } + progressWriter.out().println( new Date( System.currentTimeMillis() ) + ": Saving " + n5Params.xmlURI ); - public String getBlocksize() - { - return blocksize; - } + new XmlIoSpimData2().save( sdReduced, n5Params.xmlURI ); - public String getSubsampling() - { - return subsampling; - } - - public String getCompression() - { - return compression; - } - - public int getNumThreads() - { - return numThreads; - } - - public boolean isNoResaveData() - { - return noResaveData; - } - - public boolean isNoResaveXML() - { - return noResaveXML; - } - - public String getViewsToResave() - { - return viewsToResave; - } - - public boolean isNoFinishAttrib() - { - return noFinishAttribute; - } + progressWriter.setProgress( 1.0 ); + progressWriter.out().println( new Date( System.currentTimeMillis() ) + ": Finished saving " + n5Params.n5URI + " and " + n5Params.xmlURI ); } + public static void main(String[] args) { - /* new ImageJ(); new Resave_N5().run( null ); - SimpleMultiThreading.threadHaltUnClean(); - */ - - final Arguments parsedArgs = new Arguments( args ); - - // try to load SpimData - final HeadlessParseQueryXML xml = new HeadlessParseQueryXML(); - if ( !xml.loadXML( parsedArgs.getInputXMLPath(), false ) ) - { - IOFunctions.println( "Could not load xml: " + parsedArgs.getInputXMLPath() ); - return; - } - - final List< ViewId > viewIdsToResave = parsedArgs.getViewIdsToResave( xml.getData().getSequenceDescription().getViewDescriptions().keySet() ); - - if ( viewIdsToResave == null ) - return; - - final N5Parameters n5Params = parsedArgs.getParameters( viewIdsToResave ); - - if ( n5Params == null ) - return; - - resaveN5( xml.getData(), viewIdsToResave, n5Params ); } } diff --git a/src/main/java/net/preibisch/mvrecon/fiji/spimdata/XmlIoSpimData2.java b/src/main/java/net/preibisch/mvrecon/fiji/spimdata/XmlIoSpimData2.java index 50fb06633..e047c7aab 100644 --- a/src/main/java/net/preibisch/mvrecon/fiji/spimdata/XmlIoSpimData2.java +++ b/src/main/java/net/preibisch/mvrecon/fiji/spimdata/XmlIoSpimData2.java @@ -146,7 +146,7 @@ public void save( final SpimData2 spimData, String xmlPath ) throws SpimDataExce } } - public void save( final SpimData2 spimData, URI xmlURI ) + public boolean save( final SpimData2 spimData, URI xmlURI ) { try { @@ -156,11 +156,13 @@ public void save( final SpimData2 spimData, URI xmlURI ) { IOFunctions.println( "Failed to write XML / Copy backups / save interestpoints: " + e ); e.printStackTrace(); - return; + return false; } this.lastURI = xmlURI; // save also as zarr metadata object + + return true; } /** diff --git a/src/main/java/util/URITools.java b/src/main/java/util/URITools.java index a50041651..6308da54c 100644 --- a/src/main/java/util/URITools.java +++ b/src/main/java/util/URITools.java @@ -260,6 +260,11 @@ public static void copy( final KeyValueAccess kva, final String src, final Strin os.close(); } + public static boolean isKnownScheme( URI uri ) + { + return isFile( uri ) || isS3( uri ) || isGC( uri ); + } + public static boolean isGC( URI uri ) { final String scheme = uri.getScheme();