Skip to content

Commit

Permalink
First attempt to upgrade to scijava 37 and n5 3.0.2. Still get NPE in…
Browse files Browse the repository at this point in the history
… n5 read in SparkComputeCostMultiSem.
  • Loading branch information
trautmane committed Feb 11, 2024
1 parent a2a63c6 commit 7fad1a9
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 86 deletions.
20 changes: 10 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@
<modelVersion>4.0.0</modelVersion>
<groupId>saalfeldlab</groupId>
<artifactId>hot-knife</artifactId>
<version>0.0.4-SNAPSHOT</version>
<version>0.0.5-SNAPSHOT</version>
<parent>
<groupId>org.scijava</groupId>
<artifactId>pom-scijava</artifactId>
<version>32.0.0</version>
<version>37.0.0</version>
</parent>
<properties>
<enforcer.skip>true</enforcer.skip>
<package-name>org.janelia.saalfeldlab.hotknife</package-name>
<jackson-databind.version>2.6.7</jackson-databind.version>

<n5-imglib2.version>3.5.1</n5-imglib2.version>
<n5-hdf5.version>1.2.0</n5-hdf5.version>
<n5-aws-s3.version>3.2.0</n5-aws-s3.version>
<!-- <n5-blosc.version>1.1.0</n5-blosc.version> -->
<n5-zarr.version>0.0.6</n5-zarr.version>
<!-- <n5-imglib2.version>3.5.1</n5-imglib2.version>-->
<!-- <n5-hdf5.version>1.2.0</n5-hdf5.version>-->
<!-- <n5-aws-s3.version>3.2.0</n5-aws-s3.version>-->
<!-- &lt;!&ndash; <n5-blosc.version>1.1.0</n5-blosc.version> &ndash;&gt;-->
<!-- <n5-zarr.version>0.0.6</n5-zarr.version>-->
<n5-jpeg.version>0.0.1-beta1</n5-jpeg.version>
<n5-google-cloud>3.3.1</n5-google-cloud>
<!-- <n5-google-cloud>3.3.1</n5-google-cloud>-->

<!-- note: when upgrading to newer n5 versions, please also update render's n5 version to keep in sync -->
<n5.version>2.5.1</n5.version>
<n5-version>3.0.2</n5-version>

<n5-jpeg.version>0.0.1-beta1</n5-jpeg.version>
<!-- <n5-jpeg.version>0.0.1-beta1</n5-jpeg.version>-->
</properties>
<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,8 @@ static private void downsample(
System.out.println(Arrays.toString(gridPosition));

final RandomAccessibleInterval<FloatType> sourceBlock = Views.offsetInterval(subsampled, fOffset, croppedBlockSize);
try {
N5Utils.saveBlock(sourceBlock, n5, dataset, attributes, gridPosition);
} catch (final IOException e) {
e.printStackTrace();
}
}));
N5Utils.saveBlock(sourceBlock, n5, dataset, attributes, gridPosition);
}));

