##// END OF EJS Templates
1.0
José Chávez -
r944:0efe9dc73bde
parent child
Show More
@@ -0,0 +1,34
1 from schainpy.controller import Project
2
3 desc = "A schain project"
4
5 controller = Project()
6 controller.setup(id='191', name="project", description=desc)
7
8 readUnitConf = controller.addReadUnit(datatype='VoltageReader',
9 path="/home/nanosat/schain",
10 startDate="1970/01/01",
11 endDate="2017/12/31",
12 startTime="00:00:00",
13 endTime="23:59:59",
14 online=0,
15 verbose=1,
16 walk=1,
17 )
18
19 procUnitConf1 = controller.addProcUnit(datatype='VoltageProc', inputId=readUnitConf.getId())
20
21 opObj11 = procUnitConf1.addOperation(name='ProfileSelector', optype='other')
22 opObj11.addParameter(name='profileRangeList', value='120,183', format='intlist')
23
24 opObj11 = procUnitConf1.addOperation(name='RTIPlot', optype='other')
25 opObj11.addParameter(name='wintitle', value='Jicamarca Radio Observatory', format='str')
26 opObj11.addParameter(name='showprofile', value='0', format='int')
27 opObj11.addParameter(name='xmin', value='0', format='int')
28 opObj11.addParameter(name='xmax', value='24', format='int')
29 opObj11.addParameter(name='figpath', value="/home/nanosat/schain/figs", format='str')
30 opObj11.addParameter(name='wr_period', value='5', format='int')
31 opObj11.addParameter(name='exp_code', value='22', format='int')
32
33
34 controller.start()
@@ -0,0 +1,1
1 <Project description="A schain project" id="191" name="project"><ReadUnit datatype="Voltage" id="1911" inputId="0" name="VoltageReader"><Operation id="19111" name="run" priority="1" type="self"><Parameter format="str" id="191111" name="datatype" value="VoltageReader" /><Parameter format="str" id="191112" name="path" value="/home/nanosat/schain" /><Parameter format="date" id="191113" name="startDate" value="1970/01/01" /><Parameter format="date" id="191114" name="endDate" value="2017/12/31" /><Parameter format="time" id="191115" name="startTime" value="00:00:00" /><Parameter format="time" id="191116" name="endTime" value="23:59:59" /><Parameter format="int" id="191118" name="walk" value="1" /><Parameter format="int" id="191119" name="verbose" value="1" /><Parameter format="int" id="191120" name="online" value="0" /></Operation></ReadUnit><ProcUnit datatype="Voltage" id="1912" inputId="1911" name="VoltageProc"><Operation id="19121" name="run" priority="1" type="self" /><Operation id="19122" name="ProfileSelector" priority="2" type="other"><Parameter format="intlist" id="191221" name="profileRangeList" value="120,183" /></Operation><Operation id="19123" name="RTIPlot" priority="3" type="plotter"><Parameter format="str" id="191231" name="wintitle" value="Jicamarca Radio Observatory" /><Parameter format="int" id="191232" name="showprofile" value="0" /><Parameter format="int" id="191233" name="xmin" value="0" /><Parameter format="int" id="191234" name="xmax" value="24" /><Parameter format="str" id="191235" name="figpath" value="/home/nanosat/schain/figs" /><Parameter format="int" id="191236" name="wr_period" value="5" /><Parameter format="int" id="191237" name="exp_code" value="22" /></Operation></ProcUnit></Project> No newline at end of file
@@ -0,0 +1,1
1 You should install "digital_rf_hdf5" module if you want to read USRP data
@@ -4,10 +4,18 import subprocess
4 import os
4 import os
5 import sys
5 import sys
6 import glob
6 import glob
7 save_stdout = sys.stdout
8 sys.stdout = open('trash', 'w')
7 from multiprocessing import cpu_count
9 from multiprocessing import cpu_count
8 from schaincli import templates
10 from schaincli import templates
9 from schainpy import controller_api
11 from schainpy import controller_api
12 from schainpy.model import Operation, ProcessingUnit
10 from schainpy.utils import log
13 from schainpy.utils import log
14 from importlib import import_module
15 from pydoc import locate
16 from fuzzywuzzy import process
17 sys.stdout = save_stdout
18
11
19
12 def print_version(ctx, param, value):
20 def print_version(ctx, param, value):
13 if not value or ctx.resilient_parsing:
21 if not value or ctx.resilient_parsing:
@@ -15,13 +23,16 def print_version(ctx, param, value):
15 click.echo(schainpy.__version__)
23 click.echo(schainpy.__version__)
16 ctx.exit()
24 ctx.exit()
17
25
26
18 cliLogger = log.makelogger('schain cli')
27 cliLogger = log.makelogger('schain cli')
28 PREFIX = 'experiment'
29
19
30
20 @click.command()
31 @click.command()
21 @click.option('--version', '-v', is_flag=True, callback=print_version, help='SChain version', type=str)
32 @click.option('--version', '-v', is_flag=True, callback=print_version, help='SChain version', type=str)
22 @click.option('--xml', '-x', default=None, help='run an XML file', type=click.Path(exists=True, resolve_path=True))
33 @click.option('--xml', '-x', default=None, help='run an XML file', type=click.Path(exists=True, resolve_path=True))
23 @click.argument('command', default='run', required=True)
34 @click.argument('command', default='run', required=True)
24 @click.argument('nextcommand', default=None, required=False, type=click.Path(exists=True, resolve_path=True))
35 @click.argument('nextcommand', default=None, required=False, type=str)
25 def main(command, nextcommand, version, xml):
36 def main(command, nextcommand, version, xml):
26 """COMMAND LINE INTERFACE FOR SIGNAL CHAIN - JICAMARCA RADIO OBSERVATORY"""
37 """COMMAND LINE INTERFACE FOR SIGNAL CHAIN - JICAMARCA RADIO OBSERVATORY"""
27 if xml is not None:
38 if xml is not None:
@@ -31,20 +42,90 def main(command, nextcommand, version, xml):
31 elif command == 'test':
42 elif command == 'test':
32 test()
43 test()
33 elif command == 'run':
44 elif command == 'run':
34 if nextcommand is None:
45 runschain(nextcommand)
35 currentfiles = glob.glob('./*.py')
46 elif command == 'search':
36 numberfiles = len(currentfiles)
47 search(nextcommand)
37 print currentfiles
48 else:
38 if numberfiles > 1:
49 log.error('Command {} is not defined'.format(command))
39 log.error('There is more than one file to run')
50
40 elif numberfiles == 1:
51 def check_module(possible, instance):
41 subprocess.call(['python ' + currentfiles[0]], shell=True)
52 def check(x):
42 else:
53 try:
43 log.error('There is no file to run.')
54 instancia = locate('schainpy.model.{}'.format(x))
55 return isinstance(instancia(), instance)
56 except Exception as e:
57 return False
58 clean = clean_modules(possible)
59 return [x for x in clean if check(x)]
60
61
62 def clean_modules(module):
63 noEndsUnder = [x for x in module if not x.endswith('__')]
64 noStartUnder = [x for x in noEndsUnder if not x.startswith('__')]
65 noFullUpper = [x for x in noStartUnder if not x.isupper()]
66 return noFullUpper
67
68
69 def search(nextcommand):
70
71 if nextcommand is None:
72 log.error('There is no Operation/ProcessingUnit to search')
73 elif nextcommand == 'procs':
74 module = dir(import_module('schainpy.model'))
75 procs = check_module(module, ProcessingUnit)
76 try:
77 procs.remove('ProcessingUnit')
78 except Exception as e:
79 pass
80 log.success('Current ProcessingUnits are:\n\033[1m{}\033[0m'.format('\n'.join(procs)))
81
82 elif nextcommand == 'operations':
83 module = dir(import_module('schainpy.model'))
84 noProcs = [x for x in module if not x.endswith('Proc')]
85 operations = check_module(noProcs, Operation)
86 try:
87 operations.remove('Operation')
88 except Exception as e:
89 pass
90 log.success('Current Operations are:\n\033[1m{}\033[0m'.format('\n'.join(operations)))
91 else:
92 try:
93 module = locate('schainpy.model.{}'.format(nextcommand))
94 log.warning('Use this feature with caution. It may not return all the allowed arguments')
95 args = module().getAllowedArgs()
96 try:
97 args.remove('self')
98 except Exception as e:
99 pass
100 try:
101 args.remove('dataOut')
102 except Exception as e:
103 pass
104 log.success('Showing arguments of {} are:\n\033[1m{}\033[0m'.format(nextcommand, '\n'.join(args)))
105 except Exception as e:
106 log.error('Module {} does not exists'.format(nextcommand))
107 allModules = dir(import_module('schainpy.model'))
108 module = check_module(allModules, Operation)
109 module.extend(check_module(allModules, ProcessingUnit))
110 similar = process.extractOne(nextcommand, module)[0]
111 search(similar)
112
113
114 def runschain(nextcommand):
115 if nextcommand is None:
116 currentfiles = glob.glob('./{}_*.py'.format(PREFIX))
117 numberfiles = len(currentfiles)
118 if numberfiles > 1:
119 log.error('There is more than one file to run')
120 elif numberfiles == 1:
121 subprocess.call(['python ' + currentfiles[0]], shell=True)
44 else:
122 else:
45 subprocess.call(['python ' + nextcommand], shell=True)
123 log.error('There is no file to run')
46 else:
124 else:
47 log.error('Command is not defined.')
125 try:
126 subprocess.call(['python ' + nextcommand], shell=True)
127 except Exception as e:
128 log.error("I cannot run the file. Does it exists?")
48
129
49
130
50 def basicInputs():
131 def basicInputs():
@@ -68,11 +149,11 def generate():
68 current = templates.multiprocess.format(**inputs)
149 current = templates.multiprocess.format(**inputs)
69 else:
150 else:
70 current = templates.basic.format(**inputs)
151 current = templates.basic.format(**inputs)
71 scriptname = inputs['name'] + ".py"
152 scriptname = '{}_{}.py'.format(PREFIX, inputs['name'])
72 script = open(scriptname, 'w')
153 script = open(scriptname, 'w')
73 try:
154 try:
74 script.write(current)
155 script.write(current)
75 log.success('Script {file} generated'.format(file=scriptname))
156 log.success('Script {} generated'.format(scriptname))
76 except Exception as e:
157 except Exception as e:
77 log.error('I cannot create the file. Do you have writing permissions?')
158 log.error('I cannot create the file. Do you have writing permissions?')
78
159
@@ -91,7 +172,7 def runFromXML(filename):
91 controller.start()
172 controller.start()
92 plotterObj.start()
173 plotterObj.start()
93
174
94 cliLogger("Finishing all processes ...")
175 cliLogger("Finishing all processes")
95
176
96 controller.join(5)
177 controller.join(5)
97
178
@@ -5,175 +5,175 from schainpy.controller import Project
5 from schainpy.model.graphics.jroplotter import PlotManager
5 from schainpy.model.graphics.jroplotter import PlotManager
6
6
7 class ControllerThread(threading.Thread, Project):
7 class ControllerThread(threading.Thread, Project):
8
8
9 def __init__(self, plotter_queue=None):
9 def __init__(self, plotter_queue=None):
10
10
11 threading.Thread.__init__(self)
11 threading.Thread.__init__(self)
12 Project.__init__(self, plotter_queue)
12 Project.__init__(self, plotter_queue)
13
13
14 self.setDaemon(True)
14 self.setDaemon(True)
15
15
16 self.lock = threading.Lock()
16 self.lock = threading.Lock()
17 self.control = {'stop':False, 'pause':False}
17 self.control = {'stop':False, 'pause':False}
18
18
19 def __del__(self):
19 def __del__(self):
20
20
21 self.control['stop'] = True
21 self.control['stop'] = True
22
22
23 def stop(self):
23 def stop(self):
24
24
25 self.lock.acquire()
25 self.lock.acquire()
26
26
27 self.control['stop'] = True
27 self.control['stop'] = True
28
28
29 self.lock.release()
29 self.lock.release()
30
30
31 def pause(self):
31 def pause(self):
32
32
33 self.lock.acquire()
33 self.lock.acquire()
34
34
35 self.control['pause'] = not(self.control['pause'])
35 self.control['pause'] = not(self.control['pause'])
36 paused = self.control['pause']
36 paused = self.control['pause']
37
37
38 self.lock.release()
38 self.lock.release()
39
39
40 return paused
40 return paused
41
41
42 def isPaused(self):
42 def isPaused(self):
43
43
44 self.lock.acquire()
44 self.lock.acquire()
45 paused = self.control['pause']
45 paused = self.control['pause']
46 self.lock.release()
46 self.lock.release()
47
47
48 return paused
48 return paused
49
49
50 def isStopped(self):
50 def isStopped(self):
51
51
52 self.lock.acquire()
52 self.lock.acquire()
53 stopped = self.control['stop']
53 stopped = self.control['stop']
54 self.lock.release()
54 self.lock.release()
55
55
56 return stopped
56 return stopped
57
57
58 def run(self):
58 def run(self):
59 self.control['stop'] = False
59 self.control['stop'] = False
60 self.control['pause'] = False
60 self.control['pause'] = False
61
61
62 self.writeXml()
62 self.writeXml()
63
63
64 self.createObjects()
64 self.createObjects()
65 self.connectObjects()
65 self.connectObjects()
66 Project.run(self)
66 Project.run(self)
67
67
68 def isRunning(self):
68 def isRunning(self):
69
69
70 return self.is_alive()
70 return self.is_alive()
71
71
72 def isFinished(self):
72 def isFinished(self):
73
73
74 return not self.is_alive()
74 return not self.is_alive()
75
75
76 def setPlotters(self):
76 def setPlotters(self):
77
77
78 plotterList = PlotManager.plotterList
78 plotterList = PlotManager.plotterList
79
79
80 for thisPUConfObj in self.procUnitConfObjDict.values():
80 for thisPUConfObj in self.procUnitConfObjDict.values():
81
81
82 inputId = thisPUConfObj.getInputId()
82 inputId = thisPUConfObj.getInputId()
83
83
84 if int(inputId) == 0:
84 if int(inputId) == 0:
85 continue
85 continue
86
86
87 for thisOpObj in thisPUConfObj.getOperationObjList():
87 for thisOpObj in thisPUConfObj.getOperationObjList():
88
88
89 if thisOpObj.type == "self":
89 if thisOpObj.type == "self":
90 continue
90 continue
91
91
92 if thisOpObj.name in plotterList:
92 if thisOpObj.name in plotterList:
93 thisOpObj.type = "plotter"
93 thisOpObj.type = "plotter"
94
94
95 def setPlotterQueue(self, plotter_queue):
95 def setPlotterQueue(self, plotter_queue):
96
96
97 self.plotterQueue = plotter_queue
97 self.plotterQueue = plotter_queue
98
98
99 def getPlotterQueue(self):
99 def getPlotterQueue(self):
100
100
101 return self.plotterQueue
101 return self.plotterQueue
102
102
103 def useExternalPlotter(self):
103 def useExternalPlotter(self):
104
104
105 self.plotterQueue = Queue(10)
105 self.plotterQueue = Queue(10)
106 self.setPlotters()
106 self.setPlotters()
107
107
108 plotManagerObj = PlotManager(self.plotterQueue)
108 plotManagerObj = PlotManager(self.plotterQueue)
109 plotManagerObj.setController(self)
109 plotManagerObj.setController(self)
110
110
111 return plotManagerObj
111 return plotManagerObj
112
112
113 # from PyQt4 import QtCore
113 # from PyQt4 import QtCore
114 # from PyQt4.QtCore import SIGNAL
114 # from PyQt4.QtCore import SIGNAL
115 #
115 #
116 # class ControllerQThread(QtCore.QThread, Project):
116 # class ControllerQThread(QtCore.QThread, Project):
117 #
117 #
118 # def __init__(self, filename):
118 # def __init__(self, filename):
119 #
119 #
120 # QtCore.QThread.__init__(self)
120 # QtCore.QThread.__init__(self)
121 # Project.__init__(self)
121 # Project.__init__(self)
122 #
122 #
123 # self.filename = filename
123 # self.filename = filename
124 #
124 #
125 # self.lock = threading.Lock()
125 # self.lock = threading.Lock()
126 # self.control = {'stop':False, 'pause':False}
126 # self.control = {'stop':False, 'pause':False}
127 #
127 #
128 # def __del__(self):
128 # def __del__(self):
129 #
129 #
130 # self.control['stop'] = True
130 # self.control['stop'] = True
131 # self.wait()
131 # self.wait()
132 #
132 #
133 # def stop(self):
133 # def stop(self):
134 #
134 #
135 # self.lock.acquire()
135 # self.lock.acquire()
136 #
136 #
137 # self.control['stop'] = True
137 # self.control['stop'] = True
138 #
138 #
139 # self.lock.release()
139 # self.lock.release()
140 #
140 #
141 # def pause(self):
141 # def pause(self):
142 #
142 #
143 # self.lock.acquire()
143 # self.lock.acquire()
144 #
144 #
145 # self.control['pause'] = not(self.control['pause'])
145 # self.control['pause'] = not(self.control['pause'])
146 # paused = self.control['pause']
146 # paused = self.control['pause']
147 #
147 #
148 # self.lock.release()
148 # self.lock.release()
149 #
149 #
150 # return paused
150 # return paused
151 #
151 #
152 # def isPaused(self):
152 # def isPaused(self):
153 #
153 #
154 # self.lock.acquire()
154 # self.lock.acquire()
155 # paused = self.control['pause']
155 # paused = self.control['pause']
156 # self.lock.release()
156 # self.lock.release()
157 #
157 #
158 # return paused
158 # return paused
159 #
159 #
160 # def isStopped(self):
160 # def isStopped(self):
161 #
161 #
162 # self.lock.acquire()
162 # self.lock.acquire()
163 # stopped = self.control['stop']
163 # stopped = self.control['stop']
164 # self.lock.release()
164 # self.lock.release()
165 #
165 #
166 # return stopped
166 # return stopped
167 #
167 #
168 # def run(self):
168 # def run(self):
169 #
169 #
170 # self.control['stop'] = False
170 # self.control['stop'] = False
171 # self.control['pause'] = False
171 # self.control['pause'] = False
172 #
172 #
173 # self.readXml(self.filename)
173 # self.readXml(self.filename)
174 # self.createObjects()
174 # self.createObjects()
175 # self.connectObjects()
175 # self.connectObjects()
176 # self.emit( SIGNAL( "jobStarted( PyQt_PyObject )" ), 1)
176 # self.emit( SIGNAL( "jobStarted( PyQt_PyObject )" ), 1)
177 # Project.run(self)
177 # Project.run(self)
178 # self.emit( SIGNAL( "jobFinished( PyQt_PyObject )" ), 1)
178 # self.emit( SIGNAL( "jobFinished( PyQt_PyObject )" ), 1)
179 # No newline at end of file
179 #
@@ -9,6 +9,7 import glob
9 import time
9 import time
10 import numpy
10 import numpy
11 import fnmatch
11 import fnmatch
12 import inspect
12 import time, datetime
13 import time, datetime
13 #import h5py
14 #import h5py
14 import traceback
15 import traceback
@@ -536,6 +537,9 class JRODataIO:
536
537
537 return dtype_width
538 return dtype_width
538
539
540 def getAllowedArgs(self):
541 return inspect.getargspec(self.run).args
542
539 class JRODataReader(JRODataIO):
543 class JRODataReader(JRODataIO):
540
544
541
545
@@ -1432,12 +1436,52 class JRODataReader(JRODataIO):
1432 self.__printInfo = False
1436 self.__printInfo = False
1433
1437
1434
1438
1435 def run(self, **kwargs):
1439 def run(self,
1440 path=None,
1441 startDate=None,
1442 endDate=None,
1443 startTime=datetime.time(0,0,0),
1444 endTime=datetime.time(23,59,59),
1445 set=None,
1446 expLabel = "",
1447 ext = None,
1448 online = False,
1449 delay = 60,
1450 walk = True,
1451 getblock = False,
1452 nTxs = 1,
1453 realtime=False,
1454 blocksize=None,
1455 blocktime=None,
1456 queue=None,
1457 skip=None,
1458 cursor=None,
1459 warnings=True,
1460 verbose=True, **kwargs):
1436
1461
1437 if not(self.isConfig):
1462 if not(self.isConfig):
1438
1439 # self.dataOut = dataOut
1463 # self.dataOut = dataOut
1440 self.setup(**kwargs)
1464 self.setup( path=path,
1465 startDate=startDate,
1466 endDate=endDate,
1467 startTime=startTime,
1468 endTime=endTime,
1469 set=set,
1470 expLabel=expLabel,
1471 ext=ext,
1472 online=online,
1473 delay=delay,
1474 walk=walk,
1475 getblock=getblock,
1476 nTxs=nTxs,
1477 realtime=realtime,
1478 blocksize=blocksize,
1479 blocktime=blocktime,
1480 queue=queue,
1481 skip=skip,
1482 cursor=cursor,
1483 warnings=warnings,
1484 verbose=verbose)
1441 self.isConfig = True
1485 self.isConfig = True
1442
1486
1443 self.getData()
1487 self.getData()
@@ -1740,11 +1784,11 class JRODataWriter(JRODataIO):
1740
1784
1741 return 1
1785 return 1
1742
1786
1743 def run(self, dataOut, **kwargs):
1787 def run(self, dataOut, path, blocksPerFile, profilesPerBlock=64, set=None, ext=None, datatype=4, **kwargs):
1744
1788
1745 if not(self.isConfig):
1789 if not(self.isConfig):
1746
1790
1747 self.setup(dataOut, **kwargs)
1791 self.setup(dataOut, path, blocksPerFile, profilesPerBlock=profilesPerBlock, set=set, ext=ext, datatype=datatype, **kwargs)
1748 self.isConfig = True
1792 self.isConfig = True
1749
1793
1750 self.putData()
1794 self.putData()
@@ -1,5 +1,4
1 """.
1 """.
2
3 SCHAINPY - LOG
2 SCHAINPY - LOG
4 Simple helper for log standarization
3 Simple helper for log standarization
5 Usage:
4 Usage:
@@ -25,12 +24,12 def warning(message):
25
24
26
25
27 def error(message):
26 def error(message):
28 click.echo(click.style('[ERROR] - ' + message, bg='red', fg='white'))
27 click.echo(click.style('[ERROR] - ' + message, fg='red'))
29 pass
28 pass
30
29
31
30
32 def success(message):
31 def success(message):
33 click.echo(click.style('[SUCESS] - ' + message, bg='green', fg='white'))
32 click.echo(click.style(message, fg='green'))
34 pass
33 pass
35
34
36
35
@@ -51,6 +51,7 setup(name="schainpy",
51 "zmq",
51 "zmq",
52 "fuzzywuzzy",
52 "fuzzywuzzy",
53 "click",
53 "click",
54 "colorama"
54 "colorama",
55 "python-Levenshtein"
55 ],
56 ],
56 )
57 )
General Comments 0
You need to be logged in to leave comments. Login now