Skip to content

Commit d1ed79f

Browse files
committed
BIG WIP: convert ops.run usage to OpBuilder calls
1 parent 908ff50 commit d1ed79f

68 files changed

Lines changed: 550 additions & 397 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/test/java/net/imagej/ops/coloc/icq/LiICQTest.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import net.imglib2.type.numeric.real.FloatType;
4343

4444
import org.junit.Test;
45+
import org.scijava.ops.core.builder.OpBuilder;
4546
import org.scijava.ops.function.Functions;
4647
import org.scijava.ops.types.Nil;
4748
import org.scijava.thread.ThreadService;
@@ -58,22 +59,18 @@ public void testICQ() {
5859
final Img<ByteType> img1 = generateByteArrayTestImg(true, 10, 15, 20);
5960
final Img<ByteType> img2 = generateByteArrayTestImg(true, 10, 15, 20);
6061

61-
final Object icqValue = ops.run("coloc.icq", img1, img2);
62+
final Double icqValue = new OpBuilder(ops, "coloc.icq").input(img1, img2).outType(Double.class).apply();
6263

63-
assertTrue(icqValue instanceof Double);
64-
assertEquals(0.5, (Double) icqValue, 0.0);
64+
assertEquals(0.5, icqValue, 0.0);
6565
}
6666

6767
/**
6868
* Checks Li's ICQ value for positive correlated images.
6969
*/
7070
@Test
7171
public void liPositiveCorrTest() {
72-
final Object icqValue = ops.run("coloc.icq", positiveCorrelationImageCh1, positiveCorrelationImageCh2);
73-
74-
assertTrue(icqValue instanceof Double);
75-
final double icq = (Double) icqValue;
76-
assertTrue(icq > 0.34 && icq < 0.35);
72+
final Double icqValue = new OpBuilder(ops, "coloc.icq").input(positiveCorrelationImageCh1, positiveCorrelationImageCh2).outType(Double.class).apply();
73+
assertTrue(icqValue > 0.34 && icqValue < 0.35);
7774
}
7875

7976
/**
@@ -82,7 +79,7 @@ public void liPositiveCorrTest() {
8279
*/
8380
@Test
8481
public void liZeroCorrTest() {
85-
final Object icqValue = ops.run("coloc.icq", zeroCorrelationImageCh1, zeroCorrelationImageCh2);
82+
final Object icqValue = new OpBuilder(ops, "coloc.icq").input(zeroCorrelationImageCh1, zeroCorrelationImageCh2).apply();
8683

8784
assertTrue(icqValue instanceof Double);
8885
final double icq = (Double) icqValue;
@@ -105,7 +102,7 @@ public void testPValue() {
105102
BiFunction<Iterable<FloatType>, Iterable<FloatType>, Double> op = Functions.match(ops, "coloc.icq",
106103
new Nil<Iterable<FloatType>>() {}, new Nil<Iterable<FloatType>>() {}, new Nil<Double>() {});
107104
PValueResult value = new PValueResult();
108-
ops.run("coloc.pValue", ch1, ch2, op, es, value);
105+
new OpBuilder(ops, "coloc.pValue").input(ch1, ch2, op, es).output(value).compute();
109106
assertEquals(0.72, value.getPValue(), 0.0);
110107
}
111108

src/test/java/net/imagej/ops/coloc/kendallTau/KendallTauBRankTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public void exhaustiveKendallTauBRankTesting() {
104104
//final PairIterator<DoubleType> iter = pairIterator(values1, values2);
105105
final Iterable<Pair<IntType, IntType>> iter = new IterablePair<>(ArrayImgs.ints(values1, n), ArrayImgs.ints(values2, n));
106106
double kendallValue1 = calculateNaive(iter.iterator());
107-
double kendallValue2 = (Double) ops.run("coloc.kendallTau", values1, values2);
107+
double kendallValue2 = (Double) new OpBuilder(ops, "coloc.kendallTau").input(values1, values2).apply();
108108
if (Double.isNaN(kendallValue1)) {
109109
assertTrue("i: " + i + ", value2: " + kendallValue2, Double.isInfinite(kendallValue2) || Double.isNaN(kendallValue2));
110110
} else {
@@ -127,7 +127,7 @@ public void testPValue() {
127127
BiFunction<Iterable<FloatType>, Iterable<FloatType>, Double> op = Functions.match(ops,
128128
"coloc.kendallTau", nilI, nilI, new Nil<Double>() {});
129129
PValueResult value = new PValueResult();
130-
ops.run("coloc.pValue", ch1, ch2, op, es, value);
130+
new OpBuilder(ops, "coloc.pValue").input(ch1, ch2, op, es, value).apply();
131131
assertEquals(0.75, value.getPValue(), 0.0);
132132
}
133133

@@ -139,7 +139,7 @@ private int pseudoRandom()
139139
}
140140

141141
private <T extends RealType<T>, U extends RealType<U>> void assertTau(final double expected, final Iterable<T> img1, final Iterable<U> img2) {
142-
final double kendallValue = (double) ops.run("coloc.kendallTau", img1, img2);
142+
final double kendallValue = (double) new OpBuilder(ops, "coloc.kendallTau").input(img1, img2).apply();
143143
assertEquals(expected, kendallValue, 1e-10);
144144
}
145145

src/test/java/net/imagej/ops/coloc/maxTKendallTau/MTKTTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public void testMTKTnone() {
147147
}
148148
Img<DoubleType> vImage1 = ArrayImgs.doubles(values1, values1.length);
149149
Img<DoubleType> vImage2 = ArrayImgs.doubles(values2, values2.length);
150-
double result = (Double) ops.run("coloc.maxTKendallTau", vImage1, vImage2);
150+
double result = (Double) new OpBuilder(ops, "coloc.maxTKendallTau").input(vImage1, vImage2).apply();
151151
assertEquals(4.9E-324, result, 0.0);
152152
}
153153

@@ -163,7 +163,7 @@ public void testMTKTall() {
163163
}
164164
Img<DoubleType> vImage1 = ArrayImgs.doubles(values1, values1.length);
165165
Img<DoubleType> vImage2 = ArrayImgs.doubles(values2, values2.length);
166-
double result = (Double) ops.run("coloc.maxTKendallTau", vImage1, vImage2);
166+
double result = (Double) new OpBuilder(ops, "coloc.maxTKendallTau").input(vImage1, vImage2).apply();
167167
assertEquals(1.0, result, 0.0);
168168
}
169169

