Search in sources :

Example 31 with Range

use of org.apache.commons.lang3.Range in project Asqatasun by Asqatasun.

the class Rgaa40Rule110202Test method setProcess.

@Override
protected void setProcess() {
    // ----------------------------------------------------------------------
    // ------------------------------3NMI-01---------------------------------
    // ----------------------------------------------------------------------
    ProcessResult processResult = processPageTest("Rgaa40.Test.11.2.2-3NMI-01");
    checkResultIsPreQualified(processResult, 2, 2);
    checkRemarkIsPresent(processResult, TestSolution.NEED_MORE_INFO, RemarkMessageStore.MANUAL_CHECK_ON_ELEMENTS_MSG, HtmlElementStore.INPUT_ELEMENT, 1, new ImmutablePair(TITLE_ATTR, "title for input without type attribute (implicit text)"));
    checkRemarkIsPresent(processResult, TestSolution.NEED_MORE_INFO, RemarkMessageStore.MANUAL_CHECK_ON_ELEMENTS_MSG, HtmlElementStore.INPUT_ELEMENT, 2, new ImmutablePair(TITLE_ATTR, "title for input with type equal to text"));
    // ----------------------------------------------------------------------
    // ------------------------------3NMI-02---------------------------------
    // ----------------------------------------------------------------------
    processResult = processPageTest("Rgaa40.Test.11.2.2-3NMI-02");
    checkResultIsPreQualified(processResult, 17, 17);
    HashMap<Integer, String> mapTypeAttribute = new HashMap<Integer, String>();
    mapTypeAttribute.put(1, "checkbox");
    mapTypeAttribute.put(2, "color");
    mapTypeAttribute.put(3, "date");
    mapTypeAttribute.put(4, "datetime-local");
    mapTypeAttribute.put(5, "email");
    mapTypeAttribute.put(6, "file");
    mapTypeAttribute.put(7, "month");
    mapTypeAttribute.put(8, "number");
    mapTypeAttribute.put(9, "password");
    mapTypeAttribute.put(10, "radio");
    mapTypeAttribute.put(11, "range");
    mapTypeAttribute.put(12, "search");
    mapTypeAttribute.put(13, "tel");
    mapTypeAttribute.put(14, "text");
    mapTypeAttribute.put(15, "time");
    mapTypeAttribute.put(16, "url");
    mapTypeAttribute.put(17, "week");
    for (Map.Entry item : mapTypeAttribute.entrySet()) {
        int position = ((int) item.getKey());
        checkRemarkIsPresent(processResult, TestSolution.NEED_MORE_INFO, RemarkMessageStore.MANUAL_CHECK_ON_ELEMENTS_MSG, HtmlElementStore.INPUT_ELEMENT, position, new ImmutablePair(TITLE_ATTR, "title for input with type equal to " + item.getValue()));
    }
    // ----------------------------------------------------------------------
    // ------------------------------3NMI-03---------------------------------
    // ----------------------------------------------------------------------
    processResult = processPageTest("Rgaa40.Test.11.2.2-3NMI-03");
    checkResultIsPreQualified(processResult, 1, 1);
    checkRemarkIsPresent(processResult, TestSolution.NEED_MORE_INFO, RemarkMessageStore.MANUAL_CHECK_ON_ELEMENTS_MSG, HtmlElementStore.TEXTAREA_ELEMENT, 1, new ImmutablePair(TITLE_ATTR, "title value for TEXTAREA"));
    // ----------------------------------------------------------------------
    // ------------------------------3NMI-04---------------------------------
    // ----------------------------------------------------------------------
    processResult = processPageTest("Rgaa40.Test.11.2.2-3NMI-04");
    checkResultIsPreQualified(processResult, 3, 3);
    checkRemarkIsPresent(processResult, TestSolution.NEED_MORE_INFO, RemarkMessageStore.MANUAL_CHECK_ON_ELEMENTS_MSG, HtmlElementStore.SELECT_ELEMENT, 1, new ImmutablePair(TITLE_ATTR, "title value for SELECT"));
    checkRemarkIsPresent(processResult, TestSolution.NEED_MORE_INFO, RemarkMessageStore.MANUAL_CHECK_ON_ELEMENTS_MSG, HtmlElementStore.OPTGROUP_ELEMENT, 2, new ImmutablePair(TITLE_ATTR, "title value for OPTGROUP"));
    checkRemarkIsPresent(processResult, TestSolution.NEED_MORE_INFO, RemarkMessageStore.MANUAL_CHECK_ON_ELEMENTS_MSG, HtmlElementStore.OPTION_ELEMENT, 3, new ImmutablePair(TITLE_ATTR, "title value for OPTION"));
    // ----------------------------------------------------------------------
    // ------------------------------3NMI-05---------------------------------
    // ----------------------------------------------------------------------
    processResult = processPageTest("Rgaa40.Test.11.2.2-3NMI-05");
    checkResultIsPreQualified(processResult, 1, 1);
    checkRemarkIsPresent(processResult, TestSolution.NEED_MORE_INFO, RemarkMessageStore.MANUAL_CHECK_ON_ELEMENTS_MSG, HtmlElementStore.DATALIST_ELEMENT, 1, new ImmutablePair(TITLE_ATTR, "title value for DATALIST"));
    // ----------------------------------------------------------------------
    // ------------------------------3NMI-06---------------------------------
    // ----------------------------------------------------------------------
    processResult = processPageTest("Rgaa40.Test.11.2.2-3NMI-06");
    checkResultIsPreQualified(processResult, 3, 3);
    checkRemarkIsPresent(processResult, TestSolution.NEED_MORE_INFO, RemarkMessageStore.MANUAL_CHECK_ON_ELEMENTS_MSG, HtmlElementStore.PROGRESS_ELEMENT, 1, new ImmutablePair(TITLE_ATTR, "title value for PROGRESS"));
    checkRemarkIsPresent(processResult, TestSolution.NEED_MORE_INFO, RemarkMessageStore.MANUAL_CHECK_ON_ELEMENTS_MSG, HtmlElementStore.OUTPUT_ELEMENT, 2, new ImmutablePair(TITLE_ATTR, "title value for OUTPUT"));
    checkRemarkIsPresent(processResult, TestSolution.NEED_MORE_INFO, RemarkMessageStore.MANUAL_CHECK_ON_ELEMENTS_MSG, HtmlElementStore.METER_ELEMENT, 3, new ImmutablePair(TITLE_ATTR, "title value for METER"));
    // ----------------------------------------------------------------------
    // ------------------------------3NMI-07---------------------------------
    // ----------------------------------------------------------------------
    processResult = processPageTest("Rgaa40.Test.11.2.2-3NMI-07");
    checkResultIsPreQualified(processResult, 11, 11);
    HashMap<Integer, String> mapRoleAttribute = new HashMap<Integer, String>();
    mapRoleAttribute.put(1, "checkbox");
    mapRoleAttribute.put(2, "combobox");
    mapRoleAttribute.put(3, "listbox");
    mapRoleAttribute.put(4, "progressbar");
    mapRoleAttribute.put(5, "option");
    mapRoleAttribute.put(6, "radio");
    mapRoleAttribute.put(7, "searchbox");
    mapRoleAttribute.put(8, "slider");
    mapRoleAttribute.put(9, "spinbutton");
    mapRoleAttribute.put(10, "switch");
    mapRoleAttribute.put(11, "textbox");
    for (Map.Entry item : mapRoleAttribute.entrySet()) {
        int position = ((int) item.getKey());
        checkRemarkIsPresent(processResult, TestSolution.NEED_MORE_INFO, RemarkMessageStore.MANUAL_CHECK_ON_ELEMENTS_MSG, HtmlElementStore.DIV_ELEMENT, position, new ImmutablePair(TITLE_ATTR, "title value for ROLE " + item.getValue()));
    }
    // ----------------------------------------------------------------------
    // ------------------------------3NMI-08---------------------------------
    // ----------------------------------------------------------------------
    processResult = processPageTest("Rgaa40.Test.11.2.2-3NMI-08");
    checkResultIsPreQualified(processResult, 1, 1);
    checkRemarkIsPresent(processResult, TestSolution.NEED_MORE_INFO, RemarkMessageStore.MANUAL_CHECK_ON_ELEMENTS_MSG, HtmlElementStore.INPUT_ELEMENT, 1, new ImmutablePair(TITLE_ATTR, "title for input without parent form tag"));
    // ----------------------------------------------------------------------
    // ------------------------------4NA-01----------------------------------
    // ----------------------------------------------------------------------
    checkResultIsNotApplicable(processPageTest("Rgaa40.Test.11.2.2-4NA-01"));
    // ----------------------------------------------------------------------
    // ------------------------------4NA-02----------------------------------
    // ----------------------------------------------------------------------
    checkResultIsNotApplicable(processPageTest("Rgaa40.Test.11.2.2-4NA-02"));
    // ----------------------------------------------------------------------
    // ------------------------------4NA-03----------------------------------
    // ----------------------------------------------------------------------
    checkResultIsNotApplicable(processPageTest("Rgaa40.Test.11.2.2-4NA-03"));
    // ----------------------------------------------------------------------
    // ------------------------------4NA-04----------------------------------
    // ----------------------------------------------------------------------
    checkResultIsNotApplicable(processPageTest("Rgaa40.Test.11.2.2-4NA-04"));
    // ----------------------------------------------------------------------
    // ------------------------------4NA-05----------------------------------
    // ----------------------------------------------------------------------
    checkResultIsNotApplicable(processPageTest("Rgaa40.Test.11.2.2-4NA-05"));
    // ----------------------------------------------------------------------
    // ------------------------------4NA-06----------------------------------
    // ----------------------------------------------------------------------
    checkResultIsNotApplicable(processPageTest("Rgaa40.Test.11.2.2-4NA-06"));
    // ----------------------------------------------------------------------
    // ------------------------------4NA-07----------------------------------
    // ----------------------------------------------------------------------
    checkResultIsNotApplicable(processPageTest("Rgaa40.Test.11.2.2-4NA-07"));
    // ----------------------------------------------------------------------
    // ------------------------------4NA-08----------------------------------
    // ----------------------------------------------------------------------
    checkResultIsNotApplicable(processPageTest("Rgaa40.Test.11.2.2-4NA-08"));
}
Also used : ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) HashMap(java.util.HashMap) ProcessResult(org.asqatasun.entity.audit.ProcessResult) Map(java.util.Map) HashMap(java.util.HashMap)

