Skip to content

Commit

Permalink
fix: use MetadataUtils.relative paths where applicable
Browse files Browse the repository at this point in the history
* and add more tests
  • Loading branch information
bogovicj committed Apr 18, 2024
1 parent 2e642a1 commit 561a636
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
package org.janelia.saalfeldlab.n5.universe.metadata.ome.ngff.v04;

import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.stream.DoubleStream;

Expand Down Expand Up @@ -139,11 +137,9 @@ private static OmeNgffDataset[] buildDatasets( final String path, final NgffSing
for( int i = 0; i < children.length; i++ )
{
datasets[i] = new OmeNgffDataset();
// final Path p = Paths.get(path);
// final Path c = Paths.get(children[i].getPath());
// datasets[i].path = p.relativize(c).toString();
datasets[i].path = Paths.get(path).relativize(Paths.get(children[i].getPath())).toString();
datasets[i].path = MetadataUtils.relativePath(path, children[i].getPath());
datasets[i].coordinateTransformations = children[i].getCoordinateTransformations();

}
return datasets;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,7 @@ public void addChild(final int idx, final NgffSingleScaleAxesMetadata child) {

final OmeNgffDataset dset = new OmeNgffDataset();
// paths are relative to this object
try {
dset.path = N5URI.normalizeGroupPath(
N5URI.from("", getPath(), "").resolve(N5URI.from("", child.getPath(), ""))
.getGroupPath());
} catch (URISyntaxException e) { }

dset.path = MetadataUtils.relativePath(getPath(), child.getPath());
dset.coordinateTransformations = child.getCoordinateTransformations();
if (idx < 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.junit.Assert.assertEquals;

import org.janelia.saalfeldlab.n5.N5URI;
import org.janelia.saalfeldlab.n5.universe.metadata.axes.Axis;
import org.janelia.saalfeldlab.n5.universe.metadata.axes.AxisUtils;
import org.junit.Test;
Expand Down Expand Up @@ -40,6 +41,16 @@ private static void testHelper(final String path, final String[] childPaths) {
for (int i = 0; i < childPaths.length; i++) {
assertEquals(childPaths[i], meta.getDatasets()[i].path);
}

// test building children from multiscales
// these metadata's path variables must be relative to the root
final NgffSingleScaleAxesMetadata[] children = OmeNgffMultiScaleMetadata.buildMetadata(3, path, null, meta);
for (int i = 0; i < childPaths.length; i++) {
// ensure the paths are equal up to normalization
assertEquals(
N5URI.normalizeGroupPath(path + "/" + childPaths[i]),
N5URI.normalizeGroupPath(children[i].getPath()));
}
}

private static NgffSingleScaleAxesMetadata buildScaleLevelMetadata(final String path, final double[] res,
Expand Down

0 comments on commit 561a636

Please sign in to comment.