use of uk.ac.sussex.gdsc.test.junit5.SeededTest in project GDSC-SMLM by aherbert.
the class DynamicMultipleTargetTracingTest method checkBuilder.
@SeededTest
void checkBuilder(RandomSeed seed) {
final UniformRandomProvider rng = RngUtils.create(seed.getSeed());
final int temporalWindow = 2 + rng.nextInt(10);
final double localDiffusionWeight = rng.nextDouble();
final double diffusionCoefficientMaximum = 1 + rng.nextDouble();
final double onIntensityWeight = rng.nextDouble();
final double disappearanceDecayFactor = 1 + rng.nextDouble();
final int disappearanceThreshold = 1 + rng.nextInt(10);
final boolean disableIntensityModel = rng.nextBoolean();
final boolean disableLocalDiffusionModel = rng.nextBoolean();
final DmttConfiguration.Builder b = DmttConfiguration.newBuilder(45);
final DmttConfiguration c1 = b.setTemporalWindow(temporalWindow).setLocalDiffusionWeight(localDiffusionWeight).setDiffusionCoefficientMaximum(diffusionCoefficientMaximum).setOnIntensityWeight(onIntensityWeight).setDisappearanceDecayFactor(disappearanceDecayFactor).setDisappearanceThreshold(disappearanceThreshold).setDisableIntensityModel(disableIntensityModel).setDisableLocalDiffusionModel(disableLocalDiffusionModel).build();
// Check round-trip
for (final DmttConfiguration config : new DmttConfiguration[] { c1, c1.toBuilder().build() }) {
Assertions.assertEquals(diffusionCoefficientMaximum, config.getDiffusionCoefficientMaximum());
Assertions.assertEquals(temporalWindow, config.getTemporalWindow());
Assertions.assertEquals(localDiffusionWeight, config.getLocalDiffusionWeight());
Assertions.assertEquals(onIntensityWeight, config.getOnIntensityWeight());
Assertions.assertEquals(disappearanceDecayFactor, config.getDisappearanceDecayFactor());
Assertions.assertEquals(disappearanceThreshold, config.getDisappearanceThreshold());
Assertions.assertEquals(disableIntensityModel, config.isDisableIntensityModel());
Assertions.assertEquals(disableLocalDiffusionModel, config.isDisableLocalDiffusionModel());
}
}
use of uk.ac.sussex.gdsc.test.junit5.SeededTest in project GDSC-SMLM by aherbert.
the class ImageSourceTest method aggregatedInterlacedImageSourceCanReturnDataWithGet.
@SeededTest
void aggregatedInterlacedImageSourceCanReturnDataWithGet(RandomSeed seed) {
final int width = 5;
final int height = 3;
final int n = 15;
final float[][] data = createData(width, height, n);
final int aggregate = 3;
final int start = 4;
final int size = 2;
final int skip = 1;
final ImageSource source = new AggregatedImageSource(new InterlacedImageSource(new MemoryImageSource(width, height, data), start, size, skip), aggregate);
// Set the expected frames returned by the interlacing
final int[] expected = new int[] { 4, 5, 7, 8, 10, 11, 13, 14 };
// Randomly pick points from the positions used by next()
final int[] frames = new int[source.getFrames()];
for (int i = 0, ii = 0; ii < expected.length; i++, ii += 3) {
frames[i] = ii;
}
final UniformRandomProvider rg = RngUtils.create(seed.getSeed());
RandomUtils.shuffle(frames, rg);
Assertions.assertTrue(source.open());
for (int i = 0; i < frames.length; i++) {
// Get the range for the data
int startE = frames[i];
final int endE = Math.min(startE + 2, expected.length - 1);
final int startFrame = expected[startE];
final int endFrame = expected[endE];
// Get the data
final float[] d = source.get(startFrame);
// Check the correct range is returned
Assertions.assertEquals(startFrame, source.getStartFrameNumber());
Assertions.assertEquals(endFrame, source.getEndFrameNumber());
// Check the data is collated correctly
final float[] all = new float[data[0].length];
for (; startE <= endE; startE++) {
final int frame = expected[startE] - 1;
for (int j = 0; j < all.length; j++) {
all[j] += data[frame][j];
}
}
Assertions.assertArrayEquals(all, d);
}
// Check all the data is valid but skipped interlaced points return null
for (int i = 0; i < data.length; i++) {
final int frame = i + 1;
Assertions.assertTrue(source.isValid(frame));
if (!isExpected(frame, expected)) {
Assertions.assertNull(source.get(frame));
}
}
Assertions.assertFalse(source.isValid(0));
Assertions.assertFalse(source.isValid(data.length + 1));
}
use of uk.ac.sussex.gdsc.test.junit5.SeededTest in project GDSC-SMLM by aherbert.
the class ImageSourceTest method memoryImageSourceCanReturnCroppedDataWithGet.
@SeededTest
void memoryImageSourceCanReturnCroppedDataWithGet(RandomSeed seed) {
final int width = 5;
final int height = 3;
final Rectangle bounds = new Rectangle(2, 1, 3, 1);
final float[][] data = createData(width, height, 15);
final MemoryImageSource source = new MemoryImageSource(width, height, data);
final int[] frames = new int[data.length];
for (int i = 0; i < data.length; i++) {
frames[i] = i + 1;
}
final UniformRandomProvider rg = RngUtils.create(seed.getSeed());
RandomUtils.shuffle(frames, rg);
Assertions.assertTrue(source.open());
for (int i = 0; i < data.length; i++) {
final int frame = frames[i];
Assertions.assertTrue(source.isValid(frame));
final float[] next = source.get(frame, bounds);
Assertions.assertEquals(bounds.width * bounds.height, next.length);
Assertions.assertArrayEquals(crop(data[frame - 1], width, bounds), next);
}
Assertions.assertFalse(source.isValid(0));
Assertions.assertFalse(source.isValid(data.length + 1));
}
use of uk.ac.sussex.gdsc.test.junit5.SeededTest in project GDSC-SMLM by aherbert.
the class ImageSourceTest method interlacedImageSourceCanReturnDataWithGet.
@SeededTest
void interlacedImageSourceCanReturnDataWithGet(RandomSeed seed) {
final int width = 5;
final int height = 3;
final float[][] data = createData(width, height, 15);
final int start = 4;
final int size = 2;
final int skip = 1;
final ImageSource source = new InterlacedImageSource(new MemoryImageSource(width, height, data), start, size, skip);
final int[] frames = new int[data.length];
for (int i = 0; i < data.length; i++) {
frames[i] = i + 1;
}
final UniformRandomProvider rg = RngUtils.create(seed.getSeed());
RandomUtils.shuffle(frames, rg);
final int[] expected = new int[] { 4, 5, 7, 8, 10, 11, 13, 14 };
Assertions.assertTrue(source.open());
for (int i = 0; i < data.length; i++) {
final int frame = frames[i];
Assertions.assertTrue(source.isValid(frame));
final float[] d = source.get(frame);
if (isExpected(frame, expected)) {
Assertions.assertArrayEquals(data[frame - 1], d);
} else {
Assertions.assertNull(d);
}
}
Assertions.assertFalse(source.isValid(0));
Assertions.assertFalse(source.isValid(data.length + 1));
}
use of uk.ac.sussex.gdsc.test.junit5.SeededTest in project GDSC-SMLM by aherbert.
the class ImageSourceTest method aggregatedImageSourceCanReturnDataWithGet.
@SeededTest
void aggregatedImageSourceCanReturnDataWithGet(RandomSeed seed) {
final int width = 5;
final int height = 3;
final int aggregate = 3;
final float[][] data = createData(width, height, 15);
final ImageSource source = new AggregatedImageSource(new MemoryImageSource(width, height, data), aggregate);
final int[] frames = new int[data.length / 3];
for (int i = 0, frame = 1; i < frames.length; i++, frame += 3) {
frames[i] = frame;
}
final UniformRandomProvider rg = RngUtils.create(seed.getSeed());
RandomUtils.shuffle(frames, rg);
Assertions.assertTrue(source.open());
for (int i = 0; i < frames.length; i++) {
final int frame = frames[i];
Assertions.assertTrue(source.isValid(frame), () -> "Invalid frame " + frame);
final float[] d = source.get(frame);
Assertions.assertEquals(frame, source.getStartFrameNumber());
Assertions.assertEquals(frame + 2, source.getEndFrameNumber());
final float[] all = combine(data[frame - 1], data[frame], data[frame + 1]);
Assertions.assertArrayEquals(all, d, () -> "Invalid frame data " + frame);
}
Assertions.assertFalse(source.isValid(0));
Assertions.assertFalse(source.isValid(data.length + 1));
}
Aggregations