@@ -177,7 +177,7 @@ public void testMTKTrandom() {
177177
0x01234567);
178178
Img<FloatType> ch2 = ColocalisationTest.produceMeanBasedNoiseImage(new FloatType(), 24, 24, mean, spread, sigma,
179179
0x98765432);
180-
double result = (Double) ops.run("coloc.maxTKendallTau", ch1, ch2);
180+
double result = (Double) new OpBuilder(ops, "coloc.maxTKendallTau").input(ch1, ch2).apply();
181181
assertEquals(2.710687382741972, result, 0.0);
182182
}
183183

@@ -188,7 +188,7 @@ public void testMTKTimage() {
188188
new long[] { 0, 0, 0 }, new long[] { 20, 20, 0 });
189189
RandomAccessibleInterval<UnsignedByteType> cropCh2 = Views.interval(zeroCorrelationImageCh2,
190190
new long[] { 0, 0, 0 }, new long[] { 20, 20, 0 });
191-
double result = (Double) ops.run("coloc.maxTKendallTau", cropCh1, cropCh2);
191+
double result = (Double) new OpBuilder(ops, "coloc.maxTKendallTau").input(cropCh1, cropCh2).apply();
192192
assertEquals(2.562373279563565, result, 0.0);
193193
}
194194

@@ -210,7 +210,7 @@ public void testMTKTpValueNone() {
210210
BiFunction<RandomAccessibleInterval<DoubleType>, RandomAccessibleInterval<DoubleType>, Double> op =
211211
Functions.match(ops, "coloc.maxTKendallTau", new Nil<RandomAccessibleInterval<DoubleType>>() {}, new Nil<RandomAccessibleInterval<DoubleType>>() {}, new Nil<Double>() {});
212212
PValueResult value = new PValueResult();
213-
ops.run("coloc.pValue", vImage1, vImage2, op, 5, es, value);
213+
new OpBuilder(ops, "coloc.pValue").input(vImage1, vImage2, op, 5, es, value).apply();
214214
assertEquals(0.0, value.getPValue(), 0.0);
215215
}
216216

@@ -230,7 +230,7 @@ public void testMTKTpValueAll() {
230230
BiFunction<RandomAccessibleInterval<DoubleType>, RandomAccessibleInterval<DoubleType>, Double> op =
231231
Functions.match(ops, "coloc.maxTKendallTau", new Nil<RandomAccessibleInterval<DoubleType>>() {}, new Nil<RandomAccessibleInterval<DoubleType>>() {}, new Nil<Double>() {});
232232
PValueResult value = new PValueResult();
233-
ops.run("coloc.pValue", vImage1, vImage2, op, 5, es, value);
233+
new OpBuilder(ops, "coloc.pValue").input(vImage1, vImage2, op, 5, es, value).apply();
234234
assertEquals(0.0, value.getPValue(), 0.0);
235235
}
236236

