Search in sources :

Example 6 with DoubleArrayList

use of it.unimi.dsi.fastutil.doubles.DoubleArrayList in project mzmine2 by mzmine.

the class MZDistributionHistoTask method run.

/**
 * @see Runnable#run()
 */
public void run() {
    setStatus(TaskStatus.PROCESSING);
    logger.info("Starting to build mz distribution histogram for " + dataFile);
    // all selected scans
    scans = scanSelection.getMatchingScans(dataFile);
    totalScans = scans.length;
    // histo data
    DoubleArrayList data = new DoubleArrayList();
    for (Scan scan : scans) {
        if (isCanceled())
            return;
        // retention time in range
        if (!useRTRange || rtRange.contains(scan.getRetentionTime())) {
            // go through all mass lists
            MassList massList = scan.getMassList(massListName);
            if (massList == null) {
                setStatus(TaskStatus.ERROR);
                setErrorMessage("Scan " + dataFile + " #" + scan.getScanNumber() + " does not have a mass list " + massListName);
                return;
            }
            DataPoint[] mzValues = massList.getDataPoints();
            // insert all mz in order and count them
            Arrays.stream(mzValues).mapToDouble(dp -> dp.getMZ()).filter(mz -> mzRange.contains(mz)).forEach(mz -> data.add(mz));
            processedScans++;
        }
    }
    if (!data.isEmpty()) {
        // to array
        double[] histo = new double[data.size()];
        for (int i = 0; i < data.size(); i++) histo[i] = data.get(i);
        // create histogram dialog
        EHistogramDialog dialog = new EHistogramDialog("m/z distribution", "m/z", new HistogramData(histo), binWidth);
        dialog.setVisible(true);
    } else {
        throw new MSDKRuntimeException("Data was empty. Review your selected filters.");
    }
    setStatus(TaskStatus.FINISHED);
    logger.info("Finished mz distribution histogram on " + dataFile);
}
Also used : HistogramData(net.sf.mzmine.modules.visualization.mzhistogram.chart.HistogramData) Scan(net.sf.mzmine.datamodel.Scan) Arrays(java.util.Arrays) EHistogramDialog(net.sf.mzmine.modules.visualization.mzhistogram.chart.EHistogramDialog) TaskStatus(net.sf.mzmine.taskcontrol.TaskStatus) Range(com.google.common.collect.Range) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) Logger(java.util.logging.Logger) DataPoint(net.sf.mzmine.datamodel.DataPoint) MassList(net.sf.mzmine.datamodel.MassList) DoubleArrayList(it.unimi.dsi.fastutil.doubles.DoubleArrayList) ParameterSet(net.sf.mzmine.parameters.ParameterSet) AbstractTask(net.sf.mzmine.taskcontrol.AbstractTask) MZmineProject(net.sf.mzmine.datamodel.MZmineProject) MSDKRuntimeException(io.github.msdk.MSDKRuntimeException) ScanSelection(net.sf.mzmine.parameters.parametertypes.selectors.ScanSelection) HistogramData(net.sf.mzmine.modules.visualization.mzhistogram.chart.HistogramData) DataPoint(net.sf.mzmine.datamodel.DataPoint) EHistogramDialog(net.sf.mzmine.modules.visualization.mzhistogram.chart.EHistogramDialog) MSDKRuntimeException(io.github.msdk.MSDKRuntimeException) Scan(net.sf.mzmine.datamodel.Scan) DoubleArrayList(it.unimi.dsi.fastutil.doubles.DoubleArrayList) MassList(net.sf.mzmine.datamodel.MassList) DataPoint(net.sf.mzmine.datamodel.DataPoint)

Example 7 with DoubleArrayList

use of it.unimi.dsi.fastutil.doubles.DoubleArrayList in project palladian by palladian.

the class Spatial2dIdMap method sort.

public void sort() {
    Collections.sort(latIds, (o1, o2) -> Double.compare(o1.getCoordinate().getLatitude(), o2.getCoordinate().getLatitude()));
    Collections.sort(lngIds, (o1, o2) -> Double.compare(o1.getCoordinate().getLongitude(), o2.getCoordinate().getLongitude()));
    latValues = new DoubleArrayList(latIds.stream().map(c -> c.getCoordinate().getLatitude()).collect(Collectors.toList()));
    lngValues = new DoubleArrayList(lngIds.stream().map(c -> c.getCoordinate().getLongitude()).collect(Collectors.toList()));
}
Also used : StopWatch(ws.palladian.helper.StopWatch) DoubleArrayList(it.unimi.dsi.fastutil.doubles.DoubleArrayList) java.util(java.util) CollectionHelper(ws.palladian.helper.collection.CollectionHelper) ObjectArrayList(it.unimi.dsi.fastutil.objects.ObjectArrayList) Collectors(java.util.stream.Collectors) ProcessHelper(ws.palladian.helper.ProcessHelper) DoubleArrayList(it.unimi.dsi.fastutil.doubles.DoubleArrayList)

