Search in sources :

Example 1 with NotImplementedException

use of uk.ac.sussex.gdsc.core.data.NotImplementedException in project GDSC-SMLM by aherbert.

the class TsfPeakResultsWriter method createSpotList.

private SpotList createSpotList() {
    final SpotList.Builder builder = SpotList.newBuilder();
    builder.setApplicationId(APPLICATION_ID);
    builder.setNrSpots(size);
    // Add the standard details the TSF supports. We use extensions to add GDSC SMLM data.
    if (!TextUtils.isNullOrEmpty(getName())) {
        builder.setName(getName());
    }
    if (getSource() != null) {
        builder.setNrPixelsX(getSource().width);
        builder.setNrPixelsY(getSource().height);
        builder.setNrFrames(getSource().frames);
        builder.setSource(singleLine(getSource().toXml()));
    }
    if (getBounds() != null) {
        final ROI.Builder roiBuilder = builder.getRoiBuilder();
        roiBuilder.setX(getBounds().x);
        roiBuilder.setY(getBounds().y);
        roiBuilder.setXWidth(getBounds().width);
        roiBuilder.setYWidth(getBounds().height);
        builder.setRoi(roiBuilder.build());
    }
    if (hasCalibration()) {
        final CalibrationReader cr = getCalibrationReader();
        if (cr.hasNmPerPixel()) {
            builder.setPixelSize((float) cr.getNmPerPixel());
        }
        if (cr.hasExposureTime()) {
            builder.setExposureTime(cr.getExposureTime());
        }
        if (cr.hasReadNoise()) {
            builder.setReadNoise(cr.getReadNoise());
        }
        if (cr.hasBias()) {
            builder.setBias(cr.getBias());
        }
        if (cr.hasCameraType()) {
            builder.setCameraType(cameraTypeMap[cr.getCameraType().ordinal()]);
        }
        if (cr.hasDistanceUnit()) {
            builder.setLocationUnits(locationUnitsMap[cr.getDistanceUnit().ordinal()]);
        }
        if (cr.hasIntensityUnit()) {
            builder.setIntensityUnits(intensityUnitsMap[cr.getIntensityUnit().ordinal()]);
        }
        if (cr.hasAngleUnit()) {
            builder.setThetaUnits(thetaUnitsMap[cr.getAngleUnit().ordinal()]);
        }
        // We can use some logic here to get the QE
        if (cr.hasCountPerPhoton()) {
            builder.setGain(cr.getCountPerPhoton());
            final double qe = (cr.hasQuantumEfficiency()) ? cr.getQuantumEfficiency() : 1;
            // e-/photon / count/photon => e-/count
            final double ecf = qe / cr.getCountPerPhoton();
            builder.addEcf(ecf);
            builder.addQe(qe);
        }
    }
    if (!TextUtils.isNullOrEmpty(getConfiguration())) {
        builder.setConfiguration(singleLine(getConfiguration()));
    }
    if (getPsf() != null) {
        try {
            final Printer printer = JsonFormat.printer().omittingInsignificantWhitespace();
            builder.setPSF(printer.print(getPsf()));
        } catch (final InvalidProtocolBufferException ex) {
            // This shouldn't happen so throw it
            throw new NotImplementedException("Unable to serialise the PSF settings", ex);
        }
    }
    // Have a property so the boxSize can be set
    if (boxSize > 0) {
        builder.setBoxSize(boxSize);
    }
    builder.setFitMode(fitMode);
    final FluorophoreType.Builder typeBuilder = FluorophoreType.newBuilder();
    typeBuilder.setId(1);
    typeBuilder.setDescription("Default fluorophore");
    typeBuilder.setIsFiducial(false);
    builder.addFluorophoreTypes(typeBuilder.build());
    return builder.build();
}
Also used : FluorophoreType(uk.ac.sussex.gdsc.smlm.tsf.TSFProtos.FluorophoreType) NotImplementedException(uk.ac.sussex.gdsc.core.data.NotImplementedException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) SpotList(uk.ac.sussex.gdsc.smlm.tsf.TSFProtos.SpotList) CalibrationReader(uk.ac.sussex.gdsc.smlm.data.config.CalibrationReader) Printer(com.google.protobuf.util.JsonFormat.Printer) ROI(uk.ac.sussex.gdsc.smlm.tsf.TSFProtos.ROI)

Example 2 with NotImplementedException

use of uk.ac.sussex.gdsc.core.data.NotImplementedException in project GDSC-SMLM by aherbert.

the class BaseSteppingFunctionSolverTest method getSolver.

