Search in sources :

Example 1 with PeakResultDataOrigX

use of uk.ac.sussex.gdsc.smlm.results.data.PeakResultDataOrigX in project GDSC-SMLM by aherbert.

the class PeakResultTableModel method createTableStructure.

/**
 * Called when the structure of the table should be created. If the structure has not changed or
 * no live table are attached then this does nothing.
 *
 * @param changed Set to true if a property controlling the structure has changed
 */
private void createTableStructure(boolean changed) {
    if (changed) {
        columnsComputed.set(false);
    }
    // so it can be turned off by PeakResultTableModelFrame.
    if (liveCount.get() == 0 || columnsComputed.get()) {
        return;
    }
    columnsComputed.set(true);
    rounder = RounderUtils.create(tableSettings.getRoundingPrecision());
    // Create the converters
    final PeakResultConversionHelper helper = new PeakResultConversionHelper(calibration, psf);
    helper.setIntensityUnit(tableSettings.getIntensityUnit());
    helper.setDistanceUnit(tableSettings.getDistanceUnit());
    helper.setAngleUnit(tableSettings.getAngleUnit());
    final Converter[] converters = helper.getConverters();
    final Converter ic = converters[PeakResult.INTENSITY];
    final String[] paramNames = helper.getNames();
    final String[] unitNames = helper.getUnitNames();
    // Calibration tableCalibration = (helper.isCalibrationChanged()) ? helper.getCalibration() :
    // calibration;
    // Organise the data columns.
    // This is done as per the IJTablePeakResults for consistency
    final LocalList<PeakResultData<?>> valuesList = new LocalList<>();
    final LocalList<String> namesList = new LocalList<>();
    rowCounter = tableSettings.getShowRowCounter();
    if (rowCounter) {
        valuesList.add(new PeakResultDataFrame());
        namesList.add("#");
    }
    valuesList.add(new PeakResultDataFrame());
    addName(valuesList, namesList);
    if (showEndFrame) {
        valuesList.add(new PeakResultDataEndFrame());
        addName(valuesList, namesList);
    }
    if (showId) {
        valuesList.add(new PeakResultDataId());
        addName(valuesList, namesList);
    }
    if (showCategory) {
        valuesList.add(new PeakResultDataCategory());
        addName(valuesList, namesList);
    }
    if (tableSettings.getShowFittingData()) {
        valuesList.add(new PeakResultDataOrigX());
        addName(valuesList, namesList);
        valuesList.add(new PeakResultDataOrigY());
        addName(valuesList, namesList);
        valuesList.add(new PeakResultDataOrigValue());
        addName(valuesList, namesList);
        valuesList.add(new PeakResultDataError());
        addName(valuesList, namesList);
    }
    if (tableSettings.getShowNoiseData()) {
        // Must be converted
        valuesList.add(new PeakResultDataFloat() {

            @Override
            public Float getValue(PeakResult result) {
                return ic.convert(result.getNoise());
            }
        });
        addName("Noise", namesList, unitNames[PeakResult.INTENSITY]);
        valuesList.add(new PeakResultDataFloat() {

            @Override
            public Float getValue(PeakResult result) {
                return ic.convert(result.getMeanIntensity());
            }
        });
        addName("Mean" + paramNames[PeakResult.INTENSITY], namesList, unitNames[PeakResult.INTENSITY]);
        valuesList.add(new PeakResultDataSnr());
        addName(valuesList, namesList);
    }
    int[] outIndices = SimpleArrayUtils.natural(converters.length);
    if (!showZ) {
        final TIntArrayList list = new TIntArrayList(outIndices);
        list.remove(PeakResult.Z);
        outIndices = list.toArray();
    }
    for (final int i : outIndices) {
        // Must be converted
        valuesList.add(new PeakResultDataParameterConverter(converters[i], i));
        addName(paramNames[i], namesList, unitNames[i]);
        if (showDeviations) {
            valuesList.add(new PeakResultDataParameterDeviationConverter(converters[i], i));
            namesList.add("+/-");
        }
    }
    if (tableSettings.getShowPrecision()) {
        PeakResultDataPrecision precision = null;
        try {
            final Gaussian2DPeakResultCalculator calculator = Gaussian2DPeakResultHelper.create(getPsf(), calibration, Gaussian2DPeakResultHelper.LSE_PRECISION);
            precision = new PeakResultDataPrecision() {

                @Override
                public Double getValue(PeakResult result) {
                    if (result.hasPrecision()) {
                        return result.getPrecision();
                    }
                    if (calculator != null) {
                        return calculator.getLsePrecision(result.getParameters(), result.getNoise());
                    }
                    return 0.0;
                }
            };
        } catch (final ConfigurationException | ConversionException ex) {
        // Ignore
        }
        if (precision == null) {
            precision = new PeakResultDataPrecision();
        }
        valuesList.add(precision);
        namesList.add("Precision (nm)");
    }
    values = valuesList.toArray(new PeakResultData<?>[0]);
    names = namesList.toArray(new String[0]);
    fireTableStructureChanged();
}
Also used : PeakResultDataId(uk.ac.sussex.gdsc.smlm.results.data.PeakResultDataId) PeakResultDataParameterConverter(uk.ac.sussex.gdsc.smlm.results.data.PeakResultDataParameterConverter) PeakResult(uk.ac.sussex.gdsc.smlm.results.PeakResult) LocalList(uk.ac.sussex.gdsc.core.utils.LocalList) Gaussian2DPeakResultCalculator(uk.ac.sussex.gdsc.smlm.results.Gaussian2DPeakResultCalculator) PeakResultDataOrigValue(uk.ac.sussex.gdsc.smlm.results.data.PeakResultDataOrigValue) ConfigurationException(uk.ac.sussex.gdsc.smlm.data.config.ConfigurationException) PeakResultDataParameterDeviationConverter(uk.ac.sussex.gdsc.smlm.results.data.PeakResultDataParameterDeviationConverter) PeakResultDataParameterConverter(uk.ac.sussex.gdsc.smlm.results.data.PeakResultDataParameterConverter) Converter(uk.ac.sussex.gdsc.core.data.utils.Converter) PeakResultDataPrecision(uk.ac.sussex.gdsc.smlm.results.data.PeakResultDataPrecision) PeakResultData(uk.ac.sussex.gdsc.smlm.results.PeakResultData) ConversionException(uk.ac.sussex.gdsc.core.data.utils.ConversionException) PeakResultDataFrame(uk.ac.sussex.gdsc.smlm.results.data.PeakResultDataFrame) PeakResultDataFloat(uk.ac.sussex.gdsc.smlm.results.data.PeakResultDataFloat) PeakResultDataSnr(uk.ac.sussex.gdsc.smlm.results.data.PeakResultDataSnr) PeakResultDataParameterDeviationConverter(uk.ac.sussex.gdsc.smlm.results.data.PeakResultDataParameterDeviationConverter) TIntArrayList(gnu.trove.list.array.TIntArrayList) PeakResultDataEndFrame(uk.ac.sussex.gdsc.smlm.results.data.PeakResultDataEndFrame) PeakResultDataOrigX(uk.ac.sussex.gdsc.smlm.results.data.PeakResultDataOrigX) PeakResultDataError(uk.ac.sussex.gdsc.smlm.results.data.PeakResultDataError) PeakResultDataFloat(uk.ac.sussex.gdsc.smlm.results.data.PeakResultDataFloat) PeakResultDataOrigY(uk.ac.sussex.gdsc.smlm.results.data.PeakResultDataOrigY) PeakResultDataCategory(uk.ac.sussex.gdsc.smlm.results.data.PeakResultDataCategory) PeakResultConversionHelper(uk.ac.sussex.gdsc.smlm.results.PeakResultConversionHelper)

