Package kenozooid :: Package cli :: Module da

Source Code for Module kenozooid.cli.da

  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  Kenozooid's plotting and data analysis command line user interface. 
 22  """ 
 23   
 24  import os.path 
 25  import logging 
 26   
 27  from kenozooid.component import inject 
 28  from kenozooid.cli import CLICommand, ArgumentError, add_master_command, \ 
 29          add_uddf_input 
 30   
 31  log = logging.getLogger('kenozooid.cli.da') 
32 33 @inject(CLICommand, name='plot') 34 -class PlotProfiles(object):
35 """ 36 Plot profiles of dives command. 37 """ 38 description = 'plot graphs of dive profiles' 39 40 @classmethod
41 - def add_arguments(self, parser):
42 """ 43 Add options for plotting profiles of dives command. 44 """ 45 parser.add_argument('--type', '-t', 46 dest='plot_type', 47 default='details', 48 choices=('details', 'cmp'), 49 help='type of plot') 50 parser.add_argument('--title', 51 action='store_true', 52 dest='plot_title', 53 default=False, 54 help='display plot title') 55 parser.add_argument('--info', 56 action='store_true', 57 dest='plot_info', 58 default=False, 59 help='display dive information (depth, time, temperature)') 60 parser.add_argument('--avg-depth', 61 action='store_true', 62 dest='plot_avg_depth', 63 default=False, 64 help='display dive average depth') 65 parser.add_argument('--mod', 66 action='store_true', 67 dest='plot_mod', 68 default=False, 69 help='plot MOD of current gas (for 1.4 and 1.6 ppO2)') 70 parser.add_argument('--temp', 71 action='store_true', 72 dest='plot_temp', 73 default=False, 74 help='plot temperature graph') 75 parser.add_argument('--no-sig', 76 action='store_false', 77 dest='plot_sig', 78 default=True, 79 help='do not display Kenozooid signature') 80 parser.add_argument('--legend', 81 action='store_true', 82 dest='plot_legend', 83 default=False, 84 help='display graph legend') 85 parser.add_argument('--labels', 86 nargs='*', 87 action='store', 88 dest='plot_labels', 89 help='override dives labels') 90 add_uddf_input(parser) 91 parser.add_argument('output', 92 help='output file: pdf, png or svg')
93 94
95 - def __call__(self, args):
96 """ 97 Execute dives' profiles plotting command. 98 """ 99 import os.path 100 import kenozooid.plot as kp 101 import kenozooid.logbook as kl 102 103 fout = args.output 104 105 _, ext = os.path.splitext(fout) 106 ext = ext.replace('.', '') 107 if ext.lower() not in ('pdf', 'png', 'svg'): 108 raise ArgumentError('Unknown format of plotting output file: {0}' \ 109 .format(ext)) 110 111 r, f = args.input 112 dives = kl.find_dives(f, r, args.dives) 113 114 kp.plot(dives, fout, 115 ptype=args.plot_type, 116 format=ext, 117 title=args.plot_title, 118 info=args.plot_info, 119 temp=args.plot_temp, 120 avg_depth=args.plot_avg_depth, 121 mod=args.plot_mod, 122 sig=args.plot_sig, 123 legend=args.plot_legend, 124 labels=args.plot_labels)
125
126 127 128 @inject(CLICommand, name='analyze') 129 -class Analyze(object):
130 """ 131 Analyze dives with R script. 132 """ 133 description = 'analyze dives with R script' 134 135 @classmethod
136 - def add_arguments(self, parser):
137 """ 138 Add R script runner options. 139 """ 140 parser.add_argument('script', help='R script to execute') 141 parser.add_argument('-a', 142 nargs='*', 143 dest='args', 144 help='R script arguments') 145 add_uddf_input(parser)
146 147
148 - def __call__(self, args):
149 """ 150 Execute dives' analyze command. 151 """ 152 from kenozooid.analyze import analyze 153 import kenozooid.logbook as kl 154 155 r, f = args.input 156 dives = kl.find_dives(f, r, args.dives) 157 analyze(args.script, args.args, dives)
158 159 160 # vim: sw=4:et:ai 161