@@ -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= |
|
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': | |
|
45 | runschain(nextcommand) | |||
|
46 | elif command == 'search': | |||
|
47 | search(nextcommand) | |||
|
48 | else: | |||
|
49 | log.error('Command {} is not defined'.format(command)) | |||
|
50 | ||||
|
51 | def check_module(possible, instance): | |||
|
52 | def check(x): | |||
|
53 | try: | |||
|
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): | |||
34 |
|
|
115 | if nextcommand is None: | |
35 |
|
|
116 | currentfiles = glob.glob('./{}_*.py'.format(PREFIX)) | |
36 |
|
|
117 | numberfiles = len(currentfiles) | |
37 | print currentfiles |
|
|||
38 |
|
|
118 | if numberfiles > 1: | |
39 |
|
|
119 | log.error('There is more than one file to run') | |
40 |
|
|
120 | elif numberfiles == 1: | |
41 |
|
|
121 | subprocess.call(['python ' + currentfiles[0]], shell=True) | |
42 |
|
|
122 | else: | |
43 |
|
|
123 | log.error('There is no file to run') | |
44 |
|
|
124 | else: | |
|
125 | try: | |||
45 | subprocess.call(['python ' + nextcommand], shell=True) |
|
126 | subprocess.call(['python ' + nextcommand], shell=True) | |
46 | else: |
|
127 | except Exception as e: | |
47 | log.error('Command is not defined.') |
|
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'] |
|
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 { |
|
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 |
1 | NO CONTENT: modified file |
|
NO CONTENT: modified file |
@@ -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, |
|
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( |
|
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, |
|
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( |
|
32 | click.echo(click.style(message, fg='green')) | |
34 | pass |
|
33 | pass | |
35 |
|
34 | |||
36 |
|
35 |
General Comments 0
You need to be logged in to leave comments.
Login now