From f483ea74982eb664fe8b6ef49cef80aeff4b9485 Mon Sep 17 00:00:00 2001 From: darksnake Date: Tue, 31 Jan 2017 20:06:19 +0300 Subject: [PATCH] Spectrum merger --- .../inr/numass/scripts/Underflow.groovy | 4 ++- .../java/inr/numass/data/package-info.java | 8 +++++ .../inr/numass/storage/NumassDataUtils.java | 36 ++++++++++++++++--- 3 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 numass-main/src/main/java/inr/numass/data/package-info.java diff --git a/numass-main/src/main/groovy/inr/numass/scripts/Underflow.groovy b/numass-main/src/main/groovy/inr/numass/scripts/Underflow.groovy index 98797e7e..7a9c4ced 100644 --- a/numass-main/src/main/groovy/inr/numass/scripts/Underflow.groovy +++ b/numass-main/src/main/groovy/inr/numass/scripts/Underflow.groovy @@ -21,10 +21,12 @@ File rootDir = new File("D:\\Work\\Numass\\data\\2016_10\\Fill_2_wide") NumassStorage storage = NumassStorage.buildLocalNumassRoot(rootDir, true); -Iterable data = NumassDataUtils.sumSpectra( +Collection data = NumassDataUtils.joinSpectra( StorageUtils.loaderStream(storage).map { it.value }.filter { it.name.matches("set_.{2,3}") } ) +data = NumassDataUtils.substractReferencePoint(data, 18600d); + //if(!dataDir.exists()){ // println "dataDir directory does not exist" //} diff --git a/numass-main/src/main/java/inr/numass/data/package-info.java b/numass-main/src/main/java/inr/numass/data/package-info.java new file mode 100644 index 00000000..9f467a68 --- /dev/null +++ b/numass-main/src/main/java/inr/numass/data/package-info.java @@ -0,0 +1,8 @@ +/** + * Created by darksnake on 31-Jan-17. + */ +package inr.numass.data; + +/** + * package is obsolete + */ diff --git a/numass-storage/src/main/java/inr/numass/storage/NumassDataUtils.java b/numass-storage/src/main/java/inr/numass/storage/NumassDataUtils.java index 9de69124..884c1982 100644 --- a/numass-storage/src/main/java/inr/numass/storage/NumassDataUtils.java +++ b/numass-storage/src/main/java/inr/numass/storage/NumassDataUtils.java @@ -2,8 +2,10 @@ package inr.numass.storage; import java.time.Instant; import java.util.Arrays; -import java.util.HashMap; +import java.util.Collection; +import java.util.LinkedHashMap; import java.util.Map; +import java.util.stream.Collectors; import java.util.stream.Stream; /** @@ -11,8 +13,8 @@ import java.util.stream.Stream; */ public class NumassDataUtils { - public static Iterable sumSpectra(Stream spectra) { - Map map = new HashMap<>(); + public static Collection joinSpectra(Stream spectra) { + Map map = new LinkedHashMap<>(); spectra.forEach(datum -> { datum.forEach(point -> { double uset = point.getUset(); @@ -26,7 +28,14 @@ public class NumassDataUtils { return map.values(); } - private static NMPoint join(NMPoint first, NMPoint second) { + /** + * Spectral sum of two points + * + * @param first + * @param second + * @return + */ + public static NMPoint join(NMPoint first, NMPoint second) { if (first.getUset() != second.getUset()) { throw new RuntimeException("Voltage mismatch"); } @@ -40,4 +49,23 @@ public class NumassDataUtils { newArray ); } + + public static NMPoint substractPoint(NMPoint point, NMPoint reference) { + int[] array = new int[point.getSpectrum().length]; + Arrays.setAll(array, i -> Math.max(0, point.getSpectrum()[i] - reference.getSpectrum()[i])); + return new NMPoint( + point.getUset(), + point.getUread(), + point.getStartTime(), + point.getLength(), + array + ); + } + + public static Collection substractReferencePoint(Collection points, double uset) { + NMPoint reference = points.stream().filter(it -> it.getUset() == uset).findFirst() + .orElseThrow(() -> new RuntimeException("Reference point not found")); + return points.stream().map(it -> substractPoint(it, reference)).collect(Collectors.toList()); + } + }