Search in sources :

Example 1 with Workspace

use of io.github.mianalysis.mia.object.Workspace in project mia by mianalysis.

the class MIA_SetActiveWorkspace method action.

@Override
public String action(Object[] objects, Workspace workspace, Modules modules) {
    int workspaceID = (int) Math.round((Double) objects[0]);
    // Getting this workspace
    Workspace newActiveWorkspace = workspace.getWorkspaces().getWorkspace(workspaceID);
    // If this Workspace is present, change the active Workspace
    if (newActiveWorkspace != null)
        MacroHandler.setWorkspace(newActiveWorkspace);
    // Returning the active Workspace
    return String.valueOf(MacroHandler.getWorkspace().getID());
}
Also used : Workspace(io.github.mianalysis.mia.object.Workspace)

Example 2 with Workspace

use of io.github.mianalysis.mia.object.Workspace in project mia by mianalysis.

the class Exporter method prepareObjectsXLS.

private void prepareObjectsXLS(SXSSFWorkbook workbook, Workspaces workspaces, Modules modules) {
    // Creating bold font
    CellStyle cellStyle = workbook.createCellStyle();
    Font font = workbook.createFont();
    font.setBold(true);
    cellStyle.setFont(font);
    // Creating a new sheet for each object. Each analysed file has its own set of
    // rows (one for each object)
    HashMap<String, Sheet> objectSheets = new HashMap<>();
    HashMap<String, Integer> objectRows = new HashMap<>();
    // Creating a LinkedHashMap that links measurement names to column numbers. This
    // keeps the correct
    // measurements in the correct columns
    LinkedHashMap<String, LinkedHashMap<Integer, String>> measurementNames = new LinkedHashMap<>();
    LinkedHashMap<Integer, String> metadataNames = new LinkedHashMap<>();
    // Using the first workspace in the Workspaces to initialise column headers
    LinkedHashSet<OutputObjectsP> availableObjects = modules.getAvailableObjects(null, true);
    if (availableObjects == null)
        return;
    for (OutputObjectsP availableObject : availableObjects) {
        if (!availableObject.isExported())
            return;
        String objectName = availableObject.getObjectsName();
        // Check if this object has any associated measurements; if not, skip it
        if (!modules.objectsExportMeasurements(objectName))
            continue;
        // Creating relevant sheet prefixed with "OBJ"
        objectSheets.put(objectName, workbook.createSheet(objectName));
        objectRows.put(objectName, 1);
        Row objectHeaderRow = objectSheets.get(objectName).createRow(0);
        // Adding headers to each column
        int col = 0;
        Cell cell = objectHeaderRow.createCell(col++);
        cell.setCellValue("OBJECT_ID");
        cell.setCellStyle(cellStyle);
        String text = "ID number for this object.  Unique in the present image, but can be duplicated in other " + "images";
        addComment(cell, text);
        // Running through all the metadata values, adding them as new columns
        MetadataRefs metadataRefs = modules.getMetadataRefs(null);
        for (MetadataRef ref : metadataRefs.values()) {
            if (!ref.isExportGlobal())
                continue;
            if (!ref.isExportIndividual())
                continue;
            metadataNames.put(col, ref.getName());
            cell = objectHeaderRow.createCell(col++);
            cell.setCellValue(getMetadataString(ref.getName()));
            cell.setCellStyle(cellStyle);
        }
        // Running through all the object measurement values, adding them as new columns
        ObjMeasurementRefs objectMeasurementRefs = modules.getObjectMeasurementRefs(objectName);
        for (ObjMeasurementRef objectMeasurement : objectMeasurementRefs.values()) {
            if (!objectMeasurement.isExportIndividual())
                continue;
            if (!objectMeasurement.isExportGlobal())
                continue;
            measurementNames.putIfAbsent(objectName, new LinkedHashMap<>());
            measurementNames.get(objectName).put(col, objectMeasurement.getName());
            cell = objectHeaderRow.createCell(col++);
            addComment(cell, objectMeasurement.getDescription());
            cell.setCellValue(objectMeasurement.getNickname());
            cell.setCellStyle(cellStyle);
        }
    }
    // Running through each Workspace, adding rows
    for (Workspace workspace : workspaces) {
        for (String objectName : workspace.getObjects().keySet()) {
            Objs objects = workspace.getObjects().get(objectName);
            if (!modules.objectsExportMeasurements(objectName))
                continue;
            if (objects.values().iterator().hasNext()) {
                for (Obj object : objects.values()) {
                    if (objectSheets.get(objectName) == null || objectRows.get(objectName) == null)
                        continue;
                    Row objectValueRow = objectSheets.get(objectName).createRow(objectRows.get(objectName));
                    objectRows.compute(objectName, (k, v) -> v = v + 1);
                    Cell objectIDValueCell = objectValueRow.createCell(0);
                    objectIDValueCell.setCellValue(object.getID());
                    // Adding metadata (if enabled)
                    Metadata metadata = workspace.getMetadata();
                    for (int column : metadataNames.keySet()) {
                        Cell metaValueCell = objectValueRow.createCell(column);
                        metaValueCell.setCellValue(metadata.getAsString(metadataNames.get(column)));
                    }
                    if (measurementNames.get(objectName) == null)
                        continue;
                    // Adding measurements to the columns specified in measurementNames
                    for (int column : measurementNames.get(objectName).keySet()) {
                        Cell measValueCell = objectValueRow.createCell(column);
                        String measurementName = measurementNames.get(objectName).get(column);
                        Measurement measurement = object.getMeasurement(measurementName);
                        // If there isn't a corresponding value for this object, set a blank cell
                        if (measurement == null) {
                            measValueCell.setCellValue("");
                            continue;
                        }
                        // If the value is a NaN, also set a blank cell
                        if (Double.isNaN(measurement.getValue())) {
                            measValueCell.setCellValue("");
                            continue;
                        }
                        measValueCell.setCellValue(measurement.getValue());
                    }
                }
            }
        }
    }
}
Also used : Measurement(io.github.mianalysis.mia.object.Measurement) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Metadata(io.github.sjcross.common.metadataextractors.Metadata) Font(org.apache.poi.ss.usermodel.Font) LinkedHashMap(java.util.LinkedHashMap) OutputObjectsP(io.github.mianalysis.mia.object.parameters.objects.OutputObjectsP) ObjMeasurementRefs(io.github.mianalysis.mia.object.refs.collections.ObjMeasurementRefs) Obj(io.github.mianalysis.mia.object.Obj) MetadataRef(io.github.mianalysis.mia.object.refs.MetadataRef) Objs(io.github.mianalysis.mia.object.Objs) Cell(org.apache.poi.ss.usermodel.Cell) MetadataRefs(io.github.mianalysis.mia.object.refs.collections.MetadataRefs) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CellStyle(org.apache.poi.ss.usermodel.CellStyle) Row(org.apache.poi.ss.usermodel.Row) ObjMeasurementRef(io.github.mianalysis.mia.object.refs.ObjMeasurementRef) Sheet(org.apache.poi.ss.usermodel.Sheet) Workspace(io.github.mianalysis.mia.object.Workspace)