Example 32 with Range

use of org.apache.commons.lang3.Range in project GDSC-SMLM by aherbert.

the class PsfCreator method fitPsf.

/**
 * Fit the new PSF image and show a graph of the amplitude/width.
 *
 * @param psfStack the psf stack
 * @param loess the loess
 * @param cz the cz
 * @param averageRange the average range
 * @param fitCom the fit com
 * @return The width of the PSF in the z-centre
 */
private double fitPsf(ImageStack psfStack, LoessInterpolator loess, int cz, double averageRange, final double[][] fitCom) {
    IJ.showStatus("Fitting final PSF");
    // is not appropriate for a normalised PSF.
    if (fitConfig.getFitSolver() != FitSolver.LVM_LSE) {
        ImageJUtils.log("  " + FitProtosHelper.getName(fitConfig.getFitSolver()) + " is not appropriate for final PSF fitting.");
        ImageJUtils.log("  Switching to Least Square Estimation");
        fitConfig.setFitSolver(FitSolver.LVM_LSE);
        if (settings.getInteractiveMode()) {
            // This assumes the LVM does not need the calibration
            PeakFit.configureFitSolver(config, null, null, 0);
        }
    }
    // Update the box radius since this is used in the fitSpot method.
    boxRadius = psfStack.getWidth() / 2;
    final int x = boxRadius;
    final int y = boxRadius;
    final double shift = fitConfig.getCoordinateShiftFactor();
    // Scale the PSF
    final PSF.Builder localPsf = fitConfig.getPsf().toBuilder();
    for (int i = 0; i < localPsf.getParametersCount(); i++) {
        final PSFParameter param = localPsf.getParameters(i);
        if (param.getUnit() == PSFParameterUnit.DISTANCE) {
            final PSFParameter.Builder b = param.toBuilder();
            b.setValue(b.getValue() * settings.getMagnification());
            localPsf.setParameters(i, b);
        }
    }
    fitConfig.setPsf(localPsf.build());
    // Need to be updated after the widths have been set
    fitConfig.setCoordinateShiftFactor(shift);
    fitConfig.setBackgroundFitting(false);
    // Since the PSF will be normalised remove the camera calibration
    fitConfig.setCameraType(CameraType.CAMERA_TYPE_NA);
    fitConfig.setMinPhotons(0);
    fitConfig.setBias(0);
    fitConfig.setGain(1);
    // No complex filtering so we get a fit. It should be easy to fit anyway.
    fitConfig.setPrecisionThreshold(0);
    fitConfig.setDirectFilter(null);
    // fitConfig.setDisableSimpleFilter(true);
    // Use this for debugging the fit
    // fitConfig.setLog(uk.ac.sussex.gdsc.core.ij.ImageJPluginLoggerHelper.getDefaultLogger());
    final MemoryPeakResults results = fitSpot(psfStack, psfStack.getWidth(), psfStack.getHeight(), x, y);
    if (results.size() < 5) {
        ImageJUtils.log("  Final PSF: Not enough fit results %d", results.size());
        return 0;
    }
    // Get the results for the spot centre and width
    final double[] z = new double[results.size()];
    final double[] xCoord = new double[z.length];
    final double[] yCoord = new double[z.length];
    final double[] sd = new double[z.length];
    final double[] a = new double[z.length];
    // Set limits for the fit
    final float maxWidth = (float) (Math.max(fitConfig.getInitialXSd(), fitConfig.getInitialYSd()) * settings.getMagnification() * 4);
    // PSF is normalised to 1
    final float maxSignal = 2;
    final WidthResultProcedure wp = new WidthResultProcedure(results, DistanceUnit.PIXEL);
    wp.getWxWy();
    final HeightResultProcedure hp = new HeightResultProcedure(results, IntensityUnit.COUNT);
    hp.getH();
    final Counter counter = new Counter();
    final Counter counterOk = new Counter();
    // We have fit the results so they will be in the preferred units
    results.forEach((PeakResultProcedure) peak -> {
        int index = counter.getAndIncrement();
        final float w = Math.max(wp.wx[index], wp.wy[index]);
        if (peak.getIntensity() > maxSignal || w > maxWidth) {
            return;
        }
        index = counterOk.getAndIncrement();
        z[index] = peak.getFrame();
        fitCom[0][peak.getFrame() - 1] = xCoord[index] = peak.getXPosition() - x;
        fitCom[1][peak.getFrame() - 1] = yCoord[index] = peak.getYPosition() - y;
        sd[index] = w;
        a[index] = hp.heights[index];
    });
    // Truncate
    final double[] z2 = Arrays.copyOf(z, counter.getCount());
    final double[] xCoord2 = Arrays.copyOf(xCoord, z2.length);
    final double[] yCoord2 = Arrays.copyOf(yCoord, z2.length);
    final double[] sd2 = Arrays.copyOf(sd, z2.length);
    final double[] a2 = Arrays.copyOf(a, z2.length);
    // Extract the average smoothed range from the individual fits
    final int r = (int) Math.ceil(averageRange / 2);
    int start = 0;
    int stop = z2.length - 1;
    for (int j = 0; j < z2.length; j++) {
        if (z2[j] > cz - r) {
            start = j;
            break;
        }
    }
    for (int j = z2.length; j-- > 0; ) {
        if (z2[j] < cz + r) {
            stop = j;
            break;
        }
    }
    // Extract xy centre coords and smooth
    double[] smoothX = new double[stop - start + 1];
    double[] smoothY = new double[smoothX.length];
    double[] smoothSd = new double[smoothX.length];
    double[] smoothA = new double[smoothX.length];
    final double[] newZ = new double[smoothX.length];
    int smoothCzIndex = 0;
    for (int j = start, k = 0; j <= stop; j++, k++) {
        smoothX[k] = xCoord2[j];
        smoothY[k] = yCoord2[j];
        smoothSd[k] = sd2[j];
        smoothA[k] = a2[j];
        newZ[k] = z2[j];
        if (newZ[k] == cz) {
            smoothCzIndex = k;
        }
    }
    smoothX = loess.smooth(newZ, smoothX);
    smoothY = loess.smooth(newZ, smoothY);
    smoothSd = loess.smooth(newZ, smoothSd);
    smoothA = loess.smooth(newZ, smoothA);
    // Update the widths and positions using the magnification
    final double scale = 1.0 / settings.getMagnification();
    for (int j = 0; j < xCoord2.length; j++) {
        xCoord2[j] *= scale;
        yCoord2[j] *= scale;
        sd2[j] *= scale;
    }
    for (int j = 0; j < smoothX.length; j++) {
        smoothX[j] *= scale;
        smoothY[j] *= scale;
        smoothSd[j] *= scale;
    }
    showPlots(z2, a2, newZ, smoothA, xCoord2, yCoord2, sd2, newZ, smoothX, smoothY, smoothSd, cz);
    // Store the data for replotting
    this.z = z2;
    this.amplitude = a2;
    this.smoothAz = newZ;
    this.smoothA = smoothA;
    this.xCoord = xCoord2;
    this.yCoord = yCoord2;
    this.sd = sd2;
    this.newZ = newZ;
    this.smoothX = smoothX;
    this.smoothY = smoothY;
    this.smoothSd = smoothSd;
    // maximumIndex = findMinimumIndex(smoothSd, maximumIndex - start);
    return smoothSd[smoothCzIndex];
}
Also used : HeightResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.HeightResultProcedure) Color(java.awt.Color) Tensor2D(uk.ac.sussex.gdsc.smlm.utils.Tensor2D) Arrays(java.util.Arrays) ByteProcessor(ij.process.ByteProcessor) UnitConverterUtils(uk.ac.sussex.gdsc.smlm.data.config.UnitConverterUtils) ImageProcessor(ij.process.ImageProcessor) WindowMethod(uk.ac.sussex.gdsc.core.utils.ImageWindow.WindowMethod) MemoryUtils(uk.ac.sussex.gdsc.core.utils.MemoryUtils) PSFType(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.PSFType) CustomTricubicFunction(uk.ac.sussex.gdsc.core.math.interpolation.CustomTricubicFunction) Future(java.util.concurrent.Future) PSFCreatorSettings(uk.ac.sussex.gdsc.smlm.ij.settings.GUIProtos.PSFCreatorSettings) ImageWindow(uk.ac.sussex.gdsc.core.utils.ImageWindow) ImageCanvas(ij.gui.ImageCanvas) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) Blitter(ij.process.Blitter) FitProtosHelper(uk.ac.sussex.gdsc.smlm.data.config.FitProtosHelper) ImageJImageConverter(uk.ac.sussex.gdsc.smlm.ij.utils.ImageJImageConverter) SoftLock(uk.ac.sussex.gdsc.core.utils.SoftLock) Frame(java.awt.Frame) LoessInterpolator(org.apache.commons.math3.analysis.interpolation.LoessInterpolator) DistanceUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit) ConcurrencyUtils(uk.ac.sussex.gdsc.core.utils.concurrent.ConcurrencyUtils) GuiProtosHelper(uk.ac.sussex.gdsc.smlm.ij.settings.GuiProtosHelper) TextUtils(uk.ac.sussex.gdsc.core.utils.TextUtils) Gaussian2DFunction(uk.ac.sussex.gdsc.smlm.function.gaussian.Gaussian2DFunction) Plot(ij.gui.Plot) Executors(java.util.concurrent.Executors) ImagePlus(ij.ImagePlus) Line(ij.gui.Line) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) Prefs(ij.Prefs) StoredData(uk.ac.sussex.gdsc.core.utils.StoredData) SimpleDateFormat(java.text.SimpleDateFormat) WindowManager(ij.WindowManager) PeakResult(uk.ac.sussex.gdsc.smlm.results.PeakResult) ArrayList(java.util.ArrayList) GenericDialog(ij.gui.GenericDialog) SortUtils(uk.ac.sussex.gdsc.core.utils.SortUtils) RounderUtils(uk.ac.sussex.gdsc.core.data.utils.RounderUtils) SubPixelMethod(uk.ac.sussex.gdsc.core.ij.AlignImagesFft.SubPixelMethod) PeakResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.PeakResultProcedure) ImagePsfHelper(uk.ac.sussex.gdsc.smlm.ij.settings.ImagePsfHelper) FitConfiguration(uk.ac.sussex.gdsc.smlm.engine.FitConfiguration) Overlay(ij.gui.Overlay) ImageExtractor(uk.ac.sussex.gdsc.core.utils.ImageExtractor) SimpleImageJTrackProgress(uk.ac.sussex.gdsc.core.ij.SimpleImageJTrackProgress) Size(uk.ac.sussex.gdsc.core.math.interpolation.CustomTricubicInterpolatingFunction.Size) FitEngine(uk.ac.sussex.gdsc.smlm.engine.FitEngine) FloatProcessor(ij.process.FloatProcessor) FloatStackTrivalueProvider(uk.ac.sussex.gdsc.core.data.FloatStackTrivalueProvider) CubicSplinePsf(uk.ac.sussex.gdsc.smlm.ij.plugins.CubicSplineManager.CubicSplinePsf) DescriptiveStatistics(org.apache.commons.math3.stat.descriptive.DescriptiveStatistics) ImageStack(ij.ImageStack) CameraModel(uk.ac.sussex.gdsc.smlm.model.camera.CameraModel) PsfHelper(uk.ac.sussex.gdsc.smlm.data.config.PsfHelper) Erf(uk.ac.sussex.gdsc.smlm.function.Erf) FloatStackTrivalueProcedure(uk.ac.sussex.gdsc.core.data.procedures.FloatStackTrivalueProcedure) AngleUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.AngleUnit) Date(java.util.Date) Point(java.awt.Point) ImagePSF(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.ImagePSF) PSFParameter(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.PSFParameter) FitSolver(uk.ac.sussex.gdsc.smlm.data.config.FitProtos.FitSolver) StoredDataStatistics(uk.ac.sussex.gdsc.core.utils.StoredDataStatistics) OptionCollectedListener(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog.OptionCollectedListener) Locale(java.util.Locale) DataException(uk.ac.sussex.gdsc.core.data.DataException) NonBlockingExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.NonBlockingExtendedGenericDialog) PlotWindow(ij.gui.PlotWindow) MathUtils(uk.ac.sussex.gdsc.core.utils.MathUtils) CalibrationWriter(uk.ac.sussex.gdsc.smlm.data.config.CalibrationWriter) CustomTricubicInterpolatingFunction(uk.ac.sussex.gdsc.core.math.interpolation.CustomTricubicInterpolatingFunction) PlugInFilter(ij.plugin.filter.PlugInFilter) PsfProtosHelper(uk.ac.sussex.gdsc.smlm.data.config.PsfProtosHelper) FitParameters(uk.ac.sussex.gdsc.smlm.engine.FitParameters) SettingsManager(uk.ac.sussex.gdsc.smlm.ij.settings.SettingsManager) BasePoint(uk.ac.sussex.gdsc.core.match.BasePoint) CameraType(uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.CameraType) BlockMeanFilter(uk.ac.sussex.gdsc.smlm.filters.BlockMeanFilter) CustomTricubicInterpolator(uk.ac.sussex.gdsc.core.math.interpolation.CustomTricubicInterpolator) HeightResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.HeightResultProcedure) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) AlignImagesFft(uk.ac.sussex.gdsc.core.ij.AlignImagesFft) FitEngineConfiguration(uk.ac.sussex.gdsc.smlm.engine.FitEngineConfiguration) FloatPolygon(ij.process.FloatPolygon) OffsetPointRoi(uk.ac.sussex.gdsc.core.ij.gui.OffsetPointRoi) WidthResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.WidthResultProcedure) PSFParameterUnit(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.PSFParameterUnit) List(java.util.List) SimpleArrayUtils(uk.ac.sussex.gdsc.core.utils.SimpleArrayUtils) OptionCollectedEvent(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog.OptionCollectedEvent) FitQueue(uk.ac.sussex.gdsc.smlm.engine.FitQueue) TypeConverter(uk.ac.sussex.gdsc.core.data.utils.TypeConverter) Roi(ij.gui.Roi) ParameterisedFitJob(uk.ac.sussex.gdsc.smlm.engine.ParameterisedFitJob) Image3DAligner(uk.ac.sussex.gdsc.smlm.ij.utils.Image3DAligner) Rectangle(java.awt.Rectangle) PSF(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.PSF) HashMap(java.util.HashMap) WindowOrganiser(uk.ac.sussex.gdsc.core.ij.plugin.WindowOrganiser) IntensityUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.IntensityUnit) AtomicReference(java.util.concurrent.atomic.AtomicReference) TextField(java.awt.TextField) OptionListener(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog.OptionListener) AWTEvent(java.awt.AWTEvent) IJImageSource(uk.ac.sussex.gdsc.smlm.ij.IJImageSource) LinkedList(java.util.LinkedList) CcdCameraModel(uk.ac.sussex.gdsc.smlm.model.camera.CcdCameraModel) Statistics(uk.ac.sussex.gdsc.core.utils.Statistics) ExecutorService(java.util.concurrent.ExecutorService) DialogListener(ij.gui.DialogListener) Calibration(ij.measure.Calibration) Checkbox(java.awt.Checkbox) CubicSplinePosition(uk.ac.sussex.gdsc.core.math.interpolation.CubicSplinePosition) Label(java.awt.Label) CreateData(uk.ac.sussex.gdsc.smlm.ij.plugins.benchmark.CreateData) Rounder(uk.ac.sussex.gdsc.core.data.utils.Rounder) CalibrationReader(uk.ac.sussex.gdsc.smlm.data.config.CalibrationReader) Counter(uk.ac.sussex.gdsc.smlm.results.count.Counter) ImageJUtils(uk.ac.sussex.gdsc.core.ij.ImageJUtils) SynchronizedPeakResults(uk.ac.sussex.gdsc.smlm.results.SynchronizedPeakResults) IJ(ij.IJ) FileInfo(ij.io.FileInfo) Image2DAligner(uk.ac.sussex.gdsc.smlm.ij.utils.Image2DAligner) LocalList(uk.ac.sussex.gdsc.core.utils.LocalList) ImagePSF(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.ImagePSF) PSF(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.PSF) PSFParameter(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.PSFParameter) WidthResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.WidthResultProcedure) Point(java.awt.Point) BasePoint(uk.ac.sussex.gdsc.core.match.BasePoint) Counter(uk.ac.sussex.gdsc.smlm.results.count.Counter) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)

