public static ImageFile makeMockFile(String filename, MockImageDescription...descriptions) {
final File f = new File(new File(System.getProperty("user.home")), filename);
final ImageFile imageFile = new ImageFile(f.toURI());
if (descriptions.length == 0) return imageFile;
OME ome = new OME();
List<Plate> plates = new ArrayList<Plate>();
for (MockImageDescription d:descriptions) {
Plate plate = null;
for (Plate qPlate:plates) {
if (qPlate.getName().equals(d.plate)) {
plate = qPlate;
break;
}
}
if (plate == null) {
plate = new Plate();
plate.setName(d.plate);
ome.addPlate(plate);
}
Well well = null;
int row = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf(d.well.substring(0, 1).toUpperCase());
int col = Integer.valueOf(d.well.substring(1));
for (int i=0; i<plate.sizeOfWellList(); i++) {
final Well qWell = plate.getWell(i);
if ((qWell.getRow().equals(row)) && (qWell.getColumn().equals(col))) {
well = qWell;
break;
}
}
if (well == null) {
well = new Well();
well.setRow(new NonNegativeInteger(row));
well.setColumn(new NonNegativeInteger(col));
well.setExternalDescription(d.well);
plate.addWell(well);
}
while (well.sizeOfWellSampleList() <= d.site) {
final WellSample qSample = new WellSample();
qSample.setIndex(new NonNegativeInteger(well.sizeOfWellSampleList()));
well.addWellSample(qSample);
}
final WellSample sample = well.getWellSample(d.site);
Image image = new Image();
Pixels pixels = new Pixels();
Channel [] channels = new Channel[d.sizeC];
for (int i=0; i<d.sizeC; i++) {
Channel c = new Channel();
c.setName(MockImageDescription.DEFAULT_CHANNEL_NAMES[i]);
pixels.addChannel(c);
channels[i] = c;
}
pixels.setSizeX(new PositiveInteger(d.sizeX));
pixels.setSizeY(new PositiveInteger(d.sizeY));
pixels.setSizeC(new PositiveInteger(d.sizeC));
pixels.setSizeZ(new PositiveInteger(d.sizeZ));
pixels.setSizeT(new PositiveInteger(d.sizeT));
pixels.setDimensionOrder(d.order);
for (int i=0; i<d.sizeC*d.sizeZ*d.sizeT; i++) {
int c=0, z=0, t=0;
switch(d.order) {
case XYCTZ:
c = i % d.sizeC;
t = (i / d.sizeC) % d.sizeT;
z = i / d.sizeC / d.sizeT;
break;
case XYCZT:
c = i % d.sizeC;
z = (i / d.sizeC) % d.sizeZ;
t = i / d.sizeC / d.sizeZ;
break;
case XYTCZ:
t = i % d.sizeT;
c = (i / d.sizeT) % d.sizeC;
z = i / d.sizeC / d.sizeT;
break;
case XYTZC:
t = i % d.sizeT;
z = (i / d.sizeT) % d.sizeZ;
c = i / d.sizeZ / d.sizeT;
break;
case XYZCT:
z = i % d.sizeZ;
c = (i / d.sizeZ) % d.sizeC;
t = i / d.sizeC / d.sizeZ;
break;
case XYZTC:
z = i % d.sizeZ;
t = (i / d.sizeZ) % d.sizeT;
c = i / d.sizeT / d.sizeZ;
break;
}
Plane plane = new Plane();
plane.setTheC(new NonNegativeInteger(c));
plane.setTheZ(new NonNegativeInteger(z));
plane.setTheT(new NonNegativeInteger(t));
pixels.addPlane(plane);
}
image.setPixels(pixels);
sample.linkImage(image);
ome.addImage(image);
}
imageFile.setXMLDocument(ome);
return imageFile;
}