Aggregations

TIntArrayList (gnu.trove.list.array.TIntArrayList)1 ConversionException (uk.ac.sussex.gdsc.core.data.utils.ConversionException)1 Converter (uk.ac.sussex.gdsc.core.data.utils.Converter)1 LocalList (uk.ac.sussex.gdsc.core.utils.LocalList)1 ConfigurationException (uk.ac.sussex.gdsc.smlm.data.config.ConfigurationException)1 Gaussian2DPeakResultCalculator (uk.ac.sussex.gdsc.smlm.results.Gaussian2DPeakResultCalculator)1 PeakResult (uk.ac.sussex.gdsc.smlm.results.PeakResult)1 PeakResultConversionHelper (uk.ac.sussex.gdsc.smlm.results.PeakResultConversionHelper)1 PeakResultData (uk.ac.sussex.gdsc.smlm.results.PeakResultData)1 PeakResultDataCategory (uk.ac.sussex.gdsc.smlm.results.data.PeakResultDataCategory)1 PeakResultDataEndFrame (uk.ac.sussex.gdsc.smlm.results.data.PeakResultDataEndFrame)1 PeakResultDataError (uk.ac.sussex.gdsc.smlm.results.data.PeakResultDataError)1 PeakResultDataFloat (uk.ac.sussex.gdsc.smlm.results.data.PeakResultDataFloat)1 PeakResultDataFrame (uk.ac.sussex.gdsc.smlm.results.data.PeakResultDataFrame)1 PeakResultDataId (uk.ac.sussex.gdsc.smlm.results.data.PeakResultDataId)1 PeakResultDataOrigValue (uk.ac.sussex.gdsc.smlm.results.data.PeakResultDataOrigValue)1 PeakResultDataOrigX (uk.ac.sussex.gdsc.smlm.results.data.PeakResultDataOrigX)1 PeakResultDataOrigY (uk.ac.sussex.gdsc.smlm.results.data.PeakResultDataOrigY)1 PeakResultDataParameterConverter (uk.ac.sussex.gdsc.smlm.results.data.PeakResultDataParameterConverter)1 PeakResultDataParameterDeviationConverter (uk.ac.sussex.gdsc.smlm.results.data.PeakResultDataParameterDeviationConverter)1