lunapi 1.3.1__cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lunapi/__init__.py +13 -0
- lunapi/lunapi0.cpp +391 -0
- lunapi/lunapi0.cpython-313-x86_64-linux-gnu.so +0 -0
- lunapi/lunapi1.py +2546 -0
- lunapi-1.3.1.dist-info/METADATA +37 -0
- lunapi-1.3.1.dist-info/RECORD +8 -0
- lunapi-1.3.1.dist-info/WHEEL +6 -0
- lunapi-1.3.1.dist-info/licenses/LICENSE +674 -0
lunapi/__init__.py
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
"""The lunapi package provides an interface to the C/C++ Luna library.
|
2
|
+
|
3
|
+
This package comprises two modules
|
4
|
+
|
5
|
+
__lunapi0__ is a pybind11-generated functions to the core C/C++
|
6
|
+
(lunapi_t) functions
|
7
|
+
|
8
|
+
__lunapi1__ is a a higher-level wrapper around lunapi0-level
|
9
|
+
functions; most users will want to use lunapi1 functions
|
10
|
+
|
11
|
+
"""
|
12
|
+
|
13
|
+
from lunapi.lunapi1 import *
|
lunapi/lunapi0.cpp
ADDED
@@ -0,0 +1,391 @@
|
|
1
|
+
|
2
|
+
// --------------------------------------------------------------------
|
3
|
+
//
|
4
|
+
// This file is part of Luna.
|
5
|
+
//
|
6
|
+
// LUNA is free software: you can redistribute it and/or modify
|
7
|
+
// it under the terms of the GNU General Public License as published by
|
8
|
+
// the Free Software Foundation, either version 3 of the License, or
|
9
|
+
// (at your option) any later version.
|
10
|
+
//
|
11
|
+
// Luna is distributed in the hope that it will be useful,
|
12
|
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
// GNU General Public License for more details.
|
15
|
+
//
|
16
|
+
// You should have received a copy of the GNU General Public License
|
17
|
+
// along with Luna. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
//
|
19
|
+
// Please see LICENSE.txt for more details.
|
20
|
+
//
|
21
|
+
// --------------------------------------------------------------------
|
22
|
+
|
23
|
+
#include <pybind11/pybind11.h>
|
24
|
+
#include <pybind11/stl.h>
|
25
|
+
#include <pybind11/eigen.h>
|
26
|
+
|
27
|
+
#include "luna.h"
|
28
|
+
|
29
|
+
namespace py = pybind11;
|
30
|
+
|
31
|
+
using namespace pybind11::literals;
|
32
|
+
|
33
|
+
PYBIND11_MODULE(lunapi0, m) {
|
34
|
+
|
35
|
+
m.doc() = "LunaAPI: Python bindings for the Luna C/C++ library";
|
36
|
+
|
37
|
+
m.def( "inaugurate",
|
38
|
+
&lunapi_t::inaugurate,
|
39
|
+
py::return_value_policy::reference ,
|
40
|
+
"Start/return a reference to the Luna engine" );
|
41
|
+
|
42
|
+
m.def( "retire",
|
43
|
+
&lunapi_t::retire,
|
44
|
+
"Retire an extant Luna engine" );
|
45
|
+
|
46
|
+
m.def( "cmdfile" ,
|
47
|
+
&lunapi_t::cmdfile ,
|
48
|
+
"Load a Luna script from a file" );
|
49
|
+
|
50
|
+
m.def( "version" ,
|
51
|
+
&lunapi_t::version ,
|
52
|
+
"Version of Luna" );
|
53
|
+
|
54
|
+
m.def( "fetch_doms" ,
|
55
|
+
&lunapi_t::fetch_doms ,
|
56
|
+
"Fetch all command domains" );
|
57
|
+
m.def( "fetch_cmds" ,
|
58
|
+
&lunapi_t::fetch_cmds ,
|
59
|
+
"Fetch all commands" );
|
60
|
+
m.def( "fetch_params" ,
|
61
|
+
&lunapi_t::fetch_params ,
|
62
|
+
"Fetch all parameters for a command" );
|
63
|
+
m.def( "fetch_tbls" ,
|
64
|
+
&lunapi_t::fetch_tbls ,
|
65
|
+
"Fetch all tables for a command" );
|
66
|
+
m.def( "fetch_vars" ,
|
67
|
+
&lunapi_t::fetch_vars ,
|
68
|
+
"Fetch all variables for a command/table" );
|
69
|
+
|
70
|
+
m.def( "fetch_desc_dom" ,
|
71
|
+
&lunapi_t::fetch_desc_dom ,
|
72
|
+
"Description for a domain" );
|
73
|
+
m.def( "fetch_desc_cmd" ,
|
74
|
+
&lunapi_t::fetch_desc_cmd ,
|
75
|
+
"Description for a command" );
|
76
|
+
m.def( "fetch_desc_param" ,
|
77
|
+
&lunapi_t::fetch_desc_param ,
|
78
|
+
"Description for a command/parameter" );
|
79
|
+
m.def( "fetch_desc_tbl" ,
|
80
|
+
&lunapi_t::fetch_desc_tbl ,
|
81
|
+
"Description for a command/table" );
|
82
|
+
m.def( "fetch_desc_var" ,
|
83
|
+
&lunapi_t::fetch_desc_var ,
|
84
|
+
"Description for a command/table/variable" );
|
85
|
+
|
86
|
+
|
87
|
+
//
|
88
|
+
// lunapi_t engine class
|
89
|
+
//
|
90
|
+
|
91
|
+
py::class_<lunapi_t>(m, "luna")
|
92
|
+
|
93
|
+
.def( "read_sample_list" ,
|
94
|
+
&lunapi_t::read_sample_list,
|
95
|
+
"Load a sample list from a file" )
|
96
|
+
.def( "build_sample_list" ,
|
97
|
+
&lunapi_t::build_sample_list,
|
98
|
+
"Load a sample list from a file" )
|
99
|
+
.def( "set_sample_list",
|
100
|
+
&lunapi_t::set_sample_list,
|
101
|
+
"Set sample list directly" )
|
102
|
+
.def( "get_sample_list" ,
|
103
|
+
&lunapi_t::sample_list,
|
104
|
+
"Return the loaded sample list" )
|
105
|
+
.def( "validate_sample_list" ,
|
106
|
+
&lunapi_t::validate_sample_list ,
|
107
|
+
"Validate an attached sample list" )
|
108
|
+
.def( "insert_inst" , &lunapi_t::insert_inst )
|
109
|
+
.def( "nobs" , &lunapi_t::nobs )
|
110
|
+
.def( "clear" , &lunapi_t::clear )
|
111
|
+
|
112
|
+
.def( "silence", &lunapi_t::silence )
|
113
|
+
.def( "is_silenced" , &lunapi_t::is_silenced )
|
114
|
+
|
115
|
+
.def( "flush" , &lunapi_t::flush )
|
116
|
+
.def( "reinit" , &lunapi_t::re_init )
|
117
|
+
.def( "reset" , &lunapi_t::reset )
|
118
|
+
|
119
|
+
.def( "include" ,
|
120
|
+
&lunapi_t::includefile ,
|
121
|
+
"Include a @parameter-file" )
|
122
|
+
|
123
|
+
.def( "aliases" ,
|
124
|
+
&lunapi_t::aliases ,
|
125
|
+
"Return table of signal & annotation aliases/mappings" )
|
126
|
+
|
127
|
+
.def("opt",py::overload_cast<const std::string &,const std::string &>(&lunapi_t::var),
|
128
|
+
"Set an option value" )
|
129
|
+
|
130
|
+
.def("get_opt",py::overload_cast<const std::string &>(&lunapi_t::var,py::const_ ),
|
131
|
+
"Show an option value" )
|
132
|
+
.def("get_opts",py::overload_cast<const std::vector<std::string> &>(&lunapi_t::vars,py::const_),
|
133
|
+
"Show multiple option values" )
|
134
|
+
.def("get_all_opts",py::overload_cast<>(&lunapi_t::vars,py::const_),
|
135
|
+
"Show all option values" )
|
136
|
+
|
137
|
+
.def("clear_opts",&lunapi_t::dropvars,
|
138
|
+
"Clear options" )
|
139
|
+
.def("clear_all_opts",&lunapi_t::dropallvars,
|
140
|
+
"Clear all options" )
|
141
|
+
|
142
|
+
.def("clear_ivars",&lunapi_t::clear_ivars,
|
143
|
+
"Clear all individual-variables")
|
144
|
+
|
145
|
+
.def( "inst" ,
|
146
|
+
py::overload_cast<int>
|
147
|
+
(&lunapi_t::inst,py::const_),
|
148
|
+
"Return a lunapi-instance object from a sample list" )
|
149
|
+
|
150
|
+
.def( "inst" ,
|
151
|
+
py::overload_cast<const std::string&>
|
152
|
+
(&lunapi_t::inst,py::const_),
|
153
|
+
"Generate an lunapi-instance" )
|
154
|
+
|
155
|
+
.def( "empty_inst" ,
|
156
|
+
py::overload_cast<const std::string&,const int, const int, const std::string&, const std::string&>
|
157
|
+
(&lunapi_t::inst,py::const_),
|
158
|
+
"Generate an empty lunapi-instance of fixed record size" )
|
159
|
+
|
160
|
+
.def( "inst" ,
|
161
|
+
py::overload_cast<const std::string&,const std::string &>
|
162
|
+
(&lunapi_t::inst,py::const_),
|
163
|
+
"Generate an lunapi-instance with attached EDF" )
|
164
|
+
|
165
|
+
.def( "inst" ,
|
166
|
+
py::overload_cast<const std::string&,const std::string &,const std::string&>
|
167
|
+
(&lunapi_t::inst,py::const_),
|
168
|
+
"Generate an lunapi-instance with attached EDF & annotation" )
|
169
|
+
|
170
|
+
.def( "inst" ,
|
171
|
+
py::overload_cast<const std::string&,const std::string &,const std::set<std::string>&>
|
172
|
+
(&lunapi_t::inst,py::const_),
|
173
|
+
"Generate an lunapi-instance with attached EDF & annotations" )
|
174
|
+
|
175
|
+
.def( "get_n" , &lunapi_t::get_n)
|
176
|
+
.def( "get_id" , &lunapi_t::get_id)
|
177
|
+
.def( "get_edf" , &lunapi_t::get_edf)
|
178
|
+
.def( "get_annot" , &lunapi_t::get_annot)
|
179
|
+
|
180
|
+
.def( "import_db" ,
|
181
|
+
py::overload_cast<const std::string &>(&lunapi_t::import_db) )
|
182
|
+
.def( "import_db_subset" ,
|
183
|
+
py::overload_cast<const std::string &,const std::set<std::string> &>(&lunapi_t::import_db) )
|
184
|
+
|
185
|
+
.def("desc",&lunapi_t::desc,
|
186
|
+
"Table of basic descripives for all individuals" )
|
187
|
+
.def("eval",&lunapi_t::eval,
|
188
|
+
"Evaluate a Luna command sequence given an attached EDF" )
|
189
|
+
|
190
|
+
.def("commands",&lunapi_t::commands,
|
191
|
+
"List commands resulting from a prior eval()" )
|
192
|
+
|
193
|
+
.def("strata",&lunapi_t::strata,
|
194
|
+
"List command/strata tuples resulting from a prior eval()" )
|
195
|
+
|
196
|
+
.def("vars",&lunapi_t::variables,
|
197
|
+
"List variables (columns) from a table (defined by a command/strat pair) from a prior eval()")
|
198
|
+
|
199
|
+
.def("table",py::overload_cast<const std::string &,const std::string &>(&lunapi_t::results,py::const_) ,
|
200
|
+
"Return a result table (defined by a command/strata pair) from a prior eval()" )
|
201
|
+
|
202
|
+
.def("tables",py::overload_cast<>(&lunapi_t::results,py::const_) ,
|
203
|
+
"Return a result table (defined by a command/strata pair) from a prior eval()" );
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
|
208
|
+
//
|
209
|
+
// lunapi_inst_t : individual instance (EDF/annotation pair)
|
210
|
+
//
|
211
|
+
|
212
|
+
py::class_<lunapi_inst_t, std::shared_ptr<lunapi_inst_t> >(m, "inst")
|
213
|
+
|
214
|
+
// .def(py::init<const std::string &>(),
|
215
|
+
// py::arg( "id" ) = "id1" )
|
216
|
+
|
217
|
+
.def( "attach_edf", &lunapi_inst_t::attach_edf,
|
218
|
+
"Attach an EDF" ,
|
219
|
+
"edffile"_a )
|
220
|
+
.def( "attach_annot",&lunapi_inst_t::attach_annot,
|
221
|
+
"Attach an annotation file to the current EDF" ,
|
222
|
+
"annotfile"_a )
|
223
|
+
|
224
|
+
|
225
|
+
.def( "refresh", &lunapi_inst_t::refresh,
|
226
|
+
"Reattach the current EDF")
|
227
|
+
.def( "drop", &lunapi_inst_t::drop,
|
228
|
+
"Drop the current EDF" )
|
229
|
+
|
230
|
+
.def( "desc" , &lunapi_inst_t::desc,
|
231
|
+
"Return basic descriptive information" )
|
232
|
+
.def( "channels", &lunapi_inst_t::channels,
|
233
|
+
"Return a list of channel labels" )
|
234
|
+
.def( "chs", &lunapi_inst_t::channels,
|
235
|
+
"Return a list of channel labels" )
|
236
|
+
.def( "has_channels", &lunapi_inst_t::has_channels,
|
237
|
+
"Return boolean for whether channels exist (with aliasing)" )
|
238
|
+
.def( "has", &lunapi_inst_t::has_channels,
|
239
|
+
"Return boolean for whether channels exist (with aliasing)" )
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
.def( "annots", &lunapi_inst_t::annots,
|
244
|
+
"Return a list of all annotations class labels" )
|
245
|
+
.def( "fetch_annots", &lunapi_inst_t::fetch_annots,
|
246
|
+
"Return a list of intervals for selected annotations" )
|
247
|
+
.def( "fetch_full_annots", &lunapi_inst_t::fetch_full_annots,
|
248
|
+
"Return a list of intervals and meta-data for selected annotations" )
|
249
|
+
|
250
|
+
.def( "has_annots" , &lunapi_inst_t::has_annots,
|
251
|
+
"Return boolean for whether annotations exist (with aliasing)" )
|
252
|
+
|
253
|
+
.def( "has_staging" , &lunapi_inst_t::has_staging,
|
254
|
+
"Return boolean for whether valid staging annotations exist" )
|
255
|
+
|
256
|
+
.def( "stat" , &lunapi_inst_t::status,
|
257
|
+
"Return a dict of key details on the current EDF" )
|
258
|
+
|
259
|
+
.def( "e2i" , &lunapi_inst_t::epochs2intervals ,
|
260
|
+
"Convert epoch numbers to interval tuples" ,
|
261
|
+
"e"_a )
|
262
|
+
.def( "s2i" , &lunapi_inst_t::seconds2intervals ,
|
263
|
+
"Convert second (start/stop tuples) to interval tuples" ,
|
264
|
+
"s"_a )
|
265
|
+
|
266
|
+
.def( "data",&lunapi_inst_t::data,
|
267
|
+
"Return an array of one or more channels for all records" ,
|
268
|
+
"chs"_a , "annots"_a , "time"_a = false )
|
269
|
+
.def( "slice",&lunapi_inst_t::slice,
|
270
|
+
"Return a data matrix/column header tuple" ,
|
271
|
+
"i"_a , "chs"_a , "annots"_a , "time"_a = false )
|
272
|
+
.def( "slices",&lunapi_inst_t::slices,
|
273
|
+
"Return a list of data matrices (one per epoch/interval)" ,
|
274
|
+
"i"_a , "chs"_a , "annots"_a , "time"_a = false )
|
275
|
+
|
276
|
+
.def( "insert_signal" , &lunapi_inst_t::insert_signal,
|
277
|
+
"Insert a signal" ,
|
278
|
+
"label"_a , "data"_a , "sr"_a )
|
279
|
+
.def( "update_signal" , &lunapi_inst_t::update_signal,
|
280
|
+
"Update a signal" , "label"_a , "data"_a )
|
281
|
+
.def( "insert_annot" , &lunapi_inst_t::insert_annotation,
|
282
|
+
"Insert an annotation" ,
|
283
|
+
"label"_a , "intervals"_a , "durcol2"_a = false )
|
284
|
+
|
285
|
+
.def("ivar",py::overload_cast<const std::string &,const std::string &>(&lunapi_inst_t::ivar),
|
286
|
+
"Set an individual-variable")
|
287
|
+
.def("get_ivar",py::overload_cast<const std::string &>(&lunapi_inst_t::ivar,py::const_),
|
288
|
+
"Return an individual-variable")
|
289
|
+
.def("ivars", &lunapi_inst_t::ivars,
|
290
|
+
"Return all individual-variables")
|
291
|
+
.def("clear_ivar",&lunapi_inst_t::clear_ivar,
|
292
|
+
"Clear individual-variables")
|
293
|
+
.def("clear_selected_ivar",&lunapi_inst_t::clear_selected_ivar,
|
294
|
+
"Clear selected individual-variables")
|
295
|
+
|
296
|
+
|
297
|
+
.def("eval",&lunapi_inst_t::eval,
|
298
|
+
"Evaluate Luna commands" )
|
299
|
+
|
300
|
+
.def("proc",&lunapi_inst_t::eval_return_data,
|
301
|
+
"Similar to eval(), but returns all data tables" )
|
302
|
+
|
303
|
+
.def("commands",&lunapi_inst_t::commands,
|
304
|
+
"List commands resulting from a prior eval()" )
|
305
|
+
.def("strata",&lunapi_inst_t::strata,
|
306
|
+
"List command/strata tuples resulting from a prior eval()" )
|
307
|
+
.def("vars",&lunapi_inst_t::variables,
|
308
|
+
"List variables (columns) from a table (defined by a command/strat pair) from a prior eval()")
|
309
|
+
.def("table",py::overload_cast<const std::string &,const std::string &>(&lunapi_inst_t::results,py::const_) ,
|
310
|
+
"Return a result table (defined by a command/strata pair) from a prior eval()" )
|
311
|
+
.def("tables",py::overload_cast<>(&lunapi_inst_t::results,py::const_) ,
|
312
|
+
"Return a result table (defined by a command/strata pair) from a prior eval()" )
|
313
|
+
|
314
|
+
.def( "get_id", [](const lunapi_inst_t & a) { return a.get_id(); } )
|
315
|
+
|
316
|
+
.def("__repr__",
|
317
|
+
[](const lunapi_inst_t & a)
|
318
|
+
{
|
319
|
+
std::string s = "<lunapi-instance id:" + a.get_id();
|
320
|
+
const std::string f1 = a.get_edf_file();
|
321
|
+
const std::string f2 = a.get_annot_files();
|
322
|
+
if ( f1 != "" ) s += " edf:" + f1;
|
323
|
+
if ( f2 != "" ) s += " annot:" + f2;
|
324
|
+
s += ">";
|
325
|
+
return s;
|
326
|
+
}
|
327
|
+
);
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
//
|
332
|
+
// segsrv_t : segment-server instance (linked to a single lunapi_inst_t)
|
333
|
+
//
|
334
|
+
|
335
|
+
py::class_<segsrv_t>(m, "segsrv")
|
336
|
+
.def(py::init<lunapi_inst_ptr>())
|
337
|
+
.def( "populate", &segsrv_t::populate,
|
338
|
+
"Initiate segment-server channels, annots" ,
|
339
|
+
"chs"_a , "anns"_a )
|
340
|
+
.def( "set_window", &segsrv_t::set_window,
|
341
|
+
"Define current window" ,
|
342
|
+
"start"_a , "stop"_a )
|
343
|
+
.def( "get_signal", &segsrv_t::get_signal )
|
344
|
+
.def( "get_timetrack", &segsrv_t::get_timetrack )
|
345
|
+
.def( "get_time_scale", &segsrv_t::get_time_scale )
|
346
|
+
.def( "set_scaling", &segsrv_t::set_scaling )
|
347
|
+
.def( "fix_physical_scale", &segsrv_t::fix_physical_scale )
|
348
|
+
.def( "empirical_physical_scale", &segsrv_t::empirical_physical_scale )
|
349
|
+
.def( "free_physical_scale", &segsrv_t::free_physical_scale )
|
350
|
+
.def( "get_scaled_signal", &segsrv_t::get_scaled_signal )
|
351
|
+
.def( "get_gaps" , &segsrv_t::get_gaps )
|
352
|
+
|
353
|
+
.def( "set_epoch_size", &segsrv_t::set_epoch_size )
|
354
|
+
.def( "calc_bands", &segsrv_t::calc_bands ) // say which channels to do this for
|
355
|
+
.def( "calc_hjorths" , &segsrv_t::calc_hjorths )
|
356
|
+
.def( "nepochs" , &segsrv_t::nepochs )
|
357
|
+
|
358
|
+
.def( "get_epoch_size" , &segsrv_t::get_epoch_size )
|
359
|
+
// .def( "get_epoch_timetrack" , &segsrv_t::get_epoch_timetrack )
|
360
|
+
.def( "get_bands", &segsrv_t::get_bands ) // actually return the final epoch x band matrix for channel ch
|
361
|
+
.def( "get_hjorths" , &segsrv_t::get_hjorths )
|
362
|
+
|
363
|
+
// .def( "get_ungapped_total_sec" , &segsrv_t::get_ungapped_total_sec )
|
364
|
+
.def( "get_total_sec" , &segsrv_t::get_total_sec )
|
365
|
+
.def( "get_total_sec_original" , &segsrv_t::get_total_sec_original )
|
366
|
+
.def( "is_window_valid" , &segsrv_t::is_window_valid )
|
367
|
+
.def( "get_window_left" , &segsrv_t::get_window_left )
|
368
|
+
.def( "get_window_right" , &segsrv_t::get_window_right )
|
369
|
+
.def( "get_window_left_hms" , &segsrv_t::get_window_left_hms )
|
370
|
+
.def( "get_window_right_hms" , &segsrv_t::get_window_right_hms )
|
371
|
+
.def( "get_clock_ticks" , &segsrv_t::get_clock_ticks )
|
372
|
+
.def( "get_window_phys_range" , &segsrv_t::get_window_phys_range )
|
373
|
+
.def( "get_ylabel" , &segsrv_t::get_ylabel )
|
374
|
+
.def( "throttle" , &segsrv_t::throttle )
|
375
|
+
.def( "input_throttle" , &segsrv_t::input_throttle )
|
376
|
+
.def( "summary_threshold_mins" , &segsrv_t::summary_threshold_mins )
|
377
|
+
.def( "serve_raw_signals", &segsrv_t::serve_raw_signals )
|
378
|
+
.def( "get_summary_stats", &segsrv_t::get_summary_stats )
|
379
|
+
.def( "get_summary_timetrack", &segsrv_t::get_summary_timetrack )
|
380
|
+
|
381
|
+
.def( "compile_evts" , &segsrv_t::compile_evts )
|
382
|
+
.def( "get_evnts_xaxes" , &segsrv_t::get_evnts_xaxes )
|
383
|
+
.def( "get_evnts_yaxes" , &segsrv_t::get_evnts_yaxes )
|
384
|
+
.def( "set_evnt_format6" , &segsrv_t::set_annot_format6 )
|
385
|
+
.def( "get_evnts_xaxes_ends" , &segsrv_t::get_evnts_xaxes_ends )
|
386
|
+
.def( "get_evnts_yaxes_ends" , &segsrv_t::get_evnts_yaxes_ends )
|
387
|
+
.def( "fetch_all_annots", &segsrv_t::fetch_all_evts )
|
388
|
+
.def( "fetch_annots" , &segsrv_t::fetch_evts );
|
389
|
+
|
390
|
+
}
|
391
|
+
|
Binary file
|