Example 33 with Range

use of org.apache.commons.lang3.Range in project GDSC-SMLM by aherbert.

the class ImageJ3DResultsViewer method getPoints.

/**
 * Gets the points.
 *
 * @param results the results
 * @param settings the settings
 * @return the points
 */
static LocalList<Point3f> getPoints(MemoryPeakResults results, ImageJ3DResultsViewerSettingsOrBuilder settings) {
    final LocalList<Point3f> points = new LocalList<>(results.size());
    if (results.is3D()) {
        results.forEach(DistanceUnit.NM, (XyzResultProcedure) (x, y, z) -> {
            points.push(new Point3f(x, y, z));
        });
    } else {
        results.forEach(DistanceUnit.NM, (XyResultProcedure) (x, y) -> {
            points.push(new Point3f(x, y, 0));
        });
        final double range = settings.getDepthRange();
        if (range > 0 && results.size() > 1) {
            final DepthMode mode = DepthMode.forNumber(settings.getDepthMode());
            final double min = -settings.getDepthRange() / 2;
            switch(mode) {
                case DITHER:
                    final SplitMix r = SplitMix.new64(settings.getDitherSeed());
                    for (int i = points.size(); i-- > 0; ) {
                        points.unsafeGet(i).z += (min + r.nextDouble() * range);
                    }
                    break;
                case INTENSITY:
                    // Rank by intensity, highest first
                    final StandardResultProcedure p = new StandardResultProcedure(results);
                    p.getI();
                    final int[] indices = SimpleArrayUtils.natural(results.size());
                    SortUtils.sortIndices(indices, p.intensity, true);
                    final double inc = range / indices.length;
                    for (int i = 0; i < indices.length; i++) {
                        // The standard rendering has +z going away so put the highest rank at min
                        points.unsafeGet(indices[i]).z += (min + i * inc);
                    }
                    break;
                case NONE:
                    break;
                default:
                    throw new IllegalStateException("Unknown depth mode: " + mode);
            }
        }
    }
    return points;
}
Also used : Color(java.awt.Color) Arrays(java.util.Arrays) PickInfo(org.scijava.java3d.PickInfo) IndexedGeometryArray(org.scijava.java3d.IndexedGeometryArray) ItemGroup(uk.ac.sussex.gdsc.smlm.ij.ij3d.ItemGroup) GUI(ij.gui.GUI) DefaultListSelectionModel(javax.swing.DefaultListSelectionModel) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem) ResultsSettings(uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsSettings) TransparentItemShape(uk.ac.sussex.gdsc.smlm.ij.ij3d.TransparentItemShape) Future(java.util.concurrent.Future) Pair(org.apache.commons.lang3.tuple.Pair) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) Map(java.util.Map) FitProtosHelper(uk.ac.sussex.gdsc.smlm.data.config.FitProtosHelper) ImageWindow3D(ij3d.ImageWindow3D) Triple(org.apache.commons.lang3.tuple.Triple) LutHelper(uk.ac.sussex.gdsc.core.ij.process.LutHelper) KeyStroke(javax.swing.KeyStroke) Appearance(org.scijava.java3d.Appearance) CustomMesh(customnode.CustomMesh) ImageCanvas3D(ij3d.ImageCanvas3D) Rendering(uk.ac.sussex.gdsc.smlm.ij.ij3d.Shape3DHelper.Rendering) InputSource(uk.ac.sussex.gdsc.smlm.ij.plugins.ResultsManager.InputSource) TObjectIntHashMap(gnu.trove.map.hash.TObjectIntHashMap) ImageJ3DResultsViewerSettings(uk.ac.sussex.gdsc.smlm.ij.settings.GUIProtos.ImageJ3DResultsViewerSettings) UniverseSettings(ij3d.UniverseSettings) NamedObject(uk.ac.sussex.gdsc.smlm.data.NamedObject) DistanceUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit) ItemGeometryGroup(uk.ac.sussex.gdsc.smlm.ij.ij3d.ItemGeometryGroup) StopWatch(org.apache.commons.lang3.time.StopWatch) RawResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.RawResultProcedure) KeyEvent(java.awt.event.KeyEvent) WindowAdapter(java.awt.event.WindowAdapter) TextUtils(uk.ac.sussex.gdsc.core.utils.TextUtils) Executors(java.util.concurrent.Executors) ImagePlus(ij.ImagePlus) PlugIn(ij.plugin.PlugIn) WindowConstants(javax.swing.WindowConstants) Color3f(org.scijava.vecmath.Color3f) ListSelectionModel(javax.swing.ListSelectionModel) TransformGroup(org.scijava.java3d.TransformGroup) PeakResultProcedureX(uk.ac.sussex.gdsc.smlm.results.procedures.PeakResultProcedureX) XyzResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.XyzResultProcedure) WindowManager(ij.WindowManager) PeakResult(uk.ac.sussex.gdsc.smlm.results.PeakResult) Point3f(org.scijava.vecmath.Point3f) Point3d(org.scijava.vecmath.Point3d) ContentNode(ij3d.ContentNode) SortUtils(uk.ac.sussex.gdsc.core.utils.SortUtils) CustomPointMesh(customnode.CustomPointMesh) RounderUtils(uk.ac.sussex.gdsc.core.data.utils.RounderUtils) PeakResultTableModel(uk.ac.sussex.gdsc.smlm.ij.gui.PeakResultTableModel) PeakResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.PeakResultProcedure) CustomLineMesh(customnode.CustomLineMesh) ItemPointMesh(uk.ac.sussex.gdsc.smlm.ij.ij3d.ItemPointMesh) GeometryArray(org.scijava.java3d.GeometryArray) Field(java.lang.reflect.Field) IntersectionInfo(org.scijava.java3d.PickInfo.IntersectionInfo) Point2d(org.scijava.vecmath.Point2d) MouseEvent(java.awt.event.MouseEvent) ExecutionException(java.util.concurrent.ExecutionException) ReferenceItemMesh(uk.ac.sussex.gdsc.smlm.ij.ij3d.ReferenceItemMesh) Canvas3D(org.scijava.java3d.Canvas3D) MouseMotionListener(java.awt.event.MouseMotionListener) LineAttributes(org.scijava.java3d.LineAttributes) ItemTriangleMesh(uk.ac.sussex.gdsc.smlm.ij.ij3d.ItemTriangleMesh) ResultsTableSettings(uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsTableSettings) ListSelectionListener(javax.swing.event.ListSelectionListener) UniverseListener(ij3d.UniverseListener) TransparentItemTriangleMesh(uk.ac.sussex.gdsc.smlm.ij.ij3d.TransparentItemTriangleMesh) Builder(uk.ac.sussex.gdsc.smlm.ij.settings.GUIProtos.ImageJ3DResultsViewerSettings.Builder) StandardResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.StandardResultProcedure) TriangleArray(org.scijava.java3d.TriangleArray) Transform3D(org.scijava.java3d.Transform3D) CustomContentHelper(uk.ac.sussex.gdsc.smlm.ij.ij3d.CustomContentHelper) PointAttributes(org.scijava.java3d.PointAttributes) SplitMix(uk.ac.sussex.gdsc.core.utils.rng.SplitMix) ItemGroupNode(uk.ac.sussex.gdsc.smlm.ij.ij3d.ItemGroupNode) Content(ij3d.Content) PickCanvas(org.scijava.java3d.utils.pickfast.PickCanvas) ItemShape(uk.ac.sussex.gdsc.smlm.ij.ij3d.ItemShape) TransparentItemPointMesh(uk.ac.sussex.gdsc.smlm.ij.ij3d.TransparentItemPointMesh) CoordinatePredicateUtils(uk.ac.sussex.gdsc.core.ij.roi.CoordinatePredicateUtils) XyResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.XyResultProcedure) CustomContent(uk.ac.sussex.gdsc.smlm.ij.ij3d.CustomContent) Image3DUniverse(ij3d.Image3DUniverse) Locale(java.util.Locale) ListSelectionModelHelper(uk.ac.sussex.gdsc.smlm.ij.gui.ListSelectionModelHelper) MouseAdapter(java.awt.event.MouseAdapter) DataException(uk.ac.sussex.gdsc.core.data.DataException) ColoringAttributes(org.scijava.java3d.ColoringAttributes) MacroRunner(ij.macro.MacroRunner) MathUtils(uk.ac.sussex.gdsc.core.utils.MathUtils) ListSelectionEvent(javax.swing.event.ListSelectionEvent) UpdateableItemShape(uk.ac.sussex.gdsc.smlm.ij.ij3d.UpdateableItemShape) MouseListener(java.awt.event.MouseListener) SettingsManager(uk.ac.sussex.gdsc.smlm.ij.settings.SettingsManager) JMenuBar(javax.swing.JMenuBar) CoordinatePredicate(uk.ac.sussex.gdsc.core.ij.roi.CoordinatePredicate) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) JMenu(javax.swing.JMenu) WindowEvent(java.awt.event.WindowEvent) List(java.util.List) PeakResultTableModelFrame(uk.ac.sussex.gdsc.smlm.ij.gui.PeakResultTableModelFrame) OrderedItemGeometryGroup(uk.ac.sussex.gdsc.smlm.ij.ij3d.OrderedItemGeometryGroup) Modifier(java.lang.reflect.Modifier) SimpleArrayUtils(uk.ac.sussex.gdsc.core.utils.SimpleArrayUtils) Shape3DHelper(uk.ac.sussex.gdsc.smlm.ij.ij3d.Shape3DHelper) TransparencyAttributes(org.scijava.java3d.TransparencyAttributes) LUT(ij.process.LUT) SceneGraphPath(org.scijava.java3d.SceneGraphPath) TypeConverter(uk.ac.sussex.gdsc.core.data.utils.TypeConverter) Roi(ij.gui.Roi) PolygonAttributes(org.scijava.java3d.PolygonAttributes) PrecisionResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.PrecisionResultProcedure) PrecisionMethod(uk.ac.sussex.gdsc.smlm.data.config.FitProtos.PrecisionMethod) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) TextField(java.awt.TextField) OptionListener(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog.OptionListener) ItemMesh(uk.ac.sussex.gdsc.smlm.ij.ij3d.ItemMesh) JMenuItem(javax.swing.JMenuItem) ImageJTrackProgress(uk.ac.sussex.gdsc.core.ij.ImageJTrackProgress) CustomMeshNode(customnode.CustomMeshNode) View(org.scijava.java3d.View) ExecutorService(java.util.concurrent.ExecutorService) Shape3D(org.scijava.java3d.Shape3D) DefaultUniverse(ij3d.DefaultUniverse) TFloatArrayList(gnu.trove.list.array.TFloatArrayList) Vector3d(org.scijava.vecmath.Vector3d) PeakResultsDigest(uk.ac.sussex.gdsc.smlm.results.PeakResultsDigest) Iterator(java.util.Iterator) BranchGroup(org.scijava.java3d.BranchGroup) AxisAngle4d(org.scijava.vecmath.AxisAngle4d) Image3DMenubar(ij3d.Image3DMenubar) LutColour(uk.ac.sussex.gdsc.core.ij.process.LutHelper.LutColour) Ticker(uk.ac.sussex.gdsc.core.logging.Ticker) ActionEvent(java.awt.event.ActionEvent) ContentInstant(ij3d.ContentInstant) Rounder(uk.ac.sussex.gdsc.core.data.utils.Rounder) TimeUnit(java.util.concurrent.TimeUnit) CustomContentInstant(uk.ac.sussex.gdsc.smlm.ij.ij3d.CustomContentInstant) ImageJUtils(uk.ac.sussex.gdsc.core.ij.ImageJUtils) IJ(ij.IJ) Nullable(uk.ac.sussex.gdsc.core.annotation.Nullable) ImageJ3DResultsViewerSettingsOrBuilder(uk.ac.sussex.gdsc.smlm.ij.settings.GUIProtos.ImageJ3DResultsViewerSettingsOrBuilder) LocalList(uk.ac.sussex.gdsc.core.utils.LocalList) LocalList(uk.ac.sussex.gdsc.core.utils.LocalList) Point3f(org.scijava.vecmath.Point3f) SplitMix(uk.ac.sussex.gdsc.core.utils.rng.SplitMix) StandardResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.StandardResultProcedure)