Example 8 with DoubleArrayList

use of it.unimi.dsi.fastutil.doubles.DoubleArrayList in project CavalliumDBEngine by cavallium.

the class LLMultiLuceneIndex method mergeShards.

private Mono<Buckets> mergeShards(List<Buckets> shards) {
    return Mono.fromCallable(() -> {
        List<DoubleArrayList> seriesValues = new ArrayList<>();
        DoubleArrayList totals = new DoubleArrayList(shards.get(0).totals());
        for (Buckets shard : shards) {
            if (seriesValues.isEmpty()) {
                seriesValues.addAll(shard.seriesValues());
            } else {
                for (int serieIndex = 0; serieIndex < seriesValues.size(); serieIndex++) {
                    DoubleArrayList mergedSerieValues = seriesValues.get(serieIndex);
                    for (int dataIndex = 0; dataIndex < mergedSerieValues.size(); dataIndex++) {
                        mergedSerieValues.set(dataIndex, mergedSerieValues.getDouble(dataIndex) + shard.seriesValues().get(serieIndex).getDouble(dataIndex));
                    }
                }
            }
            for (int i = 0; i < totals.size(); i++) {
                totals.set(i, totals.getDouble(i) + shard.totals().getDouble(i));
            }
        }
        return new Buckets(seriesValues, totals);
    });
}
Also used : ObjectArrayList(it.unimi.dsi.fastutil.objects.ObjectArrayList) ArrayList(java.util.ArrayList) DoubleArrayList(it.unimi.dsi.fastutil.doubles.DoubleArrayList) DoubleArrayList(it.unimi.dsi.fastutil.doubles.DoubleArrayList) Buckets(it.cavallium.dbengine.lucene.collector.Buckets)

Example 9 with DoubleArrayList

use of it.unimi.dsi.fastutil.doubles.DoubleArrayList in project gdsc by aherbert.

the class ColocatedMask_PlugIn method createMask.

