Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused functions from ZarrAxes #120

Merged
merged 6 commits into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -370,34 +370,11 @@ private double[] getXYZScale(OmeZarrMultiscales.CoordinateTransformations coordi
double[] scale = coordinateTransformations.scale;
double[] xyzScale = null;
if (scale != null && zarrAxesList != null) {
int scalesFirstIndexBackward = scale.length - 1;
if (zarrAxes.hasChannels()) {
if (zarrAxes.is2D()) {
xyzScale = new double[]{
scale[scalesFirstIndexBackward],
scale[scalesFirstIndexBackward - 1],
1.0
};
} else {
xyzScale = new double[]{
scale[scalesFirstIndexBackward],
scale[scalesFirstIndexBackward - 1],
scale[scalesFirstIndexBackward - 2]};
}
} else {
if (zarrAxes.isSpatial3D()) {
xyzScale = new double[]{
scale[scalesFirstIndexBackward],
scale[scalesFirstIndexBackward - 1],
scale[scalesFirstIndexBackward - 2]};
} else {
xyzScale = new double[]{
scale[scalesFirstIndexBackward],
scale[scalesFirstIndexBackward - 1],
1.0
};
}
}
xyzScale = new double[]{
scale[zarrAxes.axisIndex("x", false)],
scale[zarrAxes.axisIndex("y", false)],
zarrAxes.hasZAxis() ? scale[zarrAxes.axisIndex("z", false)] : 1.0
};
}
return xyzScale;
}
Expand Down Expand Up @@ -429,10 +406,10 @@ private VoxelDimensions getVoxelDimensions3D(int setupId, int datasetId) {
String unit = zarrAxesList.get(zarrAxesList.size() - 1).getUnit();

if (scale != null && unit != null) {
if (zarrAxes.is2D()) {
return new FinalVoxelDimensions(unit, new double[]{scale[0], scale[1], 1.0});
} else {
if (zarrAxes.hasZAxis()) {
return new FinalVoxelDimensions(unit, scale);
} else {
return new FinalVoxelDimensions(unit, new double[]{scale[0], scale[1], 1.0});
}
}
}
Expand Down Expand Up @@ -591,16 +568,10 @@ private double[][] readMipmapResolutions() throws IOException {
for (int level = 1; level < mipmapResolutions.length; level++) {
long[] dimensions = getDatasetAttributes(getPathName(setupId, level)).getDimensions();
mipmapResolutions[level] = new double[3];
if (multiscale.axes.is2D()) {
for (int d = 0; d < 2; d++) {
mipmapResolutions[level][d] = Math.round(1.0 * dimensionsOfLevel0[d] / dimensions[d]);
}
mipmapResolutions[level][2] = 1.0;
} else {
for (int d = 0; d < 3; d++) {
mipmapResolutions[level][d] = 1.0 * dimensionsOfLevel0[d] / dimensions[d];
}
for (int d = 0; d < 2; d++) {
mipmapResolutions[level][d] = Math.round(1.0 * dimensionsOfLevel0[d] / dimensions[d]);
}
mipmapResolutions[level][2] = multiscale.axes.hasZAxis() ? Math.round(1.0 * dimensionsOfLevel0[2] / dimensions[2]) : 1.0;
}

return mipmapResolutions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,14 @@ public A createArray(DataBlock<?> dataBlock, long[] gridPosition) {

@Override
public long[] getCellDims(long[] gridPosition) {
long[] cellMin = new long[3];
int[] cellDims = new int[3];

// TODO: do something like in: private long[] toZarrChunkIndices( long[] gridPosition )
if (zarrAxes.is4DWithChannels() || zarrAxes.is4DWithTimepoints()) {
cellMin = new long[4];
cellDims = new int[4];
cellDims[3] = 1; // channel
}
long[] cellMin = new long[Math.max(zarrAxes.getNumDimension(), 3)];
constantinpape marked this conversation as resolved.
Show resolved Hide resolved
int[] cellDims = new int[Math.max(zarrAxes.getNumDimension(), 3)];

if (zarrAxes.is4DWithTimepointsAndChannels()) {
cellMin = new long[4];
cellDims = new int[4];
cellDims[2] = 1; // channel
cellDims[3] = 1; // timepoint
if(zarrAxes.hasChannels()) {
cellDims[zarrAxes.channelIndex()] = 1;
}

if (zarrAxes.is5D()) {
cellMin = new long[5];
cellDims = new int[5];
cellDims[3] = 1; // channel
cellDims[4] = 1; // timepoint
if(zarrAxes.hasTimepoints()) {
cellDims[zarrAxes.timeIndex()] = 1;
}

cellGrid.getCellDimensions(gridPosition, cellMin, cellDims);
Expand Down
50 changes: 13 additions & 37 deletions src/main/java/org/embl/mobie/io/ome/zarr/util/ZarrAxes.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,39 +83,6 @@ public List<ZarrAxis> toAxesList(String spaceUnit, String timeUnit) {
return zarrAxesList;
}

public boolean is2D() {
return this.axes.equals(YX.axes) || this.axes.equals(CYX.axes); // XYT XYC
}

public boolean is5D() {
return this.axes.equals(TCZYX.axes);
}

public boolean isSpatial3D() {
return this.axes.equals(CZYX.axes) || this.axes.equals(TZYX.axes) || this.axes.equals(ZYX.axes);
}

public boolean is4D() {
return this.axes.equals(CZYX.axes) || this.axes.equals(TZYX.axes) || this.axes.equals(TCYX.axes);
}

public boolean is3DWithTimepoints() {
return this.axes.equals(TYX.axes);
}

public boolean is4DWithTimepoints() {
return this.axes.equals(TZYX.axes);
}

public boolean is4DWithChannels() {
return this.axes.equals(CZYX.axes);
}

// not used anymore
public boolean is4DWithTimepointsAndChannels() {
return this.axes.equals(TCYX.axes);
}

public boolean hasTimepoints() {
return this.axes.equals(TCYX.axes) || this.axes.equals(TZYX.axes) || this.axes.equals(TYX.axes) ||
this.axes.equals(TCZYX.axes);
Expand All @@ -126,14 +93,23 @@ public boolean hasChannels() {
this.axes.equals(TCZYX.axes);
}

// the flag reverseAxes determines whether the index will be given w.r.t.
// reversedAxes=true corresponds to the java/bdv axis convention
// reversedAxes=false corresponds to the zarr axis convention
public int axisIndex(String axisName, boolean reverseAxes) {
constantinpape marked this conversation as resolved.
Show resolved Hide resolved
if(reverseAxes) {
List<String> reverseAxesList = Lists.reverse(getAxesList());
return reverseAxesList.indexOf(axisName);
}
return getAxesList().indexOf(axisName);
}

public int timeIndex() {
List<String> reverseAxesList = Lists.reverse(getAxesList());
return reverseAxesList.indexOf("t");
return axisIndex("t", true);
}

public int channelIndex() {
List<String> reverseAxesList = Lists.reverse(getAxesList());
return reverseAxesList.indexOf("c");
return axisIndex("c", true);
}

// spatial: 0,1,2 (x,y,z)
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/projects/remote/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public abstract class BaseTest extends BaseSpimDataChecker {
protected int expectedChannelsNumber = 1;
protected Dimensions expectedShape;
protected String expectedDType;
// TODO refactor the base test into a zarr base test so that we can also check for zarr specific attributes
// like the expected scale
//protected int [] expectedScale = null;

protected BaseTest(String path, ImageDataFormat format) throws SpimDataException {
super(new SpimDataOpener().openSpimData(path, format));
Expand All @@ -32,6 +35,9 @@ public void baseTest() {
Assertions.assertEquals(expectedChannelsNumber, getAllChannelsSize());
Assertions.assertEquals(expectedShape, getShape());
Assertions.assertEquals(expectedDType, getDType());
// if(expectedScale != null) {
// Assertions.assertEquals(expectedScale, getScale());
//}
}

public int getExpectedTimePoints() {
Expand Down