@@ -248,7 +248,7 @@ public void testMTKTpValueRandom() {
248248
BiFunction<RandomAccessibleInterval<FloatType>, RandomAccessibleInterval<FloatType>, Double> op =
249249
Functions.match(ops, "coloc.maxTKendallTau", new Nil<RandomAccessibleInterval<FloatType>>() {}, new Nil<RandomAccessibleInterval<FloatType>>() {}, new Nil<Double>() {});
250250
PValueResult value = new PValueResult();
251-
ops.run("coloc.pValue", ch1, ch2, op, 10, es, value);
251+
new OpBuilder(ops, "coloc.pValue").input(ch1, ch2, op, 10, es, value).apply();
252252
assertEquals(0.2, value.getPValue(), 0.0);
253253
}
254254

@@ -270,7 +270,7 @@ public void testMTKTpValueImage() {
270270
RandomAccessibleInterval<UnsignedByteType> ch1 = ShuffledView.cropAtMin(cropCh1, blockSize);
271271
RandomAccessibleInterval<UnsignedByteType> ch2 = ShuffledView.cropAtMin(cropCh2, blockSize);
272272
PValueResult value = new PValueResult();
273-
ops.run("coloc.pValue", ch1, ch2, op, 5, es, value);
273+
new OpBuilder(ops, "coloc.pValue").input(ch1, ch2, op, 5, es, value).apply();
274274
assertEquals(0.2, value.getPValue(), 0.0);
275275
}
276276
}

