fixes imports

This commit is contained in:
Alexander Nozik 2021-10-05 16:38:33 +03:00
parent 29d9bd6a72
commit d6a1f02a0d
8 changed files with 49 additions and 39 deletions

View File

@ -13,7 +13,7 @@ allprojects {
}
val dataforgeVersion by extra("0.4.0")
val kmathVersion by extra("0.3.0-dev-13")
val kmathVersion by extra("0.3.0-dev-15")
ksciencePublish{
vcs("https://mipt-npm.jetbrains.space/p/numass/code/numass/")

View File

@ -5,7 +5,6 @@
*/
package ru.inr.mass.models
import space.kscience.kmath.expressions.StringSymbol
import space.kscience.kmath.expressions.Symbol
import space.kscience.kmath.expressions.symbol
import kotlin.math.*
@ -162,8 +161,8 @@ public object NumassBeta : DifferentiableKernel {
// P(rootsterile)+ (1-P)root
}
override val x: Symbol = StringSymbol("fs")
override val y: Symbol = StringSymbol("eIn")
override val x: Symbol = Symbol("fs")
override val y: Symbol = Symbol("eIn")
override fun invoke(fs: Double, eIn: Double, arguments: Map<Symbol, Double>): Double {
val e0 = arguments.getValue(e0)

View File

@ -1,7 +1,7 @@
package ru.inr.mass.models
import space.kscience.kmath.expressions.DifferentiableExpression
import space.kscience.kmath.expressions.Expression
import space.kscience.kmath.expressions.SpecialDifferentiableExpression
import space.kscience.kmath.expressions.Symbol
public fun interface Spectrum : Expression<Double> {
@ -13,7 +13,7 @@ public fun interface Spectrum : Expression<Double> {
invoke(arguments[abscissa] ?: error("Argument $abscissa not found in arguments"), arguments)
}
public interface DifferentiableSpectrum : DifferentiableExpression<Double, Spectrum>, Spectrum
public interface DifferentiableSpectrum : SpecialDifferentiableExpression<Double, Spectrum>, Spectrum
public fun interface Kernel : Expression<Double> {
public val x: Symbol get() = Symbol.x
@ -28,7 +28,7 @@ public fun interface Kernel : Expression<Double> {
}
}
public interface DifferentiableKernel : DifferentiableExpression<Double, Kernel>, Kernel
public interface DifferentiableKernel : SpecialDifferentiableExpression<Double, Kernel>, Kernel
public fun <T> Expression<T>.withDefault(default: Map<Symbol, T>): Expression<T> = Expression { args ->
invoke(default + args)

View File

@ -93,14 +93,16 @@ public class SterileNeutrinoSpectrum(
// getHighDensityIntegrator()
// }
return DoubleField.gaussIntegrator.integrate(u..eMax, generateRanges(
u..eMax,
u + 2.0,
u + 7.0,
u + 15.0,
u + 30.0,
*((u + 50)..(u + 6000) step 25.0).toDoubleArray()
)) { eIn ->
return DoubleField.gaussIntegrator.integrate(
u..eMax, generateRanges(
u..eMax,
u + 2.0,
u + 7.0,
u + 15.0,
u + 30.0,
*((u + 50)..(u + 6000) step 25.0).toDoubleArray()
)
) { eIn ->
sumByFSS(eIn, sourceFunction, arguments) * transResFunction(eIn, u, arguments)
}.value
}
@ -135,14 +137,16 @@ public class SterileNeutrinoSpectrum(
eIn: Double,
u: Double,
arguments: Map<Symbol, Double>,
): Double = DoubleField.gaussIntegrator.integrate(u..eIn, generateRanges(
u..eIn,
u + 2.0,
u + 7.0,
u + 15.0,
u + 30.0,
*((u + 50)..(u + 6000) step 30.0).toDoubleArray()
)) { eOut: Double ->
): Double = DoubleField.gaussIntegrator.integrate(
u..eIn, generateRanges(
u..eIn,
u + 2.0,
u + 7.0,
u + 15.0,
u + 30.0,
*((u + 50)..(u + 6000) step 30.0).toDoubleArray()
)
) { eOut: Double ->
transFunc(eIn, eOut, arguments) * resolution(eOut, u, arguments)
}.value
}

View File

@ -1,3 +1,4 @@
@file:Suppress("EXPERIMENTAL_API_USAGE")
package ru.inr.mass.workspace
import kotlinx.coroutines.flow.collect
@ -14,11 +15,13 @@ import space.kscience.kmath.structures.asBuffer
/**
* Build an amplitude spectrum
* Build an amplitude spectrum with bin of 1.0 counted from 0.0. Some bins could be missing
*/
fun NumassPoint.spectrum(): UnivariateHistogram = UnivariateHistogram.uniform(1.0) {
runBlocking {
events.collect { put(it.amplitude.toDouble()) }
events.collect {
putValue(it.amplitude.toDouble())
}
}
}

View File

@ -20,14 +20,13 @@ import kotlin.streams.toList
fun readNumassDirectory(path: String): NumassDirectorySet = NUMASS.context.readNumassDirectory(path)
@OptIn(ExperimentalPathApi::class)
suspend fun readNumassRepository(path: String): DataTree<NumassDirectorySet> = ActiveDataTree {
val basePath = Path.of(path)
suspend fun readNumassRepository(path: Path): DataTree<NumassDirectorySet> = ActiveDataTree {
@Suppress("BlockingMethodInNonBlockingContext")
withContext(Dispatchers.IO) {
Files.walk(Path.of(path)).filter {
Files.walk(path).filter {
it.isDirectory() && it.resolve("meta").exists()
}.toList().forEach { childPath ->
val name = Name(childPath.relativeTo(basePath).map { segment ->
val name = Name(childPath.relativeTo(path).map { segment ->
NameToken(segment.fileName.toString())
})
val value = NUMASS.context.readNumassDirectory(childPath)
@ -36,3 +35,5 @@ suspend fun readNumassRepository(path: String): DataTree<NumassDirectorySet> = A
}
//TODO add file watcher
}
suspend fun readNumassRepository(path: String): DataTree<NumassDirectorySet> = readNumassRepository(Path.of(path))

View File

@ -10,23 +10,22 @@ import space.kscience.dataforge.values.double
import space.kscience.kmath.histogram.UnivariateHistogram
import space.kscience.kmath.histogram.center
import space.kscience.kmath.misc.UnstableKMathAPI
import space.kscience.kmath.operations.asIterable
import space.kscience.kmath.structures.Buffer
import space.kscience.kmath.structures.DoubleBuffer
import space.kscience.kmath.structures.asIterable
import space.kscience.plotly.*
import space.kscience.plotly.models.Scatter
import space.kscience.plotly.models.Trace
import space.kscience.plotly.models.TraceValues
/**
* Plot a kmath histogram
*/
@OptIn(UnstableKMathAPI::class)
fun Trace.fromSpectrum(histogram: UnivariateHistogram) {
fun Plot.histogram(histogram: UnivariateHistogram, block: Scatter.() -> Unit): Trace = scatter {
x.numbers = histogram.bins.map { it.domain.center }
y.numbers = histogram.bins.map { it.value }
}
@OptIn(UnstableKMathAPI::class)
fun Plot.spectrum(name: String, histogram: UnivariateHistogram): Trace = scatter {
this.name = name
fromSpectrum(histogram)
block()
}
fun Plot.amplitudeSpectrum(
@ -35,7 +34,9 @@ fun Plot.amplitudeSpectrum(
range: IntRange = 0..2000,
name: String = point.toString(),
): Trace = scatter {
spectrum(name, point.spectrum().reShape(binSize, range))
histogram(point.spectrum().reShape(binSize, range)) {
this.name = name
}
}
/**
@ -59,6 +60,7 @@ fun Plotly.numassDirectory(set: NumassDirectorySet, binSize: Int = 20, range: In
amplitudeSpectrum(it, binSize, range)
}
}
set.getHvData()?.let { entries ->
h2 {
+"HV"

View File

@ -1,7 +1,8 @@
package ru.inr.mass
import ru.inr.mass.models.*
import space.kscience.kmath.misc.Symbol
import space.kscience.kmath.expressions.Symbol
import kotlin.math.abs
import kotlin.math.pow
import kotlin.math.sqrt