Example 34 with Range

use of org.apache.commons.lang3.Range in project GDSC-SMLM by aherbert.

the class Fire method calculatePrecisionHistogram.

/**
 * Calculate a histogram of the precision. The precision can be either stored in the results or
 * calculated using the Mortensen formula. If the precision method for Q estimation is not fixed
 * then the histogram is fitted with a Gaussian to create an initial estimate.
 *
 * @return The precision histogram
 */
private PrecisionHistogram calculatePrecisionHistogram() {
    final boolean logFitParameters = false;
    final String title = results.getName() + " Precision Histogram";
    // Check if the results has the precision already or if it can be computed.
    final boolean canUseStored = canUseStoredPrecision(results);
    final boolean canCalculatePrecision = canCalculatePrecision(results);
    // Set the method to compute a histogram. Default to the user selected option.
    PrecisionMethod method = null;
    if ((canUseStored && precisionMethod == PrecisionMethod.STORED) || (canCalculatePrecision && precisionMethod == PrecisionMethod.CALCULATE)) {
        method = precisionMethod;
    }
    if (method == null) {
        // We only have two choices so if one is available then select it.
        if (canUseStored) {
            method = PrecisionMethod.STORED;
        } else if (canCalculatePrecision) {
            method = PrecisionMethod.CALCULATE;
        }
        // If the user selected a method not available then log a warning
        if (method != null && precisionMethod != PrecisionMethod.FIXED) {
            IJ.log(String.format("%s : Selected precision method '%s' not available, switching to '%s'", pluginTitle, precisionMethod, method.getName()));
        }
        if (method == null) {
            // This does not matter if the user has provide a fixed input.
            if (precisionMethod == PrecisionMethod.FIXED) {
                final PrecisionHistogram histogram = new PrecisionHistogram(title);
                histogram.mean = settings.mean;
                histogram.sigma = settings.sigma;
                return histogram;
            }
            // No precision
            return null;
        }
    }
    // We get here if we can compute precision.
    // Build the histogram
    StoredDataStatistics precision = new StoredDataStatistics(results.size());
    if (method == PrecisionMethod.STORED) {
        final StoredDataStatistics p = precision;
        results.forEach((PeakResultProcedure) result -> p.add(result.getPrecision()));
    } else {
        precision.add(pp.precisions);
    }
    double yMin = Double.NEGATIVE_INFINITY;
    double yMax = 0;
    // Set the min and max y-values using 1.5 x IQR
    final DescriptiveStatistics stats = precision.getStatistics();
    final double lower = stats.getPercentile(25);
    final double upper = stats.getPercentile(75);
    if (Double.isNaN(lower) || Double.isNaN(upper)) {
        if (logFitParameters) {
            ImageJUtils.log("Error computing IQR: %f - %f", lower, upper);
        }
    } else {
        final double iqr = upper - lower;
        yMin = Math.max(lower - iqr, stats.getMin());
        yMax = Math.min(upper + iqr, stats.getMax());
        if (logFitParameters) {
            ImageJUtils.log("  Data range: %f - %f. Plotting 1.5x IQR: %f - %f", stats.getMin(), stats.getMax(), yMin, yMax);
        }
    }
    if (yMin == Double.NEGATIVE_INFINITY) {
        final int n = 5;
        yMin = Math.max(stats.getMin(), stats.getMean() - n * stats.getStandardDeviation());
        yMax = Math.min(stats.getMax(), stats.getMean() + n * stats.getStandardDeviation());
        if (logFitParameters) {
            ImageJUtils.log("  Data range: %f - %f. Plotting mean +/- %dxSD: %f - %f", stats.getMin(), stats.getMax(), n, yMin, yMax);
        }
    }
    // Get the data within the range
    final double[] data = precision.getValues();
    precision = new StoredDataStatistics(data.length);
    for (final double d : data) {
        if (d < yMin || d > yMax) {
            continue;
        }
        precision.add(d);
    }
    final int histogramBins = HistogramPlot.getBins(precision, HistogramPlot.BinMethod.SCOTT);
    final float[][] hist = HistogramPlot.calcHistogram(precision.getFloatValues(), yMin, yMax, histogramBins);
    final PrecisionHistogram histogram = new PrecisionHistogram(hist, precision, title);
    if (precisionMethod == PrecisionMethod.FIXED) {
        histogram.mean = settings.mean;
        histogram.sigma = settings.sigma;
        return histogram;
    }
    // Fitting of the histogram to produce the initial estimate
    // Extract non-zero data
    float[] x = Arrays.copyOf(hist[0], hist[0].length);
    float[] y = Arrays.copyOf(hist[1], hist[1].length);
    int count = 0;
    for (int i = 0; i < y.length; i++) {
        if (y[i] > 0) {
            x[count] = x[i];
            y[count] = y[i];
            count++;
        }
    }
    x = Arrays.copyOf(x, count);
    y = Arrays.copyOf(y, count);
    // Sense check to fitted data. Get mean and SD of histogram
    final double[] stats2 = HistogramPlot.getHistogramStatistics(x, y);
    if (logFitParameters) {
        ImageJUtils.log("  Initial Statistics: %f +/- %f", stats2[0], stats2[1]);
    }
    histogram.mean = stats2[0];
    histogram.sigma = stats2[1];
    // Standard Gaussian fit
    final double[] parameters = fitGaussian(x, y);
    if (parameters == null) {
        ImageJUtils.log("  Failed to fit initial Gaussian");
        return histogram;
    }
    final double newMean = parameters[1];
    final double error = Math.abs(stats2[0] - newMean) / stats2[1];
    if (error > 3) {
        ImageJUtils.log("  Failed to fit Gaussian: %f standard deviations from histogram mean", error);
        return histogram;
    }
    if (newMean < yMin || newMean > yMax) {
        ImageJUtils.log("  Failed to fit Gaussian: %f outside data range %f - %f", newMean, yMin, yMax);
        return histogram;
    }
    if (logFitParameters) {
        ImageJUtils.log("  Initial Gaussian: %f @ %f +/- %f", parameters[0], parameters[1], parameters[2]);
    }
    histogram.mean = parameters[1];
    histogram.sigma = parameters[2];
    return histogram;
}
Also used : Color(java.awt.Color) RandomUtils(uk.ac.sussex.gdsc.core.utils.rng.RandomUtils) Arrays(java.util.Arrays) Macro(ij.Macro) ImageProcessor(ij.process.ImageProcessor) Rectangle2D(java.awt.geom.Rectangle2D) Future(java.util.concurrent.Future) Pair(org.apache.commons.lang3.tuple.Pair) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) GoalType(org.apache.commons.math3.optim.nonlinear.scalar.GoalType) UnivariateObjectiveFunction(org.apache.commons.math3.optim.univariate.UnivariateObjectiveFunction) LutHelper(uk.ac.sussex.gdsc.core.ij.process.LutHelper) WeightedObservedPoint(org.apache.commons.math3.fitting.WeightedObservedPoint) ThresholdMethod(uk.ac.sussex.gdsc.smlm.ij.frc.Frc.ThresholdMethod) XyrResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.XyrResultProcedure) LoessInterpolator(org.apache.commons.math3.analysis.interpolation.LoessInterpolator) InputSource(uk.ac.sussex.gdsc.smlm.ij.plugins.ResultsManager.InputSource) DistanceUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit) SimpleCurveFitter(org.apache.commons.math3.fitting.SimpleCurveFitter) PointValuePair(org.apache.commons.math3.optim.PointValuePair) NelderMeadSimplex(org.apache.commons.math3.optim.nonlinear.scalar.noderiv.NelderMeadSimplex) ConcurrencyUtils(uk.ac.sussex.gdsc.core.utils.concurrent.ConcurrencyUtils) TextUtils(uk.ac.sussex.gdsc.core.utils.TextUtils) Plot(ij.gui.Plot) Scrollbar(java.awt.Scrollbar) Executors(java.util.concurrent.Executors) ImagePlus(ij.ImagePlus) TDoubleArrayList(gnu.trove.list.array.TDoubleArrayList) FrcCurveResult(uk.ac.sussex.gdsc.smlm.ij.frc.Frc.FrcCurveResult) MaxEval(org.apache.commons.math3.optim.MaxEval) PlugIn(ij.plugin.PlugIn) AtomicDouble(com.google.common.util.concurrent.AtomicDouble) MathArrays(org.apache.commons.math3.util.MathArrays) Prefs(ij.Prefs) WindowManager(ij.WindowManager) PeakResult(uk.ac.sussex.gdsc.smlm.results.PeakResult) UnivariateOptimizer(org.apache.commons.math3.optim.univariate.UnivariateOptimizer) GenericDialog(ij.gui.GenericDialog) PeakResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.PeakResultProcedure) GaussianCurveFitter(org.apache.commons.math3.fitting.GaussianCurveFitter) ResultsImageSizeMode(uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsImageSizeMode) FourierMethod(uk.ac.sussex.gdsc.smlm.ij.frc.Frc.FourierMethod) MouseEvent(java.awt.event.MouseEvent) DescriptiveStatistics(org.apache.commons.math3.stat.descriptive.DescriptiveStatistics) Erf(uk.ac.sussex.gdsc.smlm.function.Erf) UnivariatePointValuePair(org.apache.commons.math3.optim.univariate.UnivariatePointValuePair) SamplingMethod(uk.ac.sussex.gdsc.smlm.ij.frc.Frc.SamplingMethod) Frc(uk.ac.sussex.gdsc.smlm.ij.frc.Frc) DoubleMedianWindow(uk.ac.sussex.gdsc.core.utils.DoubleMedianWindow) FrcFireResult(uk.ac.sussex.gdsc.smlm.ij.frc.Frc.FrcFireResult) ResultsImageSettings(uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsImageSettings) StoredDataStatistics(uk.ac.sussex.gdsc.core.utils.StoredDataStatistics) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ImageJImagePeakResults(uk.ac.sussex.gdsc.smlm.ij.results.ImageJImagePeakResults) MouseAdapter(java.awt.event.MouseAdapter) DataException(uk.ac.sussex.gdsc.core.data.DataException) NonBlockingExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.NonBlockingExtendedGenericDialog) PlotWindow(ij.gui.PlotWindow) MathUtils(uk.ac.sussex.gdsc.core.utils.MathUtils) SettingsManager(uk.ac.sussex.gdsc.smlm.ij.settings.SettingsManager) Collection(java.util.Collection) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) TrackProgressAdaptor(uk.ac.sussex.gdsc.core.logging.TrackProgressAdaptor) ResultsImageType(uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsImageType) ParametricUnivariateFunction(org.apache.commons.math3.analysis.ParametricUnivariateFunction) ObjectiveFunction(org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunction) SimplexOptimizer(org.apache.commons.math3.optim.nonlinear.scalar.noderiv.SimplexOptimizer) BracketFinder(org.apache.commons.math3.optim.univariate.BracketFinder) List(java.util.List) Gaussian(org.apache.commons.math3.analysis.function.Gaussian) SimpleArrayUtils(uk.ac.sussex.gdsc.core.utils.SimpleArrayUtils) UnivariateFunction(org.apache.commons.math3.analysis.UnivariateFunction) MultivariateFunction(org.apache.commons.math3.analysis.MultivariateFunction) LUT(ij.process.LUT) FrcCurve(uk.ac.sussex.gdsc.smlm.ij.frc.Frc.FrcCurve) PrecisionResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.PrecisionResultProcedure) Rectangle(java.awt.Rectangle) SearchInterval(org.apache.commons.math3.optim.univariate.SearchInterval) WindowOrganiser(uk.ac.sussex.gdsc.core.ij.plugin.WindowOrganiser) AtomicReference(java.util.concurrent.atomic.AtomicReference) TrackProgress(uk.ac.sussex.gdsc.core.logging.TrackProgress) TextField(java.awt.TextField) AWTEvent(java.awt.AWTEvent) ImagePeakResultsFactory(uk.ac.sussex.gdsc.smlm.ij.results.ImagePeakResultsFactory) InitialGuess(org.apache.commons.math3.optim.InitialGuess) UnitHelper(uk.ac.sussex.gdsc.smlm.data.config.UnitHelper) LinkedList(java.util.LinkedList) Statistics(uk.ac.sussex.gdsc.core.utils.Statistics) ExecutorService(java.util.concurrent.ExecutorService) DialogListener(ij.gui.DialogListener) ConversionException(uk.ac.sussex.gdsc.core.data.utils.ConversionException) Checkbox(java.awt.Checkbox) StdMath(uk.ac.sussex.gdsc.smlm.utils.StdMath) ResultsImageMode(uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsImageMode) LutColour(uk.ac.sussex.gdsc.core.ij.process.LutHelper.LutColour) Recorder(ij.plugin.frame.Recorder) WeightedObservedPoints(org.apache.commons.math3.fitting.WeightedObservedPoints) BrentOptimizer(org.apache.commons.math3.optim.univariate.BrentOptimizer) CalibrationReader(uk.ac.sussex.gdsc.smlm.data.config.CalibrationReader) Counter(uk.ac.sussex.gdsc.smlm.results.count.Counter) HistogramPlot(uk.ac.sussex.gdsc.core.ij.HistogramPlot) ImageJUtils(uk.ac.sussex.gdsc.core.ij.ImageJUtils) IJ(ij.IJ) LocalList(uk.ac.sussex.gdsc.core.utils.LocalList) UniformRandomProviders(uk.ac.sussex.gdsc.core.utils.rng.UniformRandomProviders) DescriptiveStatistics(org.apache.commons.math3.stat.descriptive.DescriptiveStatistics) StoredDataStatistics(uk.ac.sussex.gdsc.core.utils.StoredDataStatistics) WeightedObservedPoint(org.apache.commons.math3.fitting.WeightedObservedPoint)