src/test/java/net/imagej/ops/coloc/pValue/DefaultPValueTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ private void assertColoc(double expectedPValue, double expectedColocValue, doubl
9999
// new Nil<BiFunction<Iterable<FloatType>, Iterable<FloatType>, Double>>() {}.getType());
100100

101101
PValueResult output = new PValueResult();
102-
ops.run("coloc.pValue", ch1, ch2, op, result.length - 1, es, output);
102+
new OpBuilder(ops, "coloc.pValue").input(ch1, ch2, op, result.length - 1, es, output).apply();
103103
Double actualPValue = output.getPValue();
104104
Double actualColocValue = output.getColocValue();
105105
double[] actualColocValuesArray = output.getColocValuesArray();

src/test/java/net/imagej/ops/coloc/pearsons/DefaultPearsonsTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public class DefaultPearsonsTest extends ColocalisationTest {
5757
*/
5858
@Test
5959
public void fastPearsonsZeroCorrTest(){
60-
double result = (Double) ops.run("coloc.pearsons", zeroCorrelationImageCh1, zeroCorrelationImageCh2);
60+
double result = (Double) new OpBuilder(ops, "coloc.pearsons").input(zeroCorrelationImageCh1, zeroCorrelationImageCh2).apply();
6161
assertEquals(0.0, result, 0.05);
6262
}
6363

@@ -67,7 +67,7 @@ public void fastPearsonsZeroCorrTest(){
6767
*/
6868
@Test
6969
public void fastPearsonsPositiveCorrTest() {
70-
double result = (Double) ops.run("coloc.pearsons", positiveCorrelationImageCh1, positiveCorrelationImageCh2);
70+
double result = (Double) new OpBuilder(ops, "coloc.pearsons").input(positiveCorrelationImageCh1, positiveCorrelationImageCh2).apply();
7171
assertEquals(0.75, result, 0.01);
7272
}
7373

@@ -86,7 +86,7 @@ public void differentMeansTest() {
8686
512, 512, mean, spread, sigma, 0x01234567);
8787
RandomAccessibleInterval<FloatType> ch2 = produceMeanBasedNoiseImage(new FloatType(),
8888
512, 512, mean, spread, sigma, 0x98765432);
89-
double resultFast = (Double) ops.run("coloc.pearsons", ch1, ch2);
89+
double resultFast = (Double) new OpBuilder(ops, "coloc.pearsons").input(ch1, ch2).apply();
9090
assertEquals(0.0, resultFast, 0.1);
9191

9292
/* If the means are the same, it causes a numerical problem in the classic implementation of Pearson's
@@ -109,7 +109,7 @@ public void testPValue() {
109109
BiFunction<Iterable<FloatType>, Iterable<FloatType>, Double> op =
110110
Functions.match(ops, "coloc.pearsons", new Nil<Iterable<FloatType>>() {}, new Nil<Iterable<FloatType>>() {}, new Nil<Double>() {});
111111
PValueResult value = new PValueResult();
112-
ops.run("coloc.pValue", ch1, ch2, op, es, value);
112+
new OpBuilder(ops, "coloc.pValue").input(ch1, ch2, op, es, value).apply();
113113
assertEquals(0.66, value.getPValue(), 0.0);
114114
}
115115

src/test/java/net/imagej/ops/convert/ConvertIIsTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ public class ConvertIIsTest extends AbstractOpTest {
5757
@Before
5858
public void createImages() {
5959
final FinalDimensions dims = FinalDimensions.wrap(new long[] {10, 10});
60-
in = (IterableInterval<ShortType>) ops.run("create.img", dims, new ShortType());
60+
in = (IterableInterval<ShortType>) new OpBuilder(ops, "create.img").input(dims, new ShortType()).apply();
6161
addNoise(in);
62-
out = (Img<ByteType>) ops.run("create.img", dims, new ByteType());
62+
out = (Img<ByteType>) new OpBuilder(ops, "create.img").input(dims, new ByteType()).apply();
6363
}
6464

6565
@Test
6666
public void testClip() {
67-
ops.run("convert.clip", in, out);
67+
new OpBuilder(ops, "convert.clip").input(in, out).apply();
6868

6969
final Cursor<ShortType> c = in.localizingCursor();
7070
final RandomAccess<ByteType> ra = out.randomAccess();
@@ -77,7 +77,7 @@ public void testClip() {
7777

7878
@Test
7979
public void testCopy() {
80-
ops.run("convert.copy", in, out);
80+
new OpBuilder(ops, "convert.copy").input(in, out).apply();
8181

8282
final Cursor<ShortType> c = in.localizingCursor();
8383
final RandomAccess<ByteType> ra = out.randomAccess();
@@ -91,8 +91,8 @@ public void testCopy() {
9191
// -- Helper methods --
9292

9393
private void addNoise(final IterableInterval<ShortType> image) {
94-
IterableInterval<ShortType> copy = (IterableInterval<ShortType>) ops.run("copy.img", image);
95-
ops.run("filter.addNoise", copy, -32768., 32767., 10000., image);
94+
IterableInterval<ShortType> copy = (IterableInterval<ShortType>) new OpBuilder(ops, "copy.img").input(image).apply();
95+
new OpBuilder(ops, "filter.addNoise").input(copy, -32768., 32767., 10000., image).apply();
9696
}
9797

9898
private byte clip(final short value) {

src/test/java/net/imagej/ops/convert/ConvertMapTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public void testLossless() {
7272
outC1.next().getRealDouble(), 0d);
7373
}
7474

75-
ops.run("convert.float32", in, out);
75+
new OpBuilder(ops, "convert.float32").input(in, out).apply();
7676

7777
// ops.run(Ops.Map.class, out, in, new ComplexToFloat32<UnsignedByteType>());
7878

@@ -95,7 +95,7 @@ public void testLossy() {
9595
final byte[] outArray = { 4, 123, 18, 64, 90, 120, 12, 17, 73 };
9696
final Img<UnsignedByteType> out = generateUnsignedByteImg(outArray);
9797

98-
ops.run("convert.uint8", in, out);
98+
new OpBuilder(ops, "convert.uint8").input(in, out).apply();
9999
// ops.run(Ops.Map.class, out, in, new ComplexToUint8<FloatType>());
100100

101101
final Cursor<FloatType> inC = in.cursor();

src/test/java/net/imagej/ops/copy/CopyArrayImgTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public void copyArrayImgWithOutputTest() {
8686
final Img<UnsignedByteType> output = input.factory().create(input,
8787
input.firstElement());
8888

89-
ops.run("copy.img", input, output);
89+
new OpBuilder(ops, "copy.img").input(input, output).apply();
9090

9191
final Cursor<UnsignedByteType> inc = input.cursor();
9292
final Cursor<UnsignedByteType> outc = output.cursor();

src/test/java/net/imagej/ops/copy/CopyIITest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public void copyTypeTest() {
8888
Img<FloatType> inputFloat = new ArrayImgFactory<>(new FloatType()).create(new int[] { 120, 100 });
8989

9090
@SuppressWarnings("unchecked")
91-
Img<FloatType> output = (Img<FloatType>) ops.run("copy.iterableInterval", inputFloat);
91+
Img<FloatType> output = (Img<FloatType>) new OpBuilder(ops, "copy.iterableInterval").input(inputFloat).apply();
9292

9393
assertTrue("Should be FloatType.", output.firstElement() instanceof FloatType);
9494
}
@@ -97,7 +97,7 @@ public void copyTypeTest() {
9797
public void copyRAIWithOutputTest() {
9898
Img<DoubleType> output = input.factory().create(input, input.firstElement());
9999

100-
ops.run("copy.iterableInterval", output, input);
100+
new OpBuilder(ops, "copy.iterableInterval").input(output, input).apply();
101101

102102
final Cursor<DoubleType> inc = input.cursor();
103103
final Cursor<DoubleType> outc = output.cursor();

src/test/java/net/imagej/ops/copy/CopyImgLabelingTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void createData() {
7474

7575
@Test
7676
public void copyImgLabeling() {
77-
ops.run("copy.imgLabeling", input, copy);
77+
new OpBuilder(ops, "copy.imgLabeling").input(input, copy).apply();
7878
assertNotNull(copy);
7979

8080
Cursor<LabelingType<String>> inCursor = input.cursor();

0 commit comments

Comments
 (0)