##// END OF EJS Templates
multiprocess added to cli
José Chávez -
r935:507f9315e6a4
parent child
Show More
@@ -0,0 +1,1
1 <Project description="A schain project" id="191" name="project"><ReadUnit datatype="VoltageReader" 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/schain-cli" /><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="online" value="0" /><Parameter format="int" id="191119" name="walk" value="1" /></Operation></ReadUnit><ProcUnit datatype="SpectraProc" id="1912" inputId="1911" name="SpectraProc"><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="other"><Parameter format="int" id="191231" name="id" value="101" /><Parameter format="str" id="191232" name="wintitle" value="Jicamarca Radio Observatory" /><Parameter format="int" id="191233" name="showprofile" value="0" /><Parameter format="int" id="191234" name="xmin" value="0" /><Parameter format="int" id="191235" name="xmax" value="24" /><Parameter format="str" id="191236" name="figpath" value="/home/nanosat/schain/schain-cli/figs" /><Parameter format="int" id="191237" name="wr_period" value="5" /><Parameter format="int" id="191238" name="exp_code" value="22" /></Operation></ProcUnit></Project> No newline at end of file
@@ -1,43 +1,61
1 1 import click
2 2 import schainpy
3 import subprocess
4 from multiprocessing import cpu_count
3 5 from schaincli import templates
4 6 import os, sys
5 7
6 8 def print_version(ctx, param, value):
7 9 if not value or ctx.resilient_parsing:
8 10 return
9 11 click.echo(schainpy.__version__)
10 12 ctx.exit()
11 13
12 14
13 15 @click.command()
14 16 @click.option('--version', '-v', is_flag=True, callback=print_version, help='SChain version', type=str)
17 @click.option('--xml', '-x', default=None, help='xml file', type=click.Path(exists=True, resolve_path=True))
15 18 @click.argument('command', default='run', required=True)
16 def main(command, version):
19 def main(command, version, xml):
17 20 """COMMAND LINE INTERFACE FOR SIGNAL CHAIN - JICAMARCA RADIO OBSERVATORY"""
18 if command == 'generate':
21 if xml is not None:
22 subprocess.call(['schain --file=' + xml], shell=True)
23 elif command == 'generate':
19 24 generate()
20 pass
21 elif command == 'run':
22 pass
23 25 elif command == 'test':
24 26 test()
25 pass
26 27 else:
27 click.echo('[ERROR] - Command not defined.')
28 click.echo('\x1b[0;37;41m[ERROR] - Command is not defined.\x1b[0m')
28 29
29 def generate():
30 def basicInputs():
30 31 inputs = {}
31 32 inputs['desc'] = click.prompt('Enter a description', default="A schain project", type=str)
32 33 inputs['name'] = click.prompt('Name of the project', default="project", type=str)
33 34 inputs['path'] = click.prompt('Data path', default=os.getcwd(), type=click.Path(exists=True, resolve_path=True))
34 inputs['startDate'] = click.prompt('Start date', default='01/01/1970', type=str)
35 inputs['endDate'] = click.prompt('End date', default='31/12/2017', type=str)
35 inputs['startDate'] = click.prompt('Start date', default='1970/01/01', type=str)
36 inputs['endDate'] = click.prompt('End date', default='2017/12/31', type=str)
36 37 inputs['startHour'] = click.prompt('Start hour', default='00:00:00', type=str)
37 38 inputs['endHour'] = click.prompt('End hour', default='23:59:59', type=str)
38 script = open(inputs['name'] + ".py", 'w')
39 script.write(templates.basic.format(**inputs))
39 inputs['figpath'] = inputs['path'] + '/figs'
40 return inputs
41
42 def generate():
43 inputs = basicInputs()
44 inputs['multiprocess'] = click.confirm('Is this a multiprocess script?')
45 if inputs['multiprocess']:
46 inputs['nProcess'] = click.prompt('How many process?', default=cpu_count(), type=int)
47 current = templates.multiprocess.format(**inputs)
48 else:
49 current = templates.basic.format(**inputs)
50 scriptname = inputs['name'] + ".py"
51 script = open(scriptname, 'w')
52 try:
53 script.write(current)
54 click.echo('\x1b[0;37;42m[SUCCESS] Script {file} generated\x1b[0m'.format(file=scriptname))
55 except Exception as e:
56 click.echo('\x1b[0;37;41m[ERROR] I cannot create the file. Do you have writing permissions?\x1b[0m')
57
40 58
41 59 def test():
42 60 print templates.basic.format(name='hola', desc= 'desc', path='path', startDate='0', endDate='0')
43 61 click.echo('testing')
@@ -1,21 +1,75
1 basic =
2 '''import argparse
3 from schainpy.controller import Project, multiSchain
1 basic = '''from schainpy.controller import Project
4 2
5 3 desc = "{desc}"
6 4
7 5 controller = Project()
8 6 controller.setup(id='191', name="{name}", description=desc)
9 7
10 readUnitConf = controller.addReadUnit(datatype='SpectraReader',
11 path="{path}",
12 startDate="{startDate}",
13 endDate="{endDate}",
14 startTime="{startHour}",
15 endTime="{endHour}",
16 online=0,
17 walk=1,
18 )
19
20 procUnitConf2 = controllerObj.addProcUnit(datatype='Spectra', inputId=readUnitConfObj.getId())
8 readUnitConf = controller.addReadUnit(datatype='VoltageReader',
9 path="{path}",
10 startDate="{startDate}",
11 endDate="{endDate}",
12 startTime="{startHour}",
13 endTime="{endHour}",
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="{figpath}", 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()
35 '''
36
37 multiprocess = '''from schainpy.controller import Project, multiSchain
38
39 desc = "{desc}"
40
41 def fiber(cursor, skip, q, day):
42 controller = Project()
43 controller.setup(id='191', name="{name}", description=desc)
44
45 readUnitConf = controller.addReadUnit(datatype='SpectraReader',
46 path="{path}",
47 startDate="day",
48 endDate="day",
49 startTime="{startHour}",
50 endTime="{endHour}",
51 online=0,
52 queue=q,
53 cursor=cursor,
54 skip=skip,
55 verbose=1,
56 walk=1,
57 )
58
59 procUnitConf1 = controller.addProcUnit(datatype='Spectra', inputId=readUnitConf.getId())
60
61 procUnitConf2 = controller.addProcUnit(datatype='ParametersProc', inputId=readUnitConf.getId())
62 opObj11 = procUnitConf2.addOperation(name='SpectralMoments', optype='other')
63
64 opObj12 = procUnitConf2.addOperation(name='PublishData', optype='other')
65 opObj12.addParameter(name='zeromq', value=1, format='int')
66 opObj12.addParameter(name='verbose', value=0, format='bool')
67
68 controller.start()
69
70
71 if __name__ == '__main__':
72 multiSchain(fiber, nProcess={nProcess}, startDate="{startDate}", endDate="{endDate}")
73
74
21 75 '''
@@ -1,1 +1,1
1 <Project description="HF_EXAMPLE" id="191" name="test01"><ReadUnit datatype="SpectraReader" id="1911" inputId="0" name="SpectraReader"><Operation id="19111" name="run" priority="1" type="self"><Parameter format="str" id="191111" name="datatype" value="SpectraReader" /><Parameter format="str" id="191112" name="path" value="/home/nanosat/data/sp1_f0" /><Parameter format="date" id="191113" name="startDate" value="2017/01/28" /><Parameter format="date" id="191114" name="endDate" value="2017/01/28" /><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="cursor" value="5" /><Parameter format="int" id="191119" name="skip" value="177" /><Parameter format="int" id="191120" name="walk" value="1" /><Parameter format="int" id="191121" name="verbose" value="1" /><Parameter format="int" id="191122" name="online" value="0" /></Operation></ReadUnit><ProcUnit datatype="ParametersProc" id="1913" inputId="1911" name="ParametersProc"><Operation id="19131" name="run" priority="1" type="self" /><Operation id="19132" name="SpectralMoments" priority="2" type="other" /><Operation id="19133" name="PublishData" priority="3" type="other"><Parameter format="int" id="191331" name="zeromq" value="1" /><Parameter format="bool" id="191332" name="verbose" value="0" /><Parameter format="int" id="191333" name="delay" value="0" /></Operation></ProcUnit><ProcUnit datatype="Spectra" id="1912" inputId="1911" name="SpectraProc"><Operation id="19121" name="run" priority="1" type="self" /></ProcUnit></Project> No newline at end of file
1 <Project description="HF_EXAMPLE" id="191" name="test01"><ReadUnit datatype="Spectra" id="1911" inputId="0" name="SpectraReader"><Operation id="19111" name="run" priority="1" type="self"><Parameter format="str" id="191111" name="datatype" value="SpectraReader" /><Parameter format="str" id="191112" name="path" value="/home/nanosat/data/sp1_f0" /><Parameter format="date" id="191113" name="startDate" value="2017/01/28" /><Parameter format="date" id="191114" name="endDate" value="2017/01/28" /><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="cursor" value="5" /><Parameter format="int" id="191119" name="skip" value="177" /><Parameter format="int" id="191120" name="walk" value="1" /><Parameter format="int" id="191121" name="verbose" value="1" /><Parameter format="int" id="191122" name="online" value="0" /></Operation></ReadUnit><ProcUnit datatype="Parameters" id="1913" inputId="1911" name="ParametersProc"><Operation id="19131" name="run" priority="1" type="self" /><Operation id="19132" name="SpectralMoments" priority="2" type="other" /><Operation id="19133" name="PublishData" priority="3" type="other"><Parameter format="int" id="191331" name="zeromq" value="1" /><Parameter format="bool" id="191332" name="verbose" value="0" /><Parameter format="int" id="191333" name="delay" value="0" /></Operation></ProcUnit><ProcUnit datatype="Spectra" id="1912" inputId="1911" name="SpectraProc"><Operation id="19121" name="run" priority="1" type="self" /></ProcUnit></Project> No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now