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);
}
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()));
}
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);
});
}
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]);
}
}
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);
}
Aggregations