SteppingFunctionSolver getSolver(SteppingFunctionSolverClamp clamp, SteppingFunctionSolverType type, ToleranceChecker tc) {
    final ErfGaussian2DFunction f = (ErfGaussian2DFunction) GaussianFunctionFactory.create2D(1, size, size, flags, null);
    final ParameterBounds bounds = new ParameterBounds(f);
    switch(clamp) {
        case DYNAMIC_CLAMP:
            bounds.setDynamicClamp(true);
            bounds.setClampValues(defaultClampValues);
            break;
        case CLAMP:
            bounds.setClampValues(defaultClampValues);
            break;
        case NO_CLAMP:
        default:
            break;
    }
    SteppingFunctionSolver solver;
    switch(type) {
        case LSELVM:
            solver = new LseLvmSteppingFunctionSolver(f, tc, bounds);
            break;
        case MLELVM:
        case FastLogMLELVM:
            final MleLvmSteppingFunctionSolver mleSolver = new MleLvmSteppingFunctionSolver(f, tc, bounds);
            solver = mleSolver;
            // MLE requires a positive function value so use a lower bound
            solver.setBounds(getLb(), null);
            // For testing the fast log version
            if (type == FastLogMLELVM) {
                mleSolver.setFastLog(FastLogFactory.getFastLog());
            }
            break;
        case WLSELVM:
            solver = new WLseLvmSteppingFunctionSolver(f, tc, bounds);
            break;
        case FastMLE:
            solver = new FastMleSteppingFunctionSolver(f, tc, bounds);
            // MLE requires a positive function value so use a lower bound
            solver.setBounds(getLb(), null);
            break;
        default:
            throw new NotImplementedException();
    }
    if (solver instanceof LvmSteppingFunctionSolver) {
        ((LvmSteppingFunctionSolver) solver).setInitialLambda(1);
    }
    return solver;
}
Also used : ErfGaussian2DFunction(uk.ac.sussex.gdsc.smlm.function.gaussian.erf.ErfGaussian2DFunction) NotImplementedException(uk.ac.sussex.gdsc.core.data.NotImplementedException)

Example 3 with NotImplementedException

use of uk.ac.sussex.gdsc.core.data.NotImplementedException in project GDSC-SMLM by aherbert.

the class PeakResultsReaderTest method writeFile.

private static void writeFile(boolean sequential, ResultsFileFormat fileFormat, boolean showDeviations, boolean showEndFrame, boolean showId, boolean showPrecision, boolean showCategory, boolean sort, MemoryPeakResults results, String filename) {
    final PeakResults out;
    switch(fileFormat) {
        case BINARY:
            out = new BinaryFilePeakResults(filename, showDeviations, showEndFrame, showId, showPrecision, showCategory);
            break;
        case TEXT:
            out = new TextFilePeakResults(filename, showDeviations, showEndFrame, showId, showPrecision, showCategory);
            break;
        case TSF:
            out = new TsfPeakResultsWriter(filename);
            break;
        case MALK:
            out = new MalkFilePeakResults(filename);
            break;
        default:
            throw new NotImplementedException("Unsupported file format: " + fileFormat);
    }
    out.copySettings(results);
    if (sort && out instanceof FilePeakResults) {
        ((FilePeakResults) out).setSortAfterEnd(sort);
    }
    out.begin();
    if (sequential) {
        results.forEach(new PeakResultProcedure() {

            @Override
            public void execute(PeakResult peak) {
                out.add(peak.getFrame(), peak.getOrigX(), peak.getOrigY(), peak.getOrigValue(), peak.getError(), peak.getNoise(), peak.getMeanIntensity(), peak.getParameters(), peak.getParameterDeviations());
            }
        });
    } else {
        out.addAll(Arrays.asList(results.toArray()));
    }
    out.end();
}
Also used : PeakResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.PeakResultProcedure) NotImplementedException(uk.ac.sussex.gdsc.core.data.NotImplementedException)

Aggregations

NotImplementedException (uk.ac.sussex.gdsc.core.data.NotImplementedException)3 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 Printer (com.google.protobuf.util.JsonFormat.Printer)1 CalibrationReader (uk.ac.sussex.gdsc.smlm.data.config.CalibrationReader)1 ErfGaussian2DFunction (uk.ac.sussex.gdsc.smlm.function.gaussian.erf.ErfGaussian2DFunction)1 PeakResultProcedure (uk.ac.sussex.gdsc.smlm.results.procedures.PeakResultProcedure)1 FluorophoreType (uk.ac.sussex.gdsc.smlm.tsf.TSFProtos.FluorophoreType)1 ROI (uk.ac.sussex.gdsc.smlm.tsf.TSFProtos.ROI)1 SpotList (uk.ac.sussex.gdsc.smlm.tsf.TSFProtos.SpotList)1