[med-svn] [aghermann] 13/31: literate programming in basic_score.lua

andrei zavada hmmr-guest at alioth.debian.org
Sun Nov 10 00:34:16 UTC 2013


This is an automated email from the git hooks/post-receive script.

hmmr-guest pushed a commit to branch WIP
in repository aghermann.

commit 45b59ec877d4ccab908ba33e1d8e7d8e9ec1ea23
Author: Andrei Zavada <hmmr at ra>
Date:   Sat Nov 9 13:44:04 2013 +0200

    literate programming in basic_score.lua
---
 upstream/data/basic_score.lua |  103 ++++++++++++++++++++++++++++++++++++-----
 1 file changed, 91 insertions(+), 12 deletions(-)

diff --git a/upstream/data/basic_score.lua b/upstream/data/basic_score.lua
index 91d3ec4..351066b 100644
--- a/upstream/data/basic_score.lua
+++ b/upstream/data/basic_score.lua
@@ -7,28 +7,107 @@ local A, Fi, Fo = ...
 --     of Fi and Fo (see below).
 
 -- (2) Fi, a CFunction, is the proxy to get any data related to or describing
---     the montage being scored. It has the signature
+--     the montage being scored. It has the signature (think syscall):
 --        Fi( A, opcode, arg1, arg2, ...)
---     Think syscall. For what opcode's are available and the corresponding
---     parameters, see man agherman or the project documentation online.
+--     These are the supported opcodes:
+--      1. Informational.
+local op_get_channel_list         = 1
+local op_get_channel_list_of_type = 2
+local op_get_channel_data         = 3
+--      2. Metrics describing a page:
+local op_get_psd                  = 100
+local op_get_mc                   = 101
+local op_get_swu                  = 102
+local op_get_signal_envelope      = 104
 
--- (3) Fo, also a CFunction, is used to deliver the scoring decision to the host;
---     to be used like so:
---        Fo( A, page, score)
+-- For convenience, here are wrappers:
+-- (on error, Fi returns {false, error_string}; else, results as described below)
 
-local cc = {Fi(A, 2, "EEG")}
+function get_channel_list ()
+   -- returns: n_channels, ch1, ch2, ...
+   return Fi(A, op_get_channel_list)
+end
+
+function get_channel_list_of_type (t)
+   -- args: t: signal type, e.g., "EEG", "EOG", etc.
+   -- returns: n_channels, ch1, ch2, ...
+   return Fi(A, op_get_channel_list_of_type, t)
+end
+
+function get_channel_data (h)
+   -- args: h: channel, e.g., "Fz"
+   -- returns: n_pages, n_full_pages, pagesize, samplerate
+   return Fi(A, op_get_channel_data, h)
+end
+
+function get_psd (h, pa, pz, fa, fz)
+   -- args: h: channel, e.g., "Fz",
+   --       pa, pz: starting and ending pages, inclusive;
+   --       fa, fz: frequncy range to extract PSD in.
+   -- returns: a vector of numbers.
+   return Fi(A, op_get_psd, h, pa, pz, fa, fz)
+end
+
+function get_mc (h, pa, pz, fa, _)
+   -- args: h, channel, e.g., "Fz",
+   --       pa, pz: start and end pages, inclusive;
+   --       fa: f0 range to extract MC at.
+   -- returns: a vector of numbers.
+   return Fi(A, op_get_psd, h, pa, pz, fa, fz)
+end
+
+function get_swu (h, pa, pz, fa, _)
+   -- args: h: channel, e.g., "Fz",
+   --       pa, pz: starting and ending pages, inclusive;
+   --       fa: frequncy to extract SWU at.
+   -- returns: a vector of numbers.
+   return Fi(A, op_get_psd, h, pa, pz, fa, fz)
+end
+
+function get_signal_envelope (h, p, scope, dt)
+   -- args: h: channel, e.g., "Fz",
+   --       p: page,
+   --       scope: envelope scope (tightness) parameter, sec (1 should be OK),
+   --       dt: time resolution of resulting vector
+   -- returns: a vector of signal envelope breadth values, taken at dt intervals.
+   return Fi(A, op_get_signal_envelope, p, scope, dt)
+end
+
+
+-- (3) Fo, also a CFunction, is used to deliver the scoring decision to the host
+
+local nrem1 = 1
+local nrem2 = 2
+local nrem3 = 3
+local nrem4 = 4
+local rem   = 5
+local wake  = 6
+function put_score (p, s)
+   -- args: p: page, 1-based
+   --       s: score code as above
+   -- returns: nothing
+   return Fo(A, p-1, s)
+end
+
+
+-- function main
+local cc = {get_channel_list_of_type ("EEG")}
 print( string.format( "Montage has %d EEG channels", cc[1]))
 
 local H = cc[2]
-local np, nf, ps, sr = Fi(A, 3, H)
-print( string.format( "Looking at channel %q: %d pages @%d sec, sr %d", H, np, ps, sr))
+local np, nf, ps, sr = get_channel_data (H)
+print( string.format( "Looking at channel %q: %d pages (%d full) @%d sec, samplerate %d", H, np, nf, ps, sr))
 
-local delta = {Fi(A, 100, H, 0, np-1, 2, 3)}
-local theta = {Fi(A, 100, H, 0, np-1, 4, 8)}
+local delta = {get_psd (H, 0, np-1, 2, 3)}
+local theta = {get_psd (H, 0, np-1, 4, 8)}
 
+local n_scored = 0
 for p=1,np-1 do
   if delta[p] > theta[p] * 1.5 then
+     n_scored = n_scored+1
 --    print( "mark page ", p)
-    Fo( A, p - 1, 2)
+     put_score (p - 1, 3)
   end
 end
+
+return n_scored

-- 
Alioth's /git/debian-med/git-commit-notice on /srv/git.debian.org/git/debian-med/aghermann.git



More information about the debian-med-commit mailing list