Skip to content

Commit

Permalink
fix: translation metadata output for multiscales export
Browse files Browse the repository at this point in the history
  • Loading branch information
bogovicj committed Apr 12, 2024
1 parent 5b1a6e3 commit c70dea5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@

<n5.version>3.2.0</n5.version>
<n5-hdf5.version>2.2.0</n5-hdf5.version>
<n5-imglib2.version>7.0.0</n5-imglib2.version>
<n5-google-cloud.version>4.1.0</n5-google-cloud.version>
<n5-universe.version>1.4.1</n5-universe.version>
<n5-universe.version>1.4.2-SNAPSHOT</n5-universe.version>
<n5-zarr.version>1.3.1</n5-zarr.version>
<n5-zstandard.version>1.0.2</n5-zstandard.version>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,10 +491,15 @@ public <T extends RealType<T> & NativeType<T>, M extends N5DatasetMetadata, N ex
RandomAccessibleInterval<T> currentChannelImg = channelImgs.get(c);
final int nd = currentChannelImg.numDimensions();

final double[] relativeTranslation = new double[nd];

// every channel starts at the original scale level reset downsampling factors to 1
currentAbsoluteDownsampling = new long[nd];
Arrays.fill(currentAbsoluteDownsampling, 1);

final double[] baseResolution = new double[nd];
Arrays.fill(baseResolution, 1);

final N multiscaleMetadata = initializeMultiscaleMetadata((M)currentMetadata, channelDataset);
currentTranslation = new double[nd];

Expand Down Expand Up @@ -524,12 +529,13 @@ public <T extends RealType<T> & NativeType<T>, M extends N5DatasetMetadata, N ex
else
return 0.0;
});

if (downsampleMethod.equals(DOWN_AVERAGE))
Arrays.fill(relativeTranslation, 0.5);
}

// update metadata to reflect this scale level, returns new metadata instance

// TODO needs to be relative downsampling
currentMetadata = (M)metadataForThisScale(dset, currentMetadata, relativeFactors, currentTranslation);
currentMetadata = (M)metadataForThisScale(dset, currentMetadata, downsampleMethod, relativeFactors, relativeTranslation);

// write to the appropriate dataset
// if dataset exists and not overwritten, don't write metadata
Expand Down Expand Up @@ -626,15 +632,28 @@ protected boolean lastScale(final int[] chunkSize, final Interval imageDimension
return false;
}

@SuppressWarnings("unchecked")
protected <M extends N5DatasetMetadata> M metadataForThisScale(final String newPath, final M baseMetadata, final long[] downsamplingFactors,
protected <M extends N5DatasetMetadata> M metadataForThisScale(final String newPath, final M baseMetadata,
final String downsampleMethod,
final long[] downsamplingFactors,
final double[] translation) {

return metadataForThisScale(newPath, baseMetadata, downsampleMethod,
Arrays.stream(downsamplingFactors).mapToDouble(x -> (double)x).toArray(),
translation);
}

@SuppressWarnings("unchecked")
protected <M extends N5DatasetMetadata> M metadataForThisScale(final String newPath, final M baseMetadata,
final String downsampleMethod,
final double[] relativeFactor,
final double[] relativeTranslation) {


if (baseMetadata instanceof SpatialModifiable) {
return (M)(((SpatialModifiable<?>)baseMetadata).modifySpatialTransform(
newPath,
Arrays.stream(downsamplingFactors).mapToDouble(x -> (double)x).toArray(),
translation));
relativeFactor,
relativeTranslation));
}

// System.err.println("WARNING: metadata not spatial modifiable");
Expand Down Expand Up @@ -1092,7 +1111,7 @@ private Compression getCompression() {
private final boolean promptOverwrite(final String dataset) {

return JOptionPane.showConfirmDialog(null,
String.format("Dataset (%s) already exists. Completely remove that dataa and overwrite?", dataset), "Warning",
String.format("Dataset (%s) already exists. Completely remove that data and overwrite?", dataset), "Warning",
JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.YES_OPTION;
}

Expand Down

0 comments on commit c70dea5

Please sign in to comment.