Example 35 with Range

use of org.apache.commons.lang3.Range in project sts4 by spring-projects.

the class BoshCloudConfigSchema method createNetworkBlockSchema.

private YType createNetworkBlockSchema(BoshModels models) {
    AbstractType t_manual_nw = f.ybean("ManualNetwork");
    {
        YBeanType t_subnet = f.ybean("Subnet[Manual]");
        addProp(t_subnet, "range", t_ip_range).isRequired(true);
        addProp(t_subnet, "gateway", t_ip_address).isRequired(true);
        addProp(t_subnet, "dns", f.yseq(t_ip_address));
        addProp(t_subnet, "reserved", f.yseq(t_ip_address_or_range));
        addProp(t_subnet, "static", f.yseq(t_ip_address_or_range));
        addProp(t_subnet, "az", t_az_ref);
        addProp(t_subnet, "azs", f.yseq(t_az_ref));
        addProp(t_subnet, "cloud_properties", t_params);
        addProp(t_manual_nw, "subnets", f.yseq(t_subnet)).isRequired(true);
    }
    AbstractType t_vip_nw = f.ybean("VipNetwork");
    addProp(t_vip_nw, "cloud_properties", t_params);
    AbstractType t_dynamic_nw = f.ybean("DynamicNetwork");
    addProp(t_dynamic_nw, "dns", f.yseq(t_ip_address));
    addProp(t_dynamic_nw, "cloud_properties", t_params);
    {
        YBeanType t_subnet = f.ybean("Subnet[Dynamic]");
        addProp(t_subnet, "dns", f.yseq(t_ip_address));
        addProp(t_subnet, "az", t_az_ref);
        addProp(t_subnet, "azs", f.yseq(t_az_ref));
        addProp(t_subnet, "cloud_properties", t_params);
        addProp(t_dynamic_nw, "subnets", f.yseq(t_subnet));
    }
    t_dynamic_nw.require(Constraints.mutuallyExclusive("dns", "subnets"));
    t_dynamic_nw.require(Constraints.mutuallyExclusive("cloud_properties", "subnets"));
    AbstractType t_network = f.contextAware("Network", dc -> {
        String type = models.getTypeTag(dc);
        if (StringUtil.hasText(type)) {
            switch(type) {
                case "manual":
                    return t_manual_nw;
                case "dynamic":
                    return t_dynamic_nw;
                case "vip":
                    return t_vip_nw;
                default:
            }
        }
        return null;
    }).treatAsBean();
    // Add shared properties to the 'super' type.
    addProp(t_network, "name", t_network_def).isPrimary(true);
    addProp(t_network, "type", f.yenum("NetworkType", "manual", "dynamic", "vip")).isRequired(true);
    // Add shared properties to all 'sub' types.
    for (AbstractType subtype : ImmutableList.of(t_dynamic_nw, t_manual_nw, t_vip_nw)) {
        for (YTypedProperty sharedProp : t_network.getProperties()) {
            subtype.addProperty(sharedProp);
        }
    }
    return t_network;
}
Also used : AbstractType(org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.AbstractType) YTypedProperty(org.springframework.ide.vscode.commons.yaml.schema.YTypedProperty) CollectorUtil(org.springframework.ide.vscode.commons.util.CollectorUtil) YamlSchemaProblems(org.springframework.ide.vscode.commons.yaml.reconcile.YamlSchemaProblems) Collection(java.util.Collection) YamlSchema(org.springframework.ide.vscode.commons.yaml.schema.YamlSchema) YTypeUtil(org.springframework.ide.vscode.commons.yaml.schema.YTypeUtil) PartialCollection(org.springframework.ide.vscode.commons.util.PartialCollection) YType(org.springframework.ide.vscode.commons.yaml.schema.YType) ASTTypeCache(org.springframework.ide.vscode.commons.yaml.reconcile.ASTTypeCache) YBeanType(org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.YBeanType) YAtomicType(org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.YAtomicType) Constraints(org.springframework.ide.vscode.commons.yaml.schema.constraints.Constraints) StringUtil(org.springframework.ide.vscode.commons.util.StringUtil) Pair(org.apache.commons.lang3.tuple.Pair) YTypeFactory(org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory) ImmutableList(com.google.common.collect.ImmutableList) ValueParsers(org.springframework.ide.vscode.commons.util.ValueParsers) BoshModels(org.springframework.ide.vscode.bosh.models.BoshModels) Lazy(org.springframework.ide.vscode.commons.util.Lazy) AbstractType(org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.AbstractType) YBeanType(org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.YBeanType) YTypedProperty(org.springframework.ide.vscode.commons.yaml.schema.YTypedProperty)

Aggregations

List (java.util.List)30 HashMap (java.util.HashMap)24 Map (java.util.Map)24 ArrayList (java.util.ArrayList)23 Collectors (java.util.stream.Collectors)21 StringUtils (org.apache.commons.lang3.StringUtils)20 LoggerFactory (org.slf4j.LoggerFactory)17 Pair (org.apache.commons.lang3.tuple.Pair)16 Logger (org.slf4j.Logger)16 Set (java.util.Set)15 IOException (java.io.IOException)14 Optional (java.util.Optional)12 Range (org.apache.commons.lang3.Range)11 Test (org.junit.jupiter.api.Test)11 java.util (java.util)10 Date (java.util.Date)10 Lists (com.google.common.collect.Lists)9 HashSet (java.util.HashSet)9 ExecutorService (java.util.concurrent.ExecutorService)9 Collection (java.util.Collection)8