0.1.3
This commit is contained in:
parent
5d3e6948db
commit
b911790238
@ -14,7 +14,7 @@ allprojects {
|
||||
|
||||
val dataforgeVersion by extra("0.5.2")
|
||||
val tablesVersion: String by extra("0.1.5")
|
||||
val kmathVersion by extra("0.3.0-dev-18")
|
||||
val kmathVersion by extra("0.3.0")
|
||||
val plotlyVersion: String by extra("0.5.0")
|
||||
|
||||
ksciencePublish{
|
||||
|
@ -1,12 +1,14 @@
|
||||
package ru.inr.mass.data.analysis
|
||||
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.collect
|
||||
import kotlinx.coroutines.flow.transform
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import ru.inr.mass.data.api.NumassBlock
|
||||
import ru.inr.mass.data.api.getTime
|
||||
import space.kscience.kmath.histogram.UnivariateHistogram
|
||||
import space.kscience.kmath.histogram.Histogram
|
||||
import space.kscience.kmath.histogram.UniformHistogram1D
|
||||
import space.kscience.kmath.histogram.uniform1D
|
||||
import space.kscience.kmath.operations.DoubleField
|
||||
import kotlin.math.max
|
||||
import kotlin.time.DurationUnit
|
||||
|
||||
@ -23,7 +25,7 @@ public fun <T, R> Flow<T>.zipWithNext(block: (l: T, r: T) -> R): Flow<R> {
|
||||
public fun NumassBlock.timeHistogram(
|
||||
binSize: Double,
|
||||
extractor: NumassEventExtractor = NumassEventExtractor.EVENTS_ONLY,
|
||||
): UnivariateHistogram = UnivariateHistogram.uniform(binSize) {
|
||||
): UniformHistogram1D<Double> = Histogram.uniform1D(DoubleField, binSize).produce {
|
||||
runBlocking {
|
||||
extractor.extract(this@timeHistogram).zipWithNext { l, r ->
|
||||
if(l.owner == r.owner) {
|
||||
|
@ -7,8 +7,8 @@ package ru.inr.mass.models
|
||||
|
||||
import space.kscience.kmath.expressions.Symbol
|
||||
import space.kscience.kmath.expressions.symbol
|
||||
import space.kscience.kmath.functions.Function1D
|
||||
import space.kscience.kmath.functions.PiecewisePolynomial
|
||||
import space.kscience.kmath.functions.UnivariateFunction
|
||||
import space.kscience.kmath.functions.asFunction
|
||||
import space.kscience.kmath.integration.*
|
||||
import space.kscience.kmath.operations.DoubleField
|
||||
@ -84,7 +84,7 @@ public class NumassTransmission(
|
||||
public val trap: Symbol by symbol
|
||||
public val thickness: Symbol by symbol
|
||||
|
||||
private val cache = HashMap<Int, UnivariateFunction<Double>>()
|
||||
private val cache = HashMap<Int, Function1D<Double>>()
|
||||
|
||||
private const val ION_POTENTIAL = 15.4//eV
|
||||
|
||||
@ -130,7 +130,7 @@ public class NumassTransmission(
|
||||
return exp(-x)
|
||||
}
|
||||
|
||||
private fun getCachedSpectrum(order: Int): UnivariateFunction<Double> {
|
||||
private fun getCachedSpectrum(order: Int): Function1D<Double> {
|
||||
return when {
|
||||
order <= 0 -> error("Non-positive loss cache order")
|
||||
order == 1 -> singleScatterFunction
|
||||
@ -147,7 +147,7 @@ public class NumassTransmission(
|
||||
* @param order
|
||||
* @return
|
||||
*/
|
||||
private fun getLoss(order: Int): UnivariateFunction<Double> = getCachedSpectrum(order)
|
||||
private fun getLoss(order: Int): Function1D<Double> = getCachedSpectrum(order)
|
||||
|
||||
private fun getLossProbDerivs(x: Double): List<Double> {
|
||||
val res = ArrayList<Double>()
|
||||
@ -260,7 +260,7 @@ public class NumassTransmission(
|
||||
* @return
|
||||
*/
|
||||
@Synchronized
|
||||
private fun getNextLoss(margin: Double, loss: UnivariateFunction<Double>): PiecewisePolynomial<Double> {
|
||||
private fun getNextLoss(margin: Double, loss: Function1D<Double>): PiecewisePolynomial<Double> {
|
||||
val res = { x: Double ->
|
||||
DoubleField.simpsonIntegrator.integrate(5.0..margin, IntegrandMaxCalls(200)) { y ->
|
||||
loss(x - y) * singleScatterFunction(y)
|
||||
@ -324,7 +324,7 @@ public class NumassTransmission(
|
||||
private val w1 = 1.85
|
||||
private val w2 = 12.5
|
||||
|
||||
public val singleScatterFunction: UnivariateFunction<Double> = { eps: Double ->
|
||||
public val singleScatterFunction: Function1D<Double> = { eps: Double ->
|
||||
when {
|
||||
eps <= 0 -> 0.0
|
||||
eps <= b -> {
|
||||
|
@ -1,15 +1,15 @@
|
||||
package ru.inr.mass.models
|
||||
|
||||
|
||||
import space.kscience.kmath.functions.Function1D
|
||||
import space.kscience.kmath.functions.PiecewisePolynomial
|
||||
import space.kscience.kmath.functions.UnivariateFunction
|
||||
import space.kscience.kmath.interpolation.SplineInterpolator
|
||||
import space.kscience.kmath.interpolation.interpolatePolynomials
|
||||
import space.kscience.kmath.operations.DoubleField
|
||||
import space.kscience.kmath.structures.DoubleBuffer
|
||||
import kotlin.math.abs
|
||||
|
||||
public fun UnivariateFunction<Double>.cache(
|
||||
public fun Function1D<Double>.cache(
|
||||
range: ClosedFloatingPointRange<Double>,
|
||||
numCachePoints: Int,
|
||||
): PiecewisePolynomial<Double> {
|
||||
|
@ -1,7 +1,5 @@
|
||||
package ru.inr.mass.scripts
|
||||
|
||||
import kotlinx.datetime.DateTimeUnit
|
||||
import kotlinx.datetime.plus
|
||||
import ru.inr.mass.data.api.NumassBlock
|
||||
import ru.inr.mass.data.api.channels
|
||||
import ru.inr.mass.workspace.Numass
|
||||
@ -29,8 +27,9 @@ fun main() {
|
||||
channels.forEach { (key, block) ->
|
||||
targetDir.resolve("channel-$key.csv").write {
|
||||
block.listFrames().forEach { frame ->
|
||||
val frameTime = pointTime.plus(frame.timeOffset, DateTimeUnit.NANOSECOND)
|
||||
writeUtf8String("$frameTime,")
|
||||
// val frameTime = pointTime.plus(frame.timeOffset, DateTimeUnit.NANOSECOND)
|
||||
// writeUtf8String("$frameTime,")
|
||||
writeUtf8String("${frame.timeOffset},")
|
||||
val line = frame.signal.joinToString(",", postfix = "\n" )
|
||||
writeUtf8String(line)
|
||||
}
|
||||
|
@ -5,8 +5,8 @@ import space.kscience.kmath.functions.asFunction
|
||||
import space.kscience.kmath.integration.integrate
|
||||
import space.kscience.kmath.integration.splineIntegrator
|
||||
import space.kscience.kmath.integration.value
|
||||
import space.kscience.kmath.interpolation.SplineInterpolator
|
||||
import space.kscience.kmath.interpolation.interpolatePolynomials
|
||||
import space.kscience.kmath.interpolation.splineInterpolator
|
||||
import space.kscience.kmath.operations.DoubleField
|
||||
import space.kscience.kmath.real.step
|
||||
import space.kscience.plotly.Plotly
|
||||
@ -28,7 +28,7 @@ fun main() {
|
||||
Pair(e.toDouble(), p.toDouble())
|
||||
}.toList()
|
||||
|
||||
val interpolated = SplineInterpolator.double
|
||||
val interpolated = DoubleField.splineInterpolator
|
||||
.interpolatePolynomials(backScatteringSpectrum)
|
||||
.asFunction(DoubleField, 0.0)
|
||||
|
||||
|
@ -12,8 +12,8 @@ import ru.inr.mass.data.proto.HVData
|
||||
import ru.inr.mass.data.proto.NumassDirectorySet
|
||||
import space.kscience.dataforge.values.asValue
|
||||
import space.kscience.dataforge.values.double
|
||||
import space.kscience.kmath.histogram.UnivariateHistogram
|
||||
import space.kscience.kmath.histogram.center
|
||||
import space.kscience.kmath.domains.center
|
||||
import space.kscience.kmath.histogram.Histogram1D
|
||||
import space.kscience.kmath.misc.UnstableKMathAPI
|
||||
import space.kscience.kmath.operations.asIterable
|
||||
import space.kscience.kmath.structures.Buffer
|
||||
@ -26,9 +26,9 @@ import kotlin.time.DurationUnit
|
||||
* Plot a kmath histogram
|
||||
*/
|
||||
@OptIn(UnstableKMathAPI::class)
|
||||
fun Plot.histogram(histogram: UnivariateHistogram, block: Scatter.() -> Unit = {}): Trace = scatter {
|
||||
fun Plot.histogram(histogram: Histogram1D<Double, Double>, block: Scatter.() -> Unit = {}): Trace = scatter {
|
||||
x.numbers = histogram.bins.map { it.domain.center }
|
||||
y.numbers = histogram.bins.map { it.value }
|
||||
y.numbers = histogram.bins.map { it.binValue }
|
||||
line.shape = LineShape.hv
|
||||
block()
|
||||
}
|
||||
@ -58,7 +58,7 @@ fun Plotly.plotNumassBlock(
|
||||
block: NumassBlock,
|
||||
amplitudeBinSize: UInt = 20U,
|
||||
eventExtractor: NumassEventExtractor = NumassEventExtractor.EVENTS_ONLY,
|
||||
splitChannels: Boolean = true
|
||||
splitChannels: Boolean = true,
|
||||
): PlotlyFragment = Plotly.fragment {
|
||||
plot {
|
||||
runBlocking {
|
||||
@ -105,7 +105,7 @@ fun Plotly.plotNumassSet(
|
||||
h2 { +"Time spectra" }
|
||||
|
||||
plot {
|
||||
spectra.forEach { (point,spectrum) ->
|
||||
spectra.forEach { (point, spectrum) ->
|
||||
val countRate = runBlocking {
|
||||
spectrum.sum().toDouble() / point.getLength().toDouble(DurationUnit.SECONDS)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user