for (d = 0; d < n; ++d) {
offset[d] += blockSize[d];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,35 +362,32 @@ public static void processColumn(

System.out.println("Writing blocks");

try
{
// TODO: wrong dimensions
N5Writer n5w = new N5FSWriter(costN5Path);
// TODO: wrong dimensions
N5Writer n5w = new N5FSWriter(costN5Path);

// Now loop over blocks and write (for multisem, usually just one block in z)
for( int zGrid = 0; zGrid <= Math.ceil(zcorrSize[2] / zcorrBlockSize[2]); zGrid++ )
{
final long[] gridOffset = new long[]{gridCoord[0], gridCoord[1], zGrid }; //TODO: is this in original or cost steps?
// Now loop over blocks and write (for multisem, usually just one block in z)
for( int zGrid = 0; zGrid <= Math.ceil(zcorrSize[2] / zcorrBlockSize[2]); zGrid++ )
{
final long[] gridOffset = new long[]{gridCoord[0], gridCoord[1], zGrid }; //TODO: is this in original or cost steps?

System.out.println( "gridOffset: " + Util.printCoordinates( gridOffset ));
System.out.println( "gridOffset: " + Util.printCoordinates( gridOffset ));

RandomAccessibleInterval<UnsignedByteType> block = Views.interval(
Views.extendZero( cost ),
new FinalInterval(
new long[]{0, 0, zGrid * zcorrBlockSize[2]},
new long[]{cost.dimension(0) - 1, cost.dimension(1) - 1,(zGrid + 1) * zcorrBlockSize[2] - 1 }));
RandomAccessibleInterval<UnsignedByteType> block = Views.interval(
Views.extendZero( cost ),
new FinalInterval(
new long[]{0, 0, zGrid * zcorrBlockSize[2]},
new long[]{cost.dimension(0) - 1, cost.dimension(1) - 1,(zGrid + 1) * zcorrBlockSize[2] - 1 }));

System.out.println( "block: " + Util.printInterval( block ));
System.out.println( "block: " + Util.printInterval( block ));

N5Utils.saveBlock(
block,
n5w,
costDataset,
gridOffset);
}
} catch (IOException e) { throw new RuntimeException( "processColumn write blocks failed: ", e ); }
N5Utils.saveBlock(
block,
n5w,
costDataset,
gridOffset);
}

//SimpleMultiThreading.threadHaltUnClean();
//SimpleMultiThreading.threadHaltUnClean();
}

private static RandomAccessibleInterval<UnsignedByteType> mergeCosts(RandomAccessibleInterval<UnsignedByteType> topCost, RandomAccessibleInterval<UnsignedByteType> botCost) {
Expand Down Expand Up @@ -428,28 +425,24 @@ public static RandomAccessibleInterval<UnsignedByteType> processColumnAlongAxis(
final RandomAccessibleInterval<UnsignedByteType> maskRaw;
final RandomAccessible<UnsignedByteType> maskExtended;

try
{
zcorrRaw = N5Utils.open(new N5FSReader(n5Path), zcorrDataset);
zcorrRaw = N5Utils.open(new N5FSReader(n5Path), zcorrDataset);

if ( maskDataset != null )
{
maskRaw = N5Utils.open(new N5FSReader(n5Path), maskDataset);
if ( maskDataset != null )
{
maskRaw = N5Utils.open(new N5FSReader(n5Path), maskDataset);

if ( !Intervals.equals(zcorrRaw, maskRaw) )
throw new RuntimeException( "zCorrRaw interval [" + Util.printInterval(zcorrRaw) + "] and mask interval [" + Util.printInterval(maskRaw) + "] are not the same, quitting." );
if ( !Intervals.equals(zcorrRaw, maskRaw) )
throw new RuntimeException( "zCorrRaw interval [" + Util.printInterval(zcorrRaw) + "] and mask interval [" + Util.printInterval(maskRaw) + "] are not the same, quitting." );

maskExtended = Views.extendZero( maskRaw );
}
else
{
maskRaw = null;
maskExtended = null;
}

} catch (IOException e) { throw new RuntimeException( "Cannot load input zcorr data", e ); }
maskExtended = Views.extendZero( maskRaw );
}
else
{
maskRaw = null;
maskExtended = null;
}

// The cost function is implemented to be processed along dimension = 2, costAxis should be 0 or 2 with the current image data
// The cost function is implemented to be processed along dimension = 2, costAxis should be 0 or 2 with the current image data
// zcorr = Views.permute(zcorr, costAxis, 2);

final int outsideValue = 150; // TODO: global variable 170
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ private static void saveBlock(
for (int i = 0; i < sources.size(); ++i)
target.add(c.get(i));
},
UnsignedByteType::new);
new UnsignedByteType());
N5Utils.saveNonEmptyBlock(
Views.interval(
composite,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public Options(final String[] args) {

parsedSuccessfully = true;

} catch (final CmdLineException | IOException e) {
} catch (final CmdLineException e) {
System.err.println(e.getMessage());
parser.printUsage(System.err);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@
import net.imglib2.RandomAccess;
import net.imglib2.RandomAccessible;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.Sampler;
import net.imglib2.algorithm.gauss3.Gauss3;
import net.imglib2.algorithm.gauss3.SeparableSymmetricConvolution;
import net.imglib2.exception.IncompatibleTypeException;
import net.imglib2.img.display.imagej.ImageJFunctions;
import net.imglib2.type.NativeType;
import net.imglib2.type.numeric.RealType;
import net.imglib2.view.Views;
Expand Down Expand Up @@ -278,7 +276,7 @@ public void setPosition( final long position, final int d )
}

@Override
public Sampler< T > copy()
public RandomAccess<T> copy()
{
return copyRandomAccess();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,18 +285,14 @@ public void actionPerformed(final ActionEvent event) {
synchronized (viewer) {

viewer.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try {
final N5FSReader n5 = new N5FSReader(n5Path);
if (n5.datasetExists(heightFieldDataset)) {
final long[] dimensions = n5.getAttribute(heightFieldDataset, "dimensions", long[].class);
if (dimensions[0] == heightField.dimension(0) && dimensions[1] == heightField.dimension(1)) {
Util.copy(N5Utils.open(n5, heightFieldDataset), heightField);
}
}
} catch (final IOException e) {
e.printStackTrace();
}
viewer.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
final N5FSReader n5 = new N5FSReader(n5Path);
if (n5.datasetExists(heightFieldDataset)) {
final long[] dimensions = n5.getAttribute(heightFieldDataset, "dimensions", long[].class);
if (dimensions[0] == heightField.dimension(0) && dimensions[1] == heightField.dimension(1)) {
Util.copy(N5Utils.open(n5, heightFieldDataset), heightField);
}
}
viewer.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
viewer.requestRepaint();
}
}
Expand Down
11 changes: 3 additions & 8 deletions src/main/java/org/janelia/saalfeldlab/hotknife/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,10 @@ public static <T> T readRequiredAttribute(final N5FSReader n5Reader,
final String key,
final Class<T> clazz) throws IOException {
T value;
try {
value = n5Reader.getAttribute(groupName, key, clazz);
} catch (IOException e) {
throw new IOException("failed to read from " + getAttributesJsonPath(n5Reader.getBasePath(), groupName),
e);
}
if (value == null) {
value = n5Reader.getAttribute(groupName, key, clazz);
if (value == null) {
throw new IOException("required " + key + " attribute is missing from " +
getAttributesJsonPath(n5Reader.getBasePath(), groupName));
getAttributesJsonPath(n5Reader.getURI().getPath(), groupName));
}
return value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
import net.imglib2.RealLocalizable;
import net.imglib2.RealRandomAccess;
import net.imglib2.RealRandomAccessible;
import net.imglib2.Sampler;
import net.imglib2.type.Type;
import net.imglib2.type.numeric.RealType;
import net.imglib2.util.Util;
import net.preibisch.mvrecon.process.fusion.transformed.nonrigid.grid.NumericAffineModel3D;

public class NonRigidRealRandomAccess<T> implements RealRandomAccess<T>
Expand Down Expand Up @@ -189,5 +186,5 @@ public void setPosition( final long[] position )
public void setPosition( final long position, final int d ) { l[ d ] = position; }

@Override
public Sampler<T> copy() { return copyRealRandomAccess(); }
public RealRandomAccess<T> copy() { return copyRealRandomAccess(); }
}

0 comments on commit 7fad1a9

Please sign in to comment.