Spectrum merger
This commit is contained in:
parent
530bc869d3
commit
f483ea7498
@ -21,10 +21,12 @@ File rootDir = new File("D:\\Work\\Numass\\data\\2016_10\\Fill_2_wide")
|
|||||||
|
|
||||||
NumassStorage storage = NumassStorage.buildLocalNumassRoot(rootDir, true);
|
NumassStorage storage = NumassStorage.buildLocalNumassRoot(rootDir, true);
|
||||||
|
|
||||||
Iterable<NMPoint> data = NumassDataUtils.sumSpectra(
|
Collection<NMPoint> data = NumassDataUtils.joinSpectra(
|
||||||
StorageUtils.loaderStream(storage).map { it.value }.filter { it.name.matches("set_.{2,3}") }
|
StorageUtils.loaderStream(storage).map { it.value }.filter { it.name.matches("set_.{2,3}") }
|
||||||
)
|
)
|
||||||
|
|
||||||
|
data = NumassDataUtils.substractReferencePoint(data, 18600d);
|
||||||
|
|
||||||
//if(!dataDir.exists()){
|
//if(!dataDir.exists()){
|
||||||
// println "dataDir directory does not exist"
|
// println "dataDir directory does not exist"
|
||||||
//}
|
//}
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* Created by darksnake on 31-Jan-17.
|
||||||
|
*/
|
||||||
|
package inr.numass.data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* package is obsolete
|
||||||
|
*/
|
@ -2,8 +2,10 @@ package inr.numass.storage;
|
|||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.Collection;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -11,8 +13,8 @@ import java.util.stream.Stream;
|
|||||||
*/
|
*/
|
||||||
public class NumassDataUtils {
|
public class NumassDataUtils {
|
||||||
|
|
||||||
public static Iterable<NMPoint> sumSpectra(Stream<NumassData> spectra) {
|
public static Collection<NMPoint> joinSpectra(Stream<NumassData> spectra) {
|
||||||
Map<Double, NMPoint> map = new HashMap<>();
|
Map<Double, NMPoint> map = new LinkedHashMap<>();
|
||||||
spectra.forEach(datum -> {
|
spectra.forEach(datum -> {
|
||||||
datum.forEach(point -> {
|
datum.forEach(point -> {
|
||||||
double uset = point.getUset();
|
double uset = point.getUset();
|
||||||
@ -26,7 +28,14 @@ public class NumassDataUtils {
|
|||||||
return map.values();
|
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()) {
|
if (first.getUset() != second.getUset()) {
|
||||||
throw new RuntimeException("Voltage mismatch");
|
throw new RuntimeException("Voltage mismatch");
|
||||||
}
|
}
|
||||||
@ -40,4 +49,23 @@ public class NumassDataUtils {
|
|||||||
newArray
|
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<NMPoint> substractReferencePoint(Collection<NMPoint> 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());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user