Example 3 with Workspace

use of io.github.mianalysis.mia.object.Workspace in project mia by mianalysis.

the class Exporter method prepareSummary.

private void prepareSummary(SXSSFWorkbook workbook, Workspaces workspaces, Modules modules, SummaryMode summaryType) {
    AtomicInteger headerCol = new AtomicInteger(0);
    // Adding header rows for the metadata sheet.
    Sheet summarySheet = workbook.createSheet("Summary");
    Row summaryHeaderRow = summarySheet.createRow(0);
    // Creating a HashMap to store column numbers
    HashMap<String, Integer> colNumbers = new HashMap<>();
    addSummaryMetadataHeaders(summaryHeaderRow, modules, colNumbers, headerCol, summaryType);
    addSummaryGroupHeader(summaryHeaderRow, colNumbers, headerCol, summaryType);
    addSummaryImageHeaders(summaryHeaderRow, modules, colNumbers, headerCol);
    addSummaryObjectHeaders(summaryHeaderRow, modules, colNumbers, headerCol);
    // Running through each Workspace, adding a row
    int summaryRow = 1;
    switch(summaryType) {
        case PER_FILE:
            for (Workspace workspace : workspaces) {
                if (!workspace.exportWorkspace())
                    continue;
                Row summaryValueRow = summarySheet.createRow(summaryRow++);
                populateSummaryRow(summaryValueRow, workspace, modules, colNumbers, null, null);
            }
            break;
        case PER_TIMEPOINT_PER_FILE:
            for (Workspace workspace : workspaces) {
                if (!workspace.exportWorkspace())
                    continue;
                // For the current workspace, iterating over all available time points and
                // creating a new workspace
                HashMap<Integer, Workspace> currentWorkspaces = workspace.getSingleTimepointWorkspaces();
                for (Integer timepoint : currentWorkspaces.keySet()) {
                    Workspace currentWorkspace = currentWorkspaces.get(timepoint);
                    Row summaryValueRow = summarySheet.createRow(summaryRow++);
                    populateSummaryRow(summaryValueRow, currentWorkspace, modules, colNumbers, "TIMEPOINT", String.valueOf(timepoint));
                }
            }
            break;
        case GROUP_BY_METADATA:
            HashMap<String, Workspace> metadataWorkspaces = workspaces.getMetadataWorkspaces(metadataItemForSummary);
            for (String metadataValue : metadataWorkspaces.keySet()) {
                Workspace currentWorkspace = metadataWorkspaces.get(metadataValue);
                if (!currentWorkspace.exportWorkspace())
                    continue;
                Row summaryValueRow = summarySheet.createRow(summaryRow++);
                populateSummaryRow(summaryValueRow, currentWorkspace, modules, colNumbers, metadataItemForSummary, metadataValue);
            }
            break;
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet) Workspace(io.github.mianalysis.mia.object.Workspace)

Example 4 with Workspace

use of io.github.mianalysis.mia.object.Workspace in project mia by mianalysis.

the class NormaliseIntensityTest method testNormaliseIntensity8bit2D.

@Test
public void testNormaliseIntensity8bit2D() throws Exception {
    // Creating a new workspace
    Workspaces workspaces = new Workspaces();
    Workspace workspace = workspaces.getNewWorkspace(null, 1);
    // Loading the test image and adding to workspace
    String pathToImage = URLDecoder.decode(this.getClass().getResource("/images/normaliseintensity/DarkNoisyGradient2D_8bit.zip").getPath(), "UTF-8");
    ImagePlus ipl = IJ.openImage(pathToImage);
    Image image = new Image("Test_image", ipl);
    workspace.addImage(image);
    pathToImage = URLDecoder.decode(this.getClass().getResource("/images/normaliseintensity/DarkNoisyGradientNormalised2D_8bit.zip").getPath(), "UTF-8");
    Image expectedImage = new Image("Expected", IJ.openImage(pathToImage));
    // Initialising BinaryOperations
    NormaliseIntensity normaliseIntensity = new NormaliseIntensity(new Modules());
    normaliseIntensity.updateParameterValue(NormaliseIntensity.INPUT_IMAGE, "Test_image");
    normaliseIntensity.updateParameterValue(NormaliseIntensity.APPLY_TO_INPUT, false);
    normaliseIntensity.updateParameterValue(NormaliseIntensity.OUTPUT_IMAGE, "Test_output");
    // Running NormaliseIntensity
    normaliseIntensity.execute(workspace);
    // Checking the images in the workspace
    assertEquals(2, workspace.getImages().size());
    assertNotNull(workspace.getImage("Test_image"));
    assertNotNull(workspace.getImage("Test_output"));
    // Checking the output image has the expected calibration
    Image outputImage = workspace.getImage("Test_output");
    assertEquals(expectedImage, outputImage);
}
Also used : Modules(io.github.mianalysis.mia.module.Modules) Workspaces(io.github.mianalysis.mia.object.Workspaces) Image(io.github.mianalysis.mia.object.Image) ImagePlus(ij.ImagePlus) Workspace(io.github.mianalysis.mia.object.Workspace) Test(org.junit.jupiter.api.Test) ModuleTest(io.github.mianalysis.mia.module.ModuleTest)

Example 5 with Workspace

use of io.github.mianalysis.mia.object.Workspace in project mia by mianalysis.

the class NormaliseIntensityTest method testNormaliseIntensity16bit3D.

@Test
public void testNormaliseIntensity16bit3D() throws Exception {
    // Creating a new workspace
    Workspaces workspaces = new Workspaces();
    Workspace workspace = workspaces.getNewWorkspace(null, 1);
    // Loading the test image and adding to workspace
    String pathToImage = URLDecoder.decode(this.getClass().getResource("/images/normaliseintensity/DarkNoisyGradient3D_16bit.zip").getPath(), "UTF-8");
    ImagePlus ipl = IJ.openImage(pathToImage);
    Image image = new Image("Test_image", ipl);
    workspace.addImage(image);
    pathToImage = URLDecoder.decode(this.getClass().getResource("/images/normaliseintensity/DarkNoisyGradientNormalised3D_16bit.zip").getPath(), "UTF-8");
    Image expectedImage = new Image("Expected", IJ.openImage(pathToImage));
    // Initialising BinaryOperations
    NormaliseIntensity normaliseIntensity = new NormaliseIntensity(new Modules());
    normaliseIntensity.updateParameterValue(NormaliseIntensity.INPUT_IMAGE, "Test_image");
    normaliseIntensity.updateParameterValue(NormaliseIntensity.APPLY_TO_INPUT, false);
    normaliseIntensity.updateParameterValue(NormaliseIntensity.OUTPUT_IMAGE, "Test_output");
    // Running NormaliseIntensity
    normaliseIntensity.execute(workspace);
    // Checking the images in the workspace
    assertEquals(2, workspace.getImages().size());
    assertNotNull(workspace.getImage("Test_image"));
    assertNotNull(workspace.getImage("Test_output"));
    // Checking the output image has the expected calibration
    Image outputImage = workspace.getImage("Test_output");
    assertEquals(expectedImage, outputImage);
}
Also used : Modules(io.github.mianalysis.mia.module.Modules) Workspaces(io.github.mianalysis.mia.object.Workspaces) Image(io.github.mianalysis.mia.object.Image) ImagePlus(ij.ImagePlus) Workspace(io.github.mianalysis.mia.object.Workspace) Test(org.junit.jupiter.api.Test) ModuleTest(io.github.mianalysis.mia.module.ModuleTest)

Aggregations

Workspace (io.github.mianalysis.mia.object.Workspace)429 Workspaces (io.github.mianalysis.mia.object.Workspaces)418 Image (io.github.mianalysis.mia.object.Image)341 ImagePlus (ij.ImagePlus)323 ModuleTest (io.github.mianalysis.mia.module.ModuleTest)304 Test (org.junit.jupiter.api.Test)304 Modules (io.github.mianalysis.mia.module.Modules)235 Objs (io.github.mianalysis.mia.object.Objs)113 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)112 EnumSource (org.junit.jupiter.params.provider.EnumSource)112 Obj (io.github.mianalysis.mia.object.Obj)109 Objects3D (io.github.mianalysis.mia.expectedobjects.Objects3D)79 Parameters (io.github.mianalysis.mia.object.parameters.Parameters)36 File (java.io.File)26 SpatCal (io.github.sjcross.common.object.volume.SpatCal)23 Disabled (org.junit.jupiter.api.Disabled)19 CropImage (io.github.mianalysis.mia.module.images.transform.CropImage)18 Status (io.github.mianalysis.mia.object.Status)15 CalculateNearestNeighbour (io.github.mianalysis.mia.module.objects.measure.spatial.CalculateNearestNeighbour)10 Objects2D (io.github.mianalysis.mia.expectedobjects.Objects2D)7