Package kenozooid :: Module analyze

Source Code for Module kenozooid.analyze

 1  # 
 2  # Kenozooid - dive planning and analysis toolbox. 
 3  # 
 4  # Copyright (C) 2009-2019 by Artur Wroblewski <wrobell@riseup.net> 
 5  # 
 6  # This program 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  # This program 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 this program.  If not, see <http://www.gnu.org/licenses/>. 
18  # 
19   
20  """ 
21  Dive analytics via R statistical package. 
22  """ 
23   
24  import rpy2.robjects as ro 
25  import rpy2.rinterface 
26  import logging 
27  import pkg_resources 
28  import os.path 
29   
30  import kenozooid.uddf as ku 
31  import kenozooid.rglue as kr 
32   
33  log = logging.getLogger('kenozooid.analyze') 
34  R = ro.r 
35   
36   
37 -def analyze(script, args, dives):
38 """ 39 Analyze dives with specified R script. 40 41 The dive data is converted into R data frames and script is executed in 42 the context of the converted data. 43 44 :Parameters: 45 script 46 R script to run in the context of dive data. 47 args 48 R script arguments. 49 dives 50 Dive data. 51 """ 52 if not os.path.exists(script): 53 log.debug('loading {} script as resource'.format(script)) 54 script = pkg_resources.resource_filename('kenozooid', 55 'stats/{}'.format(script)) 56 else: 57 log.debug('loading {} script as file'.format(script)) 58 59 kr.inject_dive_data(dives) 60 61 if args: 62 ro.globalenv['kz.args'] = ro.StrVector(args) 63 else: 64 R('kz.args = list()') 65 66 R('source("{}")'.format(script))
67 68 69 # vim: sw=4:et:ai 70