private void createMask(boolean preview) {
    final ImagePlus imp1 = WindowManager.getImage(settings.selectedImage1);
    final ImagePlus imp2 = WindowManager.getImage(settings.selectedImage2);
    if (imp1 == null) {
        IJ.error(TITLE, "Image " + settings.selectedImage1 + " has been closed.\nPlease restart the plugin to refresh the image list.");
        return;
    }
    if (imp2 == null) {
        IJ.error(TITLE, "Image " + settings.selectedImage2 + " has been closed.\nPlease restart the plugin to refresh the image list.");
        return;
    }
    // Change the images we are monitoring
    id1 = imp1.getID();
    id2 = imp2.getID();
    // Check the dimensions
    final int width = imp1.getWidth();
    final int height = imp1.getHeight();
    if (width != imp2.getWidth() || width != imp2.getHeight()) {
        if (preview) {
            IJ.log(TITLE + ": Images must have same XY dimensions");
        } else {
            IJ.error(TITLE, "Images must have same XY dimensions");
        }
        return;
    }
    // Create a mask using the correct stack dimensions
    final int[] dimensions1 = imp1.getDimensions();
    final int[] dimensions2 = imp2.getDimensions();
    // Produce the biggest hyperstack possible
    final String[] dimName = { "C", "Z", "T" };
    final int[] index = new int[3];
    StringBuilder sb = null;
    for (int i = 0, j = 2; i < 3; i++, j++) {
        if (dimensions1[j] == dimensions2[j]) {
            index[i] = dimensions1[j];
        } else {
            // If the CZT dimensions do not match then one must be 1
            if (dimensions1[j] != 1 && dimensions2[j] != 1) {
                IJ.error(TITLE, "Images must have same " + dimName[i] + " dimension or one must be singular");
                return;
            }
            // Use the max dimension.
            // The other image is only singular so getStackIndex will clip it appropriately.
            index[i] = Math.max(dimensions1[j], dimensions2[j]);
            // Log dimension mismatch
            if (sb == null) {
                sb = new StringBuilder(TITLE).append(" Warning - Dimension mismatch:");
            } else {
                sb.append(",");
            }
            sb.append(" ").append(dimName[i]).append(" ").append(dimensions1[j]).append("!=").append(dimensions2[j]);
        }
    }
    if (sb != null) {
        IJ.log(sb.toString());
    }
    // Get the thresholds
    final DoubleArrayList list = new DoubleArrayList(index[0] * 2);
    for (int channel = 1; channel <= index[0]; channel++) {
        list.add(getMin(imp1, channel));
        list.add(getMin(imp2, channel));
    }
    // Check if it is worth doing any work.
    final SettingsList settingsList = new SettingsList(id1, id2, width, height, dimensions1[2], dimensions1[3], dimensions1[4], dimensions2[2], dimensions2[3], dimensions2[4], settings.colocatedMode, list);
    if (settingsList.equals(lastSettingsList)) {
        return;
    }
    lastSettingsList = settingsList;
    final ImageStack imageStack1 = imp1.getStack();
    final ImageStack imageStack2 = imp2.getStack();
    final ImagePlus imp = IJ.createHyperStack(TITLE, width, height, index[0], index[1], index[2], 8);
    final ImageStack outputStack = imp.getStack();
    final double[] e = list.elements();
    for (int channel = 1, next = 0; channel <= index[0]; channel++) {
        final double min1 = e[next++];
        final double min2 = e[next++];
        for (int slice = 1; slice <= index[1]; slice++) {
            for (int frame = 1; frame <= index[2]; frame++) {
                final ImageProcessor ip1 = imageStack1.getProcessor(imp1.getStackIndex(frame, slice, frame));
                final ImageProcessor ip2 = imageStack2.getProcessor(imp2.getStackIndex(frame, slice, frame));
                final byte[] b = (byte[]) outputStack.getPixels(imp1.getStackIndex(frame, slice, frame));
                if (settings.colocatedMode == 0) {
                    // AND
                    for (int i = ip2.getPixelCount(); i-- > 0; ) {
                        if (ip1.getf(i) >= min1 && ip2.getf(i) >= min2) {
                            b[i] = (byte) 255;
                        }
                    }
                } else {
                    // OR
                    for (int i = ip2.getPixelCount(); i-- > 0; ) {
                        if (ip1.getf(i) >= min1 || ip2.getf(i) >= min2) {
                            b[i] = (byte) 255;
                        }
                    }
                }
            }
        }
    }
    final ImagePlus oldImp = WindowManager.getImage(TITLE);
    if (oldImp == null) {
        imp.show();
    } else {
        oldImp.setStack(outputStack, index[0], index[1], index[2]);
    }
}
Also used : SettingsList(uk.ac.sussex.gdsc.core.utils.SettingsList) ImageStack(ij.ImageStack) DoubleArrayList(it.unimi.dsi.fastutil.doubles.DoubleArrayList) ImagePlus(ij.ImagePlus) ImageProcessor(ij.process.ImageProcessor)

Example 10 with DoubleArrayList

use of it.unimi.dsi.fastutil.doubles.DoubleArrayList in project gdsc-smlm by aherbert.

the class OptimiserFunction method addPoint.

/**
 * Adds the point.
 *
 * @param x the x
 * @param y the y
 */
public void addPoint(double x, double y) {
    if (this.x == null) {
        this.x = new DoubleArrayList();
        this.y = new DoubleArrayList();
    }
    this.x.add(x);
    this.y.add(y);
}
Also used : DoubleArrayList(it.unimi.dsi.fastutil.doubles.DoubleArrayList)

Aggregations

DoubleArrayList (it.unimi.dsi.fastutil.doubles.DoubleArrayList)45 IntArrayList (it.unimi.dsi.fastutil.ints.IntArrayList)10 UniformRandomProvider (org.apache.commons.rng.UniformRandomProvider)6 LongArrayList (it.unimi.dsi.fastutil.longs.LongArrayList)5 IntDoubleSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage)4 IntDoubleVector (com.tencent.angel.ml.math2.vector.IntDoubleVector)4 Plot (ij.gui.Plot)4 ObjectArrayList (it.unimi.dsi.fastutil.objects.ObjectArrayList)4 BooleanArrayList (it.unimi.dsi.fastutil.booleans.BooleanArrayList)3 ByteArrayList (it.unimi.dsi.fastutil.bytes.ByteArrayList)3 CharArrayList (it.unimi.dsi.fastutil.chars.CharArrayList)3 FloatArrayList (it.unimi.dsi.fastutil.floats.FloatArrayList)3 ShortArrayList (it.unimi.dsi.fastutil.shorts.ShortArrayList)3 ArrayList (java.util.ArrayList)3 DoubleDoubleBiPredicate (uk.ac.sussex.gdsc.test.api.function.DoubleDoubleBiPredicate)3 LongDoubleSparseVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleSparseVectorStorage)2 LongDoubleVector (com.tencent.angel.ml.math2.vector.LongDoubleVector)2 BigDecimal (java.math.BigDecimal)2 MathContext (java.math.MathContext)2 List (java.util.List)2