[chronojump] extrema was missing on RDotNet
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] extrema was missing on RDotNet
- Date: Mon, 10 Mar 2014 16:21:48 +0000 (UTC)
commit 2656249341c13042991f8300f40f1e81b7298e19
Author: Xavier de Blas <xaviblas gmail com>
Date: Mon Mar 10 17:21:02 2014 +0100
extrema was missing on RDotNet
.../howto-bootloader-and-firmware.txt | 2 +-
encoder/Makefile.am | 3 +-
encoder/util.R | 74 ++++++++++++++++++++
src/constants.cs | 1 +
src/gui/encoder.cs | 3 +
src/utilEncoder.cs | 5 ++
6 files changed, 86 insertions(+), 2 deletions(-)
---
diff --git a/chronopic-firmware/howto-bootloader-and-firmware.txt
b/chronopic-firmware/howto-bootloader-and-firmware.txt
index d6e7cee..8202167 100644
--- a/chronopic-firmware/howto-bootloader-and-firmware.txt
+++ b/chronopic-firmware/howto-bootloader-and-firmware.txt
@@ -51,7 +51,7 @@ sembla que es grava amb 3F32
2.A encoder 20MHz grabar firmware:
----------------------------------
-Cal que el click estigui posat a 20
+Cal que el clock estigui posat a 20
per 20MHz cal el pydownloader-wx,pero no va pq necessita python 2.6
anem a agafar el pydownloader de la web (sense wx) i compilar-lo
diff --git a/encoder/Makefile.am b/encoder/Makefile.am
index d05d6f7..927f37b 100644
--- a/encoder/Makefile.am
+++ b/encoder/Makefile.am
@@ -2,4 +2,5 @@ encoderdatadir = @datadir@/@PACKAGE@/encoder
dist_encoderdata_DATA = pyserial_pyper.py \
graph.R \
- inertia-momentum.R
+ inertia-momentum.R \
+ util.R
diff --git a/encoder/util.R b/encoder/util.R
new file mode 100644
index 0000000..2fa0c1e
--- /dev/null
+++ b/encoder/util.R
@@ -0,0 +1,74 @@
+#extrema function is part of R EMD package
+#It's included here to save time, because 'library("EMD")' is quite time consuming
+
+extrema <- function(y, ndata = length(y), ndatam1 = ndata - 1) {
+
+ minindex <- maxindex <- NULL; nextreme <- 0; cross <- NULL; ncross <- 0
+
+ z1 <- sign(diff(y))
+ index1 <- seq(1, ndatam1)[z1 != 0]; z1 <- z1[z1 != 0]
+
+ if (!(is.null(index1) || all(z1==1) || all(z1==-1))) {
+
+ index1 <- index1[c(z1[-length(z1)] != z1[-1], FALSE)] + 1
+ z1 <- z1[c(z1[-length(z1)] != z1[-1], FALSE)]
+
+ nextreme <- length(index1)
+
+ if(nextreme >= 2)
+ for(i in 1:(nextreme-1)) {
+ tmpindex <- index1[i]:(index1[i+1]-1)
+ if(z1[i] > 0) {
+ tmpindex <- tmpindex[y[index1[i]] == y[tmpindex]]
+ maxindex <- rbind(maxindex, c(min(tmpindex), max(tmpindex)))
+ } else {
+ tmpindex <- tmpindex[y[index1[i]] == y[tmpindex]]
+ minindex <- rbind(minindex, c(min(tmpindex), max(tmpindex)))
+ }
+ }
+
+ tmpindex <- index1[nextreme]:ndatam1
+ if(z1[nextreme] > 0) {
+ tmpindex <- tmpindex[y[index1[nextreme]] == y[tmpindex]]
+ maxindex <- rbind(maxindex, c(min(tmpindex), max(tmpindex)))
+ } else {
+ tmpindex <- tmpindex[y[index1[nextreme]] == y[tmpindex]]
+ minindex <- rbind(minindex, c(min(tmpindex), max(tmpindex)))
+ }
+
+ ### Finding the index of zero crossing
+
+ if (!(all(sign(y) >= 0) || all(sign(y) <= 0) || all(sign(y) == 0))) {
+ index1 <- c(1, index1)
+ for (i in 1:nextreme) {
+ if (y[index1[i]] == 0) {
+ tmp <- c(index1[i]:index1[i+1])[y[index1[i]:index1[i+1]] == 0]
+ cross <- rbind(cross, c(min(tmp), max(tmp)))
+ } else
+ if (y[index1[i]] * y[index1[i+1]] < 0) {
+ tmp <- min(c(index1[i]:index1[i+1])[y[index1[i]] *
y[index1[i]:index1[i+1]] <= 0])
+ if (y[tmp] == 0) {
+ tmp <- c(tmp:index1[i+1])[y[tmp:index1[i+1]] == 0]
+ cross <- rbind(cross, c(min(tmp), max(tmp)))
+ } else
+ cross <- rbind(cross, c(tmp-1, tmp))
+ }
+ }
+ #if (y[ndata] == 0) {
+ # tmp <- c(index1[nextreme+1]:ndata)[y[index1[nextreme+1]:ndata] == 0]
+ # cross <- rbind(cross, c(min(tmp), max(tmp)))
+ #} else
+ if (any(y[index1[nextreme+1]] * y[index1[nextreme+1]:ndata] <= 0)) {
+ tmp <- min(c(index1[nextreme+1]:ndata)[y[index1[nextreme+1]] *
y[index1[nextreme+1]:ndata] <= 0])
+ if (y[tmp] == 0) {
+ tmp <- c(tmp:ndata)[y[tmp:ndata] == 0]
+ cross <- rbind(cross, c(min(tmp), max(tmp)))
+ } else
+ cross <- rbind(cross, c(tmp-1, tmp))
+ }
+ ncross <- nrow(cross)
+ }
+ }
+
+ list(minindex=minindex, maxindex=maxindex, nextreme=nextreme, cross=cross, ncross=ncross)
+}
diff --git a/src/constants.cs b/src/constants.cs
index 71c907f..a1918d6 100644
--- a/src/constants.cs
+++ b/src/constants.cs
@@ -615,6 +615,7 @@ public class Constants
public static string EncoderScriptCaptureWindows = "pyserial_pyper_windows.exe";
public static string EncoderScriptGraph = "graph.R";
public static string EncoderScriptInertiaMomentum = "inertia-momentum.R";
+ public static string EncoderScriptUtilR = "util.R";
//no longer used:
//public static string EncoderScriptGraphCall =
//"/home/xavier/informatica/progs_meus/chronojump/chronojump/encoder/call_graph.py";
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 469cde9..14130fc 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -1804,6 +1804,9 @@ public partial class ChronoJumpWindow
}
*/
+ //load extrema method copied from EMD package
+ rengine.Evaluate("source('" + UtilEncoder.GetEncoderScriptUtilR() + "')");
+
try {
// .NET Framework array to R vector.
NumericVector group1 = rengine.CreateNumericVector(new double[] { 30.02, 29.99,
30.11, 29.97, 30.01, 29.99 });
diff --git a/src/utilEncoder.cs b/src/utilEncoder.cs
index 0c26d89..2fbfa55 100644
--- a/src/utilEncoder.cs
+++ b/src/utilEncoder.cs
@@ -166,6 +166,11 @@ public class UtilEncoder
Util.GetDataDir(), "encoder", Constants.EncoderScriptInertiaMomentum);
}
+ public static string GetEncoderScriptUtilR() {
+ return System.IO.Path.Combine(
+ Util.GetDataDir(), "encoder", Constants.EncoderScriptUtilR);
+ }
+
/********** end of encoder paths ************/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]