Skip to content

Commit

Permalink
adapt axes to new way of defining them
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Nov 25, 2024
1 parent 689ad55 commit 721f7b6
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
package io.bioimage.modelrunner.transformations;

import java.util.ArrayList;
import java.util.List;

import io.bioimage.modelrunner.tensor.Tensor;
import io.bioimage.modelrunner.utils.Constants;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.loops.LoopBuilder;
import net.imglib2.type.NativeType;
Expand Down Expand Up @@ -126,12 +128,29 @@ public void setOffset(Object offset) {
}
}

@SuppressWarnings("unchecked")
public void setAxes(Object axes) {
if (axes instanceof String )
this.axes = (String) axes;
else
else if (axes instanceof List) {
this.axes = "";
for (Object ax : (List<Object>) axes) {
if (!(ax instanceof String))
throw new IllegalArgumentException("JDLL does not currently support this axes format. Please "
+ "write an issue attaching the rdf.yaml file at: " + Constants.ISSUES_LINK);
ax = ax.equals("channel") ? "c" : ax;
this.axes += ax;
}
} else if (axes instanceof String[]) {
String[] axesArr = (String[]) axes;
this.axes = "";
for (String ax : axesArr) {
ax = ax.equals("channel") ? "c" : ax;
this.axes += ax;
}
} else
throw new IllegalArgumentException("'axes' parameter has to be an instance of " + String.class
+ ". The provided argument is " + axes.getClass());
+ ", of a String array or of a List of Strings. The provided argument is " + axes.getClass());
}

public void checkRequiredArgs() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
package io.bioimage.modelrunner.transformations;

import java.util.Arrays;
import java.util.List;

import io.bioimage.modelrunner.tensor.Tensor;

import io.bioimage.modelrunner.utils.Constants;
import net.imglib2.Cursor;
import net.imglib2.IterableInterval;
import net.imglib2.RandomAccessibleInterval;
Expand Down Expand Up @@ -96,12 +97,29 @@ public void setMaxPercentile(Object maxPercentile) {
}
}

@SuppressWarnings("unchecked")
public void setAxes(Object axes) {
if (axes instanceof String )
this.axes = (String) axes;
else
else if (axes instanceof List) {
this.axes = "";
for (Object ax : (List<Object>) axes) {
if (!(ax instanceof String))
throw new IllegalArgumentException("JDLL does not currently support this axes format. Please "
+ "write an issue attaching the rdf.yaml file at: " + Constants.ISSUES_LINK);
ax = ax.equals("channel") ? "c" : ax;
this.axes += ax;
}
} else if (axes instanceof String[]) {
String[] axesArr = (String[]) axes;
this.axes = "";
for (String ax : axesArr) {
ax = ax.equals("channel") ? "c" : ax;
this.axes += ax;
}
} else
throw new IllegalArgumentException("'axes' parameter has to be an instance of " + String.class
+ ". The provided argument is " + axes.getClass());
+ ", of a String array or of a List of Strings. The provided argument is " + axes.getClass());
}

public void setTensorName(Object tensorName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
package io.bioimage.modelrunner.transformations;

import java.util.ArrayList;
import java.util.List;

import io.bioimage.modelrunner.tensor.Tensor;

import io.bioimage.modelrunner.utils.Constants;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.img.array.ArrayImg;
import net.imglib2.img.array.ArrayImgs;
Expand Down Expand Up @@ -135,12 +136,29 @@ public void setStd(Object std) {
}
}

@SuppressWarnings("unchecked")
public void setAxes(Object axes) {
if (axes instanceof String )
this.axes = (String) axes;
else
else if (axes instanceof List) {
this.axes = "";
for (Object ax : (List<Object>) axes) {
if (!(ax instanceof String))
throw new IllegalArgumentException("JDLL does not currently support this axes format. Please "
+ "write an issue attaching the rdf.yaml file at: " + Constants.ISSUES_LINK);
ax = ax.equals("channel") ? "c" : ax;
this.axes += ax;
}
} else if (axes instanceof String[]) {
String[] axesArr = (String[]) axes;
this.axes = "";
for (String ax : axesArr) {
ax = ax.equals("channel") ? "c" : ax;
this.axes += ax;
}
} else
throw new IllegalArgumentException("'axes' parameter has to be an instance of " + String.class
+ ". The provided argument is " + axes.getClass());
+ ", of a String array or of a List of Strings. The provided argument is " + axes.getClass());
}

public void setMode(Object mode) {
Expand Down

0 comments on commit 721f7b6

Please sign in to comment.