##// END OF EJS Templates
merge from v2.3
José Chávez -
r1057:3e3a4edbb591 merge
parent child
Show More

The requested changes are too big and content was truncated. Show full diff

1 NO CONTENT: new file 100644
NO CONTENT: new file 100644
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: new file 100644
NO CONTENT: new file 100644
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: new file 100644
NO CONTENT: new file 100644
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: new file 100644
NO CONTENT: new file 100644
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: new file 100644
NO CONTENT: new file 100644
The requested commit or file is too big and content was truncated. Show full diff
@@ -1,119 +1,132
1 # Byte-compiled / optimized / DLL files
1 # Byte-compiled / optimized / DLL files
2 __pycache__/
2 __pycache__/
3 *.py[cod]
3 *.py[cod]
4 *$py.class
4 *$py.class
5
5
6 # C extensions
6 # C extensions
7 *.so
7 *.so
8
8
9 # Distribution / packaging
9 # Distribution / packaging
10 .Python
10 .Python
11 env/
11 env/
12 build/
12 build/
13 develop-eggs/
13 develop-eggs/
14 dist/
14 dist/
15 downloads/
15 downloads/
16 eggs/
16 eggs/
17 .eggs/
17 .eggs/
18 lib/
18 lib/
19 lib64/
19 lib64/
20 parts/
20 parts/
21 sdist/
21 sdist/
22 var/
22 var/
23 wheels/
23 wheels/
24 *.egg-info/
24 *.egg-info/
25 .installed.cfg
25 .installed.cfg
26 *.egg
26 *.egg
27
27
28 # PyInstaller
28 # PyInstaller
29 # Usually these files are written by a python script from a template
29 # Usually these files are written by a python script from a template
30 # before PyInstaller builds the exe, so as to inject date/other infos into it.
30 # before PyInstaller builds the exe, so as to inject date/other infos into it.
31 *.manifest
31 *.manifest
32 *.spec
32 *.spec
33
33
34 # Installer logs
34 # Installer logs
35 pip-log.txt
35 pip-log.txt
36 pip-delete-this-directory.txt
36 pip-delete-this-directory.txt
37
37
38 # Unit test / coverage reports
38 # Unit test / coverage reports
39 htmlcov/
39 htmlcov/
40 .tox/
40 .tox/
41 .coverage
41 .coverage
42 .coverage.*
42 .coverage.*
43 .cache
43 .cache
44 nosetests.xml
44 nosetests.xml
45 coverage.xml
45 coverage.xml
46 *,cover
46 *,cover
47 .hypothesis/
47 .hypothesis/
48
48
49 # Translations
49 # Translations
50 *.mo
50 *.mo
51 *.pot
51 *.pot
52
52
53 # Django stuff:
53 # Django stuff:
54 *.log
54 *.log
55 local_settings.py
55 local_settings.py
56
56
57 # Flask stuff:
57 # Flask stuff:
58 instance/
58 instance/
59 .webassets-cache
59 .webassets-cache
60
60
61 # Scrapy stuff:
61 # Scrapy stuff:
62 .scrapy
62 .scrapy
63
63
64 # Sphinx documentation
64 # Sphinx documentation
65 docs/_build/
65 docs/_build/
66
66
67 # PyBuilder
67 # PyBuilder
68 target/
68 target/
69
69
70 # Jupyter Notebook
70 # Jupyter Notebook
71 .ipynb_checkpoints
71 .ipynb_checkpoints
72
72
73 # pyenv
73 # pyenv
74 .python-version
74 .python-version
75
75
76 # celery beat schedule file
76 # celery beat schedule file
77 celerybeat-schedule
77 celerybeat-schedule
78
78
79 # SageMath parsed files
79 # SageMath parsed files
80 *.sage.py
80 *.sage.py
81
81
82 # dotenv
82 # dotenv
83 .env
83 .env
84
84
85 # virtualenv
85 # virtualenv
86 .venv
86 .venv
87 venv/
87 venv/
88 ENV/
88 ENV/
89
89
90 # Spyder project settings
90 # Spyder project settings
91 .spyderproject
91 .spyderproject
92 .spyproject
92 .spyproject
93
93
94 # Rope project settings
94 # Rope project settings
95 .ropeproject
95 .ropeproject
96
96
97 # mkdocs documentation
97 # mkdocs documentation
98 /site
98 /site
99
99
100 # eclipse
100 # eclipse
101 .project
101 .project
102 .pydevproject
102 .pydevproject
103 <<<<<<< HEAD
103 <<<<<<< HEAD
104 <<<<<<< HEAD
105 =======
106 >>>>>>> v2.3
104
107
105 # vscode
108 # vscode
106
109
107 .vscode
110 .vscode
108
111
109 schaingui/node_modules/
112 schaingui/node_modules/
110 schainpy/scripts/
113 schainpy/scripts/
114 <<<<<<< HEAD
111 =======
115 =======
112 .svn/
116 .svn/
113 *.png
117 *.png
114 *.pyc
118 *.pyc
115 schainpy/scripts
119 schainpy/scripts
116 .vscode
120 .vscode
117 schaingui/node_modules
121 schaingui/node_modules
118 trash
122 trash
119 >>>>>>> master
123 >>>>>>> master
124 =======
125 schaingui/node_modules/
126 .svn/
127 *.png
128 *.pyc
129 *.xml
130 *.log
131 trash
132 >>>>>>> v2.3
@@ -1,188 +1,157
1 import click
1 import click
2 import schainpy
2 import schainpy
3 import subprocess
3 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
7 save_stdout = sys.stdout
8 sys.stdout = open('trash', 'w')
8 sys.stdout = open('trash', 'w')
9 from multiprocessing import cpu_count
9 from multiprocessing import cpu_count
10 from schaincli import templates
10 from schaincli import templates
11 from schainpy import controller_api
11 from schainpy.controller import Project
12 from schainpy.model import Operation, ProcessingUnit
12 from schainpy.model import Operation, ProcessingUnit
13 from schainpy.utils import log
13 from schainpy.utils import log
14 from importlib import import_module
14 from importlib import import_module
15 from pydoc import locate
15 from pydoc import locate
16 from fuzzywuzzy import process
16 from fuzzywuzzy import process
17 from schainpy.utils import paramsFinder
17 sys.stdout = save_stdout
18 sys.stdout = save_stdout
18
19
19
20
20 def print_version(ctx, param, value):
21 def print_version(ctx, param, value):
21 if not value or ctx.resilient_parsing:
22 if not value or ctx.resilient_parsing:
22 return
23 return
23 click.echo(schainpy.__version__)
24 click.echo(schainpy.__version__)
24 ctx.exit()
25 ctx.exit()
25
26
26
27
27 cliLogger = log.makelogger('schain cli')
28 cliLogger = log.makelogger('schain cli')
28 PREFIX = 'experiment'
29 PREFIX = 'experiment'
29
30
30
31
31 @click.command()
32 @click.command()
32 @click.option('--version', '-v', is_flag=True, callback=print_version, help='SChain version', type=str)
33 @click.option('--version', '-v', is_flag=True, callback=print_version, help='SChain version', type=str)
33 @click.option('--xml', '-x', default=None, help='run an XML file', type=click.Path(exists=True, resolve_path=True))
34 @click.option('--xml', '-x', default=None, help='run an XML file', type=click.Path(exists=True, resolve_path=True))
34 @click.argument('command', default='run', required=True)
35 @click.argument('command', default='run', required=True)
35 @click.argument('nextcommand', default=None, required=False, type=str)
36 @click.argument('nextcommand', default=None, required=False, type=str)
36 def main(command, nextcommand, version, xml):
37 def main(command, nextcommand, version, xml):
37 """COMMAND LINE INTERFACE FOR SIGNAL CHAIN - JICAMARCA RADIO OBSERVATORY \n
38 """COMMAND LINE INTERFACE FOR SIGNAL CHAIN - JICAMARCA RADIO OBSERVATORY \n
38 Available commands.\n
39 Available commands.\n
39 --xml: runs a schain XML generated file\n
40 --xml: runs a schain XML generated file\n
40 run: runs any python script starting 'experiment_'\n
41 run: runs any python script starting 'experiment_'\n
41 generate: generates a template schain script\n
42 generate: generates a template schain script\n
42 search: return avilable operations, procs or arguments of the give operation/proc\n"""
43 search: return avilable operations, procs or arguments of the give operation/proc\n"""
43 if xml is not None:
44 if xml is not None:
44 runFromXML(xml)
45 runFromXML(xml)
45 elif command == 'generate':
46 elif command == 'generate':
46 generate()
47 generate()
47 elif command == 'test':
48 elif command == 'test':
48 test()
49 test()
49 elif command == 'run':
50 elif command == 'run':
50 runschain(nextcommand)
51 runschain(nextcommand)
51 elif command == 'search':
52 elif command == 'search':
52 search(nextcommand)
53 search(nextcommand)
53 else:
54 else:
54 log.error('Command {} is not defined'.format(command))
55 log.error('Command {} is not defined'.format(command))
55
56
56 def check_module(possible, instance):
57 def check_module(possible, instance):
57 def check(x):
58 def check(x):
58 try:
59 try:
59 instancia = locate('schainpy.model.{}'.format(x))
60 instancia = locate('schainpy.model.{}'.format(x))
60 return isinstance(instancia(), instance)
61 return isinstance(instancia(), instance)
61 except Exception as e:
62 except Exception as e:
62 return False
63 return False
63 clean = clean_modules(possible)
64 clean = clean_modules(possible)
64 return [x for x in clean if check(x)]
65 return [x for x in clean if check(x)]
65
66
66
67
67 def clean_modules(module):
68 def clean_modules(module):
68 noEndsUnder = [x for x in module if not x.endswith('__')]
69 noEndsUnder = [x for x in module if not x.endswith('__')]
69 noStartUnder = [x for x in noEndsUnder if not x.startswith('__')]
70 noStartUnder = [x for x in noEndsUnder if not x.startswith('__')]
70 noFullUpper = [x for x in noStartUnder if not x.isupper()]
71 noFullUpper = [x for x in noStartUnder if not x.isupper()]
71 return noFullUpper
72 return noFullUpper
72
73
73
74
74 def search(nextcommand):
75 def search(nextcommand):
75 if nextcommand is None:
76 if nextcommand is None:
76 log.error('There is no Operation/ProcessingUnit to search')
77 log.error('There is no Operation/ProcessingUnit to search')
77 elif nextcommand == 'procs':
78 elif nextcommand == 'procs':
78 module = dir(import_module('schainpy.model'))
79 procs = paramsFinder.getProcs()
79 procs = check_module(module, ProcessingUnit)
80 try:
81 procs.remove('ProcessingUnit')
82 except Exception as e:
83 pass
84 log.success('Current ProcessingUnits are:\n\033[1m{}\033[0m'.format('\n'.join(procs)))
80 log.success('Current ProcessingUnits are:\n\033[1m{}\033[0m'.format('\n'.join(procs)))
85
81
86 elif nextcommand == 'operations':
82 elif nextcommand == 'operations':
87 module = dir(import_module('schainpy.model'))
83 operations = paramsFinder.getOperations()
88 noProcs = [x for x in module if not x.endswith('Proc')]
89 operations = check_module(noProcs, Operation)
90 try:
91 operations.remove('Operation')
92 except Exception as e:
93 pass
94 log.success('Current Operations are:\n\033[1m{}\033[0m'.format('\n'.join(operations)))
84 log.success('Current Operations are:\n\033[1m{}\033[0m'.format('\n'.join(operations)))
95 else:
85 else:
96 try:
86 try:
97 module = locate('schainpy.model.{}'.format(nextcommand))
87 args = paramsFinder.getArgs(nextcommand)
98 args = module().getAllowedArgs()
99 log.warning('Use this feature with caution. It may not return all the allowed arguments')
88 log.warning('Use this feature with caution. It may not return all the allowed arguments')
100 try:
101 args.remove('self')
102 except Exception as e:
103 pass
104 try:
105 args.remove('dataOut')
106 except Exception as e:
107 pass
108 if len(args) == 0:
89 if len(args) == 0:
109 log.success('{} has no arguments'.format(nextcommand))
90 log.success('{} has no arguments'.format(nextcommand))
110 else:
91 else:
111 log.success('Showing arguments of {} are:\n\033[1m{}\033[0m'.format(nextcommand, '\n'.join(args)))
92 log.success('Showing arguments of {} are:\n\033[1m{}\033[0m'.format(nextcommand, '\n'.join(args)))
112 except Exception as e:
93 except Exception as e:
113 log.error('Module {} does not exists'.format(nextcommand))
94 log.error('Module {} does not exists'.format(nextcommand))
114 allModules = dir(import_module('schainpy.model'))
95 allModules = paramsFinder.getAll()
115 module = check_module(allModules, Operation)
96 similar = process.extractOne(nextcommand, allModules)[0]
116 module.extend(check_module(allModules, ProcessingUnit))
97 log.success('Showing {} instead'.format(similar))
117 similar = process.extractOne(nextcommand, module)[0]
118 log.success('Searching {} instead'.format(similar))
119 search(similar)
98 search(similar)
120
99
121
100
122 def runschain(nextcommand):
101 def runschain(nextcommand):
123 if nextcommand is None:
102 if nextcommand is None:
124 currentfiles = glob.glob('./{}_*.py'.format(PREFIX))
103 currentfiles = glob.glob('./{}_*.py'.format(PREFIX))
125 numberfiles = len(currentfiles)
104 numberfiles = len(currentfiles)
126 if numberfiles > 1:
105 if numberfiles > 1:
127 log.error('There is more than one file to run')
106 log.error('There is more than one file to run')
128 elif numberfiles == 1:
107 elif numberfiles == 1:
129 subprocess.call(['python ' + currentfiles[0]], shell=True)
108 subprocess.call(['python ' + currentfiles[0]], shell=True)
130 else:
109 else:
131 log.error('There is no file to run')
110 log.error('There is no file to run')
132 else:
111 else:
133 try:
112 try:
134 subprocess.call(['python ' + nextcommand], shell=True)
113 subprocess.call(['python ' + nextcommand], shell=True)
135 except Exception as e:
114 except Exception as e:
136 log.error("I cannot run the file. Does it exists?")
115 log.error("I cannot run the file. Does it exists?")
137
116
138
117
139 def basicInputs():
118 def basicInputs():
140 inputs = {}
119 inputs = {}
141 inputs['desc'] = click.prompt('Enter a description', default="A schain project", type=str)
120 inputs['desc'] = click.prompt('Enter a description', default="A schain project", type=str)
142 inputs['name'] = click.prompt('Name of the project', default="project", type=str)
121 inputs['name'] = click.prompt('Name of the project', default="project", type=str)
143 inputs['path'] = click.prompt('Data path', default=os.getcwd(), type=click.Path(exists=True, resolve_path=True))
122 inputs['path'] = click.prompt('Data path', default=os.getcwd(), type=click.Path(exists=True, resolve_path=True))
144 inputs['startDate'] = click.prompt('Start date', default='1970/01/01', type=str)
123 inputs['startDate'] = click.prompt('Start date', default='1970/01/01', type=str)
145 inputs['endDate'] = click.prompt('End date', default='2017/12/31', type=str)
124 inputs['endDate'] = click.prompt('End date', default='2017/12/31', type=str)
146 inputs['startHour'] = click.prompt('Start hour', default='00:00:00', type=str)
125 inputs['startHour'] = click.prompt('Start hour', default='00:00:00', type=str)
147 inputs['endHour'] = click.prompt('End hour', default='23:59:59', type=str)
126 inputs['endHour'] = click.prompt('End hour', default='23:59:59', type=str)
148 inputs['figpath'] = inputs['path'] + '/figs'
127 inputs['figpath'] = inputs['path'] + '/figs'
149 return inputs
128 return inputs
150
129
151
130
152 def generate():
131 def generate():
153 inputs = basicInputs()
132 inputs = basicInputs()
154 inputs['multiprocess'] = click.confirm('Is this a multiprocess script?')
133 inputs['multiprocess'] = click.confirm('Is this a multiprocess script?')
155 if inputs['multiprocess']:
134 if inputs['multiprocess']:
156 inputs['nProcess'] = click.prompt('How many process?', default=cpu_count(), type=int)
135 inputs['nProcess'] = click.prompt('How many process?', default=cpu_count(), type=int)
157 current = templates.multiprocess.format(**inputs)
136 current = templates.multiprocess.format(**inputs)
158 else:
137 else:
159 current = templates.basic.format(**inputs)
138 current = templates.basic.format(**inputs)
160 scriptname = '{}_{}.py'.format(PREFIX, inputs['name'])
139 scriptname = '{}_{}.py'.format(PREFIX, inputs['name'])
161 script = open(scriptname, 'w')
140 script = open(scriptname, 'w')
162 try:
141 try:
163 script.write(current)
142 script.write(current)
164 log.success('Script {} generated'.format(scriptname))
143 log.success('Script {} generated'.format(scriptname))
165 except Exception as e:
144 except Exception as e:
166 log.error('I cannot create the file. Do you have writing permissions?')
145 log.error('I cannot create the file. Do you have writing permissions?')
167
146
168
147
169 def test():
148 def test():
170 log.warning('testing')
149 log.warning('testing')
171
150
172
151
173 def runFromXML(filename):
152 def runFromXML(filename):
174 controller = controller_api.ControllerThread()
153 controller = Project()
175 if not controller.readXml(filename):
154 if not controller.readXml(filename):
176 return
155 return
177
178 plotterObj = controller.useExternalPlotter()
179
180 controller.start()
156 controller.start()
181 plotterObj.start()
182
183 cliLogger("Finishing all processes")
184
185 controller.join(5)
186
187 cliLogger("End of script")
188 return
157 return
@@ -1,108 +1,109
1 ## CHANGELOG:
1 ## CHANGELOG:
2
2
3 ### 2.3
3 ### 2.3
4 * Added high order function `multiSchain` for multiprocessing scripts.
4 * Added high order function `multiSchain` for multiprocessing scripts.
5 * Added two new Processing Units `PublishData` and `ReceiverData` for receiving and sending dataOut through multiple ways (tcp, ipc, inproc).
5 * Added two new Processing Units `PublishData` and `ReceiverData` for receiving and sending dataOut through multiple ways (tcp, ipc, inproc).
6 * Added a new graphics Processing Unit `PlotterReceiver`. It is decoupled from normal processing sequence with support for data generated by multiprocessing scripts.
6 * Added a new graphics Processing Unit `PlotterReceiver`. It is decoupled from normal processing sequence with support for data generated by multiprocessing scripts.
7 * Added support for sending realtime graphic to web server.
7 * Added support for sending realtime graphic to web server.
8 * XML command `schain` is now `schain --xml`.
8 * GUI command `schain` is now `schainGUI`.
9 * Added a CLI tool named `schain`.
9 * Added a CLI tool named `schain`.
10 * Scripts templates can be now generated with `schain generate`.
10 * Scripts templates can be now generated with `schain generate`.
11 * Now it is possible to search Processing Units and Operations with `schain search [module]` to get the right name and its allowed parameters.
11 * Now it is possible to search Processing Units and Operations with `schain search [module]` to get the right name and its allowed parameters.
12 * `schain xml` to run xml scripts.
12 * Added suggestions when parameters are poorly written.
13 * Added suggestions when parameters are poorly written.
13 * `Controller.start()` now runs in a different process than the process calling it.
14 * `Controller.start()` now runs in a different process than the process calling it.
14 * Added `schainpy.utils.log` for log standarization.
15 * Added `schainpy.utils.log` for log standarization.
15 * Running script on online mode no longer ignores date and hour. Issue #1109.
16 * Running script on online mode no longer ignores date and hour. Issue #1109.
16 * Added support for receving voltage data directly from JARS (tcp, ipc).
17 * Added support for receving voltage data directly from JARS (tcp, ipc).
17 * Updated README for compatibility with MAC OS GUI installation.
18 * Updated README for MAC OS GUI installation.
18 * Setup now installs numpy.
19 * Setup now installs numpy.
19
20
20 ### 2.2.6
21 ### 2.2.6
21 * Graphics generated by the GUI are now the same as generated by scripts. Issue #1074.
22 * Graphics generated by the GUI are now the same as generated by scripts. Issue #1074.
22 * Added support for C extensions.
23 * Added support for C extensions.
23 * Function `hildebrand_sehkon` optimized with a C wrapper.
24 * Function `hildebrand_sehkon` optimized with a C wrapper.
24 * Numpy version updated.
25 * Numpy version updated.
25 * Migration to GIT.
26 * Migration to GIT.
26
27
27 ### 2.2.5:
28 ### 2.2.5:
28 * splitProfiles and combineProfiles modules were added to VoltageProc and Signal Chain GUI.
29 * splitProfiles and combineProfiles modules were added to VoltageProc and Signal Chain GUI.
29 * nProfiles of USRP data (hdf5) is the number of profiles thera are in one second.
30 * nProfiles of USRP data (hdf5) is the number of profiles thera are in one second.
30 * jroPlotter works directly with data objects instead of dictionaries
31 * jroPlotter works directly with data objects instead of dictionaries
31 * script "schain" was added to Signal Chain installer
32 * script "schain" was added to Signal Chain installer
32
33
33 ### 2.2.4.1:
34 ### 2.2.4.1:
34 * jroIO_usrp.py is update to read Sandra's data
35 * jroIO_usrp.py is update to read Sandra's data
35 * decimation in Spectra and RTI plots is always enabled.
36 * decimation in Spectra and RTI plots is always enabled.
36 * time* window option added to GUI
37 * time* window option added to GUI
37
38
38 ### 2.2.4:
39 ### 2.2.4:
39 * jroproc_spectra_lags.py added to schainpy
40 * jroproc_spectra_lags.py added to schainpy
40 * Bug fixed in schainGUI: ProcUnit was created with the same id in some cases.
41 * Bug fixed in schainGUI: ProcUnit was created with the same id in some cases.
41 * Bug fixed in jroHeaderIO: Header size validation.
42 * Bug fixed in jroHeaderIO: Header size validation.
42
43
43 ### 2.2.3.1:
44 ### 2.2.3.1:
44 * Filtering block by time has been added.
45 * Filtering block by time has been added.
45 * Bug fixed plotting RTI, CoherenceMap and others using xmin and xmax parameters. The first day worked
46 * Bug fixed plotting RTI, CoherenceMap and others using xmin and xmax parameters. The first day worked
46 properly but the next days did not.
47 properly but the next days did not.
47
48
48 ### 2.2.3:
49 ### 2.2.3:
49 * Bug fixed in GUI: Error getting(reading) Code value
50 * Bug fixed in GUI: Error getting(reading) Code value
50 * Bug fixed in GUI: Flip option always needs channelList field
51 * Bug fixed in GUI: Flip option always needs channelList field
51 * Bug fixed in jrodata: when one branch modified a value in "dataOut" (example: dataOut.code) this value
52 * Bug fixed in jrodata: when one branch modified a value in "dataOut" (example: dataOut.code) this value
52 was modified for every branch (because this was a reference). It was modified in data.copy()
53 was modified for every branch (because this was a reference). It was modified in data.copy()
53 * Bug fixed in jroproc_voltage.profileSelector(): rangeList replaces to profileRangeList.
54 * Bug fixed in jroproc_voltage.profileSelector(): rangeList replaces to profileRangeList.
54
55
55 ### 2.2.2:
56 ### 2.2.2:
56 * VoltageProc: ProfileSelector, Reshape, Decoder with nTxs!=1 and getblock=True was tested
57 * VoltageProc: ProfileSelector, Reshape, Decoder with nTxs!=1 and getblock=True was tested
57 * Rawdata and testRawdata.py added to Signal Chain project
58 * Rawdata and testRawdata.py added to Signal Chain project
58
59
59 ### 2.2.1:
60 ### 2.2.1:
60 * Bugs fixed in GUI
61 * Bugs fixed in GUI
61 * Views were improved in GUI
62 * Views were improved in GUI
62 * Support to MST* ISR experiments
63 * Support to MST* ISR experiments
63 * Bug fixed getting noise using hyldebrant. (minimum number of points > 20%)
64 * Bug fixed getting noise using hyldebrant. (minimum number of points > 20%)
64 * handleError added to jroplotter.py
65 * handleError added to jroplotter.py
65
66
66 ### 2.2.0:
67 ### 2.2.0:
67 * GUI: use of external plotter
68 * GUI: use of external plotter
68 * Compatible with matplotlib 1.5.0
69 * Compatible with matplotlib 1.5.0
69
70
70 ### 2.1.5:
71 ### 2.1.5:
71 * serializer module added to Signal Chain
72 * serializer module added to Signal Chain
72 * jroplotter.py added to Signal Chain
73 * jroplotter.py added to Signal Chain
73
74
74 ### 2.1.4.2:
75 ### 2.1.4.2:
75 * A new Plotter Class was added
76 * A new Plotter Class was added
76 * Project.start() does not accept filename as a parameter anymore
77 * Project.start() does not accept filename as a parameter anymore
77
78
78 ### 2.1.4.1:
79 ### 2.1.4.1:
79 * Send notifications when an error different to ValueError is detected
80 * Send notifications when an error different to ValueError is detected
80
81
81 ### 2.1.4:
82 ### 2.1.4:
82 * Sending error notifications to signal chain administrator
83 * Sending error notifications to signal chain administrator
83 * Login to email server added
84 * Login to email server added
84
85
85 ### 2.1.3.3:
86 ### 2.1.3.3:
86 * Colored Button Icons were added to GUI
87 * Colored Button Icons were added to GUI
87
88
88 ### 2.1.3.2:
89 ### 2.1.3.2:
89 * GUI: user interaction enhanced
90 * GUI: user interaction enhanced
90 * controller_api.py: Safe access to ControllerThead
91 * controller_api.py: Safe access to ControllerThead
91
92
92 ### 2.1.3.1:
93 ### 2.1.3.1:
93 * GUI: every icon were resized
94 * GUI: every icon were resized
94 * jroproc_voltage.py: Print a message when "Read from code" option is selected and the code is not defined inside data file
95 * jroproc_voltage.py: Print a message when "Read from code" option is selected and the code is not defined inside data file
95
96
96 ### 2.1.3:
97 ### 2.1.3:
97 * jroplot_heispectra.py: SpectraHeisScope was not showing the right channels
98 * jroplot_heispectra.py: SpectraHeisScope was not showing the right channels
98 * jroproc_voltage.py: Bug fixed selecting profiles (self.nProfiles took a wrong value),
99 * jroproc_voltage.py: Bug fixed selecting profiles (self.nProfiles took a wrong value),
99 Bug fixed selecting heights by block (selecting profiles instead heights)
100 Bug fixed selecting heights by block (selecting profiles instead heights)
100 * jroproc_voltage.py: New feature added: decoding data by block using FFT.
101 * jroproc_voltage.py: New feature added: decoding data by block using FFT.
101 * jroIO_heispectra.py: Bug fixed in FitsReader. Using local Fits instance instead schainpy.mode.data.jrodata.Fits.
102 * jroIO_heispectra.py: Bug fixed in FitsReader. Using local Fits instance instead schainpy.mode.data.jrodata.Fits.
102 * jroIO_heispectra.py: Channel index list does not exist.
103 * jroIO_heispectra.py: Channel index list does not exist.
103
104
104 ### 2.1.2:
105 ### 2.1.2:
105 * jroutils_ftp.py: Bug fixed, Any error sending file stopped the Server Thread
106 * jroutils_ftp.py: Bug fixed, Any error sending file stopped the Server Thread
106 Server thread opens and closes remote server each time file list is sent
107 Server thread opens and closes remote server each time file list is sent
107 * jroplot_spectra.py: Noise path was not being created when noise data is saved.
108 * jroplot_spectra.py: Noise path was not being created when noise data is saved.
108 * jroIO_base.py: startTime can be greater than endTime. Example: SpreadF [18:00 * 07:00] No newline at end of file
109 * jroIO_base.py: startTime can be greater than endTime. Example: SpreadF [18:00 * 07:00]
@@ -1,8 +1,7
1 '''
1 '''
2 Created on Feb 7, 2012
2 Created on Feb 7, 2012
3
3
4 @author $Author$
4 @author $Author$
5 @version $Id$
5 @version $Id$
6 '''
6 '''
7
8 __version__ = "2.3"
7 __version__ = "2.3"
@@ -1,1294 +1,1280
1 '''
1 '''
2 Created on September , 2012
2 Created on September , 2012
3 @author:
3 @author:
4 '''
4 '''
5
5
6 import sys
6 import sys
7 import ast
7 import ast
8 import datetime
8 import datetime
9 import traceback
9 import traceback
10 import schainpy
10 import schainpy
11 import schainpy.admin
11 import schainpy.admin
12 from schainpy.utils.log import logToFile
12
13
13 from xml.etree.ElementTree import ElementTree, Element, SubElement, tostring
14 from xml.etree.ElementTree import ElementTree, Element, SubElement, tostring
14 from xml.dom import minidom
15 from xml.dom import minidom
15
16
16 from schainpy.model import *
17 from schainpy.model import *
17 from time import sleep
18 from time import sleep
18
19
20
21
19 def prettify(elem):
22 def prettify(elem):
20 """Return a pretty-printed XML string for the Element.
23 """Return a pretty-printed XML string for the Element.
21 """
24 """
22 rough_string = tostring(elem, 'utf-8')
25 rough_string = tostring(elem, 'utf-8')
23 reparsed = minidom.parseString(rough_string)
26 reparsed = minidom.parseString(rough_string)
24 return reparsed.toprettyxml(indent=" ")
27 return reparsed.toprettyxml(indent=" ")
25
28
29 def multiSchain(child, nProcess=cpu_count(), startDate=None, endDate=None, by_day=False):
30 skip = 0
31 cursor = 0
32 nFiles = None
33 processes = []
34 dt1 = datetime.datetime.strptime(startDate, '%Y/%m/%d')
35 dt2 = datetime.datetime.strptime(endDate, '%Y/%m/%d')
36 days = (dt2 - dt1).days
37
38 for day in range(days+1):
39 skip = 0
40 cursor = 0
41 q = Queue()
42 processes = []
43 dt = (dt1 + datetime.timedelta(day)).strftime('%Y/%m/%d')
44 firstProcess = Process(target=child, args=(cursor, skip, q, dt))
45 firstProcess.start()
46 if by_day:
47 continue
48 nFiles = q.get()
49 if nFiles==0:
50 continue
51 firstProcess.terminate()
52 skip = int(math.ceil(nFiles/nProcess))
53 while True:
54 processes.append(Process(target=child, args=(cursor, skip, q, dt)))
55 processes[cursor].start()
56 if nFiles < cursor*skip:
57 break
58 cursor += 1
59
60 def beforeExit(exctype, value, trace):
61 for process in processes:
62 process.terminate()
63 process.join()
64 print traceback.print_tb(trace)
65
66 sys.excepthook = beforeExit
67
68 for process in processes:
69 process.join()
70 process.terminate()
71
72 time.sleep(3)
73
74
26 class ParameterConf():
75 class ParameterConf():
27
76
28 id = None
77 id = None
29 name = None
78 name = None
30 value = None
79 value = None
31 format = None
80 format = None
32
81
33 __formated_value = None
82 __formated_value = None
34
83
35 ELEMENTNAME = 'Parameter'
84 ELEMENTNAME = 'Parameter'
36
85
37 def __init__(self):
86 def __init__(self):
38
87
39 self.format = 'str'
88 self.format = 'str'
40
89
41 def getElementName(self):
90 def getElementName(self):
42
91
43 return self.ELEMENTNAME
92 return self.ELEMENTNAME
44
93
45 def getValue(self):
94 def getValue(self):
46
95
47 value = self.value
96 value = self.value
48 format = self.format
97 format = self.format
49
98
50 if self.__formated_value != None:
99 if self.__formated_value != None:
51
100
52 return self.__formated_value
101 return self.__formated_value
53
102
54 if format == 'str':
103 if format == 'str':
55 self.__formated_value = str(value)
104 self.__formated_value = str(value)
56 return self.__formated_value
105 return self.__formated_value
57
106
58 if value == '':
107 if value == '':
59 raise ValueError, "%s: This parameter value is empty" %self.name
108 raise ValueError, "%s: This parameter value is empty" %self.name
60
109
61 if format == 'list':
110 if format == 'list':
62 strList = value.split(',')
111 strList = value.split(',')
63
112
64 self.__formated_value = strList
113 self.__formated_value = strList
65
114
66 return self.__formated_value
115 return self.__formated_value
67
116
68 if format == 'intlist':
117 if format == 'intlist':
69 """
118 """
70 Example:
119 Example:
71 value = (0,1,2)
120 value = (0,1,2)
72 """
121 """
73
122
74 new_value = ast.literal_eval(value)
123 new_value = ast.literal_eval(value)
75
124
76 if type(new_value) not in (tuple, list):
125 if type(new_value) not in (tuple, list):
77 new_value = [int(new_value)]
126 new_value = [int(new_value)]
78
127
79 self.__formated_value = new_value
128 self.__formated_value = new_value
80
129
81 return self.__formated_value
130 return self.__formated_value
82
131
83 if format == 'floatlist':
132 if format == 'floatlist':
84 """
133 """
85 Example:
134 Example:
86 value = (0.5, 1.4, 2.7)
135 value = (0.5, 1.4, 2.7)
87 """
136 """
88
137
89 new_value = ast.literal_eval(value)
138 new_value = ast.literal_eval(value)
90
139
91 if type(new_value) not in (tuple, list):
140 if type(new_value) not in (tuple, list):
92 new_value = [float(new_value)]
141 new_value = [float(new_value)]
93
142
94 self.__formated_value = new_value
143 self.__formated_value = new_value
95
144
96 return self.__formated_value
145 return self.__formated_value
97
146
98 if format == 'date':
147 if format == 'date':
99 strList = value.split('/')
148 strList = value.split('/')
100 intList = [int(x) for x in strList]
149 intList = [int(x) for x in strList]
101 date = datetime.date(intList[0], intList[1], intList[2])
150 date = datetime.date(intList[0], intList[1], intList[2])
102
151
103 self.__formated_value = date
152 self.__formated_value = date
104
153
105 return self.__formated_value
154 return self.__formated_value
106
155
107 if format == 'time':
156 if format == 'time':
108 strList = value.split(':')
157 strList = value.split(':')
109 intList = [int(x) for x in strList]
158 intList = [int(x) for x in strList]
110 time = datetime.time(intList[0], intList[1], intList[2])
159 time = datetime.time(intList[0], intList[1], intList[2])
111
160
112 self.__formated_value = time
161 self.__formated_value = time
113
162
114 return self.__formated_value
163 return self.__formated_value
115
164
116 if format == 'pairslist':
165 if format == 'pairslist':
117 """
166 """
118 Example:
167 Example:
119 value = (0,1),(1,2)
168 value = (0,1),(1,2)
120 """
169 """
121
170
122 new_value = ast.literal_eval(value)
171 new_value = ast.literal_eval(value)
123
172
124 if type(new_value) not in (tuple, list):
173 if type(new_value) not in (tuple, list):
125 raise ValueError, "%s has to be a tuple or list of pairs" %value
174 raise ValueError, "%s has to be a tuple or list of pairs" %value
126
175
127 if type(new_value[0]) not in (tuple, list):
176 if type(new_value[0]) not in (tuple, list):
128 if len(new_value) != 2:
177 if len(new_value) != 2:
129 raise ValueError, "%s has to be a tuple or list of pairs" %value
178 raise ValueError, "%s has to be a tuple or list of pairs" %value
130 new_value = [new_value]
179 new_value = [new_value]
131
180
132 for thisPair in new_value:
181 for thisPair in new_value:
133 if len(thisPair) != 2:
182 if len(thisPair) != 2:
134 raise ValueError, "%s has to be a tuple or list of pairs" %value
183 raise ValueError, "%s has to be a tuple or list of pairs" %value
135
184
136 self.__formated_value = new_value
185 self.__formated_value = new_value
137
186
138 return self.__formated_value
187 return self.__formated_value
139
188
140 if format == 'multilist':
189 if format == 'multilist':
141 """
190 """
142 Example:
191 Example:
143 value = (0,1,2),(3,4,5)
192 value = (0,1,2),(3,4,5)
144 """
193 """
145 multiList = ast.literal_eval(value)
194 multiList = ast.literal_eval(value)
146
195
147 if type(multiList[0]) == int:
196 if type(multiList[0]) == int:
148 multiList = ast.literal_eval("(" + value + ")")
197 multiList = ast.literal_eval("(" + value + ")")
149
198
150 self.__formated_value = multiList
199 self.__formated_value = multiList
151
200
152 return self.__formated_value
201 return self.__formated_value
153
202
154 if format == 'bool':
203 if format == 'bool':
155 value = int(value)
204 value = int(value)
156
205
157 if format == 'int':
206 if format == 'int':
158 value = float(value)
207 value = float(value)
159
208
160 format_func = eval(format)
209 format_func = eval(format)
161
210
162 self.__formated_value = format_func(value)
211 self.__formated_value = format_func(value)
163
212
164 return self.__formated_value
213 return self.__formated_value
165
214
166 def updateId(self, new_id):
215 def updateId(self, new_id):
167
216
168 self.id = str(new_id)
217 self.id = str(new_id)
169
218
170 def setup(self, id, name, value, format='str'):
219 def setup(self, id, name, value, format='str'):
171
220
172 self.id = str(id)
221 self.id = str(id)
173 self.name = name
222 self.name = name
174 self.value = str(value)
223 self.value = str(value)
175 self.format = str.lower(format)
224 self.format = str.lower(format)
176
225
177 self.getValue()
226 self.getValue()
178
227
179 return 1
228 return 1
180
229
181 def update(self, name, value, format='str'):
230 def update(self, name, value, format='str'):
182
231
183 self.name = name
232 self.name = name
184 self.value = str(value)
233 self.value = str(value)
185 self.format = format
234 self.format = format
186
235
187 def makeXml(self, opElement):
236 def makeXml(self, opElement):
188
237
189 parmElement = SubElement(opElement, self.ELEMENTNAME)
238 parmElement = SubElement(opElement, self.ELEMENTNAME)
190 parmElement.set('id', str(self.id))
239 parmElement.set('id', str(self.id))
191 parmElement.set('name', self.name)
240 parmElement.set('name', self.name)
192 parmElement.set('value', self.value)
241 parmElement.set('value', self.value)
193 parmElement.set('format', self.format)
242 parmElement.set('format', self.format)
194
243
195 def readXml(self, parmElement):
244 def readXml(self, parmElement):
196
245
197 self.id = parmElement.get('id')
246 self.id = parmElement.get('id')
198 self.name = parmElement.get('name')
247 self.name = parmElement.get('name')
199 self.value = parmElement.get('value')
248 self.value = parmElement.get('value')
200 self.format = str.lower(parmElement.get('format'))
249 self.format = str.lower(parmElement.get('format'))
201
250
202 #Compatible with old signal chain version
251 #Compatible with old signal chain version
203 if self.format == 'int' and self.name == 'idfigure':
252 if self.format == 'int' and self.name == 'idfigure':
204 self.name = 'id'
253 self.name = 'id'
205
254
206 def printattr(self):
255 def printattr(self):
207
256
208 print "Parameter[%s]: name = %s, value = %s, format = %s" %(self.id, self.name, self.value, self.format)
257 print "Parameter[%s]: name = %s, value = %s, format = %s" %(self.id, self.name, self.value, self.format)
209
258
210 class OperationConf():
259 class OperationConf():
211
260
212 id = None
261 id = None
213 name = None
262 name = None
214 priority = None
263 priority = None
215 type = None
264 type = None
216
265
217 parmConfObjList = []
266 parmConfObjList = []
218
267
219 ELEMENTNAME = 'Operation'
268 ELEMENTNAME = 'Operation'
220
269
221 def __init__(self):
270 def __init__(self):
222
271
223 self.id = '0'
272 self.id = '0'
224 self.name = None
273 self.name = None
225 self.priority = None
274 self.priority = None
226 self.type = 'self'
275 self.type = 'self'
227
276
228
277
229 def __getNewId(self):
278 def __getNewId(self):
230
279
231 return int(self.id)*10 + len(self.parmConfObjList) + 1
280 return int(self.id)*10 + len(self.parmConfObjList) + 1
232
281
233 def updateId(self, new_id):
282 def updateId(self, new_id):
234
283
235 self.id = str(new_id)
284 self.id = str(new_id)
236
285
237 n = 1
286 n = 1
238 for parmObj in self.parmConfObjList:
287 for parmObj in self.parmConfObjList:
239
288
240 idParm = str(int(new_id)*10 + n)
289 idParm = str(int(new_id)*10 + n)
241 parmObj.updateId(idParm)
290 parmObj.updateId(idParm)
242
291
243 n += 1
292 n += 1
244
293
245 def getElementName(self):
294 def getElementName(self):
246
295
247 return self.ELEMENTNAME
296 return self.ELEMENTNAME
248
297
249 def getParameterObjList(self):
298 def getParameterObjList(self):
250
299
251 return self.parmConfObjList
300 return self.parmConfObjList
252
301
253 def getParameterObj(self, parameterName):
302 def getParameterObj(self, parameterName):
254
303
255 for parmConfObj in self.parmConfObjList:
304 for parmConfObj in self.parmConfObjList:
256
305
257 if parmConfObj.name != parameterName:
306 if parmConfObj.name != parameterName:
258 continue
307 continue
259
308
260 return parmConfObj
309 return parmConfObj
261
310
262 return None
311 return None
263
312
264 def getParameterObjfromValue(self, parameterValue):
313 def getParameterObjfromValue(self, parameterValue):
265
314
266 for parmConfObj in self.parmConfObjList:
315 for parmConfObj in self.parmConfObjList:
267
316
268 if parmConfObj.getValue() != parameterValue:
317 if parmConfObj.getValue() != parameterValue:
269 continue
318 continue
270
319
271 return parmConfObj.getValue()
320 return parmConfObj.getValue()
272
321
273 return None
322 return None
274
323
275 def getParameterValue(self, parameterName):
324 def getParameterValue(self, parameterName):
276
325
277 parameterObj = self.getParameterObj(parameterName)
326 parameterObj = self.getParameterObj(parameterName)
278
327
279 # if not parameterObj:
328 # if not parameterObj:
280 # return None
329 # return None
281
330
282 value = parameterObj.getValue()
331 value = parameterObj.getValue()
283
332
284 return value
333 return value
285
334
286 def setup(self, id, name, priority, type):
335 def setup(self, id, name, priority, type):
287
336
288 self.id = str(id)
337 self.id = str(id)
289 self.name = name
338 self.name = name
290 self.type = type
339 self.type = type
291 self.priority = priority
340 self.priority = priority
292
341
293 self.parmConfObjList = []
342 self.parmConfObjList = []
294
343
295 def removeParameters(self):
344 def removeParameters(self):
296
345
297 for obj in self.parmConfObjList:
346 for obj in self.parmConfObjList:
298 del obj
347 del obj
299
348
300 self.parmConfObjList = []
349 self.parmConfObjList = []
301
350
302 def addParameter(self, name, value, format='str'):
351 def addParameter(self, name, value, format='str'):
303
352
304 id = self.__getNewId()
353 id = self.__getNewId()
305
354
306 parmConfObj = ParameterConf()
355 parmConfObj = ParameterConf()
307 if not parmConfObj.setup(id, name, value, format):
356 if not parmConfObj.setup(id, name, value, format):
308 return None
357 return None
309
358
310 self.parmConfObjList.append(parmConfObj)
359 self.parmConfObjList.append(parmConfObj)
311
360
312 return parmConfObj
361 return parmConfObj
313
362
314 def changeParameter(self, name, value, format='str'):
363 def changeParameter(self, name, value, format='str'):
315
364
316 parmConfObj = self.getParameterObj(name)
365 parmConfObj = self.getParameterObj(name)
317 parmConfObj.update(name, value, format)
366 parmConfObj.update(name, value, format)
318
367
319 return parmConfObj
368 return parmConfObj
320
369
321 def makeXml(self, procUnitElement):
370 def makeXml(self, procUnitElement):
322
371
323 opElement = SubElement(procUnitElement, self.ELEMENTNAME)
372 opElement = SubElement(procUnitElement, self.ELEMENTNAME)
324 opElement.set('id', str(self.id))
373 opElement.set('id', str(self.id))
325 opElement.set('name', self.name)
374 opElement.set('name', self.name)
326 opElement.set('type', self.type)
375 opElement.set('type', self.type)
327 opElement.set('priority', str(self.priority))
376 opElement.set('priority', str(self.priority))
328
377
329 for parmConfObj in self.parmConfObjList:
378 for parmConfObj in self.parmConfObjList:
330 parmConfObj.makeXml(opElement)
379 parmConfObj.makeXml(opElement)
331
380
332 def readXml(self, opElement):
381 def readXml(self, opElement):
333
382
334 self.id = opElement.get('id')
383 self.id = opElement.get('id')
335 self.name = opElement.get('name')
384 self.name = opElement.get('name')
336 self.type = opElement.get('type')
385 self.type = opElement.get('type')
337 self.priority = opElement.get('priority')
386 self.priority = opElement.get('priority')
338
387
339 #Compatible with old signal chain version
388 #Compatible with old signal chain version
340 #Use of 'run' method instead 'init'
389 #Use of 'run' method instead 'init'
341 if self.type == 'self' and self.name == 'init':
390 if self.type == 'self' and self.name == 'init':
342 self.name = 'run'
391 self.name = 'run'
343
392
344 self.parmConfObjList = []
393 self.parmConfObjList = []
345
394
346 parmElementList = opElement.iter(ParameterConf().getElementName())
395 parmElementList = opElement.iter(ParameterConf().getElementName())
347
396
348 for parmElement in parmElementList:
397 for parmElement in parmElementList:
349 parmConfObj = ParameterConf()
398 parmConfObj = ParameterConf()
350 parmConfObj.readXml(parmElement)
399 parmConfObj.readXml(parmElement)
351
400
352 #Compatible with old signal chain version
401 #Compatible with old signal chain version
353 #If an 'plot' OPERATION is found, changes name operation by the value of its type PARAMETER
402 #If an 'plot' OPERATION is found, changes name operation by the value of its type PARAMETER
354 if self.type != 'self' and self.name == 'Plot':
403 if self.type != 'self' and self.name == 'Plot':
355 if parmConfObj.format == 'str' and parmConfObj.name == 'type':
404 if parmConfObj.format == 'str' and parmConfObj.name == 'type':
356 self.name = parmConfObj.value
405 self.name = parmConfObj.value
357 continue
406 continue
358
407
359 self.parmConfObjList.append(parmConfObj)
408 self.parmConfObjList.append(parmConfObj)
360
409
361 def printattr(self):
410 def printattr(self):
362
411
363 print "%s[%s]: name = %s, type = %s, priority = %s" %(self.ELEMENTNAME,
412 print "%s[%s]: name = %s, type = %s, priority = %s" %(self.ELEMENTNAME,
364 self.id,
413 self.id,
365 self.name,
414 self.name,
366 self.type,
415 self.type,
367 self.priority)
416 self.priority)
368
417
369 for parmConfObj in self.parmConfObjList:
418 for parmConfObj in self.parmConfObjList:
370 parmConfObj.printattr()
419 parmConfObj.printattr()
371
420
372 def createObject(self, plotter_queue=None):
421 def createObject(self, plotter_queue=None):
373
422
374 if self.type == 'self':
423 if self.type == 'self':
375 raise ValueError, "This operation type cannot be created"
424 raise ValueError, "This operation type cannot be created"
376
425
377 if self.type == 'plotter':
426 if self.type == 'plotter':
378 #Plotter(plotter_name)
427 #Plotter(plotter_name)
379 if not plotter_queue:
428 if not plotter_queue:
380 raise ValueError, "plotter_queue is not defined. Use:\nmyProject = Project()\nmyProject.setPlotterQueue(plotter_queue)"
429 raise ValueError, "plotter_queue is not defined. Use:\nmyProject = Project()\nmyProject.setPlotterQueue(plotter_queue)"
381
430
382 opObj = Plotter(self.name, plotter_queue)
431 opObj = Plotter(self.name, plotter_queue)
383
432
384 if self.type == 'external' or self.type == 'other':
433 if self.type == 'external' or self.type == 'other':
385 className = eval(self.name)
434 className = eval(self.name)
386 opObj = className()
435 opObj = className()
387
436
388 return opObj
437 return opObj
389
438
390 class ProcUnitConf():
439 class ProcUnitConf():
391
440
392 id = None
441 id = None
393 name = None
442 name = None
394 datatype = None
443 datatype = None
395 inputId = None
444 inputId = None
396 parentId = None
445 parentId = None
397
446
398 opConfObjList = []
447 opConfObjList = []
399
448
400 procUnitObj = None
449 procUnitObj = None
401 opObjList = []
450 opObjList = []
402
451
403 ELEMENTNAME = 'ProcUnit'
452 ELEMENTNAME = 'ProcUnit'
404
453
405 def __init__(self):
454 def __init__(self):
406
455
407 self.id = None
456 self.id = None
408 self.datatype = None
457 self.datatype = None
409 self.name = None
458 self.name = None
410 self.inputId = None
459 self.inputId = None
411
460
412 self.opConfObjList = []
461 self.opConfObjList = []
413
462
414 self.procUnitObj = None
463 self.procUnitObj = None
415 self.opObjDict = {}
464 self.opObjDict = {}
416
465
417 def __getPriority(self):
466 def __getPriority(self):
418
467
419 return len(self.opConfObjList)+1
468 return len(self.opConfObjList)+1
420
469
421 def __getNewId(self):
470 def __getNewId(self):
422
471
423 return int(self.id)*10 + len(self.opConfObjList) + 1
472 return int(self.id)*10 + len(self.opConfObjList) + 1
424
473
425 def getElementName(self):
474 def getElementName(self):
426
475
427 return self.ELEMENTNAME
476 return self.ELEMENTNAME
428
477
429 def getId(self):
478 def getId(self):
430
479
431 return self.id
480 return self.id
432
481
433 def updateId(self, new_id, parentId=parentId):
482 def updateId(self, new_id, parentId=parentId):
434
483
435
484
436 new_id = int(parentId)*10 + (int(self.id) % 10)
485 new_id = int(parentId)*10 + (int(self.id) % 10)
437 new_inputId = int(parentId)*10 + (int(self.inputId) % 10)
486 new_inputId = int(parentId)*10 + (int(self.inputId) % 10)
438
487
439 #If this proc unit has not inputs
488 #If this proc unit has not inputs
440 if self.inputId == '0':
489 if self.inputId == '0':
441 new_inputId = 0
490 new_inputId = 0
442
491
443 n = 1
492 n = 1
444 for opConfObj in self.opConfObjList:
493 for opConfObj in self.opConfObjList:
445
494
446 idOp = str(int(new_id)*10 + n)
495 idOp = str(int(new_id)*10 + n)
447 opConfObj.updateId(idOp)
496 opConfObj.updateId(idOp)
448
497
449 n += 1
498 n += 1
450
499
451 self.parentId = str(parentId)
500 self.parentId = str(parentId)
452 self.id = str(new_id)
501 self.id = str(new_id)
453 self.inputId = str(new_inputId)
502 self.inputId = str(new_inputId)
454
503
455
504
456 def getInputId(self):
505 def getInputId(self):
457
506
458 return self.inputId
507 return self.inputId
459
508
460 def getOperationObjList(self):
509 def getOperationObjList(self):
461
510
462 return self.opConfObjList
511 return self.opConfObjList
463
512
464 def getOperationObj(self, name=None):
513 def getOperationObj(self, name=None):
465
514
466 for opConfObj in self.opConfObjList:
515 for opConfObj in self.opConfObjList:
467
516
468 if opConfObj.name != name:
517 if opConfObj.name != name:
469 continue
518 continue
470
519
471 return opConfObj
520 return opConfObj
472
521
473 return None
522 return None
474
523
475 def getOpObjfromParamValue(self, value=None):
524 def getOpObjfromParamValue(self, value=None):
476
525
477 for opConfObj in self.opConfObjList:
526 for opConfObj in self.opConfObjList:
478 if opConfObj.getParameterObjfromValue(parameterValue=value) != value:
527 if opConfObj.getParameterObjfromValue(parameterValue=value) != value:
479 continue
528 continue
480 return opConfObj
529 return opConfObj
481 return None
530 return None
482
531
483 def getProcUnitObj(self):
532 def getProcUnitObj(self):
484
533
485 return self.procUnitObj
534 return self.procUnitObj
486
535
487 def setup(self, id, name, datatype, inputId, parentId=None):
536 def setup(self, id, name, datatype, inputId, parentId=None):
488
537
489 #Compatible with old signal chain version
538 #Compatible with old signal chain version
490 if datatype==None and name==None:
539 if datatype==None and name==None:
491 raise ValueError, "datatype or name should be defined"
540 raise ValueError, "datatype or name should be defined"
492
541
493 if name==None:
542 if name==None:
494 if 'Proc' in datatype:
543 if 'Proc' in datatype:
495 name = datatype
544 name = datatype
496 else:
545 else:
497 name = '%sProc' %(datatype)
546 name = '%sProc' %(datatype)
498
547
499 if datatype==None:
548 if datatype==None:
500 datatype = name.replace('Proc','')
549 datatype = name.replace('Proc','')
501
550
502 self.id = str(id)
551 self.id = str(id)
503 self.name = name
552 self.name = name
504 self.datatype = datatype
553 self.datatype = datatype
505 self.inputId = inputId
554 self.inputId = inputId
506 self.parentId = parentId
555 self.parentId = parentId
507
556
508 self.opConfObjList = []
557 self.opConfObjList = []
509
558
510 self.addOperation(name='run', optype='self')
559 self.addOperation(name='run', optype='self')
511
560
512 def removeOperations(self):
561 def removeOperations(self):
513
562
514 for obj in self.opConfObjList:
563 for obj in self.opConfObjList:
515 del obj
564 del obj
516
565
517 self.opConfObjList = []
566 self.opConfObjList = []
518 self.addOperation(name='run')
567 self.addOperation(name='run')
519
568
520 def addParameter(self, **kwargs):
569 def addParameter(self, **kwargs):
521 '''
570 '''
522 Add parameters to "run" operation
571 Add parameters to "run" operation
523 '''
572 '''
524 opObj = self.opConfObjList[0]
573 opObj = self.opConfObjList[0]
525
574
526 opObj.addParameter(**kwargs)
575 opObj.addParameter(**kwargs)
527
576
528 return opObj
577 return opObj
529
578
530 def addOperation(self, name, optype='self'):
579 def addOperation(self, name, optype='self'):
531
580
532 id = self.__getNewId()
581 id = self.__getNewId()
533 priority = self.__getPriority()
582 priority = self.__getPriority()
534
583
535 opConfObj = OperationConf()
584 opConfObj = OperationConf()
536 opConfObj.setup(id, name=name, priority=priority, type=optype)
585 opConfObj.setup(id, name=name, priority=priority, type=optype)
537
586
538 self.opConfObjList.append(opConfObj)
587 self.opConfObjList.append(opConfObj)
539
588
540 return opConfObj
589 return opConfObj
541
590
542 def makeXml(self, projectElement):
591 def makeXml(self, projectElement):
543
592
544 procUnitElement = SubElement(projectElement, self.ELEMENTNAME)
593 procUnitElement = SubElement(projectElement, self.ELEMENTNAME)
545 procUnitElement.set('id', str(self.id))
594 procUnitElement.set('id', str(self.id))
546 procUnitElement.set('name', self.name)
595 procUnitElement.set('name', self.name)
547 procUnitElement.set('datatype', self.datatype)
596 procUnitElement.set('datatype', self.datatype)
548 procUnitElement.set('inputId', str(self.inputId))
597 procUnitElement.set('inputId', str(self.inputId))
549
598
550 for opConfObj in self.opConfObjList:
599 for opConfObj in self.opConfObjList:
551 opConfObj.makeXml(procUnitElement)
600 opConfObj.makeXml(procUnitElement)
552
601
553 def readXml(self, upElement):
602 def readXml(self, upElement):
554
603
555 self.id = upElement.get('id')
604 self.id = upElement.get('id')
556 self.name = upElement.get('name')
605 self.name = upElement.get('name')
557 self.datatype = upElement.get('datatype')
606 self.datatype = upElement.get('datatype')
558 self.inputId = upElement.get('inputId')
607 self.inputId = upElement.get('inputId')
559
608
560 if self.ELEMENTNAME == "ReadUnit":
609 if self.ELEMENTNAME == "ReadUnit":
561 self.datatype = self.datatype.replace("Reader", "")
610 self.datatype = self.datatype.replace("Reader", "")
562
611
563 if self.ELEMENTNAME == "ProcUnit":
612 if self.ELEMENTNAME == "ProcUnit":
564 self.datatype = self.datatype.replace("Proc", "")
613 self.datatype = self.datatype.replace("Proc", "")
565
614
566 if self.inputId == 'None':
615 if self.inputId == 'None':
567 self.inputId = '0'
616 self.inputId = '0'
568
617
569 self.opConfObjList = []
618 self.opConfObjList = []
570
619
571 opElementList = upElement.iter(OperationConf().getElementName())
620 opElementList = upElement.iter(OperationConf().getElementName())
572
621
573 for opElement in opElementList:
622 for opElement in opElementList:
574 opConfObj = OperationConf()
623 opConfObj = OperationConf()
575 opConfObj.readXml(opElement)
624 opConfObj.readXml(opElement)
576 self.opConfObjList.append(opConfObj)
625 self.opConfObjList.append(opConfObj)
577
626
578 def printattr(self):
627 def printattr(self):
579
628
580 print "%s[%s]: name = %s, datatype = %s, inputId = %s" %(self.ELEMENTNAME,
629 print "%s[%s]: name = %s, datatype = %s, inputId = %s" %(self.ELEMENTNAME,
581 self.id,
630 self.id,
582 self.name,
631 self.name,
583 self.datatype,
632 self.datatype,
584 self.inputId)
633 self.inputId)
585
634
586 for opConfObj in self.opConfObjList:
635 for opConfObj in self.opConfObjList:
587 opConfObj.printattr()
636 opConfObj.printattr()
588
637
589 def createObjects(self, plotter_queue=None):
638 def createObjects(self, plotter_queue=None):
590
639
591 className = eval(self.name)
640 className = eval(self.name)
592 procUnitObj = className()
641 procUnitObj = className()
593
642
594 for opConfObj in self.opConfObjList:
643 for opConfObj in self.opConfObjList:
595
644
596 if opConfObj.type == 'self':
645 if opConfObj.type == 'self':
597 continue
646 continue
598
647
599 opObj = opConfObj.createObject(plotter_queue)
648 opObj = opConfObj.createObject(plotter_queue)
600
649
601 self.opObjDict[opConfObj.id] = opObj
650 self.opObjDict[opConfObj.id] = opObj
602 procUnitObj.addOperation(opObj, opConfObj.id)
651 procUnitObj.addOperation(opObj, opConfObj.id)
603
652
604 self.procUnitObj = procUnitObj
653 self.procUnitObj = procUnitObj
605
654
606 return procUnitObj
655 return procUnitObj
607
656
608 def run(self):
657 def run(self):
609
658
610 is_ok = False
659 is_ok = False
611
660
612 for opConfObj in self.opConfObjList:
661 for opConfObj in self.opConfObjList:
613
662
614 kwargs = {}
663 kwargs = {}
615 for parmConfObj in opConfObj.getParameterObjList():
664 for parmConfObj in opConfObj.getParameterObjList():
616 if opConfObj.name == 'run' and parmConfObj.name == 'datatype':
665 if opConfObj.name == 'run' and parmConfObj.name == 'datatype':
617 continue
666 continue
618
667
619 kwargs[parmConfObj.name] = parmConfObj.getValue()
668 kwargs[parmConfObj.name] = parmConfObj.getValue()
620
669
621 #ini = time.time()
670 #ini = time.time()
622
671
623 #print "\tRunning the '%s' operation with %s" %(opConfObj.name, opConfObj.id)
672 #print "\tRunning the '%s' operation with %s" %(opConfObj.name, opConfObj.id)
624 sts = self.procUnitObj.call(opType = opConfObj.type,
673 sts = self.procUnitObj.call(opType = opConfObj.type,
625 opName = opConfObj.name,
674 opName = opConfObj.name,
626 opId = opConfObj.id,
675 opId = opConfObj.id)
627 **kwargs)
628
676
629 # total_time = time.time() - ini
677 # total_time = time.time() - ini
630 #
678 #
631 # if total_time > 0.002:
679 # if total_time > 0.002:
632 # print "%s::%s took %f seconds" %(self.name, opConfObj.name, total_time)
680 # print "%s::%s took %f seconds" %(self.name, opConfObj.name, total_time)
633
681
634 is_ok = is_ok or sts
682 is_ok = is_ok or sts
635
683
636 return is_ok
684 return is_ok
637
685
638 def close(self):
686 def close(self):
639
687
640 for opConfObj in self.opConfObjList:
688 for opConfObj in self.opConfObjList:
641 if opConfObj.type == 'self':
689 if opConfObj.type == 'self':
642 continue
690 continue
643
691
644 opObj = self.procUnitObj.getOperationObj(opConfObj.id)
692 opObj = self.procUnitObj.getOperationObj(opConfObj.id)
645 opObj.close()
693 opObj.close()
646
694
647 self.procUnitObj.close()
695 self.procUnitObj.close()
648
696
649 return
697 return
650
698
651 class ReadUnitConf(ProcUnitConf):
699 class ReadUnitConf(ProcUnitConf):
652
700
653 path = None
701 path = None
654 startDate = None
702 startDate = None
655 endDate = None
703 endDate = None
656 startTime = None
704 startTime = None
657 endTime = None
705 endTime = None
658
706
659 ELEMENTNAME = 'ReadUnit'
707 ELEMENTNAME = 'ReadUnit'
660
708
661 def __init__(self):
709 def __init__(self):
662
710
663 self.id = None
711 self.id = None
664 self.datatype = None
712 self.datatype = None
665 self.name = None
713 self.name = None
666 self.inputId = None
714 self.inputId = None
667
715
668 self.parentId = None
716 self.parentId = None
669
717
670 self.opConfObjList = []
718 self.opConfObjList = []
671 self.opObjList = []
719 self.opObjList = []
672
720
673 def getElementName(self):
721 def getElementName(self):
674
722
675 return self.ELEMENTNAME
723 return self.ELEMENTNAME
676
677 def setup(self, id, name, datatype, path, startDate="", endDate="", startTime="", endTime="", parentId=None, **kwargs):
678
724
725 def setup(self, id, name, datatype, path='', startDate="", endDate="", startTime="",
726 endTime="", parentId=None, queue=None, server=None, **kwargs):
679 #Compatible with old signal chain version
727 #Compatible with old signal chain version
680 if datatype==None and name==None:
728 if datatype==None and name==None:
681 raise ValueError, "datatype or name should be defined"
729 raise ValueError, "datatype or name should be defined"
682
730
683 if name==None:
731 if name==None:
684 if 'Reader' in datatype:
732 if 'Reader' in datatype:
685 name = datatype
733 name = datatype
686 else:
734 else:
687 name = '%sReader' %(datatype)
735 name = '%sReader' %(datatype)
688
736
689 if datatype==None:
737 if datatype==None:
690 datatype = name.replace('Reader','')
738 datatype = name.replace('Reader','')
691
739
692 self.id = id
740 self.id = id
693 self.name = name
741 self.name = name
694 self.datatype = datatype
742 self.datatype = datatype
695
743
696 self.path = os.path.abspath(path)
744 self.path = os.path.abspath(path)
697 self.startDate = startDate
745 self.startDate = startDate
698 self.endDate = endDate
746 self.endDate = endDate
699 self.startTime = startTime
747 self.startTime = startTime
700 self.endTime = endTime
748 self.endTime = endTime
701
749
702 self.inputId = '0'
750 self.inputId = '0'
703 self.parentId = parentId
751 self.parentId = parentId
704
752
705 self.addRunOperation(**kwargs)
753 self.addRunOperation(**kwargs)
706
754
707 def update(self, datatype, path, startDate, endDate, startTime, endTime, parentId=None, name=None, **kwargs):
755 def update(self, datatype, path, startDate, endDate, startTime, endTime, parentId=None, name=None, **kwargs):
708
756
709 #Compatible with old signal chain version
757 #Compatible with old signal chain version
710 if datatype==None and name==None:
758 if datatype==None and name==None:
711 raise ValueError, "datatype or name should be defined"
759 raise ValueError, "datatype or name should be defined"
712
760
713 if name==None:
761 if name==None:
714 if 'Reader' in datatype:
762 if 'Reader' in datatype:
715 name = datatype
763 name = datatype
716 else:
764 else:
717 name = '%sReader' %(datatype)
765 name = '%sReader' %(datatype)
718
766
719 if datatype==None:
767 if datatype==None:
720 datatype = name.replace('Reader','')
768 datatype = name.replace('Reader','')
721
769
722 self.datatype = datatype
770 self.datatype = datatype
723 self.name = name
771 self.name = name
724 self.path = path
772 self.path = path
725 self.startDate = startDate
773 self.startDate = startDate
726 self.endDate = endDate
774 self.endDate = endDate
727 self.startTime = startTime
775 self.startTime = startTime
728 self.endTime = endTime
776 self.endTime = endTime
729
777
730 self.inputId = '0'
778 self.inputId = '0'
731 self.parentId = parentId
779 self.parentId = parentId
732
780
733 self.updateRunOperation(**kwargs)
781 self.updateRunOperation(**kwargs)
734
782
735 def removeOperations(self):
783 def removeOperations(self):
736
784
737 for obj in self.opConfObjList:
785 for obj in self.opConfObjList:
738 del obj
786 del obj
739
787
740 self.opConfObjList = []
788 self.opConfObjList = []
741
789
742 def addRunOperation(self, **kwargs):
790 def addRunOperation(self, **kwargs):
743
791
744 opObj = self.addOperation(name = 'run', optype = 'self')
792 opObj = self.addOperation(name = 'run', optype = 'self')
745
793
746 opObj.addParameter(name='datatype' , value=self.datatype, format='str')
794 opObj.addParameter(name='datatype' , value=self.datatype, format='str')
747 opObj.addParameter(name='path' , value=self.path, format='str')
795 opObj.addParameter(name='path' , value=self.path, format='str')
748 opObj.addParameter(name='startDate' , value=self.startDate, format='date')
796 opObj.addParameter(name='startDate' , value=self.startDate, format='date')
749 opObj.addParameter(name='endDate' , value=self.endDate, format='date')
797 opObj.addParameter(name='endDate' , value=self.endDate, format='date')
750 opObj.addParameter(name='startTime' , value=self.startTime, format='time')
798 opObj.addParameter(name='startTime' , value=self.startTime, format='time')
751 opObj.addParameter(name='endTime' , value=self.endTime, format='time')
799 opObj.addParameter(name='endTime' , value=self.endTime, format='time')
752
800
753 for key, value in kwargs.items():
801 for key, value in kwargs.items():
754 opObj.addParameter(name=key, value=value, format=type(value).__name__)
802 opObj.addParameter(name=key, value=value, format=type(value).__name__)
755
803
756 return opObj
804 return opObj
757
805
758 def updateRunOperation(self, **kwargs):
806 def updateRunOperation(self, **kwargs):
759
807
760 opObj = self.getOperationObj(name = 'run')
808 opObj = self.getOperationObj(name = 'run')
761 opObj.removeParameters()
809 opObj.removeParameters()
762
810
763 opObj.addParameter(name='datatype' , value=self.datatype, format='str')
811 opObj.addParameter(name='datatype' , value=self.datatype, format='str')
764 opObj.addParameter(name='path' , value=self.path, format='str')
812 opObj.addParameter(name='path' , value=self.path, format='str')
765 opObj.addParameter(name='startDate' , value=self.startDate, format='date')
813 opObj.addParameter(name='startDate' , value=self.startDate, format='date')
766 opObj.addParameter(name='endDate' , value=self.endDate, format='date')
814 opObj.addParameter(name='endDate' , value=self.endDate, format='date')
767 opObj.addParameter(name='startTime' , value=self.startTime, format='time')
815 opObj.addParameter(name='startTime' , value=self.startTime, format='time')
768 opObj.addParameter(name='endTime' , value=self.endTime, format='time')
816 opObj.addParameter(name='endTime' , value=self.endTime, format='time')
769
817
770 for key, value in kwargs.items():
818 for key, value in kwargs.items():
771 opObj.addParameter(name=key, value=value, format=type(value).__name__)
819 opObj.addParameter(name=key, value=value, format=type(value).__name__)
772
820
773 return opObj
821 return opObj
774
822
775 # def makeXml(self, projectElement):
823 # def makeXml(self, projectElement):
776 #
824 #
777 # procUnitElement = SubElement(projectElement, self.ELEMENTNAME)
825 # procUnitElement = SubElement(projectElement, self.ELEMENTNAME)
778 # procUnitElement.set('id', str(self.id))
826 # procUnitElement.set('id', str(self.id))
779 # procUnitElement.set('name', self.name)
827 # procUnitElement.set('name', self.name)
780 # procUnitElement.set('datatype', self.datatype)
828 # procUnitElement.set('datatype', self.datatype)
781 # procUnitElement.set('inputId', str(self.inputId))
829 # procUnitElement.set('inputId', str(self.inputId))
782 #
830 #
783 # for opConfObj in self.opConfObjList:
831 # for opConfObj in self.opConfObjList:
784 # opConfObj.makeXml(procUnitElement)
832 # opConfObj.makeXml(procUnitElement)
785
833
786 def readXml(self, upElement):
834 def readXml(self, upElement):
787
835
788 self.id = upElement.get('id')
836 self.id = upElement.get('id')
789 self.name = upElement.get('name')
837 self.name = upElement.get('name')
790 self.datatype = upElement.get('datatype')
838 self.datatype = upElement.get('datatype')
791 self.inputId = upElement.get('inputId')
839 self.inputId = upElement.get('inputId')
792
840
793 if self.ELEMENTNAME == "ReadUnit":
841 if self.ELEMENTNAME == "ReadUnit":
794 self.datatype = self.datatype.replace("Reader", "")
842 self.datatype = self.datatype.replace("Reader", "")
795
843
796 if self.inputId == 'None':
844 if self.inputId == 'None':
797 self.inputId = '0'
845 self.inputId = '0'
798
846
799 self.opConfObjList = []
847 self.opConfObjList = []
800
848
801 opElementList = upElement.iter(OperationConf().getElementName())
849 opElementList = upElement.iter(OperationConf().getElementName())
802
850
803 for opElement in opElementList:
851 for opElement in opElementList:
804 opConfObj = OperationConf()
852 opConfObj = OperationConf()
805 opConfObj.readXml(opElement)
853 opConfObj.readXml(opElement)
806 self.opConfObjList.append(opConfObj)
854 self.opConfObjList.append(opConfObj)
807
855
808 if opConfObj.name == 'run':
856 if opConfObj.name == 'run':
809 self.path = opConfObj.getParameterValue('path')
857 self.path = opConfObj.getParameterValue('path')
810 self.startDate = opConfObj.getParameterValue('startDate')
858 self.startDate = opConfObj.getParameterValue('startDate')
811 self.endDate = opConfObj.getParameterValue('endDate')
859 self.endDate = opConfObj.getParameterValue('endDate')
812 self.startTime = opConfObj.getParameterValue('startTime')
860 self.startTime = opConfObj.getParameterValue('startTime')
813 self.endTime = opConfObj.getParameterValue('endTime')
861 self.endTime = opConfObj.getParameterValue('endTime')
814
862
815 class Project():
863 class Project(Process):
816
817 id = None
864 id = None
818 name = None
865 name = None
819 description = None
866 description = None
820 filename = None
867 filename = None
821
868
822 procUnitConfObjDict = None
869 procUnitConfObjDict = None
823
870
824 ELEMENTNAME = 'Project'
871 ELEMENTNAME = 'Project'
825
872
826 plotterQueue = None
873 plotterQueue = None
827
874
828 def __init__(self, plotter_queue=None):
875 def __init__(self, plotter_queue=None, logfile=None):
829
876 Process.__init__(self)
830 self.id = None
877 self.id = None
831 self.name = None
878 self.name = None
832 self.description = None
879 self.description = None
833
880 if logfile is not None:
881 logToFile(logfile)
834 self.plotterQueue = plotter_queue
882 self.plotterQueue = plotter_queue
835
883
836 self.procUnitConfObjDict = {}
884 self.procUnitConfObjDict = {}
837
885
838 def __getNewId(self):
886 def __getNewId(self):
839
887
840 idList = self.procUnitConfObjDict.keys()
888 idList = self.procUnitConfObjDict.keys()
841
889
842 id = int(self.id)*10
890 id = int(self.id)*10
843
891
844 while True:
892 while True:
845 id += 1
893 id += 1
846
894
847 if str(id) in idList:
895 if str(id) in idList:
848 continue
896 continue
849
897
850 break
898 break
851
899
852 return str(id)
900 return str(id)
853
901
854 def getElementName(self):
902 def getElementName(self):
855
903
856 return self.ELEMENTNAME
904 return self.ELEMENTNAME
857
905
858 def getId(self):
906 def getId(self):
859
907
860 return self.id
908 return self.id
861
909
862 def updateId(self, new_id):
910 def updateId(self, new_id):
863
911
864 self.id = str(new_id)
912 self.id = str(new_id)
865
913
866 keyList = self.procUnitConfObjDict.keys()
914 keyList = self.procUnitConfObjDict.keys()
867 keyList.sort()
915 keyList.sort()
868
916
869 n = 1
917 n = 1
870 newProcUnitConfObjDict = {}
918 newProcUnitConfObjDict = {}
871
919
872 for procKey in keyList:
920 for procKey in keyList:
873
921
874 procUnitConfObj = self.procUnitConfObjDict[procKey]
922 procUnitConfObj = self.procUnitConfObjDict[procKey]
875 idProcUnit = str(int(self.id)*10 + n)
923 idProcUnit = str(int(self.id)*10 + n)
876 procUnitConfObj.updateId(idProcUnit, parentId = self.id)
924 procUnitConfObj.updateId(idProcUnit, parentId = self.id)
877
925
878 newProcUnitConfObjDict[idProcUnit] = procUnitConfObj
926 newProcUnitConfObjDict[idProcUnit] = procUnitConfObj
879 n += 1
927 n += 1
880
928
881 self.procUnitConfObjDict = newProcUnitConfObjDict
929 self.procUnitConfObjDict = newProcUnitConfObjDict
882
930
883 def setup(self, id, name, description):
931 def setup(self, id, name, description):
884
932
885 self.id = str(id)
933 self.id = str(id)
886 self.name = name
934 self.name = name
887 self.description = description
935 self.description = description
888
936
889 def update(self, name, description):
937 def update(self, name, description):
890
938
891 self.name = name
939 self.name = name
892 self.description = description
940 self.description = description
893
941
894 def addReadUnit(self, id=None, datatype=None, name=None, **kwargs):
942 def addReadUnit(self, id=None, datatype=None, name=None, **kwargs):
895
896 if id is None:
943 if id is None:
897 idReadUnit = self.__getNewId()
944 idReadUnit = self.__getNewId()
898 else:
945 else:
899 idReadUnit = str(id)
946 idReadUnit = str(id)
900
947
901 readUnitConfObj = ReadUnitConf()
948 readUnitConfObj = ReadUnitConf()
902 readUnitConfObj.setup(idReadUnit, name, datatype, parentId=self.id, **kwargs)
949 readUnitConfObj.setup(idReadUnit, name, datatype, parentId=self.id, **kwargs)
903
950
904 self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj
951 self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj
905
952
906 return readUnitConfObj
953 return readUnitConfObj
907
954
908 def addProcUnit(self, inputId='0', datatype=None, name=None):
955 def addProcUnit(self, inputId='0', datatype=None, name=None):
909
956
910 idProcUnit = self.__getNewId()
957 idProcUnit = self.__getNewId()
911
958
912 procUnitConfObj = ProcUnitConf()
959 procUnitConfObj = ProcUnitConf()
913 procUnitConfObj.setup(idProcUnit, name, datatype, inputId, parentId=self.id)
960 procUnitConfObj.setup(idProcUnit, name, datatype, inputId, parentId=self.id)
914
961
915 self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj
962 self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj
916
963
917 return procUnitConfObj
964 return procUnitConfObj
918
965
919 def removeProcUnit(self, id):
966 def removeProcUnit(self, id):
920
967
921 if id in self.procUnitConfObjDict.keys():
968 if id in self.procUnitConfObjDict.keys():
922 self.procUnitConfObjDict.pop(id)
969 self.procUnitConfObjDict.pop(id)
923
970
924 def getReadUnitId(self):
971 def getReadUnitId(self):
925
972
926 readUnitConfObj = self.getReadUnitObj()
973 readUnitConfObj = self.getReadUnitObj()
927
974
928 return readUnitConfObj.id
975 return readUnitConfObj.id
929
976
930 def getReadUnitObj(self):
977 def getReadUnitObj(self):
931
978
932 for obj in self.procUnitConfObjDict.values():
979 for obj in self.procUnitConfObjDict.values():
933 if obj.getElementName() == "ReadUnit":
980 if obj.getElementName() == "ReadUnit":
934 return obj
981 return obj
935
982
936 return None
983 return None
937
984
938 def getProcUnitObj(self, id=None, name=None):
985 def getProcUnitObj(self, id=None, name=None):
939
986
940 if id != None:
987 if id != None:
941 return self.procUnitConfObjDict[id]
988 return self.procUnitConfObjDict[id]
942
989
943 if name != None:
990 if name != None:
944 return self.getProcUnitObjByName(name)
991 return self.getProcUnitObjByName(name)
945
992
946 return None
993 return None
947
994
948 def getProcUnitObjByName(self, name):
995 def getProcUnitObjByName(self, name):
949
996
950 for obj in self.procUnitConfObjDict.values():
997 for obj in self.procUnitConfObjDict.values():
951 if obj.name == name:
998 if obj.name == name:
952 return obj
999 return obj
953
1000
954 return None
1001 return None
955
1002
956 def procUnitItems(self):
1003 def procUnitItems(self):
957
1004
958 return self.procUnitConfObjDict.items()
1005 return self.procUnitConfObjDict.items()
959
1006
960 def makeXml(self):
1007 def makeXml(self):
961
1008
962 projectElement = Element('Project')
1009 projectElement = Element('Project')
963 projectElement.set('id', str(self.id))
1010 projectElement.set('id', str(self.id))
964 projectElement.set('name', self.name)
1011 projectElement.set('name', self.name)
965 projectElement.set('description', self.description)
1012 projectElement.set('description', self.description)
966
1013
967 for procUnitConfObj in self.procUnitConfObjDict.values():
1014 for procUnitConfObj in self.procUnitConfObjDict.values():
968 procUnitConfObj.makeXml(projectElement)
1015 procUnitConfObj.makeXml(projectElement)
969
1016
970 self.projectElement = projectElement
1017 self.projectElement = projectElement
971
1018
972 def writeXml(self, filename=None):
1019 def writeXml(self, filename=None):
973
1020
974 if filename == None:
1021 if filename == None:
975 if self.filename:
1022 if self.filename:
976 filename = self.filename
1023 filename = self.filename
977 else:
1024 else:
978 filename = "schain.xml"
1025 filename = "schain.xml"
979
1026
980 if not filename:
1027 if not filename:
981 print "filename has not been defined. Use setFilename(filename) for do it."
1028 print "filename has not been defined. Use setFilename(filename) for do it."
982 return 0
1029 return 0
983
1030
984 abs_file = os.path.abspath(filename)
1031 abs_file = os.path.abspath(filename)
985
1032
986 if not os.access(os.path.dirname(abs_file), os.W_OK):
1033 if not os.access(os.path.dirname(abs_file), os.W_OK):
987 print "No write permission on %s" %os.path.dirname(abs_file)
1034 print "No write permission on %s" %os.path.dirname(abs_file)
988 return 0
1035 return 0
989
1036
990 if os.path.isfile(abs_file) and not(os.access(abs_file, os.W_OK)):
1037 if os.path.isfile(abs_file) and not(os.access(abs_file, os.W_OK)):
991 print "File %s already exists and it could not be overwriten" %abs_file
1038 print "File %s already exists and it could not be overwriten" %abs_file
992 return 0
1039 return 0
993
1040
994 self.makeXml()
1041 self.makeXml()
995
1042
996 ElementTree(self.projectElement).write(abs_file, method='xml')
1043 ElementTree(self.projectElement).write(abs_file, method='xml')
997
1044
998 self.filename = abs_file
1045 self.filename = abs_file
999
1046
1000 return 1
1047 return 1
1001
1048
1002 def readXml(self, filename = None):
1049 def readXml(self, filename = None):
1003
1050
1004 if not filename:
1051 if not filename:
1005 print "filename is not defined"
1052 print "filename is not defined"
1006 return 0
1053 return 0
1007
1054
1008 abs_file = os.path.abspath(filename)
1055 abs_file = os.path.abspath(filename)
1009
1056
1010 if not os.path.isfile(abs_file):
1057 if not os.path.isfile(abs_file):
1011 print "%s file does not exist" %abs_file
1058 print "%s file does not exist" %abs_file
1012 return 0
1059 return 0
1013
1060
1014 self.projectElement = None
1061 self.projectElement = None
1015 self.procUnitConfObjDict = {}
1062 self.procUnitConfObjDict = {}
1016
1063
1017 try:
1064 try:
1018 self.projectElement = ElementTree().parse(abs_file)
1065 self.projectElement = ElementTree().parse(abs_file)
1019 except:
1066 except:
1020 print "Error reading %s, verify file format" %filename
1067 print "Error reading %s, verify file format" %filename
1021 return 0
1068 return 0
1022
1069
1023 self.project = self.projectElement.tag
1070 self.project = self.projectElement.tag
1024
1071
1025 self.id = self.projectElement.get('id')
1072 self.id = self.projectElement.get('id')
1026 self.name = self.projectElement.get('name')
1073 self.name = self.projectElement.get('name')
1027 self.description = self.projectElement.get('description')
1074 self.description = self.projectElement.get('description')
1028
1075
1029 readUnitElementList = self.projectElement.iter(ReadUnitConf().getElementName())
1076 readUnitElementList = self.projectElement.iter(ReadUnitConf().getElementName())
1030
1077
1031 for readUnitElement in readUnitElementList:
1078 for readUnitElement in readUnitElementList:
1032 readUnitConfObj = ReadUnitConf()
1079 readUnitConfObj = ReadUnitConf()
1033 readUnitConfObj.readXml(readUnitElement)
1080 readUnitConfObj.readXml(readUnitElement)
1034
1081
1035 if readUnitConfObj.parentId == None:
1082 if readUnitConfObj.parentId == None:
1036 readUnitConfObj.parentId = self.id
1083 readUnitConfObj.parentId = self.id
1037
1084
1038 self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj
1085 self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj
1039
1086
1040 procUnitElementList = self.projectElement.iter(ProcUnitConf().getElementName())
1087 procUnitElementList = self.projectElement.iter(ProcUnitConf().getElementName())
1041
1088
1042 for procUnitElement in procUnitElementList:
1089 for procUnitElement in procUnitElementList:
1043 procUnitConfObj = ProcUnitConf()
1090 procUnitConfObj = ProcUnitConf()
1044 procUnitConfObj.readXml(procUnitElement)
1091 procUnitConfObj.readXml(procUnitElement)
1045
1092
1046 if procUnitConfObj.parentId == None:
1093 if procUnitConfObj.parentId == None:
1047 procUnitConfObj.parentId = self.id
1094 procUnitConfObj.parentId = self.id
1048
1095
1049 self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj
1096 self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj
1050
1097
1051 self.filename = abs_file
1098 self.filename = abs_file
1052
1099
1053 return 1
1100 return 1
1054
1101
1055 def printattr(self):
1102 def printattr(self):
1056
1103
1057 print "Project[%s]: name = %s, description = %s" %(self.id,
1104 print "Project[%s]: name = %s, description = %s" %(self.id,
1058 self.name,
1105 self.name,
1059 self.description)
1106 self.description)
1060
1107
1061 for procUnitConfObj in self.procUnitConfObjDict.values():
1108 for procUnitConfObj in self.procUnitConfObjDict.values():
1062 procUnitConfObj.printattr()
1109 procUnitConfObj.printattr()
1063
1110
1064 def createObjects(self):
1111 def createObjects(self):
1065
1112
1066 for procUnitConfObj in self.procUnitConfObjDict.values():
1113 for procUnitConfObj in self.procUnitConfObjDict.values():
1067 procUnitConfObj.createObjects(self.plotterQueue)
1114 procUnitConfObj.createObjects(self.plotterQueue)
1068
1115
1069 def __connect(self, objIN, thisObj):
1116 def __connect(self, objIN, thisObj):
1070
1117
1071 thisObj.setInput(objIN.getOutputObj())
1118 thisObj.setInput(objIN.getOutputObj())
1072
1119
1073 def connectObjects(self):
1120 def connectObjects(self):
1074
1121
1075 for thisPUConfObj in self.procUnitConfObjDict.values():
1122 for thisPUConfObj in self.procUnitConfObjDict.values():
1076
1123
1077 inputId = thisPUConfObj.getInputId()
1124 inputId = thisPUConfObj.getInputId()
1078
1125
1079 if int(inputId) == 0:
1126 if int(inputId) == 0:
1080 continue
1127 continue
1081
1128
1082 #Get input object
1129 #Get input object
1083 puConfINObj = self.procUnitConfObjDict[inputId]
1130 puConfINObj = self.procUnitConfObjDict[inputId]
1084 puObjIN = puConfINObj.getProcUnitObj()
1131 puObjIN = puConfINObj.getProcUnitObj()
1085
1132
1086 #Get current object
1133 #Get current object
1087 thisPUObj = thisPUConfObj.getProcUnitObj()
1134 thisPUObj = thisPUConfObj.getProcUnitObj()
1088
1135
1089 self.__connect(puObjIN, thisPUObj)
1136 self.__connect(puObjIN, thisPUObj)
1090
1137
1091 def __handleError(self, procUnitConfObj, send_email=True):
1138 def __handleError(self, procUnitConfObj, send_email=True):
1092
1139
1093 import socket
1140 import socket
1094
1141
1095 err = traceback.format_exception(sys.exc_info()[0],
1142 err = traceback.format_exception(sys.exc_info()[0],
1096 sys.exc_info()[1],
1143 sys.exc_info()[1],
1097 sys.exc_info()[2])
1144 sys.exc_info()[2])
1098
1145
1099 print "***** Error occurred in %s *****" %(procUnitConfObj.name)
1146 print "***** Error occurred in %s *****" %(procUnitConfObj.name)
1100 print "***** %s" %err[-1]
1147 print "***** %s" %err[-1]
1101
1148
1102 message = "".join(err)
1149 message = "".join(err)
1103
1150
1104 sys.stderr.write(message)
1151 sys.stderr.write(message)
1105
1152
1106 if not send_email:
1153 if not send_email:
1107 return
1154 return
1108
1155
1109 subject = "SChain v%s: Error running %s\n" %(schainpy.__version__, procUnitConfObj.name)
1156 subject = "SChain v%s: Error running %s\n" %(schainpy.__version__, procUnitConfObj.name)
1110
1157
1111 subtitle = "%s: %s\n" %(procUnitConfObj.getElementName() ,procUnitConfObj.name)
1158 subtitle = "%s: %s\n" %(procUnitConfObj.getElementName() ,procUnitConfObj.name)
1112 subtitle += "Hostname: %s\n" %socket.gethostbyname(socket.gethostname())
1159 subtitle += "Hostname: %s\n" %socket.gethostbyname(socket.gethostname())
1113 subtitle += "Working directory: %s\n" %os.path.abspath("./")
1160 subtitle += "Working directory: %s\n" %os.path.abspath("./")
1114 subtitle += "Configuration file: %s\n" %self.filename
1161 subtitle += "Configuration file: %s\n" %self.filename
1115 subtitle += "Time: %s\n" %str(datetime.datetime.now())
1162 subtitle += "Time: %s\n" %str(datetime.datetime.now())
1116
1163
1117 readUnitConfObj = self.getReadUnitObj()
1164 readUnitConfObj = self.getReadUnitObj()
1118 if readUnitConfObj:
1165 if readUnitConfObj:
1119 subtitle += "\nInput parameters:\n"
1166 subtitle += "\nInput parameters:\n"
1120 subtitle += "[Data path = %s]\n" %readUnitConfObj.path
1167 subtitle += "[Data path = %s]\n" %readUnitConfObj.path
1121 subtitle += "[Data type = %s]\n" %readUnitConfObj.datatype
1168 subtitle += "[Data type = %s]\n" %readUnitConfObj.datatype
1122 subtitle += "[Start date = %s]\n" %readUnitConfObj.startDate
1169 subtitle += "[Start date = %s]\n" %readUnitConfObj.startDate
1123 subtitle += "[End date = %s]\n" %readUnitConfObj.endDate
1170 subtitle += "[End date = %s]\n" %readUnitConfObj.endDate
1124 subtitle += "[Start time = %s]\n" %readUnitConfObj.startTime
1171 subtitle += "[Start time = %s]\n" %readUnitConfObj.startTime
1125 subtitle += "[End time = %s]\n" %readUnitConfObj.endTime
1172 subtitle += "[End time = %s]\n" %readUnitConfObj.endTime
1126
1173
1127 adminObj = schainpy.admin.SchainNotify()
1174 adminObj = schainpy.admin.SchainNotify()
1128 adminObj.sendAlert(message=message,
1175 adminObj.sendAlert(message=message,
1129 subject=subject,
1176 subject=subject,
1130 subtitle=subtitle,
1177 subtitle=subtitle,
1131 filename=self.filename)
1178 filename=self.filename)
1132
1179
1133 def isPaused(self):
1180 def isPaused(self):
1134 return 0
1181 return 0
1135
1182
1136 def isStopped(self):
1183 def isStopped(self):
1137 return 0
1184 return 0
1138
1185
1139 def runController(self):
1186 def runController(self):
1140 """
1187 """
1141 returns 0 when this process has been stopped, 1 otherwise
1188 returns 0 when this process has been stopped, 1 otherwise
1142 """
1189 """
1143
1190
1144 if self.isPaused():
1191 if self.isPaused():
1145 print "Process suspended"
1192 print "Process suspended"
1146
1193
1147 while True:
1194 while True:
1148 sleep(0.1)
1195 sleep(0.1)
1149
1196
1150 if not self.isPaused():
1197 if not self.isPaused():
1151 break
1198 break
1152
1199
1153 if self.isStopped():
1200 if self.isStopped():
1154 break
1201 break
1155
1202
1156 print "Process reinitialized"
1203 print "Process reinitialized"
1157
1204
1158 if self.isStopped():
1205 if self.isStopped():
1159 print "Process stopped"
1206 print "Process stopped"
1160 return 0
1207 return 0
1161
1208
1162 return 1
1209 return 1
1163
1210
1164 def setFilename(self, filename):
1211 def setFilename(self, filename):
1165
1212
1166 self.filename = filename
1213 self.filename = filename
1167
1214
1168 def setPlotterQueue(self, plotter_queue):
1215 def setPlotterQueue(self, plotter_queue):
1169
1216
1170 raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class"
1217 raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class"
1171
1218
1172 def getPlotterQueue(self):
1219 def getPlotterQueue(self):
1173
1220
1174 raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class"
1221 raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class"
1175
1222
1176 def useExternalPlotter(self):
1223 def useExternalPlotter(self):
1177
1224
1178 raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class"
1225 raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class"
1179
1226
1180 def run(self):
1227
1228 def run(self, filename=None):
1181
1229
1230 # self.writeXml(filename)
1231 self.createObjects()
1232 self.connectObjects()
1233
1182 print
1234 print
1183 print "*"*60
1235 print "*"*60
1184 print " Starting SIGNAL CHAIN PROCESSING v%s " %schainpy.__version__
1236 print " Starting SIGNAL CHAIN PROCESSING v%s " %schainpy.__version__
1185 print "*"*60
1237 print "*"*60
1186 print
1238 print
1187
1239
1188 keyList = self.procUnitConfObjDict.keys()
1240 keyList = self.procUnitConfObjDict.keys()
1189 keyList.sort()
1241 keyList.sort()
1190
1242
1191 while(True):
1243 while(True):
1192
1244
1193 is_ok = False
1245 is_ok = False
1194
1246
1195 for procKey in keyList:
1247 for procKey in keyList:
1196 # print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id)
1248 # print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id)
1197
1249
1198 procUnitConfObj = self.procUnitConfObjDict[procKey]
1250 procUnitConfObj = self.procUnitConfObjDict[procKey]
1199
1251
1200 try:
1252 try:
1201 sts = procUnitConfObj.run()
1253 sts = procUnitConfObj.run()
1202 is_ok = is_ok or sts
1254 is_ok = is_ok or sts
1203 except KeyboardInterrupt:
1255 except KeyboardInterrupt:
1204 is_ok = False
1256 is_ok = False
1205 break
1257 break
1206 except ValueError, e:
1258 except ValueError, e:
1207 sleep(0.5)
1259 sleep(0.5)
1208 self.__handleError(procUnitConfObj, send_email=True)
1260 self.__handleError(procUnitConfObj, send_email=True)
1209 is_ok = False
1261 is_ok = False
1210 break
1262 break
1211 except:
1263 except:
1212 sleep(0.5)
1264 sleep(0.5)
1213 self.__handleError(procUnitConfObj)
1265 self.__handleError(procUnitConfObj)
1214 is_ok = False
1266 is_ok = False
1215 break
1267 break
1216
1268
1217 #If every process unit finished so end process
1269 #If every process unit finished so end process
1218 if not(is_ok):
1270 if not(is_ok):
1219 # print "Every process unit have finished"
1271 # print "Every process unit have finished"
1220 break
1272 break
1221
1273
1222 if not self.runController():
1274 if not self.runController():
1223 break
1275 break
1224
1276
1225 #Closing every process
1277 #Closing every process
1226 for procKey in keyList:
1278 for procKey in keyList:
1227 procUnitConfObj = self.procUnitConfObjDict[procKey]
1279 procUnitConfObj = self.procUnitConfObjDict[procKey]
1228 procUnitConfObj.close()
1280 procUnitConfObj.close()
1229
1230 print "Process finished"
1231
1232 def start(self):
1233
1234 self.writeXml()
1235
1236 self.createObjects()
1237 self.connectObjects()
1238 self.run()
1239
1240 if __name__ == '__main__':
1241
1242 desc = "Segundo Test"
1243 filename = "schain.xml"
1244
1245 controllerObj = Project()
1246
1247 controllerObj.setup(id = '191', name='test01', description=desc)
1248
1249 readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage',
1250 path='data/rawdata/',
1251 startDate='2011/01/01',
1252 endDate='2012/12/31',
1253 startTime='00:00:00',
1254 endTime='23:59:59',
1255 online=1,
1256 walk=1)
1257
1258 procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId())
1259
1260 opObj10 = procUnitConfObj0.addOperation(name='selectChannels')
1261 opObj10.addParameter(name='channelList', value='3,4,5', format='intlist')
1262
1263 opObj10 = procUnitConfObj0.addOperation(name='selectHeights')
1264 opObj10.addParameter(name='minHei', value='90', format='float')
1265 opObj10.addParameter(name='maxHei', value='180', format='float')
1266
1267 opObj12 = procUnitConfObj0.addOperation(name='CohInt', optype='external')
1268 opObj12.addParameter(name='n', value='10', format='int')
1269
1270 procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId())
1271 procUnitConfObj1.addParameter(name='nFFTPoints', value='32', format='int')
1272 # procUnitConfObj1.addParameter(name='pairList', value='(0,1),(0,2),(1,2)', format='')
1273
1274
1275 opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='external')
1276 opObj11.addParameter(name='idfigure', value='1', format='int')
1277 opObj11.addParameter(name='wintitle', value='SpectraPlot0', format='str')
1278 opObj11.addParameter(name='zmin', value='40', format='int')
1279 opObj11.addParameter(name='zmax', value='90', format='int')
1280 opObj11.addParameter(name='showprofile', value='1', format='int')
1281
1282 print "Escribiendo el archivo XML"
1283
1284 controllerObj.writeXml(filename)
1285
1286 print "Leyendo el archivo XML"
1287 controllerObj.readXml(filename)
1288 #controllerObj.printattr()
1289
1290 controllerObj.createObjects()
1291 controllerObj.connectObjects()
1292 controllerObj.run()
1293
1294 No newline at end of file
@@ -1,12 +1,12
1 #from schainpy.model.data.jrodata import *
1 #from schainpy.model.data.jrodata import *
2 # from schainpy.model.io.jrodataIO import *
2 # from schainpy.model.io.jrodataIO import *
3 # from schainpy.model.proc.jroprocessing import *
3 # from schainpy.model.proc.jroprocessing import *
4 # from schainpy.model.graphics.jroplot import *
4 # from schainpy.model.graphics.jroplot import *
5 # from schainpy.model.utils.jroutils import *
5 # from schainpy.model.utils.jroutils import *
6 # from schainpy.serializer import *
6 # from schainpy.serializer import *
7
7
8 from data import *
8 from data import *
9 from io import *
9 from io import *
10 from proc import *
10 from proc import *
11 from graphics import *
11 from graphics import *
12 from utils import *
12 from utils import * No newline at end of file
@@ -1,876 +1,876
1 '''
1 '''
2
2
3 $Author: murco $
3 $Author: murco $
4 $Id: JROHeaderIO.py 151 2012-10-31 19:00:51Z murco $
4 $Id: JROHeaderIO.py 151 2012-10-31 19:00:51Z murco $
5 '''
5 '''
6 import sys
6 import sys
7 import numpy
7 import numpy
8 import copy
8 import copy
9 import datetime
9 import datetime
10 import inspect
10 import inspect
11
11
12 SPEED_OF_LIGHT = 299792458
12 SPEED_OF_LIGHT = 299792458
13 SPEED_OF_LIGHT = 3e8
13 SPEED_OF_LIGHT = 3e8
14
14
15 BASIC_STRUCTURE = numpy.dtype([
15 BASIC_STRUCTURE = numpy.dtype([
16 ('nSize','<u4'),
16 ('nSize','<u4'),
17 ('nVersion','<u2'),
17 ('nVersion','<u2'),
18 ('nDataBlockId','<u4'),
18 ('nDataBlockId','<u4'),
19 ('nUtime','<u4'),
19 ('nUtime','<u4'),
20 ('nMilsec','<u2'),
20 ('nMilsec','<u2'),
21 ('nTimezone','<i2'),
21 ('nTimezone','<i2'),
22 ('nDstflag','<i2'),
22 ('nDstflag','<i2'),
23 ('nErrorCount','<u4')
23 ('nErrorCount','<u4')
24 ])
24 ])
25
25
26 SYSTEM_STRUCTURE = numpy.dtype([
26 SYSTEM_STRUCTURE = numpy.dtype([
27 ('nSize','<u4'),
27 ('nSize','<u4'),
28 ('nNumSamples','<u4'),
28 ('nNumSamples','<u4'),
29 ('nNumProfiles','<u4'),
29 ('nNumProfiles','<u4'),
30 ('nNumChannels','<u4'),
30 ('nNumChannels','<u4'),
31 ('nADCResolution','<u4'),
31 ('nADCResolution','<u4'),
32 ('nPCDIOBusWidth','<u4'),
32 ('nPCDIOBusWidth','<u4'),
33 ])
33 ])
34
34
35 RADAR_STRUCTURE = numpy.dtype([
35 RADAR_STRUCTURE = numpy.dtype([
36 ('nSize','<u4'),
36 ('nSize','<u4'),
37 ('nExpType','<u4'),
37 ('nExpType','<u4'),
38 ('nNTx','<u4'),
38 ('nNTx','<u4'),
39 ('fIpp','<f4'),
39 ('fIpp','<f4'),
40 ('fTxA','<f4'),
40 ('fTxA','<f4'),
41 ('fTxB','<f4'),
41 ('fTxB','<f4'),
42 ('nNumWindows','<u4'),
42 ('nNumWindows','<u4'),
43 ('nNumTaus','<u4'),
43 ('nNumTaus','<u4'),
44 ('nCodeType','<u4'),
44 ('nCodeType','<u4'),
45 ('nLine6Function','<u4'),
45 ('nLine6Function','<u4'),
46 ('nLine5Function','<u4'),
46 ('nLine5Function','<u4'),
47 ('fClock','<f4'),
47 ('fClock','<f4'),
48 ('nPrePulseBefore','<u4'),
48 ('nPrePulseBefore','<u4'),
49 ('nPrePulseAfter','<u4'),
49 ('nPrePulseAfter','<u4'),
50 ('sRangeIPP','<a20'),
50 ('sRangeIPP','<a20'),
51 ('sRangeTxA','<a20'),
51 ('sRangeTxA','<a20'),
52 ('sRangeTxB','<a20'),
52 ('sRangeTxB','<a20'),
53 ])
53 ])
54
54
55 SAMPLING_STRUCTURE = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
55 SAMPLING_STRUCTURE = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
56
56
57
57
58 PROCESSING_STRUCTURE = numpy.dtype([
58 PROCESSING_STRUCTURE = numpy.dtype([
59 ('nSize','<u4'),
59 ('nSize','<u4'),
60 ('nDataType','<u4'),
60 ('nDataType','<u4'),
61 ('nSizeOfDataBlock','<u4'),
61 ('nSizeOfDataBlock','<u4'),
62 ('nProfilesperBlock','<u4'),
62 ('nProfilesperBlock','<u4'),
63 ('nDataBlocksperFile','<u4'),
63 ('nDataBlocksperFile','<u4'),
64 ('nNumWindows','<u4'),
64 ('nNumWindows','<u4'),
65 ('nProcessFlags','<u4'),
65 ('nProcessFlags','<u4'),
66 ('nCoherentIntegrations','<u4'),
66 ('nCoherentIntegrations','<u4'),
67 ('nIncoherentIntegrations','<u4'),
67 ('nIncoherentIntegrations','<u4'),
68 ('nTotalSpectra','<u4')
68 ('nTotalSpectra','<u4')
69 ])
69 ])
70
70
71 class Header(object):
71 class Header(object):
72
72
73 def __init__(self):
73 def __init__(self):
74 raise NotImplementedError
74 raise NotImplementedError
75
75
76 def copy(self):
76 def copy(self):
77 return copy.deepcopy(self)
77 return copy.deepcopy(self)
78
78
79 def read(self):
79 def read(self):
80
80
81 raise NotImplementedError
81 raise NotImplementedError
82
82
83 def write(self):
83 def write(self):
84
84
85 raise NotImplementedError
85 raise NotImplementedError
86
86
87 def getAllowedArgs(self):
87 def getAllowedArgs(self):
88 args = inspect.getargspec(self.__init__).args
88 args = inspect.getargspec(self.__init__).args
89 try:
89 try:
90 args.remove('self')
90 args.remove('self')
91 except:
91 except:
92 pass
92 pass
93 return args
93 return args
94
94
95 def getAsDict(self):
95 def getAsDict(self):
96 args = self.getAllowedArgs()
96 args = self.getAllowedArgs()
97 asDict = {}
97 asDict = {}
98 for x in args:
98 for x in args:
99 asDict[x] = self[x]
99 asDict[x] = self[x]
100 return asDict
100 return asDict
101
101
102 def __getitem__(self, name):
102 def __getitem__(self, name):
103 return getattr(self, name)
103 return getattr(self, name)
104
104
105 def printInfo(self):
105 def printInfo(self):
106
106
107 message = "#"*50 + "\n"
107 message = "#"*50 + "\n"
108 message += self.__class__.__name__.upper() + "\n"
108 message += self.__class__.__name__.upper() + "\n"
109 message += "#"*50 + "\n"
109 message += "#"*50 + "\n"
110
110
111 keyList = self.__dict__.keys()
111 keyList = self.__dict__.keys()
112 keyList.sort()
112 keyList.sort()
113
113
114 for key in keyList:
114 for key in keyList:
115 message += "%s = %s" %(key, self.__dict__[key]) + "\n"
115 message += "%s = %s" %(key, self.__dict__[key]) + "\n"
116
116
117 if "size" not in keyList:
117 if "size" not in keyList:
118 attr = getattr(self, "size")
118 attr = getattr(self, "size")
119
119
120 if attr:
120 if attr:
121 message += "%s = %s" %("size", attr) + "\n"
121 message += "%s = %s" %("size", attr) + "\n"
122
122
123 print message
123 print message
124
124
125 class BasicHeader(Header):
125 class BasicHeader(Header):
126
126
127 size = None
127 size = None
128 version = None
128 version = None
129 dataBlock = None
129 dataBlock = None
130 utc = None
130 utc = None
131 ltc = None
131 ltc = None
132 miliSecond = None
132 miliSecond = None
133 timeZone = None
133 timeZone = None
134 dstFlag = None
134 dstFlag = None
135 errorCount = None
135 errorCount = None
136 datatime = None
136 datatime = None
137 structure = BASIC_STRUCTURE
137 structure = BASIC_STRUCTURE
138 __LOCALTIME = None
138 __LOCALTIME = None
139
139
140 def __init__(self, useLocalTime=True):
140 def __init__(self, useLocalTime=True):
141
141
142 self.size = 24
142 self.size = 24
143 self.version = 0
143 self.version = 0
144 self.dataBlock = 0
144 self.dataBlock = 0
145 self.utc = 0
145 self.utc = 0
146 self.miliSecond = 0
146 self.miliSecond = 0
147 self.timeZone = 0
147 self.timeZone = 0
148 self.dstFlag = 0
148 self.dstFlag = 0
149 self.errorCount = 0
149 self.errorCount = 0
150
150
151 self.useLocalTime = useLocalTime
151 self.useLocalTime = useLocalTime
152
152
153 def read(self, fp):
153 def read(self, fp):
154
154
155 self.length = 0
155 self.length = 0
156 try:
156 try:
157 if hasattr(fp, 'read'):
157 if hasattr(fp, 'read'):
158 header = numpy.fromfile(fp, BASIC_STRUCTURE,1)
158 header = numpy.fromfile(fp, BASIC_STRUCTURE,1)
159 else:
159 else:
160 header = numpy.fromstring(fp, BASIC_STRUCTURE,1)
160 header = numpy.fromstring(fp, BASIC_STRUCTURE,1)
161 except Exception, e:
161 except Exception, e:
162 print "BasicHeader: "
162 print "BasicHeader: "
163 print e
163 print e
164 return 0
164 return 0
165
165
166 self.size = int(header['nSize'][0])
166 self.size = int(header['nSize'][0])
167 self.version = int(header['nVersion'][0])
167 self.version = int(header['nVersion'][0])
168 self.dataBlock = int(header['nDataBlockId'][0])
168 self.dataBlock = int(header['nDataBlockId'][0])
169 self.utc = int(header['nUtime'][0])
169 self.utc = int(header['nUtime'][0])
170 self.miliSecond = int(header['nMilsec'][0])
170 self.miliSecond = int(header['nMilsec'][0])
171 self.timeZone = int(header['nTimezone'][0])
171 self.timeZone = int(header['nTimezone'][0])
172 self.dstFlag = int(header['nDstflag'][0])
172 self.dstFlag = int(header['nDstflag'][0])
173 self.errorCount = int(header['nErrorCount'][0])
173 self.errorCount = int(header['nErrorCount'][0])
174
174
175 if self.size < 24:
175 if self.size < 24:
176 return 0
176 return 0
177
177
178 self.length = header.nbytes
178 self.length = header.nbytes
179 return 1
179 return 1
180
180
181 def write(self, fp):
181 def write(self, fp):
182
182
183 headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount)
183 headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount)
184 header = numpy.array(headerTuple, BASIC_STRUCTURE)
184 header = numpy.array(headerTuple, BASIC_STRUCTURE)
185 header.tofile(fp)
185 header.tofile(fp)
186
186
187 return 1
187 return 1
188
188
189 def get_ltc(self):
189 def get_ltc(self):
190
190
191 return self.utc - self.timeZone*60
191 return self.utc - self.timeZone*60
192
192
193 def set_ltc(self, value):
193 def set_ltc(self, value):
194
194
195 self.utc = value + self.timeZone*60
195 self.utc = value + self.timeZone*60
196
196
197 def get_datatime(self):
197 def get_datatime(self):
198
198
199 return datetime.datetime.utcfromtimestamp(self.ltc)
199 return datetime.datetime.utcfromtimestamp(self.ltc)
200
200
201 ltc = property(get_ltc, set_ltc)
201 ltc = property(get_ltc, set_ltc)
202 datatime = property(get_datatime)
202 datatime = property(get_datatime)
203
203
204 class SystemHeader(Header):
204 class SystemHeader(Header):
205
205
206 size = None
206 size = None
207 nSamples = None
207 nSamples = None
208 nProfiles = None
208 nProfiles = None
209 nChannels = None
209 nChannels = None
210 adcResolution = None
210 adcResolution = None
211 pciDioBusWidth = None
211 pciDioBusWidth = None
212 structure = SYSTEM_STRUCTURE
212 structure = SYSTEM_STRUCTURE
213
213
214 def __init__(self, nSamples=0, nProfiles=0, nChannels=0, adcResolution=14, pciDioBusWidth=0):
214 def __init__(self, nSamples=0, nProfiles=0, nChannels=0, adcResolution=14, pciDioBusWidth=0):
215
215
216 self.size = 24
216 self.size = 24
217 self.nSamples = nSamples
217 self.nSamples = nSamples
218 self.nProfiles = nProfiles
218 self.nProfiles = nProfiles
219 self.nChannels = nChannels
219 self.nChannels = nChannels
220 self.adcResolution = adcResolution
220 self.adcResolution = adcResolution
221 self.pciDioBusWidth = pciDioBusWidth
221 self.pciDioBusWidth = pciDioBusWidth
222
222
223 def read(self, fp):
223 def read(self, fp):
224 self.length = 0
224 self.length = 0
225 try:
225 try:
226 startFp = fp.tell()
226 startFp = fp.tell()
227 except Exception, e:
227 except Exception, e:
228 startFp = None
228 startFp = None
229 pass
229 pass
230
230
231 try:
231 try:
232 if hasattr(fp, 'read'):
232 if hasattr(fp, 'read'):
233 header = numpy.fromfile(fp, SYSTEM_STRUCTURE,1)
233 header = numpy.fromfile(fp, SYSTEM_STRUCTURE,1)
234 else:
234 else:
235 header = numpy.fromstring(fp, SYSTEM_STRUCTURE,1)
235 header = numpy.fromstring(fp, SYSTEM_STRUCTURE,1)
236 except Exception, e:
236 except Exception, e:
237 print "System Header: " + str(e)
237 print "System Header: " + str(e)
238 return 0
238 return 0
239
239
240 self.size = header['nSize'][0]
240 self.size = header['nSize'][0]
241 self.nSamples = header['nNumSamples'][0]
241 self.nSamples = header['nNumSamples'][0]
242 self.nProfiles = header['nNumProfiles'][0]
242 self.nProfiles = header['nNumProfiles'][0]
243 self.nChannels = header['nNumChannels'][0]
243 self.nChannels = header['nNumChannels'][0]
244 self.adcResolution = header['nADCResolution'][0]
244 self.adcResolution = header['nADCResolution'][0]
245 self.pciDioBusWidth = header['nPCDIOBusWidth'][0]
245 self.pciDioBusWidth = header['nPCDIOBusWidth'][0]
246
246
247
247
248 if startFp is not None:
248 if startFp is not None:
249 endFp = self.size + startFp
249 endFp = self.size + startFp
250
250
251 if fp.tell() > endFp:
251 if fp.tell() > endFp:
252 sys.stderr.write("Warning %s: Size value read from System Header is lower than it has to be\n" %fp.name)
252 sys.stderr.write("Warning %s: Size value read from System Header is lower than it has to be\n" %fp.name)
253 return 0
253 return 0
254
254
255 if fp.tell() < endFp:
255 if fp.tell() < endFp:
256 sys.stderr.write("Warning %s: Size value read from System Header size is greater than it has to be\n" %fp.name)
256 sys.stderr.write("Warning %s: Size value read from System Header size is greater than it has to be\n" %fp.name)
257 return 0
257 return 0
258
258
259 self.length = header.nbytes
259 self.length = header.nbytes
260 return 1
260 return 1
261
261
262 def write(self, fp):
262 def write(self, fp):
263
263
264 headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth)
264 headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth)
265 header = numpy.array(headerTuple,SYSTEM_STRUCTURE)
265 header = numpy.array(headerTuple,SYSTEM_STRUCTURE)
266 header.tofile(fp)
266 header.tofile(fp)
267
267
268 return 1
268 return 1
269
269
270 class RadarControllerHeader(Header):
270 class RadarControllerHeader(Header):
271
271
272 expType = None
272 expType = None
273 nTx = None
273 nTx = None
274 ipp = None
274 ipp = None
275 txA = None
275 txA = None
276 txB = None
276 txB = None
277 nWindows = None
277 nWindows = None
278 numTaus = None
278 numTaus = None
279 codeType = None
279 codeType = None
280 line6Function = None
280 line6Function = None
281 line5Function = None
281 line5Function = None
282 fClock = None
282 fClock = None
283 prePulseBefore = None
283 prePulseBefore = None
284 prePulseAfter = None
284 prePulseAfter = None
285 rangeIpp = None
285 rangeIpp = None
286 rangeTxA = None
286 rangeTxA = None
287 rangeTxB = None
287 rangeTxB = None
288 structure = RADAR_STRUCTURE
288 structure = RADAR_STRUCTURE
289 __size = None
289 __size = None
290
290
291 def __init__(self, expType=2, nTx=1,
291 def __init__(self, expType=2, nTx=1,
292 ipp=None, txA=0, txB=0,
292 ipp=None, txA=0, txB=0,
293 nWindows=None, nHeights=None, firstHeight=None, deltaHeight=None,
293 nWindows=None, nHeights=None, firstHeight=None, deltaHeight=None,
294 numTaus=0, line6Function=0, line5Function=0, fClock=None,
294 numTaus=0, line6Function=0, line5Function=0, fClock=None,
295 prePulseBefore=0, prePulseAfter=0,
295 prePulseBefore=0, prePulseAfter=0,
296 codeType=0, nCode=0, nBaud=0, code=None,
296 codeType=0, nCode=0, nBaud=0, code=None,
297 flip1=0, flip2=0):
297 flip1=0, flip2=0):
298
298
299 # self.size = 116
299 # self.size = 116
300 self.expType = expType
300 self.expType = expType
301 self.nTx = nTx
301 self.nTx = nTx
302 self.ipp = ipp
302 self.ipp = ipp
303 self.txA = txA
303 self.txA = txA
304 self.txB = txB
304 self.txB = txB
305 self.rangeIpp = ipp
305 self.rangeIpp = ipp
306 self.rangeTxA = txA
306 self.rangeTxA = txA
307 self.rangeTxB = txB
307 self.rangeTxB = txB
308
308
309 self.nWindows = nWindows
309 self.nWindows = nWindows
310 self.numTaus = numTaus
310 self.numTaus = numTaus
311 self.codeType = codeType
311 self.codeType = codeType
312 self.line6Function = line6Function
312 self.line6Function = line6Function
313 self.line5Function = line5Function
313 self.line5Function = line5Function
314 self.fClock = fClock
314 self.fClock = fClock
315 self.prePulseBefore = prePulseBefore
315 self.prePulseBefore = prePulseBefore
316 self.prePulseAfter = prePulseAfter
316 self.prePulseAfter = prePulseAfter
317
317
318 self.nHeights = nHeights
318 self.nHeights = nHeights
319 self.firstHeight = firstHeight
319 self.firstHeight = firstHeight
320 self.deltaHeight = deltaHeight
320 self.deltaHeight = deltaHeight
321 self.samplesWin = nHeights
321 self.samplesWin = nHeights
322
322
323 self.nCode = nCode
323 self.nCode = nCode
324 self.nBaud = nBaud
324 self.nBaud = nBaud
325 self.code = code
325 self.code = code
326 self.flip1 = flip1
326 self.flip1 = flip1
327 self.flip2 = flip2
327 self.flip2 = flip2
328
328
329 self.code_size = int(numpy.ceil(self.nBaud/32.))*self.nCode*4
329 self.code_size = int(numpy.ceil(self.nBaud/32.))*self.nCode*4
330 # self.dynamic = numpy.array([],numpy.dtype('byte'))
330 # self.dynamic = numpy.array([],numpy.dtype('byte'))
331
331
332 if self.fClock is None and self.deltaHeight is not None:
332 if self.fClock is None and self.deltaHeight is not None:
333 self.fClock = 0.15/(deltaHeight*1e-6) #0.15Km / (height * 1u)
333 self.fClock = 0.15/(deltaHeight*1e-6) #0.15Km / (height * 1u)
334
334
335 def read(self, fp):
335 def read(self, fp):
336 self.length = 0
336 self.length = 0
337 try:
337 try:
338 startFp = fp.tell()
338 startFp = fp.tell()
339 except Exception, e:
339 except Exception, e:
340 startFp = None
340 startFp = None
341 pass
341 pass
342
342
343 try:
343 try:
344 if hasattr(fp, 'read'):
344 if hasattr(fp, 'read'):
345 header = numpy.fromfile(fp, RADAR_STRUCTURE,1)
345 header = numpy.fromfile(fp, RADAR_STRUCTURE,1)
346 else:
346 else:
347 header = numpy.fromstring(fp, RADAR_STRUCTURE,1)
347 header = numpy.fromstring(fp, RADAR_STRUCTURE,1)
348 self.length += header.nbytes
348 self.length += header.nbytes
349 except Exception, e:
349 except Exception, e:
350 print "RadarControllerHeader: " + str(e)
350 print "RadarControllerHeader: " + str(e)
351 return 0
351 return 0
352
352
353 size = int(header['nSize'][0])
353 size = int(header['nSize'][0])
354 self.expType = int(header['nExpType'][0])
354 self.expType = int(header['nExpType'][0])
355 self.nTx = int(header['nNTx'][0])
355 self.nTx = int(header['nNTx'][0])
356 self.ipp = float(header['fIpp'][0])
356 self.ipp = float(header['fIpp'][0])
357 self.txA = float(header['fTxA'][0])
357 self.txA = float(header['fTxA'][0])
358 self.txB = float(header['fTxB'][0])
358 self.txB = float(header['fTxB'][0])
359 self.nWindows = int(header['nNumWindows'][0])
359 self.nWindows = int(header['nNumWindows'][0])
360 self.numTaus = int(header['nNumTaus'][0])
360 self.numTaus = int(header['nNumTaus'][0])
361 self.codeType = int(header['nCodeType'][0])
361 self.codeType = int(header['nCodeType'][0])
362 self.line6Function = int(header['nLine6Function'][0])
362 self.line6Function = int(header['nLine6Function'][0])
363 self.line5Function = int(header['nLine5Function'][0])
363 self.line5Function = int(header['nLine5Function'][0])
364 self.fClock = float(header['fClock'][0])
364 self.fClock = float(header['fClock'][0])
365 self.prePulseBefore = int(header['nPrePulseBefore'][0])
365 self.prePulseBefore = int(header['nPrePulseBefore'][0])
366 self.prePulseAfter = int(header['nPrePulseAfter'][0])
366 self.prePulseAfter = int(header['nPrePulseAfter'][0])
367 self.rangeIpp = header['sRangeIPP'][0]
367 self.rangeIpp = header['sRangeIPP'][0]
368 self.rangeTxA = header['sRangeTxA'][0]
368 self.rangeTxA = header['sRangeTxA'][0]
369 self.rangeTxB = header['sRangeTxB'][0]
369 self.rangeTxB = header['sRangeTxB'][0]
370
370
371 try:
371 try:
372 if hasattr(fp, 'read'):
372 if hasattr(fp, 'read'):
373 samplingWindow = numpy.fromfile(fp, SAMPLING_STRUCTURE, self.nWindows)
373 samplingWindow = numpy.fromfile(fp, SAMPLING_STRUCTURE, self.nWindows)
374 else:
374 else:
375 samplingWindow = numpy.fromstring(fp[self.length:], SAMPLING_STRUCTURE, self.nWindows)
375 samplingWindow = numpy.fromstring(fp[self.length:], SAMPLING_STRUCTURE, self.nWindows)
376 self.length += samplingWindow.nbytes
376 self.length += samplingWindow.nbytes
377 except Exception, e:
377 except Exception, e:
378 print "RadarControllerHeader: " + str(e)
378 print "RadarControllerHeader: " + str(e)
379 return 0
379 return 0
380 self.nHeights = int(numpy.sum(samplingWindow['nsa']))
380 self.nHeights = int(numpy.sum(samplingWindow['nsa']))
381 self.firstHeight = samplingWindow['h0']
381 self.firstHeight = samplingWindow['h0']
382 self.deltaHeight = samplingWindow['dh']
382 self.deltaHeight = samplingWindow['dh']
383 self.samplesWin = samplingWindow['nsa']
383 self.samplesWin = samplingWindow['nsa']
384
384
385
385
386
386
387 try:
387 try:
388 if hasattr(fp, 'read'):
388 if hasattr(fp, 'read'):
389 self.Taus = numpy.fromfile(fp, '<f4', self.numTaus)
389 self.Taus = numpy.fromfile(fp, '<f4', self.numTaus)
390 else:
390 else:
391 self.Taus = numpy.fromstring(fp[self.length:], '<f4', self.numTaus)
391 self.Taus = numpy.fromstring(fp[self.length:], '<f4', self.numTaus)
392 self.length += self.Taus.nbytes
392 self.length += self.Taus.nbytes
393 except Exception, e:
393 except Exception, e:
394 print "RadarControllerHeader: " + str(e)
394 print "RadarControllerHeader: " + str(e)
395 return 0
395 return 0
396
396
397
397
398
398
399 self.code_size = 0
399 self.code_size = 0
400 if self.codeType != 0:
400 if self.codeType != 0:
401
401
402 try:
402 try:
403 if hasattr(fp, 'read'):
403 if hasattr(fp, 'read'):
404 self.nCode = numpy.fromfile(fp, '<u4', 1)
404 self.nCode = numpy.fromfile(fp, '<u4', 1)[0]
405 self.length += self.nCode.nbytes
405 self.length += self.nCode.nbytes
406 self.nBaud = numpy.fromfile(fp, '<u4', 1)
406 self.nBaud = numpy.fromfile(fp, '<u4', 1)[0]
407 self.length += self.nBaud.nbytes
407 self.length += self.nBaud.nbytes
408 else:
408 else:
409 self.nCode = numpy.fromstring(fp[self.length:], '<u4', 1)[0]
409 self.nCode = numpy.fromstring(fp[self.length:], '<u4', 1)[0]
410 self.length += self.nCode.nbytes
410 self.length += self.nCode.nbytes
411 self.nBaud = numpy.fromstring(fp[self.length:], '<u4', 1)[0]
411 self.nBaud = numpy.fromstring(fp[self.length:], '<u4', 1)[0]
412 self.length += self.nBaud.nbytes
412 self.length += self.nBaud.nbytes
413 except Exception, e:
413 except Exception, e:
414 print "RadarControllerHeader: " + str(e)
414 print "RadarControllerHeader: " + str(e)
415 return 0
415 return 0
416 code = numpy.empty([self.nCode,self.nBaud],dtype='i1')
416 code = numpy.empty([self.nCode,self.nBaud],dtype='i1')
417
417
418 for ic in range(self.nCode):
418 for ic in range(self.nCode):
419 try:
419 try:
420 if hasattr(fp, 'read'):
420 if hasattr(fp, 'read'):
421 temp = numpy.fromfile(fp,'u4', int(numpy.ceil(self.nBaud/32.)))
421 temp = numpy.fromfile(fp,'u4', int(numpy.ceil(self.nBaud/32.)))
422 else:
422 else:
423 temp = numpy.fromstring(fp,'u4', int(numpy.ceil(self.nBaud/32.)))
423 temp = numpy.fromstring(fp,'u4', int(numpy.ceil(self.nBaud/32.)))
424 self.length += temp.nbytes
424 self.length += temp.nbytes
425 except Exception, e:
425 except Exception, e:
426 print "RadarControllerHeader: " + str(e)
426 print "RadarControllerHeader: " + str(e)
427 return 0
427 return 0
428
428
429 for ib in range(self.nBaud-1,-1,-1):
429 for ib in range(self.nBaud-1,-1,-1):
430 code[ic,ib] = temp[ib/32]%2
430 code[ic,ib] = temp[ib/32]%2
431 temp[ib/32] = temp[ib/32]/2
431 temp[ib/32] = temp[ib/32]/2
432
432
433 self.code = 2.0*code - 1.0
433 self.code = 2.0*code - 1.0
434 self.code_size = int(numpy.ceil(self.nBaud/32.))*self.nCode*4
434 self.code_size = int(numpy.ceil(self.nBaud/32.))*self.nCode*4
435
435
436 # if self.line5Function == RCfunction.FLIP:
436 # if self.line5Function == RCfunction.FLIP:
437 # self.flip1 = numpy.fromfile(fp,'<u4',1)
437 # self.flip1 = numpy.fromfile(fp,'<u4',1)
438 #
438 #
439 # if self.line6Function == RCfunction.FLIP:
439 # if self.line6Function == RCfunction.FLIP:
440 # self.flip2 = numpy.fromfile(fp,'<u4',1)
440 # self.flip2 = numpy.fromfile(fp,'<u4',1)
441 if startFp is not None:
441 if startFp is not None:
442 endFp = size + startFp
442 endFp = size + startFp
443
443
444 if fp.tell() != endFp:
444 if fp.tell() != endFp:
445 # fp.seek(endFp)
445 # fp.seek(endFp)
446 print "%s: Radar Controller Header size is not consistent: from data [%d] != from header field [%d]" %(fp.name, fp.tell()-startFp, size)
446 print "%s: Radar Controller Header size is not consistent: from data [%d] != from header field [%d]" %(fp.name, fp.tell()-startFp, size)
447 # return 0
447 # return 0
448
448
449 if fp.tell() > endFp:
449 if fp.tell() > endFp:
450 sys.stderr.write("Warning %s: Size value read from Radar Controller header is lower than it has to be\n" %fp.name)
450 sys.stderr.write("Warning %s: Size value read from Radar Controller header is lower than it has to be\n" %fp.name)
451 # return 0
451 # return 0
452
452
453 if fp.tell() < endFp:
453 if fp.tell() < endFp:
454 sys.stderr.write("Warning %s: Size value read from Radar Controller header is greater than it has to be\n" %fp.name)
454 sys.stderr.write("Warning %s: Size value read from Radar Controller header is greater than it has to be\n" %fp.name)
455
455
456
456
457 return 1
457 return 1
458
458
459 def write(self, fp):
459 def write(self, fp):
460
460
461 headerTuple = (self.size,
461 headerTuple = (self.size,
462 self.expType,
462 self.expType,
463 self.nTx,
463 self.nTx,
464 self.ipp,
464 self.ipp,
465 self.txA,
465 self.txA,
466 self.txB,
466 self.txB,
467 self.nWindows,
467 self.nWindows,
468 self.numTaus,
468 self.numTaus,
469 self.codeType,
469 self.codeType,
470 self.line6Function,
470 self.line6Function,
471 self.line5Function,
471 self.line5Function,
472 self.fClock,
472 self.fClock,
473 self.prePulseBefore,
473 self.prePulseBefore,
474 self.prePulseAfter,
474 self.prePulseAfter,
475 self.rangeIpp,
475 self.rangeIpp,
476 self.rangeTxA,
476 self.rangeTxA,
477 self.rangeTxB)
477 self.rangeTxB)
478
478
479 header = numpy.array(headerTuple,RADAR_STRUCTURE)
479 header = numpy.array(headerTuple,RADAR_STRUCTURE)
480 header.tofile(fp)
480 header.tofile(fp)
481
481
482 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
482 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
483 samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE)
483 samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE)
484 samplingWindow.tofile(fp)
484 samplingWindow.tofile(fp)
485
485
486 if self.numTaus > 0:
486 if self.numTaus > 0:
487 self.Taus.tofile(fp)
487 self.Taus.tofile(fp)
488
488
489 if self.codeType !=0:
489 if self.codeType !=0:
490 nCode = numpy.array(self.nCode, '<u4')
490 nCode = numpy.array(self.nCode, '<u4')
491 nCode.tofile(fp)
491 nCode.tofile(fp)
492 nBaud = numpy.array(self.nBaud, '<u4')
492 nBaud = numpy.array(self.nBaud, '<u4')
493 nBaud.tofile(fp)
493 nBaud.tofile(fp)
494 code1 = (self.code + 1.0)/2.
494 code1 = (self.code + 1.0)/2.
495
495
496 for ic in range(self.nCode):
496 for ic in range(self.nCode):
497 tempx = numpy.zeros(numpy.ceil(self.nBaud/32.))
497 tempx = numpy.zeros(numpy.ceil(self.nBaud/32.))
498 start = 0
498 start = 0
499 end = 32
499 end = 32
500 for i in range(len(tempx)):
500 for i in range(len(tempx)):
501 code_selected = code1[ic,start:end]
501 code_selected = code1[ic,start:end]
502 for j in range(len(code_selected)-1,-1,-1):
502 for j in range(len(code_selected)-1,-1,-1):
503 if code_selected[j] == 1:
503 if code_selected[j] == 1:
504 tempx[i] = tempx[i] + 2**(len(code_selected)-1-j)
504 tempx[i] = tempx[i] + 2**(len(code_selected)-1-j)
505 start = start + 32
505 start = start + 32
506 end = end + 32
506 end = end + 32
507
507
508 tempx = tempx.astype('u4')
508 tempx = tempx.astype('u4')
509 tempx.tofile(fp)
509 tempx.tofile(fp)
510
510
511 # if self.line5Function == RCfunction.FLIP:
511 # if self.line5Function == RCfunction.FLIP:
512 # self.flip1.tofile(fp)
512 # self.flip1.tofile(fp)
513 #
513 #
514 # if self.line6Function == RCfunction.FLIP:
514 # if self.line6Function == RCfunction.FLIP:
515 # self.flip2.tofile(fp)
515 # self.flip2.tofile(fp)
516
516
517 return 1
517 return 1
518
518
519 def get_ippSeconds(self):
519 def get_ippSeconds(self):
520 '''
520 '''
521 '''
521 '''
522 ippSeconds = 2.0 * 1000 * self.ipp / SPEED_OF_LIGHT
522 ippSeconds = 2.0 * 1000 * self.ipp / SPEED_OF_LIGHT
523
523
524 return ippSeconds
524 return ippSeconds
525
525
526 def set_ippSeconds(self, ippSeconds):
526 def set_ippSeconds(self, ippSeconds):
527 '''
527 '''
528 '''
528 '''
529
529
530 self.ipp = ippSeconds * SPEED_OF_LIGHT / (2.0*1000)
530 self.ipp = ippSeconds * SPEED_OF_LIGHT / (2.0*1000)
531
531
532 return
532 return
533
533
534 def get_size(self):
534 def get_size(self):
535
535
536 self.__size = 116 + 12*self.nWindows + 4*self.numTaus
536 self.__size = 116 + 12*self.nWindows + 4*self.numTaus
537
537
538 if self.codeType != 0:
538 if self.codeType != 0:
539 self.__size += 4 + 4 + 4*self.nCode*numpy.ceil(self.nBaud/32.)
539 self.__size += 4 + 4 + 4*self.nCode*numpy.ceil(self.nBaud/32.)
540
540
541 return self.__size
541 return self.__size
542
542
543 def set_size(self, value):
543 def set_size(self, value):
544
544
545 raise IOError, "size is a property and it cannot be set, just read"
545 raise IOError, "size is a property and it cannot be set, just read"
546
546
547 return
547 return
548
548
549 ippSeconds = property(get_ippSeconds, set_ippSeconds)
549 ippSeconds = property(get_ippSeconds, set_ippSeconds)
550 size = property(get_size, set_size)
550 size = property(get_size, set_size)
551
551
552 class ProcessingHeader(Header):
552 class ProcessingHeader(Header):
553
553
554 # size = None
554 # size = None
555 dtype = None
555 dtype = None
556 blockSize = None
556 blockSize = None
557 profilesPerBlock = None
557 profilesPerBlock = None
558 dataBlocksPerFile = None
558 dataBlocksPerFile = None
559 nWindows = None
559 nWindows = None
560 processFlags = None
560 processFlags = None
561 nCohInt = None
561 nCohInt = None
562 nIncohInt = None
562 nIncohInt = None
563 totalSpectra = None
563 totalSpectra = None
564 structure = PROCESSING_STRUCTURE
564 structure = PROCESSING_STRUCTURE
565 flag_dc = None
565 flag_dc = None
566 flag_cspc = None
566 flag_cspc = None
567
567
568 def __init__(self, dtype=0, blockSize=0, profilesPerBlock=0, dataBlocksPerFile=0, nWindows=0,processFlags=0, nCohInt=0,
568 def __init__(self, dtype=0, blockSize=0, profilesPerBlock=0, dataBlocksPerFile=0, nWindows=0,processFlags=0, nCohInt=0,
569 nIncohInt=0, totalSpectra=0, nHeights=0, firstHeight=0, deltaHeight=0, samplesWin=0, spectraComb=0, nCode=0,
569 nIncohInt=0, totalSpectra=0, nHeights=0, firstHeight=0, deltaHeight=0, samplesWin=0, spectraComb=0, nCode=0,
570 code=0, nBaud=None, shif_fft=False, flag_dc=False, flag_cspc=False, flag_decode=False, flag_deflip=False
570 code=0, nBaud=None, shif_fft=False, flag_dc=False, flag_cspc=False, flag_decode=False, flag_deflip=False
571 ):
571 ):
572
572
573 # self.size = 0
573 # self.size = 0
574 self.dtype = dtype
574 self.dtype = dtype
575 self.blockSize = blockSize
575 self.blockSize = blockSize
576 self.profilesPerBlock = 0
576 self.profilesPerBlock = 0
577 self.dataBlocksPerFile = 0
577 self.dataBlocksPerFile = 0
578 self.nWindows = 0
578 self.nWindows = 0
579 self.processFlags = 0
579 self.processFlags = 0
580 self.nCohInt = 0
580 self.nCohInt = 0
581 self.nIncohInt = 0
581 self.nIncohInt = 0
582 self.totalSpectra = 0
582 self.totalSpectra = 0
583
583
584 self.nHeights = 0
584 self.nHeights = 0
585 self.firstHeight = 0
585 self.firstHeight = 0
586 self.deltaHeight = 0
586 self.deltaHeight = 0
587 self.samplesWin = 0
587 self.samplesWin = 0
588 self.spectraComb = 0
588 self.spectraComb = 0
589 self.nCode = None
589 self.nCode = None
590 self.code = None
590 self.code = None
591 self.nBaud = None
591 self.nBaud = None
592
592
593 self.shif_fft = False
593 self.shif_fft = False
594 self.flag_dc = False
594 self.flag_dc = False
595 self.flag_cspc = False
595 self.flag_cspc = False
596 self.flag_decode = False
596 self.flag_decode = False
597 self.flag_deflip = False
597 self.flag_deflip = False
598 self.length = 0
598 self.length = 0
599
599
600 def read(self, fp):
600 def read(self, fp):
601 self.length = 0
601 self.length = 0
602 try:
602 try:
603 startFp = fp.tell()
603 startFp = fp.tell()
604 except Exception, e:
604 except Exception, e:
605 startFp = None
605 startFp = None
606 pass
606 pass
607
607
608 try:
608 try:
609 if hasattr(fp, 'read'):
609 if hasattr(fp, 'read'):
610 header = numpy.fromfile(fp, PROCESSING_STRUCTURE, 1)
610 header = numpy.fromfile(fp, PROCESSING_STRUCTURE, 1)
611 else:
611 else:
612 header = numpy.fromstring(fp, PROCESSING_STRUCTURE, 1)
612 header = numpy.fromstring(fp, PROCESSING_STRUCTURE, 1)
613 self.length += header.nbytes
613 self.length += header.nbytes
614 except Exception, e:
614 except Exception, e:
615 print "ProcessingHeader: " + str(e)
615 print "ProcessingHeader: " + str(e)
616 return 0
616 return 0
617
617
618 size = int(header['nSize'][0])
618 size = int(header['nSize'][0])
619 self.dtype = int(header['nDataType'][0])
619 self.dtype = int(header['nDataType'][0])
620 self.blockSize = int(header['nSizeOfDataBlock'][0])
620 self.blockSize = int(header['nSizeOfDataBlock'][0])
621 self.profilesPerBlock = int(header['nProfilesperBlock'][0])
621 self.profilesPerBlock = int(header['nProfilesperBlock'][0])
622 self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0])
622 self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0])
623 self.nWindows = int(header['nNumWindows'][0])
623 self.nWindows = int(header['nNumWindows'][0])
624 self.processFlags = header['nProcessFlags']
624 self.processFlags = header['nProcessFlags']
625 self.nCohInt = int(header['nCoherentIntegrations'][0])
625 self.nCohInt = int(header['nCoherentIntegrations'][0])
626 self.nIncohInt = int(header['nIncoherentIntegrations'][0])
626 self.nIncohInt = int(header['nIncoherentIntegrations'][0])
627 self.totalSpectra = int(header['nTotalSpectra'][0])
627 self.totalSpectra = int(header['nTotalSpectra'][0])
628
628
629 try:
629 try:
630 if hasattr(fp, 'read'):
630 if hasattr(fp, 'read'):
631 samplingWindow = numpy.fromfile(fp, SAMPLING_STRUCTURE, self.nWindows)
631 samplingWindow = numpy.fromfile(fp, SAMPLING_STRUCTURE, self.nWindows)
632 else:
632 else:
633 samplingWindow = numpy.fromstring(fp[self.length:], SAMPLING_STRUCTURE, self.nWindows)
633 samplingWindow = numpy.fromstring(fp[self.length:], SAMPLING_STRUCTURE, self.nWindows)
634 self.length += samplingWindow.nbytes
634 self.length += samplingWindow.nbytes
635 except Exception, e:
635 except Exception, e:
636 print "ProcessingHeader: " + str(e)
636 print "ProcessingHeader: " + str(e)
637 return 0
637 return 0
638
638
639 self.nHeights = int(numpy.sum(samplingWindow['nsa']))
639 self.nHeights = int(numpy.sum(samplingWindow['nsa']))
640 self.firstHeight = float(samplingWindow['h0'][0])
640 self.firstHeight = float(samplingWindow['h0'][0])
641 self.deltaHeight = float(samplingWindow['dh'][0])
641 self.deltaHeight = float(samplingWindow['dh'][0])
642 self.samplesWin = samplingWindow['nsa'][0]
642 self.samplesWin = samplingWindow['nsa'][0]
643
643
644
644
645 try:
645 try:
646 if hasattr(fp, 'read'):
646 if hasattr(fp, 'read'):
647 self.spectraComb = numpy.fromfile(fp, 'u1', 2*self.totalSpectra)
647 self.spectraComb = numpy.fromfile(fp, 'u1', 2*self.totalSpectra)
648 else:
648 else:
649 self.spectraComb = numpy.fromstring(fp[self.length:], 'u1', 2*self.totalSpectra)
649 self.spectraComb = numpy.fromstring(fp[self.length:], 'u1', 2*self.totalSpectra)
650 self.length += self.spectraComb.nbytes
650 self.length += self.spectraComb.nbytes
651 except Exception, e:
651 except Exception, e:
652 print "ProcessingHeader: " + str(e)
652 print "ProcessingHeader: " + str(e)
653 return 0
653 return 0
654
654
655 if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE):
655 if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE):
656 self.nCode = int(numpy.fromfile(fp,'<u4',1))
656 self.nCode = int(numpy.fromfile(fp,'<u4',1))
657 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
657 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
658 self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nCode,self.nBaud)
658 self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nCode,self.nBaud)
659
659
660 if ((self.processFlags & PROCFLAG.EXP_NAME_ESP) == PROCFLAG.EXP_NAME_ESP):
660 if ((self.processFlags & PROCFLAG.EXP_NAME_ESP) == PROCFLAG.EXP_NAME_ESP):
661 exp_name_len = int(numpy.fromfile(fp,'<u4',1))
661 exp_name_len = int(numpy.fromfile(fp,'<u4',1))
662 exp_name = numpy.fromfile(fp,'u1',exp_name_len+1)
662 exp_name = numpy.fromfile(fp,'u1',exp_name_len+1)
663
663
664 if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA):
664 if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA):
665 self.shif_fft = True
665 self.shif_fft = True
666 else:
666 else:
667 self.shif_fft = False
667 self.shif_fft = False
668
668
669 if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC):
669 if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC):
670 self.flag_dc = True
670 self.flag_dc = True
671 else:
671 else:
672 self.flag_dc = False
672 self.flag_dc = False
673
673
674 if ((self.processFlags & PROCFLAG.DECODE_DATA) == PROCFLAG.DECODE_DATA):
674 if ((self.processFlags & PROCFLAG.DECODE_DATA) == PROCFLAG.DECODE_DATA):
675 self.flag_decode = True
675 self.flag_decode = True
676 else:
676 else:
677 self.flag_decode = False
677 self.flag_decode = False
678
678
679 if ((self.processFlags & PROCFLAG.DEFLIP_DATA) == PROCFLAG.DEFLIP_DATA):
679 if ((self.processFlags & PROCFLAG.DEFLIP_DATA) == PROCFLAG.DEFLIP_DATA):
680 self.flag_deflip = True
680 self.flag_deflip = True
681 else:
681 else:
682 self.flag_deflip = False
682 self.flag_deflip = False
683
683
684 nChannels = 0
684 nChannels = 0
685 nPairs = 0
685 nPairs = 0
686 pairList = []
686 pairList = []
687
687
688 for i in range( 0, self.totalSpectra*2, 2 ):
688 for i in range( 0, self.totalSpectra*2, 2 ):
689 if self.spectraComb[i] == self.spectraComb[i+1]:
689 if self.spectraComb[i] == self.spectraComb[i+1]:
690 nChannels = nChannels + 1 #par de canales iguales
690 nChannels = nChannels + 1 #par de canales iguales
691 else:
691 else:
692 nPairs = nPairs + 1 #par de canales diferentes
692 nPairs = nPairs + 1 #par de canales diferentes
693 pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) )
693 pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) )
694
694
695 self.flag_cspc = False
695 self.flag_cspc = False
696 if nPairs > 0:
696 if nPairs > 0:
697 self.flag_cspc = True
697 self.flag_cspc = True
698
698
699
699
700
700
701 if startFp is not None:
701 if startFp is not None:
702 endFp = size + startFp
702 endFp = size + startFp
703 if fp.tell() > endFp:
703 if fp.tell() > endFp:
704 sys.stderr.write("Warning: Processing header size is lower than it has to be")
704 sys.stderr.write("Warning: Processing header size is lower than it has to be")
705 return 0
705 return 0
706
706
707 if fp.tell() < endFp:
707 if fp.tell() < endFp:
708 sys.stderr.write("Warning: Processing header size is greater than it is considered")
708 sys.stderr.write("Warning: Processing header size is greater than it is considered")
709
709
710 return 1
710 return 1
711
711
712 def write(self, fp):
712 def write(self, fp):
713 #Clear DEFINE_PROCESS_CODE
713 #Clear DEFINE_PROCESS_CODE
714 self.processFlags = self.processFlags & (~PROCFLAG.DEFINE_PROCESS_CODE)
714 self.processFlags = self.processFlags & (~PROCFLAG.DEFINE_PROCESS_CODE)
715
715
716 headerTuple = (self.size,
716 headerTuple = (self.size,
717 self.dtype,
717 self.dtype,
718 self.blockSize,
718 self.blockSize,
719 self.profilesPerBlock,
719 self.profilesPerBlock,
720 self.dataBlocksPerFile,
720 self.dataBlocksPerFile,
721 self.nWindows,
721 self.nWindows,
722 self.processFlags,
722 self.processFlags,
723 self.nCohInt,
723 self.nCohInt,
724 self.nIncohInt,
724 self.nIncohInt,
725 self.totalSpectra)
725 self.totalSpectra)
726
726
727 header = numpy.array(headerTuple,PROCESSING_STRUCTURE)
727 header = numpy.array(headerTuple,PROCESSING_STRUCTURE)
728 header.tofile(fp)
728 header.tofile(fp)
729
729
730 if self.nWindows != 0:
730 if self.nWindows != 0:
731 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
731 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
732 samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE)
732 samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE)
733 samplingWindow.tofile(fp)
733 samplingWindow.tofile(fp)
734
734
735 if self.totalSpectra != 0:
735 if self.totalSpectra != 0:
736 # spectraComb = numpy.array([],numpy.dtype('u1'))
736 # spectraComb = numpy.array([],numpy.dtype('u1'))
737 spectraComb = self.spectraComb
737 spectraComb = self.spectraComb
738 spectraComb.tofile(fp)
738 spectraComb.tofile(fp)
739
739
740 # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
740 # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
741 # nCode = numpy.array([self.nCode], numpy.dtype('u4')) #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba
741 # nCode = numpy.array([self.nCode], numpy.dtype('u4')) #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba
742 # nCode.tofile(fp)
742 # nCode.tofile(fp)
743 #
743 #
744 # nBaud = numpy.array([self.nBaud], numpy.dtype('u4'))
744 # nBaud = numpy.array([self.nBaud], numpy.dtype('u4'))
745 # nBaud.tofile(fp)
745 # nBaud.tofile(fp)
746 #
746 #
747 # code = self.code.reshape(self.nCode*self.nBaud)
747 # code = self.code.reshape(self.nCode*self.nBaud)
748 # code = code.astype(numpy.dtype('<f4'))
748 # code = code.astype(numpy.dtype('<f4'))
749 # code.tofile(fp)
749 # code.tofile(fp)
750
750
751 return 1
751 return 1
752
752
753 def get_size(self):
753 def get_size(self):
754
754
755 self.__size = 40 + 12*self.nWindows + 2*self.totalSpectra
755 self.__size = 40 + 12*self.nWindows + 2*self.totalSpectra
756
756
757 # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
757 # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
758 # self.__size += 4 + 4 + 4*self.nCode*numpy.ceil(self.nBaud/32.)
758 # self.__size += 4 + 4 + 4*self.nCode*numpy.ceil(self.nBaud/32.)
759 # self.__size += 4 + 4 + 4 * self.nCode * self.nBaud
759 # self.__size += 4 + 4 + 4 * self.nCode * self.nBaud
760
760
761 return self.__size
761 return self.__size
762
762
763 def set_size(self, value):
763 def set_size(self, value):
764
764
765 raise IOError, "size is a property and it cannot be set, just read"
765 raise IOError, "size is a property and it cannot be set, just read"
766
766
767 return
767 return
768
768
769 size = property(get_size, set_size)
769 size = property(get_size, set_size)
770
770
771 class RCfunction:
771 class RCfunction:
772 NONE=0
772 NONE=0
773 FLIP=1
773 FLIP=1
774 CODE=2
774 CODE=2
775 SAMPLING=3
775 SAMPLING=3
776 LIN6DIV256=4
776 LIN6DIV256=4
777 SYNCHRO=5
777 SYNCHRO=5
778
778
779 class nCodeType:
779 class nCodeType:
780 NONE=0
780 NONE=0
781 USERDEFINE=1
781 USERDEFINE=1
782 BARKER2=2
782 BARKER2=2
783 BARKER3=3
783 BARKER3=3
784 BARKER4=4
784 BARKER4=4
785 BARKER5=5
785 BARKER5=5
786 BARKER7=6
786 BARKER7=6
787 BARKER11=7
787 BARKER11=7
788 BARKER13=8
788 BARKER13=8
789 AC128=9
789 AC128=9
790 COMPLEMENTARYCODE2=10
790 COMPLEMENTARYCODE2=10
791 COMPLEMENTARYCODE4=11
791 COMPLEMENTARYCODE4=11
792 COMPLEMENTARYCODE8=12
792 COMPLEMENTARYCODE8=12
793 COMPLEMENTARYCODE16=13
793 COMPLEMENTARYCODE16=13
794 COMPLEMENTARYCODE32=14
794 COMPLEMENTARYCODE32=14
795 COMPLEMENTARYCODE64=15
795 COMPLEMENTARYCODE64=15
796 COMPLEMENTARYCODE128=16
796 COMPLEMENTARYCODE128=16
797 CODE_BINARY28=17
797 CODE_BINARY28=17
798
798
799 class PROCFLAG:
799 class PROCFLAG:
800
800
801 COHERENT_INTEGRATION = numpy.uint32(0x00000001)
801 COHERENT_INTEGRATION = numpy.uint32(0x00000001)
802 DECODE_DATA = numpy.uint32(0x00000002)
802 DECODE_DATA = numpy.uint32(0x00000002)
803 SPECTRA_CALC = numpy.uint32(0x00000004)
803 SPECTRA_CALC = numpy.uint32(0x00000004)
804 INCOHERENT_INTEGRATION = numpy.uint32(0x00000008)
804 INCOHERENT_INTEGRATION = numpy.uint32(0x00000008)
805 POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010)
805 POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010)
806 SHIFT_FFT_DATA = numpy.uint32(0x00000020)
806 SHIFT_FFT_DATA = numpy.uint32(0x00000020)
807
807
808 DATATYPE_CHAR = numpy.uint32(0x00000040)
808 DATATYPE_CHAR = numpy.uint32(0x00000040)
809 DATATYPE_SHORT = numpy.uint32(0x00000080)
809 DATATYPE_SHORT = numpy.uint32(0x00000080)
810 DATATYPE_LONG = numpy.uint32(0x00000100)
810 DATATYPE_LONG = numpy.uint32(0x00000100)
811 DATATYPE_INT64 = numpy.uint32(0x00000200)
811 DATATYPE_INT64 = numpy.uint32(0x00000200)
812 DATATYPE_FLOAT = numpy.uint32(0x00000400)
812 DATATYPE_FLOAT = numpy.uint32(0x00000400)
813 DATATYPE_DOUBLE = numpy.uint32(0x00000800)
813 DATATYPE_DOUBLE = numpy.uint32(0x00000800)
814
814
815 DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000)
815 DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000)
816 DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000)
816 DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000)
817 DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000)
817 DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000)
818
818
819 SAVE_CHANNELS_DC = numpy.uint32(0x00008000)
819 SAVE_CHANNELS_DC = numpy.uint32(0x00008000)
820 DEFLIP_DATA = numpy.uint32(0x00010000)
820 DEFLIP_DATA = numpy.uint32(0x00010000)
821 DEFINE_PROCESS_CODE = numpy.uint32(0x00020000)
821 DEFINE_PROCESS_CODE = numpy.uint32(0x00020000)
822
822
823 ACQ_SYS_NATALIA = numpy.uint32(0x00040000)
823 ACQ_SYS_NATALIA = numpy.uint32(0x00040000)
824 ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000)
824 ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000)
825 ACQ_SYS_ADRXD = numpy.uint32(0x000C0000)
825 ACQ_SYS_ADRXD = numpy.uint32(0x000C0000)
826 ACQ_SYS_JULIA = numpy.uint32(0x00100000)
826 ACQ_SYS_JULIA = numpy.uint32(0x00100000)
827 ACQ_SYS_XXXXXX = numpy.uint32(0x00140000)
827 ACQ_SYS_XXXXXX = numpy.uint32(0x00140000)
828
828
829 EXP_NAME_ESP = numpy.uint32(0x00200000)
829 EXP_NAME_ESP = numpy.uint32(0x00200000)
830 CHANNEL_NAMES_ESP = numpy.uint32(0x00400000)
830 CHANNEL_NAMES_ESP = numpy.uint32(0x00400000)
831
831
832 OPERATION_MASK = numpy.uint32(0x0000003F)
832 OPERATION_MASK = numpy.uint32(0x0000003F)
833 DATATYPE_MASK = numpy.uint32(0x00000FC0)
833 DATATYPE_MASK = numpy.uint32(0x00000FC0)
834 DATAARRANGE_MASK = numpy.uint32(0x00007000)
834 DATAARRANGE_MASK = numpy.uint32(0x00007000)
835 ACQ_SYS_MASK = numpy.uint32(0x001C0000)
835 ACQ_SYS_MASK = numpy.uint32(0x001C0000)
836
836
837 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
837 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
838 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
838 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
839 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
839 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
840 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
840 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
841 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
841 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
842 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
842 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
843
843
844 NUMPY_DTYPE_LIST = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
844 NUMPY_DTYPE_LIST = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
845
845
846 PROCFLAG_DTYPE_LIST = [PROCFLAG.DATATYPE_CHAR,
846 PROCFLAG_DTYPE_LIST = [PROCFLAG.DATATYPE_CHAR,
847 PROCFLAG.DATATYPE_SHORT,
847 PROCFLAG.DATATYPE_SHORT,
848 PROCFLAG.DATATYPE_LONG,
848 PROCFLAG.DATATYPE_LONG,
849 PROCFLAG.DATATYPE_INT64,
849 PROCFLAG.DATATYPE_INT64,
850 PROCFLAG.DATATYPE_FLOAT,
850 PROCFLAG.DATATYPE_FLOAT,
851 PROCFLAG.DATATYPE_DOUBLE]
851 PROCFLAG.DATATYPE_DOUBLE]
852
852
853 DTYPE_WIDTH = [1, 2, 4, 8, 4, 8]
853 DTYPE_WIDTH = [1, 2, 4, 8, 4, 8]
854
854
855 def get_dtype_index(numpy_dtype):
855 def get_dtype_index(numpy_dtype):
856
856
857 index = None
857 index = None
858
858
859 for i in range(len(NUMPY_DTYPE_LIST)):
859 for i in range(len(NUMPY_DTYPE_LIST)):
860 if numpy_dtype == NUMPY_DTYPE_LIST[i]:
860 if numpy_dtype == NUMPY_DTYPE_LIST[i]:
861 index = i
861 index = i
862 break
862 break
863
863
864 return index
864 return index
865
865
866 def get_numpy_dtype(index):
866 def get_numpy_dtype(index):
867
867
868 return NUMPY_DTYPE_LIST[index]
868 return NUMPY_DTYPE_LIST[index]
869
869
870 def get_procflag_dtype(index):
870 def get_procflag_dtype(index):
871
871
872 return PROCFLAG_DTYPE_LIST[index]
872 return PROCFLAG_DTYPE_LIST[index]
873
873
874 def get_dtype_width(index):
874 def get_dtype_width(index):
875
875
876 return DTYPE_WIDTH[index] No newline at end of file
876 return DTYPE_WIDTH[index]
@@ -1,657 +1,657
1 import os
1 import os
2 import numpy
2 import numpy
3 import time, datetime
3 import time, datetime
4 import mpldriver
4 import mpldriver
5
5
6 from schainpy.model.proc.jroproc_base import Operation
6 from schainpy.model.proc.jroproc_base import Operation
7
7
8 def isTimeInHourRange(datatime, xmin, xmax):
8 def isTimeInHourRange(datatime, xmin, xmax):
9
9
10 if xmin == None or xmax == None:
10 if xmin == None or xmax == None:
11 return 1
11 return 1
12 hour = datatime.hour + datatime.minute/60.0
12 hour = datatime.hour + datatime.minute/60.0
13
13
14 if xmin < (xmax % 24):
14 if xmin < (xmax % 24):
15
15
16 if hour >= xmin and hour <= xmax:
16 if hour >= xmin and hour <= xmax:
17 return 1
17 return 1
18 else:
18 else:
19 return 0
19 return 0
20
20
21 else:
21 else:
22
22
23 if hour >= xmin or hour <= (xmax % 24):
23 if hour >= xmin or hour <= (xmax % 24):
24 return 1
24 return 1
25 else:
25 else:
26 return 0
26 return 0
27
27
28 return 0
28 return 0
29
29
30 def isRealtime(utcdatatime):
30 def isRealtime(utcdatatime):
31
31
32 utcnow = time.mktime(time.localtime())
32 utcnow = time.mktime(time.localtime())
33 delta = abs(utcnow - utcdatatime) # abs
33 delta = abs(utcnow - utcdatatime) # abs
34 if delta >= 30.:
34 if delta >= 30.:
35 return False
35 return False
36 return True
36 return True
37
37
38 class Figure(Operation):
38 class Figure(Operation):
39
39
40 __driver = mpldriver
40 __driver = mpldriver
41 fig = None
41 fig = None
42
42
43 id = None
43 id = None
44 wintitle = None
44 wintitle = None
45 width = None
45 width = None
46 height = None
46 height = None
47 nplots = None
47 nplots = None
48 timerange = None
48 timerange = None
49
49
50 axesObjList = []
50 axesObjList = []
51
51
52 WIDTH = 300
52 WIDTH = 300
53 HEIGHT = 200
53 HEIGHT = 200
54 PREFIX = 'fig'
54 PREFIX = 'fig'
55
55
56 xmin = None
56 xmin = None
57 xmax = None
57 xmax = None
58
58
59 counter_imagwr = 0
59 counter_imagwr = 0
60
60
61 figfile = None
61 figfile = None
62
62
63 created = False
63 created = False
64
64 parameters = {}
65 def __init__(self, **kwargs):
65 def __init__(self, **kwargs):
66
66
67 Operation.__init__(self, **kwargs)
67 Operation.__init__(self, **kwargs)
68
68
69 def __del__(self):
69 def __del__(self):
70
70
71 self.__driver.closeFigure()
71 self.__driver.closeFigure()
72
72
73 def getFilename(self, name, ext='.png'):
73 def getFilename(self, name, ext='.png'):
74
74
75 path = '%s%03d' %(self.PREFIX, self.id)
75 path = '%s%03d' %(self.PREFIX, self.id)
76 filename = '%s_%s%s' %(self.PREFIX, name, ext)
76 filename = '%s_%s%s' %(self.PREFIX, name, ext)
77 return os.path.join(path, filename)
77 return os.path.join(path, filename)
78
78
79 def getAxesObjList(self):
79 def getAxesObjList(self):
80
80
81 return self.axesObjList
81 return self.axesObjList
82
82
83 def getSubplots(self):
83 def getSubplots(self):
84
84
85 raise NotImplementedError
85 raise NotImplementedError
86
86
87 def getScreenDim(self, widthplot, heightplot):
87 def getScreenDim(self, widthplot, heightplot):
88
88
89 nrow, ncol = self.getSubplots()
89 nrow, ncol = self.getSubplots()
90
90
91 widthscreen = widthplot*ncol
91 widthscreen = widthplot*ncol
92 heightscreen = heightplot*nrow
92 heightscreen = heightplot*nrow
93
93
94 return widthscreen, heightscreen
94 return widthscreen, heightscreen
95
95
96 def getTimeLim(self, x, xmin=None, xmax=None, timerange=None):
96 def getTimeLim(self, x, xmin=None, xmax=None, timerange=None):
97
97
98 # if self.xmin != None and self.xmax != None:
98 # if self.xmin != None and self.xmax != None:
99 # if timerange == None:
99 # if timerange == None:
100 # timerange = self.xmax - self.xmin
100 # timerange = self.xmax - self.xmin
101 # xmin = self.xmin + timerange
101 # xmin = self.xmin + timerange
102 # xmax = self.xmax + timerange
102 # xmax = self.xmax + timerange
103 #
103 #
104 # return xmin, xmax
104 # return xmin, xmax
105
105
106 if timerange == None and (xmin==None or xmax==None):
106 if timerange == None and (xmin==None or xmax==None):
107 timerange = 14400 #seconds
107 timerange = 14400 #seconds
108
108
109 if timerange != None:
109 if timerange != None:
110 txmin = x[0] #- x[0] % min(timerange/10, 10*60)
110 txmin = x[0] #- x[0] % min(timerange/10, 10*60)
111 else:
111 else:
112 txmin = x[0] #- x[0] % 10*60
112 txmin = x[0] #- x[0] % 10*60
113
113
114 thisdatetime = datetime.datetime.utcfromtimestamp(txmin)
114 thisdatetime = datetime.datetime.utcfromtimestamp(txmin)
115 thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
115 thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
116
116
117 if timerange != None:
117 if timerange != None:
118 xmin = (thisdatetime - thisdate).seconds/(60*60.)
118 xmin = (thisdatetime - thisdate).seconds/(60*60.)
119 xmax = xmin + timerange/(60*60.)
119 xmax = xmin + timerange/(60*60.)
120
120
121 d1970 = datetime.datetime(1970,1,1)
121 d1970 = datetime.datetime(1970,1,1)
122
122
123 mindt = thisdate + datetime.timedelta(hours=xmin) #- datetime.timedelta(seconds=time.timezone)
123 mindt = thisdate + datetime.timedelta(hours=xmin) #- datetime.timedelta(seconds=time.timezone)
124 xmin_sec = (mindt - d1970).total_seconds() #time.mktime(mindt.timetuple()) - time.timezone
124 xmin_sec = (mindt - d1970).total_seconds() #time.mktime(mindt.timetuple()) - time.timezone
125
125
126 maxdt = thisdate + datetime.timedelta(hours=xmax) #- datetime.timedelta(seconds=time.timezone)
126 maxdt = thisdate + datetime.timedelta(hours=xmax) #- datetime.timedelta(seconds=time.timezone)
127 xmax_sec = (maxdt - d1970).total_seconds() #time.mktime(maxdt.timetuple()) - time.timezone
127 xmax_sec = (maxdt - d1970).total_seconds() #time.mktime(maxdt.timetuple()) - time.timezone
128
128
129 return xmin_sec, xmax_sec
129 return xmin_sec, xmax_sec
130
130
131 def init(self, id, nplots, wintitle):
131 def init(self, id, nplots, wintitle):
132
132
133 raise NotImplementedError, "This method has been replaced by createFigure"
133 raise NotImplementedError, "This method has been replaced by createFigure"
134
134
135 def createFigure(self, id, wintitle, widthplot=None, heightplot=None, show=True):
135 def createFigure(self, id, wintitle, widthplot=None, heightplot=None, show=True):
136
136
137 """
137 """
138 Crea la figura de acuerdo al driver y parametros seleccionados seleccionados.
138 Crea la figura de acuerdo al driver y parametros seleccionados seleccionados.
139 Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH
139 Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH
140 y self.HEIGHT y el numero de subplots (nrow, ncol)
140 y self.HEIGHT y el numero de subplots (nrow, ncol)
141
141
142 Input:
142 Input:
143 id : Los parametros necesarios son
143 id : Los parametros necesarios son
144 wintitle :
144 wintitle :
145
145
146 """
146 """
147
147
148 if widthplot == None:
148 if widthplot == None:
149 widthplot = self.WIDTH
149 widthplot = self.WIDTH
150
150
151 if heightplot == None:
151 if heightplot == None:
152 heightplot = self.HEIGHT
152 heightplot = self.HEIGHT
153
153
154 self.id = id
154 self.id = id
155
155
156 self.wintitle = wintitle
156 self.wintitle = wintitle
157
157
158 self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot)
158 self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot)
159
159
160 # if self.created:
160 # if self.created:
161 # self.__driver.closeFigure(self.fig)
161 # self.__driver.closeFigure(self.fig)
162
162
163 if not self.created:
163 if not self.created:
164 self.fig = self.__driver.createFigure(id=self.id,
164 self.fig = self.__driver.createFigure(id=self.id,
165 wintitle=self.wintitle,
165 wintitle=self.wintitle,
166 width=self.widthscreen,
166 width=self.widthscreen,
167 height=self.heightscreen,
167 height=self.heightscreen,
168 show=show)
168 show=show)
169 else:
169 else:
170 self.__driver.clearFigure(self.fig)
170 self.__driver.clearFigure(self.fig)
171
171
172 self.axesObjList = []
172 self.axesObjList = []
173 self.counter_imagwr = 0
173 self.counter_imagwr = 0
174
174
175 self.created = True
175 self.created = True
176
176
177 def setDriver(self, driver=mpldriver):
177 def setDriver(self, driver=mpldriver):
178
178
179 self.__driver = driver
179 self.__driver = driver
180
180
181 def setTitle(self, title):
181 def setTitle(self, title):
182
182
183 self.__driver.setTitle(self.fig, title)
183 self.__driver.setTitle(self.fig, title)
184
184
185 def setWinTitle(self, title):
185 def setWinTitle(self, title):
186
186
187 self.__driver.setWinTitle(self.fig, title=title)
187 self.__driver.setWinTitle(self.fig, title=title)
188
188
189 def setTextFromAxes(self, text):
189 def setTextFromAxes(self, text):
190
190
191 raise NotImplementedError, "This method has been replaced with Axes.setText"
191 raise NotImplementedError, "This method has been replaced with Axes.setText"
192
192
193 def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan):
193 def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan):
194
194
195 raise NotImplementedError, "This method has been replaced with Axes.addAxes"
195 raise NotImplementedError, "This method has been replaced with Axes.addAxes"
196
196
197 def addAxes(self, *args):
197 def addAxes(self, *args):
198 """
198 """
199
199
200 Input:
200 Input:
201 *args : Los parametros necesarios son
201 *args : Los parametros necesarios son
202 nrow, ncol, xpos, ypos, colspan, rowspan
202 nrow, ncol, xpos, ypos, colspan, rowspan
203 """
203 """
204
204
205 axesObj = Axes(self.fig, *args)
205 axesObj = Axes(self.fig, *args)
206 self.axesObjList.append(axesObj)
206 self.axesObjList.append(axesObj)
207
207
208 def saveFigure(self, figpath, figfile, *args):
208 def saveFigure(self, figpath, figfile, *args):
209
209
210 filename = os.path.join(figpath, figfile)
210 filename = os.path.join(figpath, figfile)
211
211
212 fullpath = os.path.split(filename)[0]
212 fullpath = os.path.split(filename)[0]
213
213
214 if not os.path.exists(fullpath):
214 if not os.path.exists(fullpath):
215 subpath = os.path.split(fullpath)[0]
215 subpath = os.path.split(fullpath)[0]
216
216
217 if not os.path.exists(subpath):
217 if not os.path.exists(subpath):
218 os.mkdir(subpath)
218 os.mkdir(subpath)
219
219
220 os.mkdir(fullpath)
220 os.mkdir(fullpath)
221
221
222 self.__driver.saveFigure(self.fig, filename, *args)
222 self.__driver.saveFigure(self.fig, filename, *args)
223
223
224 def save(self, figpath, figfile=None, save=True, ftp=False, wr_period=1, thisDatetime=None, update_figfile=True):
224 def save(self, figpath, figfile=None, save=True, ftp=False, wr_period=1, thisDatetime=None, update_figfile=True):
225
225
226 self.counter_imagwr += 1
226 self.counter_imagwr += 1
227 if self.counter_imagwr < wr_period:
227 if self.counter_imagwr < wr_period:
228 return
228 return
229
229
230 self.counter_imagwr = 0
230 self.counter_imagwr = 0
231
231
232 if save:
232 if save:
233
233
234 if not figfile:
234 if not figfile:
235
235
236 if not thisDatetime:
236 if not thisDatetime:
237 raise ValueError, "Saving figure: figfile or thisDatetime should be defined"
237 raise ValueError, "Saving figure: figfile or thisDatetime should be defined"
238 return
238 return
239
239
240 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
240 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
241 figfile = self.getFilename(name = str_datetime)
241 figfile = self.getFilename(name = str_datetime)
242
242
243 if self.figfile == None:
243 if self.figfile == None:
244 self.figfile = figfile
244 self.figfile = figfile
245
245
246 if update_figfile:
246 if update_figfile:
247 self.figfile = figfile
247 self.figfile = figfile
248
248
249 # store png plot to local folder
249 # store png plot to local folder
250 self.saveFigure(figpath, self.figfile)
250 self.saveFigure(figpath, self.figfile)
251
251
252
252
253 if not ftp:
253 if not ftp:
254 return
254 return
255
255
256 if not thisDatetime:
256 if not thisDatetime:
257 return
257 return
258
258
259 # store png plot to FTP server according to RT-Web format
259 # store png plot to FTP server according to RT-Web format
260 ftp_filename = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
260 ftp_filename = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
261 # ftp_filename = os.path.join(figpath, name)
261 # ftp_filename = os.path.join(figpath, name)
262 self.saveFigure(figpath, ftp_filename)
262 self.saveFigure(figpath, ftp_filename)
263
263
264 def getNameToFtp(self, thisDatetime, FTP_WEI, EXP_CODE, SUB_EXP_CODE, PLOT_CODE, PLOT_POS):
264 def getNameToFtp(self, thisDatetime, FTP_WEI, EXP_CODE, SUB_EXP_CODE, PLOT_CODE, PLOT_POS):
265 YEAR_STR = '%4.4d'%thisDatetime.timetuple().tm_year
265 YEAR_STR = '%4.4d'%thisDatetime.timetuple().tm_year
266 DOY_STR = '%3.3d'%thisDatetime.timetuple().tm_yday
266 DOY_STR = '%3.3d'%thisDatetime.timetuple().tm_yday
267 FTP_WEI = '%2.2d'%FTP_WEI
267 FTP_WEI = '%2.2d'%FTP_WEI
268 EXP_CODE = '%3.3d'%EXP_CODE
268 EXP_CODE = '%3.3d'%EXP_CODE
269 SUB_EXP_CODE = '%2.2d'%SUB_EXP_CODE
269 SUB_EXP_CODE = '%2.2d'%SUB_EXP_CODE
270 PLOT_CODE = '%2.2d'%PLOT_CODE
270 PLOT_CODE = '%2.2d'%PLOT_CODE
271 PLOT_POS = '%2.2d'%PLOT_POS
271 PLOT_POS = '%2.2d'%PLOT_POS
272 name = YEAR_STR + DOY_STR + FTP_WEI + EXP_CODE + SUB_EXP_CODE + PLOT_CODE + PLOT_POS
272 name = YEAR_STR + DOY_STR + FTP_WEI + EXP_CODE + SUB_EXP_CODE + PLOT_CODE + PLOT_POS
273 return name
273 return name
274
274
275 def draw(self):
275 def draw(self):
276
276
277 self.__driver.draw(self.fig)
277 self.__driver.draw(self.fig)
278
278
279 def run(self):
279 def run(self):
280
280
281 raise NotImplementedError
281 raise NotImplementedError
282
282
283 def close(self, show=False):
283 def close(self, show=False):
284
284
285 self.__driver.closeFigure(show=show, fig=self.fig)
285 self.__driver.closeFigure(show=show, fig=self.fig)
286
286
287 axesList = property(getAxesObjList)
287 axesList = property(getAxesObjList)
288
288
289
289
290 class Axes:
290 class Axes:
291
291
292 __driver = mpldriver
292 __driver = mpldriver
293 fig = None
293 fig = None
294 ax = None
294 ax = None
295 plot = None
295 plot = None
296 __missing = 1E30
296 __missing = 1E30
297 __firsttime = None
297 __firsttime = None
298
298
299 __showprofile = False
299 __showprofile = False
300
300
301 xmin = None
301 xmin = None
302 xmax = None
302 xmax = None
303 ymin = None
303 ymin = None
304 ymax = None
304 ymax = None
305 zmin = None
305 zmin = None
306 zmax = None
306 zmax = None
307
307
308 x_buffer = None
308 x_buffer = None
309 z_buffer = None
309 z_buffer = None
310
310
311 decimationx = None
311 decimationx = None
312 decimationy = None
312 decimationy = None
313
313
314 __MAXNUMX = 200
314 __MAXNUMX = 200
315 __MAXNUMY = 400
315 __MAXNUMY = 400
316
316
317 __MAXNUMTIME = 500
317 __MAXNUMTIME = 500
318
318
319 def __init__(self, *args):
319 def __init__(self, *args):
320
320
321 """
321 """
322
322
323 Input:
323 Input:
324 *args : Los parametros necesarios son
324 *args : Los parametros necesarios son
325 fig, nrow, ncol, xpos, ypos, colspan, rowspan
325 fig, nrow, ncol, xpos, ypos, colspan, rowspan
326 """
326 """
327
327
328 ax = self.__driver.createAxes(*args)
328 ax = self.__driver.createAxes(*args)
329 self.fig = args[0]
329 self.fig = args[0]
330 self.ax = ax
330 self.ax = ax
331 self.plot = None
331 self.plot = None
332
332
333 self.__firsttime = True
333 self.__firsttime = True
334 self.idlineList = []
334 self.idlineList = []
335
335
336 self.x_buffer = numpy.array([])
336 self.x_buffer = numpy.array([])
337 self.z_buffer = numpy.array([])
337 self.z_buffer = numpy.array([])
338
338
339 def setText(self, text):
339 def setText(self, text):
340
340
341 self.__driver.setAxesText(self.ax, text)
341 self.__driver.setAxesText(self.ax, text)
342
342
343 def setXAxisAsTime(self):
343 def setXAxisAsTime(self):
344 pass
344 pass
345
345
346 def pline(self, x, y,
346 def pline(self, x, y,
347 xmin=None, xmax=None,
347 xmin=None, xmax=None,
348 ymin=None, ymax=None,
348 ymin=None, ymax=None,
349 xlabel='', ylabel='',
349 xlabel='', ylabel='',
350 title='',
350 title='',
351 **kwargs):
351 **kwargs):
352
352
353 """
353 """
354
354
355 Input:
355 Input:
356 x :
356 x :
357 y :
357 y :
358 xmin :
358 xmin :
359 xmax :
359 xmax :
360 ymin :
360 ymin :
361 ymax :
361 ymax :
362 xlabel :
362 xlabel :
363 ylabel :
363 ylabel :
364 title :
364 title :
365 **kwargs : Los parametros aceptados son
365 **kwargs : Los parametros aceptados son
366
366
367 ticksize
367 ticksize
368 ytick_visible
368 ytick_visible
369 """
369 """
370
370
371 if self.__firsttime:
371 if self.__firsttime:
372
372
373 if xmin == None: xmin = numpy.nanmin(x)
373 if xmin == None: xmin = numpy.nanmin(x)
374 if xmax == None: xmax = numpy.nanmax(x)
374 if xmax == None: xmax = numpy.nanmax(x)
375 if ymin == None: ymin = numpy.nanmin(y)
375 if ymin == None: ymin = numpy.nanmin(y)
376 if ymax == None: ymax = numpy.nanmax(y)
376 if ymax == None: ymax = numpy.nanmax(y)
377
377
378 self.plot = self.__driver.createPline(self.ax, x, y,
378 self.plot = self.__driver.createPline(self.ax, x, y,
379 xmin, xmax,
379 xmin, xmax,
380 ymin, ymax,
380 ymin, ymax,
381 xlabel=xlabel,
381 xlabel=xlabel,
382 ylabel=ylabel,
382 ylabel=ylabel,
383 title=title,
383 title=title,
384 **kwargs)
384 **kwargs)
385
385
386 self.idlineList.append(0)
386 self.idlineList.append(0)
387 self.__firsttime = False
387 self.__firsttime = False
388 return
388 return
389
389
390 self.__driver.pline(self.plot, x, y, xlabel=xlabel,
390 self.__driver.pline(self.plot, x, y, xlabel=xlabel,
391 ylabel=ylabel,
391 ylabel=ylabel,
392 title=title)
392 title=title)
393
393
394 # self.__driver.pause()
394 # self.__driver.pause()
395
395
396 def addpline(self, x, y, idline, **kwargs):
396 def addpline(self, x, y, idline, **kwargs):
397 lines = self.ax.lines
397 lines = self.ax.lines
398
398
399 if idline in self.idlineList:
399 if idline in self.idlineList:
400 self.__driver.set_linedata(self.ax, x, y, idline)
400 self.__driver.set_linedata(self.ax, x, y, idline)
401
401
402 if idline not in(self.idlineList):
402 if idline not in(self.idlineList):
403 self.__driver.addpline(self.ax, x, y, **kwargs)
403 self.__driver.addpline(self.ax, x, y, **kwargs)
404 self.idlineList.append(idline)
404 self.idlineList.append(idline)
405
405
406 return
406 return
407
407
408 def pmultiline(self, x, y,
408 def pmultiline(self, x, y,
409 xmin=None, xmax=None,
409 xmin=None, xmax=None,
410 ymin=None, ymax=None,
410 ymin=None, ymax=None,
411 xlabel='', ylabel='',
411 xlabel='', ylabel='',
412 title='',
412 title='',
413 **kwargs):
413 **kwargs):
414
414
415 if self.__firsttime:
415 if self.__firsttime:
416
416
417 if xmin == None: xmin = numpy.nanmin(x)
417 if xmin == None: xmin = numpy.nanmin(x)
418 if xmax == None: xmax = numpy.nanmax(x)
418 if xmax == None: xmax = numpy.nanmax(x)
419 if ymin == None: ymin = numpy.nanmin(y)
419 if ymin == None: ymin = numpy.nanmin(y)
420 if ymax == None: ymax = numpy.nanmax(y)
420 if ymax == None: ymax = numpy.nanmax(y)
421
421
422 self.plot = self.__driver.createPmultiline(self.ax, x, y,
422 self.plot = self.__driver.createPmultiline(self.ax, x, y,
423 xmin, xmax,
423 xmin, xmax,
424 ymin, ymax,
424 ymin, ymax,
425 xlabel=xlabel,
425 xlabel=xlabel,
426 ylabel=ylabel,
426 ylabel=ylabel,
427 title=title,
427 title=title,
428 **kwargs)
428 **kwargs)
429 self.__firsttime = False
429 self.__firsttime = False
430 return
430 return
431
431
432 self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel,
432 self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel,
433 ylabel=ylabel,
433 ylabel=ylabel,
434 title=title)
434 title=title)
435
435
436 # self.__driver.pause()
436 # self.__driver.pause()
437
437
438 def pmultilineyaxis(self, x, y,
438 def pmultilineyaxis(self, x, y,
439 xmin=None, xmax=None,
439 xmin=None, xmax=None,
440 ymin=None, ymax=None,
440 ymin=None, ymax=None,
441 xlabel='', ylabel='',
441 xlabel='', ylabel='',
442 title='',
442 title='',
443 **kwargs):
443 **kwargs):
444
444
445 if self.__firsttime:
445 if self.__firsttime:
446
446
447 if xmin == None: xmin = numpy.nanmin(x)
447 if xmin == None: xmin = numpy.nanmin(x)
448 if xmax == None: xmax = numpy.nanmax(x)
448 if xmax == None: xmax = numpy.nanmax(x)
449 if ymin == None: ymin = numpy.nanmin(y)
449 if ymin == None: ymin = numpy.nanmin(y)
450 if ymax == None: ymax = numpy.nanmax(y)
450 if ymax == None: ymax = numpy.nanmax(y)
451
451
452 self.plot = self.__driver.createPmultilineYAxis(self.ax, x, y,
452 self.plot = self.__driver.createPmultilineYAxis(self.ax, x, y,
453 xmin, xmax,
453 xmin, xmax,
454 ymin, ymax,
454 ymin, ymax,
455 xlabel=xlabel,
455 xlabel=xlabel,
456 ylabel=ylabel,
456 ylabel=ylabel,
457 title=title,
457 title=title,
458 **kwargs)
458 **kwargs)
459 if self.xmin == None: self.xmin = xmin
459 if self.xmin == None: self.xmin = xmin
460 if self.xmax == None: self.xmax = xmax
460 if self.xmax == None: self.xmax = xmax
461 if self.ymin == None: self.ymin = ymin
461 if self.ymin == None: self.ymin = ymin
462 if self.ymax == None: self.ymax = ymax
462 if self.ymax == None: self.ymax = ymax
463
463
464 self.__firsttime = False
464 self.__firsttime = False
465 return
465 return
466
466
467 self.__driver.pmultilineyaxis(self.plot, x, y, xlabel=xlabel,
467 self.__driver.pmultilineyaxis(self.plot, x, y, xlabel=xlabel,
468 ylabel=ylabel,
468 ylabel=ylabel,
469 title=title)
469 title=title)
470
470
471 # self.__driver.pause()
471 # self.__driver.pause()
472
472
473 def pcolor(self, x, y, z,
473 def pcolor(self, x, y, z,
474 xmin=None, xmax=None,
474 xmin=None, xmax=None,
475 ymin=None, ymax=None,
475 ymin=None, ymax=None,
476 zmin=None, zmax=None,
476 zmin=None, zmax=None,
477 xlabel='', ylabel='',
477 xlabel='', ylabel='',
478 title='', colormap='jet',
478 title='', colormap='jet',
479 **kwargs):
479 **kwargs):
480
480
481 """
481 """
482 Input:
482 Input:
483 x :
483 x :
484 y :
484 y :
485 x :
485 x :
486 xmin :
486 xmin :
487 xmax :
487 xmax :
488 ymin :
488 ymin :
489 ymax :
489 ymax :
490 zmin :
490 zmin :
491 zmax :
491 zmax :
492 xlabel :
492 xlabel :
493 ylabel :
493 ylabel :
494 title :
494 title :
495 **kwargs : Los parametros aceptados son
495 **kwargs : Los parametros aceptados son
496 ticksize=9,
496 ticksize=9,
497 cblabel=''
497 cblabel=''
498 """
498 """
499
499
500 #Decimating data
500 #Decimating data
501 xlen = len(x)
501 xlen = len(x)
502 ylen = len(y)
502 ylen = len(y)
503
503
504 decimationx = int(xlen/self.__MAXNUMX) + 1
504 decimationx = int(xlen/self.__MAXNUMX) + 1
505 decimationy = int(ylen/self.__MAXNUMY) + 1
505 decimationy = int(ylen/self.__MAXNUMY) + 1
506
506
507
507
508 x_buffer = x#[::decimationx]
508 x_buffer = x#[::decimationx]
509 y_buffer = y#[::decimationy]
509 y_buffer = y#[::decimationy]
510 z_buffer = z#[::decimationx, ::decimationy]
510 z_buffer = z#[::decimationx, ::decimationy]
511 #===================================================
511 #===================================================
512
512
513 if self.__firsttime:
513 if self.__firsttime:
514
514
515 if xmin == None: xmin = numpy.nanmin(x)
515 if xmin == None: xmin = numpy.nanmin(x)
516 if xmax == None: xmax = numpy.nanmax(x)
516 if xmax == None: xmax = numpy.nanmax(x)
517 if ymin == None: ymin = numpy.nanmin(y)
517 if ymin == None: ymin = numpy.nanmin(y)
518 if ymax == None: ymax = numpy.nanmax(y)
518 if ymax == None: ymax = numpy.nanmax(y)
519 if zmin == None: zmin = numpy.nanmin(z)
519 if zmin == None: zmin = numpy.nanmin(z)
520 if zmax == None: zmax = numpy.nanmax(z)
520 if zmax == None: zmax = numpy.nanmax(z)
521
521
522
522
523 self.plot = self.__driver.createPcolor(self.ax, x_buffer,
523 self.plot = self.__driver.createPcolor(self.ax, x_buffer,
524 y_buffer,
524 y_buffer,
525 z_buffer,
525 z_buffer,
526 xmin, xmax,
526 xmin, xmax,
527 ymin, ymax,
527 ymin, ymax,
528 zmin, zmax,
528 zmin, zmax,
529 xlabel=xlabel,
529 xlabel=xlabel,
530 ylabel=ylabel,
530 ylabel=ylabel,
531 title=title,
531 title=title,
532 colormap=colormap,
532 colormap=colormap,
533 **kwargs)
533 **kwargs)
534
534
535 if self.xmin == None: self.xmin = xmin
535 if self.xmin == None: self.xmin = xmin
536 if self.xmax == None: self.xmax = xmax
536 if self.xmax == None: self.xmax = xmax
537 if self.ymin == None: self.ymin = ymin
537 if self.ymin == None: self.ymin = ymin
538 if self.ymax == None: self.ymax = ymax
538 if self.ymax == None: self.ymax = ymax
539 if self.zmin == None: self.zmin = zmin
539 if self.zmin == None: self.zmin = zmin
540 if self.zmax == None: self.zmax = zmax
540 if self.zmax == None: self.zmax = zmax
541
541
542 self.__firsttime = False
542 self.__firsttime = False
543 return
543 return
544
544
545 self.__driver.pcolor(self.plot,
545 self.__driver.pcolor(self.plot,
546 z_buffer,
546 z_buffer,
547 xlabel=xlabel,
547 xlabel=xlabel,
548 ylabel=ylabel,
548 ylabel=ylabel,
549 title=title)
549 title=title)
550
550
551 # self.__driver.pause()
551 # self.__driver.pause()
552
552
553 def pcolorbuffer(self, x, y, z,
553 def pcolorbuffer(self, x, y, z,
554 xmin=None, xmax=None,
554 xmin=None, xmax=None,
555 ymin=None, ymax=None,
555 ymin=None, ymax=None,
556 zmin=None, zmax=None,
556 zmin=None, zmax=None,
557 xlabel='', ylabel='',
557 xlabel='', ylabel='',
558 title='', rti = True, colormap='jet',
558 title='', rti = True, colormap='jet',
559 maxNumX = None, maxNumY = None,
559 maxNumX = None, maxNumY = None,
560 **kwargs):
560 **kwargs):
561
561
562 if maxNumX == None:
562 if maxNumX == None:
563 maxNumX = self.__MAXNUMTIME
563 maxNumX = self.__MAXNUMTIME
564
564
565 if maxNumY == None:
565 if maxNumY == None:
566 maxNumY = self.__MAXNUMY
566 maxNumY = self.__MAXNUMY
567
567
568 if self.__firsttime:
568 if self.__firsttime:
569 self.z_buffer = z
569 self.z_buffer = z
570 self.x_buffer = numpy.hstack((self.x_buffer, x))
570 self.x_buffer = numpy.hstack((self.x_buffer, x))
571
571
572 if xmin == None: xmin = numpy.nanmin(x)
572 if xmin == None: xmin = numpy.nanmin(x)
573 if xmax == None: xmax = numpy.nanmax(x)
573 if xmax == None: xmax = numpy.nanmax(x)
574 if ymin == None: ymin = numpy.nanmin(y)
574 if ymin == None: ymin = numpy.nanmin(y)
575 if ymax == None: ymax = numpy.nanmax(y)
575 if ymax == None: ymax = numpy.nanmax(y)
576 if zmin == None: zmin = numpy.nanmin(z)
576 if zmin == None: zmin = numpy.nanmin(z)
577 if zmax == None: zmax = numpy.nanmax(z)
577 if zmax == None: zmax = numpy.nanmax(z)
578
578
579 self.plot = self.__driver.createPcolor(self.ax, self.x_buffer, y, z,
579 self.plot = self.__driver.createPcolor(self.ax, self.x_buffer, y, z,
580 xmin, xmax,
580 xmin, xmax,
581 ymin, ymax,
581 ymin, ymax,
582 zmin, zmax,
582 zmin, zmax,
583 xlabel=xlabel,
583 xlabel=xlabel,
584 ylabel=ylabel,
584 ylabel=ylabel,
585 title=title,
585 title=title,
586 colormap=colormap,
586 colormap=colormap,
587 **kwargs)
587 **kwargs)
588
588
589 if self.xmin == None: self.xmin = xmin
589 if self.xmin == None: self.xmin = xmin
590 if self.xmax == None: self.xmax = xmax
590 if self.xmax == None: self.xmax = xmax
591 if self.ymin == None: self.ymin = ymin
591 if self.ymin == None: self.ymin = ymin
592 if self.ymax == None: self.ymax = ymax
592 if self.ymax == None: self.ymax = ymax
593 if self.zmin == None: self.zmin = zmin
593 if self.zmin == None: self.zmin = zmin
594 if self.zmax == None: self.zmax = zmax
594 if self.zmax == None: self.zmax = zmax
595
595
596 self.__firsttime = False
596 self.__firsttime = False
597 return
597 return
598
598
599 self.x_buffer = numpy.hstack((self.x_buffer[:-1], x[0], x[-1]))
599 self.x_buffer = numpy.hstack((self.x_buffer[:-1], x[0], x[-1]))
600 self.z_buffer = numpy.hstack((self.z_buffer, z))
600 self.z_buffer = numpy.hstack((self.z_buffer, z))
601 z_buffer = self.z_buffer.reshape(-1,len(y))
601 z_buffer = self.z_buffer.reshape(-1,len(y))
602
602
603 #Decimating data
603 #Decimating data
604 xlen = len(self.x_buffer)
604 xlen = len(self.x_buffer)
605 ylen = len(y)
605 ylen = len(y)
606
606
607 decimationx = int(xlen/maxNumX) + 1
607 decimationx = int(xlen/maxNumX) + 1
608 decimationy = int(ylen/maxNumY) + 1
608 decimationy = int(ylen/maxNumY) + 1
609
609
610 x_buffer = self.x_buffer#[::decimationx]
610 x_buffer = self.x_buffer#[::decimationx]
611 y_buffer = y#[::decimationy]
611 y_buffer = y#[::decimationy]
612 z_buffer = z_buffer#[::decimationx, ::decimationy]
612 z_buffer = z_buffer#[::decimationx, ::decimationy]
613 #===================================================
613 #===================================================
614
614
615 x_buffer, y_buffer, z_buffer = self.__fillGaps(x_buffer, y_buffer, z_buffer)
615 x_buffer, y_buffer, z_buffer = self.__fillGaps(x_buffer, y_buffer, z_buffer)
616
616
617 self.__driver.addpcolorbuffer(self.ax, x_buffer, y_buffer, z_buffer, self.zmin, self.zmax,
617 self.__driver.addpcolorbuffer(self.ax, x_buffer, y_buffer, z_buffer, self.zmin, self.zmax,
618 xlabel=xlabel,
618 xlabel=xlabel,
619 ylabel=ylabel,
619 ylabel=ylabel,
620 title=title,
620 title=title,
621 colormap=colormap)
621 colormap=colormap)
622
622
623 # self.__driver.pause()
623 # self.__driver.pause()
624
624
625 def polar(self, x, y,
625 def polar(self, x, y,
626 title='', xlabel='',ylabel='',**kwargs):
626 title='', xlabel='',ylabel='',**kwargs):
627
627
628 if self.__firsttime:
628 if self.__firsttime:
629 self.plot = self.__driver.createPolar(self.ax, x, y, title = title, xlabel = xlabel, ylabel = ylabel)
629 self.plot = self.__driver.createPolar(self.ax, x, y, title = title, xlabel = xlabel, ylabel = ylabel)
630 self.__firsttime = False
630 self.__firsttime = False
631 self.x_buffer = x
631 self.x_buffer = x
632 self.y_buffer = y
632 self.y_buffer = y
633 return
633 return
634
634
635 self.x_buffer = numpy.hstack((self.x_buffer,x))
635 self.x_buffer = numpy.hstack((self.x_buffer,x))
636 self.y_buffer = numpy.hstack((self.y_buffer,y))
636 self.y_buffer = numpy.hstack((self.y_buffer,y))
637 self.__driver.polar(self.plot, self.x_buffer, self.y_buffer, xlabel=xlabel,
637 self.__driver.polar(self.plot, self.x_buffer, self.y_buffer, xlabel=xlabel,
638 ylabel=ylabel,
638 ylabel=ylabel,
639 title=title)
639 title=title)
640
640
641 # self.__driver.pause()
641 # self.__driver.pause()
642
642
643 def __fillGaps(self, x_buffer, y_buffer, z_buffer):
643 def __fillGaps(self, x_buffer, y_buffer, z_buffer):
644
644
645 if x_buffer.shape[0] < 2:
645 if x_buffer.shape[0] < 2:
646 return x_buffer, y_buffer, z_buffer
646 return x_buffer, y_buffer, z_buffer
647
647
648 deltas = x_buffer[1:] - x_buffer[0:-1]
648 deltas = x_buffer[1:] - x_buffer[0:-1]
649 x_median = numpy.median(deltas)
649 x_median = numpy.median(deltas)
650
650
651 index = numpy.where(deltas > 5*x_median)
651 index = numpy.where(deltas > 5*x_median)
652
652
653 if len(index[0]) != 0:
653 if len(index[0]) != 0:
654 z_buffer[index[0],::] = self.__missing
654 z_buffer[index[0],::] = self.__missing
655 z_buffer = numpy.ma.masked_inside(z_buffer,0.99*self.__missing,1.01*self.__missing)
655 z_buffer = numpy.ma.masked_inside(z_buffer,0.99*self.__missing,1.01*self.__missing)
656
656
657 return x_buffer, y_buffer, z_buffer
657 return x_buffer, y_buffer, z_buffer
@@ -1,188 +1,187
1 import os
1 import os
2 import datetime
2 import datetime
3 import numpy
3 import numpy
4 import copy
4 import copy
5
5 from schainpy.model import *
6 from figure import Figure, isRealtime
6 from figure import Figure, isRealtime
7
7
8 class CorrelationPlot(Figure):
8 class CorrelationPlot(Figure):
9
10 isConfig = None
9 isConfig = None
11 __nsubplots = None
10 __nsubplots = None
12
11
13 WIDTHPROF = None
12 WIDTHPROF = None
14 HEIGHTPROF = None
13 HEIGHTPROF = None
15 PREFIX = 'corr'
14 PREFIX = 'corr'
16
15
17 def __init__(self, **kwargs):
16 def __init__(self, **kwargs):
18 Figure.__init__(self, **kwargs)
17 Figure.__init__(self, **kwargs)
19 self.isConfig = False
18 self.isConfig = False
20 self.__nsubplots = 1
19 self.__nsubplots = 1
21
20
22 self.WIDTH = 280
21 self.WIDTH = 280
23 self.HEIGHT = 250
22 self.HEIGHT = 250
24 self.WIDTHPROF = 120
23 self.WIDTHPROF = 120
25 self.HEIGHTPROF = 0
24 self.HEIGHTPROF = 0
26 self.counter_imagwr = 0
25 self.counter_imagwr = 0
27
26
28 self.PLOT_CODE = 1
27 self.PLOT_CODE = 1
29 self.FTP_WEI = None
28 self.FTP_WEI = None
30 self.EXP_CODE = None
29 self.EXP_CODE = None
31 self.SUB_EXP_CODE = None
30 self.SUB_EXP_CODE = None
32 self.PLOT_POS = None
31 self.PLOT_POS = None
33
32
34 def getSubplots(self):
33 def getSubplots(self):
35
34
36 ncol = int(numpy.sqrt(self.nplots)+0.9)
35 ncol = int(numpy.sqrt(self.nplots)+0.9)
37 nrow = int(self.nplots*1./ncol + 0.9)
36 nrow = int(self.nplots*1./ncol + 0.9)
38
37
39 return nrow, ncol
38 return nrow, ncol
40
39
41 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
40 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
42
41
43 showprofile = False
42 showprofile = False
44 self.__showprofile = showprofile
43 self.__showprofile = showprofile
45 self.nplots = nplots
44 self.nplots = nplots
46
45
47 ncolspan = 1
46 ncolspan = 1
48 colspan = 1
47 colspan = 1
49 if showprofile:
48 if showprofile:
50 ncolspan = 3
49 ncolspan = 3
51 colspan = 2
50 colspan = 2
52 self.__nsubplots = 2
51 self.__nsubplots = 2
53
52
54 self.createFigure(id = id,
53 self.createFigure(id = id,
55 wintitle = wintitle,
54 wintitle = wintitle,
56 widthplot = self.WIDTH + self.WIDTHPROF,
55 widthplot = self.WIDTH + self.WIDTHPROF,
57 heightplot = self.HEIGHT + self.HEIGHTPROF,
56 heightplot = self.HEIGHT + self.HEIGHTPROF,
58 show=show)
57 show=show)
59
58
60 nrow, ncol = self.getSubplots()
59 nrow, ncol = self.getSubplots()
61
60
62 counter = 0
61 counter = 0
63 for y in range(nrow):
62 for y in range(nrow):
64 for x in range(ncol):
63 for x in range(ncol):
65
64
66 if counter >= self.nplots:
65 if counter >= self.nplots:
67 break
66 break
68
67
69 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
68 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
70
69
71 if showprofile:
70 if showprofile:
72 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
71 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
73
72
74 counter += 1
73 counter += 1
75
74
76 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
75 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
77 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
76 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
78 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
77 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
79 server=None, folder=None, username=None, password=None,
78 server=None, folder=None, username=None, password=None,
80 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
79 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
81
80
82 """
81 """
83
82
84 Input:
83 Input:
85 dataOut :
84 dataOut :
86 id :
85 id :
87 wintitle :
86 wintitle :
88 channelList :
87 channelList :
89 showProfile :
88 showProfile :
90 xmin : None,
89 xmin : None,
91 xmax : None,
90 xmax : None,
92 ymin : None,
91 ymin : None,
93 ymax : None,
92 ymax : None,
94 zmin : None,
93 zmin : None,
95 zmax : None
94 zmax : None
96 """
95 """
97
96
98 if dataOut.flagNoData:
97 if dataOut.flagNoData:
99 return None
98 return None
100
99
101 if realtime:
100 if realtime:
102 if not(isRealtime(utcdatatime = dataOut.utctime)):
101 if not(isRealtime(utcdatatime = dataOut.utctime)):
103 print 'Skipping this plot function'
102 print 'Skipping this plot function'
104 return
103 return
105
104
106 if channelList == None:
105 if channelList == None:
107 channelIndexList = dataOut.channelIndexList
106 channelIndexList = dataOut.channelIndexList
108 else:
107 else:
109 channelIndexList = []
108 channelIndexList = []
110 for channel in channelList:
109 for channel in channelList:
111 if channel not in dataOut.channelList:
110 if channel not in dataOut.channelList:
112 raise ValueError, "Channel %d is not in dataOut.channelList"
111 raise ValueError, "Channel %d is not in dataOut.channelList"
113 channelIndexList.append(dataOut.channelList.index(channel))
112 channelIndexList.append(dataOut.channelList.index(channel))
114
113
115 factor = dataOut.normFactor
114 factor = dataOut.normFactor
116 lenfactor = factor.shape[1]
115 lenfactor = factor.shape[1]
117 x = dataOut.getLagTRange(1)
116 x = dataOut.getLagTRange(1)
118 y = dataOut.getHeiRange()
117 y = dataOut.getHeiRange()
119
118
120 z = copy.copy(dataOut.data_corr[:,:,0,:])
119 z = copy.copy(dataOut.data_corr[:,:,0,:])
121 for i in range(dataOut.data_corr.shape[0]):
120 for i in range(dataOut.data_corr.shape[0]):
122 z[i,:,:] = z[i,:,:]/factor[i,:]
121 z[i,:,:] = z[i,:,:]/factor[i,:]
123 zdB = numpy.abs(z)
122 zdB = numpy.abs(z)
124
123
125 avg = numpy.average(z, axis=1)
124 avg = numpy.average(z, axis=1)
126 # avg = numpy.nanmean(z, axis=1)
125 # avg = numpy.nanmean(z, axis=1)
127 # noise = dataOut.noise/factor
126 # noise = dataOut.noise/factor
128
127
129 #thisDatetime = dataOut.datatime
128 #thisDatetime = dataOut.datatime
130 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
129 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
131 title = wintitle + " Correlation"
130 title = wintitle + " Correlation"
132 xlabel = "Lag T (s)"
131 xlabel = "Lag T (s)"
133 ylabel = "Range (Km)"
132 ylabel = "Range (Km)"
134
133
135 if not self.isConfig:
134 if not self.isConfig:
136
135
137 nplots = dataOut.data_corr.shape[0]
136 nplots = dataOut.data_corr.shape[0]
138
137
139 self.setup(id=id,
138 self.setup(id=id,
140 nplots=nplots,
139 nplots=nplots,
141 wintitle=wintitle,
140 wintitle=wintitle,
142 showprofile=showprofile,
141 showprofile=showprofile,
143 show=show)
142 show=show)
144
143
145 if xmin == None: xmin = numpy.nanmin(x)
144 if xmin == None: xmin = numpy.nanmin(x)
146 if xmax == None: xmax = numpy.nanmax(x)
145 if xmax == None: xmax = numpy.nanmax(x)
147 if ymin == None: ymin = numpy.nanmin(y)
146 if ymin == None: ymin = numpy.nanmin(y)
148 if ymax == None: ymax = numpy.nanmax(y)
147 if ymax == None: ymax = numpy.nanmax(y)
149 if zmin == None: zmin = 0
148 if zmin == None: zmin = 0
150 if zmax == None: zmax = 1
149 if zmax == None: zmax = 1
151
150
152 self.FTP_WEI = ftp_wei
151 self.FTP_WEI = ftp_wei
153 self.EXP_CODE = exp_code
152 self.EXP_CODE = exp_code
154 self.SUB_EXP_CODE = sub_exp_code
153 self.SUB_EXP_CODE = sub_exp_code
155 self.PLOT_POS = plot_pos
154 self.PLOT_POS = plot_pos
156
155
157 self.isConfig = True
156 self.isConfig = True
158
157
159 self.setWinTitle(title)
158 self.setWinTitle(title)
160
159
161 for i in range(self.nplots):
160 for i in range(self.nplots):
162 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
161 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
163 title = "Channel %d and %d: : %s" %(dataOut.pairsList[i][0],dataOut.pairsList[i][1] , str_datetime)
162 title = "Channel %d and %d: : %s" %(dataOut.pairsList[i][0],dataOut.pairsList[i][1] , str_datetime)
164 axes = self.axesList[i*self.__nsubplots]
163 axes = self.axesList[i*self.__nsubplots]
165 axes.pcolor(x, y, zdB[i,:,:],
164 axes.pcolor(x, y, zdB[i,:,:],
166 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
165 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
167 xlabel=xlabel, ylabel=ylabel, title=title,
166 xlabel=xlabel, ylabel=ylabel, title=title,
168 ticksize=9, cblabel='')
167 ticksize=9, cblabel='')
169
168
170 # if self.__showprofile:
169 # if self.__showprofile:
171 # axes = self.axesList[i*self.__nsubplots +1]
170 # axes = self.axesList[i*self.__nsubplots +1]
172 # axes.pline(avgdB[i], y,
171 # axes.pline(avgdB[i], y,
173 # xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
172 # xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
174 # xlabel='dB', ylabel='', title='',
173 # xlabel='dB', ylabel='', title='',
175 # ytick_visible=False,
174 # ytick_visible=False,
176 # grid='x')
175 # grid='x')
177 #
176 #
178 # noiseline = numpy.repeat(noisedB[i], len(y))
177 # noiseline = numpy.repeat(noisedB[i], len(y))
179 # axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
178 # axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
180
179
181 self.draw()
180 self.draw()
182
181
183 self.save(figpath=figpath,
182 self.save(figpath=figpath,
184 figfile=figfile,
183 figfile=figfile,
185 save=save,
184 save=save,
186 ftp=ftp,
185 ftp=ftp,
187 wr_period=wr_period,
186 wr_period=wr_period,
188 thisDatetime=thisDatetime)
187 thisDatetime=thisDatetime)
@@ -1,775 +1,964
1
1
2 import os
2 import os
3 import zmq
3 import zmq
4 import time
4 import time
5 import numpy
5 import numpy
6 import datetime
6 import datetime
7 import numpy as np
7 import numpy as np
8 import matplotlib
8 import matplotlib
9 import glob
9 matplotlib.use('TkAgg')
10 matplotlib.use('TkAgg')
10 import matplotlib.pyplot as plt
11 import matplotlib.pyplot as plt
11 from mpl_toolkits.axes_grid1 import make_axes_locatable
12 from mpl_toolkits.axes_grid1 import make_axes_locatable
12 from matplotlib.ticker import FuncFormatter, LinearLocator
13 from matplotlib.ticker import FuncFormatter, LinearLocator
13 from multiprocessing import Process
14 from multiprocessing import Process
14
15
15 from schainpy.model.proc.jroproc_base import Operation
16 from schainpy.model.proc.jroproc_base import Operation
16
17
17 plt.ion()
18 plt.ion()
18
19
19 func = lambda x, pos: ('%s') %(datetime.datetime.fromtimestamp(x).strftime('%H:%M'))
20 func = lambda x, pos: ('%s') %(datetime.datetime.fromtimestamp(x).strftime('%H:%M'))
21 fromtimestamp = lambda x, mintime : (datetime.datetime.utcfromtimestamp(mintime).replace(hour=(x + 5), minute=0) - d1970).total_seconds()
22
20
23
21 d1970 = datetime.datetime(1970,1,1)
24 d1970 = datetime.datetime(1970,1,1)
22
25
23 class PlotData(Operation, Process):
26 class PlotData(Operation, Process):
24
27
25 CODE = 'Figure'
28 CODE = 'Figure'
26 colormap = 'jro'
29 colormap = 'jro'
27 CONFLATE = False
30 CONFLATE = False
28 __MAXNUMX = 80
31 __MAXNUMX = 80
29 __missing = 1E30
32 __missing = 1E30
30
33
31 def __init__(self, **kwargs):
34 def __init__(self, **kwargs):
32
35
33 Operation.__init__(self, plot=True, **kwargs)
36 Operation.__init__(self, plot=True, **kwargs)
34 Process.__init__(self)
37 Process.__init__(self)
35 self.kwargs['code'] = self.CODE
38 self.kwargs['code'] = self.CODE
36 self.mp = False
39 self.mp = False
37 self.dataOut = None
40 self.dataOut = None
38 self.isConfig = False
41 self.isConfig = False
39 self.figure = None
42 self.figure = None
40 self.axes = []
43 self.axes = []
41 self.localtime = kwargs.pop('localtime', True)
44 self.localtime = kwargs.pop('localtime', True)
42 self.show = kwargs.get('show', True)
45 self.show = kwargs.get('show', True)
43 self.save = kwargs.get('save', False)
46 self.save = kwargs.get('save', False)
44 self.colormap = kwargs.get('colormap', self.colormap)
47 self.colormap = kwargs.get('colormap', self.colormap)
45 self.colormap_coh = kwargs.get('colormap_coh', 'jet')
48 self.colormap_coh = kwargs.get('colormap_coh', 'jet')
46 self.colormap_phase = kwargs.get('colormap_phase', 'RdBu_r')
49 self.colormap_phase = kwargs.get('colormap_phase', 'RdBu_r')
47 self.showprofile = kwargs.get('showprofile', True)
50 self.showprofile = kwargs.get('showprofile', True)
48 self.title = kwargs.get('wintitle', '')
51 self.title = kwargs.get('wintitle', '')
49 self.xaxis = kwargs.get('xaxis', 'frequency')
52 self.xaxis = kwargs.get('xaxis', 'frequency')
50 self.zmin = kwargs.get('zmin', None)
53 self.zmin = kwargs.get('zmin', None)
51 self.zmax = kwargs.get('zmax', None)
54 self.zmax = kwargs.get('zmax', None)
52 self.xmin = kwargs.get('xmin', None)
55 self.xmin = kwargs.get('xmin', None)
53 self.xmax = kwargs.get('xmax', None)
56 self.xmax = kwargs.get('xmax', None)
54 self.xrange = kwargs.get('xrange', 24)
57 self.xrange = kwargs.get('xrange', 24)
55 self.ymin = kwargs.get('ymin', None)
58 self.ymin = kwargs.get('ymin', None)
56 self.ymax = kwargs.get('ymax', None)
59 self.ymax = kwargs.get('ymax', None)
57 self.__MAXNUMY = kwargs.get('decimation', 80)
60 self.__MAXNUMY = kwargs.get('decimation', 5000)
58 self.throttle_value = 5
61 self.throttle_value = 5
59 self.times = []
62 self.times = []
60 #self.interactive = self.kwargs['parent']
63 #self.interactive = self.kwargs['parent']
61
64
65 '''
66 this new parameter is created to plot data from varius channels at different figures
67 1. crear una lista de figuras donde se puedan plotear las figuras,
68 2. dar las opciones de configuracion a cada figura, estas opciones son iguales para ambas figuras
69 3. probar?
70 '''
71 self.ind_plt_ch = kwargs.get('ind_plt_ch', False)
72 self.figurelist = None
73
62
74
63 def fill_gaps(self, x_buffer, y_buffer, z_buffer):
75 def fill_gaps(self, x_buffer, y_buffer, z_buffer):
64
76
65 if x_buffer.shape[0] < 2:
77 if x_buffer.shape[0] < 2:
66 return x_buffer, y_buffer, z_buffer
78 return x_buffer, y_buffer, z_buffer
67
79
68 deltas = x_buffer[1:] - x_buffer[0:-1]
80 deltas = x_buffer[1:] - x_buffer[0:-1]
69 x_median = np.median(deltas)
81 x_median = np.median(deltas)
70
82
71 index = np.where(deltas > 5*x_median)
83 index = np.where(deltas > 5*x_median)
72
84
73 if len(index[0]) != 0:
85 if len(index[0]) != 0:
74 z_buffer[::, index[0], ::] = self.__missing
86 z_buffer[::, index[0], ::] = self.__missing
75 z_buffer = np.ma.masked_inside(z_buffer,
87 z_buffer = np.ma.masked_inside(z_buffer,
76 0.99*self.__missing,
88 0.99*self.__missing,
77 1.01*self.__missing)
89 1.01*self.__missing)
78
90
79 return x_buffer, y_buffer, z_buffer
91 return x_buffer, y_buffer, z_buffer
80
92
81 def decimate(self):
93 def decimate(self):
82
94
83 # dx = int(len(self.x)/self.__MAXNUMX) + 1
95 # dx = int(len(self.x)/self.__MAXNUMX) + 1
84 dy = int(len(self.y)/self.__MAXNUMY) + 1
96 dy = int(len(self.y)/self.__MAXNUMY) + 1
85
97
86 # x = self.x[::dx]
98 # x = self.x[::dx]
87 x = self.x
99 x = self.x
88 y = self.y[::dy]
100 y = self.y[::dy]
89 z = self.z[::, ::, ::dy]
101 z = self.z[::, ::, ::dy]
90
102
91 return x, y, z
103 return x, y, z
92
104
105 '''
106 JM:
107 elimana las otras imagenes generadas debido a que lso workers no llegan en orden y le pueden
108 poner otro tiempo a la figura q no necesariamente es el ultimo.
109 Solo se realiza cuando termina la imagen.
110 Problemas:
111
112 File "/home/ci-81/workspace/schainv2.3/schainpy/model/graphics/jroplot_data.py", line 145, in __plot
113 for n, eachfigure in enumerate(self.figurelist):
114 TypeError: 'NoneType' object is not iterable
115
116 '''
117 def deleteanotherfiles(self):
118 figurenames=[]
119 if self.figurelist != None:
120 for n, eachfigure in enumerate(self.figurelist):
121 #add specific name for each channel in channelList
122 ghostfigname = os.path.join(self.save, '{}_{}_{}'.format(self.titles[n].replace(' ',''),self.CODE,
123 datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d')))
124 figname = os.path.join(self.save, '{}_{}_{}.png'.format(self.titles[n].replace(' ',''),self.CODE,
125 datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S')))
126
127 for ghostfigure in glob.glob(ghostfigname+'*'): #ghostfigure will adopt all posible names of figures
128 if ghostfigure != figname:
129 os.remove(ghostfigure)
130 print 'Removing GhostFigures:' , figname
131 else :
132 '''Erasing ghost images for just on******************'''
133 ghostfigname = os.path.join(self.save, '{}_{}'.format(self.CODE,datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d')))
134 figname = os.path.join(self.save, '{}_{}.png'.format(self.CODE,datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S')))
135 for ghostfigure in glob.glob(ghostfigname+'*'): #ghostfigure will adopt all posible names of figures
136 if ghostfigure != figname:
137 os.remove(ghostfigure)
138 print 'Removing GhostFigures:' , figname
139
93 def __plot(self):
140 def __plot(self):
94
141
95 print 'plotting...{}'.format(self.CODE)
142 print 'plotting...{}'.format(self.CODE)
96
143 if self.ind_plt_ch is False : #standard
97 if self.show:
144 if self.show:
98 self.figure.show()
145 self.figure.show()
99
146 self.plot()
100 self.plot()
147 plt.tight_layout()
101 plt.tight_layout()
148 self.figure.canvas.manager.set_window_title('{} {} - {}'.format(self.title, self.CODE.upper(),
102 self.figure.canvas.manager.set_window_title('{} {} - {}'.format(self.title, self.CODE.upper(),
103 datetime.datetime.fromtimestamp(self.max_time).strftime('%Y/%m/%d')))
149 datetime.datetime.fromtimestamp(self.max_time).strftime('%Y/%m/%d')))
150 else :
151 print 'len(self.figurelist): ',len(self.figurelist)
152 for n, eachfigure in enumerate(self.figurelist):
153 if self.show:
154 eachfigure.show()
155
156 self.plot()
157 eachfigure.tight_layout() # ajuste de cada subplot
158 eachfigure.canvas.manager.set_window_title('{} {} - {}'.format(self.title[n], self.CODE.upper(),
159 datetime.datetime.fromtimestamp(self.max_time).strftime('%Y/%m/%d')))
160
161 # if self.save:
162 # if self.ind_plt_ch is False : #standard
163 # figname = os.path.join(self.save, '{}_{}.png'.format(self.CODE,
164 # datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S')))
165 # print 'Saving figure: {}'.format(figname)
166 # self.figure.savefig(figname)
167 # else :
168 # for n, eachfigure in enumerate(self.figurelist):
169 # #add specific name for each channel in channelList
170 # figname = os.path.join(self.save, '{}_{}_{}.png'.format(self.titles[n],self.CODE,
171 # datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S')))
172 #
173 # print 'Saving figure: {}'.format(figname)
174 # eachfigure.savefig(figname)
175
176 if self.ind_plt_ch is False :
177 self.figure.canvas.draw()
178 else :
179 for eachfigure in self.figurelist:
180 eachfigure.canvas.draw()
104
181
105 if self.save:
182 if self.save:
106 figname = os.path.join(self.save, '{}_{}.png'.format(self.CODE,
183 if self.ind_plt_ch is False : #standard
107 datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S')))
184 figname = os.path.join(self.save, '{}_{}.png'.format(self.CODE,
108 print 'Saving figure: {}'.format(figname)
185 datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S')))
109 self.figure.savefig(figname)
186 print 'Saving figure: {}'.format(figname)
187 self.figure.savefig(figname)
188 else :
189 for n, eachfigure in enumerate(self.figurelist):
190 #add specific name for each channel in channelList
191 figname = os.path.join(self.save, '{}_{}_{}.png'.format(self.titles[n].replace(' ',''),self.CODE,
192 datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S')))
193
194 print 'Saving figure: {}'.format(figname)
195 eachfigure.savefig(figname)
110
196
111 self.figure.canvas.draw()
112
197
113 def plot(self):
198 def plot(self):
114
199
115 print 'plotting...{}'.format(self.CODE.upper())
200 print 'plotting...{}'.format(self.CODE.upper())
116 return
201 return
117
202
118 def run(self):
203 def run(self):
119
204
120 print '[Starting] {}'.format(self.name)
205 print '[Starting] {}'.format(self.name)
121
206
122 context = zmq.Context()
207 context = zmq.Context()
123 receiver = context.socket(zmq.SUB)
208 receiver = context.socket(zmq.SUB)
124 receiver.setsockopt(zmq.SUBSCRIBE, '')
209 receiver.setsockopt(zmq.SUBSCRIBE, '')
125 receiver.setsockopt(zmq.CONFLATE, self.CONFLATE)
210 receiver.setsockopt(zmq.CONFLATE, self.CONFLATE)
126
211
127 if 'server' in self.kwargs['parent']:
212 if 'server' in self.kwargs['parent']:
128 receiver.connect('ipc:///tmp/{}.plots'.format(self.kwargs['parent']['server']))
213 receiver.connect('ipc:///tmp/{}.plots'.format(self.kwargs['parent']['server']))
129 else:
214 else:
130 receiver.connect("ipc:///tmp/zmq.plots")
215 receiver.connect("ipc:///tmp/zmq.plots")
131
216
132 seconds_passed = 0
217 seconds_passed = 0
133
218
134 while True:
219 while True:
135 try:
220 try:
136 self.data = receiver.recv_pyobj(flags=zmq.NOBLOCK)#flags=zmq.NOBLOCK
221 self.data = receiver.recv_pyobj(flags=zmq.NOBLOCK)#flags=zmq.NOBLOCK
137 self.started = self.data['STARTED']
222 self.started = self.data['STARTED']
138 self.dataOut = self.data['dataOut']
223 self.dataOut = self.data['dataOut']
139
224
140 if (len(self.times) < len(self.data['times']) and not self.started and self.data['ENDED']):
225 if (len(self.times) < len(self.data['times']) and not self.started and self.data['ENDED']):
141 continue
226 continue
142
227
143 self.times = self.data['times']
228 self.times = self.data['times']
144 self.times.sort()
229 self.times.sort()
145 self.throttle_value = self.data['throttle']
230 self.throttle_value = self.data['throttle']
146 self.min_time = self.times[0]
231 self.min_time = self.times[0]
147 self.max_time = self.times[-1]
232 self.max_time = self.times[-1]
148
233
149 if self.isConfig is False:
234 if self.isConfig is False:
150 print 'setting up'
235 print 'setting up'
151 self.setup()
236 self.setup()
152 self.isConfig = True
237 self.isConfig = True
153 self.__plot()
238 self.__plot()
154
239
155 if self.data['ENDED'] is True:
240 if self.data['ENDED'] is True:
156 print '********GRAPHIC ENDED********'
241 print '********GRAPHIC ENDED********'
157 self.ended = True
242 self.ended = True
158 self.isConfig = False
243 self.isConfig = False
159 self.__plot()
244 self.__plot()
245 self.deleteanotherfiles() #CLPDG
160 elif seconds_passed >= self.data['throttle']:
246 elif seconds_passed >= self.data['throttle']:
161 print 'passed', seconds_passed
247 print 'passed', seconds_passed
162 self.__plot()
248 self.__plot()
163 seconds_passed = 0
249 seconds_passed = 0
164
250
165 except zmq.Again as e:
251 except zmq.Again as e:
166 print 'Waiting for data...'
252 print 'Waiting for data...'
167 plt.pause(2)
253 plt.pause(2)
168 seconds_passed += 2
254 seconds_passed += 2
169
255
170 def close(self):
256 def close(self):
171 if self.dataOut:
257 if self.dataOut:
172 self.__plot()
258 self.__plot()
173
259
174
260
175 class PlotSpectraData(PlotData):
261 class PlotSpectraData(PlotData):
176
262
177 CODE = 'spc'
263 CODE = 'spc'
178 colormap = 'jro'
264 colormap = 'jro'
179 CONFLATE = False
265 CONFLATE = False
180
266
181 def setup(self):
267 def setup(self):
182
268
183 ncolspan = 1
269 ncolspan = 1
184 colspan = 1
270 colspan = 1
185 self.ncols = int(numpy.sqrt(self.dataOut.nChannels)+0.9)
271 self.ncols = int(numpy.sqrt(self.dataOut.nChannels)+0.9)
186 self.nrows = int(self.dataOut.nChannels*1./self.ncols + 0.9)
272 self.nrows = int(self.dataOut.nChannels*1./self.ncols + 0.9)
187 self.width = 3.6*self.ncols
273 self.width = 3.6*self.ncols
188 self.height = 3.2*self.nrows
274 self.height = 3.2*self.nrows
189 if self.showprofile:
275 if self.showprofile:
190 ncolspan = 3
276 ncolspan = 3
191 colspan = 2
277 colspan = 2
192 self.width += 1.2*self.ncols
278 self.width += 1.2*self.ncols
193
279
194 self.ylabel = 'Range [Km]'
280 self.ylabel = 'Range [Km]'
195 self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList]
281 self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList]
196
282
197 if self.figure is None:
283 if self.figure is None:
198 self.figure = plt.figure(figsize=(self.width, self.height),
284 self.figure = plt.figure(figsize=(self.width, self.height),
199 edgecolor='k',
285 edgecolor='k',
200 facecolor='w')
286 facecolor='w')
201 else:
287 else:
202 self.figure.clf()
288 self.figure.clf()
203
289
204 n = 0
290 n = 0
205 for y in range(self.nrows):
291 for y in range(self.nrows):
206 for x in range(self.ncols):
292 for x in range(self.ncols):
207 if n >= self.dataOut.nChannels:
293 if n >= self.dataOut.nChannels:
208 break
294 break
209 ax = plt.subplot2grid((self.nrows, self.ncols*ncolspan), (y, x*ncolspan), 1, colspan)
295 ax = plt.subplot2grid((self.nrows, self.ncols*ncolspan), (y, x*ncolspan), 1, colspan)
210 if self.showprofile:
296 if self.showprofile:
211 ax.ax_profile = plt.subplot2grid((self.nrows, self.ncols*ncolspan), (y, x*ncolspan+colspan), 1, 1)
297 ax.ax_profile = plt.subplot2grid((self.nrows, self.ncols*ncolspan), (y, x*ncolspan+colspan), 1, 1)
212
298
213 ax.firsttime = True
299 ax.firsttime = True
214 self.axes.append(ax)
300 self.axes.append(ax)
215 n += 1
301 n += 1
216
302
217 def plot(self):
303 def plot(self):
218
304
219 if self.xaxis == "frequency":
305 if self.xaxis == "frequency":
220 x = self.dataOut.getFreqRange(1)/1000.
306 x = self.dataOut.getFreqRange(1)/1000.
221 xlabel = "Frequency (kHz)"
307 xlabel = "Frequency (kHz)"
222 elif self.xaxis == "time":
308 elif self.xaxis == "time":
223 x = self.dataOut.getAcfRange(1)
309 x = self.dataOut.getAcfRange(1)
224 xlabel = "Time (ms)"
310 xlabel = "Time (ms)"
225 else:
311 else:
226 x = self.dataOut.getVelRange(1)
312 x = self.dataOut.getVelRange(1)
227 xlabel = "Velocity (m/s)"
313 xlabel = "Velocity (m/s)"
228
314
229 y = self.dataOut.getHeiRange()
315 y = self.dataOut.getHeiRange()
230 z = self.data[self.CODE]
316 z = self.data[self.CODE]
231
317
232 for n, ax in enumerate(self.axes):
318 for n, ax in enumerate(self.axes):
233
234 if ax.firsttime:
319 if ax.firsttime:
235 self.xmax = self.xmax if self.xmax else np.nanmax(x)
320 self.xmax = self.xmax if self.xmax else np.nanmax(x)
236 self.xmin = self.xmin if self.xmin else -self.xmax
321 self.xmin = self.xmin if self.xmin else -self.xmax
237 self.ymin = self.ymin if self.ymin else np.nanmin(y)
322 self.ymin = self.ymin if self.ymin else np.nanmin(y)
238 self.ymax = self.ymax if self.ymax else np.nanmax(y)
323 self.ymax = self.ymax if self.ymax else np.nanmax(y)
239 self.zmin = self.zmin if self.zmin else np.nanmin(z)
324 self.zmin = self.zmin if self.zmin else np.nanmin(z)
240 self.zmax = self.zmax if self.zmax else np.nanmax(z)
325 self.zmax = self.zmax if self.zmax else np.nanmax(z)
241 ax.plot = ax.pcolormesh(x, y, z[n].T,
326 ax.plot = ax.pcolormesh(x, y, z[n].T,
242 vmin=self.zmin,
327 vmin=self.zmin,
243 vmax=self.zmax,
328 vmax=self.zmax,
244 cmap=plt.get_cmap(self.colormap)
329 cmap=plt.get_cmap(self.colormap)
245 )
330 )
246 divider = make_axes_locatable(ax)
331 divider = make_axes_locatable(ax)
247 cax = divider.new_horizontal(size='3%', pad=0.05)
332 cax = divider.new_horizontal(size='3%', pad=0.05)
248 self.figure.add_axes(cax)
333 self.figure.add_axes(cax)
249 plt.colorbar(ax.plot, cax)
334 plt.colorbar(ax.plot, cax)
250
335
251 ax.set_xlim(self.xmin, self.xmax)
336 ax.set_xlim(self.xmin, self.xmax)
252 ax.set_ylim(self.ymin, self.ymax)
337 ax.set_ylim(self.ymin, self.ymax)
253
338
254 ax.set_ylabel(self.ylabel)
339 ax.set_ylabel(self.ylabel)
255 ax.set_xlabel(xlabel)
340 ax.set_xlabel(xlabel)
256
341
257 ax.firsttime = False
342 ax.firsttime = False
258
343
259 if self.showprofile:
344 if self.showprofile:
260 ax.plot_profile= ax.ax_profile.plot(self.data['rti'][self.max_time][n], y)[0]
345 ax.plot_profile= ax.ax_profile.plot(self.data['rti'][self.max_time][n], y)[0]
261 ax.ax_profile.set_xlim(self.zmin, self.zmax)
346 ax.ax_profile.set_xlim(self.zmin, self.zmax)
262 ax.ax_profile.set_ylim(self.ymin, self.ymax)
347 ax.ax_profile.set_ylim(self.ymin, self.ymax)
263 ax.ax_profile.set_xlabel('dB')
348 ax.ax_profile.set_xlabel('dB')
264 ax.ax_profile.grid(b=True, axis='x')
349 ax.ax_profile.grid(b=True, axis='x')
265 ax.plot_noise = ax.ax_profile.plot(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y,
350 ax.plot_noise = ax.ax_profile.plot(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y,
266 color="k", linestyle="dashed", lw=2)[0]
351 color="k", linestyle="dashed", lw=2)[0]
267 [tick.set_visible(False) for tick in ax.ax_profile.get_yticklabels()]
352 [tick.set_visible(False) for tick in ax.ax_profile.get_yticklabels()]
268 else:
353 else:
269 ax.plot.set_array(z[n].T.ravel())
354 ax.plot.set_array(z[n].T.ravel())
270 if self.showprofile:
355 if self.showprofile:
271 ax.plot_profile.set_data(self.data['rti'][self.max_time][n], y)
356 ax.plot_profile.set_data(self.data['rti'][self.max_time][n], y)
272 ax.plot_noise.set_data(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y)
357 ax.plot_noise.set_data(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y)
273
358
274 ax.set_title('{} - Noise: {:.2f} dB'.format(self.titles[n], self.data['noise'][self.max_time][n]),
359 ax.set_title('{} - Noise: {:.2f} dB'.format(self.titles[n], self.data['noise'][self.max_time][n]),
275 size=8)
360 size=8)
276 self.saveTime = self.max_time
361 self.saveTime = self.max_time
277
362
278
363
279 class PlotCrossSpectraData(PlotData):
364 class PlotCrossSpectraData(PlotData):
280
365
281 CODE = 'cspc'
366 CODE = 'cspc'
282 zmin_coh = None
367 zmin_coh = None
283 zmax_coh = None
368 zmax_coh = None
284 zmin_phase = None
369 zmin_phase = None
285 zmax_phase = None
370 zmax_phase = None
286 CONFLATE = False
371 CONFLATE = False
287
372
288 def setup(self):
373 def setup(self):
289
374
290 ncolspan = 1
375 ncolspan = 1
291 colspan = 1
376 colspan = 1
292 self.ncols = 2
377 self.ncols = 2
293 self.nrows = self.dataOut.nPairs
378 self.nrows = self.dataOut.nPairs
294 self.width = 3.6*self.ncols
379 self.width = 3.6*self.ncols
295 self.height = 3.2*self.nrows
380 self.height = 3.2*self.nrows
296
381
297 self.ylabel = 'Range [Km]'
382 self.ylabel = 'Range [Km]'
298 self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList]
383 self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList]
299
384
300 if self.figure is None:
385 if self.figure is None:
301 self.figure = plt.figure(figsize=(self.width, self.height),
386 self.figure = plt.figure(figsize=(self.width, self.height),
302 edgecolor='k',
387 edgecolor='k',
303 facecolor='w')
388 facecolor='w')
304 else:
389 else:
305 self.figure.clf()
390 self.figure.clf()
306
391
307 for y in range(self.nrows):
392 for y in range(self.nrows):
308 for x in range(self.ncols):
393 for x in range(self.ncols):
309 ax = plt.subplot2grid((self.nrows, self.ncols), (y, x), 1, 1)
394 ax = plt.subplot2grid((self.nrows, self.ncols), (y, x), 1, 1)
310 ax.firsttime = True
395 ax.firsttime = True
311 self.axes.append(ax)
396 self.axes.append(ax)
312
397
313 def plot(self):
398 def plot(self):
314
399
315 if self.xaxis == "frequency":
400 if self.xaxis == "frequency":
316 x = self.dataOut.getFreqRange(1)/1000.
401 x = self.dataOut.getFreqRange(1)/1000.
317 xlabel = "Frequency (kHz)"
402 xlabel = "Frequency (kHz)"
318 elif self.xaxis == "time":
403 elif self.xaxis == "time":
319 x = self.dataOut.getAcfRange(1)
404 x = self.dataOut.getAcfRange(1)
320 xlabel = "Time (ms)"
405 xlabel = "Time (ms)"
321 else:
406 else:
322 x = self.dataOut.getVelRange(1)
407 x = self.dataOut.getVelRange(1)
323 xlabel = "Velocity (m/s)"
408 xlabel = "Velocity (m/s)"
324
409
325 y = self.dataOut.getHeiRange()
410 y = self.dataOut.getHeiRange()
326 z_coh = self.data['cspc_coh']
411 z_coh = self.data['cspc_coh']
327 z_phase = self.data['cspc_phase']
412 z_phase = self.data['cspc_phase']
328
413
329 for n in range(self.nrows):
414 for n in range(self.nrows):
330 ax = self.axes[2*n]
415 ax = self.axes[2*n]
331 ax1 = self.axes[2*n+1]
416 ax1 = self.axes[2*n+1]
332 if ax.firsttime:
417 if ax.firsttime:
333 self.xmax = self.xmax if self.xmax else np.nanmax(x)
418 self.xmax = self.xmax if self.xmax else np.nanmax(x)
334 self.xmin = self.xmin if self.xmin else -self.xmax
419 self.xmin = self.xmin if self.xmin else -self.xmax
335 self.ymin = self.ymin if self.ymin else np.nanmin(y)
420 self.ymin = self.ymin if self.ymin else np.nanmin(y)
336 self.ymax = self.ymax if self.ymax else np.nanmax(y)
421 self.ymax = self.ymax if self.ymax else np.nanmax(y)
337 self.zmin_coh = self.zmin_coh if self.zmin_coh else 0.0
422 self.zmin_coh = self.zmin_coh if self.zmin_coh else 0.0
338 self.zmax_coh = self.zmax_coh if self.zmax_coh else 1.0
423 self.zmax_coh = self.zmax_coh if self.zmax_coh else 1.0
339 self.zmin_phase = self.zmin_phase if self.zmin_phase else -180
424 self.zmin_phase = self.zmin_phase if self.zmin_phase else -180
340 self.zmax_phase = self.zmax_phase if self.zmax_phase else 180
425 self.zmax_phase = self.zmax_phase if self.zmax_phase else 180
341
426
342 ax.plot = ax.pcolormesh(x, y, z_coh[n].T,
427 ax.plot = ax.pcolormesh(x, y, z_coh[n].T,
343 vmin=self.zmin_coh,
428 vmin=self.zmin_coh,
344 vmax=self.zmax_coh,
429 vmax=self.zmax_coh,
345 cmap=plt.get_cmap(self.colormap_coh)
430 cmap=plt.get_cmap(self.colormap_coh)
346 )
431 )
347 divider = make_axes_locatable(ax)
432 divider = make_axes_locatable(ax)
348 cax = divider.new_horizontal(size='3%', pad=0.05)
433 cax = divider.new_horizontal(size='3%', pad=0.05)
349 self.figure.add_axes(cax)
434 self.figure.add_axes(cax)
350 plt.colorbar(ax.plot, cax)
435 plt.colorbar(ax.plot, cax)
351
436
352 ax.set_xlim(self.xmin, self.xmax)
437 ax.set_xlim(self.xmin, self.xmax)
353 ax.set_ylim(self.ymin, self.ymax)
438 ax.set_ylim(self.ymin, self.ymax)
354
439
355 ax.set_ylabel(self.ylabel)
440 ax.set_ylabel(self.ylabel)
356 ax.set_xlabel(xlabel)
441 ax.set_xlabel(xlabel)
357 ax.firsttime = False
442 ax.firsttime = False
358
443
359 ax1.plot = ax1.pcolormesh(x, y, z_phase[n].T,
444 ax1.plot = ax1.pcolormesh(x, y, z_phase[n].T,
360 vmin=self.zmin_phase,
445 vmin=self.zmin_phase,
361 vmax=self.zmax_phase,
446 vmax=self.zmax_phase,
362 cmap=plt.get_cmap(self.colormap_phase)
447 cmap=plt.get_cmap(self.colormap_phase)
363 )
448 )
364 divider = make_axes_locatable(ax1)
449 divider = make_axes_locatable(ax1)
365 cax = divider.new_horizontal(size='3%', pad=0.05)
450 cax = divider.new_horizontal(size='3%', pad=0.05)
366 self.figure.add_axes(cax)
451 self.figure.add_axes(cax)
367 plt.colorbar(ax1.plot, cax)
452 plt.colorbar(ax1.plot, cax)
368
453
369 ax1.set_xlim(self.xmin, self.xmax)
454 ax1.set_xlim(self.xmin, self.xmax)
370 ax1.set_ylim(self.ymin, self.ymax)
455 ax1.set_ylim(self.ymin, self.ymax)
371
456
372 ax1.set_ylabel(self.ylabel)
457 ax1.set_ylabel(self.ylabel)
373 ax1.set_xlabel(xlabel)
458 ax1.set_xlabel(xlabel)
374 ax1.firsttime = False
459 ax1.firsttime = False
375 else:
460 else:
376 ax.plot.set_array(z_coh[n].T.ravel())
461 ax.plot.set_array(z_coh[n].T.ravel())
377 ax1.plot.set_array(z_phase[n].T.ravel())
462 ax1.plot.set_array(z_phase[n].T.ravel())
378
463
379 ax.set_title('Coherence Ch{} * Ch{}'.format(self.dataOut.pairsList[n][0], self.dataOut.pairsList[n][1]), size=8)
464 ax.set_title('Coherence Ch{} * Ch{}'.format(self.dataOut.pairsList[n][0], self.dataOut.pairsList[n][1]), size=8)
380 ax1.set_title('Phase Ch{} * Ch{}'.format(self.dataOut.pairsList[n][0], self.dataOut.pairsList[n][1]), size=8)
465 ax1.set_title('Phase Ch{} * Ch{}'.format(self.dataOut.pairsList[n][0], self.dataOut.pairsList[n][1]), size=8)
381 self.saveTime = self.max_time
466 self.saveTime = self.max_time
382
467
383
468
384 class PlotSpectraMeanData(PlotSpectraData):
469 class PlotSpectraMeanData(PlotSpectraData):
385
470
386 CODE = 'spc_mean'
471 CODE = 'spc_mean'
387 colormap = 'jet'
472 colormap = 'jet'
388
473
389 def plot(self):
474 def plot(self):
390
475
391 if self.xaxis == "frequency":
476 if self.xaxis == "frequency":
392 x = self.dataOut.getFreqRange(1)/1000.
477 x = self.dataOut.getFreqRange(1)/1000.
393 xlabel = "Frequency (kHz)"
478 xlabel = "Frequency (kHz)"
394 elif self.xaxis == "time":
479 elif self.xaxis == "time":
395 x = self.dataOut.getAcfRange(1)
480 x = self.dataOut.getAcfRange(1)
396 xlabel = "Time (ms)"
481 xlabel = "Time (ms)"
397 else:
482 else:
398 x = self.dataOut.getVelRange(1)
483 x = self.dataOut.getVelRange(1)
399 xlabel = "Velocity (m/s)"
484 xlabel = "Velocity (m/s)"
400
485
401 y = self.dataOut.getHeiRange()
486 y = self.dataOut.getHeiRange()
402 z = self.data['spc']
487 z = self.data['spc']
403 mean = self.data['mean'][self.max_time]
488 mean = self.data['mean'][self.max_time]
404
489
405 for n, ax in enumerate(self.axes):
490 for n, ax in enumerate(self.axes):
406
491
407 if ax.firsttime:
492 if ax.firsttime:
408 self.xmax = self.xmax if self.xmax else np.nanmax(x)
493 self.xmax = self.xmax if self.xmax else np.nanmax(x)
409 self.xmin = self.xmin if self.xmin else -self.xmax
494 self.xmin = self.xmin if self.xmin else -self.xmax
410 self.ymin = self.ymin if self.ymin else np.nanmin(y)
495 self.ymin = self.ymin if self.ymin else np.nanmin(y)
411 self.ymax = self.ymax if self.ymax else np.nanmax(y)
496 self.ymax = self.ymax if self.ymax else np.nanmax(y)
412 self.zmin = self.zmin if self.zmin else np.nanmin(z)
497 self.zmin = self.zmin if self.zmin else np.nanmin(z)
413 self.zmax = self.zmax if self.zmax else np.nanmax(z)
498 self.zmax = self.zmax if self.zmax else np.nanmax(z)
414 ax.plt = ax.pcolormesh(x, y, z[n].T,
499 ax.plt = ax.pcolormesh(x, y, z[n].T,
415 vmin=self.zmin,
500 vmin=self.zmin,
416 vmax=self.zmax,
501 vmax=self.zmax,
417 cmap=plt.get_cmap(self.colormap)
502 cmap=plt.get_cmap(self.colormap)
418 )
503 )
419 ax.plt_dop = ax.plot(mean[n], y,
504 ax.plt_dop = ax.plot(mean[n], y,
420 color='k')[0]
505 color='k')[0]
421
506
422 divider = make_axes_locatable(ax)
507 divider = make_axes_locatable(ax)
423 cax = divider.new_horizontal(size='3%', pad=0.05)
508 cax = divider.new_horizontal(size='3%', pad=0.05)
424 self.figure.add_axes(cax)
509 self.figure.add_axes(cax)
425 plt.colorbar(ax.plt, cax)
510 plt.colorbar(ax.plt, cax)
426
511
427 ax.set_xlim(self.xmin, self.xmax)
512 ax.set_xlim(self.xmin, self.xmax)
428 ax.set_ylim(self.ymin, self.ymax)
513 ax.set_ylim(self.ymin, self.ymax)
429
514
430 ax.set_ylabel(self.ylabel)
515 ax.set_ylabel(self.ylabel)
431 ax.set_xlabel(xlabel)
516 ax.set_xlabel(xlabel)
432
517
433 ax.firsttime = False
518 ax.firsttime = False
434
519
435 if self.showprofile:
520 if self.showprofile:
436 ax.plt_profile= ax.ax_profile.plot(self.data['rti'][self.max_time][n], y)[0]
521 ax.plt_profile= ax.ax_profile.plot(self.data['rti'][self.max_time][n], y)[0]
437 ax.ax_profile.set_xlim(self.zmin, self.zmax)
522 ax.ax_profile.set_xlim(self.zmin, self.zmax)
438 ax.ax_profile.set_ylim(self.ymin, self.ymax)
523 ax.ax_profile.set_ylim(self.ymin, self.ymax)
439 ax.ax_profile.set_xlabel('dB')
524 ax.ax_profile.set_xlabel('dB')
440 ax.ax_profile.grid(b=True, axis='x')
525 ax.ax_profile.grid(b=True, axis='x')
441 ax.plt_noise = ax.ax_profile.plot(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y,
526 ax.plt_noise = ax.ax_profile.plot(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y,
442 color="k", linestyle="dashed", lw=2)[0]
527 color="k", linestyle="dashed", lw=2)[0]
443 [tick.set_visible(False) for tick in ax.ax_profile.get_yticklabels()]
528 [tick.set_visible(False) for tick in ax.ax_profile.get_yticklabels()]
444 else:
529 else:
445 ax.plt.set_array(z[n].T.ravel())
530 ax.plt.set_array(z[n].T.ravel())
446 ax.plt_dop.set_data(mean[n], y)
531 ax.plt_dop.set_data(mean[n], y)
447 if self.showprofile:
532 if self.showprofile:
448 ax.plt_profile.set_data(self.data['rti'][self.max_time][n], y)
533 ax.plt_profile.set_data(self.data['rti'][self.max_time][n], y)
449 ax.plt_noise.set_data(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y)
534 ax.plt_noise.set_data(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y)
450
535
451 ax.set_title('{} - Noise: {:.2f} dB'.format(self.titles[n], self.data['noise'][self.max_time][n]),
536 ax.set_title('{} - Noise: {:.2f} dB'.format(self.titles[n], self.data['noise'][self.max_time][n]),
452 size=8)
537 size=8)
453 self.saveTime = self.max_time
538 self.saveTime = self.max_time
454
539
455
540
456 class PlotRTIData(PlotData):
541 class PlotRTIData(PlotData):
457
542
458 CODE = 'rti'
543 CODE = 'rti'
459 colormap = 'jro'
544 colormap = 'jro'
460
545
461 def setup(self):
546 def setup(self):
462 self.ncols = 1
547 self.ncols = 1
463 self.nrows = self.dataOut.nChannels
548 self.nrows = self.dataOut.nChannels
464 self.width = 10
549 self.width = 10
465 self.height = 2.2*self.nrows if self.nrows<6 else 12
550 #TODO : arreglar la altura de la figura, esta hardcodeada.
551 #Se arreglo, testear!
552 if self.ind_plt_ch:
553 self.height = 3.2#*self.nrows if self.nrows<6 else 12
554 else:
555 self.height = 2.2*self.nrows if self.nrows<6 else 12
556
557 '''
466 if self.nrows==1:
558 if self.nrows==1:
467 self.height += 1
559 self.height += 1
560 '''
468 self.ylabel = 'Range [Km]'
561 self.ylabel = 'Range [Km]'
469 self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList]
562 self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList]
470
563
471 if self.figure is None:
564 '''
472 self.figure = plt.figure(figsize=(self.width, self.height),
565 Logica:
473 edgecolor='k',
566 1) Si la variable ind_plt_ch es True, va a crear mas de 1 figura
474 facecolor='w')
567 2) guardamos "Figures" en una lista y "axes" en otra, quizas se deberia guardar el
475 else:
568 axis dentro de "Figures" como un diccionario.
476 self.figure.clf()
569 '''
477 self.axes = []
570 if self.ind_plt_ch is False: #standard mode
478
571
479 for n in range(self.nrows):
572 if self.figure is None: #solo para la priemra vez
480 ax = self.figure.add_subplot(self.nrows, self.ncols, n+1)
573 self.figure = plt.figure(figsize=(self.width, self.height),
481 ax.firsttime = True
574 edgecolor='k',
482 self.axes.append(ax)
575 facecolor='w')
483
576 else:
484 def plot(self):
577 self.figure.clf()
485
578 self.axes = []
486 self.x = np.array(self.times)
487 self.y = self.dataOut.getHeiRange()
488 self.z = []
489
490 for ch in range(self.nrows):
491 self.z.append([self.data[self.CODE][t][ch] for t in self.times])
492
579
493 self.z = np.array(self.z)
494 for n, ax in enumerate(self.axes):
495 x, y, z = self.fill_gaps(*self.decimate())
496 xmin = self.min_time
497 xmax = xmin+self.xrange*60*60
498 self.zmin = self.zmin if self.zmin else np.min(self.z)
499 self.zmax = self.zmax if self.zmax else np.max(self.z)
500 if ax.firsttime:
501 self.ymin = self.ymin if self.ymin else np.nanmin(self.y)
502 self.ymax = self.ymax if self.ymax else np.nanmax(self.y)
503 plot = ax.pcolormesh(x, y, z[n].T,
504 vmin=self.zmin,
505 vmax=self.zmax,
506 cmap=plt.get_cmap(self.colormap)
507 )
508 divider = make_axes_locatable(ax)
509 cax = divider.new_horizontal(size='2%', pad=0.05)
510 self.figure.add_axes(cax)
511 plt.colorbar(plot, cax)
512 ax.set_ylim(self.ymin, self.ymax)
513
580
514 ax.xaxis.set_major_formatter(FuncFormatter(func))
581 for n in range(self.nrows):
515 ax.xaxis.set_major_locator(LinearLocator(6))
582 ax = self.figure.add_subplot(self.nrows, self.ncols, n+1)
583 #ax = self.figure(n+1)
584 ax.firsttime = True
585 self.axes.append(ax)
516
586
517 ax.set_ylabel(self.ylabel)
587 else : #append one figure foreach channel in channelList
588 if self.figurelist == None:
589 self.figurelist = []
590 for n in range(self.nrows):
591 self.figure = plt.figure(figsize=(self.width, self.height),
592 edgecolor='k',
593 facecolor='w')
594 #add always one subplot
595 self.figurelist.append(self.figure)
596
597 else : # cada dia nuevo limpia el axes, pero mantiene el figure
598 for eachfigure in self.figurelist:
599 eachfigure.clf() # eliminaria todas las figuras de la lista?
600 self.axes = []
601
602 for eachfigure in self.figurelist:
603 ax = eachfigure.add_subplot(1,1,1) #solo 1 axis por figura
604 #ax = self.figure(n+1)
605 ax.firsttime = True
606 #Cada figura tiene un distinto puntero
607 self.axes.append(ax)
608 #plt.close(eachfigure)
518
609
519 # if self.xmin is None:
520 # xmin = self.min_time
521 # else:
522 # xmin = (datetime.datetime.combine(self.dataOut.datatime.date(),
523 # datetime.time(self.xmin, 0, 0))-d1970).total_seconds()
524
610
525 ax.set_xlim(xmin, xmax)
611 def plot(self):
526 ax.firsttime = False
527 else:
528 ax.collections.remove(ax.collections[0])
529 ax.set_xlim(xmin, xmax)
530 plot = ax.pcolormesh(x, y, z[n].T,
531 vmin=self.zmin,
532 vmax=self.zmax,
533 cmap=plt.get_cmap(self.colormap)
534 )
535 ax.set_title('{} {}'.format(self.titles[n],
536 datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')),
537 size=8)
538
612
539 self.saveTime = self.min_time
613 if self.ind_plt_ch is False: #standard mode
614 self.x = np.array(self.times)
615 self.y = self.dataOut.getHeiRange()
616 self.z = []
617
618 for ch in range(self.nrows):
619 self.z.append([self.data[self.CODE][t][ch] for t in self.times])
620
621 self.z = np.array(self.z)
622 for n, ax in enumerate(self.axes):
623 x, y, z = self.fill_gaps(*self.decimate())
624 if self.xmin is None:
625 xmin = self.min_time
626 else:
627 xmin = fromtimestamp(int(self.xmin), self.min_time)
628 if self.xmax is None:
629 xmax = xmin + self.xrange*60*60
630 else:
631 xmax = xmin + (self.xmax - self.xmin) * 60 * 60
632 self.zmin = self.zmin if self.zmin else np.min(self.z)
633 self.zmax = self.zmax if self.zmax else np.max(self.z)
634 if ax.firsttime:
635 self.ymin = self.ymin if self.ymin else np.nanmin(self.y)
636 self.ymax = self.ymax if self.ymax else np.nanmax(self.y)
637 plot = ax.pcolormesh(x, y, z[n].T,
638 vmin=self.zmin,
639 vmax=self.zmax,
640 cmap=plt.get_cmap(self.colormap)
641 )
642 divider = make_axes_locatable(ax)
643 cax = divider.new_horizontal(size='2%', pad=0.05)
644 self.figure.add_axes(cax)
645 plt.colorbar(plot, cax)
646 ax.set_ylim(self.ymin, self.ymax)
647 ax.xaxis.set_major_formatter(FuncFormatter(func))
648 ax.xaxis.set_major_locator(LinearLocator(6))
649 ax.set_ylabel(self.ylabel)
650 # if self.xmin is None:
651 # xmin = self.min_time
652 # else:
653 # xmin = (datetime.datetime.combine(self.dataOut.datatime.date(),
654 # datetime.time(self.xmin, 0, 0))-d1970).total_seconds()
655
656 ax.set_xlim(xmin, xmax)
657 ax.firsttime = False
658 else:
659 ax.collections.remove(ax.collections[0])
660 ax.set_xlim(xmin, xmax)
661 plot = ax.pcolormesh(x, y, z[n].T,
662 vmin=self.zmin,
663 vmax=self.zmax,
664 cmap=plt.get_cmap(self.colormap)
665 )
666 ax.set_title('{} {}'.format(self.titles[n],
667 datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')),
668 size=8)
669
670 self.saveTime = self.min_time
671 else :
672 self.x = np.array(self.times)
673 self.y = self.dataOut.getHeiRange()
674 self.z = []
675
676 for ch in range(self.nrows):
677 self.z.append([self.data[self.CODE][t][ch] for t in self.times])
678
679 self.z = np.array(self.z)
680 for n, eachfigure in enumerate(self.figurelist): #estaba ax in axes
681
682 x, y, z = self.fill_gaps(*self.decimate())
683 xmin = self.min_time
684 xmax = xmin+self.xrange*60*60
685 self.zmin = self.zmin if self.zmin else np.min(self.z)
686 self.zmax = self.zmax if self.zmax else np.max(self.z)
687 if self.axes[n].firsttime:
688 self.ymin = self.ymin if self.ymin else np.nanmin(self.y)
689 self.ymax = self.ymax if self.ymax else np.nanmax(self.y)
690 plot = self.axes[n].pcolormesh(x, y, z[n].T,
691 vmin=self.zmin,
692 vmax=self.zmax,
693 cmap=plt.get_cmap(self.colormap)
694 )
695 divider = make_axes_locatable(self.axes[n])
696 cax = divider.new_horizontal(size='2%', pad=0.05)
697 eachfigure.add_axes(cax)
698 #self.figure2.add_axes(cax)
699 plt.colorbar(plot, cax)
700 self.axes[n].set_ylim(self.ymin, self.ymax)
701
702 self.axes[n].xaxis.set_major_formatter(FuncFormatter(func))
703 self.axes[n].xaxis.set_major_locator(LinearLocator(6))
704
705 self.axes[n].set_ylabel(self.ylabel)
706
707 if self.xmin is None:
708 xmin = self.min_time
709 else:
710 xmin = (datetime.datetime.combine(self.dataOut.datatime.date(),
711 datetime.time(self.xmin, 0, 0))-d1970).total_seconds()
712
713 self.axes[n].set_xlim(xmin, xmax)
714 self.axes[n].firsttime = False
715 else:
716 self.axes[n].collections.remove(self.axes[n].collections[0])
717 self.axes[n].set_xlim(xmin, xmax)
718 plot = self.axes[n].pcolormesh(x, y, z[n].T,
719 vmin=self.zmin,
720 vmax=self.zmax,
721 cmap=plt.get_cmap(self.colormap)
722 )
723 self.axes[n].set_title('{} {}'.format(self.titles[n],
724 datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')),
725 size=8)
726
727 self.saveTime = self.min_time
540
728
541
729
542 class PlotCOHData(PlotRTIData):
730 class PlotCOHData(PlotRTIData):
543
731
544 CODE = 'coh'
732 CODE = 'coh'
545
733
546 def setup(self):
734 def setup(self):
547
735
548 self.ncols = 1
736 self.ncols = 1
549 self.nrows = self.dataOut.nPairs
737 self.nrows = self.dataOut.nPairs
550 self.width = 10
738 self.width = 10
551 self.height = 2.2*self.nrows if self.nrows<6 else 12
739 self.height = 2.2*self.nrows if self.nrows<6 else 12
740 self.ind_plt_ch = False #just for coherence and phase
552 if self.nrows==1:
741 if self.nrows==1:
553 self.height += 1
742 self.height += 1
554 self.ylabel = 'Range [Km]'
743 self.ylabel = 'Range [Km]'
555 self.titles = ['{} Ch{} * Ch{}'.format(self.CODE.upper(), x[0], x[1]) for x in self.dataOut.pairsList]
744 self.titles = ['{} Ch{} * Ch{}'.format(self.CODE.upper(), x[0], x[1]) for x in self.dataOut.pairsList]
556
745
557 if self.figure is None:
746 if self.figure is None:
558 self.figure = plt.figure(figsize=(self.width, self.height),
747 self.figure = plt.figure(figsize=(self.width, self.height),
559 edgecolor='k',
748 edgecolor='k',
560 facecolor='w')
749 facecolor='w')
561 else:
750 else:
562 self.figure.clf()
751 self.figure.clf()
563 self.axes = []
752 self.axes = []
564
753
565 for n in range(self.nrows):
754 for n in range(self.nrows):
566 ax = self.figure.add_subplot(self.nrows, self.ncols, n+1)
755 ax = self.figure.add_subplot(self.nrows, self.ncols, n+1)
567 ax.firsttime = True
756 ax.firsttime = True
568 self.axes.append(ax)
757 self.axes.append(ax)
569
758
570
759
571 class PlotNoiseData(PlotData):
760 class PlotNoiseData(PlotData):
572 CODE = 'noise'
761 CODE = 'noise'
573
762
574 def setup(self):
763 def setup(self):
575
764
576 self.ncols = 1
765 self.ncols = 1
577 self.nrows = 1
766 self.nrows = 1
578 self.width = 10
767 self.width = 10
579 self.height = 3.2
768 self.height = 3.2
580 self.ylabel = 'Intensity [dB]'
769 self.ylabel = 'Intensity [dB]'
581 self.titles = ['Noise']
770 self.titles = ['Noise']
582
771
583 if self.figure is None:
772 if self.figure is None:
584 self.figure = plt.figure(figsize=(self.width, self.height),
773 self.figure = plt.figure(figsize=(self.width, self.height),
585 edgecolor='k',
774 edgecolor='k',
586 facecolor='w')
775 facecolor='w')
587 else:
776 else:
588 self.figure.clf()
777 self.figure.clf()
589 self.axes = []
778 self.axes = []
590
779
591 self.ax = self.figure.add_subplot(self.nrows, self.ncols, 1)
780 self.ax = self.figure.add_subplot(self.nrows, self.ncols, 1)
592 self.ax.firsttime = True
781 self.ax.firsttime = True
593
782
594 def plot(self):
783 def plot(self):
595
784
596 x = self.times
785 x = self.times
597 xmin = self.min_time
786 xmin = self.min_time
598 xmax = xmin+self.xrange*60*60
787 xmax = xmin+self.xrange*60*60
599 if self.ax.firsttime:
788 if self.ax.firsttime:
600 for ch in self.dataOut.channelList:
789 for ch in self.dataOut.channelList:
601 y = [self.data[self.CODE][t][ch] for t in self.times]
790 y = [self.data[self.CODE][t][ch] for t in self.times]
602 self.ax.plot(x, y, lw=1, label='Ch{}'.format(ch))
791 self.ax.plot(x, y, lw=1, label='Ch{}'.format(ch))
603 self.ax.firsttime = False
792 self.ax.firsttime = False
604 self.ax.xaxis.set_major_formatter(FuncFormatter(func))
793 self.ax.xaxis.set_major_formatter(FuncFormatter(func))
605 self.ax.xaxis.set_major_locator(LinearLocator(6))
794 self.ax.xaxis.set_major_locator(LinearLocator(6))
606 self.ax.set_ylabel(self.ylabel)
795 self.ax.set_ylabel(self.ylabel)
607 plt.legend()
796 plt.legend()
608 else:
797 else:
609 for ch in self.dataOut.channelList:
798 for ch in self.dataOut.channelList:
610 y = [self.data[self.CODE][t][ch] for t in self.times]
799 y = [self.data[self.CODE][t][ch] for t in self.times]
611 self.ax.lines[ch].set_data(x, y)
800 self.ax.lines[ch].set_data(x, y)
612
801
613 self.ax.set_xlim(xmin, xmax)
802 self.ax.set_xlim(xmin, xmax)
614 self.ax.set_ylim(min(y)-5, max(y)+5)
803 self.ax.set_ylim(min(y)-5, max(y)+5)
615 self.saveTime = self.min_time
804 self.saveTime = self.min_time
616
805
617
806
618 class PlotWindProfilerData(PlotRTIData):
807 class PlotWindProfilerData(PlotRTIData):
619
808
620 CODE = 'wind'
809 CODE = 'wind'
621 colormap = 'seismic'
810 colormap = 'seismic'
622
811
623 def setup(self):
812 def setup(self):
624 self.ncols = 1
813 self.ncols = 1
625 self.nrows = self.dataOut.data_output.shape[0]
814 self.nrows = self.dataOut.data_output.shape[0]
626 self.width = 10
815 self.width = 10
627 self.height = 2.2*self.nrows
816 self.height = 2.2*self.nrows
628 self.ylabel = 'Height [Km]'
817 self.ylabel = 'Height [Km]'
629 self.titles = ['Zonal Wind' ,'Meridional Wind', 'Vertical Wind']
818 self.titles = ['Zonal Wind' ,'Meridional Wind', 'Vertical Wind']
630 self.clabels = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)']
819 self.clabels = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)']
631 self.windFactor = [1, 1, 100]
820 self.windFactor = [1, 1, 100]
632
821
633 if self.figure is None:
822 if self.figure is None:
634 self.figure = plt.figure(figsize=(self.width, self.height),
823 self.figure = plt.figure(figsize=(self.width, self.height),
635 edgecolor='k',
824 edgecolor='k',
636 facecolor='w')
825 facecolor='w')
637 else:
826 else:
638 self.figure.clf()
827 self.figure.clf()
639 self.axes = []
828 self.axes = []
640
829
641 for n in range(self.nrows):
830 for n in range(self.nrows):
642 ax = self.figure.add_subplot(self.nrows, self.ncols, n+1)
831 ax = self.figure.add_subplot(self.nrows, self.ncols, n+1)
643 ax.firsttime = True
832 ax.firsttime = True
644 self.axes.append(ax)
833 self.axes.append(ax)
645
834
646 def plot(self):
835 def plot(self):
647
836
648 self.x = np.array(self.times)
837 self.x = np.array(self.times)
649 self.y = self.dataOut.heightList
838 self.y = self.dataOut.heightList
650 self.z = []
839 self.z = []
651
840
652 for ch in range(self.nrows):
841 for ch in range(self.nrows):
653 self.z.append([self.data['output'][t][ch] for t in self.times])
842 self.z.append([self.data['output'][t][ch] for t in self.times])
654
843
655 self.z = np.array(self.z)
844 self.z = np.array(self.z)
656 self.z = numpy.ma.masked_invalid(self.z)
845 self.z = numpy.ma.masked_invalid(self.z)
657
846
658 cmap=plt.get_cmap(self.colormap)
847 cmap=plt.get_cmap(self.colormap)
659 cmap.set_bad('black', 1.)
848 cmap.set_bad('black', 1.)
660
849
661 for n, ax in enumerate(self.axes):
850 for n, ax in enumerate(self.axes):
662 x, y, z = self.fill_gaps(*self.decimate())
851 x, y, z = self.fill_gaps(*self.decimate())
663 xmin = self.min_time
852 xmin = self.min_time
664 xmax = xmin+self.xrange*60*60
853 xmax = xmin+self.xrange*60*60
665 if ax.firsttime:
854 if ax.firsttime:
666 self.ymin = self.ymin if self.ymin else np.nanmin(self.y)
855 self.ymin = self.ymin if self.ymin else np.nanmin(self.y)
667 self.ymax = self.ymax if self.ymax else np.nanmax(self.y)
856 self.ymax = self.ymax if self.ymax else np.nanmax(self.y)
668 self.zmax = self.zmax if self.zmax else numpy.nanmax(abs(self.z[:-1, :]))
857 self.zmax = self.zmax if self.zmax else numpy.nanmax(abs(self.z[:-1, :]))
669 self.zmin = self.zmin if self.zmin else -self.zmax
858 self.zmin = self.zmin if self.zmin else -self.zmax
670
859
671 plot = ax.pcolormesh(x, y, z[n].T*self.windFactor[n],
860 plot = ax.pcolormesh(x, y, z[n].T*self.windFactor[n],
672 vmin=self.zmin,
861 vmin=self.zmin,
673 vmax=self.zmax,
862 vmax=self.zmax,
674 cmap=cmap
863 cmap=cmap
675 )
864 )
676 divider = make_axes_locatable(ax)
865 divider = make_axes_locatable(ax)
677 cax = divider.new_horizontal(size='2%', pad=0.05)
866 cax = divider.new_horizontal(size='2%', pad=0.05)
678 self.figure.add_axes(cax)
867 self.figure.add_axes(cax)
679 cb = plt.colorbar(plot, cax)
868 cb = plt.colorbar(plot, cax)
680 cb.set_label(self.clabels[n])
869 cb.set_label(self.clabels[n])
681 ax.set_ylim(self.ymin, self.ymax)
870 ax.set_ylim(self.ymin, self.ymax)
682
871
683 ax.xaxis.set_major_formatter(FuncFormatter(func))
872 ax.xaxis.set_major_formatter(FuncFormatter(func))
684 ax.xaxis.set_major_locator(LinearLocator(6))
873 ax.xaxis.set_major_locator(LinearLocator(6))
685
874
686 ax.set_ylabel(self.ylabel)
875 ax.set_ylabel(self.ylabel)
687
876
688 ax.set_xlim(xmin, xmax)
877 ax.set_xlim(xmin, xmax)
689 ax.firsttime = False
878 ax.firsttime = False
690 else:
879 else:
691 ax.collections.remove(ax.collections[0])
880 ax.collections.remove(ax.collections[0])
692 ax.set_xlim(xmin, xmax)
881 ax.set_xlim(xmin, xmax)
693 plot = ax.pcolormesh(x, y, z[n].T*self.windFactor[n],
882 plot = ax.pcolormesh(x, y, z[n].T*self.windFactor[n],
694 vmin=self.zmin,
883 vmin=self.zmin,
695 vmax=self.zmax,
884 vmax=self.zmax,
696 cmap=plt.get_cmap(self.colormap)
885 cmap=plt.get_cmap(self.colormap)
697 )
886 )
698 ax.set_title('{} {}'.format(self.titles[n],
887 ax.set_title('{} {}'.format(self.titles[n],
699 datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')),
888 datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')),
700 size=8)
889 size=8)
701
890
702 self.saveTime = self.min_time
891 self.saveTime = self.min_time
703
892
704
893
705 class PlotSNRData(PlotRTIData):
894 class PlotSNRData(PlotRTIData):
706 CODE = 'snr'
895 CODE = 'snr'
707 colormap = 'jet'
896 colormap = 'jet'
708
897
709 class PlotDOPData(PlotRTIData):
898 class PlotDOPData(PlotRTIData):
710 CODE = 'dop'
899 CODE = 'dop'
711 colormap = 'jet'
900 colormap = 'jet'
712
901
713
902
714 class PlotPHASEData(PlotCOHData):
903 class PlotPHASEData(PlotCOHData):
715 CODE = 'phase'
904 CODE = 'phase'
716 colormap = 'seismic'
905 colormap = 'seismic'
717
906
718
907
719 class PlotSkyMapData(PlotData):
908 class PlotSkyMapData(PlotData):
720
909
721 CODE = 'met'
910 CODE = 'met'
722
911
723 def setup(self):
912 def setup(self):
724
913
725 self.ncols = 1
914 self.ncols = 1
726 self.nrows = 1
915 self.nrows = 1
727 self.width = 7.2
916 self.width = 7.2
728 self.height = 7.2
917 self.height = 7.2
729
918
730 self.xlabel = 'Zonal Zenith Angle (deg)'
919 self.xlabel = 'Zonal Zenith Angle (deg)'
731 self.ylabel = 'Meridional Zenith Angle (deg)'
920 self.ylabel = 'Meridional Zenith Angle (deg)'
732
921
733 if self.figure is None:
922 if self.figure is None:
734 self.figure = plt.figure(figsize=(self.width, self.height),
923 self.figure = plt.figure(figsize=(self.width, self.height),
735 edgecolor='k',
924 edgecolor='k',
736 facecolor='w')
925 facecolor='w')
737 else:
926 else:
738 self.figure.clf()
927 self.figure.clf()
739
928
740 self.ax = plt.subplot2grid((self.nrows, self.ncols), (0, 0), 1, 1, polar=True)
929 self.ax = plt.subplot2grid((self.nrows, self.ncols), (0, 0), 1, 1, polar=True)
741 self.ax.firsttime = True
930 self.ax.firsttime = True
742
931
743
932
744 def plot(self):
933 def plot(self):
745
934
746 arrayParameters = np.concatenate([self.data['param'][t] for t in self.times])
935 arrayParameters = np.concatenate([self.data['param'][t] for t in self.times])
747 error = arrayParameters[:,-1]
936 error = arrayParameters[:,-1]
748 indValid = numpy.where(error == 0)[0]
937 indValid = numpy.where(error == 0)[0]
749 finalMeteor = arrayParameters[indValid,:]
938 finalMeteor = arrayParameters[indValid,:]
750 finalAzimuth = finalMeteor[:,3]
939 finalAzimuth = finalMeteor[:,3]
751 finalZenith = finalMeteor[:,4]
940 finalZenith = finalMeteor[:,4]
752
941
753 x = finalAzimuth*numpy.pi/180
942 x = finalAzimuth*numpy.pi/180
754 y = finalZenith
943 y = finalZenith
755
944
756 if self.ax.firsttime:
945 if self.ax.firsttime:
757 self.ax.plot = self.ax.plot(x, y, 'bo', markersize=5)[0]
946 self.ax.plot = self.ax.plot(x, y, 'bo', markersize=5)[0]
758 self.ax.set_ylim(0,90)
947 self.ax.set_ylim(0,90)
759 self.ax.set_yticks(numpy.arange(0,90,20))
948 self.ax.set_yticks(numpy.arange(0,90,20))
760 self.ax.set_xlabel(self.xlabel)
949 self.ax.set_xlabel(self.xlabel)
761 self.ax.set_ylabel(self.ylabel)
950 self.ax.set_ylabel(self.ylabel)
762 self.ax.yaxis.labelpad = 40
951 self.ax.yaxis.labelpad = 40
763 self.ax.firsttime = False
952 self.ax.firsttime = False
764 else:
953 else:
765 self.ax.plot.set_data(x, y)
954 self.ax.plot.set_data(x, y)
766
955
767
956
768 dt1 = datetime.datetime.fromtimestamp(self.min_time).strftime('%y/%m/%d %H:%M:%S')
957 dt1 = datetime.datetime.fromtimestamp(self.min_time).strftime('%y/%m/%d %H:%M:%S')
769 dt2 = datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')
958 dt2 = datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')
770 title = 'Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n' % (dt1,
959 title = 'Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n' % (dt1,
771 dt2,
960 dt2,
772 len(x))
961 len(x))
773 self.ax.set_title(title, size=8)
962 self.ax.set_title(title, size=8)
774
963
775 self.saveTime = self.max_time
964 self.saveTime = self.max_time
@@ -1,1945 +1,1945
1 import os
1 import os
2 import datetime
2 import datetime
3 import numpy
3 import numpy
4 import inspect
4 import inspect
5 from figure import Figure, isRealtime, isTimeInHourRange
5 from figure import Figure, isRealtime, isTimeInHourRange
6 from plotting_codes import *
6 from plotting_codes import *
7
7
8
8
9 class MomentsPlot(Figure):
9 class MomentsPlot(Figure):
10
10
11 isConfig = None
11 isConfig = None
12 __nsubplots = None
12 __nsubplots = None
13
13
14 WIDTHPROF = None
14 WIDTHPROF = None
15 HEIGHTPROF = None
15 HEIGHTPROF = None
16 PREFIX = 'prm'
16 PREFIX = 'prm'
17
18 def __init__(self, **kwargs):
17 def __init__(self, **kwargs):
19 Figure.__init__(self, **kwargs)
18 Figure.__init__(self, **kwargs)
20 self.isConfig = False
19 self.isConfig = False
21 self.__nsubplots = 1
20 self.__nsubplots = 1
22
21
23 self.WIDTH = 280
22 self.WIDTH = 280
24 self.HEIGHT = 250
23 self.HEIGHT = 250
25 self.WIDTHPROF = 120
24 self.WIDTHPROF = 120
26 self.HEIGHTPROF = 0
25 self.HEIGHTPROF = 0
27 self.counter_imagwr = 0
26 self.counter_imagwr = 0
28
27
29 self.PLOT_CODE = MOMENTS_CODE
28 self.PLOT_CODE = MOMENTS_CODE
30
29
31 self.FTP_WEI = None
30 self.FTP_WEI = None
32 self.EXP_CODE = None
31 self.EXP_CODE = None
33 self.SUB_EXP_CODE = None
32 self.SUB_EXP_CODE = None
34 self.PLOT_POS = None
33 self.PLOT_POS = None
35
34
36 def getSubplots(self):
35 def getSubplots(self):
37
36
38 ncol = int(numpy.sqrt(self.nplots)+0.9)
37 ncol = int(numpy.sqrt(self.nplots)+0.9)
39 nrow = int(self.nplots*1./ncol + 0.9)
38 nrow = int(self.nplots*1./ncol + 0.9)
40
39
41 return nrow, ncol
40 return nrow, ncol
42
41
43 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
42 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
44
43
45 self.__showprofile = showprofile
44 self.__showprofile = showprofile
46 self.nplots = nplots
45 self.nplots = nplots
47
46
48 ncolspan = 1
47 ncolspan = 1
49 colspan = 1
48 colspan = 1
50 if showprofile:
49 if showprofile:
51 ncolspan = 3
50 ncolspan = 3
52 colspan = 2
51 colspan = 2
53 self.__nsubplots = 2
52 self.__nsubplots = 2
54
53
55 self.createFigure(id = id,
54 self.createFigure(id = id,
56 wintitle = wintitle,
55 wintitle = wintitle,
57 widthplot = self.WIDTH + self.WIDTHPROF,
56 widthplot = self.WIDTH + self.WIDTHPROF,
58 heightplot = self.HEIGHT + self.HEIGHTPROF,
57 heightplot = self.HEIGHT + self.HEIGHTPROF,
59 show=show)
58 show=show)
60
59
61 nrow, ncol = self.getSubplots()
60 nrow, ncol = self.getSubplots()
62
61
63 counter = 0
62 counter = 0
64 for y in range(nrow):
63 for y in range(nrow):
65 for x in range(ncol):
64 for x in range(ncol):
66
65
67 if counter >= self.nplots:
66 if counter >= self.nplots:
68 break
67 break
69
68
70 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
69 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
71
70
72 if showprofile:
71 if showprofile:
73 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
72 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
74
73
75 counter += 1
74 counter += 1
76
75
77 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
76 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
78 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
77 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
79 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
78 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
80 server=None, folder=None, username=None, password=None,
79 server=None, folder=None, username=None, password=None,
81 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
80 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
82
81
83 """
82 """
84
83
85 Input:
84 Input:
86 dataOut :
85 dataOut :
87 id :
86 id :
88 wintitle :
87 wintitle :
89 channelList :
88 channelList :
90 showProfile :
89 showProfile :
91 xmin : None,
90 xmin : None,
92 xmax : None,
91 xmax : None,
93 ymin : None,
92 ymin : None,
94 ymax : None,
93 ymax : None,
95 zmin : None,
94 zmin : None,
96 zmax : None
95 zmax : None
97 """
96 """
98
97
99 if dataOut.flagNoData:
98 if dataOut.flagNoData:
100 return None
99 return None
101
100
102 if realtime:
101 if realtime:
103 if not(isRealtime(utcdatatime = dataOut.utctime)):
102 if not(isRealtime(utcdatatime = dataOut.utctime)):
104 print 'Skipping this plot function'
103 print 'Skipping this plot function'
105 return
104 return
106
105
107 if channelList == None:
106 if channelList == None:
108 channelIndexList = dataOut.channelIndexList
107 channelIndexList = dataOut.channelIndexList
109 else:
108 else:
110 channelIndexList = []
109 channelIndexList = []
111 for channel in channelList:
110 for channel in channelList:
112 if channel not in dataOut.channelList:
111 if channel not in dataOut.channelList:
113 raise ValueError, "Channel %d is not in dataOut.channelList"
112 raise ValueError, "Channel %d is not in dataOut.channelList"
114 channelIndexList.append(dataOut.channelList.index(channel))
113 channelIndexList.append(dataOut.channelList.index(channel))
115
114
116 factor = dataOut.normFactor
115 factor = dataOut.normFactor
117 x = dataOut.abscissaList
116 x = dataOut.abscissaList
118 y = dataOut.heightList
117 y = dataOut.heightList
119
118
120 z = dataOut.data_pre[channelIndexList,:,:]/factor
119 z = dataOut.data_pre[channelIndexList,:,:]/factor
121 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
120 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
122 avg = numpy.average(z, axis=1)
121 avg = numpy.average(z, axis=1)
123 noise = dataOut.noise/factor
122 noise = dataOut.noise/factor
124
123
125 zdB = 10*numpy.log10(z)
124 zdB = 10*numpy.log10(z)
126 avgdB = 10*numpy.log10(avg)
125 avgdB = 10*numpy.log10(avg)
127 noisedB = 10*numpy.log10(noise)
126 noisedB = 10*numpy.log10(noise)
128
127
129 #thisDatetime = dataOut.datatime
128 #thisDatetime = dataOut.datatime
130 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
129 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
131 title = wintitle + " Parameters"
130 title = wintitle + " Parameters"
132 xlabel = "Velocity (m/s)"
131 xlabel = "Velocity (m/s)"
133 ylabel = "Range (Km)"
132 ylabel = "Range (Km)"
134
133
135 update_figfile = False
134 update_figfile = False
136
135
137 if not self.isConfig:
136 if not self.isConfig:
138
137
139 nplots = len(channelIndexList)
138 nplots = len(channelIndexList)
140
139
141 self.setup(id=id,
140 self.setup(id=id,
142 nplots=nplots,
141 nplots=nplots,
143 wintitle=wintitle,
142 wintitle=wintitle,
144 showprofile=showprofile,
143 showprofile=showprofile,
145 show=show)
144 show=show)
146
145
147 if xmin == None: xmin = numpy.nanmin(x)
146 if xmin == None: xmin = numpy.nanmin(x)
148 if xmax == None: xmax = numpy.nanmax(x)
147 if xmax == None: xmax = numpy.nanmax(x)
149 if ymin == None: ymin = numpy.nanmin(y)
148 if ymin == None: ymin = numpy.nanmin(y)
150 if ymax == None: ymax = numpy.nanmax(y)
149 if ymax == None: ymax = numpy.nanmax(y)
151 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
150 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
152 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
151 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
153
152
154 self.FTP_WEI = ftp_wei
153 self.FTP_WEI = ftp_wei
155 self.EXP_CODE = exp_code
154 self.EXP_CODE = exp_code
156 self.SUB_EXP_CODE = sub_exp_code
155 self.SUB_EXP_CODE = sub_exp_code
157 self.PLOT_POS = plot_pos
156 self.PLOT_POS = plot_pos
158
157
159 self.isConfig = True
158 self.isConfig = True
160 update_figfile = True
159 update_figfile = True
161
160
162 self.setWinTitle(title)
161 self.setWinTitle(title)
163
162
164 for i in range(self.nplots):
163 for i in range(self.nplots):
165 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
164 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
166 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i], noisedB[i], str_datetime)
165 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i], noisedB[i], str_datetime)
167 axes = self.axesList[i*self.__nsubplots]
166 axes = self.axesList[i*self.__nsubplots]
168 axes.pcolor(x, y, zdB[i,:,:],
167 axes.pcolor(x, y, zdB[i,:,:],
169 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
168 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
170 xlabel=xlabel, ylabel=ylabel, title=title,
169 xlabel=xlabel, ylabel=ylabel, title=title,
171 ticksize=9, cblabel='')
170 ticksize=9, cblabel='')
172 #Mean Line
171 #Mean Line
173 mean = dataOut.data_param[i, 1, :]
172 mean = dataOut.data_param[i, 1, :]
174 axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1)
173 axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1)
175
174
176 if self.__showprofile:
175 if self.__showprofile:
177 axes = self.axesList[i*self.__nsubplots +1]
176 axes = self.axesList[i*self.__nsubplots +1]
178 axes.pline(avgdB[i], y,
177 axes.pline(avgdB[i], y,
179 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
178 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
180 xlabel='dB', ylabel='', title='',
179 xlabel='dB', ylabel='', title='',
181 ytick_visible=False,
180 ytick_visible=False,
182 grid='x')
181 grid='x')
183
182
184 noiseline = numpy.repeat(noisedB[i], len(y))
183 noiseline = numpy.repeat(noisedB[i], len(y))
185 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
184 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
186
185
187 self.draw()
186 self.draw()
188
187
189 self.save(figpath=figpath,
188 self.save(figpath=figpath,
190 figfile=figfile,
189 figfile=figfile,
191 save=save,
190 save=save,
192 ftp=ftp,
191 ftp=ftp,
193 wr_period=wr_period,
192 wr_period=wr_period,
194 thisDatetime=thisDatetime)
193 thisDatetime=thisDatetime)
195
194
196
195
197
196
198 class SkyMapPlot(Figure):
197 class SkyMapPlot(Figure):
199
198
200 __isConfig = None
199 __isConfig = None
201 __nsubplots = None
200 __nsubplots = None
202
201
203 WIDTHPROF = None
202 WIDTHPROF = None
204 HEIGHTPROF = None
203 HEIGHTPROF = None
205 PREFIX = 'mmap'
204 PREFIX = 'mmap'
206
205
207 def __init__(self, **kwargs):
206 def __init__(self, **kwargs):
208 Figure.__init__(self, **kwargs)
207 Figure.__init__(self, **kwargs)
209 self.isConfig = False
208 self.isConfig = False
210 self.__nsubplots = 1
209 self.__nsubplots = 1
211
210
212 # self.WIDTH = 280
211 # self.WIDTH = 280
213 # self.HEIGHT = 250
212 # self.HEIGHT = 250
214 self.WIDTH = 600
213 self.WIDTH = 600
215 self.HEIGHT = 600
214 self.HEIGHT = 600
216 self.WIDTHPROF = 120
215 self.WIDTHPROF = 120
217 self.HEIGHTPROF = 0
216 self.HEIGHTPROF = 0
218 self.counter_imagwr = 0
217 self.counter_imagwr = 0
219
218
220 self.PLOT_CODE = MSKYMAP_CODE
219 self.PLOT_CODE = MSKYMAP_CODE
221
220
222 self.FTP_WEI = None
221 self.FTP_WEI = None
223 self.EXP_CODE = None
222 self.EXP_CODE = None
224 self.SUB_EXP_CODE = None
223 self.SUB_EXP_CODE = None
225 self.PLOT_POS = None
224 self.PLOT_POS = None
226
225
227 def getSubplots(self):
226 def getSubplots(self):
228
227
229 ncol = int(numpy.sqrt(self.nplots)+0.9)
228 ncol = int(numpy.sqrt(self.nplots)+0.9)
230 nrow = int(self.nplots*1./ncol + 0.9)
229 nrow = int(self.nplots*1./ncol + 0.9)
231
230
232 return nrow, ncol
231 return nrow, ncol
233
232
234 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
233 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
235
234
236 self.__showprofile = showprofile
235 self.__showprofile = showprofile
237 self.nplots = nplots
236 self.nplots = nplots
238
237
239 ncolspan = 1
238 ncolspan = 1
240 colspan = 1
239 colspan = 1
241
240
242 self.createFigure(id = id,
241 self.createFigure(id = id,
243 wintitle = wintitle,
242 wintitle = wintitle,
244 widthplot = self.WIDTH, #+ self.WIDTHPROF,
243 widthplot = self.WIDTH, #+ self.WIDTHPROF,
245 heightplot = self.HEIGHT,# + self.HEIGHTPROF,
244 heightplot = self.HEIGHT,# + self.HEIGHTPROF,
246 show=show)
245 show=show)
247
246
248 nrow, ncol = 1,1
247 nrow, ncol = 1,1
249 counter = 0
248 counter = 0
250 x = 0
249 x = 0
251 y = 0
250 y = 0
252 self.addAxes(1, 1, 0, 0, 1, 1, True)
251 self.addAxes(1, 1, 0, 0, 1, 1, True)
253
252
254 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
253 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
255 tmin=0, tmax=24, timerange=None,
254 tmin=0, tmax=24, timerange=None,
256 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
255 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
257 server=None, folder=None, username=None, password=None,
256 server=None, folder=None, username=None, password=None,
258 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
257 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
259
258
260 """
259 """
261
260
262 Input:
261 Input:
263 dataOut :
262 dataOut :
264 id :
263 id :
265 wintitle :
264 wintitle :
266 channelList :
265 channelList :
267 showProfile :
266 showProfile :
268 xmin : None,
267 xmin : None,
269 xmax : None,
268 xmax : None,
270 ymin : None,
269 ymin : None,
271 ymax : None,
270 ymax : None,
272 zmin : None,
271 zmin : None,
273 zmax : None
272 zmax : None
274 """
273 """
275
274
276 arrayParameters = dataOut.data_param
275 arrayParameters = dataOut.data_param
277 error = arrayParameters[:,-1]
276 error = arrayParameters[:,-1]
278 indValid = numpy.where(error == 0)[0]
277 indValid = numpy.where(error == 0)[0]
279 finalMeteor = arrayParameters[indValid,:]
278 finalMeteor = arrayParameters[indValid,:]
280 finalAzimuth = finalMeteor[:,3]
279 finalAzimuth = finalMeteor[:,3]
281 finalZenith = finalMeteor[:,4]
280 finalZenith = finalMeteor[:,4]
282
281
283 x = finalAzimuth*numpy.pi/180
282 x = finalAzimuth*numpy.pi/180
284 y = finalZenith
283 y = finalZenith
285 x1 = [dataOut.ltctime, dataOut.ltctime]
284 x1 = [dataOut.ltctime, dataOut.ltctime]
286
285
287 #thisDatetime = dataOut.datatime
286 #thisDatetime = dataOut.datatime
288 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
287 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
289 title = wintitle + " Parameters"
288 title = wintitle + " Parameters"
290 xlabel = "Zonal Zenith Angle (deg) "
289 xlabel = "Zonal Zenith Angle (deg) "
291 ylabel = "Meridional Zenith Angle (deg)"
290 ylabel = "Meridional Zenith Angle (deg)"
292 update_figfile = False
291 update_figfile = False
293
292
294 if not self.isConfig:
293 if not self.isConfig:
295
294
296 nplots = 1
295 nplots = 1
297
296
298 self.setup(id=id,
297 self.setup(id=id,
299 nplots=nplots,
298 nplots=nplots,
300 wintitle=wintitle,
299 wintitle=wintitle,
301 showprofile=showprofile,
300 showprofile=showprofile,
302 show=show)
301 show=show)
303
302
304 if self.xmin is None and self.xmax is None:
303 if self.xmin is None and self.xmax is None:
305 self.xmin, self.xmax = self.getTimeLim(x1, tmin, tmax, timerange)
304 self.xmin, self.xmax = self.getTimeLim(x1, tmin, tmax, timerange)
306
305
307 if timerange != None:
306 if timerange != None:
308 self.timerange = timerange
307 self.timerange = timerange
309 else:
308 else:
310 self.timerange = self.xmax - self.xmin
309 self.timerange = self.xmax - self.xmin
311
310
312 self.FTP_WEI = ftp_wei
311 self.FTP_WEI = ftp_wei
313 self.EXP_CODE = exp_code
312 self.EXP_CODE = exp_code
314 self.SUB_EXP_CODE = sub_exp_code
313 self.SUB_EXP_CODE = sub_exp_code
315 self.PLOT_POS = plot_pos
314 self.PLOT_POS = plot_pos
316 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
315 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
317 self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
316 self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
318 self.isConfig = True
317 self.isConfig = True
319 update_figfile = True
318 update_figfile = True
320
319
321 self.setWinTitle(title)
320 self.setWinTitle(title)
322
321
323 i = 0
322 i = 0
324 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
323 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
325
324
326 axes = self.axesList[i*self.__nsubplots]
325 axes = self.axesList[i*self.__nsubplots]
327 nevents = axes.x_buffer.shape[0] + x.shape[0]
326 nevents = axes.x_buffer.shape[0] + x.shape[0]
328 title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents)
327 title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents)
329 axes.polar(x, y,
328 axes.polar(x, y,
330 title=title, xlabel=xlabel, ylabel=ylabel,
329 title=title, xlabel=xlabel, ylabel=ylabel,
331 ticksize=9, cblabel='')
330 ticksize=9, cblabel='')
332
331
333 self.draw()
332 self.draw()
334
333
335 self.save(figpath=figpath,
334 self.save(figpath=figpath,
336 figfile=figfile,
335 figfile=figfile,
337 save=save,
336 save=save,
338 ftp=ftp,
337 ftp=ftp,
339 wr_period=wr_period,
338 wr_period=wr_period,
340 thisDatetime=thisDatetime,
339 thisDatetime=thisDatetime,
341 update_figfile=update_figfile)
340 update_figfile=update_figfile)
342
341
343 if dataOut.ltctime >= self.xmax:
342 if dataOut.ltctime >= self.xmax:
344 self.isConfigmagwr = wr_period
343 self.isConfigmagwr = wr_period
345 self.isConfig = False
344 self.isConfig = False
346 update_figfile = True
345 update_figfile = True
347 axes.__firsttime = True
346 axes.__firsttime = True
348 self.xmin += self.timerange
347 self.xmin += self.timerange
349 self.xmax += self.timerange
348 self.xmax += self.timerange
350
349
351
350
352
351
353
352
354 class WindProfilerPlot(Figure):
353 class WindProfilerPlot(Figure):
355
354
356 __isConfig = None
355 __isConfig = None
357 __nsubplots = None
356 __nsubplots = None
358
357
359 WIDTHPROF = None
358 WIDTHPROF = None
360 HEIGHTPROF = None
359 HEIGHTPROF = None
361 PREFIX = 'wind'
360 PREFIX = 'wind'
362
361
363 def __init__(self, **kwargs):
362 def __init__(self, **kwargs):
364 Figure.__init__(self, **kwargs)
363 Figure.__init__(self, **kwargs)
365 self.timerange = None
364 self.timerange = None
366 self.isConfig = False
365 self.isConfig = False
367 self.__nsubplots = 1
366 self.__nsubplots = 1
368
367
369 self.WIDTH = 800
368 self.WIDTH = 800
370 self.HEIGHT = 300
369 self.HEIGHT = 300
371 self.WIDTHPROF = 120
370 self.WIDTHPROF = 120
372 self.HEIGHTPROF = 0
371 self.HEIGHTPROF = 0
373 self.counter_imagwr = 0
372 self.counter_imagwr = 0
374
373
375 self.PLOT_CODE = WIND_CODE
374 self.PLOT_CODE = WIND_CODE
376
375
377 self.FTP_WEI = None
376 self.FTP_WEI = None
378 self.EXP_CODE = None
377 self.EXP_CODE = None
379 self.SUB_EXP_CODE = None
378 self.SUB_EXP_CODE = None
380 self.PLOT_POS = None
379 self.PLOT_POS = None
381 self.tmin = None
380 self.tmin = None
382 self.tmax = None
381 self.tmax = None
383
382
384 self.xmin = None
383 self.xmin = None
385 self.xmax = None
384 self.xmax = None
386
385
387 self.figfile = None
386 self.figfile = None
388
387
389 def getSubplots(self):
388 def getSubplots(self):
390
389
391 ncol = 1
390 ncol = 1
392 nrow = self.nplots
391 nrow = self.nplots
393
392
394 return nrow, ncol
393 return nrow, ncol
395
394
396 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
395 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
397
396
398 self.__showprofile = showprofile
397 self.__showprofile = showprofile
399 self.nplots = nplots
398 self.nplots = nplots
400
399
401 ncolspan = 1
400 ncolspan = 1
402 colspan = 1
401 colspan = 1
403
402
404 self.createFigure(id = id,
403 self.createFigure(id = id,
405 wintitle = wintitle,
404 wintitle = wintitle,
406 widthplot = self.WIDTH + self.WIDTHPROF,
405 widthplot = self.WIDTH + self.WIDTHPROF,
407 heightplot = self.HEIGHT + self.HEIGHTPROF,
406 heightplot = self.HEIGHT + self.HEIGHTPROF,
408 show=show)
407 show=show)
409
408
410 nrow, ncol = self.getSubplots()
409 nrow, ncol = self.getSubplots()
411
410
412 counter = 0
411 counter = 0
413 for y in range(nrow):
412 for y in range(nrow):
414 if counter >= self.nplots:
413 if counter >= self.nplots:
415 break
414 break
416
415
417 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
416 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
418 counter += 1
417 counter += 1
419
418
420 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='False',
419 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='False',
421 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
420 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
422 zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None,
421 zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None,
423 timerange=None, SNRthresh = None,
422 timerange=None, SNRthresh = None,
424 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
423 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
425 server=None, folder=None, username=None, password=None,
424 server=None, folder=None, username=None, password=None,
426 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
425 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
427 """
426 """
428
427
429 Input:
428 Input:
430 dataOut :
429 dataOut :
431 id :
430 id :
432 wintitle :
431 wintitle :
433 channelList :
432 channelList :
434 showProfile :
433 showProfile :
435 xmin : None,
434 xmin : None,
436 xmax : None,
435 xmax : None,
437 ymin : None,
436 ymin : None,
438 ymax : None,
437 ymax : None,
439 zmin : None,
438 zmin : None,
440 zmax : None
439 zmax : None
441 """
440 """
442
441
443 # if timerange is not None:
442 # if timerange is not None:
444 # self.timerange = timerange
443 # self.timerange = timerange
445 #
444 #
446 # tmin = None
445 # tmin = None
447 # tmax = None
446 # tmax = None
448
447
449
448
450 x = dataOut.getTimeRange1(dataOut.outputInterval)
449 x = dataOut.getTimeRange1(dataOut.outputInterval)
451 y = dataOut.heightList
450 y = dataOut.heightList
452 z = dataOut.data_output.copy()
451 z = dataOut.data_output.copy()
453 nplots = z.shape[0] #Number of wind dimensions estimated
452 nplots = z.shape[0] #Number of wind dimensions estimated
454 nplotsw = nplots
453 nplotsw = nplots
455
454
456
455
457 #If there is a SNR function defined
456 #If there is a SNR function defined
458 if dataOut.data_SNR is not None:
457 if dataOut.data_SNR is not None:
459 nplots += 1
458 nplots += 1
460 SNR = dataOut.data_SNR
459 SNR = dataOut.data_SNR
461 SNRavg = numpy.average(SNR, axis=0)
460 SNRavg = numpy.average(SNR, axis=0)
462
461
463 SNRdB = 10*numpy.log10(SNR)
462 SNRdB = 10*numpy.log10(SNR)
464 SNRavgdB = 10*numpy.log10(SNRavg)
463 SNRavgdB = 10*numpy.log10(SNRavg)
465
464
466 if SNRthresh == None: SNRthresh = -5.0
465 if SNRthresh == None: SNRthresh = -5.0
467 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
466 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
468
467
469 for i in range(nplotsw):
468 for i in range(nplotsw):
470 z[i,ind] = numpy.nan
469 z[i,ind] = numpy.nan
471
470
472 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
471 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
473 #thisDatetime = datetime.datetime.now()
472 #thisDatetime = datetime.datetime.now()
474 title = wintitle + "Wind"
473 title = wintitle + "Wind"
475 xlabel = ""
474 xlabel = ""
476 ylabel = "Height (km)"
475 ylabel = "Height (km)"
477 update_figfile = False
476 update_figfile = False
478
477
479 if not self.isConfig:
478 if not self.isConfig:
480
479
481 self.setup(id=id,
480 self.setup(id=id,
482 nplots=nplots,
481 nplots=nplots,
483 wintitle=wintitle,
482 wintitle=wintitle,
484 showprofile=showprofile,
483 showprofile=showprofile,
485 show=show)
484 show=show)
486
485
487 if timerange is not None:
486 if timerange is not None:
488 self.timerange = timerange
487 self.timerange = timerange
489
488
490 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
489 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
491
490
492 if ymin == None: ymin = numpy.nanmin(y)
491 if ymin == None: ymin = numpy.nanmin(y)
493 if ymax == None: ymax = numpy.nanmax(y)
492 if ymax == None: ymax = numpy.nanmax(y)
494
493
495 if zmax == None: zmax = numpy.nanmax(abs(z[range(2),:]))
494 if zmax == None: zmax = numpy.nanmax(abs(z[range(2),:]))
496 #if numpy.isnan(zmax): zmax = 50
495 #if numpy.isnan(zmax): zmax = 50
497 if zmin == None: zmin = -zmax
496 if zmin == None: zmin = -zmax
498
497
499 if nplotsw == 3:
498 if nplotsw == 3:
500 if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:]))
499 if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:]))
501 if zmin_ver == None: zmin_ver = -zmax_ver
500 if zmin_ver == None: zmin_ver = -zmax_ver
502
501
503 if dataOut.data_SNR is not None:
502 if dataOut.data_SNR is not None:
504 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
503 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
505 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
504 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
506
505
507
506
508 self.FTP_WEI = ftp_wei
507 self.FTP_WEI = ftp_wei
509 self.EXP_CODE = exp_code
508 self.EXP_CODE = exp_code
510 self.SUB_EXP_CODE = sub_exp_code
509 self.SUB_EXP_CODE = sub_exp_code
511 self.PLOT_POS = plot_pos
510 self.PLOT_POS = plot_pos
512
511
513 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
512 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
514 self.isConfig = True
513 self.isConfig = True
515 self.figfile = figfile
514 self.figfile = figfile
516 update_figfile = True
515 update_figfile = True
517
516
518 self.setWinTitle(title)
517 self.setWinTitle(title)
519
518
520 if ((self.xmax - x[1]) < (x[1]-x[0])):
519 if ((self.xmax - x[1]) < (x[1]-x[0])):
521 x[1] = self.xmax
520 x[1] = self.xmax
522
521
523 strWind = ['Zonal', 'Meridional', 'Vertical']
522 strWind = ['Zonal', 'Meridional', 'Vertical']
524 strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)']
523 strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)']
525 zmaxVector = [zmax, zmax, zmax_ver]
524 zmaxVector = [zmax, zmax, zmax_ver]
526 zminVector = [zmin, zmin, zmin_ver]
525 zminVector = [zmin, zmin, zmin_ver]
527 windFactor = [1,1,100]
526 windFactor = [1,1,100]
528
527
529 for i in range(nplotsw):
528 for i in range(nplotsw):
530
529
531 title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
530 title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
532 axes = self.axesList[i*self.__nsubplots]
531 axes = self.axesList[i*self.__nsubplots]
533
532
534 z1 = z[i,:].reshape((1,-1))*windFactor[i]
533 z1 = z[i,:].reshape((1,-1))*windFactor[i]
535 #z1=numpy.ma.masked_where(z1==0.,z1)
534 #z1=numpy.ma.masked_where(z1==0.,z1)
536
535
537 axes.pcolorbuffer(x, y, z1,
536 axes.pcolorbuffer(x, y, z1,
538 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
537 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
539 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
538 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
540 ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="seismic" )
539 ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="seismic" )
541
540
542 if dataOut.data_SNR is not None:
541 if dataOut.data_SNR is not None:
543 i += 1
542 i += 1
544 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
543 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
545 axes = self.axesList[i*self.__nsubplots]
544 axes = self.axesList[i*self.__nsubplots]
546 SNRavgdB = SNRavgdB.reshape((1,-1))
545 SNRavgdB = SNRavgdB.reshape((1,-1))
547 axes.pcolorbuffer(x, y, SNRavgdB,
546 axes.pcolorbuffer(x, y, SNRavgdB,
548 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
547 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
549 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
548 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
550 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
549 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
551
550
552 self.draw()
551 self.draw()
553
552
554 self.save(figpath=figpath,
553 self.save(figpath=figpath,
555 figfile=figfile,
554 figfile=figfile,
556 save=save,
555 save=save,
557 ftp=ftp,
556 ftp=ftp,
558 wr_period=wr_period,
557 wr_period=wr_period,
559 thisDatetime=thisDatetime,
558 thisDatetime=thisDatetime,
560 update_figfile=update_figfile)
559 update_figfile=update_figfile)
561
560
562 if dataOut.ltctime + dataOut.outputInterval >= self.xmax:
561 if dataOut.ltctime + dataOut.outputInterval >= self.xmax:
563 self.counter_imagwr = wr_period
562 self.counter_imagwr = wr_period
564 self.isConfig = False
563 self.isConfig = False
565 update_figfile = True
564 update_figfile = True
566
565
567
566
568 class ParametersPlot(Figure):
567 class ParametersPlot(Figure):
569
568
570 __isConfig = None
569 __isConfig = None
571 __nsubplots = None
570 __nsubplots = None
572
571
573 WIDTHPROF = None
572 WIDTHPROF = None
574 HEIGHTPROF = None
573 HEIGHTPROF = None
575 PREFIX = 'param'
574 PREFIX = 'param'
576
575
577 nplots = None
576 nplots = None
578 nchan = None
577 nchan = None
579
578
580 def __init__(self, **kwargs):
579 def __init__(self, **kwargs):
581 Figure.__init__(self, **kwargs)
580 Figure.__init__(self, **kwargs)
582 self.timerange = None
581 self.timerange = None
583 self.isConfig = False
582 self.isConfig = False
584 self.__nsubplots = 1
583 self.__nsubplots = 1
585
584
586 self.WIDTH = 800
585 self.WIDTH = 800
587 self.HEIGHT = 180
586 self.HEIGHT = 180
588 self.WIDTHPROF = 120
587 self.WIDTHPROF = 120
589 self.HEIGHTPROF = 0
588 self.HEIGHTPROF = 0
590 self.counter_imagwr = 0
589 self.counter_imagwr = 0
591
590
592 self.PLOT_CODE = RTI_CODE
591 self.PLOT_CODE = RTI_CODE
593
592
594 self.FTP_WEI = None
593 self.FTP_WEI = None
595 self.EXP_CODE = None
594 self.EXP_CODE = None
596 self.SUB_EXP_CODE = None
595 self.SUB_EXP_CODE = None
597 self.PLOT_POS = None
596 self.PLOT_POS = None
598 self.tmin = None
597 self.tmin = None
599 self.tmax = None
598 self.tmax = None
600
599
601 self.xmin = None
600 self.xmin = None
602 self.xmax = None
601 self.xmax = None
603
602
604 self.figfile = None
603 self.figfile = None
605
604
606 def getSubplots(self):
605 def getSubplots(self):
607
606
608 ncol = 1
607 ncol = 1
609 nrow = self.nplots
608 nrow = self.nplots
610
609
611 return nrow, ncol
610 return nrow, ncol
612
611
613 def setup(self, id, nplots, wintitle, show=True):
612 def setup(self, id, nplots, wintitle, show=True):
614
613
615 self.nplots = nplots
614 self.nplots = nplots
616
615
617 ncolspan = 1
616 ncolspan = 1
618 colspan = 1
617 colspan = 1
619
618
620 self.createFigure(id = id,
619 self.createFigure(id = id,
621 wintitle = wintitle,
620 wintitle = wintitle,
622 widthplot = self.WIDTH + self.WIDTHPROF,
621 widthplot = self.WIDTH + self.WIDTHPROF,
623 heightplot = self.HEIGHT + self.HEIGHTPROF,
622 heightplot = self.HEIGHT + self.HEIGHTPROF,
624 show=show)
623 show=show)
625
624
626 nrow, ncol = self.getSubplots()
625 nrow, ncol = self.getSubplots()
627
626
628 counter = 0
627 counter = 0
629 for y in range(nrow):
628 for y in range(nrow):
630 for x in range(ncol):
629 for x in range(ncol):
631
630
632 if counter >= self.nplots:
631 if counter >= self.nplots:
633 break
632 break
634
633
635 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
634 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
636
635
637 counter += 1
636 counter += 1
638
637
639 def run(self, dataOut, id, wintitle="", channelList=None, paramIndex = 0, colormap=True,
638 def run(self, dataOut, id, wintitle="", channelList=None, paramIndex = 0, colormap=True,
640 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, timerange=None,
639 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, timerange=None,
641 showSNR=False, SNRthresh = -numpy.inf, SNRmin=None, SNRmax=None,
640 showSNR=False, SNRthresh = -numpy.inf, SNRmin=None, SNRmax=None,
642 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
641 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
643 server=None, folder=None, username=None, password=None,
642 server=None, folder=None, username=None, password=None,
644 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
643 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
645 """
644 """
646
645
647 Input:
646 Input:
648 dataOut :
647 dataOut :
649 id :
648 id :
650 wintitle :
649 wintitle :
651 channelList :
650 channelList :
652 showProfile :
651 showProfile :
653 xmin : None,
652 xmin : None,
654 xmax : None,
653 xmax : None,
655 ymin : None,
654 ymin : None,
656 ymax : None,
655 ymax : None,
657 zmin : None,
656 zmin : None,
658 zmax : None
657 zmax : None
659 """
658 """
660
659
661 if colormap:
660 if colormap:
662 colormap="jet"
661 colormap="jet"
663 else:
662 else:
664 colormap="RdBu_r"
663 colormap="RdBu_r"
665
664
666 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
665 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
667 return
666 return
668
667
669 if channelList == None:
668 if channelList == None:
670 channelIndexList = range(dataOut.data_param.shape[0])
669 channelIndexList = range(dataOut.data_param.shape[0])
671 else:
670 else:
672 channelIndexList = []
671 channelIndexList = []
673 for channel in channelList:
672 for channel in channelList:
674 if channel not in dataOut.channelList:
673 if channel not in dataOut.channelList:
675 raise ValueError, "Channel %d is not in dataOut.channelList"
674 raise ValueError, "Channel %d is not in dataOut.channelList"
676 channelIndexList.append(dataOut.channelList.index(channel))
675 channelIndexList.append(dataOut.channelList.index(channel))
677
676
678 x = dataOut.getTimeRange1(dataOut.paramInterval)
677 x = dataOut.getTimeRange1(dataOut.paramInterval)
679 y = dataOut.getHeiRange()
678 y = dataOut.getHeiRange()
680
679
681 if dataOut.data_param.ndim == 3:
680 if dataOut.data_param.ndim == 3:
682 z = dataOut.data_param[channelIndexList,paramIndex,:]
681 z = dataOut.data_param[channelIndexList,paramIndex,:]
683 else:
682 else:
684 z = dataOut.data_param[channelIndexList,:]
683 z = dataOut.data_param[channelIndexList,:]
685
684
686 if showSNR:
685 if showSNR:
687 #SNR data
686 #SNR data
688 SNRarray = dataOut.data_SNR[channelIndexList,:]
687 SNRarray = dataOut.data_SNR[channelIndexList,:]
689 SNRdB = 10*numpy.log10(SNRarray)
688 SNRdB = 10*numpy.log10(SNRarray)
690 ind = numpy.where(SNRdB < SNRthresh)
689 ind = numpy.where(SNRdB < SNRthresh)
691 z[ind] = numpy.nan
690 z[ind] = numpy.nan
692
691
693 thisDatetime = dataOut.datatime
692 thisDatetime = dataOut.datatime
694 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
693 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
695 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
694 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
696 xlabel = ""
695 xlabel = ""
697 ylabel = "Range (Km)"
696 ylabel = "Range (Km)"
698
697
699 update_figfile = False
698 update_figfile = False
700
699
701 if not self.isConfig:
700 if not self.isConfig:
702
701
703 nchan = len(channelIndexList)
702 nchan = len(channelIndexList)
704 self.nchan = nchan
703 self.nchan = nchan
705 self.plotFact = 1
704 self.plotFact = 1
706 nplots = nchan
705 nplots = nchan
707
706
708 if showSNR:
707 if showSNR:
709 nplots = nchan*2
708 nplots = nchan*2
710 self.plotFact = 2
709 self.plotFact = 2
711 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
710 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
712 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
711 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
713
712
714 self.setup(id=id,
713 self.setup(id=id,
715 nplots=nplots,
714 nplots=nplots,
716 wintitle=wintitle,
715 wintitle=wintitle,
717 show=show)
716 show=show)
718
717
719 if timerange != None:
718 if timerange != None:
720 self.timerange = timerange
719 self.timerange = timerange
721
720
722 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
721 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
723
722
724 if ymin == None: ymin = numpy.nanmin(y)
723 if ymin == None: ymin = numpy.nanmin(y)
725 if ymax == None: ymax = numpy.nanmax(y)
724 if ymax == None: ymax = numpy.nanmax(y)
726 if zmin == None: zmin = numpy.nanmin(z)
725 if zmin == None: zmin = numpy.nanmin(z)
727 if zmax == None: zmax = numpy.nanmax(z)
726 if zmax == None: zmax = numpy.nanmax(z)
728
727
729 self.FTP_WEI = ftp_wei
728 self.FTP_WEI = ftp_wei
730 self.EXP_CODE = exp_code
729 self.EXP_CODE = exp_code
731 self.SUB_EXP_CODE = sub_exp_code
730 self.SUB_EXP_CODE = sub_exp_code
732 self.PLOT_POS = plot_pos
731 self.PLOT_POS = plot_pos
733
732
734 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
733 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
735 self.isConfig = True
734 self.isConfig = True
736 self.figfile = figfile
735 self.figfile = figfile
737 update_figfile = True
736 update_figfile = True
738
737
739 self.setWinTitle(title)
738 self.setWinTitle(title)
740
739
741 for i in range(self.nchan):
740 for i in range(self.nchan):
742 index = channelIndexList[i]
741 index = channelIndexList[i]
743 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
742 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
744 axes = self.axesList[i*self.plotFact]
743 axes = self.axesList[i*self.plotFact]
745 z1 = z[i,:].reshape((1,-1))
744 z1 = z[i,:].reshape((1,-1))
746 axes.pcolorbuffer(x, y, z1,
745 axes.pcolorbuffer(x, y, z1,
747 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
746 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
748 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
747 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
749 ticksize=9, cblabel='', cbsize="1%",colormap=colormap)
748 ticksize=9, cblabel='', cbsize="1%",colormap=colormap)
750
749
751 if showSNR:
750 if showSNR:
752 title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
751 title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
753 axes = self.axesList[i*self.plotFact + 1]
752 axes = self.axesList[i*self.plotFact + 1]
754 SNRdB1 = SNRdB[i,:].reshape((1,-1))
753 SNRdB1 = SNRdB[i,:].reshape((1,-1))
755 axes.pcolorbuffer(x, y, SNRdB1,
754 axes.pcolorbuffer(x, y, SNRdB1,
756 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
755 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
757 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
756 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
758 ticksize=9, cblabel='', cbsize="1%",colormap='jet')
757 ticksize=9, cblabel='', cbsize="1%",colormap='jet')
759
758
760
759
761 self.draw()
760 self.draw()
762
761
763 if dataOut.ltctime >= self.xmax:
762 if dataOut.ltctime >= self.xmax:
764 self.counter_imagwr = wr_period
763 self.counter_imagwr = wr_period
765 self.isConfig = False
764 self.isConfig = False
766 update_figfile = True
765 update_figfile = True
767
766
768 self.save(figpath=figpath,
767 self.save(figpath=figpath,
769 figfile=figfile,
768 figfile=figfile,
770 save=save,
769 save=save,
771 ftp=ftp,
770 ftp=ftp,
772 wr_period=wr_period,
771 wr_period=wr_period,
773 thisDatetime=thisDatetime,
772 thisDatetime=thisDatetime,
774 update_figfile=update_figfile)
773 update_figfile=update_figfile)
775
774
776
775
777
776
778 class Parameters1Plot(Figure):
777 class Parameters1Plot(Figure):
779
778
780 __isConfig = None
779 __isConfig = None
781 __nsubplots = None
780 __nsubplots = None
782
781
783 WIDTHPROF = None
782 WIDTHPROF = None
784 HEIGHTPROF = None
783 HEIGHTPROF = None
785 PREFIX = 'prm'
784 PREFIX = 'prm'
786
785
787 def __init__(self, **kwargs):
786 def __init__(self, **kwargs):
788 Figure.__init__(self, **kwargs)
787 Figure.__init__(self, **kwargs)
789 self.timerange = 2*60*60
788 self.timerange = 2*60*60
790 self.isConfig = False
789 self.isConfig = False
791 self.__nsubplots = 1
790 self.__nsubplots = 1
792
791
793 self.WIDTH = 800
792 self.WIDTH = 800
794 self.HEIGHT = 180
793 self.HEIGHT = 180
795 self.WIDTHPROF = 120
794 self.WIDTHPROF = 120
796 self.HEIGHTPROF = 0
795 self.HEIGHTPROF = 0
797 self.counter_imagwr = 0
796 self.counter_imagwr = 0
798
797
799 self.PLOT_CODE = PARMS_CODE
798 self.PLOT_CODE = PARMS_CODE
800
799
801 self.FTP_WEI = None
800 self.FTP_WEI = None
802 self.EXP_CODE = None
801 self.EXP_CODE = None
803 self.SUB_EXP_CODE = None
802 self.SUB_EXP_CODE = None
804 self.PLOT_POS = None
803 self.PLOT_POS = None
805 self.tmin = None
804 self.tmin = None
806 self.tmax = None
805 self.tmax = None
807
806
808 self.xmin = None
807 self.xmin = None
809 self.xmax = None
808 self.xmax = None
810
809
811 self.figfile = None
810 self.figfile = None
812
811
813 def getSubplots(self):
812 def getSubplots(self):
814
813
815 ncol = 1
814 ncol = 1
816 nrow = self.nplots
815 nrow = self.nplots
817
816
818 return nrow, ncol
817 return nrow, ncol
819
818
820 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
819 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
821
820
822 self.__showprofile = showprofile
821 self.__showprofile = showprofile
823 self.nplots = nplots
822 self.nplots = nplots
824
823
825 ncolspan = 1
824 ncolspan = 1
826 colspan = 1
825 colspan = 1
827
826
828 self.createFigure(id = id,
827 self.createFigure(id = id,
829 wintitle = wintitle,
828 wintitle = wintitle,
830 widthplot = self.WIDTH + self.WIDTHPROF,
829 widthplot = self.WIDTH + self.WIDTHPROF,
831 heightplot = self.HEIGHT + self.HEIGHTPROF,
830 heightplot = self.HEIGHT + self.HEIGHTPROF,
832 show=show)
831 show=show)
833
832
834 nrow, ncol = self.getSubplots()
833 nrow, ncol = self.getSubplots()
835
834
836 counter = 0
835 counter = 0
837 for y in range(nrow):
836 for y in range(nrow):
838 for x in range(ncol):
837 for x in range(ncol):
839
838
840 if counter >= self.nplots:
839 if counter >= self.nplots:
841 break
840 break
842
841
843 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
842 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
844
843
845 if showprofile:
844 if showprofile:
846 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
845 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
847
846
848 counter += 1
847 counter += 1
849
848
850 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
849 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
851 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None,
850 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None,
852 parameterIndex = None, onlyPositive = False,
851 parameterIndex = None, onlyPositive = False,
853 SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None, onlySNR = False,
852 SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None, onlySNR = False,
854 DOP = True,
853 DOP = True,
855 zlabel = "", parameterName = "", parameterObject = "data_param",
854 zlabel = "", parameterName = "", parameterObject = "data_param",
856 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
855 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
857 server=None, folder=None, username=None, password=None,
856 server=None, folder=None, username=None, password=None,
858 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
857 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
859 #print inspect.getargspec(self.run).args
858 #print inspect.getargspec(self.run).args
860 """
859 """
861
860
862 Input:
861 Input:
863 dataOut :
862 dataOut :
864 id :
863 id :
865 wintitle :
864 wintitle :
866 channelList :
865 channelList :
867 showProfile :
866 showProfile :
868 xmin : None,
867 xmin : None,
869 xmax : None,
868 xmax : None,
870 ymin : None,
869 ymin : None,
871 ymax : None,
870 ymax : None,
872 zmin : None,
871 zmin : None,
873 zmax : None
872 zmax : None
874 """
873 """
875
874
876 data_param = getattr(dataOut, parameterObject)
875 data_param = getattr(dataOut, parameterObject)
877
876
878 if channelList == None:
877 if channelList == None:
879 channelIndexList = numpy.arange(data_param.shape[0])
878 channelIndexList = numpy.arange(data_param.shape[0])
880 else:
879 else:
881 channelIndexList = numpy.array(channelList)
880 channelIndexList = numpy.array(channelList)
882
881
883 nchan = len(channelIndexList) #Number of channels being plotted
882 nchan = len(channelIndexList) #Number of channels being plotted
884
883
885 if nchan < 1:
884 if nchan < 1:
886 return
885 return
887
886
888 nGraphsByChannel = 0
887 nGraphsByChannel = 0
889
888
890 if SNR:
889 if SNR:
891 nGraphsByChannel += 1
890 nGraphsByChannel += 1
892 if DOP:
891 if DOP:
893 nGraphsByChannel += 1
892 nGraphsByChannel += 1
894
893
895 if nGraphsByChannel < 1:
894 if nGraphsByChannel < 1:
896 return
895 return
897
896
898 nplots = nGraphsByChannel*nchan
897 nplots = nGraphsByChannel*nchan
899
898
900 if timerange is not None:
899 if timerange is not None:
901 self.timerange = timerange
900 self.timerange = timerange
902
901
903 #tmin = None
902 #tmin = None
904 #tmax = None
903 #tmax = None
905 if parameterIndex == None:
904 if parameterIndex == None:
906 parameterIndex = 1
905 parameterIndex = 1
907
906
908 x = dataOut.getTimeRange1(dataOut.paramInterval)
907 x = dataOut.getTimeRange1(dataOut.paramInterval)
909 y = dataOut.heightList
908 y = dataOut.heightList
910 z = data_param[channelIndexList,parameterIndex,:].copy()
909 z = data_param[channelIndexList,parameterIndex,:].copy()
911
910
912 zRange = dataOut.abscissaList
911 zRange = dataOut.abscissaList
913 # nChannels = z.shape[0] #Number of wind dimensions estimated
912 # nChannels = z.shape[0] #Number of wind dimensions estimated
914 # thisDatetime = dataOut.datatime
913 # thisDatetime = dataOut.datatime
915
914
916 if dataOut.data_SNR is not None:
915 if dataOut.data_SNR is not None:
917 SNRarray = dataOut.data_SNR[channelIndexList,:]
916 SNRarray = dataOut.data_SNR[channelIndexList,:]
918 SNRdB = 10*numpy.log10(SNRarray)
917 SNRdB = 10*numpy.log10(SNRarray)
919 # SNRavgdB = 10*numpy.log10(SNRavg)
918 # SNRavgdB = 10*numpy.log10(SNRavg)
920 ind = numpy.where(SNRdB < 10**(SNRthresh/10))
919 ind = numpy.where(SNRdB < 10**(SNRthresh/10))
921 z[ind] = numpy.nan
920 z[ind] = numpy.nan
922
921
923 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
922 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
924 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
923 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
925 xlabel = ""
924 xlabel = ""
926 ylabel = "Range (Km)"
925 ylabel = "Range (Km)"
927
926
928 if (SNR and not onlySNR): nplots = 2*nplots
927 if (SNR and not onlySNR): nplots = 2*nplots
929
928
930 if onlyPositive:
929 if onlyPositive:
931 colormap = "jet"
930 colormap = "jet"
932 zmin = 0
931 zmin = 0
933 else: colormap = "RdBu_r"
932 else: colormap = "RdBu_r"
934
933
935 if not self.isConfig:
934 if not self.isConfig:
936
935
937 self.setup(id=id,
936 self.setup(id=id,
938 nplots=nplots,
937 nplots=nplots,
939 wintitle=wintitle,
938 wintitle=wintitle,
940 showprofile=showprofile,
939 showprofile=showprofile,
941 show=show)
940 show=show)
942
941
943 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
942 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
944
943
945 if ymin == None: ymin = numpy.nanmin(y)
944 if ymin == None: ymin = numpy.nanmin(y)
946 if ymax == None: ymax = numpy.nanmax(y)
945 if ymax == None: ymax = numpy.nanmax(y)
947 if zmin == None: zmin = numpy.nanmin(zRange)
946 if zmin == None: zmin = numpy.nanmin(zRange)
948 if zmax == None: zmax = numpy.nanmax(zRange)
947 if zmax == None: zmax = numpy.nanmax(zRange)
949
948
950 if SNR:
949 if SNR:
951 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
950 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
952 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
951 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
953
952
954 self.FTP_WEI = ftp_wei
953 self.FTP_WEI = ftp_wei
955 self.EXP_CODE = exp_code
954 self.EXP_CODE = exp_code
956 self.SUB_EXP_CODE = sub_exp_code
955 self.SUB_EXP_CODE = sub_exp_code
957 self.PLOT_POS = plot_pos
956 self.PLOT_POS = plot_pos
958
957
959 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
958 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
960 self.isConfig = True
959 self.isConfig = True
961 self.figfile = figfile
960 self.figfile = figfile
962
961
963 self.setWinTitle(title)
962 self.setWinTitle(title)
964
963
965 if ((self.xmax - x[1]) < (x[1]-x[0])):
964 if ((self.xmax - x[1]) < (x[1]-x[0])):
966 x[1] = self.xmax
965 x[1] = self.xmax
967
966
968 for i in range(nchan):
967 for i in range(nchan):
969
968
970 if (SNR and not onlySNR): j = 2*i
969 if (SNR and not onlySNR): j = 2*i
971 else: j = i
970 else: j = i
972
971
973 j = nGraphsByChannel*i
972 j = nGraphsByChannel*i
974
973
975 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
974 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
976 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
975 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
977
976
978 if not onlySNR:
977 if not onlySNR:
979 axes = self.axesList[j*self.__nsubplots]
978 axes = self.axesList[j*self.__nsubplots]
980 z1 = z[i,:].reshape((1,-1))
979 z1 = z[i,:].reshape((1,-1))
981 axes.pcolorbuffer(x, y, z1,
980 axes.pcolorbuffer(x, y, z1,
982 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
981 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
983 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
982 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
984 ticksize=9, cblabel=zlabel, cbsize="1%")
983 ticksize=9, cblabel=zlabel, cbsize="1%")
985
984
986 if DOP:
985 if DOP:
987 title = "%s Channel %d: %s" %(parameterName, channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
986 title = "%s Channel %d: %s" %(parameterName, channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
988
987
989 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
988 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
990 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
989 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
991 axes = self.axesList[j]
990 axes = self.axesList[j]
992 z1 = z[i,:].reshape((1,-1))
991 z1 = z[i,:].reshape((1,-1))
993 axes.pcolorbuffer(x, y, z1,
992 axes.pcolorbuffer(x, y, z1,
994 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
993 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
995 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
994 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
996 ticksize=9, cblabel=zlabel, cbsize="1%")
995 ticksize=9, cblabel=zlabel, cbsize="1%")
997
996
998 if SNR:
997 if SNR:
999 title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
998 title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1000 axes = self.axesList[(j)*self.__nsubplots]
999 axes = self.axesList[(j)*self.__nsubplots]
1001 if not onlySNR:
1000 if not onlySNR:
1002 axes = self.axesList[(j + 1)*self.__nsubplots]
1001 axes = self.axesList[(j + 1)*self.__nsubplots]
1003
1002
1004 axes = self.axesList[(j + nGraphsByChannel-1)]
1003 axes = self.axesList[(j + nGraphsByChannel-1)]
1005
1004
1006 z1 = SNRdB[i,:].reshape((1,-1))
1005 z1 = SNRdB[i,:].reshape((1,-1))
1007 axes.pcolorbuffer(x, y, z1,
1006 axes.pcolorbuffer(x, y, z1,
1008 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1007 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1009 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet",
1008 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet",
1010 ticksize=9, cblabel=zlabel, cbsize="1%")
1009 ticksize=9, cblabel=zlabel, cbsize="1%")
1011
1010
1012
1011
1013
1012
1014 self.draw()
1013 self.draw()
1015
1014
1016 if x[1] >= self.axesList[0].xmax:
1015 if x[1] >= self.axesList[0].xmax:
1017 self.counter_imagwr = wr_period
1016 self.counter_imagwr = wr_period
1018 self.isConfig = False
1017 self.isConfig = False
1019 self.figfile = None
1018 self.figfile = None
1020
1019
1021 self.save(figpath=figpath,
1020 self.save(figpath=figpath,
1022 figfile=figfile,
1021 figfile=figfile,
1023 save=save,
1022 save=save,
1024 ftp=ftp,
1023 ftp=ftp,
1025 wr_period=wr_period,
1024 wr_period=wr_period,
1026 thisDatetime=thisDatetime,
1025 thisDatetime=thisDatetime,
1027 update_figfile=False)
1026 update_figfile=False)
1028
1027
1029 class SpectralFittingPlot(Figure):
1028 class SpectralFittingPlot(Figure):
1030
1029
1031 __isConfig = None
1030 __isConfig = None
1032 __nsubplots = None
1031 __nsubplots = None
1033
1032
1034 WIDTHPROF = None
1033 WIDTHPROF = None
1035 HEIGHTPROF = None
1034 HEIGHTPROF = None
1036 PREFIX = 'prm'
1035 PREFIX = 'prm'
1037
1036
1038
1037
1039 N = None
1038 N = None
1040 ippSeconds = None
1039 ippSeconds = None
1041
1040
1042 def __init__(self, **kwargs):
1041 def __init__(self, **kwargs):
1043 Figure.__init__(self, **kwargs)
1042 Figure.__init__(self, **kwargs)
1044 self.isConfig = False
1043 self.isConfig = False
1045 self.__nsubplots = 1
1044 self.__nsubplots = 1
1046
1045
1047 self.PLOT_CODE = SPECFIT_CODE
1046 self.PLOT_CODE = SPECFIT_CODE
1048
1047
1049 self.WIDTH = 450
1048 self.WIDTH = 450
1050 self.HEIGHT = 250
1049 self.HEIGHT = 250
1051 self.WIDTHPROF = 0
1050 self.WIDTHPROF = 0
1052 self.HEIGHTPROF = 0
1051 self.HEIGHTPROF = 0
1053
1052
1054 def getSubplots(self):
1053 def getSubplots(self):
1055
1054
1056 ncol = int(numpy.sqrt(self.nplots)+0.9)
1055 ncol = int(numpy.sqrt(self.nplots)+0.9)
1057 nrow = int(self.nplots*1./ncol + 0.9)
1056 nrow = int(self.nplots*1./ncol + 0.9)
1058
1057
1059 return nrow, ncol
1058 return nrow, ncol
1060
1059
1061 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
1060 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
1062
1061
1063 showprofile = False
1062 showprofile = False
1064 self.__showprofile = showprofile
1063 self.__showprofile = showprofile
1065 self.nplots = nplots
1064 self.nplots = nplots
1066
1065
1067 ncolspan = 5
1066 ncolspan = 5
1068 colspan = 4
1067 colspan = 4
1069 if showprofile:
1068 if showprofile:
1070 ncolspan = 5
1069 ncolspan = 5
1071 colspan = 4
1070 colspan = 4
1072 self.__nsubplots = 2
1071 self.__nsubplots = 2
1073
1072
1074 self.createFigure(id = id,
1073 self.createFigure(id = id,
1075 wintitle = wintitle,
1074 wintitle = wintitle,
1076 widthplot = self.WIDTH + self.WIDTHPROF,
1075 widthplot = self.WIDTH + self.WIDTHPROF,
1077 heightplot = self.HEIGHT + self.HEIGHTPROF,
1076 heightplot = self.HEIGHT + self.HEIGHTPROF,
1078 show=show)
1077 show=show)
1079
1078
1080 nrow, ncol = self.getSubplots()
1079 nrow, ncol = self.getSubplots()
1081
1080
1082 counter = 0
1081 counter = 0
1083 for y in range(nrow):
1082 for y in range(nrow):
1084 for x in range(ncol):
1083 for x in range(ncol):
1085
1084
1086 if counter >= self.nplots:
1085 if counter >= self.nplots:
1087 break
1086 break
1088
1087
1089 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1088 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1090
1089
1091 if showprofile:
1090 if showprofile:
1092 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1091 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1093
1092
1094 counter += 1
1093 counter += 1
1095
1094
1096 def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True,
1095 def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True,
1097 xmin=None, xmax=None, ymin=None, ymax=None,
1096 xmin=None, xmax=None, ymin=None, ymax=None,
1098 save=False, figpath='./', figfile=None, show=True):
1097 save=False, figpath='./', figfile=None, show=True):
1099
1098
1100 """
1099 """
1101
1100
1102 Input:
1101 Input:
1103 dataOut :
1102 dataOut :
1104 id :
1103 id :
1105 wintitle :
1104 wintitle :
1106 channelList :
1105 channelList :
1107 showProfile :
1106 showProfile :
1108 xmin : None,
1107 xmin : None,
1109 xmax : None,
1108 xmax : None,
1110 zmin : None,
1109 zmin : None,
1111 zmax : None
1110 zmax : None
1112 """
1111 """
1113
1112
1114 if cutHeight==None:
1113 if cutHeight==None:
1115 h=270
1114 h=270
1116 heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin()
1115 heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin()
1117 cutHeight = dataOut.heightList[heightindex]
1116 cutHeight = dataOut.heightList[heightindex]
1118
1117
1119 factor = dataOut.normFactor
1118 factor = dataOut.normFactor
1120 x = dataOut.abscissaList[:-1]
1119 x = dataOut.abscissaList[:-1]
1121 #y = dataOut.getHeiRange()
1120 #y = dataOut.getHeiRange()
1122
1121
1123 z = dataOut.data_pre[:,:,heightindex]/factor
1122 z = dataOut.data_pre[:,:,heightindex]/factor
1124 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1123 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1125 avg = numpy.average(z, axis=1)
1124 avg = numpy.average(z, axis=1)
1126 listChannels = z.shape[0]
1125 listChannels = z.shape[0]
1127
1126
1128 #Reconstruct Function
1127 #Reconstruct Function
1129 if fit==True:
1128 if fit==True:
1130 groupArray = dataOut.groupList
1129 groupArray = dataOut.groupList
1131 listChannels = groupArray.reshape((groupArray.size))
1130 listChannels = groupArray.reshape((groupArray.size))
1132 listChannels.sort()
1131 listChannels.sort()
1133 spcFitLine = numpy.zeros(z.shape)
1132 spcFitLine = numpy.zeros(z.shape)
1134 constants = dataOut.constants
1133 constants = dataOut.constants
1135
1134
1136 nGroups = groupArray.shape[0]
1135 nGroups = groupArray.shape[0]
1137 nChannels = groupArray.shape[1]
1136 nChannels = groupArray.shape[1]
1138 nProfiles = z.shape[1]
1137 nProfiles = z.shape[1]
1139
1138
1140 for f in range(nGroups):
1139 for f in range(nGroups):
1141 groupChann = groupArray[f,:]
1140 groupChann = groupArray[f,:]
1142 p = dataOut.data_param[f,:,heightindex]
1141 p = dataOut.data_param[f,:,heightindex]
1143 # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167])
1142 # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167])
1144 fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles
1143 fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles
1145 fitLineAux = fitLineAux.reshape((nChannels,nProfiles))
1144 fitLineAux = fitLineAux.reshape((nChannels,nProfiles))
1146 spcFitLine[groupChann,:] = fitLineAux
1145 spcFitLine[groupChann,:] = fitLineAux
1147 # spcFitLine = spcFitLine/factor
1146 # spcFitLine = spcFitLine/factor
1148
1147
1149 z = z[listChannels,:]
1148 z = z[listChannels,:]
1150 spcFitLine = spcFitLine[listChannels,:]
1149 spcFitLine = spcFitLine[listChannels,:]
1151 spcFitLinedB = 10*numpy.log10(spcFitLine)
1150 spcFitLinedB = 10*numpy.log10(spcFitLine)
1152
1151
1153 zdB = 10*numpy.log10(z)
1152 zdB = 10*numpy.log10(z)
1154 #thisDatetime = dataOut.datatime
1153 #thisDatetime = dataOut.datatime
1155 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1154 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1156 title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1155 title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1157 xlabel = "Velocity (m/s)"
1156 xlabel = "Velocity (m/s)"
1158 ylabel = "Spectrum"
1157 ylabel = "Spectrum"
1159
1158
1160 if not self.isConfig:
1159 if not self.isConfig:
1161
1160
1162 nplots = listChannels.size
1161 nplots = listChannels.size
1163
1162
1164 self.setup(id=id,
1163 self.setup(id=id,
1165 nplots=nplots,
1164 nplots=nplots,
1166 wintitle=wintitle,
1165 wintitle=wintitle,
1167 showprofile=showprofile,
1166 showprofile=showprofile,
1168 show=show)
1167 show=show)
1169
1168
1170 if xmin == None: xmin = numpy.nanmin(x)
1169 if xmin == None: xmin = numpy.nanmin(x)
1171 if xmax == None: xmax = numpy.nanmax(x)
1170 if xmax == None: xmax = numpy.nanmax(x)
1172 if ymin == None: ymin = numpy.nanmin(zdB)
1171 if ymin == None: ymin = numpy.nanmin(zdB)
1173 if ymax == None: ymax = numpy.nanmax(zdB)+2
1172 if ymax == None: ymax = numpy.nanmax(zdB)+2
1174
1173
1175 self.isConfig = True
1174 self.isConfig = True
1176
1175
1177 self.setWinTitle(title)
1176 self.setWinTitle(title)
1178 for i in range(self.nplots):
1177 for i in range(self.nplots):
1179 # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i])
1178 # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i])
1180 title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i])
1179 title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i])
1181 axes = self.axesList[i*self.__nsubplots]
1180 axes = self.axesList[i*self.__nsubplots]
1182 if fit == False:
1181 if fit == False:
1183 axes.pline(x, zdB[i,:],
1182 axes.pline(x, zdB[i,:],
1184 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1183 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1185 xlabel=xlabel, ylabel=ylabel, title=title
1184 xlabel=xlabel, ylabel=ylabel, title=title
1186 )
1185 )
1187 if fit == True:
1186 if fit == True:
1188 fitline=spcFitLinedB[i,:]
1187 fitline=spcFitLinedB[i,:]
1189 y=numpy.vstack([zdB[i,:],fitline] )
1188 y=numpy.vstack([zdB[i,:],fitline] )
1190 legendlabels=['Data','Fitting']
1189 legendlabels=['Data','Fitting']
1191 axes.pmultilineyaxis(x, y,
1190 axes.pmultilineyaxis(x, y,
1192 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1191 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1193 xlabel=xlabel, ylabel=ylabel, title=title,
1192 xlabel=xlabel, ylabel=ylabel, title=title,
1194 legendlabels=legendlabels, marker=None,
1193 legendlabels=legendlabels, marker=None,
1195 linestyle='solid', grid='both')
1194 linestyle='solid', grid='both')
1196
1195
1197 self.draw()
1196 self.draw()
1198
1197
1199 self.save(figpath=figpath,
1198 self.save(figpath=figpath,
1200 figfile=figfile,
1199 figfile=figfile,
1201 save=save,
1200 save=save,
1202 ftp=ftp,
1201 ftp=ftp,
1203 wr_period=wr_period,
1202 wr_period=wr_period,
1204 thisDatetime=thisDatetime)
1203 thisDatetime=thisDatetime)
1205
1204
1206
1205
1207 class EWDriftsPlot(Figure):
1206 class EWDriftsPlot(Figure):
1208
1207
1209 __isConfig = None
1208 __isConfig = None
1210 __nsubplots = None
1209 __nsubplots = None
1211
1210
1212 WIDTHPROF = None
1211 WIDTHPROF = None
1213 HEIGHTPROF = None
1212 HEIGHTPROF = None
1214 PREFIX = 'drift'
1213 PREFIX = 'drift'
1215
1214
1216 def __init__(self, **kwargs):
1215 def __init__(self, **kwargs):
1217 Figure.__init__(self, **kwargs)
1216 Figure.__init__(self, **kwargs)
1218 self.timerange = 2*60*60
1217 self.timerange = 2*60*60
1219 self.isConfig = False
1218 self.isConfig = False
1220 self.__nsubplots = 1
1219 self.__nsubplots = 1
1221
1220
1222 self.WIDTH = 800
1221 self.WIDTH = 800
1223 self.HEIGHT = 150
1222 self.HEIGHT = 150
1224 self.WIDTHPROF = 120
1223 self.WIDTHPROF = 120
1225 self.HEIGHTPROF = 0
1224 self.HEIGHTPROF = 0
1226 self.counter_imagwr = 0
1225 self.counter_imagwr = 0
1227
1226
1228 self.PLOT_CODE = EWDRIFT_CODE
1227 self.PLOT_CODE = EWDRIFT_CODE
1229
1228
1230 self.FTP_WEI = None
1229 self.FTP_WEI = None
1231 self.EXP_CODE = None
1230 self.EXP_CODE = None
1232 self.SUB_EXP_CODE = None
1231 self.SUB_EXP_CODE = None
1233 self.PLOT_POS = None
1232 self.PLOT_POS = None
1234 self.tmin = None
1233 self.tmin = None
1235 self.tmax = None
1234 self.tmax = None
1236
1235
1237 self.xmin = None
1236 self.xmin = None
1238 self.xmax = None
1237 self.xmax = None
1239
1238
1240 self.figfile = None
1239 self.figfile = None
1241
1240
1242 def getSubplots(self):
1241 def getSubplots(self):
1243
1242
1244 ncol = 1
1243 ncol = 1
1245 nrow = self.nplots
1244 nrow = self.nplots
1246
1245
1247 return nrow, ncol
1246 return nrow, ncol
1248
1247
1249 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1248 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1250
1249
1251 self.__showprofile = showprofile
1250 self.__showprofile = showprofile
1252 self.nplots = nplots
1251 self.nplots = nplots
1253
1252
1254 ncolspan = 1
1253 ncolspan = 1
1255 colspan = 1
1254 colspan = 1
1256
1255
1257 self.createFigure(id = id,
1256 self.createFigure(id = id,
1258 wintitle = wintitle,
1257 wintitle = wintitle,
1259 widthplot = self.WIDTH + self.WIDTHPROF,
1258 widthplot = self.WIDTH + self.WIDTHPROF,
1260 heightplot = self.HEIGHT + self.HEIGHTPROF,
1259 heightplot = self.HEIGHT + self.HEIGHTPROF,
1261 show=show)
1260 show=show)
1262
1261
1263 nrow, ncol = self.getSubplots()
1262 nrow, ncol = self.getSubplots()
1264
1263
1265 counter = 0
1264 counter = 0
1266 for y in range(nrow):
1265 for y in range(nrow):
1267 if counter >= self.nplots:
1266 if counter >= self.nplots:
1268 break
1267 break
1269
1268
1270 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
1269 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
1271 counter += 1
1270 counter += 1
1272
1271
1273 def run(self, dataOut, id, wintitle="", channelList=None,
1272 def run(self, dataOut, id, wintitle="", channelList=None,
1274 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
1273 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
1275 zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None,
1274 zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None,
1276 timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False,
1275 timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False,
1277 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1276 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1278 server=None, folder=None, username=None, password=None,
1277 server=None, folder=None, username=None, password=None,
1279 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1278 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1280 """
1279 """
1281
1280
1282 Input:
1281 Input:
1283 dataOut :
1282 dataOut :
1284 id :
1283 id :
1285 wintitle :
1284 wintitle :
1286 channelList :
1285 channelList :
1287 showProfile :
1286 showProfile :
1288 xmin : None,
1287 xmin : None,
1289 xmax : None,
1288 xmax : None,
1290 ymin : None,
1289 ymin : None,
1291 ymax : None,
1290 ymax : None,
1292 zmin : None,
1291 zmin : None,
1293 zmax : None
1292 zmax : None
1294 """
1293 """
1295
1294
1296 if timerange is not None:
1295 if timerange is not None:
1297 self.timerange = timerange
1296 self.timerange = timerange
1298
1297
1299 tmin = None
1298 tmin = None
1300 tmax = None
1299 tmax = None
1301
1300
1302 x = dataOut.getTimeRange1(dataOut.outputInterval)
1301 x = dataOut.getTimeRange1(dataOut.outputInterval)
1303 # y = dataOut.heightList
1302 # y = dataOut.heightList
1304 y = dataOut.heightList
1303 y = dataOut.heightList
1305
1304
1306 z = dataOut.data_output
1305 z = dataOut.data_output
1307 nplots = z.shape[0] #Number of wind dimensions estimated
1306 nplots = z.shape[0] #Number of wind dimensions estimated
1308 nplotsw = nplots
1307 nplotsw = nplots
1309
1308
1310 #If there is a SNR function defined
1309 #If there is a SNR function defined
1311 if dataOut.data_SNR is not None:
1310 if dataOut.data_SNR is not None:
1312 nplots += 1
1311 nplots += 1
1313 SNR = dataOut.data_SNR
1312 SNR = dataOut.data_SNR
1314
1313
1315 if SNR_1:
1314 if SNR_1:
1316 SNR += 1
1315 SNR += 1
1317
1316
1318 SNRavg = numpy.average(SNR, axis=0)
1317 SNRavg = numpy.average(SNR, axis=0)
1319
1318
1320 SNRdB = 10*numpy.log10(SNR)
1319 SNRdB = 10*numpy.log10(SNR)
1321 SNRavgdB = 10*numpy.log10(SNRavg)
1320 SNRavgdB = 10*numpy.log10(SNRavg)
1322
1321
1323 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
1322 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
1324
1323
1325 for i in range(nplotsw):
1324 for i in range(nplotsw):
1326 z[i,ind] = numpy.nan
1325 z[i,ind] = numpy.nan
1327
1326
1328
1327
1329 showprofile = False
1328 showprofile = False
1330 # thisDatetime = dataOut.datatime
1329 # thisDatetime = dataOut.datatime
1331 thisDatetime = datetime.datetime.utcfromtimestamp(x[1])
1330 thisDatetime = datetime.datetime.utcfromtimestamp(x[1])
1332 title = wintitle + " EW Drifts"
1331 title = wintitle + " EW Drifts"
1333 xlabel = ""
1332 xlabel = ""
1334 ylabel = "Height (Km)"
1333 ylabel = "Height (Km)"
1335
1334
1336 if not self.isConfig:
1335 if not self.isConfig:
1337
1336
1338 self.setup(id=id,
1337 self.setup(id=id,
1339 nplots=nplots,
1338 nplots=nplots,
1340 wintitle=wintitle,
1339 wintitle=wintitle,
1341 showprofile=showprofile,
1340 showprofile=showprofile,
1342 show=show)
1341 show=show)
1343
1342
1344 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1343 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1345
1344
1346 if ymin == None: ymin = numpy.nanmin(y)
1345 if ymin == None: ymin = numpy.nanmin(y)
1347 if ymax == None: ymax = numpy.nanmax(y)
1346 if ymax == None: ymax = numpy.nanmax(y)
1348
1347
1349 if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:]))
1348 if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:]))
1350 if zminZonal == None: zminZonal = -zmaxZonal
1349 if zminZonal == None: zminZonal = -zmaxZonal
1351 if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:]))
1350 if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:]))
1352 if zminVertical == None: zminVertical = -zmaxVertical
1351 if zminVertical == None: zminVertical = -zmaxVertical
1353
1352
1354 if dataOut.data_SNR is not None:
1353 if dataOut.data_SNR is not None:
1355 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
1354 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
1356 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
1355 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
1357
1356
1358 self.FTP_WEI = ftp_wei
1357 self.FTP_WEI = ftp_wei
1359 self.EXP_CODE = exp_code
1358 self.EXP_CODE = exp_code
1360 self.SUB_EXP_CODE = sub_exp_code
1359 self.SUB_EXP_CODE = sub_exp_code
1361 self.PLOT_POS = plot_pos
1360 self.PLOT_POS = plot_pos
1362
1361
1363 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1362 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1364 self.isConfig = True
1363 self.isConfig = True
1365
1364
1366
1365
1367 self.setWinTitle(title)
1366 self.setWinTitle(title)
1368
1367
1369 if ((self.xmax - x[1]) < (x[1]-x[0])):
1368 if ((self.xmax - x[1]) < (x[1]-x[0])):
1370 x[1] = self.xmax
1369 x[1] = self.xmax
1371
1370
1372 strWind = ['Zonal','Vertical']
1371 strWind = ['Zonal','Vertical']
1373 strCb = 'Velocity (m/s)'
1372 strCb = 'Velocity (m/s)'
1374 zmaxVector = [zmaxZonal, zmaxVertical]
1373 zmaxVector = [zmaxZonal, zmaxVertical]
1375 zminVector = [zminZonal, zminVertical]
1374 zminVector = [zminZonal, zminVertical]
1376
1375
1377 for i in range(nplotsw):
1376 for i in range(nplotsw):
1378
1377
1379 title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1378 title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1380 axes = self.axesList[i*self.__nsubplots]
1379 axes = self.axesList[i*self.__nsubplots]
1381
1380
1382 z1 = z[i,:].reshape((1,-1))
1381 z1 = z[i,:].reshape((1,-1))
1383
1382
1384 axes.pcolorbuffer(x, y, z1,
1383 axes.pcolorbuffer(x, y, z1,
1385 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
1384 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
1386 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1385 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1387 ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r")
1386 ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r")
1388
1387
1389 if dataOut.data_SNR is not None:
1388 if dataOut.data_SNR is not None:
1390 i += 1
1389 i += 1
1391 if SNR_1:
1390 if SNR_1:
1392 title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1391 title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1393 else:
1392 else:
1394 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1393 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1395 axes = self.axesList[i*self.__nsubplots]
1394 axes = self.axesList[i*self.__nsubplots]
1396 SNRavgdB = SNRavgdB.reshape((1,-1))
1395 SNRavgdB = SNRavgdB.reshape((1,-1))
1397
1396
1398 axes.pcolorbuffer(x, y, SNRavgdB,
1397 axes.pcolorbuffer(x, y, SNRavgdB,
1399 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1398 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1400 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1399 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1401 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
1400 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
1402
1401
1403 self.draw()
1402 self.draw()
1404
1403
1405 if x[1] >= self.axesList[0].xmax:
1404 if x[1] >= self.axesList[0].xmax:
1406 self.counter_imagwr = wr_period
1405 self.counter_imagwr = wr_period
1407 self.isConfig = False
1406 self.isConfig = False
1408 self.figfile = None
1407 self.figfile = None
1409
1408
1410
1409
1411
1410
1412
1411
1413 class PhasePlot(Figure):
1412 class PhasePlot(Figure):
1414
1413
1415 __isConfig = None
1414 __isConfig = None
1416 __nsubplots = None
1415 __nsubplots = None
1417
1416
1418 PREFIX = 'mphase'
1417 PREFIX = 'mphase'
1419
1418
1419
1420 def __init__(self, **kwargs):
1420 def __init__(self, **kwargs):
1421 Figure.__init__(self, **kwargs)
1421 Figure.__init__(self, **kwargs)
1422 self.timerange = 24*60*60
1422 self.timerange = 24*60*60
1423 self.isConfig = False
1423 self.isConfig = False
1424 self.__nsubplots = 1
1424 self.__nsubplots = 1
1425 self.counter_imagwr = 0
1425 self.counter_imagwr = 0
1426 self.WIDTH = 600
1426 self.WIDTH = 600
1427 self.HEIGHT = 300
1427 self.HEIGHT = 300
1428 self.WIDTHPROF = 120
1428 self.WIDTHPROF = 120
1429 self.HEIGHTPROF = 0
1429 self.HEIGHTPROF = 0
1430 self.xdata = None
1430 self.xdata = None
1431 self.ydata = None
1431 self.ydata = None
1432
1432
1433 self.PLOT_CODE = MPHASE_CODE
1433 self.PLOT_CODE = MPHASE_CODE
1434
1434
1435 self.FTP_WEI = None
1435 self.FTP_WEI = None
1436 self.EXP_CODE = None
1436 self.EXP_CODE = None
1437 self.SUB_EXP_CODE = None
1437 self.SUB_EXP_CODE = None
1438 self.PLOT_POS = None
1438 self.PLOT_POS = None
1439
1439
1440
1440
1441 self.filename_phase = None
1441 self.filename_phase = None
1442
1442
1443 self.figfile = None
1443 self.figfile = None
1444
1444
1445 def getSubplots(self):
1445 def getSubplots(self):
1446
1446
1447 ncol = 1
1447 ncol = 1
1448 nrow = 1
1448 nrow = 1
1449
1449
1450 return nrow, ncol
1450 return nrow, ncol
1451
1451
1452 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1452 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1453
1453
1454 self.__showprofile = showprofile
1454 self.__showprofile = showprofile
1455 self.nplots = nplots
1455 self.nplots = nplots
1456
1456
1457 ncolspan = 7
1457 ncolspan = 7
1458 colspan = 6
1458 colspan = 6
1459 self.__nsubplots = 2
1459 self.__nsubplots = 2
1460
1460
1461 self.createFigure(id = id,
1461 self.createFigure(id = id,
1462 wintitle = wintitle,
1462 wintitle = wintitle,
1463 widthplot = self.WIDTH+self.WIDTHPROF,
1463 widthplot = self.WIDTH+self.WIDTHPROF,
1464 heightplot = self.HEIGHT+self.HEIGHTPROF,
1464 heightplot = self.HEIGHT+self.HEIGHTPROF,
1465 show=show)
1465 show=show)
1466
1466
1467 nrow, ncol = self.getSubplots()
1467 nrow, ncol = self.getSubplots()
1468
1468
1469 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1469 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1470
1470
1471
1471
1472 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1472 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1473 xmin=None, xmax=None, ymin=None, ymax=None,
1473 xmin=None, xmax=None, ymin=None, ymax=None,
1474 timerange=None,
1474 timerange=None,
1475 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1475 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1476 server=None, folder=None, username=None, password=None,
1476 server=None, folder=None, username=None, password=None,
1477 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1477 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1478
1478
1479
1479
1480 tmin = None
1480 tmin = None
1481 tmax = None
1481 tmax = None
1482 x = dataOut.getTimeRange1(dataOut.outputInterval)
1482 x = dataOut.getTimeRange1(dataOut.outputInterval)
1483 y = dataOut.getHeiRange()
1483 y = dataOut.getHeiRange()
1484
1484
1485
1485
1486 #thisDatetime = dataOut.datatime
1486 #thisDatetime = dataOut.datatime
1487 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1487 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1488 title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1488 title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1489 xlabel = "Local Time"
1489 xlabel = "Local Time"
1490 ylabel = "Phase"
1490 ylabel = "Phase"
1491
1491
1492
1492
1493 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1493 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1494 phase_beacon = dataOut.data_output
1494 phase_beacon = dataOut.data_output
1495 update_figfile = False
1495 update_figfile = False
1496
1496
1497 if not self.isConfig:
1497 if not self.isConfig:
1498
1498
1499 self.nplots = phase_beacon.size
1499 self.nplots = phase_beacon.size
1500
1500
1501 self.setup(id=id,
1501 self.setup(id=id,
1502 nplots=self.nplots,
1502 nplots=self.nplots,
1503 wintitle=wintitle,
1503 wintitle=wintitle,
1504 showprofile=showprofile,
1504 showprofile=showprofile,
1505 show=show)
1505 show=show)
1506
1506
1507 if timerange is not None:
1507 if timerange is not None:
1508 self.timerange = timerange
1508 self.timerange = timerange
1509
1509
1510 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1510 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1511
1511
1512 if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0
1512 if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0
1513 if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0
1513 if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0
1514
1514
1515 self.FTP_WEI = ftp_wei
1515 self.FTP_WEI = ftp_wei
1516 self.EXP_CODE = exp_code
1516 self.EXP_CODE = exp_code
1517 self.SUB_EXP_CODE = sub_exp_code
1517 self.SUB_EXP_CODE = sub_exp_code
1518 self.PLOT_POS = plot_pos
1518 self.PLOT_POS = plot_pos
1519
1519
1520 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1520 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1521 self.isConfig = True
1521 self.isConfig = True
1522 self.figfile = figfile
1522 self.figfile = figfile
1523 self.xdata = numpy.array([])
1523 self.xdata = numpy.array([])
1524 self.ydata = numpy.array([])
1524 self.ydata = numpy.array([])
1525
1525
1526 #open file beacon phase
1526 #open file beacon phase
1527 path = '%s%03d' %(self.PREFIX, self.id)
1527 path = '%s%03d' %(self.PREFIX, self.id)
1528 beacon_file = os.path.join(path,'%s.txt'%self.name)
1528 beacon_file = os.path.join(path,'%s.txt'%self.name)
1529 self.filename_phase = os.path.join(figpath,beacon_file)
1529 self.filename_phase = os.path.join(figpath,beacon_file)
1530 update_figfile = True
1530 update_figfile = True
1531
1531
1532
1532
1533 #store data beacon phase
1533 #store data beacon phase
1534 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1534 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1535
1535
1536 self.setWinTitle(title)
1536 self.setWinTitle(title)
1537
1537
1538
1538
1539 title = "Phase Offset %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1539 title = "Phase Offset %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1540
1540
1541 legendlabels = ["phase %d"%(chan) for chan in numpy.arange(self.nplots)]
1541 legendlabels = ["phase %d"%(chan) for chan in numpy.arange(self.nplots)]
1542
1542
1543 axes = self.axesList[0]
1543 axes = self.axesList[0]
1544
1544
1545 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1545 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1546
1546
1547 if len(self.ydata)==0:
1547 if len(self.ydata)==0:
1548 self.ydata = phase_beacon.reshape(-1,1)
1548 self.ydata = phase_beacon.reshape(-1,1)
1549 else:
1549 else:
1550 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1550 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1551
1551
1552
1552
1553 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1553 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1554 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1554 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1555 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1555 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1556 XAxisAsTime=True, grid='both'
1556 XAxisAsTime=True, grid='both'
1557 )
1557 )
1558
1558
1559 self.draw()
1559 self.draw()
1560
1560
1561 self.save(figpath=figpath,
1561 self.save(figpath=figpath,
1562 figfile=figfile,
1562 figfile=figfile,
1563 save=save,
1563 save=save,
1564 ftp=ftp,
1564 ftp=ftp,
1565 wr_period=wr_period,
1565 wr_period=wr_period,
1566 thisDatetime=thisDatetime,
1566 thisDatetime=thisDatetime,
1567 update_figfile=update_figfile)
1567 update_figfile=update_figfile)
1568
1568
1569 if dataOut.ltctime + dataOut.outputInterval >= self.xmax:
1569 if dataOut.ltctime + dataOut.outputInterval >= self.xmax:
1570 self.counter_imagwr = wr_period
1570 self.counter_imagwr = wr_period
1571 self.isConfig = False
1571 self.isConfig = False
1572 update_figfile = True
1572 update_figfile = True
1573
1573
1574
1574
1575
1575
1576 class NSMeteorDetection1Plot(Figure):
1576 class NSMeteorDetection1Plot(Figure):
1577
1577
1578 isConfig = None
1578 isConfig = None
1579 __nsubplots = None
1579 __nsubplots = None
1580
1580
1581 WIDTHPROF = None
1581 WIDTHPROF = None
1582 HEIGHTPROF = None
1582 HEIGHTPROF = None
1583 PREFIX = 'nsm'
1583 PREFIX = 'nsm'
1584
1584
1585 zminList = None
1585 zminList = None
1586 zmaxList = None
1586 zmaxList = None
1587 cmapList = None
1587 cmapList = None
1588 titleList = None
1588 titleList = None
1589 nPairs = None
1589 nPairs = None
1590 nChannels = None
1590 nChannels = None
1591 nParam = None
1591 nParam = None
1592
1592
1593 def __init__(self, **kwargs):
1593 def __init__(self, **kwargs):
1594 Figure.__init__(self, **kwargs)
1594 Figure.__init__(self, **kwargs)
1595 self.isConfig = False
1595 self.isConfig = False
1596 self.__nsubplots = 1
1596 self.__nsubplots = 1
1597
1597
1598 self.WIDTH = 750
1598 self.WIDTH = 750
1599 self.HEIGHT = 250
1599 self.HEIGHT = 250
1600 self.WIDTHPROF = 120
1600 self.WIDTHPROF = 120
1601 self.HEIGHTPROF = 0
1601 self.HEIGHTPROF = 0
1602 self.counter_imagwr = 0
1602 self.counter_imagwr = 0
1603
1603
1604 self.PLOT_CODE = SPEC_CODE
1604 self.PLOT_CODE = SPEC_CODE
1605
1605
1606 self.FTP_WEI = None
1606 self.FTP_WEI = None
1607 self.EXP_CODE = None
1607 self.EXP_CODE = None
1608 self.SUB_EXP_CODE = None
1608 self.SUB_EXP_CODE = None
1609 self.PLOT_POS = None
1609 self.PLOT_POS = None
1610
1610
1611 self.__xfilter_ena = False
1611 self.__xfilter_ena = False
1612 self.__yfilter_ena = False
1612 self.__yfilter_ena = False
1613
1613
1614 def getSubplots(self):
1614 def getSubplots(self):
1615
1615
1616 ncol = 3
1616 ncol = 3
1617 nrow = int(numpy.ceil(self.nplots/3.0))
1617 nrow = int(numpy.ceil(self.nplots/3.0))
1618
1618
1619 return nrow, ncol
1619 return nrow, ncol
1620
1620
1621 def setup(self, id, nplots, wintitle, show=True):
1621 def setup(self, id, nplots, wintitle, show=True):
1622
1622
1623 self.nplots = nplots
1623 self.nplots = nplots
1624
1624
1625 ncolspan = 1
1625 ncolspan = 1
1626 colspan = 1
1626 colspan = 1
1627
1627
1628 self.createFigure(id = id,
1628 self.createFigure(id = id,
1629 wintitle = wintitle,
1629 wintitle = wintitle,
1630 widthplot = self.WIDTH + self.WIDTHPROF,
1630 widthplot = self.WIDTH + self.WIDTHPROF,
1631 heightplot = self.HEIGHT + self.HEIGHTPROF,
1631 heightplot = self.HEIGHT + self.HEIGHTPROF,
1632 show=show)
1632 show=show)
1633
1633
1634 nrow, ncol = self.getSubplots()
1634 nrow, ncol = self.getSubplots()
1635
1635
1636 counter = 0
1636 counter = 0
1637 for y in range(nrow):
1637 for y in range(nrow):
1638 for x in range(ncol):
1638 for x in range(ncol):
1639
1639
1640 if counter >= self.nplots:
1640 if counter >= self.nplots:
1641 break
1641 break
1642
1642
1643 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1643 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1644
1644
1645 counter += 1
1645 counter += 1
1646
1646
1647 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
1647 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
1648 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
1648 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
1649 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
1649 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
1650 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1650 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1651 server=None, folder=None, username=None, password=None,
1651 server=None, folder=None, username=None, password=None,
1652 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
1652 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
1653 xaxis="frequency"):
1653 xaxis="frequency"):
1654
1654
1655 """
1655 """
1656
1656
1657 Input:
1657 Input:
1658 dataOut :
1658 dataOut :
1659 id :
1659 id :
1660 wintitle :
1660 wintitle :
1661 channelList :
1661 channelList :
1662 showProfile :
1662 showProfile :
1663 xmin : None,
1663 xmin : None,
1664 xmax : None,
1664 xmax : None,
1665 ymin : None,
1665 ymin : None,
1666 ymax : None,
1666 ymax : None,
1667 zmin : None,
1667 zmin : None,
1668 zmax : None
1668 zmax : None
1669 """
1669 """
1670 #SEPARAR EN DOS PLOTS
1670 #SEPARAR EN DOS PLOTS
1671 nParam = dataOut.data_param.shape[1] - 3
1671 nParam = dataOut.data_param.shape[1] - 3
1672
1672
1673 utctime = dataOut.data_param[0,0]
1673 utctime = dataOut.data_param[0,0]
1674 tmet = dataOut.data_param[:,1].astype(int)
1674 tmet = dataOut.data_param[:,1].astype(int)
1675 hmet = dataOut.data_param[:,2].astype(int)
1675 hmet = dataOut.data_param[:,2].astype(int)
1676
1676
1677 x = dataOut.abscissaList
1677 x = dataOut.abscissaList
1678 y = dataOut.heightList
1678 y = dataOut.heightList
1679
1679
1680 z = numpy.zeros((nParam, y.size, x.size - 1))
1680 z = numpy.zeros((nParam, y.size, x.size - 1))
1681 z[:,:] = numpy.nan
1681 z[:,:] = numpy.nan
1682 z[:,hmet,tmet] = dataOut.data_param[:,3:].T
1682 z[:,hmet,tmet] = dataOut.data_param[:,3:].T
1683 z[0,:,:] = 10*numpy.log10(z[0,:,:])
1683 z[0,:,:] = 10*numpy.log10(z[0,:,:])
1684
1684
1685 xlabel = "Time (s)"
1685 xlabel = "Time (s)"
1686 ylabel = "Range (km)"
1686 ylabel = "Range (km)"
1687
1687
1688 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1688 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1689
1689
1690 if not self.isConfig:
1690 if not self.isConfig:
1691
1691
1692 nplots = nParam
1692 nplots = nParam
1693
1693
1694 self.setup(id=id,
1694 self.setup(id=id,
1695 nplots=nplots,
1695 nplots=nplots,
1696 wintitle=wintitle,
1696 wintitle=wintitle,
1697 show=show)
1697 show=show)
1698
1698
1699 if xmin is None: xmin = numpy.nanmin(x)
1699 if xmin is None: xmin = numpy.nanmin(x)
1700 if xmax is None: xmax = numpy.nanmax(x)
1700 if xmax is None: xmax = numpy.nanmax(x)
1701 if ymin is None: ymin = numpy.nanmin(y)
1701 if ymin is None: ymin = numpy.nanmin(y)
1702 if ymax is None: ymax = numpy.nanmax(y)
1702 if ymax is None: ymax = numpy.nanmax(y)
1703 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
1703 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
1704 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
1704 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
1705 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
1705 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
1706 if vmin is None: vmin = -vmax
1706 if vmin is None: vmin = -vmax
1707 if wmin is None: wmin = 0
1707 if wmin is None: wmin = 0
1708 if wmax is None: wmax = 50
1708 if wmax is None: wmax = 50
1709
1709
1710 pairsList = dataOut.groupList
1710 pairsList = dataOut.groupList
1711 self.nPairs = len(dataOut.groupList)
1711 self.nPairs = len(dataOut.groupList)
1712
1712
1713 zminList = [SNRmin, vmin, cmin] + [pmin]*self.nPairs
1713 zminList = [SNRmin, vmin, cmin] + [pmin]*self.nPairs
1714 zmaxList = [SNRmax, vmax, cmax] + [pmax]*self.nPairs
1714 zmaxList = [SNRmax, vmax, cmax] + [pmax]*self.nPairs
1715 titleList = ["SNR","Radial Velocity","Coherence"]
1715 titleList = ["SNR","Radial Velocity","Coherence"]
1716 cmapList = ["jet","RdBu_r","jet"]
1716 cmapList = ["jet","RdBu_r","jet"]
1717
1717
1718 for i in range(self.nPairs):
1718 for i in range(self.nPairs):
1719 strAux1 = "Phase Difference "+ str(pairsList[i][0]) + str(pairsList[i][1])
1719 strAux1 = "Phase Difference "+ str(pairsList[i][0]) + str(pairsList[i][1])
1720 titleList = titleList + [strAux1]
1720 titleList = titleList + [strAux1]
1721 cmapList = cmapList + ["RdBu_r"]
1721 cmapList = cmapList + ["RdBu_r"]
1722
1722
1723 self.zminList = zminList
1723 self.zminList = zminList
1724 self.zmaxList = zmaxList
1724 self.zmaxList = zmaxList
1725 self.cmapList = cmapList
1725 self.cmapList = cmapList
1726 self.titleList = titleList
1726 self.titleList = titleList
1727
1727
1728 self.FTP_WEI = ftp_wei
1728 self.FTP_WEI = ftp_wei
1729 self.EXP_CODE = exp_code
1729 self.EXP_CODE = exp_code
1730 self.SUB_EXP_CODE = sub_exp_code
1730 self.SUB_EXP_CODE = sub_exp_code
1731 self.PLOT_POS = plot_pos
1731 self.PLOT_POS = plot_pos
1732
1732
1733 self.isConfig = True
1733 self.isConfig = True
1734
1734
1735 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
1735 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
1736
1736
1737 for i in range(nParam):
1737 for i in range(nParam):
1738 title = self.titleList[i] + ": " +str_datetime
1738 title = self.titleList[i] + ": " +str_datetime
1739 axes = self.axesList[i]
1739 axes = self.axesList[i]
1740 axes.pcolor(x, y, z[i,:].T,
1740 axes.pcolor(x, y, z[i,:].T,
1741 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
1741 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
1742 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
1742 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
1743 self.draw()
1743 self.draw()
1744
1744
1745 if figfile == None:
1745 if figfile == None:
1746 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1746 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1747 name = str_datetime
1747 name = str_datetime
1748 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1748 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1749 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
1749 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
1750 figfile = self.getFilename(name)
1750 figfile = self.getFilename(name)
1751
1751
1752 self.save(figpath=figpath,
1752 self.save(figpath=figpath,
1753 figfile=figfile,
1753 figfile=figfile,
1754 save=save,
1754 save=save,
1755 ftp=ftp,
1755 ftp=ftp,
1756 wr_period=wr_period,
1756 wr_period=wr_period,
1757 thisDatetime=thisDatetime)
1757 thisDatetime=thisDatetime)
1758
1758
1759
1759
1760 class NSMeteorDetection2Plot(Figure):
1760 class NSMeteorDetection2Plot(Figure):
1761
1761
1762 isConfig = None
1762 isConfig = None
1763 __nsubplots = None
1763 __nsubplots = None
1764
1764
1765 WIDTHPROF = None
1765 WIDTHPROF = None
1766 HEIGHTPROF = None
1766 HEIGHTPROF = None
1767 PREFIX = 'nsm'
1767 PREFIX = 'nsm'
1768
1768
1769 zminList = None
1769 zminList = None
1770 zmaxList = None
1770 zmaxList = None
1771 cmapList = None
1771 cmapList = None
1772 titleList = None
1772 titleList = None
1773 nPairs = None
1773 nPairs = None
1774 nChannels = None
1774 nChannels = None
1775 nParam = None
1775 nParam = None
1776
1776
1777 def __init__(self, **kwargs):
1777 def __init__(self, **kwargs):
1778 Figure.__init__(self, **kwargs)
1778 Figure.__init__(self, **kwargs)
1779 self.isConfig = False
1779 self.isConfig = False
1780 self.__nsubplots = 1
1780 self.__nsubplots = 1
1781
1781
1782 self.WIDTH = 750
1782 self.WIDTH = 750
1783 self.HEIGHT = 250
1783 self.HEIGHT = 250
1784 self.WIDTHPROF = 120
1784 self.WIDTHPROF = 120
1785 self.HEIGHTPROF = 0
1785 self.HEIGHTPROF = 0
1786 self.counter_imagwr = 0
1786 self.counter_imagwr = 0
1787
1787
1788 self.PLOT_CODE = SPEC_CODE
1788 self.PLOT_CODE = SPEC_CODE
1789
1789
1790 self.FTP_WEI = None
1790 self.FTP_WEI = None
1791 self.EXP_CODE = None
1791 self.EXP_CODE = None
1792 self.SUB_EXP_CODE = None
1792 self.SUB_EXP_CODE = None
1793 self.PLOT_POS = None
1793 self.PLOT_POS = None
1794
1794
1795 self.__xfilter_ena = False
1795 self.__xfilter_ena = False
1796 self.__yfilter_ena = False
1796 self.__yfilter_ena = False
1797
1797
1798 def getSubplots(self):
1798 def getSubplots(self):
1799
1799
1800 ncol = 3
1800 ncol = 3
1801 nrow = int(numpy.ceil(self.nplots/3.0))
1801 nrow = int(numpy.ceil(self.nplots/3.0))
1802
1802
1803 return nrow, ncol
1803 return nrow, ncol
1804
1804
1805 def setup(self, id, nplots, wintitle, show=True):
1805 def setup(self, id, nplots, wintitle, show=True):
1806
1806
1807 self.nplots = nplots
1807 self.nplots = nplots
1808
1808
1809 ncolspan = 1
1809 ncolspan = 1
1810 colspan = 1
1810 colspan = 1
1811
1811
1812 self.createFigure(id = id,
1812 self.createFigure(id = id,
1813 wintitle = wintitle,
1813 wintitle = wintitle,
1814 widthplot = self.WIDTH + self.WIDTHPROF,
1814 widthplot = self.WIDTH + self.WIDTHPROF,
1815 heightplot = self.HEIGHT + self.HEIGHTPROF,
1815 heightplot = self.HEIGHT + self.HEIGHTPROF,
1816 show=show)
1816 show=show)
1817
1817
1818 nrow, ncol = self.getSubplots()
1818 nrow, ncol = self.getSubplots()
1819
1819
1820 counter = 0
1820 counter = 0
1821 for y in range(nrow):
1821 for y in range(nrow):
1822 for x in range(ncol):
1822 for x in range(ncol):
1823
1823
1824 if counter >= self.nplots:
1824 if counter >= self.nplots:
1825 break
1825 break
1826
1826
1827 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1827 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1828
1828
1829 counter += 1
1829 counter += 1
1830
1830
1831 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
1831 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
1832 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
1832 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
1833 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
1833 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
1834 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1834 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1835 server=None, folder=None, username=None, password=None,
1835 server=None, folder=None, username=None, password=None,
1836 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
1836 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
1837 xaxis="frequency"):
1837 xaxis="frequency"):
1838
1838
1839 """
1839 """
1840
1840
1841 Input:
1841 Input:
1842 dataOut :
1842 dataOut :
1843 id :
1843 id :
1844 wintitle :
1844 wintitle :
1845 channelList :
1845 channelList :
1846 showProfile :
1846 showProfile :
1847 xmin : None,
1847 xmin : None,
1848 xmax : None,
1848 xmax : None,
1849 ymin : None,
1849 ymin : None,
1850 ymax : None,
1850 ymax : None,
1851 zmin : None,
1851 zmin : None,
1852 zmax : None
1852 zmax : None
1853 """
1853 """
1854 #Rebuild matrix
1854 #Rebuild matrix
1855 utctime = dataOut.data_param[0,0]
1855 utctime = dataOut.data_param[0,0]
1856 cmet = dataOut.data_param[:,1].astype(int)
1856 cmet = dataOut.data_param[:,1].astype(int)
1857 tmet = dataOut.data_param[:,2].astype(int)
1857 tmet = dataOut.data_param[:,2].astype(int)
1858 hmet = dataOut.data_param[:,3].astype(int)
1858 hmet = dataOut.data_param[:,3].astype(int)
1859
1859
1860 nParam = 3
1860 nParam = 3
1861 nChan = len(dataOut.groupList)
1861 nChan = len(dataOut.groupList)
1862 x = dataOut.abscissaList
1862 x = dataOut.abscissaList
1863 y = dataOut.heightList
1863 y = dataOut.heightList
1864
1864
1865 z = numpy.full((nChan, nParam, y.size, x.size - 1),numpy.nan)
1865 z = numpy.full((nChan, nParam, y.size, x.size - 1),numpy.nan)
1866 z[cmet,:,hmet,tmet] = dataOut.data_param[:,4:]
1866 z[cmet,:,hmet,tmet] = dataOut.data_param[:,4:]
1867 z[:,0,:,:] = 10*numpy.log10(z[:,0,:,:]) #logarithmic scale
1867 z[:,0,:,:] = 10*numpy.log10(z[:,0,:,:]) #logarithmic scale
1868 z = numpy.reshape(z, (nChan*nParam, y.size, x.size-1))
1868 z = numpy.reshape(z, (nChan*nParam, y.size, x.size-1))
1869
1869
1870 xlabel = "Time (s)"
1870 xlabel = "Time (s)"
1871 ylabel = "Range (km)"
1871 ylabel = "Range (km)"
1872
1872
1873 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1873 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1874
1874
1875 if not self.isConfig:
1875 if not self.isConfig:
1876
1876
1877 nplots = nParam*nChan
1877 nplots = nParam*nChan
1878
1878
1879 self.setup(id=id,
1879 self.setup(id=id,
1880 nplots=nplots,
1880 nplots=nplots,
1881 wintitle=wintitle,
1881 wintitle=wintitle,
1882 show=show)
1882 show=show)
1883
1883
1884 if xmin is None: xmin = numpy.nanmin(x)
1884 if xmin is None: xmin = numpy.nanmin(x)
1885 if xmax is None: xmax = numpy.nanmax(x)
1885 if xmax is None: xmax = numpy.nanmax(x)
1886 if ymin is None: ymin = numpy.nanmin(y)
1886 if ymin is None: ymin = numpy.nanmin(y)
1887 if ymax is None: ymax = numpy.nanmax(y)
1887 if ymax is None: ymax = numpy.nanmax(y)
1888 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
1888 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
1889 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
1889 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
1890 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
1890 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
1891 if vmin is None: vmin = -vmax
1891 if vmin is None: vmin = -vmax
1892 if wmin is None: wmin = 0
1892 if wmin is None: wmin = 0
1893 if wmax is None: wmax = 50
1893 if wmax is None: wmax = 50
1894
1894
1895 self.nChannels = nChan
1895 self.nChannels = nChan
1896
1896
1897 zminList = []
1897 zminList = []
1898 zmaxList = []
1898 zmaxList = []
1899 titleList = []
1899 titleList = []
1900 cmapList = []
1900 cmapList = []
1901 for i in range(self.nChannels):
1901 for i in range(self.nChannels):
1902 strAux1 = "SNR Channel "+ str(i)
1902 strAux1 = "SNR Channel "+ str(i)
1903 strAux2 = "Radial Velocity Channel "+ str(i)
1903 strAux2 = "Radial Velocity Channel "+ str(i)
1904 strAux3 = "Spectral Width Channel "+ str(i)
1904 strAux3 = "Spectral Width Channel "+ str(i)
1905
1905
1906 titleList = titleList + [strAux1,strAux2,strAux3]
1906 titleList = titleList + [strAux1,strAux2,strAux3]
1907 cmapList = cmapList + ["jet","RdBu_r","jet"]
1907 cmapList = cmapList + ["jet","RdBu_r","jet"]
1908 zminList = zminList + [SNRmin,vmin,wmin]
1908 zminList = zminList + [SNRmin,vmin,wmin]
1909 zmaxList = zmaxList + [SNRmax,vmax,wmax]
1909 zmaxList = zmaxList + [SNRmax,vmax,wmax]
1910
1910
1911 self.zminList = zminList
1911 self.zminList = zminList
1912 self.zmaxList = zmaxList
1912 self.zmaxList = zmaxList
1913 self.cmapList = cmapList
1913 self.cmapList = cmapList
1914 self.titleList = titleList
1914 self.titleList = titleList
1915
1915
1916 self.FTP_WEI = ftp_wei
1916 self.FTP_WEI = ftp_wei
1917 self.EXP_CODE = exp_code
1917 self.EXP_CODE = exp_code
1918 self.SUB_EXP_CODE = sub_exp_code
1918 self.SUB_EXP_CODE = sub_exp_code
1919 self.PLOT_POS = plot_pos
1919 self.PLOT_POS = plot_pos
1920
1920
1921 self.isConfig = True
1921 self.isConfig = True
1922
1922
1923 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
1923 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
1924
1924
1925 for i in range(self.nplots):
1925 for i in range(self.nplots):
1926 title = self.titleList[i] + ": " +str_datetime
1926 title = self.titleList[i] + ": " +str_datetime
1927 axes = self.axesList[i]
1927 axes = self.axesList[i]
1928 axes.pcolor(x, y, z[i,:].T,
1928 axes.pcolor(x, y, z[i,:].T,
1929 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
1929 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
1930 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
1930 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
1931 self.draw()
1931 self.draw()
1932
1932
1933 if figfile == None:
1933 if figfile == None:
1934 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1934 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1935 name = str_datetime
1935 name = str_datetime
1936 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1936 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1937 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
1937 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
1938 figfile = self.getFilename(name)
1938 figfile = self.getFilename(name)
1939
1939
1940 self.save(figpath=figpath,
1940 self.save(figpath=figpath,
1941 figfile=figfile,
1941 figfile=figfile,
1942 save=save,
1942 save=save,
1943 ftp=ftp,
1943 ftp=ftp,
1944 wr_period=wr_period,
1944 wr_period=wr_period,
1945 thisDatetime=thisDatetime)
1945 thisDatetime=thisDatetime)
@@ -1,1534 +1,1535
1 '''
1 '''
2 Created on Jul 9, 2014
2 Created on Jul 9, 2014
3
3
4 @author: roj-idl71
4 @author: roj-idl71
5 '''
5 '''
6 import os
6 import os
7 import datetime
7 import datetime
8 import numpy
8 import numpy
9
9
10 from figure import Figure, isRealtime, isTimeInHourRange
10 from figure import Figure, isRealtime, isTimeInHourRange
11 from plotting_codes import *
11 from plotting_codes import *
12
12
13
13 class SpectraPlot(Figure):
14 class SpectraPlot(Figure):
14
15
15 isConfig = None
16 isConfig = None
16 __nsubplots = None
17 __nsubplots = None
17
18
18 WIDTHPROF = None
19 WIDTHPROF = None
19 HEIGHTPROF = None
20 HEIGHTPROF = None
20 PREFIX = 'spc'
21 PREFIX = 'spc'
21
22
22 def __init__(self, **kwargs):
23 def __init__(self, **kwargs):
23 Figure.__init__(self, **kwargs)
24 Figure.__init__(self, **kwargs)
24 self.isConfig = False
25 self.isConfig = False
25 self.__nsubplots = 1
26 self.__nsubplots = 1
26
27
27 self.WIDTH = 1000
28 self.WIDTH = 1000
28 self.HEIGHT = 1000
29 self.HEIGHT = 1000
29 self.WIDTHPROF = 120
30 self.WIDTHPROF = 120
30 self.HEIGHTPROF = 0
31 self.HEIGHTPROF = 0
31 self.counter_imagwr = 0
32 self.counter_imagwr = 0
32
33
33 self.PLOT_CODE = SPEC_CODE
34 self.PLOT_CODE = SPEC_CODE
34
35
35 self.FTP_WEI = None
36 self.FTP_WEI = None
36 self.EXP_CODE = None
37 self.EXP_CODE = None
37 self.SUB_EXP_CODE = None
38 self.SUB_EXP_CODE = None
38 self.PLOT_POS = None
39 self.PLOT_POS = None
39
40
40 self.__xfilter_ena = False
41 self.__xfilter_ena = False
41 self.__yfilter_ena = False
42 self.__yfilter_ena = False
42
43
43 def getSubplots(self):
44 def getSubplots(self):
44
45
45 ncol = int(numpy.sqrt(self.nplots)+0.9)
46 ncol = int(numpy.sqrt(self.nplots)+0.9)
46 nrow = int(self.nplots*1./ncol + 0.9)
47 nrow = int(self.nplots*1./ncol + 0.9)
47
48
48 return nrow, ncol
49 return nrow, ncol
49
50
50 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
51 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
51
52
52 self.__showprofile = showprofile
53 self.__showprofile = showprofile
53 self.nplots = nplots
54 self.nplots = nplots
54
55
55 ncolspan = 1
56 ncolspan = 1
56 colspan = 1
57 colspan = 1
57 if showprofile:
58 if showprofile:
58 ncolspan = 3
59 ncolspan = 3
59 colspan = 2
60 colspan = 2
60 self.__nsubplots = 2
61 self.__nsubplots = 2
61
62
62 self.createFigure(id = id,
63 self.createFigure(id = id,
63 wintitle = wintitle,
64 wintitle = wintitle,
64 widthplot = self.WIDTH + self.WIDTHPROF,
65 widthplot = self.WIDTH + self.WIDTHPROF,
65 heightplot = self.HEIGHT + self.HEIGHTPROF,
66 heightplot = self.HEIGHT + self.HEIGHTPROF,
66 show=show)
67 show=show)
67
68
68 nrow, ncol = self.getSubplots()
69 nrow, ncol = self.getSubplots()
69
70
70 counter = 0
71 counter = 0
71 for y in range(nrow):
72 for y in range(nrow):
72 for x in range(ncol):
73 for x in range(ncol):
73
74
74 if counter >= self.nplots:
75 if counter >= self.nplots:
75 break
76 break
76
77
77 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
78 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
78
79
79 if showprofile:
80 if showprofile:
80 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
81 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
81
82
82 counter += 1
83 counter += 1
83
84
84 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
85 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
85 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
86 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
86 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
87 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
87 server=None, folder=None, username=None, password=None,
88 server=None, folder=None, username=None, password=None,
88 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
89 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
89 xaxis="velocity", **kwargs):
90 xaxis="velocity", **kwargs):
90
91
91 """
92 """
92
93
93 Input:
94 Input:
94 dataOut :
95 dataOut :
95 id :
96 id :
96 wintitle :
97 wintitle :
97 channelList :
98 channelList :
98 showProfile :
99 showProfile :
99 xmin : None,
100 xmin : None,
100 xmax : None,
101 xmax : None,
101 ymin : None,
102 ymin : None,
102 ymax : None,
103 ymax : None,
103 zmin : None,
104 zmin : None,
104 zmax : None
105 zmax : None
105 """
106 """
106
107
107 colormap = kwargs.get('colormap','jet')
108 colormap = kwargs.get('colormap','jet')
108
109
109 if realtime:
110 if realtime:
110 if not(isRealtime(utcdatatime = dataOut.utctime)):
111 if not(isRealtime(utcdatatime = dataOut.utctime)):
111 print 'Skipping this plot function'
112 print 'Skipping this plot function'
112 return
113 return
113
114
114 if channelList == None:
115 if channelList == None:
115 channelIndexList = dataOut.channelIndexList
116 channelIndexList = dataOut.channelIndexList
116 else:
117 else:
117 channelIndexList = []
118 channelIndexList = []
118 for channel in channelList:
119 for channel in channelList:
119 if channel not in dataOut.channelList:
120 if channel not in dataOut.channelList:
120 raise ValueError, "Channel %d is not in dataOut.channelList" %channel
121 raise ValueError, "Channel %d is not in dataOut.channelList" %channel
121 channelIndexList.append(dataOut.channelList.index(channel))
122 channelIndexList.append(dataOut.channelList.index(channel))
122
123
123 factor = dataOut.normFactor
124 factor = dataOut.normFactor
124
125
125 if xaxis == "frequency":
126 if xaxis == "frequency":
126 x = dataOut.getFreqRange(1)/1000.
127 x = dataOut.getFreqRange(1)/1000.
127 xlabel = "Frequency (kHz)"
128 xlabel = "Frequency (kHz)"
128
129
129 elif xaxis == "time":
130 elif xaxis == "time":
130 x = dataOut.getAcfRange(1)
131 x = dataOut.getAcfRange(1)
131 xlabel = "Time (ms)"
132 xlabel = "Time (ms)"
132
133
133 else:
134 else:
134 x = dataOut.getVelRange(1)
135 x = dataOut.getVelRange(1)
135 xlabel = "Velocity (m/s)"
136 xlabel = "Velocity (m/s)"
136
137
137 ylabel = "Range (Km)"
138 ylabel = "Range (Km)"
138
139
139 y = dataOut.getHeiRange()
140 y = dataOut.getHeiRange()
140
141
141 z = dataOut.data_spc/factor
142 z = dataOut.data_spc/factor
142 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
143 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
143 zdB = 10*numpy.log10(z)
144 zdB = 10*numpy.log10(z)
144
145
145 avg = numpy.average(z, axis=1)
146 avg = numpy.average(z, axis=1)
146 avgdB = 10*numpy.log10(avg)
147 avgdB = 10*numpy.log10(avg)
147
148
148 noise = dataOut.getNoise()/factor
149 noise = dataOut.getNoise()/factor
149 noisedB = 10*numpy.log10(noise)
150 noisedB = 10*numpy.log10(noise)
150
151
151 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
152 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
152 title = wintitle + " Spectra"
153 title = wintitle + " Spectra"
153 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
154 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
154 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
155 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
155
156
156 if not self.isConfig:
157 if not self.isConfig:
157
158
158 nplots = len(channelIndexList)
159 nplots = len(channelIndexList)
159
160
160 self.setup(id=id,
161 self.setup(id=id,
161 nplots=nplots,
162 nplots=nplots,
162 wintitle=wintitle,
163 wintitle=wintitle,
163 showprofile=showprofile,
164 showprofile=showprofile,
164 show=show)
165 show=show)
165
166
166 if xmin == None: xmin = numpy.nanmin(x)
167 if xmin == None: xmin = numpy.nanmin(x)
167 if xmax == None: xmax = numpy.nanmax(x)
168 if xmax == None: xmax = numpy.nanmax(x)
168 if ymin == None: ymin = numpy.nanmin(y)
169 if ymin == None: ymin = numpy.nanmin(y)
169 if ymax == None: ymax = numpy.nanmax(y)
170 if ymax == None: ymax = numpy.nanmax(y)
170 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
171 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
171 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
172 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
172
173
173 self.FTP_WEI = ftp_wei
174 self.FTP_WEI = ftp_wei
174 self.EXP_CODE = exp_code
175 self.EXP_CODE = exp_code
175 self.SUB_EXP_CODE = sub_exp_code
176 self.SUB_EXP_CODE = sub_exp_code
176 self.PLOT_POS = plot_pos
177 self.PLOT_POS = plot_pos
177
178
178 self.isConfig = True
179 self.isConfig = True
179
180
180 self.setWinTitle(title)
181 self.setWinTitle(title)
181
182
182 for i in range(self.nplots):
183 for i in range(self.nplots):
183 index = channelIndexList[i]
184 index = channelIndexList[i]
184 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
185 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
185 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime)
186 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime)
186 if len(dataOut.beam.codeList) != 0:
187 if len(dataOut.beam.codeList) != 0:
187 title = "Ch%d:%4.2fdB,%2.2f,%2.2f:%s" %(dataOut.channelList[index], noisedB[index], dataOut.beam.azimuthList[index], dataOut.beam.zenithList[index], str_datetime)
188 title = "Ch%d:%4.2fdB,%2.2f,%2.2f:%s" %(dataOut.channelList[index], noisedB[index], dataOut.beam.azimuthList[index], dataOut.beam.zenithList[index], str_datetime)
188
189
189 axes = self.axesList[i*self.__nsubplots]
190 axes = self.axesList[i*self.__nsubplots]
190 axes.pcolor(x, y, zdB[index,:,:],
191 axes.pcolor(x, y, zdB[index,:,:],
191 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
192 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
192 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
193 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
193 ticksize=9, cblabel='')
194 ticksize=9, cblabel='')
194
195
195 if self.__showprofile:
196 if self.__showprofile:
196 axes = self.axesList[i*self.__nsubplots +1]
197 axes = self.axesList[i*self.__nsubplots +1]
197 axes.pline(avgdB[index,:], y,
198 axes.pline(avgdB[index,:], y,
198 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
199 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
199 xlabel='dB', ylabel='', title='',
200 xlabel='dB', ylabel='', title='',
200 ytick_visible=False,
201 ytick_visible=False,
201 grid='x')
202 grid='x')
202
203
203 noiseline = numpy.repeat(noisedB[index], len(y))
204 noiseline = numpy.repeat(noisedB[index], len(y))
204 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
205 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
205
206
206 self.draw()
207 self.draw()
207
208
208 if figfile == None:
209 if figfile == None:
209 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
210 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
210 name = str_datetime
211 name = str_datetime
211 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
212 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
212 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
213 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
213 figfile = self.getFilename(name)
214 figfile = self.getFilename(name)
214
215
215 self.save(figpath=figpath,
216 self.save(figpath=figpath,
216 figfile=figfile,
217 figfile=figfile,
217 save=save,
218 save=save,
218 ftp=ftp,
219 ftp=ftp,
219 wr_period=wr_period,
220 wr_period=wr_period,
220 thisDatetime=thisDatetime)
221 thisDatetime=thisDatetime)
221
222
222 class CrossSpectraPlot(Figure):
223 class CrossSpectraPlot(Figure):
223
224
224 isConfig = None
225 isConfig = None
225 __nsubplots = None
226 __nsubplots = None
226
227
227 WIDTH = None
228 WIDTH = None
228 HEIGHT = None
229 HEIGHT = None
229 WIDTHPROF = None
230 WIDTHPROF = None
230 HEIGHTPROF = None
231 HEIGHTPROF = None
231 PREFIX = 'cspc'
232 PREFIX = 'cspc'
232
233
233 def __init__(self, **kwargs):
234 def __init__(self, **kwargs):
234 Figure.__init__(self, **kwargs)
235 Figure.__init__(self, **kwargs)
235 self.isConfig = False
236 self.isConfig = False
236 self.__nsubplots = 4
237 self.__nsubplots = 4
237 self.counter_imagwr = 0
238 self.counter_imagwr = 0
238 self.WIDTH = 250
239 self.WIDTH = 250
239 self.HEIGHT = 250
240 self.HEIGHT = 250
240 self.WIDTHPROF = 0
241 self.WIDTHPROF = 0
241 self.HEIGHTPROF = 0
242 self.HEIGHTPROF = 0
242
243
243 self.PLOT_CODE = CROSS_CODE
244 self.PLOT_CODE = CROSS_CODE
244 self.FTP_WEI = None
245 self.FTP_WEI = None
245 self.EXP_CODE = None
246 self.EXP_CODE = None
246 self.SUB_EXP_CODE = None
247 self.SUB_EXP_CODE = None
247 self.PLOT_POS = None
248 self.PLOT_POS = None
248
249
249 def getSubplots(self):
250 def getSubplots(self):
250
251
251 ncol = 4
252 ncol = 4
252 nrow = self.nplots
253 nrow = self.nplots
253
254
254 return nrow, ncol
255 return nrow, ncol
255
256
256 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
257 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
257
258
258 self.__showprofile = showprofile
259 self.__showprofile = showprofile
259 self.nplots = nplots
260 self.nplots = nplots
260
261
261 ncolspan = 1
262 ncolspan = 1
262 colspan = 1
263 colspan = 1
263
264
264 self.createFigure(id = id,
265 self.createFigure(id = id,
265 wintitle = wintitle,
266 wintitle = wintitle,
266 widthplot = self.WIDTH + self.WIDTHPROF,
267 widthplot = self.WIDTH + self.WIDTHPROF,
267 heightplot = self.HEIGHT + self.HEIGHTPROF,
268 heightplot = self.HEIGHT + self.HEIGHTPROF,
268 show=True)
269 show=True)
269
270
270 nrow, ncol = self.getSubplots()
271 nrow, ncol = self.getSubplots()
271
272
272 counter = 0
273 counter = 0
273 for y in range(nrow):
274 for y in range(nrow):
274 for x in range(ncol):
275 for x in range(ncol):
275 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
276 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
276
277
277 counter += 1
278 counter += 1
278
279
279 def run(self, dataOut, id, wintitle="", pairsList=None,
280 def run(self, dataOut, id, wintitle="", pairsList=None,
280 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
281 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
281 coh_min=None, coh_max=None, phase_min=None, phase_max=None,
282 coh_min=None, coh_max=None, phase_min=None, phase_max=None,
282 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
283 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
283 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
284 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
284 server=None, folder=None, username=None, password=None,
285 server=None, folder=None, username=None, password=None,
285 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0,
286 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0,
286 xaxis='frequency'):
287 xaxis='frequency'):
287
288
288 """
289 """
289
290
290 Input:
291 Input:
291 dataOut :
292 dataOut :
292 id :
293 id :
293 wintitle :
294 wintitle :
294 channelList :
295 channelList :
295 showProfile :
296 showProfile :
296 xmin : None,
297 xmin : None,
297 xmax : None,
298 xmax : None,
298 ymin : None,
299 ymin : None,
299 ymax : None,
300 ymax : None,
300 zmin : None,
301 zmin : None,
301 zmax : None
302 zmax : None
302 """
303 """
303
304
304 if pairsList == None:
305 if pairsList == None:
305 pairsIndexList = dataOut.pairsIndexList
306 pairsIndexList = dataOut.pairsIndexList
306 else:
307 else:
307 pairsIndexList = []
308 pairsIndexList = []
308 for pair in pairsList:
309 for pair in pairsList:
309 if pair not in dataOut.pairsList:
310 if pair not in dataOut.pairsList:
310 raise ValueError, "Pair %s is not in dataOut.pairsList" %str(pair)
311 raise ValueError, "Pair %s is not in dataOut.pairsList" %str(pair)
311 pairsIndexList.append(dataOut.pairsList.index(pair))
312 pairsIndexList.append(dataOut.pairsList.index(pair))
312
313
313 if not pairsIndexList:
314 if not pairsIndexList:
314 return
315 return
315
316
316 if len(pairsIndexList) > 4:
317 if len(pairsIndexList) > 4:
317 pairsIndexList = pairsIndexList[0:4]
318 pairsIndexList = pairsIndexList[0:4]
318
319
319 factor = dataOut.normFactor
320 factor = dataOut.normFactor
320 x = dataOut.getVelRange(1)
321 x = dataOut.getVelRange(1)
321 y = dataOut.getHeiRange()
322 y = dataOut.getHeiRange()
322 z = dataOut.data_spc[:,:,:]/factor
323 z = dataOut.data_spc[:,:,:]/factor
323 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
324 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
324
325
325 noise = dataOut.noise/factor
326 noise = dataOut.noise/factor
326
327
327 zdB = 10*numpy.log10(z)
328 zdB = 10*numpy.log10(z)
328 noisedB = 10*numpy.log10(noise)
329 noisedB = 10*numpy.log10(noise)
329
330
330 if coh_min == None:
331 if coh_min == None:
331 coh_min = 0.0
332 coh_min = 0.0
332 if coh_max == None:
333 if coh_max == None:
333 coh_max = 1.0
334 coh_max = 1.0
334
335
335 if phase_min == None:
336 if phase_min == None:
336 phase_min = -180
337 phase_min = -180
337 if phase_max == None:
338 if phase_max == None:
338 phase_max = 180
339 phase_max = 180
339
340
340 #thisDatetime = dataOut.datatime
341 #thisDatetime = dataOut.datatime
341 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
342 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
342 title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
343 title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
343 # xlabel = "Velocity (m/s)"
344 # xlabel = "Velocity (m/s)"
344 ylabel = "Range (Km)"
345 ylabel = "Range (Km)"
345
346
346 if xaxis == "frequency":
347 if xaxis == "frequency":
347 x = dataOut.getFreqRange(1)/1000.
348 x = dataOut.getFreqRange(1)/1000.
348 xlabel = "Frequency (kHz)"
349 xlabel = "Frequency (kHz)"
349
350
350 elif xaxis == "time":
351 elif xaxis == "time":
351 x = dataOut.getAcfRange(1)
352 x = dataOut.getAcfRange(1)
352 xlabel = "Time (ms)"
353 xlabel = "Time (ms)"
353
354
354 else:
355 else:
355 x = dataOut.getVelRange(1)
356 x = dataOut.getVelRange(1)
356 xlabel = "Velocity (m/s)"
357 xlabel = "Velocity (m/s)"
357
358
358 if not self.isConfig:
359 if not self.isConfig:
359
360
360 nplots = len(pairsIndexList)
361 nplots = len(pairsIndexList)
361
362
362 self.setup(id=id,
363 self.setup(id=id,
363 nplots=nplots,
364 nplots=nplots,
364 wintitle=wintitle,
365 wintitle=wintitle,
365 showprofile=False,
366 showprofile=False,
366 show=show)
367 show=show)
367
368
368 avg = numpy.abs(numpy.average(z, axis=1))
369 avg = numpy.abs(numpy.average(z, axis=1))
369 avgdB = 10*numpy.log10(avg)
370 avgdB = 10*numpy.log10(avg)
370
371
371 if xmin == None: xmin = numpy.nanmin(x)
372 if xmin == None: xmin = numpy.nanmin(x)
372 if xmax == None: xmax = numpy.nanmax(x)
373 if xmax == None: xmax = numpy.nanmax(x)
373 if ymin == None: ymin = numpy.nanmin(y)
374 if ymin == None: ymin = numpy.nanmin(y)
374 if ymax == None: ymax = numpy.nanmax(y)
375 if ymax == None: ymax = numpy.nanmax(y)
375 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
376 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
376 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
377 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
377
378
378 self.FTP_WEI = ftp_wei
379 self.FTP_WEI = ftp_wei
379 self.EXP_CODE = exp_code
380 self.EXP_CODE = exp_code
380 self.SUB_EXP_CODE = sub_exp_code
381 self.SUB_EXP_CODE = sub_exp_code
381 self.PLOT_POS = plot_pos
382 self.PLOT_POS = plot_pos
382
383
383 self.isConfig = True
384 self.isConfig = True
384
385
385 self.setWinTitle(title)
386 self.setWinTitle(title)
386
387
387 for i in range(self.nplots):
388 for i in range(self.nplots):
388 pair = dataOut.pairsList[pairsIndexList[i]]
389 pair = dataOut.pairsList[pairsIndexList[i]]
389
390
390 chan_index0 = dataOut.channelList.index(pair[0])
391 chan_index0 = dataOut.channelList.index(pair[0])
391 chan_index1 = dataOut.channelList.index(pair[1])
392 chan_index1 = dataOut.channelList.index(pair[1])
392
393
393 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
394 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
394 title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[chan_index0], str_datetime)
395 title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[chan_index0], str_datetime)
395 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index0,:,:]/factor)
396 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index0,:,:]/factor)
396 axes0 = self.axesList[i*self.__nsubplots]
397 axes0 = self.axesList[i*self.__nsubplots]
397 axes0.pcolor(x, y, zdB,
398 axes0.pcolor(x, y, zdB,
398 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
399 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
399 xlabel=xlabel, ylabel=ylabel, title=title,
400 xlabel=xlabel, ylabel=ylabel, title=title,
400 ticksize=9, colormap=power_cmap, cblabel='')
401 ticksize=9, colormap=power_cmap, cblabel='')
401
402
402 title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[chan_index1], str_datetime)
403 title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[chan_index1], str_datetime)
403 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index1,:,:]/factor)
404 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index1,:,:]/factor)
404 axes0 = self.axesList[i*self.__nsubplots+1]
405 axes0 = self.axesList[i*self.__nsubplots+1]
405 axes0.pcolor(x, y, zdB,
406 axes0.pcolor(x, y, zdB,
406 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
407 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
407 xlabel=xlabel, ylabel=ylabel, title=title,
408 xlabel=xlabel, ylabel=ylabel, title=title,
408 ticksize=9, colormap=power_cmap, cblabel='')
409 ticksize=9, colormap=power_cmap, cblabel='')
409
410
410 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[chan_index0,:,:]*dataOut.data_spc[chan_index1,:,:])
411 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[chan_index0,:,:]*dataOut.data_spc[chan_index1,:,:])
411 coherence = numpy.abs(coherenceComplex)
412 coherence = numpy.abs(coherenceComplex)
412 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
413 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
413 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
414 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
414
415
415 title = "Coherence Ch%d * Ch%d" %(pair[0], pair[1])
416 title = "Coherence Ch%d * Ch%d" %(pair[0], pair[1])
416 axes0 = self.axesList[i*self.__nsubplots+2]
417 axes0 = self.axesList[i*self.__nsubplots+2]
417 axes0.pcolor(x, y, coherence,
418 axes0.pcolor(x, y, coherence,
418 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=coh_min, zmax=coh_max,
419 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=coh_min, zmax=coh_max,
419 xlabel=xlabel, ylabel=ylabel, title=title,
420 xlabel=xlabel, ylabel=ylabel, title=title,
420 ticksize=9, colormap=coherence_cmap, cblabel='')
421 ticksize=9, colormap=coherence_cmap, cblabel='')
421
422
422 title = "Phase Ch%d * Ch%d" %(pair[0], pair[1])
423 title = "Phase Ch%d * Ch%d" %(pair[0], pair[1])
423 axes0 = self.axesList[i*self.__nsubplots+3]
424 axes0 = self.axesList[i*self.__nsubplots+3]
424 axes0.pcolor(x, y, phase,
425 axes0.pcolor(x, y, phase,
425 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
426 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
426 xlabel=xlabel, ylabel=ylabel, title=title,
427 xlabel=xlabel, ylabel=ylabel, title=title,
427 ticksize=9, colormap=phase_cmap, cblabel='')
428 ticksize=9, colormap=phase_cmap, cblabel='')
428
429
429
430
430
431
431 self.draw()
432 self.draw()
432
433
433 self.save(figpath=figpath,
434 self.save(figpath=figpath,
434 figfile=figfile,
435 figfile=figfile,
435 save=save,
436 save=save,
436 ftp=ftp,
437 ftp=ftp,
437 wr_period=wr_period,
438 wr_period=wr_period,
438 thisDatetime=thisDatetime)
439 thisDatetime=thisDatetime)
439
440
440
441
441 class RTIPlot(Figure):
442 class RTIPlot(Figure):
442
443
443 __isConfig = None
444 __isConfig = None
444 __nsubplots = None
445 __nsubplots = None
445
446
446 WIDTHPROF = None
447 WIDTHPROF = None
447 HEIGHTPROF = None
448 HEIGHTPROF = None
448 PREFIX = 'rti'
449 PREFIX = 'rti'
449
450
450 def __init__(self, **kwargs):
451 def __init__(self, **kwargs):
451
452
452 Figure.__init__(self, **kwargs)
453 Figure.__init__(self, **kwargs)
453 self.timerange = None
454 self.timerange = None
454 self.isConfig = False
455 self.isConfig = False
455 self.__nsubplots = 1
456 self.__nsubplots = 1
456
457
457 self.WIDTH = 800
458 self.WIDTH = 800
458 self.HEIGHT = 180
459 self.HEIGHT = 180
459 self.WIDTHPROF = 120
460 self.WIDTHPROF = 120
460 self.HEIGHTPROF = 0
461 self.HEIGHTPROF = 0
461 self.counter_imagwr = 0
462 self.counter_imagwr = 0
462
463
463 self.PLOT_CODE = RTI_CODE
464 self.PLOT_CODE = RTI_CODE
464
465
465 self.FTP_WEI = None
466 self.FTP_WEI = None
466 self.EXP_CODE = None
467 self.EXP_CODE = None
467 self.SUB_EXP_CODE = None
468 self.SUB_EXP_CODE = None
468 self.PLOT_POS = None
469 self.PLOT_POS = None
469 self.tmin = None
470 self.tmin = None
470 self.tmax = None
471 self.tmax = None
471
472
472 self.xmin = None
473 self.xmin = None
473 self.xmax = None
474 self.xmax = None
474
475
475 self.figfile = None
476 self.figfile = None
476
477
477 def getSubplots(self):
478 def getSubplots(self):
478
479
479 ncol = 1
480 ncol = 1
480 nrow = self.nplots
481 nrow = self.nplots
481
482
482 return nrow, ncol
483 return nrow, ncol
483
484
484 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
485 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
485
486
486 self.__showprofile = showprofile
487 self.__showprofile = showprofile
487 self.nplots = nplots
488 self.nplots = nplots
488
489
489 ncolspan = 1
490 ncolspan = 1
490 colspan = 1
491 colspan = 1
491 if showprofile:
492 if showprofile:
492 ncolspan = 7
493 ncolspan = 7
493 colspan = 6
494 colspan = 6
494 self.__nsubplots = 2
495 self.__nsubplots = 2
495
496
496 self.createFigure(id = id,
497 self.createFigure(id = id,
497 wintitle = wintitle,
498 wintitle = wintitle,
498 widthplot = self.WIDTH + self.WIDTHPROF,
499 widthplot = self.WIDTH + self.WIDTHPROF,
499 heightplot = self.HEIGHT + self.HEIGHTPROF,
500 heightplot = self.HEIGHT + self.HEIGHTPROF,
500 show=show)
501 show=show)
501
502
502 nrow, ncol = self.getSubplots()
503 nrow, ncol = self.getSubplots()
503
504
504 counter = 0
505 counter = 0
505 for y in range(nrow):
506 for y in range(nrow):
506 for x in range(ncol):
507 for x in range(ncol):
507
508
508 if counter >= self.nplots:
509 if counter >= self.nplots:
509 break
510 break
510
511
511 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
512 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
512
513
513 if showprofile:
514 if showprofile:
514 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
515 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
515
516
516 counter += 1
517 counter += 1
517
518
518 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
519 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
519 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
520 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
520 timerange=None,
521 timerange=None,
521 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
522 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
522 server=None, folder=None, username=None, password=None,
523 server=None, folder=None, username=None, password=None,
523 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, **kwargs):
524 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, **kwargs):
524
525
525 """
526 """
526
527
527 Input:
528 Input:
528 dataOut :
529 dataOut :
529 id :
530 id :
530 wintitle :
531 wintitle :
531 channelList :
532 channelList :
532 showProfile :
533 showProfile :
533 xmin : None,
534 xmin : None,
534 xmax : None,
535 xmax : None,
535 ymin : None,
536 ymin : None,
536 ymax : None,
537 ymax : None,
537 zmin : None,
538 zmin : None,
538 zmax : None
539 zmax : None
539 """
540 """
540
541
541 colormap = kwargs.get('colormap', 'jet')
542 colormap = kwargs.get('colormap', 'jet')
542 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
543 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
543 return
544 return
544
545
545 if channelList == None:
546 if channelList == None:
546 channelIndexList = dataOut.channelIndexList
547 channelIndexList = dataOut.channelIndexList
547 else:
548 else:
548 channelIndexList = []
549 channelIndexList = []
549 for channel in channelList:
550 for channel in channelList:
550 if channel not in dataOut.channelList:
551 if channel not in dataOut.channelList:
551 raise ValueError, "Channel %d is not in dataOut.channelList"
552 raise ValueError, "Channel %d is not in dataOut.channelList"
552 channelIndexList.append(dataOut.channelList.index(channel))
553 channelIndexList.append(dataOut.channelList.index(channel))
553
554
554 if hasattr(dataOut, 'normFactor'):
555 if hasattr(dataOut, 'normFactor'):
555 factor = dataOut.normFactor
556 factor = dataOut.normFactor
556 else:
557 else:
557 factor = 1
558 factor = 1
558
559
559 # factor = dataOut.normFactor
560 # factor = dataOut.normFactor
560 x = dataOut.getTimeRange()
561 x = dataOut.getTimeRange()
561 y = dataOut.getHeiRange()
562 y = dataOut.getHeiRange()
562
563
563 # z = dataOut.data_spc/factor
564 # z = dataOut.data_spc/factor
564 # z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
565 # z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
565 # avg = numpy.average(z, axis=1)
566 # avg = numpy.average(z, axis=1)
566 # avgdB = 10.*numpy.log10(avg)
567 # avgdB = 10.*numpy.log10(avg)
567 avgdB = dataOut.getPower()
568 avgdB = dataOut.getPower()
568
569
569 thisDatetime = dataOut.datatime
570 thisDatetime = dataOut.datatime
570 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
571 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
571 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
572 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
572 xlabel = ""
573 xlabel = ""
573 ylabel = "Range (Km)"
574 ylabel = "Range (Km)"
574
575
575 update_figfile = False
576 update_figfile = False
576
577
577 if dataOut.ltctime >= self.xmax:
578 if dataOut.ltctime >= self.xmax:
578 self.counter_imagwr = wr_period
579 self.counter_imagwr = wr_period
579 self.isConfig = False
580 self.isConfig = False
580 update_figfile = True
581 update_figfile = True
581
582
582 if not self.isConfig:
583 if not self.isConfig:
583
584
584 nplots = len(channelIndexList)
585 nplots = len(channelIndexList)
585
586
586 self.setup(id=id,
587 self.setup(id=id,
587 nplots=nplots,
588 nplots=nplots,
588 wintitle=wintitle,
589 wintitle=wintitle,
589 showprofile=showprofile,
590 showprofile=showprofile,
590 show=show)
591 show=show)
591
592
592 if timerange != None:
593 if timerange != None:
593 self.timerange = timerange
594 self.timerange = timerange
594
595
595 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
596 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
596
597
597 noise = dataOut.noise/factor
598 noise = dataOut.noise/factor
598 noisedB = 10*numpy.log10(noise)
599 noisedB = 10*numpy.log10(noise)
599
600
600 if ymin == None: ymin = numpy.nanmin(y)
601 if ymin == None: ymin = numpy.nanmin(y)
601 if ymax == None: ymax = numpy.nanmax(y)
602 if ymax == None: ymax = numpy.nanmax(y)
602 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
603 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
603 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
604 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
604
605
605 self.FTP_WEI = ftp_wei
606 self.FTP_WEI = ftp_wei
606 self.EXP_CODE = exp_code
607 self.EXP_CODE = exp_code
607 self.SUB_EXP_CODE = sub_exp_code
608 self.SUB_EXP_CODE = sub_exp_code
608 self.PLOT_POS = plot_pos
609 self.PLOT_POS = plot_pos
609
610
610 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
611 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
611 self.isConfig = True
612 self.isConfig = True
612 self.figfile = figfile
613 self.figfile = figfile
613 update_figfile = True
614 update_figfile = True
614
615
615 self.setWinTitle(title)
616 self.setWinTitle(title)
616
617
617 for i in range(self.nplots):
618 for i in range(self.nplots):
618 index = channelIndexList[i]
619 index = channelIndexList[i]
619 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
620 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
620 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
621 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
621 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
622 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
622 axes = self.axesList[i*self.__nsubplots]
623 axes = self.axesList[i*self.__nsubplots]
623 zdB = avgdB[index].reshape((1,-1))
624 zdB = avgdB[index].reshape((1,-1))
624 axes.pcolorbuffer(x, y, zdB,
625 axes.pcolorbuffer(x, y, zdB,
625 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
626 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
626 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
627 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
627 ticksize=9, cblabel='', cbsize="1%", colormap=colormap)
628 ticksize=9, cblabel='', cbsize="1%", colormap=colormap)
628
629
629 if self.__showprofile:
630 if self.__showprofile:
630 axes = self.axesList[i*self.__nsubplots +1]
631 axes = self.axesList[i*self.__nsubplots +1]
631 axes.pline(avgdB[index], y,
632 axes.pline(avgdB[index], y,
632 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
633 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
633 xlabel='dB', ylabel='', title='',
634 xlabel='dB', ylabel='', title='',
634 ytick_visible=False,
635 ytick_visible=False,
635 grid='x')
636 grid='x')
636
637
637 self.draw()
638 self.draw()
638
639
639 self.save(figpath=figpath,
640 self.save(figpath=figpath,
640 figfile=figfile,
641 figfile=figfile,
641 save=save,
642 save=save,
642 ftp=ftp,
643 ftp=ftp,
643 wr_period=wr_period,
644 wr_period=wr_period,
644 thisDatetime=thisDatetime,
645 thisDatetime=thisDatetime,
645 update_figfile=update_figfile)
646 update_figfile=update_figfile)
646
647
647 class CoherenceMap(Figure):
648 class CoherenceMap(Figure):
648 isConfig = None
649 isConfig = None
649 __nsubplots = None
650 __nsubplots = None
650
651
651 WIDTHPROF = None
652 WIDTHPROF = None
652 HEIGHTPROF = None
653 HEIGHTPROF = None
653 PREFIX = 'cmap'
654 PREFIX = 'cmap'
654
655
655 def __init__(self, **kwargs):
656 def __init__(self, **kwargs):
656 Figure.__init__(self, **kwargs)
657 Figure.__init__(self, **kwargs)
657 self.timerange = 2*60*60
658 self.timerange = 2*60*60
658 self.isConfig = False
659 self.isConfig = False
659 self.__nsubplots = 1
660 self.__nsubplots = 1
660
661
661 self.WIDTH = 800
662 self.WIDTH = 800
662 self.HEIGHT = 180
663 self.HEIGHT = 180
663 self.WIDTHPROF = 120
664 self.WIDTHPROF = 120
664 self.HEIGHTPROF = 0
665 self.HEIGHTPROF = 0
665 self.counter_imagwr = 0
666 self.counter_imagwr = 0
666
667
667 self.PLOT_CODE = COH_CODE
668 self.PLOT_CODE = COH_CODE
668
669
669 self.FTP_WEI = None
670 self.FTP_WEI = None
670 self.EXP_CODE = None
671 self.EXP_CODE = None
671 self.SUB_EXP_CODE = None
672 self.SUB_EXP_CODE = None
672 self.PLOT_POS = None
673 self.PLOT_POS = None
673 self.counter_imagwr = 0
674 self.counter_imagwr = 0
674
675
675 self.xmin = None
676 self.xmin = None
676 self.xmax = None
677 self.xmax = None
677
678
678 def getSubplots(self):
679 def getSubplots(self):
679 ncol = 1
680 ncol = 1
680 nrow = self.nplots*2
681 nrow = self.nplots*2
681
682
682 return nrow, ncol
683 return nrow, ncol
683
684
684 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
685 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
685 self.__showprofile = showprofile
686 self.__showprofile = showprofile
686 self.nplots = nplots
687 self.nplots = nplots
687
688
688 ncolspan = 1
689 ncolspan = 1
689 colspan = 1
690 colspan = 1
690 if showprofile:
691 if showprofile:
691 ncolspan = 7
692 ncolspan = 7
692 colspan = 6
693 colspan = 6
693 self.__nsubplots = 2
694 self.__nsubplots = 2
694
695
695 self.createFigure(id = id,
696 self.createFigure(id = id,
696 wintitle = wintitle,
697 wintitle = wintitle,
697 widthplot = self.WIDTH + self.WIDTHPROF,
698 widthplot = self.WIDTH + self.WIDTHPROF,
698 heightplot = self.HEIGHT + self.HEIGHTPROF,
699 heightplot = self.HEIGHT + self.HEIGHTPROF,
699 show=True)
700 show=True)
700
701
701 nrow, ncol = self.getSubplots()
702 nrow, ncol = self.getSubplots()
702
703
703 for y in range(nrow):
704 for y in range(nrow):
704 for x in range(ncol):
705 for x in range(ncol):
705
706
706 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
707 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
707
708
708 if showprofile:
709 if showprofile:
709 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
710 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
710
711
711 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
712 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
712 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
713 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
713 timerange=None, phase_min=None, phase_max=None,
714 timerange=None, phase_min=None, phase_max=None,
714 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
715 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
715 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
716 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
716 server=None, folder=None, username=None, password=None,
717 server=None, folder=None, username=None, password=None,
717 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
718 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
718
719
719 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
720 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
720 return
721 return
721
722
722 if pairsList == None:
723 if pairsList == None:
723 pairsIndexList = dataOut.pairsIndexList
724 pairsIndexList = dataOut.pairsIndexList
724 else:
725 else:
725 pairsIndexList = []
726 pairsIndexList = []
726 for pair in pairsList:
727 for pair in pairsList:
727 if pair not in dataOut.pairsList:
728 if pair not in dataOut.pairsList:
728 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
729 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
729 pairsIndexList.append(dataOut.pairsList.index(pair))
730 pairsIndexList.append(dataOut.pairsList.index(pair))
730
731
731 if pairsIndexList == []:
732 if pairsIndexList == []:
732 return
733 return
733
734
734 if len(pairsIndexList) > 4:
735 if len(pairsIndexList) > 4:
735 pairsIndexList = pairsIndexList[0:4]
736 pairsIndexList = pairsIndexList[0:4]
736
737
737 if phase_min == None:
738 if phase_min == None:
738 phase_min = -180
739 phase_min = -180
739 if phase_max == None:
740 if phase_max == None:
740 phase_max = 180
741 phase_max = 180
741
742
742 x = dataOut.getTimeRange()
743 x = dataOut.getTimeRange()
743 y = dataOut.getHeiRange()
744 y = dataOut.getHeiRange()
744
745
745 thisDatetime = dataOut.datatime
746 thisDatetime = dataOut.datatime
746
747
747 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
748 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
748 xlabel = ""
749 xlabel = ""
749 ylabel = "Range (Km)"
750 ylabel = "Range (Km)"
750 update_figfile = False
751 update_figfile = False
751
752
752 if not self.isConfig:
753 if not self.isConfig:
753 nplots = len(pairsIndexList)
754 nplots = len(pairsIndexList)
754 self.setup(id=id,
755 self.setup(id=id,
755 nplots=nplots,
756 nplots=nplots,
756 wintitle=wintitle,
757 wintitle=wintitle,
757 showprofile=showprofile,
758 showprofile=showprofile,
758 show=show)
759 show=show)
759
760
760 if timerange != None:
761 if timerange != None:
761 self.timerange = timerange
762 self.timerange = timerange
762
763
763 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
764 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
764
765
765 if ymin == None: ymin = numpy.nanmin(y)
766 if ymin == None: ymin = numpy.nanmin(y)
766 if ymax == None: ymax = numpy.nanmax(y)
767 if ymax == None: ymax = numpy.nanmax(y)
767 if zmin == None: zmin = 0.
768 if zmin == None: zmin = 0.
768 if zmax == None: zmax = 1.
769 if zmax == None: zmax = 1.
769
770
770 self.FTP_WEI = ftp_wei
771 self.FTP_WEI = ftp_wei
771 self.EXP_CODE = exp_code
772 self.EXP_CODE = exp_code
772 self.SUB_EXP_CODE = sub_exp_code
773 self.SUB_EXP_CODE = sub_exp_code
773 self.PLOT_POS = plot_pos
774 self.PLOT_POS = plot_pos
774
775
775 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
776 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
776
777
777 self.isConfig = True
778 self.isConfig = True
778 update_figfile = True
779 update_figfile = True
779
780
780 self.setWinTitle(title)
781 self.setWinTitle(title)
781
782
782 for i in range(self.nplots):
783 for i in range(self.nplots):
783
784
784 pair = dataOut.pairsList[pairsIndexList[i]]
785 pair = dataOut.pairsList[pairsIndexList[i]]
785
786
786 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
787 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
787 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
788 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
788 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
789 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
789
790
790
791
791 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
792 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
792 coherence = numpy.abs(avgcoherenceComplex)
793 coherence = numpy.abs(avgcoherenceComplex)
793
794
794 z = coherence.reshape((1,-1))
795 z = coherence.reshape((1,-1))
795
796
796 counter = 0
797 counter = 0
797
798
798 title = "Coherence Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
799 title = "Coherence Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
799 axes = self.axesList[i*self.__nsubplots*2]
800 axes = self.axesList[i*self.__nsubplots*2]
800 axes.pcolorbuffer(x, y, z,
801 axes.pcolorbuffer(x, y, z,
801 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
802 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
802 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
803 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
803 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
804 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
804
805
805 if self.__showprofile:
806 if self.__showprofile:
806 counter += 1
807 counter += 1
807 axes = self.axesList[i*self.__nsubplots*2 + counter]
808 axes = self.axesList[i*self.__nsubplots*2 + counter]
808 axes.pline(coherence, y,
809 axes.pline(coherence, y,
809 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
810 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
810 xlabel='', ylabel='', title='', ticksize=7,
811 xlabel='', ylabel='', title='', ticksize=7,
811 ytick_visible=False, nxticks=5,
812 ytick_visible=False, nxticks=5,
812 grid='x')
813 grid='x')
813
814
814 counter += 1
815 counter += 1
815
816
816 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
817 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
817
818
818 z = phase.reshape((1,-1))
819 z = phase.reshape((1,-1))
819
820
820 title = "Phase Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
821 title = "Phase Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
821 axes = self.axesList[i*self.__nsubplots*2 + counter]
822 axes = self.axesList[i*self.__nsubplots*2 + counter]
822 axes.pcolorbuffer(x, y, z,
823 axes.pcolorbuffer(x, y, z,
823 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
824 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
824 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
825 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
825 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
826 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
826
827
827 if self.__showprofile:
828 if self.__showprofile:
828 counter += 1
829 counter += 1
829 axes = self.axesList[i*self.__nsubplots*2 + counter]
830 axes = self.axesList[i*self.__nsubplots*2 + counter]
830 axes.pline(phase, y,
831 axes.pline(phase, y,
831 xmin=phase_min, xmax=phase_max, ymin=ymin, ymax=ymax,
832 xmin=phase_min, xmax=phase_max, ymin=ymin, ymax=ymax,
832 xlabel='', ylabel='', title='', ticksize=7,
833 xlabel='', ylabel='', title='', ticksize=7,
833 ytick_visible=False, nxticks=4,
834 ytick_visible=False, nxticks=4,
834 grid='x')
835 grid='x')
835
836
836 self.draw()
837 self.draw()
837
838
838 if dataOut.ltctime >= self.xmax:
839 if dataOut.ltctime >= self.xmax:
839 self.counter_imagwr = wr_period
840 self.counter_imagwr = wr_period
840 self.isConfig = False
841 self.isConfig = False
841 update_figfile = True
842 update_figfile = True
842
843
843 self.save(figpath=figpath,
844 self.save(figpath=figpath,
844 figfile=figfile,
845 figfile=figfile,
845 save=save,
846 save=save,
846 ftp=ftp,
847 ftp=ftp,
847 wr_period=wr_period,
848 wr_period=wr_period,
848 thisDatetime=thisDatetime,
849 thisDatetime=thisDatetime,
849 update_figfile=update_figfile)
850 update_figfile=update_figfile)
850
851
851 class PowerProfilePlot(Figure):
852 class PowerProfilePlot(Figure):
852
853
853 isConfig = None
854 isConfig = None
854 __nsubplots = None
855 __nsubplots = None
855
856
856 WIDTHPROF = None
857 WIDTHPROF = None
857 HEIGHTPROF = None
858 HEIGHTPROF = None
858 PREFIX = 'spcprofile'
859 PREFIX = 'spcprofile'
859
860
860 def __init__(self, **kwargs):
861 def __init__(self, **kwargs):
861 Figure.__init__(self, **kwargs)
862 Figure.__init__(self, **kwargs)
862 self.isConfig = False
863 self.isConfig = False
863 self.__nsubplots = 1
864 self.__nsubplots = 1
864
865
865 self.PLOT_CODE = POWER_CODE
866 self.PLOT_CODE = POWER_CODE
866
867
867 self.WIDTH = 300
868 self.WIDTH = 300
868 self.HEIGHT = 500
869 self.HEIGHT = 500
869 self.counter_imagwr = 0
870 self.counter_imagwr = 0
870
871
871 def getSubplots(self):
872 def getSubplots(self):
872 ncol = 1
873 ncol = 1
873 nrow = 1
874 nrow = 1
874
875
875 return nrow, ncol
876 return nrow, ncol
876
877
877 def setup(self, id, nplots, wintitle, show):
878 def setup(self, id, nplots, wintitle, show):
878
879
879 self.nplots = nplots
880 self.nplots = nplots
880
881
881 ncolspan = 1
882 ncolspan = 1
882 colspan = 1
883 colspan = 1
883
884
884 self.createFigure(id = id,
885 self.createFigure(id = id,
885 wintitle = wintitle,
886 wintitle = wintitle,
886 widthplot = self.WIDTH,
887 widthplot = self.WIDTH,
887 heightplot = self.HEIGHT,
888 heightplot = self.HEIGHT,
888 show=show)
889 show=show)
889
890
890 nrow, ncol = self.getSubplots()
891 nrow, ncol = self.getSubplots()
891
892
892 counter = 0
893 counter = 0
893 for y in range(nrow):
894 for y in range(nrow):
894 for x in range(ncol):
895 for x in range(ncol):
895 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
896 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
896
897
897 def run(self, dataOut, id, wintitle="", channelList=None,
898 def run(self, dataOut, id, wintitle="", channelList=None,
898 xmin=None, xmax=None, ymin=None, ymax=None,
899 xmin=None, xmax=None, ymin=None, ymax=None,
899 save=False, figpath='./', figfile=None, show=True,
900 save=False, figpath='./', figfile=None, show=True,
900 ftp=False, wr_period=1, server=None,
901 ftp=False, wr_period=1, server=None,
901 folder=None, username=None, password=None):
902 folder=None, username=None, password=None):
902
903
903
904
904 if channelList == None:
905 if channelList == None:
905 channelIndexList = dataOut.channelIndexList
906 channelIndexList = dataOut.channelIndexList
906 channelList = dataOut.channelList
907 channelList = dataOut.channelList
907 else:
908 else:
908 channelIndexList = []
909 channelIndexList = []
909 for channel in channelList:
910 for channel in channelList:
910 if channel not in dataOut.channelList:
911 if channel not in dataOut.channelList:
911 raise ValueError, "Channel %d is not in dataOut.channelList"
912 raise ValueError, "Channel %d is not in dataOut.channelList"
912 channelIndexList.append(dataOut.channelList.index(channel))
913 channelIndexList.append(dataOut.channelList.index(channel))
913
914
914 factor = dataOut.normFactor
915 factor = dataOut.normFactor
915
916
916 y = dataOut.getHeiRange()
917 y = dataOut.getHeiRange()
917
918
918 #for voltage
919 #for voltage
919 if dataOut.type == 'Voltage':
920 if dataOut.type == 'Voltage':
920 x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
921 x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
921 x = x.real
922 x = x.real
922 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
923 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
923
924
924 #for spectra
925 #for spectra
925 if dataOut.type == 'Spectra':
926 if dataOut.type == 'Spectra':
926 x = dataOut.data_spc[channelIndexList,:,:]/factor
927 x = dataOut.data_spc[channelIndexList,:,:]/factor
927 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
928 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
928 x = numpy.average(x, axis=1)
929 x = numpy.average(x, axis=1)
929
930
930
931
931 xdB = 10*numpy.log10(x)
932 xdB = 10*numpy.log10(x)
932
933
933 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
934 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
934 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
935 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
935 xlabel = "dB"
936 xlabel = "dB"
936 ylabel = "Range (Km)"
937 ylabel = "Range (Km)"
937
938
938 if not self.isConfig:
939 if not self.isConfig:
939
940
940 nplots = 1
941 nplots = 1
941
942
942 self.setup(id=id,
943 self.setup(id=id,
943 nplots=nplots,
944 nplots=nplots,
944 wintitle=wintitle,
945 wintitle=wintitle,
945 show=show)
946 show=show)
946
947
947 if ymin == None: ymin = numpy.nanmin(y)
948 if ymin == None: ymin = numpy.nanmin(y)
948 if ymax == None: ymax = numpy.nanmax(y)
949 if ymax == None: ymax = numpy.nanmax(y)
949 if xmin == None: xmin = numpy.nanmin(xdB)*0.9
950 if xmin == None: xmin = numpy.nanmin(xdB)*0.9
950 if xmax == None: xmax = numpy.nanmax(xdB)*1.1
951 if xmax == None: xmax = numpy.nanmax(xdB)*1.1
951
952
952 self.isConfig = True
953 self.isConfig = True
953
954
954 self.setWinTitle(title)
955 self.setWinTitle(title)
955
956
956 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
957 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
957 axes = self.axesList[0]
958 axes = self.axesList[0]
958
959
959 legendlabels = ["channel %d"%x for x in channelList]
960 legendlabels = ["channel %d"%x for x in channelList]
960 axes.pmultiline(xdB, y,
961 axes.pmultiline(xdB, y,
961 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
962 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
962 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
963 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
963 ytick_visible=True, nxticks=5,
964 ytick_visible=True, nxticks=5,
964 grid='x')
965 grid='x')
965
966
966 self.draw()
967 self.draw()
967
968
968 self.save(figpath=figpath,
969 self.save(figpath=figpath,
969 figfile=figfile,
970 figfile=figfile,
970 save=save,
971 save=save,
971 ftp=ftp,
972 ftp=ftp,
972 wr_period=wr_period,
973 wr_period=wr_period,
973 thisDatetime=thisDatetime)
974 thisDatetime=thisDatetime)
974
975
975 class SpectraCutPlot(Figure):
976 class SpectraCutPlot(Figure):
976
977
977 isConfig = None
978 isConfig = None
978 __nsubplots = None
979 __nsubplots = None
979
980
980 WIDTHPROF = None
981 WIDTHPROF = None
981 HEIGHTPROF = None
982 HEIGHTPROF = None
982 PREFIX = 'spc_cut'
983 PREFIX = 'spc_cut'
983
984
984 def __init__(self, **kwargs):
985 def __init__(self, **kwargs):
985 Figure.__init__(self, **kwargs)
986 Figure.__init__(self, **kwargs)
986 self.isConfig = False
987 self.isConfig = False
987 self.__nsubplots = 1
988 self.__nsubplots = 1
988
989
989 self.PLOT_CODE = POWER_CODE
990 self.PLOT_CODE = POWER_CODE
990
991
991 self.WIDTH = 700
992 self.WIDTH = 700
992 self.HEIGHT = 500
993 self.HEIGHT = 500
993 self.counter_imagwr = 0
994 self.counter_imagwr = 0
994
995
995 def getSubplots(self):
996 def getSubplots(self):
996 ncol = 1
997 ncol = 1
997 nrow = 1
998 nrow = 1
998
999
999 return nrow, ncol
1000 return nrow, ncol
1000
1001
1001 def setup(self, id, nplots, wintitle, show):
1002 def setup(self, id, nplots, wintitle, show):
1002
1003
1003 self.nplots = nplots
1004 self.nplots = nplots
1004
1005
1005 ncolspan = 1
1006 ncolspan = 1
1006 colspan = 1
1007 colspan = 1
1007
1008
1008 self.createFigure(id = id,
1009 self.createFigure(id = id,
1009 wintitle = wintitle,
1010 wintitle = wintitle,
1010 widthplot = self.WIDTH,
1011 widthplot = self.WIDTH,
1011 heightplot = self.HEIGHT,
1012 heightplot = self.HEIGHT,
1012 show=show)
1013 show=show)
1013
1014
1014 nrow, ncol = self.getSubplots()
1015 nrow, ncol = self.getSubplots()
1015
1016
1016 counter = 0
1017 counter = 0
1017 for y in range(nrow):
1018 for y in range(nrow):
1018 for x in range(ncol):
1019 for x in range(ncol):
1019 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1020 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1020
1021
1021 def run(self, dataOut, id, wintitle="", channelList=None,
1022 def run(self, dataOut, id, wintitle="", channelList=None,
1022 xmin=None, xmax=None, ymin=None, ymax=None,
1023 xmin=None, xmax=None, ymin=None, ymax=None,
1023 save=False, figpath='./', figfile=None, show=True,
1024 save=False, figpath='./', figfile=None, show=True,
1024 ftp=False, wr_period=1, server=None,
1025 ftp=False, wr_period=1, server=None,
1025 folder=None, username=None, password=None,
1026 folder=None, username=None, password=None,
1026 xaxis="frequency"):
1027 xaxis="frequency"):
1027
1028
1028
1029
1029 if channelList == None:
1030 if channelList == None:
1030 channelIndexList = dataOut.channelIndexList
1031 channelIndexList = dataOut.channelIndexList
1031 channelList = dataOut.channelList
1032 channelList = dataOut.channelList
1032 else:
1033 else:
1033 channelIndexList = []
1034 channelIndexList = []
1034 for channel in channelList:
1035 for channel in channelList:
1035 if channel not in dataOut.channelList:
1036 if channel not in dataOut.channelList:
1036 raise ValueError, "Channel %d is not in dataOut.channelList"
1037 raise ValueError, "Channel %d is not in dataOut.channelList"
1037 channelIndexList.append(dataOut.channelList.index(channel))
1038 channelIndexList.append(dataOut.channelList.index(channel))
1038
1039
1039 factor = dataOut.normFactor
1040 factor = dataOut.normFactor
1040
1041
1041 y = dataOut.getHeiRange()
1042 y = dataOut.getHeiRange()
1042
1043
1043 z = dataOut.data_spc/factor
1044 z = dataOut.data_spc/factor
1044 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1045 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1045
1046
1046 hei_index = numpy.arange(25)*3 + 20
1047 hei_index = numpy.arange(25)*3 + 20
1047
1048
1048 if xaxis == "frequency":
1049 if xaxis == "frequency":
1049 x = dataOut.getFreqRange()/1000.
1050 x = dataOut.getFreqRange()/1000.
1050 zdB = 10*numpy.log10(z[0,:,hei_index])
1051 zdB = 10*numpy.log10(z[0,:,hei_index])
1051 xlabel = "Frequency (kHz)"
1052 xlabel = "Frequency (kHz)"
1052 ylabel = "Power (dB)"
1053 ylabel = "Power (dB)"
1053
1054
1054 elif xaxis == "time":
1055 elif xaxis == "time":
1055 x = dataOut.getAcfRange()
1056 x = dataOut.getAcfRange()
1056 zdB = z[0,:,hei_index]
1057 zdB = z[0,:,hei_index]
1057 xlabel = "Time (ms)"
1058 xlabel = "Time (ms)"
1058 ylabel = "ACF"
1059 ylabel = "ACF"
1059
1060
1060 else:
1061 else:
1061 x = dataOut.getVelRange()
1062 x = dataOut.getVelRange()
1062 zdB = 10*numpy.log10(z[0,:,hei_index])
1063 zdB = 10*numpy.log10(z[0,:,hei_index])
1063 xlabel = "Velocity (m/s)"
1064 xlabel = "Velocity (m/s)"
1064 ylabel = "Power (dB)"
1065 ylabel = "Power (dB)"
1065
1066
1066 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1067 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1067 title = wintitle + " Range Cuts %s" %(thisDatetime.strftime("%d-%b-%Y"))
1068 title = wintitle + " Range Cuts %s" %(thisDatetime.strftime("%d-%b-%Y"))
1068
1069
1069 if not self.isConfig:
1070 if not self.isConfig:
1070
1071
1071 nplots = 1
1072 nplots = 1
1072
1073
1073 self.setup(id=id,
1074 self.setup(id=id,
1074 nplots=nplots,
1075 nplots=nplots,
1075 wintitle=wintitle,
1076 wintitle=wintitle,
1076 show=show)
1077 show=show)
1077
1078
1078 if xmin == None: xmin = numpy.nanmin(x)*0.9
1079 if xmin == None: xmin = numpy.nanmin(x)*0.9
1079 if xmax == None: xmax = numpy.nanmax(x)*1.1
1080 if xmax == None: xmax = numpy.nanmax(x)*1.1
1080 if ymin == None: ymin = numpy.nanmin(zdB)
1081 if ymin == None: ymin = numpy.nanmin(zdB)
1081 if ymax == None: ymax = numpy.nanmax(zdB)
1082 if ymax == None: ymax = numpy.nanmax(zdB)
1082
1083
1083 self.isConfig = True
1084 self.isConfig = True
1084
1085
1085 self.setWinTitle(title)
1086 self.setWinTitle(title)
1086
1087
1087 title = "Spectra Cuts: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1088 title = "Spectra Cuts: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1088 axes = self.axesList[0]
1089 axes = self.axesList[0]
1089
1090
1090 legendlabels = ["Range = %dKm" %y[i] for i in hei_index]
1091 legendlabels = ["Range = %dKm" %y[i] for i in hei_index]
1091
1092
1092 axes.pmultilineyaxis( x, zdB,
1093 axes.pmultilineyaxis( x, zdB,
1093 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1094 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1094 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1095 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1095 ytick_visible=True, nxticks=5,
1096 ytick_visible=True, nxticks=5,
1096 grid='x')
1097 grid='x')
1097
1098
1098 self.draw()
1099 self.draw()
1099
1100
1100 self.save(figpath=figpath,
1101 self.save(figpath=figpath,
1101 figfile=figfile,
1102 figfile=figfile,
1102 save=save,
1103 save=save,
1103 ftp=ftp,
1104 ftp=ftp,
1104 wr_period=wr_period,
1105 wr_period=wr_period,
1105 thisDatetime=thisDatetime)
1106 thisDatetime=thisDatetime)
1106
1107
1107 class Noise(Figure):
1108 class Noise(Figure):
1108
1109
1109 isConfig = None
1110 isConfig = None
1110 __nsubplots = None
1111 __nsubplots = None
1111
1112
1112 PREFIX = 'noise'
1113 PREFIX = 'noise'
1113
1114
1114 def __init__(self, **kwargs):
1115 def __init__(self, **kwargs):
1115 Figure.__init__(self, **kwargs)
1116 Figure.__init__(self, **kwargs)
1116 self.timerange = 24*60*60
1117 self.timerange = 24*60*60
1117 self.isConfig = False
1118 self.isConfig = False
1118 self.__nsubplots = 1
1119 self.__nsubplots = 1
1119 self.counter_imagwr = 0
1120 self.counter_imagwr = 0
1120 self.WIDTH = 800
1121 self.WIDTH = 800
1121 self.HEIGHT = 400
1122 self.HEIGHT = 400
1122 self.WIDTHPROF = 120
1123 self.WIDTHPROF = 120
1123 self.HEIGHTPROF = 0
1124 self.HEIGHTPROF = 0
1124 self.xdata = None
1125 self.xdata = None
1125 self.ydata = None
1126 self.ydata = None
1126
1127
1127 self.PLOT_CODE = NOISE_CODE
1128 self.PLOT_CODE = NOISE_CODE
1128
1129
1129 self.FTP_WEI = None
1130 self.FTP_WEI = None
1130 self.EXP_CODE = None
1131 self.EXP_CODE = None
1131 self.SUB_EXP_CODE = None
1132 self.SUB_EXP_CODE = None
1132 self.PLOT_POS = None
1133 self.PLOT_POS = None
1133 self.figfile = None
1134 self.figfile = None
1134
1135
1135 self.xmin = None
1136 self.xmin = None
1136 self.xmax = None
1137 self.xmax = None
1137
1138
1138 def getSubplots(self):
1139 def getSubplots(self):
1139
1140
1140 ncol = 1
1141 ncol = 1
1141 nrow = 1
1142 nrow = 1
1142
1143
1143 return nrow, ncol
1144 return nrow, ncol
1144
1145
1145 def openfile(self, filename):
1146 def openfile(self, filename):
1146 dirname = os.path.dirname(filename)
1147 dirname = os.path.dirname(filename)
1147
1148
1148 if not os.path.exists(dirname):
1149 if not os.path.exists(dirname):
1149 os.mkdir(dirname)
1150 os.mkdir(dirname)
1150
1151
1151 f = open(filename,'w+')
1152 f = open(filename,'w+')
1152 f.write('\n\n')
1153 f.write('\n\n')
1153 f.write('JICAMARCA RADIO OBSERVATORY - Noise \n')
1154 f.write('JICAMARCA RADIO OBSERVATORY - Noise \n')
1154 f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' )
1155 f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' )
1155 f.close()
1156 f.close()
1156
1157
1157 def save_data(self, filename_phase, data, data_datetime):
1158 def save_data(self, filename_phase, data, data_datetime):
1158
1159
1159 f=open(filename_phase,'a')
1160 f=open(filename_phase,'a')
1160
1161
1161 timetuple_data = data_datetime.timetuple()
1162 timetuple_data = data_datetime.timetuple()
1162 day = str(timetuple_data.tm_mday)
1163 day = str(timetuple_data.tm_mday)
1163 month = str(timetuple_data.tm_mon)
1164 month = str(timetuple_data.tm_mon)
1164 year = str(timetuple_data.tm_year)
1165 year = str(timetuple_data.tm_year)
1165 hour = str(timetuple_data.tm_hour)
1166 hour = str(timetuple_data.tm_hour)
1166 minute = str(timetuple_data.tm_min)
1167 minute = str(timetuple_data.tm_min)
1167 second = str(timetuple_data.tm_sec)
1168 second = str(timetuple_data.tm_sec)
1168
1169
1169 data_msg = ''
1170 data_msg = ''
1170 for i in range(len(data)):
1171 for i in range(len(data)):
1171 data_msg += str(data[i]) + ' '
1172 data_msg += str(data[i]) + ' '
1172
1173
1173 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' ' + data_msg + '\n')
1174 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' ' + data_msg + '\n')
1174 f.close()
1175 f.close()
1175
1176
1176
1177
1177 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1178 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1178
1179
1179 self.__showprofile = showprofile
1180 self.__showprofile = showprofile
1180 self.nplots = nplots
1181 self.nplots = nplots
1181
1182
1182 ncolspan = 7
1183 ncolspan = 7
1183 colspan = 6
1184 colspan = 6
1184 self.__nsubplots = 2
1185 self.__nsubplots = 2
1185
1186
1186 self.createFigure(id = id,
1187 self.createFigure(id = id,
1187 wintitle = wintitle,
1188 wintitle = wintitle,
1188 widthplot = self.WIDTH+self.WIDTHPROF,
1189 widthplot = self.WIDTH+self.WIDTHPROF,
1189 heightplot = self.HEIGHT+self.HEIGHTPROF,
1190 heightplot = self.HEIGHT+self.HEIGHTPROF,
1190 show=show)
1191 show=show)
1191
1192
1192 nrow, ncol = self.getSubplots()
1193 nrow, ncol = self.getSubplots()
1193
1194
1194 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1195 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1195
1196
1196
1197
1197 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1198 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1198 xmin=None, xmax=None, ymin=None, ymax=None,
1199 xmin=None, xmax=None, ymin=None, ymax=None,
1199 timerange=None,
1200 timerange=None,
1200 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1201 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1201 server=None, folder=None, username=None, password=None,
1202 server=None, folder=None, username=None, password=None,
1202 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1203 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1203
1204
1204 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1205 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1205 return
1206 return
1206
1207
1207 if channelList == None:
1208 if channelList == None:
1208 channelIndexList = dataOut.channelIndexList
1209 channelIndexList = dataOut.channelIndexList
1209 channelList = dataOut.channelList
1210 channelList = dataOut.channelList
1210 else:
1211 else:
1211 channelIndexList = []
1212 channelIndexList = []
1212 for channel in channelList:
1213 for channel in channelList:
1213 if channel not in dataOut.channelList:
1214 if channel not in dataOut.channelList:
1214 raise ValueError, "Channel %d is not in dataOut.channelList"
1215 raise ValueError, "Channel %d is not in dataOut.channelList"
1215 channelIndexList.append(dataOut.channelList.index(channel))
1216 channelIndexList.append(dataOut.channelList.index(channel))
1216
1217
1217 x = dataOut.getTimeRange()
1218 x = dataOut.getTimeRange()
1218 #y = dataOut.getHeiRange()
1219 #y = dataOut.getHeiRange()
1219 factor = dataOut.normFactor
1220 factor = dataOut.normFactor
1220 noise = dataOut.noise[channelIndexList]/factor
1221 noise = dataOut.noise[channelIndexList]/factor
1221 noisedB = 10*numpy.log10(noise)
1222 noisedB = 10*numpy.log10(noise)
1222
1223
1223 thisDatetime = dataOut.datatime
1224 thisDatetime = dataOut.datatime
1224
1225
1225 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1226 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1226 xlabel = ""
1227 xlabel = ""
1227 ylabel = "Intensity (dB)"
1228 ylabel = "Intensity (dB)"
1228 update_figfile = False
1229 update_figfile = False
1229
1230
1230 if not self.isConfig:
1231 if not self.isConfig:
1231
1232
1232 nplots = 1
1233 nplots = 1
1233
1234
1234 self.setup(id=id,
1235 self.setup(id=id,
1235 nplots=nplots,
1236 nplots=nplots,
1236 wintitle=wintitle,
1237 wintitle=wintitle,
1237 showprofile=showprofile,
1238 showprofile=showprofile,
1238 show=show)
1239 show=show)
1239
1240
1240 if timerange != None:
1241 if timerange != None:
1241 self.timerange = timerange
1242 self.timerange = timerange
1242
1243
1243 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1244 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1244
1245
1245 if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0
1246 if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0
1246 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1247 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1247
1248
1248 self.FTP_WEI = ftp_wei
1249 self.FTP_WEI = ftp_wei
1249 self.EXP_CODE = exp_code
1250 self.EXP_CODE = exp_code
1250 self.SUB_EXP_CODE = sub_exp_code
1251 self.SUB_EXP_CODE = sub_exp_code
1251 self.PLOT_POS = plot_pos
1252 self.PLOT_POS = plot_pos
1252
1253
1253
1254
1254 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1255 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1255 self.isConfig = True
1256 self.isConfig = True
1256 self.figfile = figfile
1257 self.figfile = figfile
1257 self.xdata = numpy.array([])
1258 self.xdata = numpy.array([])
1258 self.ydata = numpy.array([])
1259 self.ydata = numpy.array([])
1259
1260
1260 update_figfile = True
1261 update_figfile = True
1261
1262
1262 #open file beacon phase
1263 #open file beacon phase
1263 path = '%s%03d' %(self.PREFIX, self.id)
1264 path = '%s%03d' %(self.PREFIX, self.id)
1264 noise_file = os.path.join(path,'%s.txt'%self.name)
1265 noise_file = os.path.join(path,'%s.txt'%self.name)
1265 self.filename_noise = os.path.join(figpath,noise_file)
1266 self.filename_noise = os.path.join(figpath,noise_file)
1266
1267
1267 self.setWinTitle(title)
1268 self.setWinTitle(title)
1268
1269
1269 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1270 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1270
1271
1271 legendlabels = ["channel %d"%(idchannel) for idchannel in channelList]
1272 legendlabels = ["channel %d"%(idchannel) for idchannel in channelList]
1272 axes = self.axesList[0]
1273 axes = self.axesList[0]
1273
1274
1274 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1275 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1275
1276
1276 if len(self.ydata)==0:
1277 if len(self.ydata)==0:
1277 self.ydata = noisedB.reshape(-1,1)
1278 self.ydata = noisedB.reshape(-1,1)
1278 else:
1279 else:
1279 self.ydata = numpy.hstack((self.ydata, noisedB.reshape(-1,1)))
1280 self.ydata = numpy.hstack((self.ydata, noisedB.reshape(-1,1)))
1280
1281
1281
1282
1282 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1283 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1283 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1284 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1284 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1285 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1285 XAxisAsTime=True, grid='both'
1286 XAxisAsTime=True, grid='both'
1286 )
1287 )
1287
1288
1288 self.draw()
1289 self.draw()
1289
1290
1290 if dataOut.ltctime >= self.xmax:
1291 if dataOut.ltctime >= self.xmax:
1291 self.counter_imagwr = wr_period
1292 self.counter_imagwr = wr_period
1292 self.isConfig = False
1293 self.isConfig = False
1293 update_figfile = True
1294 update_figfile = True
1294
1295
1295 self.save(figpath=figpath,
1296 self.save(figpath=figpath,
1296 figfile=figfile,
1297 figfile=figfile,
1297 save=save,
1298 save=save,
1298 ftp=ftp,
1299 ftp=ftp,
1299 wr_period=wr_period,
1300 wr_period=wr_period,
1300 thisDatetime=thisDatetime,
1301 thisDatetime=thisDatetime,
1301 update_figfile=update_figfile)
1302 update_figfile=update_figfile)
1302
1303
1303 #store data beacon phase
1304 #store data beacon phase
1304 if save:
1305 if save:
1305 self.save_data(self.filename_noise, noisedB, thisDatetime)
1306 self.save_data(self.filename_noise, noisedB, thisDatetime)
1306
1307
1307 class BeaconPhase(Figure):
1308 class BeaconPhase(Figure):
1308
1309
1309 __isConfig = None
1310 __isConfig = None
1310 __nsubplots = None
1311 __nsubplots = None
1311
1312
1312 PREFIX = 'beacon_phase'
1313 PREFIX = 'beacon_phase'
1313
1314
1314 def __init__(self, **kwargs):
1315 def __init__(self, **kwargs):
1315 Figure.__init__(self, **kwargs)
1316 Figure.__init__(self, **kwargs)
1316 self.timerange = 24*60*60
1317 self.timerange = 24*60*60
1317 self.isConfig = False
1318 self.isConfig = False
1318 self.__nsubplots = 1
1319 self.__nsubplots = 1
1319 self.counter_imagwr = 0
1320 self.counter_imagwr = 0
1320 self.WIDTH = 800
1321 self.WIDTH = 800
1321 self.HEIGHT = 400
1322 self.HEIGHT = 400
1322 self.WIDTHPROF = 120
1323 self.WIDTHPROF = 120
1323 self.HEIGHTPROF = 0
1324 self.HEIGHTPROF = 0
1324 self.xdata = None
1325 self.xdata = None
1325 self.ydata = None
1326 self.ydata = None
1326
1327
1327 self.PLOT_CODE = BEACON_CODE
1328 self.PLOT_CODE = BEACON_CODE
1328
1329
1329 self.FTP_WEI = None
1330 self.FTP_WEI = None
1330 self.EXP_CODE = None
1331 self.EXP_CODE = None
1331 self.SUB_EXP_CODE = None
1332 self.SUB_EXP_CODE = None
1332 self.PLOT_POS = None
1333 self.PLOT_POS = None
1333
1334
1334 self.filename_phase = None
1335 self.filename_phase = None
1335
1336
1336 self.figfile = None
1337 self.figfile = None
1337
1338
1338 self.xmin = None
1339 self.xmin = None
1339 self.xmax = None
1340 self.xmax = None
1340
1341
1341 def getSubplots(self):
1342 def getSubplots(self):
1342
1343
1343 ncol = 1
1344 ncol = 1
1344 nrow = 1
1345 nrow = 1
1345
1346
1346 return nrow, ncol
1347 return nrow, ncol
1347
1348
1348 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1349 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1349
1350
1350 self.__showprofile = showprofile
1351 self.__showprofile = showprofile
1351 self.nplots = nplots
1352 self.nplots = nplots
1352
1353
1353 ncolspan = 7
1354 ncolspan = 7
1354 colspan = 6
1355 colspan = 6
1355 self.__nsubplots = 2
1356 self.__nsubplots = 2
1356
1357
1357 self.createFigure(id = id,
1358 self.createFigure(id = id,
1358 wintitle = wintitle,
1359 wintitle = wintitle,
1359 widthplot = self.WIDTH+self.WIDTHPROF,
1360 widthplot = self.WIDTH+self.WIDTHPROF,
1360 heightplot = self.HEIGHT+self.HEIGHTPROF,
1361 heightplot = self.HEIGHT+self.HEIGHTPROF,
1361 show=show)
1362 show=show)
1362
1363
1363 nrow, ncol = self.getSubplots()
1364 nrow, ncol = self.getSubplots()
1364
1365
1365 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1366 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1366
1367
1367 def save_phase(self, filename_phase):
1368 def save_phase(self, filename_phase):
1368 f = open(filename_phase,'w+')
1369 f = open(filename_phase,'w+')
1369 f.write('\n\n')
1370 f.write('\n\n')
1370 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
1371 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
1371 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
1372 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
1372 f.close()
1373 f.close()
1373
1374
1374 def save_data(self, filename_phase, data, data_datetime):
1375 def save_data(self, filename_phase, data, data_datetime):
1375 f=open(filename_phase,'a')
1376 f=open(filename_phase,'a')
1376 timetuple_data = data_datetime.timetuple()
1377 timetuple_data = data_datetime.timetuple()
1377 day = str(timetuple_data.tm_mday)
1378 day = str(timetuple_data.tm_mday)
1378 month = str(timetuple_data.tm_mon)
1379 month = str(timetuple_data.tm_mon)
1379 year = str(timetuple_data.tm_year)
1380 year = str(timetuple_data.tm_year)
1380 hour = str(timetuple_data.tm_hour)
1381 hour = str(timetuple_data.tm_hour)
1381 minute = str(timetuple_data.tm_min)
1382 minute = str(timetuple_data.tm_min)
1382 second = str(timetuple_data.tm_sec)
1383 second = str(timetuple_data.tm_sec)
1383 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1384 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1384 f.close()
1385 f.close()
1385
1386
1386
1387
1387 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1388 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1388 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
1389 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
1389 timerange=None,
1390 timerange=None,
1390 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1391 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1391 server=None, folder=None, username=None, password=None,
1392 server=None, folder=None, username=None, password=None,
1392 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1393 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1393
1394
1394 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1395 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1395 return
1396 return
1396
1397
1397 if pairsList == None:
1398 if pairsList == None:
1398 pairsIndexList = dataOut.pairsIndexList[:10]
1399 pairsIndexList = dataOut.pairsIndexList[:10]
1399 else:
1400 else:
1400 pairsIndexList = []
1401 pairsIndexList = []
1401 for pair in pairsList:
1402 for pair in pairsList:
1402 if pair not in dataOut.pairsList:
1403 if pair not in dataOut.pairsList:
1403 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
1404 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
1404 pairsIndexList.append(dataOut.pairsList.index(pair))
1405 pairsIndexList.append(dataOut.pairsList.index(pair))
1405
1406
1406 if pairsIndexList == []:
1407 if pairsIndexList == []:
1407 return
1408 return
1408
1409
1409 # if len(pairsIndexList) > 4:
1410 # if len(pairsIndexList) > 4:
1410 # pairsIndexList = pairsIndexList[0:4]
1411 # pairsIndexList = pairsIndexList[0:4]
1411
1412
1412 hmin_index = None
1413 hmin_index = None
1413 hmax_index = None
1414 hmax_index = None
1414
1415
1415 if hmin != None and hmax != None:
1416 if hmin != None and hmax != None:
1416 indexes = numpy.arange(dataOut.nHeights)
1417 indexes = numpy.arange(dataOut.nHeights)
1417 hmin_list = indexes[dataOut.heightList >= hmin]
1418 hmin_list = indexes[dataOut.heightList >= hmin]
1418 hmax_list = indexes[dataOut.heightList <= hmax]
1419 hmax_list = indexes[dataOut.heightList <= hmax]
1419
1420
1420 if hmin_list.any():
1421 if hmin_list.any():
1421 hmin_index = hmin_list[0]
1422 hmin_index = hmin_list[0]
1422
1423
1423 if hmax_list.any():
1424 if hmax_list.any():
1424 hmax_index = hmax_list[-1]+1
1425 hmax_index = hmax_list[-1]+1
1425
1426
1426 x = dataOut.getTimeRange()
1427 x = dataOut.getTimeRange()
1427 #y = dataOut.getHeiRange()
1428 #y = dataOut.getHeiRange()
1428
1429
1429
1430
1430 thisDatetime = dataOut.datatime
1431 thisDatetime = dataOut.datatime
1431
1432
1432 title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1433 title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1433 xlabel = "Local Time"
1434 xlabel = "Local Time"
1434 ylabel = "Phase (degrees)"
1435 ylabel = "Phase (degrees)"
1435
1436
1436 update_figfile = False
1437 update_figfile = False
1437
1438
1438 nplots = len(pairsIndexList)
1439 nplots = len(pairsIndexList)
1439 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1440 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1440 phase_beacon = numpy.zeros(len(pairsIndexList))
1441 phase_beacon = numpy.zeros(len(pairsIndexList))
1441 for i in range(nplots):
1442 for i in range(nplots):
1442 pair = dataOut.pairsList[pairsIndexList[i]]
1443 pair = dataOut.pairsList[pairsIndexList[i]]
1443 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0)
1444 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0)
1444 powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0)
1445 powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0)
1445 powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0)
1446 powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0)
1446 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1447 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1447 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1448 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1448
1449
1449 #print "Phase %d%d" %(pair[0], pair[1])
1450 #print "Phase %d%d" %(pair[0], pair[1])
1450 #print phase[dataOut.beacon_heiIndexList]
1451 #print phase[dataOut.beacon_heiIndexList]
1451
1452
1452 if dataOut.beacon_heiIndexList:
1453 if dataOut.beacon_heiIndexList:
1453 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1454 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1454 else:
1455 else:
1455 phase_beacon[i] = numpy.average(phase)
1456 phase_beacon[i] = numpy.average(phase)
1456
1457
1457 if not self.isConfig:
1458 if not self.isConfig:
1458
1459
1459 nplots = len(pairsIndexList)
1460 nplots = len(pairsIndexList)
1460
1461
1461 self.setup(id=id,
1462 self.setup(id=id,
1462 nplots=nplots,
1463 nplots=nplots,
1463 wintitle=wintitle,
1464 wintitle=wintitle,
1464 showprofile=showprofile,
1465 showprofile=showprofile,
1465 show=show)
1466 show=show)
1466
1467
1467 if timerange != None:
1468 if timerange != None:
1468 self.timerange = timerange
1469 self.timerange = timerange
1469
1470
1470 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1471 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1471
1472
1472 if ymin == None: ymin = 0
1473 if ymin == None: ymin = 0
1473 if ymax == None: ymax = 360
1474 if ymax == None: ymax = 360
1474
1475
1475 self.FTP_WEI = ftp_wei
1476 self.FTP_WEI = ftp_wei
1476 self.EXP_CODE = exp_code
1477 self.EXP_CODE = exp_code
1477 self.SUB_EXP_CODE = sub_exp_code
1478 self.SUB_EXP_CODE = sub_exp_code
1478 self.PLOT_POS = plot_pos
1479 self.PLOT_POS = plot_pos
1479
1480
1480 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1481 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1481 self.isConfig = True
1482 self.isConfig = True
1482 self.figfile = figfile
1483 self.figfile = figfile
1483 self.xdata = numpy.array([])
1484 self.xdata = numpy.array([])
1484 self.ydata = numpy.array([])
1485 self.ydata = numpy.array([])
1485
1486
1486 update_figfile = True
1487 update_figfile = True
1487
1488
1488 #open file beacon phase
1489 #open file beacon phase
1489 path = '%s%03d' %(self.PREFIX, self.id)
1490 path = '%s%03d' %(self.PREFIX, self.id)
1490 beacon_file = os.path.join(path,'%s.txt'%self.name)
1491 beacon_file = os.path.join(path,'%s.txt'%self.name)
1491 self.filename_phase = os.path.join(figpath,beacon_file)
1492 self.filename_phase = os.path.join(figpath,beacon_file)
1492 #self.save_phase(self.filename_phase)
1493 #self.save_phase(self.filename_phase)
1493
1494
1494
1495
1495 #store data beacon phase
1496 #store data beacon phase
1496 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1497 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1497
1498
1498 self.setWinTitle(title)
1499 self.setWinTitle(title)
1499
1500
1500
1501
1501 title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1502 title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1502
1503
1503 legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList]
1504 legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList]
1504
1505
1505 axes = self.axesList[0]
1506 axes = self.axesList[0]
1506
1507
1507 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1508 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1508
1509
1509 if len(self.ydata)==0:
1510 if len(self.ydata)==0:
1510 self.ydata = phase_beacon.reshape(-1,1)
1511 self.ydata = phase_beacon.reshape(-1,1)
1511 else:
1512 else:
1512 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1513 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1513
1514
1514
1515
1515 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1516 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1516 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1517 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1517 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1518 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1518 XAxisAsTime=True, grid='both'
1519 XAxisAsTime=True, grid='both'
1519 )
1520 )
1520
1521
1521 self.draw()
1522 self.draw()
1522
1523
1523 if dataOut.ltctime >= self.xmax:
1524 if dataOut.ltctime >= self.xmax:
1524 self.counter_imagwr = wr_period
1525 self.counter_imagwr = wr_period
1525 self.isConfig = False
1526 self.isConfig = False
1526 update_figfile = True
1527 update_figfile = True
1527
1528
1528 self.save(figpath=figpath,
1529 self.save(figpath=figpath,
1529 figfile=figfile,
1530 figfile=figfile,
1530 save=save,
1531 save=save,
1531 ftp=ftp,
1532 ftp=ftp,
1532 wr_period=wr_period,
1533 wr_period=wr_period,
1533 thisDatetime=thisDatetime,
1534 thisDatetime=thisDatetime,
1534 update_figfile=update_figfile)
1535 update_figfile=update_figfile)
@@ -1,1779 +1,1855
1 '''
1 '''
2 Created on Jul 2, 2014
2 Created on Jul 2, 2014
3
3
4 @author: roj-idl71
4 @author: roj-idl71
5 '''
5 '''
6 import os
6 import os
7 import sys
7 import sys
8 import glob
8 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 inspect
13 import time, datetime
13 import time, datetime
14 import traceback
14 import traceback
15 import zmq
15 import zmq
16
16
17 try:
17 try:
18 from gevent import sleep
18 from gevent import sleep
19 except:
19 except:
20 from time import sleep
20 from time import sleep
21
21
22 from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader
22 from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader
23 from schainpy.model.data.jroheaderIO import get_dtype_index, get_numpy_dtype, get_procflag_dtype, get_dtype_width
23 from schainpy.model.data.jroheaderIO import get_dtype_index, get_numpy_dtype, get_procflag_dtype, get_dtype_width
24
24
25 LOCALTIME = True
25 LOCALTIME = True
26
26
27 def isNumber(cad):
27 def isNumber(cad):
28 """
28 """
29 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
29 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
30
30
31 Excepciones:
31 Excepciones:
32 Si un determinado string no puede ser convertido a numero
32 Si un determinado string no puede ser convertido a numero
33 Input:
33 Input:
34 str, string al cual se le analiza para determinar si convertible a un numero o no
34 str, string al cual se le analiza para determinar si convertible a un numero o no
35
35
36 Return:
36 Return:
37 True : si el string es uno numerico
37 True : si el string es uno numerico
38 False : no es un string numerico
38 False : no es un string numerico
39 """
39 """
40 try:
40 try:
41 float( cad )
41 float( cad )
42 return True
42 return True
43 except:
43 except:
44 return False
44 return False
45
45
46 def isFileInEpoch(filename, startUTSeconds, endUTSeconds):
46 def isFileInEpoch(filename, startUTSeconds, endUTSeconds):
47 """
47 """
48 Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado.
48 Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado.
49
49
50 Inputs:
50 Inputs:
51 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
51 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
52
52
53 startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en
53 startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en
54 segundos contados desde 01/01/1970.
54 segundos contados desde 01/01/1970.
55 endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en
55 endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en
56 segundos contados desde 01/01/1970.
56 segundos contados desde 01/01/1970.
57
57
58 Return:
58 Return:
59 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
59 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
60 fecha especificado, de lo contrario retorna False.
60 fecha especificado, de lo contrario retorna False.
61
61
62 Excepciones:
62 Excepciones:
63 Si el archivo no existe o no puede ser abierto
63 Si el archivo no existe o no puede ser abierto
64 Si la cabecera no puede ser leida.
64 Si la cabecera no puede ser leida.
65
65
66 """
66 """
67 basicHeaderObj = BasicHeader(LOCALTIME)
67 basicHeaderObj = BasicHeader(LOCALTIME)
68
68
69 try:
69 try:
70 fp = open(filename,'rb')
70 fp = open(filename,'rb')
71 except IOError:
71 except IOError:
72 print "The file %s can't be opened" %(filename)
72 print "The file %s can't be opened" %(filename)
73 return 0
73 return 0
74
74
75 sts = basicHeaderObj.read(fp)
75 sts = basicHeaderObj.read(fp)
76 fp.close()
76 fp.close()
77
77
78 if not(sts):
78 if not(sts):
79 print "Skipping the file %s because it has not a valid header" %(filename)
79 print "Skipping the file %s because it has not a valid header" %(filename)
80 return 0
80 return 0
81
81
82 if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)):
82 if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)):
83 return 0
83 return 0
84
84
85 return 1
85 return 1
86
86
87 def isTimeInRange(thisTime, startTime, endTime):
87 def isTimeInRange(thisTime, startTime, endTime):
88
88
89 if endTime >= startTime:
89 if endTime >= startTime:
90 if (thisTime < startTime) or (thisTime > endTime):
90 if (thisTime < startTime) or (thisTime > endTime):
91 return 0
91 return 0
92
92
93 return 1
93 return 1
94 else:
94 else:
95 if (thisTime < startTime) and (thisTime > endTime):
95 if (thisTime < startTime) and (thisTime > endTime):
96 return 0
96 return 0
97
97
98 return 1
98 return 1
99
99
100 def isFileInTimeRange(filename, startDate, endDate, startTime, endTime):
100 def isFileInTimeRange(filename, startDate, endDate, startTime, endTime):
101 """
101 """
102 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
102 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
103
103
104 Inputs:
104 Inputs:
105 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
105 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
106
106
107 startDate : fecha inicial del rango seleccionado en formato datetime.date
107 startDate : fecha inicial del rango seleccionado en formato datetime.date
108
108
109 endDate : fecha final del rango seleccionado en formato datetime.date
109 endDate : fecha final del rango seleccionado en formato datetime.date
110
110
111 startTime : tiempo inicial del rango seleccionado en formato datetime.time
111 startTime : tiempo inicial del rango seleccionado en formato datetime.time
112
112
113 endTime : tiempo final del rango seleccionado en formato datetime.time
113 endTime : tiempo final del rango seleccionado en formato datetime.time
114
114
115 Return:
115 Return:
116 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
116 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
117 fecha especificado, de lo contrario retorna False.
117 fecha especificado, de lo contrario retorna False.
118
118
119 Excepciones:
119 Excepciones:
120 Si el archivo no existe o no puede ser abierto
120 Si el archivo no existe o no puede ser abierto
121 Si la cabecera no puede ser leida.
121 Si la cabecera no puede ser leida.
122
122
123 """
123 """
124
124
125
125
126 try:
126 try:
127 fp = open(filename,'rb')
127 fp = open(filename,'rb')
128 except IOError:
128 except IOError:
129 print "The file %s can't be opened" %(filename)
129 print "The file %s can't be opened" %(filename)
130 return None
130 return None
131
131
132 firstBasicHeaderObj = BasicHeader(LOCALTIME)
132 firstBasicHeaderObj = BasicHeader(LOCALTIME)
133 systemHeaderObj = SystemHeader()
133 systemHeaderObj = SystemHeader()
134 radarControllerHeaderObj = RadarControllerHeader()
134 radarControllerHeaderObj = RadarControllerHeader()
135 processingHeaderObj = ProcessingHeader()
135 processingHeaderObj = ProcessingHeader()
136
136
137 lastBasicHeaderObj = BasicHeader(LOCALTIME)
137 lastBasicHeaderObj = BasicHeader(LOCALTIME)
138
138
139 sts = firstBasicHeaderObj.read(fp)
139 sts = firstBasicHeaderObj.read(fp)
140
140
141 if not(sts):
141 if not(sts):
142 print "[Reading] Skipping the file %s because it has not a valid header" %(filename)
142 print "[Reading] Skipping the file %s because it has not a valid header" %(filename)
143 return None
143 return None
144
144
145 if not systemHeaderObj.read(fp):
145 if not systemHeaderObj.read(fp):
146 return None
146 return None
147
147
148 if not radarControllerHeaderObj.read(fp):
148 if not radarControllerHeaderObj.read(fp):
149 return None
149 return None
150
150
151 if not processingHeaderObj.read(fp):
151 if not processingHeaderObj.read(fp):
152 return None
152 return None
153
153
154 filesize = os.path.getsize(filename)
154 filesize = os.path.getsize(filename)
155
155
156 offset = processingHeaderObj.blockSize + 24 #header size
156 offset = processingHeaderObj.blockSize + 24 #header size
157
157
158 if filesize <= offset:
158 if filesize <= offset:
159 print "[Reading] %s: This file has not enough data" %filename
159 print "[Reading] %s: This file has not enough data" %filename
160 return None
160 return None
161
161
162 fp.seek(-offset, 2)
162 fp.seek(-offset, 2)
163
163
164 sts = lastBasicHeaderObj.read(fp)
164 sts = lastBasicHeaderObj.read(fp)
165
165
166 fp.close()
166 fp.close()
167
167
168 thisDatetime = lastBasicHeaderObj.datatime
168 thisDatetime = lastBasicHeaderObj.datatime
169 thisTime_last_block = thisDatetime.time()
169 thisTime_last_block = thisDatetime.time()
170
170
171 thisDatetime = firstBasicHeaderObj.datatime
171 thisDatetime = firstBasicHeaderObj.datatime
172 thisDate = thisDatetime.date()
172 thisDate = thisDatetime.date()
173 thisTime_first_block = thisDatetime.time()
173 thisTime_first_block = thisDatetime.time()
174
174
175 #General case
175 #General case
176 # o>>>>>>>>>>>>>><<<<<<<<<<<<<<o
176 # o>>>>>>>>>>>>>><<<<<<<<<<<<<<o
177 #-----------o----------------------------o-----------
177 #-----------o----------------------------o-----------
178 # startTime endTime
178 # startTime endTime
179
179
180 if endTime >= startTime:
180 if endTime >= startTime:
181 if (thisTime_last_block < startTime) or (thisTime_first_block > endTime):
181 if (thisTime_last_block < startTime) or (thisTime_first_block > endTime):
182 return None
182 return None
183
183
184 return thisDatetime
184 return thisDatetime
185
185
186 #If endTime < startTime then endTime belongs to the next day
186 #If endTime < startTime then endTime belongs to the next day
187
187
188
188
189 #<<<<<<<<<<<o o>>>>>>>>>>>
189 #<<<<<<<<<<<o o>>>>>>>>>>>
190 #-----------o----------------------------o-----------
190 #-----------o----------------------------o-----------
191 # endTime startTime
191 # endTime startTime
192
192
193 if (thisDate == startDate) and (thisTime_last_block < startTime):
193 if (thisDate == startDate) and (thisTime_last_block < startTime):
194 return None
194 return None
195
195
196 if (thisDate == endDate) and (thisTime_first_block > endTime):
196 if (thisDate == endDate) and (thisTime_first_block > endTime):
197 return None
197 return None
198
198
199 if (thisTime_last_block < startTime) and (thisTime_first_block > endTime):
199 if (thisTime_last_block < startTime) and (thisTime_first_block > endTime):
200 return None
200 return None
201
201
202 return thisDatetime
202 return thisDatetime
203
203
204 def isFolderInDateRange(folder, startDate=None, endDate=None):
204 def isFolderInDateRange(folder, startDate=None, endDate=None):
205 """
205 """
206 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
206 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
207
207
208 Inputs:
208 Inputs:
209 folder : nombre completo del directorio.
209 folder : nombre completo del directorio.
210 Su formato deberia ser "/path_root/?YYYYDDD"
210 Su formato deberia ser "/path_root/?YYYYDDD"
211
211
212 siendo:
212 siendo:
213 YYYY : Anio (ejemplo 2015)
213 YYYY : Anio (ejemplo 2015)
214 DDD : Dia del anio (ejemplo 305)
214 DDD : Dia del anio (ejemplo 305)
215
215
216 startDate : fecha inicial del rango seleccionado en formato datetime.date
216 startDate : fecha inicial del rango seleccionado en formato datetime.date
217
217
218 endDate : fecha final del rango seleccionado en formato datetime.date
218 endDate : fecha final del rango seleccionado en formato datetime.date
219
219
220 Return:
220 Return:
221 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
221 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
222 fecha especificado, de lo contrario retorna False.
222 fecha especificado, de lo contrario retorna False.
223 Excepciones:
223 Excepciones:
224 Si el directorio no tiene el formato adecuado
224 Si el directorio no tiene el formato adecuado
225 """
225 """
226
226
227 basename = os.path.basename(folder)
227 basename = os.path.basename(folder)
228
228
229 if not isRadarFolder(basename):
229 if not isRadarFolder(basename):
230 print "The folder %s has not the rigth format" %folder
230 print "The folder %s has not the rigth format" %folder
231 return 0
231 return 0
232
232
233 if startDate and endDate:
233 if startDate and endDate:
234 thisDate = getDateFromRadarFolder(basename)
234 thisDate = getDateFromRadarFolder(basename)
235
235
236 if thisDate < startDate:
236 if thisDate < startDate:
237 return 0
237 return 0
238
238
239 if thisDate > endDate:
239 if thisDate > endDate:
240 return 0
240 return 0
241
241
242 return 1
242 return 1
243
243
244 def isFileInDateRange(filename, startDate=None, endDate=None):
244 def isFileInDateRange(filename, startDate=None, endDate=None):
245 """
245 """
246 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
246 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
247
247
248 Inputs:
248 Inputs:
249 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
249 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
250
250
251 Su formato deberia ser "?YYYYDDDsss"
251 Su formato deberia ser "?YYYYDDDsss"
252
252
253 siendo:
253 siendo:
254 YYYY : Anio (ejemplo 2015)
254 YYYY : Anio (ejemplo 2015)
255 DDD : Dia del anio (ejemplo 305)
255 DDD : Dia del anio (ejemplo 305)
256 sss : set
256 sss : set
257
257
258 startDate : fecha inicial del rango seleccionado en formato datetime.date
258 startDate : fecha inicial del rango seleccionado en formato datetime.date
259
259
260 endDate : fecha final del rango seleccionado en formato datetime.date
260 endDate : fecha final del rango seleccionado en formato datetime.date
261
261
262 Return:
262 Return:
263 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
263 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
264 fecha especificado, de lo contrario retorna False.
264 fecha especificado, de lo contrario retorna False.
265 Excepciones:
265 Excepciones:
266 Si el archivo no tiene el formato adecuado
266 Si el archivo no tiene el formato adecuado
267 """
267 """
268
268
269 basename = os.path.basename(filename)
269 basename = os.path.basename(filename)
270
270
271 if not isRadarFile(basename):
271 if not isRadarFile(basename):
272 print "The filename %s has not the rigth format" %filename
272 print "The filename %s has not the rigth format" %filename
273 return 0
273 return 0
274
274
275 if startDate and endDate:
275 if startDate and endDate:
276 thisDate = getDateFromRadarFile(basename)
276 thisDate = getDateFromRadarFile(basename)
277
277
278 if thisDate < startDate:
278 if thisDate < startDate:
279 return 0
279 return 0
280
280
281 if thisDate > endDate:
281 if thisDate > endDate:
282 return 0
282 return 0
283
283
284 return 1
284 return 1
285
285
286 def getFileFromSet(path, ext, set):
286 def getFileFromSet(path, ext, set):
287 validFilelist = []
287 validFilelist = []
288 fileList = os.listdir(path)
288 fileList = os.listdir(path)
289
289
290 # 0 1234 567 89A BCDE
290 # 0 1234 567 89A BCDE
291 # H YYYY DDD SSS .ext
291 # H YYYY DDD SSS .ext
292
292
293 for thisFile in fileList:
293 for thisFile in fileList:
294 try:
294 try:
295 year = int(thisFile[1:5])
295 year = int(thisFile[1:5])
296 doy = int(thisFile[5:8])
296 doy = int(thisFile[5:8])
297 except:
297 except:
298 continue
298 continue
299
299
300 if (os.path.splitext(thisFile)[-1].lower() != ext.lower()):
300 if (os.path.splitext(thisFile)[-1].lower() != ext.lower()):
301 continue
301 continue
302
302
303 validFilelist.append(thisFile)
303 validFilelist.append(thisFile)
304
304
305 myfile = fnmatch.filter(validFilelist,'*%4.4d%3.3d%3.3d*'%(year,doy,set))
305 myfile = fnmatch.filter(validFilelist,'*%4.4d%3.3d%3.3d*'%(year,doy,set))
306
306
307 if len(myfile)!= 0:
307 if len(myfile)!= 0:
308 return myfile[0]
308 return myfile[0]
309 else:
309 else:
310 filename = '*%4.4d%3.3d%3.3d%s'%(year,doy,set,ext.lower())
310 filename = '*%4.4d%3.3d%3.3d%s'%(year,doy,set,ext.lower())
311 print 'the filename %s does not exist'%filename
311 print 'the filename %s does not exist'%filename
312 print '...going to the last file: '
312 print '...going to the last file: '
313
313
314 if validFilelist:
314 if validFilelist:
315 validFilelist = sorted( validFilelist, key=str.lower )
315 validFilelist = sorted( validFilelist, key=str.lower )
316 return validFilelist[-1]
316 return validFilelist[-1]
317
317
318 return None
318 return None
319
319
320 def getlastFileFromPath(path, ext):
320 def getlastFileFromPath(path, ext):
321 """
321 """
322 Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext"
322 Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext"
323 al final de la depuracion devuelve el ultimo file de la lista que quedo.
323 al final de la depuracion devuelve el ultimo file de la lista que quedo.
324
324
325 Input:
325 Input:
326 fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta
326 fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta
327 ext : extension de los files contenidos en una carpeta
327 ext : extension de los files contenidos en una carpeta
328
328
329 Return:
329 Return:
330 El ultimo file de una determinada carpeta, no se considera el path.
330 El ultimo file de una determinada carpeta, no se considera el path.
331 """
331 """
332 validFilelist = []
332 validFilelist = []
333 fileList = os.listdir(path)
333 fileList = os.listdir(path)
334
334
335 # 0 1234 567 89A BCDE
335 # 0 1234 567 89A BCDE
336 # H YYYY DDD SSS .ext
336 # H YYYY DDD SSS .ext
337
337
338 for thisFile in fileList:
338 for thisFile in fileList:
339
339
340 year = thisFile[1:5]
340 year = thisFile[1:5]
341 if not isNumber(year):
341 if not isNumber(year):
342 continue
342 continue
343
343
344 doy = thisFile[5:8]
344 doy = thisFile[5:8]
345 if not isNumber(doy):
345 if not isNumber(doy):
346 continue
346 continue
347
347
348 year = int(year)
348 year = int(year)
349 doy = int(doy)
349 doy = int(doy)
350
350
351 if (os.path.splitext(thisFile)[-1].lower() != ext.lower()):
351 if (os.path.splitext(thisFile)[-1].lower() != ext.lower()):
352 continue
352 continue
353
353
354 validFilelist.append(thisFile)
354 validFilelist.append(thisFile)
355
355
356 if validFilelist:
356 if validFilelist:
357 validFilelist = sorted( validFilelist, key=str.lower )
357 validFilelist = sorted( validFilelist, key=str.lower )
358 return validFilelist[-1]
358 return validFilelist[-1]
359
359
360 return None
360 return None
361
361
362 def checkForRealPath(path, foldercounter, year, doy, set, ext):
362 def checkForRealPath(path, foldercounter, year, doy, set, ext):
363 """
363 """
364 Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path,
364 Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path,
365 Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar
365 Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar
366 el path exacto de un determinado file.
366 el path exacto de un determinado file.
367
367
368 Example :
368 Example :
369 nombre correcto del file es .../.../D2009307/P2009307367.ext
369 nombre correcto del file es .../.../D2009307/P2009307367.ext
370
370
371 Entonces la funcion prueba con las siguientes combinaciones
371 Entonces la funcion prueba con las siguientes combinaciones
372 .../.../y2009307367.ext
372 .../.../y2009307367.ext
373 .../.../Y2009307367.ext
373 .../.../Y2009307367.ext
374 .../.../x2009307/y2009307367.ext
374 .../.../x2009307/y2009307367.ext
375 .../.../x2009307/Y2009307367.ext
375 .../.../x2009307/Y2009307367.ext
376 .../.../X2009307/y2009307367.ext
376 .../.../X2009307/y2009307367.ext
377 .../.../X2009307/Y2009307367.ext
377 .../.../X2009307/Y2009307367.ext
378 siendo para este caso, la ultima combinacion de letras, identica al file buscado
378 siendo para este caso, la ultima combinacion de letras, identica al file buscado
379
379
380 Return:
380 Return:
381 Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file
381 Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file
382 caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas
382 caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas
383 para el filename
383 para el filename
384 """
384 """
385 fullfilename = None
385 fullfilename = None
386 find_flag = False
386 find_flag = False
387 filename = None
387 filename = None
388
388
389 prefixDirList = [None,'d','D']
389 prefixDirList = [None,'d','D']
390 if ext.lower() == ".r": #voltage
390 if ext.lower() == ".r": #voltage
391 prefixFileList = ['d','D']
391 prefixFileList = ['d','D']
392 elif ext.lower() == ".pdata": #spectra
392 elif ext.lower() == ".pdata": #spectra
393 prefixFileList = ['p','P']
393 prefixFileList = ['p','P']
394 else:
394 else:
395 return None, filename
395 return None, filename
396
396
397 #barrido por las combinaciones posibles
397 #barrido por las combinaciones posibles
398 for prefixDir in prefixDirList:
398 for prefixDir in prefixDirList:
399 thispath = path
399 thispath = path
400 if prefixDir != None:
400 if prefixDir != None:
401 #formo el nombre del directorio xYYYYDDD (x=d o x=D)
401 #formo el nombre del directorio xYYYYDDD (x=d o x=D)
402 if foldercounter == 0:
402 if foldercounter == 0:
403 thispath = os.path.join(path, "%s%04d%03d" % ( prefixDir, year, doy ))
403 thispath = os.path.join(path, "%s%04d%03d" % ( prefixDir, year, doy ))
404 else:
404 else:
405 thispath = os.path.join(path, "%s%04d%03d_%02d" % ( prefixDir, year, doy , foldercounter))
405 thispath = os.path.join(path, "%s%04d%03d_%02d" % ( prefixDir, year, doy , foldercounter))
406 for prefixFile in prefixFileList: #barrido por las dos combinaciones posibles de "D"
406 for prefixFile in prefixFileList: #barrido por las dos combinaciones posibles de "D"
407 filename = "%s%04d%03d%03d%s" % ( prefixFile, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext
407 filename = "%s%04d%03d%03d%s" % ( prefixFile, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext
408 fullfilename = os.path.join( thispath, filename ) #formo el path completo
408 fullfilename = os.path.join( thispath, filename ) #formo el path completo
409
409
410 if os.path.exists( fullfilename ): #verifico que exista
410 if os.path.exists( fullfilename ): #verifico que exista
411 find_flag = True
411 find_flag = True
412 break
412 break
413 if find_flag:
413 if find_flag:
414 break
414 break
415
415
416 if not(find_flag):
416 if not(find_flag):
417 return None, filename
417 return None, filename
418
418
419 return fullfilename, filename
419 return fullfilename, filename
420
420
421 def isRadarFolder(folder):
421 def isRadarFolder(folder):
422 try:
422 try:
423 year = int(folder[1:5])
423 year = int(folder[1:5])
424 doy = int(folder[5:8])
424 doy = int(folder[5:8])
425 except:
425 except:
426 return 0
426 return 0
427
427
428 return 1
428 return 1
429
429
430 def isRadarFile(file):
430 def isRadarFile(file):
431 try:
431 try:
432 year = int(file[1:5])
432 year = int(file[1:5])
433 doy = int(file[5:8])
433 doy = int(file[5:8])
434 set = int(file[8:11])
434 set = int(file[8:11])
435 except:
435 except:
436 return 0
436 return 0
437
437
438 return 1
438 return 1
439
439
440 def getDateFromRadarFile(file):
440 def getDateFromRadarFile(file):
441 try:
441 try:
442 year = int(file[1:5])
442 year = int(file[1:5])
443 doy = int(file[5:8])
443 doy = int(file[5:8])
444 set = int(file[8:11])
444 set = int(file[8:11])
445 except:
445 except:
446 return None
446 return None
447
447
448 thisDate = datetime.date(year, 1, 1) + datetime.timedelta(doy-1)
448 thisDate = datetime.date(year, 1, 1) + datetime.timedelta(doy-1)
449 return thisDate
449 return thisDate
450
450
451 def getDateFromRadarFolder(folder):
451 def getDateFromRadarFolder(folder):
452 try:
452 try:
453 year = int(folder[1:5])
453 year = int(folder[1:5])
454 doy = int(folder[5:8])
454 doy = int(folder[5:8])
455 except:
455 except:
456 return None
456 return None
457
457
458 thisDate = datetime.date(year, 1, 1) + datetime.timedelta(doy-1)
458 thisDate = datetime.date(year, 1, 1) + datetime.timedelta(doy-1)
459 return thisDate
459 return thisDate
460
460
461 class JRODataIO:
461 class JRODataIO:
462
462
463 c = 3E8
463 c = 3E8
464
464
465 isConfig = False
465 isConfig = False
466
466
467 basicHeaderObj = None
467 basicHeaderObj = None
468
468
469 systemHeaderObj = None
469 systemHeaderObj = None
470
470
471 radarControllerHeaderObj = None
471 radarControllerHeaderObj = None
472
472
473 processingHeaderObj = None
473 processingHeaderObj = None
474
474
475 dtype = None
475 dtype = None
476
476
477 pathList = []
477 pathList = []
478
478
479 filenameList = []
479 filenameList = []
480
480
481 filename = None
481 filename = None
482
482
483 ext = None
483 ext = None
484
484
485 flagIsNewFile = 1
485 flagIsNewFile = 1
486
486
487 flagDiscontinuousBlock = 0
487 flagDiscontinuousBlock = 0
488
488
489 flagIsNewBlock = 0
489 flagIsNewBlock = 0
490
490
491 fp = None
491 fp = None
492
492
493 firstHeaderSize = 0
493 firstHeaderSize = 0
494
494
495 basicHeaderSize = 24
495 basicHeaderSize = 24
496
496
497 versionFile = 1103
497 versionFile = 1103
498
498
499 fileSize = None
499 fileSize = None
500
500
501 # ippSeconds = None
501 # ippSeconds = None
502
502
503 fileSizeByHeader = None
503 fileSizeByHeader = None
504
504
505 fileIndex = None
505 fileIndex = None
506
506
507 profileIndex = None
507 profileIndex = None
508
508
509 blockIndex = None
509 blockIndex = None
510
510
511 nTotalBlocks = None
511 nTotalBlocks = None
512
512
513 maxTimeStep = 30
513 maxTimeStep = 30
514
514
515 lastUTTime = None
515 lastUTTime = None
516
516
517 datablock = None
517 datablock = None
518
518
519 dataOut = None
519 dataOut = None
520
520
521 blocksize = None
521 blocksize = None
522
522
523 getByBlock = False
523 getByBlock = False
524
524
525 def __init__(self):
525 def __init__(self):
526
526
527 raise NotImplementedError
527 raise NotImplementedError
528
528
529 def run(self):
529 def run(self):
530
530
531 raise NotImplementedError
531 raise NotImplementedError
532
532
533 def getDtypeWidth(self):
533 def getDtypeWidth(self):
534
534
535 dtype_index = get_dtype_index(self.dtype)
535 dtype_index = get_dtype_index(self.dtype)
536 dtype_width = get_dtype_width(dtype_index)
536 dtype_width = get_dtype_width(dtype_index)
537
537
538 return dtype_width
538 return dtype_width
539
539
540 def getAllowedArgs(self):
540 def getAllowedArgs(self):
541 return inspect.getargspec(self.run).args
541 return inspect.getargspec(self.run).args
542
542
543 class JRODataReader(JRODataIO):
543 class JRODataReader(JRODataIO):
544
544
545
545 firstTime = True
546 online = 0
546 online = 0
547
547
548 realtime = 0
548 realtime = 0
549
549
550 nReadBlocks = 0
550 nReadBlocks = 0
551
551
552 delay = 10 #number of seconds waiting a new file
552 delay = 10 #number of seconds waiting a new file
553
553
554 nTries = 3 #quantity tries
554 nTries = 3 #quantity tries
555
555
556 nFiles = 3 #number of files for searching
556 nFiles = 3 #number of files for searching
557
557
558 path = None
558 path = None
559
559
560 foldercounter = 0
560 foldercounter = 0
561
561
562 flagNoMoreFiles = 0
562 flagNoMoreFiles = 0
563
563
564 datetimeList = []
564 datetimeList = []
565
565
566 __isFirstTimeOnline = 1
566 __isFirstTimeOnline = 1
567
567
568 __printInfo = True
568 __printInfo = True
569
569
570 profileIndex = None
570 profileIndex = None
571
571
572 nTxs = 1
572 nTxs = 1
573
573
574 txIndex = None
574 txIndex = None
575
575
576 #Added--------------------
576 #Added--------------------
577
577
578 selBlocksize = None
578 selBlocksize = None
579
579
580 selBlocktime = None
580 selBlocktime = None
581
581
582
582 onlineWithDate = False
583 def __init__(self):
583 def __init__(self):
584
584
585 """
585 """
586 This class is used to find data files
586 This class is used to find data files
587
587
588 Example:
588 Example:
589 reader = JRODataReader()
589 reader = JRODataReader()
590 fileList = reader.findDataFiles()
590 fileList = reader.findDataFiles()
591
591
592 """
592 """
593 pass
593 pass
594
594
595
595
596 def createObjByDefault(self):
596 def createObjByDefault(self):
597 """
597 """
598
598
599 """
599 """
600 raise NotImplementedError
600 raise NotImplementedError
601
601
602 def getBlockDimension(self):
602 def getBlockDimension(self):
603
603
604 raise NotImplementedError
604 raise NotImplementedError
605
605
606 def __searchFilesOffLine(self,
606 def __searchFilesOffLine(self,
607 path,
607 path,
608 startDate=None,
608 startDate=None,
609 endDate=None,
609 endDate=None,
610 startTime=datetime.time(0,0,0),
610 startTime=datetime.time(0,0,0),
611 endTime=datetime.time(23,59,59),
611 endTime=datetime.time(23,59,59),
612 set=None,
612 set=None,
613 expLabel='',
613 expLabel='',
614 ext='.r',
614 ext='.r',
615 queue=None,
615 queue=None,
616 cursor=None,
616 cursor=None,
617 skip=None,
617 skip=None,
618 walk=True):
618 walk=True):
619
620 self.filenameList = []
619 self.filenameList = []
621 self.datetimeList = []
620 self.datetimeList = []
622
621
623 pathList = []
622 pathList = []
624
623
625 dateList, pathList = self.findDatafiles(path, startDate, endDate, expLabel, ext, walk, include_path=True)
624 dateList, pathList = self.findDatafiles(path, startDate, endDate, expLabel, ext, walk, include_path=True)
626
625
627 if dateList == []:
626 if dateList == []:
628 # print "[Reading] Date range selected invalid [%s - %s]: No *%s files in %s)" %(startDate, endDate, ext, path)
627 # print "[Reading] Date range selected invalid [%s - %s]: No *%s files in %s)" %(startDate, endDate, ext, path)
629 return None, None
628 return None, None
630
629
631 if len(dateList) > 1:
630 if len(dateList) > 1:
632 print "[Reading] Data found for date range [%s - %s]: total days = %d" %(startDate, endDate, len(dateList))
631 print "[Reading] Data found for date range [%s - %s]: total days = %d" %(startDate, endDate, len(dateList))
633 else:
632 else:
634 print "[Reading] Data found for date range [%s - %s]: date = %s" %(startDate, endDate, dateList[0])
633 print "[Reading] Data found for date range [%s - %s]: date = %s" %(startDate, endDate, dateList[0])
635
634
636 filenameList = []
635 filenameList = []
637 datetimeList = []
636 datetimeList = []
638
637
639 for thisPath in pathList:
638 for thisPath in pathList:
640 # thisPath = pathList[pathDict[file]]
639 # thisPath = pathList[pathDict[file]]
641
640
642 fileList = glob.glob1(thisPath, "*%s" %ext)
641 fileList = glob.glob1(thisPath, "*%s" %ext)
643 fileList.sort()
642 fileList.sort()
644
643
645 skippedFileList = []
644 skippedFileList = []
646
645
647 if cursor is not None and skip is not None:
646 if cursor is not None and skip is not None:
648 # if cursor*skip > len(fileList):
647 # if cursor*skip > len(fileList):
649 if skip == 0:
648 if skip == 0:
650 if queue is not None:
649 if queue is not None:
651 queue.put(len(fileList))
650 queue.put(len(fileList))
652 skippedFileList = []
651 skippedFileList = []
653 else:
652 else:
654 skippedFileList = fileList[cursor*skip: cursor*skip + skip]
653 skippedFileList = fileList[cursor*skip: cursor*skip + skip]
655
654
656 else:
655 else:
657 skippedFileList = fileList
656 skippedFileList = fileList
658
657
659 for file in skippedFileList:
658 for file in skippedFileList:
660
659
661 filename = os.path.join(thisPath,file)
660 filename = os.path.join(thisPath,file)
662
661
663 if not isFileInDateRange(filename, startDate, endDate):
662 if not isFileInDateRange(filename, startDate, endDate):
664 continue
663 continue
665
664
666 thisDatetime = isFileInTimeRange(filename, startDate, endDate, startTime, endTime)
665 thisDatetime = isFileInTimeRange(filename, startDate, endDate, startTime, endTime)
667
666
668 if not(thisDatetime):
667 if not(thisDatetime):
669 continue
668 continue
670
669
671 filenameList.append(filename)
670 filenameList.append(filename)
672 datetimeList.append(thisDatetime)
671 datetimeList.append(thisDatetime)
673
672
674 if not(filenameList):
673 if not(filenameList):
675 print "[Reading] Time range selected invalid [%s - %s]: No *%s files in %s)" %(startTime, endTime, ext, path)
674 print "[Reading] Time range selected invalid [%s - %s]: No *%s files in %s)" %(startTime, endTime, ext, path)
676 return None, None
675 return None, None
677
676
678 print "[Reading] %d file(s) was(were) found in time range: %s - %s" %(len(filenameList), startTime, endTime)
677 print "[Reading] %d file(s) was(were) found in time range: %s - %s" %(len(filenameList), startTime, endTime)
679 print
678 print
680
679
681 for i in range(len(filenameList)):
680 for i in range(len(filenameList)):
682 print "[Reading] %s -> [%s]" %(filenameList[i], datetimeList[i].ctime())
681 print "[Reading] %s -> [%s]" %(filenameList[i], datetimeList[i].ctime())
683
682
684 self.filenameList = filenameList
683 self.filenameList = filenameList
685 self.datetimeList = datetimeList
684 self.datetimeList = datetimeList
686
687 return pathList, filenameList
685 return pathList, filenameList
688
686
689 def __searchFilesOnLine(self, path, expLabel = "", ext = None, walk=True, set=None):
687 def __searchFilesOnLine(self, path, expLabel="", ext=None, walk=True, set=None, startDate=None, startTime=None):
690
688
691 """
689 """
692 Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y
690 Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y
693 devuelve el archivo encontrado ademas de otros datos.
691 devuelve el archivo encontrado ademas de otros datos.
694
692
695 Input:
693 Input:
696 path : carpeta donde estan contenidos los files que contiene data
694 path : carpeta donde estan contenidos los files que contiene data
697
695
698 expLabel : Nombre del subexperimento (subfolder)
696 expLabel : Nombre del subexperimento (subfolder)
699
697
700 ext : extension de los files
698 ext : extension de los files
701
699
702 walk : Si es habilitado no realiza busquedas dentro de los ubdirectorios (doypath)
700 walk : Si es habilitado no realiza busquedas dentro de los subdirectorios (doypath)
703
701
704 Return:
702 Return:
705 directory : eL directorio donde esta el file encontrado
703 directory : eL directorio donde esta el file encontrado
706 filename : el ultimo file de una determinada carpeta
704 filename : el ultimo file de una determinada carpeta
707 year : el anho
705 year : el anho
708 doy : el numero de dia del anho
706 doy : el numero de dia del anho
709 set : el set del archivo
707 set : el set del archivo
710
708
711
709
712 """
710 """
711 pathList = None
712 filenameList = None
713 if not os.path.isdir(path):
713 if not os.path.isdir(path):
714 return None, None, None, None, None, None
714 return None, None, None, None, None, None
715
715
716 dirList = []
716 dirList = []
717
717
718 if not walk:
718 if not walk:
719 fullpath = path
719 fullpath = path
720 foldercounter = 0
720 foldercounter = 0
721 else:
721 else:
722 #Filtra solo los directorios
722 # Filtra solo los directorios
723 for thisPath in os.listdir(path):
723 for thisPath in os.listdir(path):
724 if not os.path.isdir(os.path.join(path,thisPath)):
724 if not os.path.isdir(os.path.join(path,thisPath)):
725 continue
725 continue
726 if not isRadarFolder(thisPath):
726 if not isRadarFolder(thisPath):
727 continue
727 continue
728
728
729 dirList.append(thisPath)
729 dirList.append(thisPath)
730
730
731 if not(dirList):
731 if not(dirList):
732 return None, None, None, None, None, None
732 return None, None, None, None, None, None
733
733
734 dirList = sorted( dirList, key=str.lower )
734 dirList = sorted( dirList, key=str.lower )
735
735
736 doypath = dirList[-1]
736 doypath = dirList[-1]
737 foldercounter = int(doypath.split('_')[1]) if len(doypath.split('_'))>1 else 0
737 foldercounter = int(doypath.split('_')[1]) if len(doypath.split('_'))>1 else 0
738 fullpath = os.path.join(path, doypath, expLabel)
738 fullpath = os.path.join(path, doypath, expLabel)
739
739
740
740
741 print "[Reading] %s folder was found: " %(fullpath )
741 print "[Reading] %s folder was found: " %(fullpath )
742
742
743 if set == None:
743 if set == None:
744 filename = getlastFileFromPath(fullpath, ext)
744 filename = getlastFileFromPath(fullpath, ext)
745 else:
745 else:
746 filename = getFileFromSet(fullpath, ext, set)
746 filename = getFileFromSet(fullpath, ext, set)
747
747
748 if not(filename):
748 if not(filename):
749 return None, None, None, None, None, None
749 return None, None, None, None, None, None
750
750
751 print "[Reading] %s file was found" %(filename)
751 print "[Reading] %s file was found" %(filename)
752
752
753 if not(self.__verifyFile(os.path.join(fullpath, filename))):
753 if not(self.__verifyFile(os.path.join(fullpath, filename))):
754 return None, None, None, None, None, None
754 return None, None, None, None, None, None
755
755
756 year = int( filename[1:5] )
756 year = int( filename[1:5] )
757 doy = int( filename[5:8] )
757 doy = int( filename[5:8] )
758 set = int( filename[8:11] )
758 set = int( filename[8:11] )
759
759
760 return fullpath, foldercounter, filename, year, doy, set
760 return fullpath, foldercounter, filename, year, doy, set
761
761
762 def __setNextFileOffline(self):
762 def __setNextFileOffline(self):
763
763
764 idFile = self.fileIndex
764 idFile = self.fileIndex
765
765
766 while (True):
766 while (True):
767 idFile += 1
767 idFile += 1
768 if not(idFile < len(self.filenameList)):
768 if not(idFile < len(self.filenameList)):
769 self.flagNoMoreFiles = 1
769 self.flagNoMoreFiles = 1
770 # print "[Reading] No more Files"
770 # print "[Reading] No more Files"
771 return 0
771 return 0
772
772
773 filename = self.filenameList[idFile]
773 filename = self.filenameList[idFile]
774
774
775 if not(self.__verifyFile(filename)):
775 if not(self.__verifyFile(filename)):
776 continue
776 continue
777
777
778 fileSize = os.path.getsize(filename)
778 fileSize = os.path.getsize(filename)
779 fp = open(filename,'rb')
779 fp = open(filename,'rb')
780 break
780 break
781
781
782 self.flagIsNewFile = 1
782 self.flagIsNewFile = 1
783 self.fileIndex = idFile
783 self.fileIndex = idFile
784 self.filename = filename
784 self.filename = filename
785 self.fileSize = fileSize
785 self.fileSize = fileSize
786 self.fp = fp
786 self.fp = fp
787
787
788 # print "[Reading] Setting the file: %s"%self.filename
788 #print "[Reading] Setting the file: %s"%self.filename
789
789
790 return 1
790 return 1
791
791
792 def __setNextFileOnline(self):
792 def __setNextFileOnline(self):
793 """
793 """
794 Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si
794 Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si
795 no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files
795 no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files
796 siguientes.
796 siguientes.
797
797
798 Affected:
798 Affected:
799 self.flagIsNewFile
799 self.flagIsNewFile
800 self.filename
800 self.filename
801 self.fileSize
801 self.fileSize
802 self.fp
802 self.fp
803 self.set
803 self.set
804 self.flagNoMoreFiles
804 self.flagNoMoreFiles
805
805
806 Return:
806 Return:
807 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado
807 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado
808 1 : si el file fue abierto con exito y esta listo a ser leido
808 1 : si el file fue abierto con exito y esta listo a ser leido
809
809
810 Excepciones:
810 Excepciones:
811 Si un determinado file no puede ser abierto
811 Si un determinado file no puede ser abierto
812 """
812 """
813
813 nFiles = 0
814 nFiles = 0
814 fileOk_flag = False
815 fileOk_flag = False
815 firstTime_flag = True
816 firstTime_flag = True
816
817
817 self.set += 1
818 self.set += 1
818
819
819 if self.set > 999:
820 if self.set > 999:
820 self.set = 0
821 self.set = 0
821 self.foldercounter += 1
822 self.foldercounter += 1
822
823
823 #busca el 1er file disponible
824 #busca el 1er file disponible
824 fullfilename, filename = checkForRealPath( self.path, self.foldercounter, self.year, self.doy, self.set, self.ext )
825 fullfilename, filename = checkForRealPath( self.path, self.foldercounter, self.year, self.doy, self.set, self.ext )
825 if fullfilename:
826 if fullfilename:
826 if self.__verifyFile(fullfilename, False):
827 if self.__verifyFile(fullfilename, False):
827 fileOk_flag = True
828 fileOk_flag = True
828
829
829 #si no encuentra un file entonces espera y vuelve a buscar
830 #si no encuentra un file entonces espera y vuelve a buscar
830 if not(fileOk_flag):
831 if not(fileOk_flag):
831 for nFiles in range(self.nFiles+1): #busco en los siguientes self.nFiles+1 files posibles
832 for nFiles in range(self.nFiles+1): #busco en los siguientes self.nFiles+1 files posibles
832
833
833 if firstTime_flag: #si es la 1era vez entonces hace el for self.nTries veces
834 if firstTime_flag: #si es la 1era vez entonces hace el for self.nTries veces
834 tries = self.nTries
835 tries = self.nTries
835 else:
836 else:
836 tries = 1 #si no es la 1era vez entonces solo lo hace una vez
837 tries = 1 #si no es la 1era vez entonces solo lo hace una vez
837
838
838 for nTries in range( tries ):
839 for nTries in range( tries ):
839 if firstTime_flag:
840 if firstTime_flag:
840 print "\t[Reading] Waiting %0.2f sec for the next file: \"%s\" , try %03d ..." % ( self.delay, filename, nTries+1 )
841 print "\t[Reading] Waiting %0.2f sec for the next file: \"%s\" , try %03d ..." % ( self.delay, filename, nTries+1 )
841 sleep( self.delay )
842 sleep( self.delay )
842 else:
843 else:
843 print "\t[Reading] Searching the next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext)
844 print "\t[Reading] Searching the next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext)
844
845
845 fullfilename, filename = checkForRealPath( self.path, self.foldercounter, self.year, self.doy, self.set, self.ext )
846 fullfilename, filename = checkForRealPath( self.path, self.foldercounter, self.year, self.doy, self.set, self.ext )
846 if fullfilename:
847 if fullfilename:
847 if self.__verifyFile(fullfilename):
848 if self.__verifyFile(fullfilename):
848 fileOk_flag = True
849 fileOk_flag = True
849 break
850 break
850
851
851 if fileOk_flag:
852 if fileOk_flag:
852 break
853 break
853
854
854 firstTime_flag = False
855 firstTime_flag = False
855
856
856 print "\t[Reading] Skipping the file \"%s\" due to this file doesn't exist" % filename
857 print "\t[Reading] Skipping the file \"%s\" due to this file doesn't exist" % filename
857 self.set += 1
858 self.set += 1
858
859
859 if nFiles == (self.nFiles-1): #si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta
860 if nFiles == (self.nFiles-1): #si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta
860 self.set = 0
861 self.set = 0
861 self.doy += 1
862 self.doy += 1
862 self.foldercounter = 0
863 self.foldercounter = 0
863
864
864 if fileOk_flag:
865 if fileOk_flag:
865 self.fileSize = os.path.getsize( fullfilename )
866 self.fileSize = os.path.getsize( fullfilename )
866 self.filename = fullfilename
867 self.filename = fullfilename
867 self.flagIsNewFile = 1
868 self.flagIsNewFile = 1
868 if self.fp != None: self.fp.close()
869 if self.fp != None: self.fp.close()
869 self.fp = open(fullfilename, 'rb')
870 self.fp = open(fullfilename, 'rb')
870 self.flagNoMoreFiles = 0
871 self.flagNoMoreFiles = 0
871 # print '[Reading] Setting the file: %s' % fullfilename
872 # print '[Reading] Setting the file: %s' % fullfilename
872 else:
873 else:
873 self.fileSize = 0
874 self.fileSize = 0
874 self.filename = None
875 self.filename = None
875 self.flagIsNewFile = 0
876 self.flagIsNewFile = 0
876 self.fp = None
877 self.fp = None
877 self.flagNoMoreFiles = 1
878 self.flagNoMoreFiles = 1
878 # print '[Reading] No more files to read'
879 # print '[Reading] No more files to read'
879
880
880 return fileOk_flag
881 return fileOk_flag
881
882
882 def setNextFile(self):
883 def setNextFile(self):
883 if self.fp != None:
884 if self.fp != None:
884 self.fp.close()
885 self.fp.close()
885
886 if self.online:
886 if self.online:
887 newFile = self.__setNextFileOnline()
887 newFile = self.__setNextFileOnline()
888 else:
888 else:
889 newFile = self.__setNextFileOffline()
889 newFile = self.__setNextFileOffline()
890
891 if not(newFile):
890 if not(newFile):
891 if self.onlineWithDate is True:
892 self.onlineWithDate=False
893 self.online = True
894 self.firstTime = False
895 self.setup(
896 path=self.path,
897 startDate=self.startDate,
898 endDate=self.endDate,
899 startTime=self.startTime ,
900 endTime=self.endTime,
901 set=self.set,
902 expLabel=self.expLabel,
903 ext=self.ext,
904 online=self.online,
905 delay=self.delay,
906 walk=self.walk,
907 getblock=self.getblock,
908 nTxs=self.nTxs,
909 realtime=self.realtime,
910 blocksize=self.blocksize,
911 blocktime=self.blocktime
912 )
913 return 1
892 print '[Reading] No more files to read'
914 print '[Reading] No more files to read'
893 return 0
915 return 0
894
916
895 if self.verbose:
917 if self.verbose:
896 print '[Reading] Setting the file: %s' % self.filename
918 print '[Reading] Setting the file: %s' % self.filename
897
919
898 self.__readFirstHeader()
920 self.__readFirstHeader()
899 self.nReadBlocks = 0
921 self.nReadBlocks = 0
900 return 1
922 return 1
901
923
902 def __waitNewBlock(self):
924 def __waitNewBlock(self):
903 """
925 """
904 Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma.
926 Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma.
905
927
906 Si el modo de lectura es OffLine siempre retorn 0
928 Si el modo de lectura es OffLine siempre retorn 0
907 """
929 """
908 if not self.online:
930 if not self.online:
909 return 0
931 return 0
910
932
911 if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile):
933 if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile):
912 return 0
934 return 0
913
935
914 currentPointer = self.fp.tell()
936 currentPointer = self.fp.tell()
915
937
916 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
938 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
917
939
918 for nTries in range( self.nTries ):
940 for nTries in range( self.nTries ):
919
941
920 self.fp.close()
942 self.fp.close()
921 self.fp = open( self.filename, 'rb' )
943 self.fp = open( self.filename, 'rb' )
922 self.fp.seek( currentPointer )
944 self.fp.seek( currentPointer )
923
945
924 self.fileSize = os.path.getsize( self.filename )
946 self.fileSize = os.path.getsize( self.filename )
925 currentSize = self.fileSize - currentPointer
947 currentSize = self.fileSize - currentPointer
926
948
927 if ( currentSize >= neededSize ):
949 if ( currentSize >= neededSize ):
928 self.basicHeaderObj.read(self.fp)
950 self.basicHeaderObj.read(self.fp)
929 return 1
951 return 1
930
952
931 if self.fileSize == self.fileSizeByHeader:
953 if self.fileSize == self.fileSizeByHeader:
932 # self.flagEoF = True
954 # self.flagEoF = True
933 return 0
955 return 0
934
956
935 print "[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1)
957 print "[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1)
936 sleep( self.delay )
958 sleep( self.delay )
937
959
938
960
939 return 0
961 return 0
940
962
941 def waitDataBlock(self,pointer_location):
963 def waitDataBlock(self,pointer_location):
942
964
943 currentPointer = pointer_location
965 currentPointer = pointer_location
944
966
945 neededSize = self.processingHeaderObj.blockSize #+ self.basicHeaderSize
967 neededSize = self.processingHeaderObj.blockSize #+ self.basicHeaderSize
946
968
947 for nTries in range( self.nTries ):
969 for nTries in range( self.nTries ):
948 self.fp.close()
970 self.fp.close()
949 self.fp = open( self.filename, 'rb' )
971 self.fp = open( self.filename, 'rb' )
950 self.fp.seek( currentPointer )
972 self.fp.seek( currentPointer )
951
973
952 self.fileSize = os.path.getsize( self.filename )
974 self.fileSize = os.path.getsize( self.filename )
953 currentSize = self.fileSize - currentPointer
975 currentSize = self.fileSize - currentPointer
954
976
955 if ( currentSize >= neededSize ):
977 if ( currentSize >= neededSize ):
956 return 1
978 return 1
957
979
958 print "[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1)
980 print "[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1)
959 sleep( self.delay )
981 sleep( self.delay )
960
982
961 return 0
983 return 0
962
984
963 def __jumpToLastBlock(self):
985 def __jumpToLastBlock(self):
964
986
965 if not(self.__isFirstTimeOnline):
987 if not(self.__isFirstTimeOnline):
966 return
988 return
967
989
968 csize = self.fileSize - self.fp.tell()
990 csize = self.fileSize - self.fp.tell()
969 blocksize = self.processingHeaderObj.blockSize
991 blocksize = self.processingHeaderObj.blockSize
970
992
971 #salta el primer bloque de datos
993 #salta el primer bloque de datos
972 if csize > self.processingHeaderObj.blockSize:
994 if csize > self.processingHeaderObj.blockSize:
973 self.fp.seek(self.fp.tell() + blocksize)
995 self.fp.seek(self.fp.tell() + blocksize)
974 else:
996 else:
975 return
997 return
976
998
977 csize = self.fileSize - self.fp.tell()
999 csize = self.fileSize - self.fp.tell()
978 neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize
1000 neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize
979 while True:
1001 while True:
980
1002
981 if self.fp.tell()<self.fileSize:
1003 if self.fp.tell()<self.fileSize:
982 self.fp.seek(self.fp.tell() + neededsize)
1004 self.fp.seek(self.fp.tell() + neededsize)
983 else:
1005 else:
984 self.fp.seek(self.fp.tell() - neededsize)
1006 self.fp.seek(self.fp.tell() - neededsize)
985 break
1007 break
986
1008
987 # csize = self.fileSize - self.fp.tell()
1009 # csize = self.fileSize - self.fp.tell()
988 # neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize
1010 # neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize
989 # factor = int(csize/neededsize)
1011 # factor = int(csize/neededsize)
990 # if factor > 0:
1012 # if factor > 0:
991 # self.fp.seek(self.fp.tell() + factor*neededsize)
1013 # self.fp.seek(self.fp.tell() + factor*neededsize)
992
1014
993 self.flagIsNewFile = 0
1015 self.flagIsNewFile = 0
994 self.__isFirstTimeOnline = 0
1016 self.__isFirstTimeOnline = 0
995
1017
996 def __setNewBlock(self):
1018 def __setNewBlock(self):
997 #if self.server is None:
1019 #if self.server is None:
998 if self.fp == None:
1020 if self.fp == None:
999 return 0
1021 return 0
1000
1022
1001 # if self.online:
1023 # if self.online:
1002 # self.__jumpToLastBlock()
1024 # self.__jumpToLastBlock()
1003
1025
1004 if self.flagIsNewFile:
1026 if self.flagIsNewFile:
1005 self.lastUTTime = self.basicHeaderObj.utc
1027 self.lastUTTime = self.basicHeaderObj.utc
1006 return 1
1028 return 1
1007
1029
1008 if self.realtime:
1030 if self.realtime:
1009 self.flagDiscontinuousBlock = 1
1031 self.flagDiscontinuousBlock = 1
1010 if not(self.setNextFile()):
1032 if not(self.setNextFile()):
1011 return 0
1033 return 0
1012 else:
1034 else:
1013 return 1
1035 return 1
1014 #if self.server is None:
1036 #if self.server is None:
1015 currentSize = self.fileSize - self.fp.tell()
1037 currentSize = self.fileSize - self.fp.tell()
1016 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
1038 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
1017 if (currentSize >= neededSize):
1039 if (currentSize >= neededSize):
1018 self.basicHeaderObj.read(self.fp)
1040 self.basicHeaderObj.read(self.fp)
1019 self.lastUTTime = self.basicHeaderObj.utc
1041 self.lastUTTime = self.basicHeaderObj.utc
1020 return 1
1042 return 1
1021 # else:
1043 # else:
1022 # self.basicHeaderObj.read(self.zHeader)
1044 # self.basicHeaderObj.read(self.zHeader)
1023 # self.lastUTTime = self.basicHeaderObj.utc
1045 # self.lastUTTime = self.basicHeaderObj.utc
1024 # return 1
1046 # return 1
1025 if self.__waitNewBlock():
1047 if self.__waitNewBlock():
1026 self.lastUTTime = self.basicHeaderObj.utc
1048 self.lastUTTime = self.basicHeaderObj.utc
1027 return 1
1049 return 1
1028 #if self.server is None:
1050 #if self.server is None:
1029 if not(self.setNextFile()):
1051 if not(self.setNextFile()):
1030 return 0
1052 return 0
1031
1053
1032 deltaTime = self.basicHeaderObj.utc - self.lastUTTime #
1054 deltaTime = self.basicHeaderObj.utc - self.lastUTTime #
1033 self.lastUTTime = self.basicHeaderObj.utc
1055 self.lastUTTime = self.basicHeaderObj.utc
1034
1056
1035 self.flagDiscontinuousBlock = 0
1057 self.flagDiscontinuousBlock = 0
1036
1058
1037 if deltaTime > self.maxTimeStep:
1059 if deltaTime > self.maxTimeStep:
1038 self.flagDiscontinuousBlock = 1
1060 self.flagDiscontinuousBlock = 1
1039
1061
1040 return 1
1062 return 1
1041
1063
1042 def readNextBlock(self):
1064 def readNextBlock(self):
1043
1065
1044 #Skip block out of startTime and endTime
1066 #Skip block out of startTime and endTime
1045 while True:
1067 while True:
1046 if not(self.__setNewBlock()):
1068 if not(self.__setNewBlock()):
1047 print 'returning'
1069 print 'returning'
1048 return 0
1070 return 0
1049 if not(self.readBlock()):
1071 if not(self.readBlock()):
1050 return 0
1072 return 0
1051
1052 self.getBasicHeader()
1073 self.getBasicHeader()
1053
1054 if not isTimeInRange(self.dataOut.datatime.time(), self.startTime, self.endTime):
1074 if not isTimeInRange(self.dataOut.datatime.time(), self.startTime, self.endTime):
1055
1075
1056 print "[Reading] Block No. %d/%d -> %s [Skipping]" %(self.nReadBlocks,
1076 print "[Reading] Block No. %d/%d -> %s [Skipping]" %(self.nReadBlocks,
1057 self.processingHeaderObj.dataBlocksPerFile,
1077 self.processingHeaderObj.dataBlocksPerFile,
1058 self.dataOut.datatime.ctime())
1078 self.dataOut.datatime.ctime())
1059 continue
1079 continue
1060
1080
1061 break
1081 break
1062
1082
1063 if self.verbose:
1083 if self.verbose:
1064 print "[Reading] Block No. %d/%d -> %s" %(self.nReadBlocks,
1084 print "[Reading] Block No. %d/%d -> %s" %(self.nReadBlocks,
1065 self.processingHeaderObj.dataBlocksPerFile,
1085 self.processingHeaderObj.dataBlocksPerFile,
1066 self.dataOut.datatime.ctime())
1086 self.dataOut.datatime.ctime())
1067 return 1
1087 return 1
1068
1088
1069 def __readFirstHeader(self):
1089 def __readFirstHeader(self):
1070
1090
1071 self.basicHeaderObj.read(self.fp)
1091 self.basicHeaderObj.read(self.fp)
1072 self.systemHeaderObj.read(self.fp)
1092 self.systemHeaderObj.read(self.fp)
1073 self.radarControllerHeaderObj.read(self.fp)
1093 self.radarControllerHeaderObj.read(self.fp)
1074 self.processingHeaderObj.read(self.fp)
1094 self.processingHeaderObj.read(self.fp)
1075
1095
1076 self.firstHeaderSize = self.basicHeaderObj.size
1096 self.firstHeaderSize = self.basicHeaderObj.size
1077
1097
1078 datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
1098 datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
1079 if datatype == 0:
1099 if datatype == 0:
1080 datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')])
1100 datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')])
1081 elif datatype == 1:
1101 elif datatype == 1:
1082 datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')])
1102 datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')])
1083 elif datatype == 2:
1103 elif datatype == 2:
1084 datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')])
1104 datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')])
1085 elif datatype == 3:
1105 elif datatype == 3:
1086 datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')])
1106 datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')])
1087 elif datatype == 4:
1107 elif datatype == 4:
1088 datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')])
1108 datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')])
1089 elif datatype == 5:
1109 elif datatype == 5:
1090 datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')])
1110 datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')])
1091 else:
1111 else:
1092 raise ValueError, 'Data type was not defined'
1112 raise ValueError, 'Data type was not defined'
1093
1113
1094 self.dtype = datatype_str
1114 self.dtype = datatype_str
1095 #self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c
1115 #self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c
1096 self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1)
1116 self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1)
1097 # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels)
1117 # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels)
1098 # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels)
1118 # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels)
1099 self.getBlockDimension()
1119 self.getBlockDimension()
1100
1120
1101 def __verifyFile(self, filename, msgFlag=True):
1121 def __verifyFile(self, filename, msgFlag=True):
1102
1122
1103 msg = None
1123 msg = None
1104
1124
1105 try:
1125 try:
1106 fp = open(filename, 'rb')
1126 fp = open(filename, 'rb')
1107 except IOError:
1127 except IOError:
1108
1128
1109 if msgFlag:
1129 if msgFlag:
1110 print "[Reading] File %s can't be opened" % (filename)
1130 print "[Reading] File %s can't be opened" % (filename)
1111
1131
1112 return False
1132 return False
1113
1133
1114 currentPosition = fp.tell()
1134 currentPosition = fp.tell()
1115 neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize
1135 neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize
1116
1136
1117 if neededSize == 0:
1137 if neededSize == 0:
1118 basicHeaderObj = BasicHeader(LOCALTIME)
1138 basicHeaderObj = BasicHeader(LOCALTIME)
1119 systemHeaderObj = SystemHeader()
1139 systemHeaderObj = SystemHeader()
1120 radarControllerHeaderObj = RadarControllerHeader()
1140 radarControllerHeaderObj = RadarControllerHeader()
1121 processingHeaderObj = ProcessingHeader()
1141 processingHeaderObj = ProcessingHeader()
1122
1142
1123 if not( basicHeaderObj.read(fp) ):
1143 if not( basicHeaderObj.read(fp) ):
1124 fp.close()
1144 fp.close()
1125 return False
1145 return False
1126
1146
1127 if not( systemHeaderObj.read(fp) ):
1147 if not( systemHeaderObj.read(fp) ):
1128 fp.close()
1148 fp.close()
1129 return False
1149 return False
1130
1150
1131 if not( radarControllerHeaderObj.read(fp) ):
1151 if not( radarControllerHeaderObj.read(fp) ):
1132 fp.close()
1152 fp.close()
1133 return False
1153 return False
1134
1154
1135 if not( processingHeaderObj.read(fp) ):
1155 if not( processingHeaderObj.read(fp) ):
1136 fp.close()
1156 fp.close()
1137 return False
1157 return False
1138
1158
1139 neededSize = processingHeaderObj.blockSize + basicHeaderObj.size
1159 neededSize = processingHeaderObj.blockSize + basicHeaderObj.size
1140 else:
1160 else:
1141 msg = "[Reading] Skipping the file %s due to it hasn't enough data" %filename
1161 msg = "[Reading] Skipping the file %s due to it hasn't enough data" %filename
1142
1162
1143 fp.close()
1163 fp.close()
1144
1164
1145 fileSize = os.path.getsize(filename)
1165 fileSize = os.path.getsize(filename)
1146 currentSize = fileSize - currentPosition
1166 currentSize = fileSize - currentPosition
1147
1167
1148 if currentSize < neededSize:
1168 if currentSize < neededSize:
1149 if msgFlag and (msg != None):
1169 if msgFlag and (msg != None):
1150 print msg
1170 print msg
1151 return False
1171 return False
1152
1172
1153 return True
1173 return True
1154
1174
1155 def findDatafiles(self, path, startDate=None, endDate=None, expLabel='', ext='.r', walk=True, include_path=False):
1175 def findDatafiles(self, path, startDate=None, endDate=None, expLabel='', ext='.r', walk=True, include_path=False):
1156
1176
1157 path_empty = True
1177 path_empty = True
1158
1178
1159 dateList = []
1179 dateList = []
1160 pathList = []
1180 pathList = []
1161
1181
1162 multi_path = path.split(',')
1182 multi_path = path.split(',')
1163
1183
1164 if not walk:
1184 if not walk:
1165
1185
1166 for single_path in multi_path:
1186 for single_path in multi_path:
1167
1187
1168 if not os.path.isdir(single_path):
1188 if not os.path.isdir(single_path):
1169 continue
1189 continue
1170
1190
1171 fileList = glob.glob1(single_path, "*"+ext)
1191 fileList = glob.glob1(single_path, "*"+ext)
1172
1192
1173 if not fileList:
1193 if not fileList:
1174 continue
1194 continue
1175
1195
1176 path_empty = False
1196 path_empty = False
1177
1197
1178 fileList.sort()
1198 fileList.sort()
1179
1199
1180 for thisFile in fileList:
1200 for thisFile in fileList:
1181
1201
1182 if not os.path.isfile(os.path.join(single_path, thisFile)):
1202 if not os.path.isfile(os.path.join(single_path, thisFile)):
1183 continue
1203 continue
1184
1204
1185 if not isRadarFile(thisFile):
1205 if not isRadarFile(thisFile):
1186 continue
1206 continue
1187
1207
1188 if not isFileInDateRange(thisFile, startDate, endDate):
1208 if not isFileInDateRange(thisFile, startDate, endDate):
1189 continue
1209 continue
1190
1210
1191 thisDate = getDateFromRadarFile(thisFile)
1211 thisDate = getDateFromRadarFile(thisFile)
1192
1212
1193 if thisDate in dateList:
1213 if thisDate in dateList:
1194 continue
1214 continue
1195
1215
1196 dateList.append(thisDate)
1216 dateList.append(thisDate)
1197 pathList.append(single_path)
1217 pathList.append(single_path)
1198
1218
1199 else:
1219 else:
1200 for single_path in multi_path:
1220 for single_path in multi_path:
1201
1221
1202 if not os.path.isdir(single_path):
1222 if not os.path.isdir(single_path):
1203 continue
1223 continue
1204
1224
1205 dirList = []
1225 dirList = []
1206
1226
1207 for thisPath in os.listdir(single_path):
1227 for thisPath in os.listdir(single_path):
1208
1228
1209 if not os.path.isdir(os.path.join(single_path,thisPath)):
1229 if not os.path.isdir(os.path.join(single_path,thisPath)):
1210 continue
1230 continue
1211
1231
1212 if not isRadarFolder(thisPath):
1232 if not isRadarFolder(thisPath):
1213 continue
1233 continue
1214
1234
1215 if not isFolderInDateRange(thisPath, startDate, endDate):
1235 if not isFolderInDateRange(thisPath, startDate, endDate):
1216 continue
1236 continue
1217
1237
1218 dirList.append(thisPath)
1238 dirList.append(thisPath)
1219
1239
1220 if not dirList:
1240 if not dirList:
1221 continue
1241 continue
1222
1242
1223 dirList.sort()
1243 dirList.sort()
1224
1244
1225 for thisDir in dirList:
1245 for thisDir in dirList:
1226
1246
1227 datapath = os.path.join(single_path, thisDir, expLabel)
1247 datapath = os.path.join(single_path, thisDir, expLabel)
1228 fileList = glob.glob1(datapath, "*"+ext)
1248 fileList = glob.glob1(datapath, "*"+ext)
1229
1249
1230 if not fileList:
1250 if not fileList:
1231 continue
1251 continue
1232
1252
1233 path_empty = False
1253 path_empty = False
1234
1254
1235 thisDate = getDateFromRadarFolder(thisDir)
1255 thisDate = getDateFromRadarFolder(thisDir)
1236
1256
1237 pathList.append(datapath)
1257 pathList.append(datapath)
1238 dateList.append(thisDate)
1258 dateList.append(thisDate)
1239
1259
1240 dateList.sort()
1260 dateList.sort()
1241
1261
1242 if walk:
1262 if walk:
1243 pattern_path = os.path.join(multi_path[0], "[dYYYYDDD]", expLabel)
1263 pattern_path = os.path.join(multi_path[0], "[dYYYYDDD]", expLabel)
1244 else:
1264 else:
1245 pattern_path = multi_path[0]
1265 pattern_path = multi_path[0]
1246
1266
1247 if path_empty:
1267 if path_empty:
1248 print "[Reading] No *%s files in %s for %s to %s" %(ext, pattern_path, startDate, endDate)
1268 print "[Reading] No *%s files in %s for %s to %s" %(ext, pattern_path, startDate, endDate)
1249 else:
1269 else:
1250 if not dateList:
1270 if not dateList:
1251 print "[Reading] Date range selected invalid [%s - %s]: No *%s files in %s)" %(startDate, endDate, ext, path)
1271 print "[Reading] Date range selected invalid [%s - %s]: No *%s files in %s)" %(startDate, endDate, ext, path)
1252
1272
1253 if include_path:
1273 if include_path:
1254 return dateList, pathList
1274 return dateList, pathList
1255
1275
1256 return dateList
1276 return dateList
1257
1277
1258 def setup(self,
1278 def setup(self,
1259 path=None,
1279 path=None,
1260 startDate=None,
1280 startDate=None,
1261 endDate=None,
1281 endDate=None,
1262 startTime=datetime.time(0,0,0),
1282 startTime=datetime.time(0,0,0),
1263 endTime=datetime.time(23,59,59),
1283 endTime=datetime.time(23,59,59),
1264 set=None,
1284 set=None,
1265 expLabel = "",
1285 expLabel = "",
1266 ext = None,
1286 ext = None,
1267 online = False,
1287 online = False,
1268 delay = 60,
1288 delay = 60,
1269 walk = True,
1289 walk = True,
1270 getblock = False,
1290 getblock = False,
1271 nTxs = 1,
1291 nTxs = 1,
1272 realtime=False,
1292 realtime=False,
1273 blocksize=None,
1293 blocksize=None,
1274 blocktime=None,
1294 blocktime=None,
1275 queue=None,
1276 skip=None,
1277 cursor=None,
1278 warnings=True,
1279 verbose=True,
1295 verbose=True,
1280 server=None):
1296 **kwargs):
1281 if server is not None:
1282 if 'tcp://' in server:
1283 address = server
1284 else:
1285 address = 'ipc:///tmp/%s' % server
1286 self.server = address
1287 self.context = zmq.Context()
1288 self.receiver = self.context.socket(zmq.PULL)
1289 self.receiver.connect(self.server)
1290 time.sleep(0.5)
1291 print '[Starting] ReceiverData from {}'.format(self.server)
1292 else:
1293 self.server = None
1294 if path == None:
1295 raise ValueError, "[Reading] The path is not valid"
1296
1297 if ext == None:
1298 ext = self.ext
1299
1300 if online:
1301 print "[Reading] Searching files in online mode..."
1302
1297
1303 for nTries in range( self.nTries ):
1298 if path == None:
1304 fullpath, foldercounter, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext, walk=walk, set=set)
1299 raise ValueError, "[Reading] The path is not valid"
1305
1300
1306 if fullpath:
1307 break
1308
1309 print '[Reading] Waiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1)
1310 sleep( self.delay )
1311
1312 if not(fullpath):
1313 print "[Reading] There 'isn't any valid file in %s" % path
1314 return
1315
1301
1316 self.year = year
1302 if ext == None:
1317 self.doy = doy
1303 ext = self.ext
1318 self.set = set - 1
1304
1319 self.path = path
1305 self.verbose=verbose
1320 self.foldercounter = foldercounter
1306 self.path = path
1321 last_set = None
1307 self.startDate = startDate
1322 else:
1308 self.endDate = endDate
1323 print "[Reading] Searching files in offline mode ..."
1309 self.startTime = startTime
1324 pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate,
1310 self.endTime = endTime
1311 self.set = set
1312 self.expLabel = expLabel
1313 self.ext = ext
1314 self.online = online
1315 self.delay = delay
1316 self.walk = walk
1317 self.getblock = getblock
1318 self.nTxs = nTxs
1319 self.realtime = realtime
1320 self.blocksize = blocksize
1321 self.blocktime = blocktime
1322
1323
1324 if self.firstTime is True:
1325 pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate,
1325 startTime=startTime, endTime=endTime,
1326 startTime=startTime, endTime=endTime,
1326 set=set, expLabel=expLabel, ext=ext,
1327 set=set, expLabel=expLabel, ext=ext,
1327 walk=walk, cursor=cursor,
1328 walk=walk)
1328 skip=skip, queue=queue)
1329 if filenameList is not None: filenameList = filenameList[:-1]
1329
1330 if not(pathList):
1331 # print "[Reading] No *%s files in %s (%s - %s)"%(ext, path,
1332 # datetime.datetime.combine(startDate,startTime).ctime(),
1333 # datetime.datetime.combine(endDate,endTime).ctime())
1334
1335 # sys.exit(-1)
1336
1330
1331 if pathList is not None and filenameList is not None and online:
1332 self.onlineWithDate = True
1333 online = False
1337 self.fileIndex = -1
1334 self.fileIndex = -1
1338 self.pathList = []
1335 self.pathList = pathList
1339 self.filenameList = []
1336 self.filenameList = filenameList
1340 return
1337 file_name = os.path.basename(filenameList[-1])
1338 basename, ext = os.path.splitext(file_name)
1339 last_set = int(basename[-3:])
1340
1341 if online:
1342 print "[Reading] Searching files in online mode..."
1343
1344 for nTries in range(self.nTries):
1345 fullpath, foldercounter, file, year, doy, set = self.__searchFilesOnLine(path=path,
1346 expLabel=expLabel,
1347 ext=ext,
1348 walk=walk,
1349 startDate=startDate,
1350 startTime=startTime,
1351 set=set)
1352
1353 if fullpath:
1354 break
1355 print '[Reading] Waiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1)
1356 sleep( self.delay )
1357
1358 if not(fullpath):
1359 print "[Reading] There 'isn't any valid file in %s" % path
1360 return
1361
1362 self.year = year
1363 self.doy = doy
1364 self.set = set - 1
1365 self.path = path
1366 self.foldercounter = foldercounter
1367 last_set = None
1368 else:
1369 print "[Reading] Searching files in offline mode ..."
1370 pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate,
1371 startTime=startTime, endTime=endTime,
1372 set=set, expLabel=expLabel, ext=ext,
1373 walk=walk)
1374
1375 if not(pathList):
1376 # print "[Reading] No *%s files in %s (%s - %s)"%(ext, path,
1377 # datetime.datetime.combine(startDate,startTime).ctime(),
1378 # datetime.datetime.combine(endDate,endTime).ctime())
1379
1380 # sys.exit(-1)
1381
1382 self.fileIndex = -1
1383 self.pathList = []
1384 self.filenameList = []
1385 return
1386
1387 self.fileIndex = -1
1388 self.pathList = pathList
1389 self.filenameList = filenameList
1390 file_name = os.path.basename(filenameList[-1])
1391 basename, ext = os.path.splitext(file_name)
1392 last_set = int(basename[-3:])
1341
1393
1394
1395 self.online = online
1396 self.realtime = realtime
1397 self.delay = delay
1398 ext = ext.lower()
1399 self.ext = ext
1400 self.getByBlock = getblock
1401 self.nTxs = nTxs
1402 self.startTime = startTime
1403 self.endTime = endTime
1404
1405
1406 #Added-----------------
1407 self.selBlocksize = blocksize
1408 self.selBlocktime = blocktime
1409
1410
1411 if not(self.setNextFile()):
1412 if (startDate!=None) and (endDate!=None):
1413 print "[Reading] No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())
1414 elif startDate != None:
1415 print "[Reading] No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime())
1416 else:
1417 print "[Reading] No files"
1418
1342 self.fileIndex = -1
1419 self.fileIndex = -1
1343 self.pathList = []
1420 self.pathList = []
1344 self.filenameList = []
1421 self.filenameList = []
1345 return
1422 return
1346
1423
1347 # self.getBasicHeader()
1424 # self.getBasicHeader()
1348
1425
1349 if last_set != None:
1426 if last_set != None:
1350 self.dataOut.last_block = last_set * self.processingHeaderObj.dataBlocksPerFile + self.basicHeaderObj.dataBlock
1427 self.dataOut.last_block = last_set * self.processingHeaderObj.dataBlocksPerFile + self.basicHeaderObj.dataBlock
1351 return
1428 return
1352
1429
1353 def getBasicHeader(self):
1430 def getBasicHeader(self):
1354
1431
1355 self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.radarControllerHeaderObj.ippSeconds
1432 self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.radarControllerHeaderObj.ippSeconds
1356
1433
1357 self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock
1434 self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock
1358
1435
1359 self.dataOut.timeZone = self.basicHeaderObj.timeZone
1436 self.dataOut.timeZone = self.basicHeaderObj.timeZone
1360
1437
1361 self.dataOut.dstFlag = self.basicHeaderObj.dstFlag
1438 self.dataOut.dstFlag = self.basicHeaderObj.dstFlag
1362
1439
1363 self.dataOut.errorCount = self.basicHeaderObj.errorCount
1440 self.dataOut.errorCount = self.basicHeaderObj.errorCount
1364
1441
1365 self.dataOut.useLocalTime = self.basicHeaderObj.useLocalTime
1442 self.dataOut.useLocalTime = self.basicHeaderObj.useLocalTime
1366
1443
1367 self.dataOut.ippSeconds = self.radarControllerHeaderObj.ippSeconds/self.nTxs
1444 self.dataOut.ippSeconds = self.radarControllerHeaderObj.ippSeconds/self.nTxs
1368
1445
1369 # self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock*self.nTxs
1446 # self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock*self.nTxs
1370
1447
1371
1448
1372 def getFirstHeader(self):
1449 def getFirstHeader(self):
1373
1450
1374 raise NotImplementedError
1451 raise NotImplementedError
1375
1452
1376 def getData(self):
1453 def getData(self):
1377
1454
1378 raise NotImplementedError
1455 raise NotImplementedError
1379
1456
1380 def hasNotDataInBuffer(self):
1457 def hasNotDataInBuffer(self):
1381
1458
1382 raise NotImplementedError
1459 raise NotImplementedError
1383
1460
1384 def readBlock(self):
1461 def readBlock(self):
1385
1462
1386 raise NotImplementedError
1463 raise NotImplementedError
1387
1464
1388 def isEndProcess(self):
1465 def isEndProcess(self):
1389
1466
1390 return self.flagNoMoreFiles
1467 return self.flagNoMoreFiles
1391
1468
1392 def printReadBlocks(self):
1469 def printReadBlocks(self):
1393
1470
1394 print "[Reading] Number of read blocks per file %04d" %self.nReadBlocks
1471 print "[Reading] Number of read blocks per file %04d" %self.nReadBlocks
1395
1472
1396 def printTotalBlocks(self):
1473 def printTotalBlocks(self):
1397
1474
1398 print "[Reading] Number of read blocks %04d" %self.nTotalBlocks
1475 print "[Reading] Number of read blocks %04d" %self.nTotalBlocks
1399
1476
1400 def printNumberOfBlock(self):
1477 def printNumberOfBlock(self):
1401
1478
1402 if self.flagIsNewBlock:
1479 if self.flagIsNewBlock:
1403 print "[Reading] Block No. %d/%d -> %s" %(self.nReadBlocks,
1480 print "[Reading] Block No. %d/%d -> %s" %(self.nReadBlocks,
1404 self.processingHeaderObj.dataBlocksPerFile,
1481 self.processingHeaderObj.dataBlocksPerFile,
1405 self.dataOut.datatime.ctime())
1482 self.dataOut.datatime.ctime())
1406
1483
1407 def printInfo(self):
1484 def printInfo(self):
1408
1485
1409 if self.__printInfo == False:
1486 if self.__printInfo == False:
1410 return
1487 return
1411
1488
1412 self.basicHeaderObj.printInfo()
1489 self.basicHeaderObj.printInfo()
1413 self.systemHeaderObj.printInfo()
1490 self.systemHeaderObj.printInfo()
1414 self.radarControllerHeaderObj.printInfo()
1491 self.radarControllerHeaderObj.printInfo()
1415 self.processingHeaderObj.printInfo()
1492 self.processingHeaderObj.printInfo()
1416
1493
1417 self.__printInfo = False
1494 self.__printInfo = False
1418
1495
1419
1420 def run(self,
1496 def run(self,
1421 path=None,
1497 path=None,
1422 startDate=None,
1498 startDate=None,
1423 endDate=None,
1499 endDate=None,
1424 startTime=datetime.time(0,0,0),
1500 startTime=datetime.time(0,0,0),
1425 endTime=datetime.time(23,59,59),
1501 endTime=datetime.time(23,59,59),
1426 set=None,
1502 set=None,
1427 expLabel = "",
1503 expLabel = "",
1428 ext = None,
1504 ext = None,
1429 online = False,
1505 online = False,
1430 delay = 60,
1506 delay = 60,
1431 walk = True,
1507 walk = True,
1432 getblock = False,
1508 getblock = False,
1433 nTxs = 1,
1509 nTxs = 1,
1434 realtime=False,
1510 realtime=False,
1435 blocksize=None,
1511 blocksize=None,
1436 blocktime=None,
1512 blocktime=None,
1437 queue=None,
1513 queue=None,
1438 skip=None,
1514 skip=None,
1439 cursor=None,
1515 cursor=None,
1440 warnings=True,
1516 warnings=True,
1441 server=None,
1517 server=None,
1442 verbose=True, **kwargs):
1518 verbose=True, **kwargs):
1443
1519
1444 if not(self.isConfig):
1520 if not(self.isConfig):
1445 # self.dataOut = dataOut
1521 # self.dataOut = dataOut
1446 self.setup( path=path,
1522 self.setup( path=path,
1447 startDate=startDate,
1523 startDate=startDate,
1448 endDate=endDate,
1524 endDate=endDate,
1449 startTime=startTime,
1525 startTime=startTime,
1450 endTime=endTime,
1526 endTime=endTime,
1451 set=set,
1527 set=set,
1452 expLabel=expLabel,
1528 expLabel=expLabel,
1453 ext=ext,
1529 ext=ext,
1454 online=online,
1530 online=online,
1455 delay=delay,
1531 delay=delay,
1456 walk=walk,
1532 walk=walk,
1457 getblock=getblock,
1533 getblock=getblock,
1458 nTxs=nTxs,
1534 nTxs=nTxs,
1459 realtime=realtime,
1535 realtime=realtime,
1460 blocksize=blocksize,
1536 blocksize=blocksize,
1461 blocktime=blocktime,
1537 blocktime=blocktime,
1462 queue=queue,
1538 queue=queue,
1463 skip=skip,
1539 skip=skip,
1464 cursor=cursor,
1540 cursor=cursor,
1465 warnings=warnings,
1541 warnings=warnings,
1466 server=server,
1542 server=server,
1467 verbose=verbose)
1543 verbose=verbose, **kwargs)
1468 self.isConfig = True
1544 self.isConfig = True
1469 if server is None:
1545 if server is None:
1470 self.getData()
1546 self.getData()
1471 else:
1547 else:
1472 self.getFromServer()
1548 self.getFromServer()
1473
1549
1474 class JRODataWriter(JRODataIO):
1550 class JRODataWriter(JRODataIO):
1475
1551
1476 """
1552 """
1477 Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura
1553 Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura
1478 de los datos siempre se realiza por bloques.
1554 de los datos siempre se realiza por bloques.
1479 """
1555 """
1480
1556
1481 blockIndex = 0
1557 blockIndex = 0
1482
1558
1483 path = None
1559 path = None
1484
1560
1485 setFile = None
1561 setFile = None
1486
1562
1487 profilesPerBlock = None
1563 profilesPerBlock = None
1488
1564
1489 blocksPerFile = None
1565 blocksPerFile = None
1490
1566
1491 nWriteBlocks = 0
1567 nWriteBlocks = 0
1492
1568
1493 fileDate = None
1569 fileDate = None
1494
1570
1495 def __init__(self, dataOut=None):
1571 def __init__(self, dataOut=None):
1496 raise NotImplementedError
1572 raise NotImplementedError
1497
1573
1498
1574
1499 def hasAllDataInBuffer(self):
1575 def hasAllDataInBuffer(self):
1500 raise NotImplementedError
1576 raise NotImplementedError
1501
1577
1502
1578
1503 def setBlockDimension(self):
1579 def setBlockDimension(self):
1504 raise NotImplementedError
1580 raise NotImplementedError
1505
1581
1506
1582
1507 def writeBlock(self):
1583 def writeBlock(self):
1508 raise NotImplementedError
1584 raise NotImplementedError
1509
1585
1510
1586
1511 def putData(self):
1587 def putData(self):
1512 raise NotImplementedError
1588 raise NotImplementedError
1513
1589
1514
1590
1515 def getProcessFlags(self):
1591 def getProcessFlags(self):
1516
1592
1517 processFlags = 0
1593 processFlags = 0
1518
1594
1519 dtype_index = get_dtype_index(self.dtype)
1595 dtype_index = get_dtype_index(self.dtype)
1520 procflag_dtype = get_procflag_dtype(dtype_index)
1596 procflag_dtype = get_procflag_dtype(dtype_index)
1521
1597
1522 processFlags += procflag_dtype
1598 processFlags += procflag_dtype
1523
1599
1524 if self.dataOut.flagDecodeData:
1600 if self.dataOut.flagDecodeData:
1525 processFlags += PROCFLAG.DECODE_DATA
1601 processFlags += PROCFLAG.DECODE_DATA
1526
1602
1527 if self.dataOut.flagDeflipData:
1603 if self.dataOut.flagDeflipData:
1528 processFlags += PROCFLAG.DEFLIP_DATA
1604 processFlags += PROCFLAG.DEFLIP_DATA
1529
1605
1530 if self.dataOut.code is not None:
1606 if self.dataOut.code is not None:
1531 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
1607 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
1532
1608
1533 if self.dataOut.nCohInt > 1:
1609 if self.dataOut.nCohInt > 1:
1534 processFlags += PROCFLAG.COHERENT_INTEGRATION
1610 processFlags += PROCFLAG.COHERENT_INTEGRATION
1535
1611
1536 if self.dataOut.type == "Spectra":
1612 if self.dataOut.type == "Spectra":
1537 if self.dataOut.nIncohInt > 1:
1613 if self.dataOut.nIncohInt > 1:
1538 processFlags += PROCFLAG.INCOHERENT_INTEGRATION
1614 processFlags += PROCFLAG.INCOHERENT_INTEGRATION
1539
1615
1540 if self.dataOut.data_dc is not None:
1616 if self.dataOut.data_dc is not None:
1541 processFlags += PROCFLAG.SAVE_CHANNELS_DC
1617 processFlags += PROCFLAG.SAVE_CHANNELS_DC
1542
1618
1543 if self.dataOut.flagShiftFFT:
1619 if self.dataOut.flagShiftFFT:
1544 processFlags += PROCFLAG.SHIFT_FFT_DATA
1620 processFlags += PROCFLAG.SHIFT_FFT_DATA
1545
1621
1546 return processFlags
1622 return processFlags
1547
1623
1548 def setBasicHeader(self):
1624 def setBasicHeader(self):
1549
1625
1550 self.basicHeaderObj.size = self.basicHeaderSize #bytes
1626 self.basicHeaderObj.size = self.basicHeaderSize #bytes
1551 self.basicHeaderObj.version = self.versionFile
1627 self.basicHeaderObj.version = self.versionFile
1552 self.basicHeaderObj.dataBlock = self.nTotalBlocks
1628 self.basicHeaderObj.dataBlock = self.nTotalBlocks
1553
1629
1554 utc = numpy.floor(self.dataOut.utctime)
1630 utc = numpy.floor(self.dataOut.utctime)
1555 milisecond = (self.dataOut.utctime - utc)* 1000.0
1631 milisecond = (self.dataOut.utctime - utc)* 1000.0
1556
1632
1557 self.basicHeaderObj.utc = utc
1633 self.basicHeaderObj.utc = utc
1558 self.basicHeaderObj.miliSecond = milisecond
1634 self.basicHeaderObj.miliSecond = milisecond
1559 self.basicHeaderObj.timeZone = self.dataOut.timeZone
1635 self.basicHeaderObj.timeZone = self.dataOut.timeZone
1560 self.basicHeaderObj.dstFlag = self.dataOut.dstFlag
1636 self.basicHeaderObj.dstFlag = self.dataOut.dstFlag
1561 self.basicHeaderObj.errorCount = self.dataOut.errorCount
1637 self.basicHeaderObj.errorCount = self.dataOut.errorCount
1562
1638
1563 def setFirstHeader(self):
1639 def setFirstHeader(self):
1564 """
1640 """
1565 Obtiene una copia del First Header
1641 Obtiene una copia del First Header
1566
1642
1567 Affected:
1643 Affected:
1568
1644
1569 self.basicHeaderObj
1645 self.basicHeaderObj
1570 self.systemHeaderObj
1646 self.systemHeaderObj
1571 self.radarControllerHeaderObj
1647 self.radarControllerHeaderObj
1572 self.processingHeaderObj self.
1648 self.processingHeaderObj self.
1573
1649
1574 Return:
1650 Return:
1575 None
1651 None
1576 """
1652 """
1577
1653
1578 raise NotImplementedError
1654 raise NotImplementedError
1579
1655
1580 def __writeFirstHeader(self):
1656 def __writeFirstHeader(self):
1581 """
1657 """
1582 Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader)
1658 Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader)
1583
1659
1584 Affected:
1660 Affected:
1585 __dataType
1661 __dataType
1586
1662
1587 Return:
1663 Return:
1588 None
1664 None
1589 """
1665 """
1590
1666
1591 # CALCULAR PARAMETROS
1667 # CALCULAR PARAMETROS
1592
1668
1593 sizeLongHeader = self.systemHeaderObj.size + self.radarControllerHeaderObj.size + self.processingHeaderObj.size
1669 sizeLongHeader = self.systemHeaderObj.size + self.radarControllerHeaderObj.size + self.processingHeaderObj.size
1594 self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader
1670 self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader
1595
1671
1596 self.basicHeaderObj.write(self.fp)
1672 self.basicHeaderObj.write(self.fp)
1597 self.systemHeaderObj.write(self.fp)
1673 self.systemHeaderObj.write(self.fp)
1598 self.radarControllerHeaderObj.write(self.fp)
1674 self.radarControllerHeaderObj.write(self.fp)
1599 self.processingHeaderObj.write(self.fp)
1675 self.processingHeaderObj.write(self.fp)
1600
1676
1601 def __setNewBlock(self):
1677 def __setNewBlock(self):
1602 """
1678 """
1603 Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header
1679 Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header
1604
1680
1605 Return:
1681 Return:
1606 0 : si no pudo escribir nada
1682 0 : si no pudo escribir nada
1607 1 : Si escribio el Basic el First Header
1683 1 : Si escribio el Basic el First Header
1608 """
1684 """
1609 if self.fp == None:
1685 if self.fp == None:
1610 self.setNextFile()
1686 self.setNextFile()
1611
1687
1612 if self.flagIsNewFile:
1688 if self.flagIsNewFile:
1613 return 1
1689 return 1
1614
1690
1615 if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile:
1691 if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile:
1616 self.basicHeaderObj.write(self.fp)
1692 self.basicHeaderObj.write(self.fp)
1617 return 1
1693 return 1
1618
1694
1619 if not( self.setNextFile() ):
1695 if not( self.setNextFile() ):
1620 return 0
1696 return 0
1621
1697
1622 return 1
1698 return 1
1623
1699
1624
1700
1625 def writeNextBlock(self):
1701 def writeNextBlock(self):
1626 """
1702 """
1627 Selecciona el bloque siguiente de datos y los escribe en un file
1703 Selecciona el bloque siguiente de datos y los escribe en un file
1628
1704
1629 Return:
1705 Return:
1630 0 : Si no hizo pudo escribir el bloque de datos
1706 0 : Si no hizo pudo escribir el bloque de datos
1631 1 : Si no pudo escribir el bloque de datos
1707 1 : Si no pudo escribir el bloque de datos
1632 """
1708 """
1633 if not( self.__setNewBlock() ):
1709 if not( self.__setNewBlock() ):
1634 return 0
1710 return 0
1635
1711
1636 self.writeBlock()
1712 self.writeBlock()
1637
1713
1638 print "[Writing] Block No. %d/%d" %(self.blockIndex,
1714 print "[Writing] Block No. %d/%d" %(self.blockIndex,
1639 self.processingHeaderObj.dataBlocksPerFile)
1715 self.processingHeaderObj.dataBlocksPerFile)
1640
1716
1641 return 1
1717 return 1
1642
1718
1643 def setNextFile(self):
1719 def setNextFile(self):
1644 """
1720 """
1645 Determina el siguiente file que sera escrito
1721 Determina el siguiente file que sera escrito
1646
1722
1647 Affected:
1723 Affected:
1648 self.filename
1724 self.filename
1649 self.subfolder
1725 self.subfolder
1650 self.fp
1726 self.fp
1651 self.setFile
1727 self.setFile
1652 self.flagIsNewFile
1728 self.flagIsNewFile
1653
1729
1654 Return:
1730 Return:
1655 0 : Si el archivo no puede ser escrito
1731 0 : Si el archivo no puede ser escrito
1656 1 : Si el archivo esta listo para ser escrito
1732 1 : Si el archivo esta listo para ser escrito
1657 """
1733 """
1658 ext = self.ext
1734 ext = self.ext
1659 path = self.path
1735 path = self.path
1660
1736
1661 if self.fp != None:
1737 if self.fp != None:
1662 self.fp.close()
1738 self.fp.close()
1663
1739
1664 timeTuple = time.localtime( self.dataOut.utctime)
1740 timeTuple = time.localtime( self.dataOut.utctime)
1665 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
1741 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
1666
1742
1667 fullpath = os.path.join( path, subfolder )
1743 fullpath = os.path.join( path, subfolder )
1668 setFile = self.setFile
1744 setFile = self.setFile
1669
1745
1670 if not( os.path.exists(fullpath) ):
1746 if not( os.path.exists(fullpath) ):
1671 os.mkdir(fullpath)
1747 os.mkdir(fullpath)
1672 setFile = -1 #inicializo mi contador de seteo
1748 setFile = -1 #inicializo mi contador de seteo
1673 else:
1749 else:
1674 filesList = os.listdir( fullpath )
1750 filesList = os.listdir( fullpath )
1675 if len( filesList ) > 0:
1751 if len( filesList ) > 0:
1676 filesList = sorted( filesList, key=str.lower )
1752 filesList = sorted( filesList, key=str.lower )
1677 filen = filesList[-1]
1753 filen = filesList[-1]
1678 # el filename debera tener el siguiente formato
1754 # el filename debera tener el siguiente formato
1679 # 0 1234 567 89A BCDE (hex)
1755 # 0 1234 567 89A BCDE (hex)
1680 # x YYYY DDD SSS .ext
1756 # x YYYY DDD SSS .ext
1681 if isNumber( filen[8:11] ):
1757 if isNumber( filen[8:11] ):
1682 setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
1758 setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
1683 else:
1759 else:
1684 setFile = -1
1760 setFile = -1
1685 else:
1761 else:
1686 setFile = -1 #inicializo mi contador de seteo
1762 setFile = -1 #inicializo mi contador de seteo
1687
1763
1688 setFile += 1
1764 setFile += 1
1689
1765
1690 #If this is a new day it resets some values
1766 #If this is a new day it resets some values
1691 if self.dataOut.datatime.date() > self.fileDate:
1767 if self.dataOut.datatime.date() > self.fileDate:
1692 setFile = 0
1768 setFile = 0
1693 self.nTotalBlocks = 0
1769 self.nTotalBlocks = 0
1694
1770
1695 filen = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, timeTuple.tm_year, timeTuple.tm_yday, setFile, ext )
1771 filen = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, timeTuple.tm_year, timeTuple.tm_yday, setFile, ext )
1696
1772
1697 filename = os.path.join( path, subfolder, filen )
1773 filename = os.path.join( path, subfolder, filen )
1698
1774
1699 fp = open( filename,'wb' )
1775 fp = open( filename,'wb' )
1700
1776
1701 self.blockIndex = 0
1777 self.blockIndex = 0
1702
1778
1703 #guardando atributos
1779 #guardando atributos
1704 self.filename = filename
1780 self.filename = filename
1705 self.subfolder = subfolder
1781 self.subfolder = subfolder
1706 self.fp = fp
1782 self.fp = fp
1707 self.setFile = setFile
1783 self.setFile = setFile
1708 self.flagIsNewFile = 1
1784 self.flagIsNewFile = 1
1709 self.fileDate = self.dataOut.datatime.date()
1785 self.fileDate = self.dataOut.datatime.date()
1710
1786
1711 self.setFirstHeader()
1787 self.setFirstHeader()
1712
1788
1713 print '[Writing] Opening file: %s'%self.filename
1789 print '[Writing] Opening file: %s'%self.filename
1714
1790
1715 self.__writeFirstHeader()
1791 self.__writeFirstHeader()
1716
1792
1717 return 1
1793 return 1
1718
1794
1719 def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=64, set=None, ext=None, datatype=4):
1795 def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=64, set=None, ext=None, datatype=4, verbose=True):
1720 """
1796 """
1721 Setea el tipo de formato en la cual sera guardada la data y escribe el First Header
1797 Setea el tipo de formato en la cual sera guardada la data y escribe el First Header
1722
1798
1723 Inputs:
1799 Inputs:
1724 path : directory where data will be saved
1800 path : directory where data will be saved
1725 profilesPerBlock : number of profiles per block
1801 profilesPerBlock : number of profiles per block
1726 set : initial file set
1802 set : initial file set
1727 datatype : An integer number that defines data type:
1803 datatype : An integer number that defines data type:
1728 0 : int8 (1 byte)
1804 0 : int8 (1 byte)
1729 1 : int16 (2 bytes)
1805 1 : int16 (2 bytes)
1730 2 : int32 (4 bytes)
1806 2 : int32 (4 bytes)
1731 3 : int64 (8 bytes)
1807 3 : int64 (8 bytes)
1732 4 : float32 (4 bytes)
1808 4 : float32 (4 bytes)
1733 5 : double64 (8 bytes)
1809 5 : double64 (8 bytes)
1734
1810
1735 Return:
1811 Return:
1736 0 : Si no realizo un buen seteo
1812 0 : Si no realizo un buen seteo
1737 1 : Si realizo un buen seteo
1813 1 : Si realizo un buen seteo
1738 """
1814 """
1739
1815
1740 if ext == None:
1816 if ext == None:
1741 ext = self.ext
1817 ext = self.ext
1742
1818
1743 self.ext = ext.lower()
1819 self.ext = ext.lower()
1744
1820
1745 self.path = path
1821 self.path = path
1746
1822
1747 if set is None:
1823 if set is None:
1748 self.setFile = -1
1824 self.setFile = -1
1749 else:
1825 else:
1750 self.setFile = set - 1
1826 self.setFile = set - 1
1751
1827
1752 self.blocksPerFile = blocksPerFile
1828 self.blocksPerFile = blocksPerFile
1753
1829
1754 self.profilesPerBlock = profilesPerBlock
1830 self.profilesPerBlock = profilesPerBlock
1755
1831
1756 self.dataOut = dataOut
1832 self.dataOut = dataOut
1757 self.fileDate = self.dataOut.datatime.date()
1833 self.fileDate = self.dataOut.datatime.date()
1758 #By default
1834 #By default
1759 self.dtype = self.dataOut.dtype
1835 self.dtype = self.dataOut.dtype
1760
1836
1761 if datatype is not None:
1837 if datatype is not None:
1762 self.dtype = get_numpy_dtype(datatype)
1838 self.dtype = get_numpy_dtype(datatype)
1763
1839
1764 if not(self.setNextFile()):
1840 if not(self.setNextFile()):
1765 print "[Writing] There isn't a next file"
1841 print "[Writing] There isn't a next file"
1766 return 0
1842 return 0
1767
1843
1768 self.setBlockDimension()
1844 self.setBlockDimension()
1769
1845
1770 return 1
1846 return 1
1771
1847
1772 def run(self, dataOut, path, blocksPerFile, profilesPerBlock=64, set=None, ext=None, datatype=4, **kwargs):
1848 def run(self, dataOut, path, blocksPerFile, profilesPerBlock=64, set=None, ext=None, datatype=4, **kwargs):
1773
1849
1774 if not(self.isConfig):
1850 if not(self.isConfig):
1775
1851
1776 self.setup(dataOut, path, blocksPerFile, profilesPerBlock=profilesPerBlock, set=set, ext=ext, datatype=datatype, **kwargs)
1852 self.setup(dataOut, path, blocksPerFile, profilesPerBlock=profilesPerBlock, set=set, ext=ext, datatype=datatype, **kwargs)
1777 self.isConfig = True
1853 self.isConfig = True
1778
1854
1779 self.putData()
1855 self.putData()
@@ -1,849 +1,848
1 '''
1 '''
2 Created on Jul 3, 2014
2 Created on Jul 3, 2014
3
3
4 @author: roj-idl71
4 @author: roj-idl71
5 '''
5 '''
6
6
7 import os, sys
7 import os, sys
8 import time, datetime
8 import time, datetime
9 import numpy
9 import numpy
10 import fnmatch
10 import fnmatch
11 import glob
11 import glob
12 from time import sleep
12 from time import sleep
13
13
14 try:
14 try:
15 import pyfits
15 import pyfits
16 except ImportError, e:
16 except ImportError, e:
17 print "Fits data cannot be used. Install pyfits module"
17 print "Fits data cannot be used. Install pyfits module"
18
18
19 from xml.etree.ElementTree import ElementTree
19 from xml.etree.ElementTree import ElementTree
20
20
21 from jroIO_base import isRadarFolder, isNumber
21 from jroIO_base import isRadarFolder, isNumber
22 from schainpy.model.data.jrodata import Fits
22 from schainpy.model.data.jrodata import Fits
23 from schainpy.model.proc.jroproc_base import Operation, ProcessingUnit
23 from schainpy.model.proc.jroproc_base import Operation, ProcessingUnit
24
24
25 class PyFits(object):
25 class PyFits(object):
26 name=None
26 name=None
27 format=None
27 format=None
28 array =None
28 array =None
29 data =None
29 data =None
30 thdulist=None
30 thdulist=None
31 prihdr=None
31 prihdr=None
32 hdu=None
32 hdu=None
33
33
34 def __init__(self):
34 def __init__(self):
35
35
36 pass
36 pass
37
37
38 def setColF(self,name,format,array):
38 def setColF(self,name,format,array):
39 self.name=name
39 self.name=name
40 self.format=format
40 self.format=format
41 self.array=array
41 self.array=array
42 a1=numpy.array([self.array],dtype=numpy.float32)
42 a1=numpy.array([self.array],dtype=numpy.float32)
43 self.col1 = pyfits.Column(name=self.name, format=self.format, array=a1)
43 self.col1 = pyfits.Column(name=self.name, format=self.format, array=a1)
44 return self.col1
44 return self.col1
45
45
46 # def setColP(self,name,format,data):
46 # def setColP(self,name,format,data):
47 # self.name=name
47 # self.name=name
48 # self.format=format
48 # self.format=format
49 # self.data=data
49 # self.data=data
50 # a2=numpy.array([self.data],dtype=numpy.float32)
50 # a2=numpy.array([self.data],dtype=numpy.float32)
51 # self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2)
51 # self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2)
52 # return self.col2
52 # return self.col2
53
53
54
54
55 def writeData(self,name,format,data):
55 def writeData(self,name,format,data):
56 self.name=name
56 self.name=name
57 self.format=format
57 self.format=format
58 self.data=data
58 self.data=data
59 a2=numpy.array([self.data],dtype=numpy.float32)
59 a2=numpy.array([self.data],dtype=numpy.float32)
60 self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2)
60 self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2)
61 return self.col2
61 return self.col2
62
62
63 def cFImage(self,idblock,year,month,day,hour,minute,second):
63 def cFImage(self,idblock,year,month,day,hour,minute,second):
64 self.hdu= pyfits.PrimaryHDU(idblock)
64 self.hdu= pyfits.PrimaryHDU(idblock)
65 self.hdu.header.set("Year",year)
65 self.hdu.header.set("Year",year)
66 self.hdu.header.set("Month",month)
66 self.hdu.header.set("Month",month)
67 self.hdu.header.set("Day",day)
67 self.hdu.header.set("Day",day)
68 self.hdu.header.set("Hour",hour)
68 self.hdu.header.set("Hour",hour)
69 self.hdu.header.set("Minute",minute)
69 self.hdu.header.set("Minute",minute)
70 self.hdu.header.set("Second",second)
70 self.hdu.header.set("Second",second)
71 return self.hdu
71 return self.hdu
72
72
73
73
74 def Ctable(self,colList):
74 def Ctable(self,colList):
75 self.cols=pyfits.ColDefs(colList)
75 self.cols=pyfits.ColDefs(colList)
76 self.tbhdu = pyfits.new_table(self.cols)
76 self.tbhdu = pyfits.new_table(self.cols)
77 return self.tbhdu
77 return self.tbhdu
78
78
79
79
80 def CFile(self,hdu,tbhdu):
80 def CFile(self,hdu,tbhdu):
81 self.thdulist=pyfits.HDUList([hdu,tbhdu])
81 self.thdulist=pyfits.HDUList([hdu,tbhdu])
82
82
83 def wFile(self,filename):
83 def wFile(self,filename):
84 if os.path.isfile(filename):
84 if os.path.isfile(filename):
85 os.remove(filename)
85 os.remove(filename)
86 self.thdulist.writeto(filename)
86 self.thdulist.writeto(filename)
87
87
88
88
89 class ParameterConf:
89 class ParameterConf:
90 ELEMENTNAME = 'Parameter'
90 ELEMENTNAME = 'Parameter'
91 def __init__(self):
91 def __init__(self):
92 self.name = ''
92 self.name = ''
93 self.value = ''
93 self.value = ''
94
94
95 def readXml(self, parmElement):
95 def readXml(self, parmElement):
96 self.name = parmElement.get('name')
96 self.name = parmElement.get('name')
97 self.value = parmElement.get('value')
97 self.value = parmElement.get('value')
98
98
99 def getElementName(self):
99 def getElementName(self):
100 return self.ELEMENTNAME
100 return self.ELEMENTNAME
101
101
102 class Metadata(object):
102 class Metadata(object):
103
103
104 def __init__(self, filename):
104 def __init__(self, filename):
105 self.parmConfObjList = []
105 self.parmConfObjList = []
106 self.readXml(filename)
106 self.readXml(filename)
107
107
108 def readXml(self, filename):
108 def readXml(self, filename):
109 self.projectElement = None
109 self.projectElement = None
110 self.procUnitConfObjDict = {}
110 self.procUnitConfObjDict = {}
111 self.projectElement = ElementTree().parse(filename)
111 self.projectElement = ElementTree().parse(filename)
112 self.project = self.projectElement.tag
112 self.project = self.projectElement.tag
113
113
114 parmElementList = self.projectElement.getiterator(ParameterConf().getElementName())
114 parmElementList = self.projectElement.getiterator(ParameterConf().getElementName())
115
115
116 for parmElement in parmElementList:
116 for parmElement in parmElementList:
117 parmConfObj = ParameterConf()
117 parmConfObj = ParameterConf()
118 parmConfObj.readXml(parmElement)
118 parmConfObj.readXml(parmElement)
119 self.parmConfObjList.append(parmConfObj)
119 self.parmConfObjList.append(parmConfObj)
120
120
121 class FitsWriter(Operation):
121 class FitsWriter(Operation):
122
123 def __init__(self, **kwargs):
122 def __init__(self, **kwargs):
124 Operation.__init__(self, **kwargs)
123 Operation.__init__(self, **kwargs)
125 self.isConfig = False
124 self.isConfig = False
126 self.dataBlocksPerFile = None
125 self.dataBlocksPerFile = None
127 self.blockIndex = 0
126 self.blockIndex = 0
128 self.flagIsNewFile = 1
127 self.flagIsNewFile = 1
129 self.fitsObj = None
128 self.fitsObj = None
130 self.optchar = 'P'
129 self.optchar = 'P'
131 self.ext = '.fits'
130 self.ext = '.fits'
132 self.setFile = 0
131 self.setFile = 0
133
132
134 def setFitsHeader(self, dataOut, metadatafile=None):
133 def setFitsHeader(self, dataOut, metadatafile=None):
135
134
136 header_data = pyfits.PrimaryHDU()
135 header_data = pyfits.PrimaryHDU()
137
136
138 header_data.header['EXPNAME'] = "RADAR DATA"
137 header_data.header['EXPNAME'] = "RADAR DATA"
139 header_data.header['DATATYPE'] = "SPECTRA"
138 header_data.header['DATATYPE'] = "SPECTRA"
140 header_data.header['COMMENT'] = ""
139 header_data.header['COMMENT'] = ""
141
140
142 if metadatafile:
141 if metadatafile:
143
142
144 metadata4fits = Metadata(metadatafile)
143 metadata4fits = Metadata(metadatafile)
145
144
146 for parameter in metadata4fits.parmConfObjList:
145 for parameter in metadata4fits.parmConfObjList:
147 parm_name = parameter.name
146 parm_name = parameter.name
148 parm_value = parameter.value
147 parm_value = parameter.value
149
148
150 header_data.header[parm_name] = parm_value
149 header_data.header[parm_name] = parm_value
151
150
152 header_data.header['DATETIME'] = time.strftime("%b %d %Y %H:%M:%S", dataOut.datatime.timetuple())
151 header_data.header['DATETIME'] = time.strftime("%b %d %Y %H:%M:%S", dataOut.datatime.timetuple())
153 header_data.header['CHANNELLIST'] = str(dataOut.channelList)
152 header_data.header['CHANNELLIST'] = str(dataOut.channelList)
154 header_data.header['NCHANNELS'] = dataOut.nChannels
153 header_data.header['NCHANNELS'] = dataOut.nChannels
155 #header_data.header['HEIGHTS'] = dataOut.heightList
154 #header_data.header['HEIGHTS'] = dataOut.heightList
156 header_data.header['NHEIGHTS'] = dataOut.nHeights
155 header_data.header['NHEIGHTS'] = dataOut.nHeights
157
156
158 header_data.header['IPPSECONDS'] = dataOut.ippSeconds
157 header_data.header['IPPSECONDS'] = dataOut.ippSeconds
159 header_data.header['NCOHINT'] = dataOut.nCohInt
158 header_data.header['NCOHINT'] = dataOut.nCohInt
160 header_data.header['NINCOHINT'] = dataOut.nIncohInt
159 header_data.header['NINCOHINT'] = dataOut.nIncohInt
161 header_data.header['TIMEZONE'] = dataOut.timeZone
160 header_data.header['TIMEZONE'] = dataOut.timeZone
162 header_data.header['NBLOCK'] = self.blockIndex
161 header_data.header['NBLOCK'] = self.blockIndex
163
162
164 header_data.writeto(self.filename)
163 header_data.writeto(self.filename)
165
164
166 self.addExtension(dataOut.heightList,'HEIGHTLIST')
165 self.addExtension(dataOut.heightList,'HEIGHTLIST')
167
166
168
167
169 def setup(self, dataOut, path, dataBlocksPerFile=100, metadatafile=None):
168 def setup(self, dataOut, path, dataBlocksPerFile=100, metadatafile=None):
170
169
171 self.path = path
170 self.path = path
172 self.dataOut = dataOut
171 self.dataOut = dataOut
173 self.metadatafile = metadatafile
172 self.metadatafile = metadatafile
174 self.dataBlocksPerFile = dataBlocksPerFile
173 self.dataBlocksPerFile = dataBlocksPerFile
175
174
176 def open(self):
175 def open(self):
177 self.fitsObj = pyfits.open(self.filename, mode='update')
176 self.fitsObj = pyfits.open(self.filename, mode='update')
178
177
179
178
180 def addExtension(self, data, tagname):
179 def addExtension(self, data, tagname):
181 self.open()
180 self.open()
182 extension = pyfits.ImageHDU(data=data, name=tagname)
181 extension = pyfits.ImageHDU(data=data, name=tagname)
183 #extension.header['TAG'] = tagname
182 #extension.header['TAG'] = tagname
184 self.fitsObj.append(extension)
183 self.fitsObj.append(extension)
185 self.write()
184 self.write()
186
185
187 def addData(self, data):
186 def addData(self, data):
188 self.open()
187 self.open()
189 extension = pyfits.ImageHDU(data=data, name=self.fitsObj[0].header['DATATYPE'])
188 extension = pyfits.ImageHDU(data=data, name=self.fitsObj[0].header['DATATYPE'])
190 extension.header['UTCTIME'] = self.dataOut.utctime
189 extension.header['UTCTIME'] = self.dataOut.utctime
191 self.fitsObj.append(extension)
190 self.fitsObj.append(extension)
192 self.blockIndex += 1
191 self.blockIndex += 1
193 self.fitsObj[0].header['NBLOCK'] = self.blockIndex
192 self.fitsObj[0].header['NBLOCK'] = self.blockIndex
194
193
195 self.write()
194 self.write()
196
195
197 def write(self):
196 def write(self):
198
197
199 self.fitsObj.flush(verbose=True)
198 self.fitsObj.flush(verbose=True)
200 self.fitsObj.close()
199 self.fitsObj.close()
201
200
202
201
203 def setNextFile(self):
202 def setNextFile(self):
204
203
205 ext = self.ext
204 ext = self.ext
206 path = self.path
205 path = self.path
207
206
208 timeTuple = time.localtime( self.dataOut.utctime)
207 timeTuple = time.localtime( self.dataOut.utctime)
209 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
208 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
210
209
211 fullpath = os.path.join( path, subfolder )
210 fullpath = os.path.join( path, subfolder )
212 if not( os.path.exists(fullpath) ):
211 if not( os.path.exists(fullpath) ):
213 os.mkdir(fullpath)
212 os.mkdir(fullpath)
214 self.setFile = -1 #inicializo mi contador de seteo
213 self.setFile = -1 #inicializo mi contador de seteo
215 else:
214 else:
216 filesList = os.listdir( fullpath )
215 filesList = os.listdir( fullpath )
217 if len( filesList ) > 0:
216 if len( filesList ) > 0:
218 filesList = sorted( filesList, key=str.lower )
217 filesList = sorted( filesList, key=str.lower )
219 filen = filesList[-1]
218 filen = filesList[-1]
220
219
221 if isNumber( filen[8:11] ):
220 if isNumber( filen[8:11] ):
222 self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
221 self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
223 else:
222 else:
224 self.setFile = -1
223 self.setFile = -1
225 else:
224 else:
226 self.setFile = -1 #inicializo mi contador de seteo
225 self.setFile = -1 #inicializo mi contador de seteo
227
226
228 setFile = self.setFile
227 setFile = self.setFile
229 setFile += 1
228 setFile += 1
230
229
231 thisFile = '%s%4.4d%3.3d%3.3d%s' % (self.optchar,
230 thisFile = '%s%4.4d%3.3d%3.3d%s' % (self.optchar,
232 timeTuple.tm_year,
231 timeTuple.tm_year,
233 timeTuple.tm_yday,
232 timeTuple.tm_yday,
234 setFile,
233 setFile,
235 ext )
234 ext )
236
235
237 filename = os.path.join( path, subfolder, thisFile )
236 filename = os.path.join( path, subfolder, thisFile )
238
237
239 self.blockIndex = 0
238 self.blockIndex = 0
240 self.filename = filename
239 self.filename = filename
241 self.setFile = setFile
240 self.setFile = setFile
242 self.flagIsNewFile = 1
241 self.flagIsNewFile = 1
243
242
244 print 'Writing the file: %s'%self.filename
243 print 'Writing the file: %s'%self.filename
245
244
246 self.setFitsHeader(self.dataOut, self.metadatafile)
245 self.setFitsHeader(self.dataOut, self.metadatafile)
247
246
248 return 1
247 return 1
249
248
250 def writeBlock(self):
249 def writeBlock(self):
251 self.addData(self.dataOut.data_spc)
250 self.addData(self.dataOut.data_spc)
252 self.flagIsNewFile = 0
251 self.flagIsNewFile = 0
253
252
254
253
255 def __setNewBlock(self):
254 def __setNewBlock(self):
256
255
257 if self.flagIsNewFile:
256 if self.flagIsNewFile:
258 return 1
257 return 1
259
258
260 if self.blockIndex < self.dataBlocksPerFile:
259 if self.blockIndex < self.dataBlocksPerFile:
261 return 1
260 return 1
262
261
263 if not( self.setNextFile() ):
262 if not( self.setNextFile() ):
264 return 0
263 return 0
265
264
266 return 1
265 return 1
267
266
268 def writeNextBlock(self):
267 def writeNextBlock(self):
269 if not( self.__setNewBlock() ):
268 if not( self.__setNewBlock() ):
270 return 0
269 return 0
271 self.writeBlock()
270 self.writeBlock()
272 return 1
271 return 1
273
272
274 def putData(self):
273 def putData(self):
275 if self.flagIsNewFile:
274 if self.flagIsNewFile:
276 self.setNextFile()
275 self.setNextFile()
277 self.writeNextBlock()
276 self.writeNextBlock()
278
277
279 def run(self, dataOut, **kwargs):
278 def run(self, dataOut, path, dataBlocksPerFile=100, metadatafile=None, **kwargs):
280 if not(self.isConfig):
279 if not(self.isConfig):
281 self.setup(dataOut, **kwargs)
280 self.setup(dataOut, path, dataBlocksPerFile=dataBlocksPerFile, metadatafile=metadatafile, **kwargs)
282 self.isConfig = True
281 self.isConfig = True
283 self.putData()
282 self.putData()
284
283
285
284
286 class FitsReader(ProcessingUnit):
285 class FitsReader(ProcessingUnit):
287
286
288 # __TIMEZONE = time.timezone
287 # __TIMEZONE = time.timezone
289
288
290 expName = None
289 expName = None
291 datetimestr = None
290 datetimestr = None
292 utc = None
291 utc = None
293 nChannels = None
292 nChannels = None
294 nSamples = None
293 nSamples = None
295 dataBlocksPerFile = None
294 dataBlocksPerFile = None
296 comments = None
295 comments = None
297 lastUTTime = None
296 lastUTTime = None
298 header_dict = None
297 header_dict = None
299 data = None
298 data = None
300 data_header_dict = None
299 data_header_dict = None
301
300
302 def __init__(self, **kwargs):
301 def __init__(self, **kwargs):
303 ProcessingUnit.__init__(self, **kwargs)
302 ProcessingUnit.__init__(self, **kwargs)
304 self.isConfig = False
303 self.isConfig = False
305 self.ext = '.fits'
304 self.ext = '.fits'
306 self.setFile = 0
305 self.setFile = 0
307 self.flagNoMoreFiles = 0
306 self.flagNoMoreFiles = 0
308 self.flagIsNewFile = 1
307 self.flagIsNewFile = 1
309 self.flagDiscontinuousBlock = None
308 self.flagDiscontinuousBlock = None
310 self.fileIndex = None
309 self.fileIndex = None
311 self.filename = None
310 self.filename = None
312 self.fileSize = None
311 self.fileSize = None
313 self.fitsObj = None
312 self.fitsObj = None
314 self.timeZone = None
313 self.timeZone = None
315 self.nReadBlocks = 0
314 self.nReadBlocks = 0
316 self.nTotalBlocks = 0
315 self.nTotalBlocks = 0
317 self.dataOut = self.createObjByDefault()
316 self.dataOut = self.createObjByDefault()
318 self.maxTimeStep = 10# deberia ser definido por el usuario usando el metodo setup()
317 self.maxTimeStep = 10# deberia ser definido por el usuario usando el metodo setup()
319 self.blockIndex = 1
318 self.blockIndex = 1
320
319
321 def createObjByDefault(self):
320 def createObjByDefault(self):
322
321
323 dataObj = Fits()
322 dataObj = Fits()
324
323
325 return dataObj
324 return dataObj
326
325
327 def isFileinThisTime(self, filename, startTime, endTime, useLocalTime=False):
326 def isFileinThisTime(self, filename, startTime, endTime, useLocalTime=False):
328 try:
327 try:
329 fitsObj = pyfits.open(filename,'readonly')
328 fitsObj = pyfits.open(filename,'readonly')
330 except:
329 except:
331 print "File %s can't be opened" %(filename)
330 print "File %s can't be opened" %(filename)
332 return None
331 return None
333
332
334 header = fitsObj[0].header
333 header = fitsObj[0].header
335 struct_time = time.strptime(header['DATETIME'], "%b %d %Y %H:%M:%S")
334 struct_time = time.strptime(header['DATETIME'], "%b %d %Y %H:%M:%S")
336 utc = time.mktime(struct_time) - time.timezone #TIMEZONE debe ser un parametro del header FITS
335 utc = time.mktime(struct_time) - time.timezone #TIMEZONE debe ser un parametro del header FITS
337
336
338 ltc = utc
337 ltc = utc
339 if useLocalTime:
338 if useLocalTime:
340 ltc -= time.timezone
339 ltc -= time.timezone
341 thisDatetime = datetime.datetime.utcfromtimestamp(ltc)
340 thisDatetime = datetime.datetime.utcfromtimestamp(ltc)
342 thisTime = thisDatetime.time()
341 thisTime = thisDatetime.time()
343
342
344 if not ((startTime <= thisTime) and (endTime > thisTime)):
343 if not ((startTime <= thisTime) and (endTime > thisTime)):
345 return None
344 return None
346
345
347 return thisDatetime
346 return thisDatetime
348
347
349 def __setNextFileOnline(self):
348 def __setNextFileOnline(self):
350 raise NotImplementedError
349 raise NotImplementedError
351
350
352 def __setNextFileOffline(self):
351 def __setNextFileOffline(self):
353 idFile = self.fileIndex
352 idFile = self.fileIndex
354
353
355 while (True):
354 while (True):
356 idFile += 1
355 idFile += 1
357 if not(idFile < len(self.filenameList)):
356 if not(idFile < len(self.filenameList)):
358 self.flagNoMoreFiles = 1
357 self.flagNoMoreFiles = 1
359 print "No more Files"
358 print "No more Files"
360 return 0
359 return 0
361
360
362 filename = self.filenameList[idFile]
361 filename = self.filenameList[idFile]
363
362
364 # if not(self.__verifyFile(filename)):
363 # if not(self.__verifyFile(filename)):
365 # continue
364 # continue
366
365
367 fileSize = os.path.getsize(filename)
366 fileSize = os.path.getsize(filename)
368 fitsObj = pyfits.open(filename,'readonly')
367 fitsObj = pyfits.open(filename,'readonly')
369 break
368 break
370
369
371 self.flagIsNewFile = 1
370 self.flagIsNewFile = 1
372 self.fileIndex = idFile
371 self.fileIndex = idFile
373 self.filename = filename
372 self.filename = filename
374 self.fileSize = fileSize
373 self.fileSize = fileSize
375 self.fitsObj = fitsObj
374 self.fitsObj = fitsObj
376 self.blockIndex = 0
375 self.blockIndex = 0
377 print "Setting the file: %s"%self.filename
376 print "Setting the file: %s"%self.filename
378
377
379 return 1
378 return 1
380
379
381 def __setValuesFromHeader(self):
380 def __setValuesFromHeader(self):
382
381
383 self.dataOut.header = self.header_dict
382 self.dataOut.header = self.header_dict
384 self.dataOut.expName = self.expName
383 self.dataOut.expName = self.expName
385
384
386 self.dataOut.timeZone = self.timeZone
385 self.dataOut.timeZone = self.timeZone
387 self.dataOut.dataBlocksPerFile = self.dataBlocksPerFile
386 self.dataOut.dataBlocksPerFile = self.dataBlocksPerFile
388 self.dataOut.comments = self.comments
387 self.dataOut.comments = self.comments
389 # self.dataOut.timeInterval = self.timeInterval
388 # self.dataOut.timeInterval = self.timeInterval
390 self.dataOut.channelList = self.channelList
389 self.dataOut.channelList = self.channelList
391 self.dataOut.heightList = self.heightList
390 self.dataOut.heightList = self.heightList
392
391
393 self.dataOut.nCohInt = self.nCohInt
392 self.dataOut.nCohInt = self.nCohInt
394 self.dataOut.nIncohInt = self.nIncohInt
393 self.dataOut.nIncohInt = self.nIncohInt
395
394
396 self.dataOut.ippSeconds = self.ippSeconds
395 self.dataOut.ippSeconds = self.ippSeconds
397
396
398 def readHeader(self):
397 def readHeader(self):
399 headerObj = self.fitsObj[0]
398 headerObj = self.fitsObj[0]
400
399
401 self.header_dict = headerObj.header
400 self.header_dict = headerObj.header
402 if 'EXPNAME' in headerObj.header.keys():
401 if 'EXPNAME' in headerObj.header.keys():
403 self.expName = headerObj.header['EXPNAME']
402 self.expName = headerObj.header['EXPNAME']
404
403
405 if 'DATATYPE' in headerObj.header.keys():
404 if 'DATATYPE' in headerObj.header.keys():
406 self.dataType = headerObj.header['DATATYPE']
405 self.dataType = headerObj.header['DATATYPE']
407
406
408 self.datetimestr = headerObj.header['DATETIME']
407 self.datetimestr = headerObj.header['DATETIME']
409 channelList = headerObj.header['CHANNELLIST']
408 channelList = headerObj.header['CHANNELLIST']
410 channelList = channelList.split('[')
409 channelList = channelList.split('[')
411 channelList = channelList[1].split(']')
410 channelList = channelList[1].split(']')
412 channelList = channelList[0].split(',')
411 channelList = channelList[0].split(',')
413 channelList = [int(ch) for ch in channelList]
412 channelList = [int(ch) for ch in channelList]
414 self.channelList = channelList
413 self.channelList = channelList
415 self.nChannels = headerObj.header['NCHANNELS']
414 self.nChannels = headerObj.header['NCHANNELS']
416 self.nHeights = headerObj.header['NHEIGHTS']
415 self.nHeights = headerObj.header['NHEIGHTS']
417 self.ippSeconds = headerObj.header['IPPSECONDS']
416 self.ippSeconds = headerObj.header['IPPSECONDS']
418 self.nCohInt = headerObj.header['NCOHINT']
417 self.nCohInt = headerObj.header['NCOHINT']
419 self.nIncohInt = headerObj.header['NINCOHINT']
418 self.nIncohInt = headerObj.header['NINCOHINT']
420 self.dataBlocksPerFile = headerObj.header['NBLOCK']
419 self.dataBlocksPerFile = headerObj.header['NBLOCK']
421 self.timeZone = headerObj.header['TIMEZONE']
420 self.timeZone = headerObj.header['TIMEZONE']
422
421
423 # self.timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
422 # self.timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
424
423
425 if 'COMMENT' in headerObj.header.keys():
424 if 'COMMENT' in headerObj.header.keys():
426 self.comments = headerObj.header['COMMENT']
425 self.comments = headerObj.header['COMMENT']
427
426
428 self.readHeightList()
427 self.readHeightList()
429
428
430 def readHeightList(self):
429 def readHeightList(self):
431 self.blockIndex = self.blockIndex + 1
430 self.blockIndex = self.blockIndex + 1
432 obj = self.fitsObj[self.blockIndex]
431 obj = self.fitsObj[self.blockIndex]
433 self.heightList = obj.data
432 self.heightList = obj.data
434 self.blockIndex = self.blockIndex + 1
433 self.blockIndex = self.blockIndex + 1
435
434
436 def readExtension(self):
435 def readExtension(self):
437 obj = self.fitsObj[self.blockIndex]
436 obj = self.fitsObj[self.blockIndex]
438 self.heightList = obj.data
437 self.heightList = obj.data
439 self.blockIndex = self.blockIndex + 1
438 self.blockIndex = self.blockIndex + 1
440
439
441 def setNextFile(self):
440 def setNextFile(self):
442
441
443 if self.online:
442 if self.online:
444 newFile = self.__setNextFileOnline()
443 newFile = self.__setNextFileOnline()
445 else:
444 else:
446 newFile = self.__setNextFileOffline()
445 newFile = self.__setNextFileOffline()
447
446
448 if not(newFile):
447 if not(newFile):
449 return 0
448 return 0
450
449
451 self.readHeader()
450 self.readHeader()
452 self.__setValuesFromHeader()
451 self.__setValuesFromHeader()
453 self.nReadBlocks = 0
452 self.nReadBlocks = 0
454 # self.blockIndex = 1
453 # self.blockIndex = 1
455 return 1
454 return 1
456
455
457 def __searchFilesOffLine(self,
456 def __searchFilesOffLine(self,
458 path,
457 path,
459 startDate,
458 startDate,
460 endDate,
459 endDate,
461 startTime=datetime.time(0,0,0),
460 startTime=datetime.time(0,0,0),
462 endTime=datetime.time(23,59,59),
461 endTime=datetime.time(23,59,59),
463 set=None,
462 set=None,
464 expLabel='',
463 expLabel='',
465 ext='.fits',
464 ext='.fits',
466 walk=True):
465 walk=True):
467
466
468 pathList = []
467 pathList = []
469
468
470 if not walk:
469 if not walk:
471 pathList.append(path)
470 pathList.append(path)
472
471
473 else:
472 else:
474 dirList = []
473 dirList = []
475 for thisPath in os.listdir(path):
474 for thisPath in os.listdir(path):
476 if not os.path.isdir(os.path.join(path,thisPath)):
475 if not os.path.isdir(os.path.join(path,thisPath)):
477 continue
476 continue
478 if not isRadarFolder(thisPath):
477 if not isRadarFolder(thisPath):
479 continue
478 continue
480
479
481 dirList.append(thisPath)
480 dirList.append(thisPath)
482
481
483 if not(dirList):
482 if not(dirList):
484 return None, None
483 return None, None
485
484
486 thisDate = startDate
485 thisDate = startDate
487
486
488 while(thisDate <= endDate):
487 while(thisDate <= endDate):
489 year = thisDate.timetuple().tm_year
488 year = thisDate.timetuple().tm_year
490 doy = thisDate.timetuple().tm_yday
489 doy = thisDate.timetuple().tm_yday
491
490
492 matchlist = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy) + '*')
491 matchlist = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy) + '*')
493 if len(matchlist) == 0:
492 if len(matchlist) == 0:
494 thisDate += datetime.timedelta(1)
493 thisDate += datetime.timedelta(1)
495 continue
494 continue
496 for match in matchlist:
495 for match in matchlist:
497 pathList.append(os.path.join(path,match,expLabel))
496 pathList.append(os.path.join(path,match,expLabel))
498
497
499 thisDate += datetime.timedelta(1)
498 thisDate += datetime.timedelta(1)
500
499
501 if pathList == []:
500 if pathList == []:
502 print "Any folder was found for the date range: %s-%s" %(startDate, endDate)
501 print "Any folder was found for the date range: %s-%s" %(startDate, endDate)
503 return None, None
502 return None, None
504
503
505 print "%d folder(s) was(were) found for the date range: %s - %s" %(len(pathList), startDate, endDate)
504 print "%d folder(s) was(were) found for the date range: %s - %s" %(len(pathList), startDate, endDate)
506
505
507 filenameList = []
506 filenameList = []
508 datetimeList = []
507 datetimeList = []
509
508
510 for i in range(len(pathList)):
509 for i in range(len(pathList)):
511
510
512 thisPath = pathList[i]
511 thisPath = pathList[i]
513
512
514 fileList = glob.glob1(thisPath, "*%s" %ext)
513 fileList = glob.glob1(thisPath, "*%s" %ext)
515 fileList.sort()
514 fileList.sort()
516
515
517 for thisFile in fileList:
516 for thisFile in fileList:
518
517
519 filename = os.path.join(thisPath,thisFile)
518 filename = os.path.join(thisPath,thisFile)
520 thisDatetime = self.isFileinThisTime(filename, startTime, endTime)
519 thisDatetime = self.isFileinThisTime(filename, startTime, endTime)
521
520
522 if not(thisDatetime):
521 if not(thisDatetime):
523 continue
522 continue
524
523
525 filenameList.append(filename)
524 filenameList.append(filename)
526 datetimeList.append(thisDatetime)
525 datetimeList.append(thisDatetime)
527
526
528 if not(filenameList):
527 if not(filenameList):
529 print "Any file was found for the time range %s - %s" %(startTime, endTime)
528 print "Any file was found for the time range %s - %s" %(startTime, endTime)
530 return None, None
529 return None, None
531
530
532 print "%d file(s) was(were) found for the time range: %s - %s" %(len(filenameList), startTime, endTime)
531 print "%d file(s) was(were) found for the time range: %s - %s" %(len(filenameList), startTime, endTime)
533 print
532 print
534
533
535 for i in range(len(filenameList)):
534 for i in range(len(filenameList)):
536 print "%s -> [%s]" %(filenameList[i], datetimeList[i].ctime())
535 print "%s -> [%s]" %(filenameList[i], datetimeList[i].ctime())
537
536
538 self.filenameList = filenameList
537 self.filenameList = filenameList
539 self.datetimeList = datetimeList
538 self.datetimeList = datetimeList
540
539
541 return pathList, filenameList
540 return pathList, filenameList
542
541
543 def setup(self, path=None,
542 def setup(self, path=None,
544 startDate=None,
543 startDate=None,
545 endDate=None,
544 endDate=None,
546 startTime=datetime.time(0,0,0),
545 startTime=datetime.time(0,0,0),
547 endTime=datetime.time(23,59,59),
546 endTime=datetime.time(23,59,59),
548 set=0,
547 set=0,
549 expLabel = "",
548 expLabel = "",
550 ext = None,
549 ext = None,
551 online = False,
550 online = False,
552 delay = 60,
551 delay = 60,
553 walk = True):
552 walk = True):
554
553
555 if path == None:
554 if path == None:
556 raise ValueError, "The path is not valid"
555 raise ValueError, "The path is not valid"
557
556
558 if ext == None:
557 if ext == None:
559 ext = self.ext
558 ext = self.ext
560
559
561 if not(online):
560 if not(online):
562 print "Searching files in offline mode ..."
561 print "Searching files in offline mode ..."
563 pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate,
562 pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate,
564 startTime=startTime, endTime=endTime,
563 startTime=startTime, endTime=endTime,
565 set=set, expLabel=expLabel, ext=ext,
564 set=set, expLabel=expLabel, ext=ext,
566 walk=walk)
565 walk=walk)
567
566
568 if not(pathList):
567 if not(pathList):
569 print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path,
568 print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path,
570 datetime.datetime.combine(startDate,startTime).ctime(),
569 datetime.datetime.combine(startDate,startTime).ctime(),
571 datetime.datetime.combine(endDate,endTime).ctime())
570 datetime.datetime.combine(endDate,endTime).ctime())
572
571
573 sys.exit(-1)
572 sys.exit(-1)
574
573
575 self.fileIndex = -1
574 self.fileIndex = -1
576 self.pathList = pathList
575 self.pathList = pathList
577 self.filenameList = filenameList
576 self.filenameList = filenameList
578
577
579 self.online = online
578 self.online = online
580 self.delay = delay
579 self.delay = delay
581 ext = ext.lower()
580 ext = ext.lower()
582 self.ext = ext
581 self.ext = ext
583
582
584 if not(self.setNextFile()):
583 if not(self.setNextFile()):
585 if (startDate!=None) and (endDate!=None):
584 if (startDate!=None) and (endDate!=None):
586 print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())
585 print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())
587 elif startDate != None:
586 elif startDate != None:
588 print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime())
587 print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime())
589 else:
588 else:
590 print "No files"
589 print "No files"
591
590
592 sys.exit(-1)
591 sys.exit(-1)
593
592
594
593
595
594
596 def readBlock(self):
595 def readBlock(self):
597 dataObj = self.fitsObj[self.blockIndex]
596 dataObj = self.fitsObj[self.blockIndex]
598
597
599 self.data = dataObj.data
598 self.data = dataObj.data
600 self.data_header_dict = dataObj.header
599 self.data_header_dict = dataObj.header
601 self.utc = self.data_header_dict['UTCTIME']
600 self.utc = self.data_header_dict['UTCTIME']
602
601
603 self.flagIsNewFile = 0
602 self.flagIsNewFile = 0
604 self.blockIndex += 1
603 self.blockIndex += 1
605 self.nTotalBlocks += 1
604 self.nTotalBlocks += 1
606 self.nReadBlocks += 1
605 self.nReadBlocks += 1
607
606
608 return 1
607 return 1
609
608
610 def __jumpToLastBlock(self):
609 def __jumpToLastBlock(self):
611 raise NotImplementedError
610 raise NotImplementedError
612
611
613 def __waitNewBlock(self):
612 def __waitNewBlock(self):
614 """
613 """
615 Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma.
614 Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma.
616
615
617 Si el modo de lectura es OffLine siempre retorn 0
616 Si el modo de lectura es OffLine siempre retorn 0
618 """
617 """
619 if not self.online:
618 if not self.online:
620 return 0
619 return 0
621
620
622 if (self.nReadBlocks >= self.dataBlocksPerFile):
621 if (self.nReadBlocks >= self.dataBlocksPerFile):
623 return 0
622 return 0
624
623
625 currentPointer = self.fp.tell()
624 currentPointer = self.fp.tell()
626
625
627 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
626 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
628
627
629 for nTries in range( self.nTries ):
628 for nTries in range( self.nTries ):
630
629
631 self.fp.close()
630 self.fp.close()
632 self.fp = open( self.filename, 'rb' )
631 self.fp = open( self.filename, 'rb' )
633 self.fp.seek( currentPointer )
632 self.fp.seek( currentPointer )
634
633
635 self.fileSize = os.path.getsize( self.filename )
634 self.fileSize = os.path.getsize( self.filename )
636 currentSize = self.fileSize - currentPointer
635 currentSize = self.fileSize - currentPointer
637
636
638 if ( currentSize >= neededSize ):
637 if ( currentSize >= neededSize ):
639 self.__rdBasicHeader()
638 self.__rdBasicHeader()
640 return 1
639 return 1
641
640
642 print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1)
641 print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1)
643 sleep( self.delay )
642 sleep( self.delay )
644
643
645
644
646 return 0
645 return 0
647
646
648 def __setNewBlock(self):
647 def __setNewBlock(self):
649
648
650 if self.online:
649 if self.online:
651 self.__jumpToLastBlock()
650 self.__jumpToLastBlock()
652
651
653 if self.flagIsNewFile:
652 if self.flagIsNewFile:
654 return 1
653 return 1
655
654
656 self.lastUTTime = self.utc
655 self.lastUTTime = self.utc
657
656
658 if self.online:
657 if self.online:
659 if self.__waitNewBlock():
658 if self.__waitNewBlock():
660 return 1
659 return 1
661
660
662 if self.nReadBlocks < self.dataBlocksPerFile:
661 if self.nReadBlocks < self.dataBlocksPerFile:
663 return 1
662 return 1
664
663
665 if not(self.setNextFile()):
664 if not(self.setNextFile()):
666 return 0
665 return 0
667
666
668 deltaTime = self.utc - self.lastUTTime
667 deltaTime = self.utc - self.lastUTTime
669
668
670 self.flagDiscontinuousBlock = 0
669 self.flagDiscontinuousBlock = 0
671
670
672 if deltaTime > self.maxTimeStep:
671 if deltaTime > self.maxTimeStep:
673 self.flagDiscontinuousBlock = 1
672 self.flagDiscontinuousBlock = 1
674
673
675 return 1
674 return 1
676
675
677
676
678 def readNextBlock(self):
677 def readNextBlock(self):
679 if not(self.__setNewBlock()):
678 if not(self.__setNewBlock()):
680 return 0
679 return 0
681
680
682 if not(self.readBlock()):
681 if not(self.readBlock()):
683 return 0
682 return 0
684
683
685 return 1
684 return 1
686
685
687 def printInfo(self):
686 def printInfo(self):
688
687
689 pass
688 pass
690
689
691 def getData(self):
690 def getData(self):
692
691
693 if self.flagNoMoreFiles:
692 if self.flagNoMoreFiles:
694 self.dataOut.flagNoData = True
693 self.dataOut.flagNoData = True
695 print 'Process finished'
694 print 'Process finished'
696 return 0
695 return 0
697
696
698 self.flagDiscontinuousBlock = 0
697 self.flagDiscontinuousBlock = 0
699 self.flagIsNewBlock = 0
698 self.flagIsNewBlock = 0
700
699
701 if not(self.readNextBlock()):
700 if not(self.readNextBlock()):
702 return 0
701 return 0
703
702
704 if self.data is None:
703 if self.data is None:
705 self.dataOut.flagNoData = True
704 self.dataOut.flagNoData = True
706 return 0
705 return 0
707
706
708 self.dataOut.data = self.data
707 self.dataOut.data = self.data
709 self.dataOut.data_header = self.data_header_dict
708 self.dataOut.data_header = self.data_header_dict
710 self.dataOut.utctime = self.utc
709 self.dataOut.utctime = self.utc
711
710
712 # self.dataOut.header = self.header_dict
711 # self.dataOut.header = self.header_dict
713 # self.dataOut.expName = self.expName
712 # self.dataOut.expName = self.expName
714 # self.dataOut.nChannels = self.nChannels
713 # self.dataOut.nChannels = self.nChannels
715 # self.dataOut.timeZone = self.timeZone
714 # self.dataOut.timeZone = self.timeZone
716 # self.dataOut.dataBlocksPerFile = self.dataBlocksPerFile
715 # self.dataOut.dataBlocksPerFile = self.dataBlocksPerFile
717 # self.dataOut.comments = self.comments
716 # self.dataOut.comments = self.comments
718 # # self.dataOut.timeInterval = self.timeInterval
717 # # self.dataOut.timeInterval = self.timeInterval
719 # self.dataOut.channelList = self.channelList
718 # self.dataOut.channelList = self.channelList
720 # self.dataOut.heightList = self.heightList
719 # self.dataOut.heightList = self.heightList
721 self.dataOut.flagNoData = False
720 self.dataOut.flagNoData = False
722
721
723 return self.dataOut.data
722 return self.dataOut.data
724
723
725 def run(self, **kwargs):
724 def run(self, **kwargs):
726
725
727 if not(self.isConfig):
726 if not(self.isConfig):
728 self.setup(**kwargs)
727 self.setup(**kwargs)
729 self.isConfig = True
728 self.isConfig = True
730
729
731 self.getData()
730 self.getData()
732
731
733 class SpectraHeisWriter(Operation):
732 class SpectraHeisWriter(Operation):
734 # set = None
733 # set = None
735 setFile = None
734 setFile = None
736 idblock = None
735 idblock = None
737 doypath = None
736 doypath = None
738 subfolder = None
737 subfolder = None
739
738
740 def __init__(self, **kwargs):
739 def __init__(self, **kwargs):
741 Operation.__init__(self, **kwargs)
740 Operation.__init__(self, **kwargs)
742 self.wrObj = PyFits()
741 self.wrObj = PyFits()
743 # self.dataOut = dataOut
742 # self.dataOut = dataOut
744 self.nTotalBlocks=0
743 self.nTotalBlocks=0
745 # self.set = None
744 # self.set = None
746 self.setFile = None
745 self.setFile = None
747 self.idblock = 0
746 self.idblock = 0
748 self.wrpath = None
747 self.wrpath = None
749 self.doypath = None
748 self.doypath = None
750 self.subfolder = None
749 self.subfolder = None
751 self.isConfig = False
750 self.isConfig = False
752
751
753 def isNumber(str):
752 def isNumber(str):
754 """
753 """
755 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
754 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
756
755
757 Excepciones:
756 Excepciones:
758 Si un determinado string no puede ser convertido a numero
757 Si un determinado string no puede ser convertido a numero
759 Input:
758 Input:
760 str, string al cual se le analiza para determinar si convertible a un numero o no
759 str, string al cual se le analiza para determinar si convertible a un numero o no
761
760
762 Return:
761 Return:
763 True : si el string es uno numerico
762 True : si el string es uno numerico
764 False : no es un string numerico
763 False : no es un string numerico
765 """
764 """
766 try:
765 try:
767 float( str )
766 float( str )
768 return True
767 return True
769 except:
768 except:
770 return False
769 return False
771
770
772 def setup(self, dataOut, wrpath):
771 def setup(self, dataOut, wrpath):
773
772
774 if not(os.path.exists(wrpath)):
773 if not(os.path.exists(wrpath)):
775 os.mkdir(wrpath)
774 os.mkdir(wrpath)
776
775
777 self.wrpath = wrpath
776 self.wrpath = wrpath
778 # self.setFile = 0
777 # self.setFile = 0
779 self.dataOut = dataOut
778 self.dataOut = dataOut
780
779
781 def putData(self):
780 def putData(self):
782 name= time.localtime( self.dataOut.utctime)
781 name= time.localtime( self.dataOut.utctime)
783 ext=".fits"
782 ext=".fits"
784
783
785 if self.doypath == None:
784 if self.doypath == None:
786 self.subfolder = 'F%4.4d%3.3d_%d' % (name.tm_year,name.tm_yday,time.mktime(datetime.datetime.now().timetuple()))
785 self.subfolder = 'F%4.4d%3.3d_%d' % (name.tm_year,name.tm_yday,time.mktime(datetime.datetime.now().timetuple()))
787 self.doypath = os.path.join( self.wrpath, self.subfolder )
786 self.doypath = os.path.join( self.wrpath, self.subfolder )
788 os.mkdir(self.doypath)
787 os.mkdir(self.doypath)
789
788
790 if self.setFile == None:
789 if self.setFile == None:
791 # self.set = self.dataOut.set
790 # self.set = self.dataOut.set
792 self.setFile = 0
791 self.setFile = 0
793 # if self.set != self.dataOut.set:
792 # if self.set != self.dataOut.set:
794 ## self.set = self.dataOut.set
793 ## self.set = self.dataOut.set
795 # self.setFile = 0
794 # self.setFile = 0
796
795
797 #make the filename
796 #make the filename
798 thisFile = 'D%4.4d%3.3d_%3.3d%s' % (name.tm_year,name.tm_yday,self.setFile,ext)
797 thisFile = 'D%4.4d%3.3d_%3.3d%s' % (name.tm_year,name.tm_yday,self.setFile,ext)
799
798
800 filename = os.path.join(self.wrpath,self.subfolder, thisFile)
799 filename = os.path.join(self.wrpath,self.subfolder, thisFile)
801
800
802 idblock = numpy.array([self.idblock],dtype="int64")
801 idblock = numpy.array([self.idblock],dtype="int64")
803 header=self.wrObj.cFImage(idblock=idblock,
802 header=self.wrObj.cFImage(idblock=idblock,
804 year=time.gmtime(self.dataOut.utctime).tm_year,
803 year=time.gmtime(self.dataOut.utctime).tm_year,
805 month=time.gmtime(self.dataOut.utctime).tm_mon,
804 month=time.gmtime(self.dataOut.utctime).tm_mon,
806 day=time.gmtime(self.dataOut.utctime).tm_mday,
805 day=time.gmtime(self.dataOut.utctime).tm_mday,
807 hour=time.gmtime(self.dataOut.utctime).tm_hour,
806 hour=time.gmtime(self.dataOut.utctime).tm_hour,
808 minute=time.gmtime(self.dataOut.utctime).tm_min,
807 minute=time.gmtime(self.dataOut.utctime).tm_min,
809 second=time.gmtime(self.dataOut.utctime).tm_sec)
808 second=time.gmtime(self.dataOut.utctime).tm_sec)
810
809
811 c=3E8
810 c=3E8
812 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
811 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
813 freq=numpy.arange(-1*self.dataOut.nHeights/2.,self.dataOut.nHeights/2.)*(c/(2*deltaHeight*1000))
812 freq=numpy.arange(-1*self.dataOut.nHeights/2.,self.dataOut.nHeights/2.)*(c/(2*deltaHeight*1000))
814
813
815 colList = []
814 colList = []
816
815
817 colFreq=self.wrObj.setColF(name="freq", format=str(self.dataOut.nFFTPoints)+'E', array=freq)
816 colFreq=self.wrObj.setColF(name="freq", format=str(self.dataOut.nFFTPoints)+'E', array=freq)
818
817
819 colList.append(colFreq)
818 colList.append(colFreq)
820
819
821 nchannel=self.dataOut.nChannels
820 nchannel=self.dataOut.nChannels
822
821
823 for i in range(nchannel):
822 for i in range(nchannel):
824 col = self.wrObj.writeData(name="PCh"+str(i+1),
823 col = self.wrObj.writeData(name="PCh"+str(i+1),
825 format=str(self.dataOut.nFFTPoints)+'E',
824 format=str(self.dataOut.nFFTPoints)+'E',
826 data=10*numpy.log10(self.dataOut.data_spc[i,:]))
825 data=10*numpy.log10(self.dataOut.data_spc[i,:]))
827
826
828 colList.append(col)
827 colList.append(col)
829
828
830 data=self.wrObj.Ctable(colList=colList)
829 data=self.wrObj.Ctable(colList=colList)
831
830
832 self.wrObj.CFile(header,data)
831 self.wrObj.CFile(header,data)
833
832
834 self.wrObj.wFile(filename)
833 self.wrObj.wFile(filename)
835
834
836 #update the setFile
835 #update the setFile
837 self.setFile += 1
836 self.setFile += 1
838 self.idblock += 1
837 self.idblock += 1
839
838
840 return 1
839 return 1
841
840
842 def run(self, dataOut, **kwargs):
841 def run(self, dataOut, **kwargs):
843
842
844 if not(self.isConfig):
843 if not(self.isConfig):
845
844
846 self.setup(dataOut, **kwargs)
845 self.setup(dataOut, **kwargs)
847 self.isConfig = True
846 self.isConfig = True
848
847
849 self.putData()
848 self.putData()
@@ -1,1090 +1,1095
1 import numpy
1 import numpy
2 import time
2 import time
3 import os
3 import os
4 import h5py
4 import h5py
5 import re
5 import re
6 import datetime
6 import datetime
7
7
8 from schainpy.model.data.jrodata import *
8 from schainpy.model.data.jrodata import *
9 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
9 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
10 # from jroIO_base import *
10 # from jroIO_base import *
11 from schainpy.model.io.jroIO_base import *
11 from schainpy.model.io.jroIO_base import *
12 import schainpy
12 import schainpy
13
13
14
14
15 class ParamReader(ProcessingUnit):
15 class ParamReader(ProcessingUnit):
16 '''
16 '''
17 Reads HDF5 format files
17 Reads HDF5 format files
18
18
19 path
19 path
20
20
21 startDate
21 startDate
22
22
23 endDate
23 endDate
24
24
25 startTime
25 startTime
26
26
27 endTime
27 endTime
28 '''
28 '''
29
29
30 ext = ".hdf5"
30 ext = ".hdf5"
31
31
32 optchar = "D"
32 optchar = "D"
33
33
34 timezone = None
34 timezone = None
35
35
36 startTime = None
36 startTime = None
37
37
38 endTime = None
38 endTime = None
39
39
40 fileIndex = None
40 fileIndex = None
41
41
42 utcList = None #To select data in the utctime list
42 utcList = None #To select data in the utctime list
43
43
44 blockList = None #List to blocks to be read from the file
44 blockList = None #List to blocks to be read from the file
45
45
46 blocksPerFile = None #Number of blocks to be read
46 blocksPerFile = None #Number of blocks to be read
47
47
48 blockIndex = None
48 blockIndex = None
49
49
50 path = None
50 path = None
51
51
52 #List of Files
52 #List of Files
53
53
54 filenameList = None
54 filenameList = None
55
55
56 datetimeList = None
56 datetimeList = None
57
57
58 #Hdf5 File
58 #Hdf5 File
59
59
60 listMetaname = None
60 listMetaname = None
61
61
62 listMeta = None
62 listMeta = None
63
63
64 listDataname = None
64 listDataname = None
65
65
66 listData = None
66 listData = None
67
67
68 listShapes = None
68 listShapes = None
69
69
70 fp = None
70 fp = None
71
71
72 #dataOut reconstruction
72 #dataOut reconstruction
73
73
74 dataOut = None
74 dataOut = None
75
75
76
76
77 def __init__(self, **kwargs):
77 def __init__(self, **kwargs):
78 ProcessingUnit.__init__(self, **kwargs)
78 ProcessingUnit.__init__(self, **kwargs)
79 self.dataOut = Parameters()
79 self.dataOut = Parameters()
80 return
80 return
81
81
82 def setup(self, **kwargs):
82 def setup(self, **kwargs):
83
83
84 path = kwargs['path']
84 path = kwargs['path']
85 startDate = kwargs['startDate']
85 startDate = kwargs['startDate']
86 endDate = kwargs['endDate']
86 endDate = kwargs['endDate']
87 startTime = kwargs['startTime']
87 startTime = kwargs['startTime']
88 endTime = kwargs['endTime']
88 endTime = kwargs['endTime']
89 walk = kwargs['walk']
89 walk = kwargs['walk']
90 if kwargs.has_key('ext'):
90 if kwargs.has_key('ext'):
91 ext = kwargs['ext']
91 ext = kwargs['ext']
92 else:
92 else:
93 ext = '.hdf5'
93 ext = '.hdf5'
94 if kwargs.has_key('timezone'):
94 if kwargs.has_key('timezone'):
95 self.timezone = kwargs['timezone']
95 self.timezone = kwargs['timezone']
96 else:
96 else:
97 self.timezone = 'lt'
97 self.timezone = 'lt'
98
98
99 print "[Reading] Searching files in offline mode ..."
99 print "[Reading] Searching files in offline mode ..."
100 pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate,
100 pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate,
101 startTime=startTime, endTime=endTime,
101 startTime=startTime, endTime=endTime,
102 ext=ext, walk=walk)
102 ext=ext, walk=walk)
103
103
104 if not(filenameList):
104 if not(filenameList):
105 print "There is no files into the folder: %s"%(path)
105 print "There is no files into the folder: %s"%(path)
106 sys.exit(-1)
106 sys.exit(-1)
107
107
108 self.fileIndex = -1
108 self.fileIndex = -1
109 self.startTime = startTime
109 self.startTime = startTime
110 self.endTime = endTime
110 self.endTime = endTime
111
111
112 self.__readMetadata()
112 self.__readMetadata()
113
113
114 self.__setNextFileOffline()
114 self.__setNextFileOffline()
115
115
116 return
116 return
117
117
118 def __searchFilesOffLine(self,
118 def __searchFilesOffLine(self,
119 path,
119 path,
120 startDate=None,
120 startDate=None,
121 endDate=None,
121 endDate=None,
122 startTime=datetime.time(0,0,0),
122 startTime=datetime.time(0,0,0),
123 endTime=datetime.time(23,59,59),
123 endTime=datetime.time(23,59,59),
124 ext='.hdf5',
124 ext='.hdf5',
125 walk=True):
125 walk=True):
126
126
127 expLabel = ''
127 expLabel = ''
128 self.filenameList = []
128 self.filenameList = []
129 self.datetimeList = []
129 self.datetimeList = []
130
130
131 pathList = []
131 pathList = []
132
132
133 JRODataObj = JRODataReader()
133 JRODataObj = JRODataReader()
134 dateList, pathList = JRODataObj.findDatafiles(path, startDate, endDate, expLabel, ext, walk, include_path=True)
134 dateList, pathList = JRODataObj.findDatafiles(path, startDate, endDate, expLabel, ext, walk, include_path=True)
135
135
136 if dateList == []:
136 if dateList == []:
137 print "[Reading] No *%s files in %s from %s to %s)"%(ext, path,
137 print "[Reading] No *%s files in %s from %s to %s)"%(ext, path,
138 datetime.datetime.combine(startDate,startTime).ctime(),
138 datetime.datetime.combine(startDate,startTime).ctime(),
139 datetime.datetime.combine(endDate,endTime).ctime())
139 datetime.datetime.combine(endDate,endTime).ctime())
140
140
141 return None, None
141 return None, None
142
142
143 if len(dateList) > 1:
143 if len(dateList) > 1:
144 print "[Reading] %d days were found in date range: %s - %s" %(len(dateList), startDate, endDate)
144 print "[Reading] %d days were found in date range: %s - %s" %(len(dateList), startDate, endDate)
145 else:
145 else:
146 print "[Reading] data was found for the date %s" %(dateList[0])
146 print "[Reading] data was found for the date %s" %(dateList[0])
147
147
148 filenameList = []
148 filenameList = []
149 datetimeList = []
149 datetimeList = []
150
150
151 #----------------------------------------------------------------------------------
151 #----------------------------------------------------------------------------------
152
152
153 for thisPath in pathList:
153 for thisPath in pathList:
154 # thisPath = pathList[pathDict[file]]
154 # thisPath = pathList[pathDict[file]]
155
155
156 fileList = glob.glob1(thisPath, "*%s" %ext)
156 fileList = glob.glob1(thisPath, "*%s" %ext)
157 fileList.sort()
157 fileList.sort()
158
158
159 for file in fileList:
159 for file in fileList:
160
160
161 filename = os.path.join(thisPath,file)
161 filename = os.path.join(thisPath,file)
162
162
163 if not isFileInDateRange(filename, startDate, endDate):
163 if not isFileInDateRange(filename, startDate, endDate):
164 continue
164 continue
165
165
166 thisDatetime = self.__isFileInTimeRange(filename, startDate, endDate, startTime, endTime)
166 thisDatetime = self.__isFileInTimeRange(filename, startDate, endDate, startTime, endTime)
167
167
168 if not(thisDatetime):
168 if not(thisDatetime):
169 continue
169 continue
170
170
171 filenameList.append(filename)
171 filenameList.append(filename)
172 datetimeList.append(thisDatetime)
172 datetimeList.append(thisDatetime)
173
173
174 if not(filenameList):
174 if not(filenameList):
175 print "[Reading] Any file was found int time range %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())
175 print "[Reading] Any file was found int time range %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())
176 return None, None
176 return None, None
177
177
178 print "[Reading] %d file(s) was(were) found in time range: %s - %s" %(len(filenameList), startTime, endTime)
178 print "[Reading] %d file(s) was(were) found in time range: %s - %s" %(len(filenameList), startTime, endTime)
179 print
179 print
180
180
181 for i in range(len(filenameList)):
181 for i in range(len(filenameList)):
182 print "[Reading] %s -> [%s]" %(filenameList[i], datetimeList[i].ctime())
182 print "[Reading] %s -> [%s]" %(filenameList[i], datetimeList[i].ctime())
183
183
184 self.filenameList = filenameList
184 self.filenameList = filenameList
185 self.datetimeList = datetimeList
185 self.datetimeList = datetimeList
186
186
187 return pathList, filenameList
187 return pathList, filenameList
188
188
189 def __isFileInTimeRange(self,filename, startDate, endDate, startTime, endTime):
189 def __isFileInTimeRange(self,filename, startDate, endDate, startTime, endTime):
190
190
191 """
191 """
192 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
192 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
193
193
194 Inputs:
194 Inputs:
195 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
195 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
196
196
197 startDate : fecha inicial del rango seleccionado en formato datetime.date
197 startDate : fecha inicial del rango seleccionado en formato datetime.date
198
198
199 endDate : fecha final del rango seleccionado en formato datetime.date
199 endDate : fecha final del rango seleccionado en formato datetime.date
200
200
201 startTime : tiempo inicial del rango seleccionado en formato datetime.time
201 startTime : tiempo inicial del rango seleccionado en formato datetime.time
202
202
203 endTime : tiempo final del rango seleccionado en formato datetime.time
203 endTime : tiempo final del rango seleccionado en formato datetime.time
204
204
205 Return:
205 Return:
206 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
206 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
207 fecha especificado, de lo contrario retorna False.
207 fecha especificado, de lo contrario retorna False.
208
208
209 Excepciones:
209 Excepciones:
210 Si el archivo no existe o no puede ser abierto
210 Si el archivo no existe o no puede ser abierto
211 Si la cabecera no puede ser leida.
211 Si la cabecera no puede ser leida.
212
212
213 """
213 """
214
214
215 try:
215 try:
216 fp = h5py.File(filename,'r')
216 fp = h5py.File(filename,'r')
217 grp1 = fp['Data']
217 grp1 = fp['Data']
218
218
219 except IOError:
219 except IOError:
220 traceback.print_exc()
220 traceback.print_exc()
221 raise IOError, "The file %s can't be opened" %(filename)
221 raise IOError, "The file %s can't be opened" %(filename)
222 #chino rata
222 #chino rata
223 #In case has utctime attribute
223 #In case has utctime attribute
224 grp2 = grp1['utctime']
224 grp2 = grp1['utctime']
225 # thisUtcTime = grp2.value[0] - 5*3600 #To convert to local time
225 # thisUtcTime = grp2.value[0] - 5*3600 #To convert to local time
226 thisUtcTime = grp2.value[0]
226 thisUtcTime = grp2.value[0]
227
227
228 fp.close()
228 fp.close()
229
229
230 if self.timezone == 'lt':
230 if self.timezone == 'lt':
231 thisUtcTime -= 5*3600
231 thisUtcTime -= 5*3600
232
232
233 thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0] + 5*3600)
233 thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0] + 5*3600)
234 # thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0])
234 # thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0])
235 thisDate = thisDatetime.date()
235 thisDate = thisDatetime.date()
236 thisTime = thisDatetime.time()
236 thisTime = thisDatetime.time()
237
237
238 startUtcTime = (datetime.datetime.combine(thisDate,startTime)- datetime.datetime(1970, 1, 1)).total_seconds()
238 startUtcTime = (datetime.datetime.combine(thisDate,startTime)- datetime.datetime(1970, 1, 1)).total_seconds()
239 endUtcTime = (datetime.datetime.combine(thisDate,endTime)- datetime.datetime(1970, 1, 1)).total_seconds()
239 endUtcTime = (datetime.datetime.combine(thisDate,endTime)- datetime.datetime(1970, 1, 1)).total_seconds()
240
240
241 #General case
241 #General case
242 # o>>>>>>>>>>>>>><<<<<<<<<<<<<<o
242 # o>>>>>>>>>>>>>><<<<<<<<<<<<<<o
243 #-----------o----------------------------o-----------
243 #-----------o----------------------------o-----------
244 # startTime endTime
244 # startTime endTime
245
245
246 if endTime >= startTime:
246 if endTime >= startTime:
247 thisUtcLog = numpy.logical_and(thisUtcTime > startUtcTime, thisUtcTime < endUtcTime)
247 thisUtcLog = numpy.logical_and(thisUtcTime > startUtcTime, thisUtcTime < endUtcTime)
248 if numpy.any(thisUtcLog): #If there is one block between the hours mentioned
248 if numpy.any(thisUtcLog): #If there is one block between the hours mentioned
249 return thisDatetime
249 return thisDatetime
250 return None
250 return None
251
251
252 #If endTime < startTime then endTime belongs to the next day
252 #If endTime < startTime then endTime belongs to the next day
253 #<<<<<<<<<<<o o>>>>>>>>>>>
253 #<<<<<<<<<<<o o>>>>>>>>>>>
254 #-----------o----------------------------o-----------
254 #-----------o----------------------------o-----------
255 # endTime startTime
255 # endTime startTime
256
256
257 if (thisDate == startDate) and numpy.all(thisUtcTime < startUtcTime):
257 if (thisDate == startDate) and numpy.all(thisUtcTime < startUtcTime):
258 return None
258 return None
259
259
260 if (thisDate == endDate) and numpy.all(thisUtcTime > endUtcTime):
260 if (thisDate == endDate) and numpy.all(thisUtcTime > endUtcTime):
261 return None
261 return None
262
262
263 if numpy.all(thisUtcTime < startUtcTime) and numpy.all(thisUtcTime > endUtcTime):
263 if numpy.all(thisUtcTime < startUtcTime) and numpy.all(thisUtcTime > endUtcTime):
264 return None
264 return None
265
265
266 return thisDatetime
266 return thisDatetime
267
267
268 def __setNextFileOffline(self):
268 def __setNextFileOffline(self):
269
269
270 self.fileIndex += 1
270 self.fileIndex += 1
271 idFile = self.fileIndex
271 idFile = self.fileIndex
272
272
273 if not(idFile < len(self.filenameList)):
273 if not(idFile < len(self.filenameList)):
274 print "No more Files"
274 print "No more Files"
275 return 0
275 return 0
276
276
277 filename = self.filenameList[idFile]
277 filename = self.filenameList[idFile]
278
278
279 filePointer = h5py.File(filename,'r')
279 filePointer = h5py.File(filename,'r')
280
280
281 self.filename = filename
281 self.filename = filename
282
282
283 self.fp = filePointer
283 self.fp = filePointer
284
284
285 print "Setting the file: %s"%self.filename
285 print "Setting the file: %s"%self.filename
286
286
287 # self.__readMetadata()
287 # self.__readMetadata()
288 self.__setBlockList()
288 self.__setBlockList()
289 self.__readData()
289 self.__readData()
290 # self.nRecords = self.fp['Data'].attrs['blocksPerFile']
290 # self.nRecords = self.fp['Data'].attrs['blocksPerFile']
291 # self.nRecords = self.fp['Data'].attrs['nRecords']
291 # self.nRecords = self.fp['Data'].attrs['nRecords']
292 self.blockIndex = 0
292 self.blockIndex = 0
293 return 1
293 return 1
294
294
295 def __setBlockList(self):
295 def __setBlockList(self):
296 '''
296 '''
297 Selects the data within the times defined
297 Selects the data within the times defined
298
298
299 self.fp
299 self.fp
300 self.startTime
300 self.startTime
301 self.endTime
301 self.endTime
302
302
303 self.blockList
303 self.blockList
304 self.blocksPerFile
304 self.blocksPerFile
305
305
306 '''
306 '''
307 fp = self.fp
307 fp = self.fp
308 startTime = self.startTime
308 startTime = self.startTime
309 endTime = self.endTime
309 endTime = self.endTime
310
310
311 grp = fp['Data']
311 grp = fp['Data']
312 thisUtcTime = grp['utctime'].value.astype(numpy.float)[0]
312 thisUtcTime = grp['utctime'].value.astype(numpy.float)[0]
313
313
314 #ERROOOOR
314 #ERROOOOR
315 if self.timezone == 'lt':
315 if self.timezone == 'lt':
316 thisUtcTime -= 5*3600
316 thisUtcTime -= 5*3600
317
317
318 thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0] + 5*3600)
318 thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0] + 5*3600)
319
319
320 thisDate = thisDatetime.date()
320 thisDate = thisDatetime.date()
321 thisTime = thisDatetime.time()
321 thisTime = thisDatetime.time()
322
322
323 startUtcTime = (datetime.datetime.combine(thisDate,startTime) - datetime.datetime(1970, 1, 1)).total_seconds()
323 startUtcTime = (datetime.datetime.combine(thisDate,startTime) - datetime.datetime(1970, 1, 1)).total_seconds()
324 endUtcTime = (datetime.datetime.combine(thisDate,endTime) - datetime.datetime(1970, 1, 1)).total_seconds()
324 endUtcTime = (datetime.datetime.combine(thisDate,endTime) - datetime.datetime(1970, 1, 1)).total_seconds()
325
325
326 ind = numpy.where(numpy.logical_and(thisUtcTime >= startUtcTime, thisUtcTime < endUtcTime))[0]
326 ind = numpy.where(numpy.logical_and(thisUtcTime >= startUtcTime, thisUtcTime < endUtcTime))[0]
327
327
328 self.blockList = ind
328 self.blockList = ind
329 self.blocksPerFile = len(ind)
329 self.blocksPerFile = len(ind)
330
330
331 return
331 return
332
332
333 def __readMetadata(self):
333 def __readMetadata(self):
334 '''
334 '''
335 Reads Metadata
335 Reads Metadata
336
336
337 self.pathMeta
337 self.pathMeta
338
338
339 self.listShapes
339 self.listShapes
340 self.listMetaname
340 self.listMetaname
341 self.listMeta
341 self.listMeta
342
342
343 '''
343 '''
344
344
345 # grp = self.fp['Data']
345 # grp = self.fp['Data']
346 # pathMeta = os.path.join(self.path, grp.attrs['metadata'])
346 # pathMeta = os.path.join(self.path, grp.attrs['metadata'])
347 #
347 #
348 # if pathMeta == self.pathMeta:
348 # if pathMeta == self.pathMeta:
349 # return
349 # return
350 # else:
350 # else:
351 # self.pathMeta = pathMeta
351 # self.pathMeta = pathMeta
352 #
352 #
353 # filePointer = h5py.File(self.pathMeta,'r')
353 # filePointer = h5py.File(self.pathMeta,'r')
354 # groupPointer = filePointer['Metadata']
354 # groupPointer = filePointer['Metadata']
355
355
356 filename = self.filenameList[0]
356 filename = self.filenameList[0]
357
357
358 fp = h5py.File(filename,'r')
358 fp = h5py.File(filename,'r')
359
359
360 gp = fp['Metadata']
360 gp = fp['Metadata']
361
361
362 listMetaname = []
362 listMetaname = []
363 listMetadata = []
363 listMetadata = []
364 for item in gp.items():
364 for item in gp.items():
365 name = item[0]
365 name = item[0]
366
366
367 if name=='array dimensions':
367 if name=='array dimensions':
368 table = gp[name][:]
368 table = gp[name][:]
369 listShapes = {}
369 listShapes = {}
370 for shapes in table:
370 for shapes in table:
371 listShapes[shapes[0]] = numpy.array([shapes[1],shapes[2],shapes[3],shapes[4],shapes[5]])
371 listShapes[shapes[0]] = numpy.array([shapes[1],shapes[2],shapes[3],shapes[4],shapes[5]])
372 else:
372 else:
373 data = gp[name].value
373 data = gp[name].value
374 listMetaname.append(name)
374 listMetaname.append(name)
375 listMetadata.append(data)
375 listMetadata.append(data)
376
376
377 # if name=='type':
377 # if name=='type':
378 # self.__initDataOut(data)
378 # self.__initDataOut(data)
379
379
380 self.listShapes = listShapes
380 self.listShapes = listShapes
381 self.listMetaname = listMetaname
381 self.listMetaname = listMetaname
382 self.listMeta = listMetadata
382 self.listMeta = listMetadata
383
383
384 fp.close()
384 fp.close()
385 return
385 return
386
386
387 def __readData(self):
387 def __readData(self):
388 grp = self.fp['Data']
388 grp = self.fp['Data']
389 listdataname = []
389 listdataname = []
390 listdata = []
390 listdata = []
391
391
392 for item in grp.items():
392 for item in grp.items():
393 name = item[0]
393 name = item[0]
394 listdataname.append(name)
394 listdataname.append(name)
395
395
396 array = self.__setDataArray(grp[name],self.listShapes[name])
396 array = self.__setDataArray(grp[name],self.listShapes[name])
397 listdata.append(array)
397 listdata.append(array)
398
398
399 self.listDataname = listdataname
399 self.listDataname = listdataname
400 self.listData = listdata
400 self.listData = listdata
401 return
401 return
402
402
403 def __setDataArray(self, dataset, shapes):
403 def __setDataArray(self, dataset, shapes):
404
404
405 nDims = shapes[0]
405 nDims = shapes[0]
406
406
407 nDim2 = shapes[1] #Dimension 0
407 nDim2 = shapes[1] #Dimension 0
408
408
409 nDim1 = shapes[2] #Dimension 1, number of Points or Parameters
409 nDim1 = shapes[2] #Dimension 1, number of Points or Parameters
410
410
411 nDim0 = shapes[3] #Dimension 2, number of samples or ranges
411 nDim0 = shapes[3] #Dimension 2, number of samples or ranges
412
412
413 mode = shapes[4] #Mode of storing
413 mode = shapes[4] #Mode of storing
414
414
415 blockList = self.blockList
415 blockList = self.blockList
416
416
417 blocksPerFile = self.blocksPerFile
417 blocksPerFile = self.blocksPerFile
418
418
419 #Depending on what mode the data was stored
419 #Depending on what mode the data was stored
420 if mode == 0: #Divided in channels
420 if mode == 0: #Divided in channels
421 arrayData = dataset.value.astype(numpy.float)[0][blockList]
421 arrayData = dataset.value.astype(numpy.float)[0][blockList]
422 if mode == 1: #Divided in parameter
422 if mode == 1: #Divided in parameter
423 strds = 'table'
423 strds = 'table'
424 nDatas = nDim1
424 nDatas = nDim1
425 newShapes = (blocksPerFile,nDim2,nDim0)
425 newShapes = (blocksPerFile,nDim2,nDim0)
426 elif mode==2: #Concatenated in a table
426 elif mode==2: #Concatenated in a table
427 strds = 'table0'
427 strds = 'table0'
428 arrayData = dataset[strds].value
428 arrayData = dataset[strds].value
429 #Selecting part of the dataset
429 #Selecting part of the dataset
430 utctime = arrayData[:,0]
430 utctime = arrayData[:,0]
431 u, indices = numpy.unique(utctime, return_index=True)
431 u, indices = numpy.unique(utctime, return_index=True)
432
432
433 if blockList.size != indices.size:
433 if blockList.size != indices.size:
434 indMin = indices[blockList[0]]
434 indMin = indices[blockList[0]]
435 if blockList[1] + 1 >= indices.size:
435 if blockList[1] + 1 >= indices.size:
436 arrayData = arrayData[indMin:,:]
436 arrayData = arrayData[indMin:,:]
437 else:
437 else:
438 indMax = indices[blockList[1] + 1]
438 indMax = indices[blockList[1] + 1]
439 arrayData = arrayData[indMin:indMax,:]
439 arrayData = arrayData[indMin:indMax,:]
440 return arrayData
440 return arrayData
441
441
442 # One dimension
442 # One dimension
443 if nDims == 0:
443 if nDims == 0:
444 arrayData = dataset.value.astype(numpy.float)[0][blockList]
444 arrayData = dataset.value.astype(numpy.float)[0][blockList]
445
445
446 # Two dimensions
446 # Two dimensions
447 elif nDims == 2:
447 elif nDims == 2:
448 arrayData = numpy.zeros((blocksPerFile,nDim1,nDim0))
448 arrayData = numpy.zeros((blocksPerFile,nDim1,nDim0))
449 newShapes = (blocksPerFile,nDim0)
449 newShapes = (blocksPerFile,nDim0)
450 nDatas = nDim1
450 nDatas = nDim1
451
451
452 for i in range(nDatas):
452 for i in range(nDatas):
453 data = dataset[strds + str(i)].value
453 data = dataset[strds + str(i)].value
454 arrayData[:,i,:] = data[blockList,:]
454 arrayData[:,i,:] = data[blockList,:]
455
455
456 # Three dimensions
456 # Three dimensions
457 else:
457 else:
458 arrayData = numpy.zeros((blocksPerFile,nDim2,nDim1,nDim0))
458 arrayData = numpy.zeros((blocksPerFile,nDim2,nDim1,nDim0))
459 for i in range(nDatas):
459 for i in range(nDatas):
460
460
461 data = dataset[strds + str(i)].value
461 data = dataset[strds + str(i)].value
462
462
463 for b in range(blockList.size):
463 for b in range(blockList.size):
464 arrayData[b,:,i,:] = data[:,:,blockList[b]]
464 arrayData[b,:,i,:] = data[:,:,blockList[b]]
465
465
466 return arrayData
466 return arrayData
467
467
468 def __setDataOut(self):
468 def __setDataOut(self):
469 listMeta = self.listMeta
469 listMeta = self.listMeta
470 listMetaname = self.listMetaname
470 listMetaname = self.listMetaname
471 listDataname = self.listDataname
471 listDataname = self.listDataname
472 listData = self.listData
472 listData = self.listData
473 listShapes = self.listShapes
473 listShapes = self.listShapes
474
474
475 blockIndex = self.blockIndex
475 blockIndex = self.blockIndex
476 # blockList = self.blockList
476 # blockList = self.blockList
477
477
478 for i in range(len(listMeta)):
478 for i in range(len(listMeta)):
479 setattr(self.dataOut,listMetaname[i],listMeta[i])
479 setattr(self.dataOut,listMetaname[i],listMeta[i])
480
480
481 for j in range(len(listData)):
481 for j in range(len(listData)):
482 nShapes = listShapes[listDataname[j]][0]
482 nShapes = listShapes[listDataname[j]][0]
483 mode = listShapes[listDataname[j]][4]
483 mode = listShapes[listDataname[j]][4]
484 if nShapes == 1:
484 if nShapes == 1:
485 setattr(self.dataOut,listDataname[j],listData[j][blockIndex])
485 setattr(self.dataOut,listDataname[j],listData[j][blockIndex])
486 elif nShapes > 1:
486 elif nShapes > 1:
487 setattr(self.dataOut,listDataname[j],listData[j][blockIndex,:])
487 setattr(self.dataOut,listDataname[j],listData[j][blockIndex,:])
488 elif mode==0:
488 elif mode==0:
489 setattr(self.dataOut,listDataname[j],listData[j][blockIndex])
489 setattr(self.dataOut,listDataname[j],listData[j][blockIndex])
490 #Mode Meteors
490 #Mode Meteors
491 elif mode ==2:
491 elif mode ==2:
492 selectedData = self.__selectDataMode2(listData[j], blockIndex)
492 selectedData = self.__selectDataMode2(listData[j], blockIndex)
493 setattr(self.dataOut, listDataname[j], selectedData)
493 setattr(self.dataOut, listDataname[j], selectedData)
494 return
494 return
495
495
496 def __selectDataMode2(self, data, blockIndex):
496 def __selectDataMode2(self, data, blockIndex):
497 utctime = data[:,0]
497 utctime = data[:,0]
498 aux, indices = numpy.unique(utctime, return_inverse=True)
498 aux, indices = numpy.unique(utctime, return_inverse=True)
499 selInd = numpy.where(indices == blockIndex)[0]
499 selInd = numpy.where(indices == blockIndex)[0]
500 selData = data[selInd,:]
500 selData = data[selInd,:]
501
501
502 return selData
502 return selData
503
503
504 def getData(self):
504 def getData(self):
505
505
506 # if self.flagNoMoreFiles:
506 # if self.flagNoMoreFiles:
507 # self.dataOut.flagNoData = True
507 # self.dataOut.flagNoData = True
508 # print 'Process finished'
508 # print 'Process finished'
509 # return 0
509 # return 0
510 #
510 #
511 if self.blockIndex==self.blocksPerFile:
511 if self.blockIndex==self.blocksPerFile:
512 if not( self.__setNextFileOffline() ):
512 if not( self.__setNextFileOffline() ):
513 self.dataOut.flagNoData = True
513 self.dataOut.flagNoData = True
514 return 0
514 return 0
515
515
516 # if self.datablock == None: # setear esta condicion cuando no hayan datos por leers
516 # if self.datablock == None: # setear esta condicion cuando no hayan datos por leers
517 # self.dataOut.flagNoData = True
517 # self.dataOut.flagNoData = True
518 # return 0
518 # return 0
519 # self.__readData()
519 # self.__readData()
520 self.__setDataOut()
520 self.__setDataOut()
521 self.dataOut.flagNoData = False
521 self.dataOut.flagNoData = False
522
522
523 self.blockIndex += 1
523 self.blockIndex += 1
524
524
525 return
525 return
526
526
527 def run(self, **kwargs):
527 def run(self, **kwargs):
528
528
529 if not(self.isConfig):
529 if not(self.isConfig):
530 self.setup(**kwargs)
530 self.setup(**kwargs)
531 # self.setObjProperties()
531 # self.setObjProperties()
532 self.isConfig = True
532 self.isConfig = True
533
533
534 self.getData()
534 self.getData()
535
535
536 return
536 return
537
537
538 class ParamWriter(Operation):
538 class ParamWriter(Operation):
539 '''
539 '''
540 HDF5 Writer, stores parameters data in HDF5 format files
540 HDF5 Writer, stores parameters data in HDF5 format files
541
541
542 path: path where the files will be stored
542 path: path where the files will be stored
543
543
544 blocksPerFile: number of blocks that will be saved in per HDF5 format file
544 blocksPerFile: number of blocks that will be saved in per HDF5 format file
545
545
546 mode: selects the data stacking mode: '0' channels, '1' parameters, '3' table (for meteors)
546 mode: selects the data stacking mode: '0' channels, '1' parameters, '3' table (for meteors)
547
547
548 metadataList: list of attributes that will be stored as metadata
548 metadataList: list of attributes that will be stored as metadata
549
549
550 dataList: list of attributes that will be stores as data
550 dataList: list of attributes that will be stores as data
551
551
552 '''
552 '''
553
553
554
554
555 ext = ".hdf5"
555 ext = ".hdf5"
556
556
557 optchar = "D"
557 optchar = "D"
558
558
559 metaoptchar = "M"
559 metaoptchar = "M"
560
560
561 metaFile = None
561 metaFile = None
562
562
563 filename = None
563 filename = None
564
564
565 path = None
565 path = None
566
566
567 setFile = None
567 setFile = None
568
568
569 fp = None
569 fp = None
570
570
571 grp = None
571 grp = None
572
572
573 ds = None
573 ds = None
574
574
575 firsttime = True
575 firsttime = True
576
576
577 #Configurations
577 #Configurations
578
578
579 blocksPerFile = None
579 blocksPerFile = None
580
580
581 blockIndex = None
581 blockIndex = None
582
582
583 dataOut = None
583 dataOut = None
584
584
585 #Data Arrays
585 #Data Arrays
586
586
587 dataList = None
587 dataList = None
588
588
589 metadataList = None
589 metadataList = None
590
590
591 # arrayDim = None
591 # arrayDim = None
592
592
593 dsList = None #List of dictionaries with dataset properties
593 dsList = None #List of dictionaries with dataset properties
594
594
595 tableDim = None
595 tableDim = None
596
596
597 # dtype = [('arrayName', 'S20'),('nChannels', 'i'), ('nPoints', 'i'), ('nSamples', 'i'),('mode', 'b')]
597 # dtype = [('arrayName', 'S20'),('nChannels', 'i'), ('nPoints', 'i'), ('nSamples', 'i'),('mode', 'b')]
598
598
599 dtype = [('arrayName', 'S20'),('nDimensions', 'i'), ('dim2', 'i'), ('dim1', 'i'),('dim0', 'i'),('mode', 'b')]
599 dtype = [('arrayName', 'S20'),('nDimensions', 'i'), ('dim2', 'i'), ('dim1', 'i'),('dim0', 'i'),('mode', 'b')]
600
600
601 currentDay = None
601 currentDay = None
602
602
603 lastTime = None
603 lastTime = None
604
604
605 def __init__(self, **kwargs):
605 def __init__(self, **kwargs):
606 Operation.__init__(self, **kwargs)
606 Operation.__init__(self, **kwargs)
607 self.isConfig = False
607 self.isConfig = False
608 return
608 return
609
609
610 def setup(self, dataOut, **kwargs):
610 def setup(self, dataOut, path=None, blocksPerFile=10, metadataList=None, dataList=None, mode=None, **kwargs):
611
611 self.path = path
612 self.path = kwargs['path']
612 self.blocksPerFile = blocksPerFile
613
613 self.metadataList = metadataList
614 if kwargs.has_key('blocksPerFile'):
614 self.dataList = dataList
615 self.blocksPerFile = kwargs['blocksPerFile']
616 else:
617 self.blocksPerFile = 10
618
619 self.metadataList = kwargs['metadataList']
620 self.dataList = kwargs['dataList']
621 self.dataOut = dataOut
615 self.dataOut = dataOut
622
623 if kwargs.has_key('mode'):
624 mode = kwargs['mode']
625
626 if type(mode) == int:
627 mode = numpy.zeros(len(self.dataList)) + mode
628 else:
629 mode = numpy.ones(len(self.dataList))
630
631 self.mode = mode
616 self.mode = mode
617
618 if self.mode is not None:
619 self.mode = numpy.zeros(len(self.dataList)) + mode
620 else:
621 self.mode = numpy.ones(len(self.dataList))
632
622
633 arrayDim = numpy.zeros((len(self.dataList),5))
623 arrayDim = numpy.zeros((len(self.dataList),5))
634
624
635 #Table dimensions
625 #Table dimensions
636 dtype0 = self.dtype
626 dtype0 = self.dtype
637 tableList = []
627 tableList = []
638
628
639 #Dictionary and list of tables
629 #Dictionary and list of tables
640 dsList = []
630 dsList = []
641
631
642 for i in range(len(self.dataList)):
632 for i in range(len(self.dataList)):
643 dsDict = {}
633 dsDict = {}
644 dataAux = getattr(self.dataOut, self.dataList[i])
634 dataAux = getattr(self.dataOut, self.dataList[i])
645 dsDict['variable'] = self.dataList[i]
635 dsDict['variable'] = self.dataList[i]
646 #--------------------- Conditionals ------------------------
636 #--------------------- Conditionals ------------------------
647 #There is no data
637 #There is no data
648 if dataAux is None:
638 if dataAux is None:
649 return 0
639 return 0
650
640
651 #Not array, just a number
641 #Not array, just a number
652 #Mode 0
642 #Mode 0
653 if type(dataAux)==float or type(dataAux)==int:
643 if type(dataAux)==float or type(dataAux)==int:
654 dsDict['mode'] = 0
644 dsDict['mode'] = 0
655 dsDict['nDim'] = 0
645 dsDict['nDim'] = 0
656 arrayDim[i,0] = 0
646 arrayDim[i,0] = 0
657 dsList.append(dsDict)
647 dsList.append(dsDict)
658
648
659 #Mode 2: meteors
649 #Mode 2: meteors
660 elif mode[i] == 2:
650 elif mode[i] == 2:
661 # dsDict['nDim'] = 0
651 # dsDict['nDim'] = 0
662 dsDict['dsName'] = 'table0'
652 dsDict['dsName'] = 'table0'
663 dsDict['mode'] = 2 # Mode meteors
653 dsDict['mode'] = 2 # Mode meteors
664 dsDict['shape'] = dataAux.shape[-1]
654 dsDict['shape'] = dataAux.shape[-1]
665 dsDict['nDim'] = 0
655 dsDict['nDim'] = 0
666 dsDict['dsNumber'] = 1
656 dsDict['dsNumber'] = 1
667
657
668 arrayDim[i,3] = dataAux.shape[-1]
658 arrayDim[i,3] = dataAux.shape[-1]
669 arrayDim[i,4] = mode[i] #Mode the data was stored
659 arrayDim[i,4] = mode[i] #Mode the data was stored
670
660
671 dsList.append(dsDict)
661 dsList.append(dsDict)
672
662
673 #Mode 1
663 #Mode 1
674 else:
664 else:
675 arrayDim0 = dataAux.shape #Data dimensions
665 arrayDim0 = dataAux.shape #Data dimensions
676 arrayDim[i,0] = len(arrayDim0) #Number of array dimensions
666 arrayDim[i,0] = len(arrayDim0) #Number of array dimensions
677 arrayDim[i,4] = mode[i] #Mode the data was stored
667 arrayDim[i,4] = mode[i] #Mode the data was stored
678
668
679 strtable = 'table'
669 strtable = 'table'
680 dsDict['mode'] = 1 # Mode parameters
670 dsDict['mode'] = 1 # Mode parameters
681
671
682 # Three-dimension arrays
672 # Three-dimension arrays
683 if len(arrayDim0) == 3:
673 if len(arrayDim0) == 3:
684 arrayDim[i,1:-1] = numpy.array(arrayDim0)
674 arrayDim[i,1:-1] = numpy.array(arrayDim0)
685 nTables = int(arrayDim[i,2])
675 nTables = int(arrayDim[i,2])
686 dsDict['dsNumber'] = nTables
676 dsDict['dsNumber'] = nTables
687 dsDict['shape'] = arrayDim[i,2:4]
677 dsDict['shape'] = arrayDim[i,2:4]
688 dsDict['nDim'] = 3
678 dsDict['nDim'] = 3
689
679
690 for j in range(nTables):
680 for j in range(nTables):
691 dsDict = dsDict.copy()
681 dsDict = dsDict.copy()
692 dsDict['dsName'] = strtable + str(j)
682 dsDict['dsName'] = strtable + str(j)
693 dsList.append(dsDict)
683 dsList.append(dsDict)
694
684
695 # Two-dimension arrays
685 # Two-dimension arrays
696 elif len(arrayDim0) == 2:
686 elif len(arrayDim0) == 2:
697 arrayDim[i,2:-1] = numpy.array(arrayDim0)
687 arrayDim[i,2:-1] = numpy.array(arrayDim0)
698 nTables = int(arrayDim[i,2])
688 nTables = int(arrayDim[i,2])
699 dsDict['dsNumber'] = nTables
689 dsDict['dsNumber'] = nTables
700 dsDict['shape'] = arrayDim[i,3]
690 dsDict['shape'] = arrayDim[i,3]
701 dsDict['nDim'] = 2
691 dsDict['nDim'] = 2
702
692
703 for j in range(nTables):
693 for j in range(nTables):
704 dsDict = dsDict.copy()
694 dsDict = dsDict.copy()
705 dsDict['dsName'] = strtable + str(j)
695 dsDict['dsName'] = strtable + str(j)
706 dsList.append(dsDict)
696 dsList.append(dsDict)
707
697
708 # One-dimension arrays
698 # One-dimension arrays
709 elif len(arrayDim0) == 1:
699 elif len(arrayDim0) == 1:
710 arrayDim[i,3] = arrayDim0[0]
700 arrayDim[i,3] = arrayDim0[0]
711 dsDict['shape'] = arrayDim0[0]
701 dsDict['shape'] = arrayDim0[0]
712 dsDict['dsNumber'] = 1
702 dsDict['dsNumber'] = 1
713 dsDict['dsName'] = strtable + str(0)
703 dsDict['dsName'] = strtable + str(0)
714 dsDict['nDim'] = 1
704 dsDict['nDim'] = 1
715 dsList.append(dsDict)
705 dsList.append(dsDict)
716
706
717 table = numpy.array((self.dataList[i],) + tuple(arrayDim[i,:]),dtype = dtype0)
707 table = numpy.array((self.dataList[i],) + tuple(arrayDim[i,:]),dtype = dtype0)
718 tableList.append(table)
708 tableList.append(table)
719
709
720 # self.arrayDim = arrayDim
710 # self.arrayDim = arrayDim
721 self.dsList = dsList
711 self.dsList = dsList
722 self.tableDim = numpy.array(tableList, dtype = dtype0)
712 self.tableDim = numpy.array(tableList, dtype = dtype0)
723 self.blockIndex = 0
713 self.blockIndex = 0
724
714
725 timeTuple = time.localtime(dataOut.utctime)
715 timeTuple = time.localtime(dataOut.utctime)
726 self.currentDay = timeTuple.tm_yday
716 self.currentDay = timeTuple.tm_yday
727 return 1
717 return 1
728
718
729 def putMetadata(self):
719 def putMetadata(self):
730
720
731 fp = self.createMetadataFile()
721 fp = self.createMetadataFile()
732 self.writeMetadata(fp)
722 self.writeMetadata(fp)
733 fp.close()
723 fp.close()
734 return
724 return
735
725
736 def createMetadataFile(self):
726 def createMetadataFile(self):
737 ext = self.ext
727 ext = self.ext
738 path = self.path
728 path = self.path
739 setFile = self.setFile
729 setFile = self.setFile
740
730
741 timeTuple = time.localtime(self.dataOut.utctime)
731 timeTuple = time.localtime(self.dataOut.utctime)
742
732
743 subfolder = ''
733 subfolder = ''
744 fullpath = os.path.join( path, subfolder )
734 fullpath = os.path.join( path, subfolder )
745
735
746 if not( os.path.exists(fullpath) ):
736 if not( os.path.exists(fullpath) ):
747 os.mkdir(fullpath)
737 os.mkdir(fullpath)
748 setFile = -1 #inicializo mi contador de seteo
738 setFile = -1 #inicializo mi contador de seteo
749
739
750 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
740 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
751 fullpath = os.path.join( path, subfolder )
741 fullpath = os.path.join( path, subfolder )
752
742
753 if not( os.path.exists(fullpath) ):
743 if not( os.path.exists(fullpath) ):
754 os.mkdir(fullpath)
744 os.mkdir(fullpath)
755 setFile = -1 #inicializo mi contador de seteo
745 setFile = -1 #inicializo mi contador de seteo
756
746
757 else:
747 else:
758 filesList = os.listdir( fullpath )
748 filesList = os.listdir( fullpath )
759 filesList = sorted( filesList, key=str.lower )
749 filesList = sorted( filesList, key=str.lower )
760 if len( filesList ) > 0:
750 if len( filesList ) > 0:
761 filesList = [k for k in filesList if 'M' in k]
751 filesList = [k for k in filesList if 'M' in k]
762 filen = filesList[-1]
752 filen = filesList[-1]
763 # el filename debera tener el siguiente formato
753 # el filename debera tener el siguiente formato
764 # 0 1234 567 89A BCDE (hex)
754 # 0 1234 567 89A BCDE (hex)
765 # x YYYY DDD SSS .ext
755 # x YYYY DDD SSS .ext
766 if isNumber( filen[8:11] ):
756 if isNumber( filen[8:11] ):
767 setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
757 setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
768 else:
758 else:
769 setFile = -1
759 setFile = -1
770 else:
760 else:
771 setFile = -1 #inicializo mi contador de seteo
761 setFile = -1 #inicializo mi contador de seteo
772
762
773 setFile += 1
763 if self.setType is None:
774
764 setFile += 1
775 file = '%s%4.4d%3.3d%3.3d%s' % (self.metaoptchar,
765 file = '%s%4.4d%3.3d%03d%s' % (self.metaoptchar,
776 timeTuple.tm_year,
766 timeTuple.tm_year,
777 timeTuple.tm_yday,
767 timeTuple.tm_yday,
778 setFile,
768 setFile,
779 ext )
769 ext )
770 else:
771 setFile = timeTuple.tm_hour*60+timeTuple.tm_min
772 file = '%s%4.4d%3.3d%04d%s' % (self.metaoptchar,
773 timeTuple.tm_year,
774 timeTuple.tm_yday,
775 setFile,
776 ext )
780
777
781 filename = os.path.join( path, subfolder, file )
778 filename = os.path.join( path, subfolder, file )
782 self.metaFile = file
779 self.metaFile = file
783 #Setting HDF5 File
780 #Setting HDF5 File
784 fp = h5py.File(filename,'w')
781 fp = h5py.File(filename,'w')
785
782
786 return fp
783 return fp
787
784
788 def writeMetadata(self, fp):
785 def writeMetadata(self, fp):
789
786
790 grp = fp.create_group("Metadata")
787 grp = fp.create_group("Metadata")
791 grp.create_dataset('array dimensions', data = self.tableDim, dtype = self.dtype)
788 grp.create_dataset('array dimensions', data = self.tableDim, dtype = self.dtype)
792
789
793 for i in range(len(self.metadataList)):
790 for i in range(len(self.metadataList)):
794 grp.create_dataset(self.metadataList[i], data=getattr(self.dataOut, self.metadataList[i]))
791 grp.create_dataset(self.metadataList[i], data=getattr(self.dataOut, self.metadataList[i]))
795 return
792 return
796
793
797 def timeFlag(self):
794 def timeFlag(self):
798 currentTime = self.dataOut.utctime
795 currentTime = self.dataOut.utctime
799
796
800 if self.lastTime is None:
797 if self.lastTime is None:
801 self.lastTime = currentTime
798 self.lastTime = currentTime
802
799
803 #Day
800 #Day
804 timeTuple = time.localtime(currentTime)
801 timeTuple = time.localtime(currentTime)
805 dataDay = timeTuple.tm_yday
802 dataDay = timeTuple.tm_yday
806
803
807 #Time
804 #Time
808 timeDiff = currentTime - self.lastTime
805 timeDiff = currentTime - self.lastTime
809
806
810 #Si el dia es diferente o si la diferencia entre un dato y otro supera la hora
807 #Si el dia es diferente o si la diferencia entre un dato y otro supera la hora
811 if dataDay != self.currentDay:
808 if dataDay != self.currentDay:
812 self.currentDay = dataDay
809 self.currentDay = dataDay
813 return True
810 return True
814 elif timeDiff > 3*60*60:
811 elif timeDiff > 3*60*60:
815 self.lastTime = currentTime
812 self.lastTime = currentTime
816 return True
813 return True
817 else:
814 else:
818 self.lastTime = currentTime
815 self.lastTime = currentTime
819 return False
816 return False
820
817
821 def setNextFile(self):
818 def setNextFile(self):
822
819
823 ext = self.ext
820 ext = self.ext
824 path = self.path
821 path = self.path
825 setFile = self.setFile
822 setFile = self.setFile
826 mode = self.mode
823 mode = self.mode
827
824
828 timeTuple = time.localtime(self.dataOut.utctime)
825 timeTuple = time.localtime(self.dataOut.utctime)
829 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
826 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
830
827
831 fullpath = os.path.join( path, subfolder )
828 fullpath = os.path.join( path, subfolder )
832
829
833 if os.path.exists(fullpath):
830 if os.path.exists(fullpath):
834 filesList = os.listdir( fullpath )
831 filesList = os.listdir( fullpath )
835 filesList = [k for k in filesList if 'D' in k]
832 filesList = [k for k in filesList if 'D' in k]
836 if len( filesList ) > 0:
833 if len( filesList ) > 0:
837 filesList = sorted( filesList, key=str.lower )
834 filesList = sorted( filesList, key=str.lower )
838 filen = filesList[-1]
835 filen = filesList[-1]
839 # el filename debera tener el siguiente formato
836 # el filename debera tener el siguiente formato
840 # 0 1234 567 89A BCDE (hex)
837 # 0 1234 567 89A BCDE (hex)
841 # x YYYY DDD SSS .ext
838 # x YYYY DDD SSS .ext
842 if isNumber( filen[8:11] ):
839 if isNumber( filen[8:11] ):
843 setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
840 setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
844 else:
841 else:
845 setFile = -1
842 setFile = -1
846 else:
843 else:
847 setFile = -1 #inicializo mi contador de seteo
844 setFile = -1 #inicializo mi contador de seteo
848 else:
845 else:
849 os.makedirs(fullpath)
846 os.makedirs(fullpath)
850 setFile = -1 #inicializo mi contador de seteo
847 setFile = -1 #inicializo mi contador de seteo
851
848
852 setFile += 1
849 if self.setType is None:
853
850 setFile += 1
854 file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar,
851 file = '%s%4.4d%3.3d%03d%s' % (self.metaoptchar,
855 timeTuple.tm_year,
852 timeTuple.tm_year,
856 timeTuple.tm_yday,
853 timeTuple.tm_yday,
857 setFile,
854 setFile,
858 ext )
855 ext )
856 else:
857 setFile = timeTuple.tm_hour*60+timeTuple.tm_min
858 file = '%s%4.4d%3.3d%04d%s' % (self.metaoptchar,
859 timeTuple.tm_year,
860 timeTuple.tm_yday,
861 setFile,
862 ext )
859
863
860 filename = os.path.join( path, subfolder, file )
864 filename = os.path.join( path, subfolder, file )
861
865
862 #Setting HDF5 File
866 #Setting HDF5 File
863 fp = h5py.File(filename,'w')
867 fp = h5py.File(filename,'w')
864 #write metadata
868 #write metadata
865 self.writeMetadata(fp)
869 self.writeMetadata(fp)
866 #Write data
870 #Write data
867 grp = fp.create_group("Data")
871 grp = fp.create_group("Data")
868 # grp.attrs['metadata'] = self.metaFile
872 # grp.attrs['metadata'] = self.metaFile
869
873
870 # grp.attrs['blocksPerFile'] = 0
874 # grp.attrs['blocksPerFile'] = 0
871 ds = []
875 ds = []
872 data = []
876 data = []
873 dsList = self.dsList
877 dsList = self.dsList
874 i = 0
878 i = 0
875 while i < len(dsList):
879 while i < len(dsList):
876 dsInfo = dsList[i]
880 dsInfo = dsList[i]
877 #One-dimension data
881 #One-dimension data
878 if dsInfo['mode'] == 0:
882 if dsInfo['mode'] == 0:
879 # ds0 = grp.create_dataset(self.dataList[i], (1,1), maxshape=(1,self.blocksPerFile) , chunks = True, dtype='S20')
883 # ds0 = grp.create_dataset(self.dataList[i], (1,1), maxshape=(1,self.blocksPerFile) , chunks = True, dtype='S20')
880 ds0 = grp.create_dataset(dsInfo['variable'], (1,1), maxshape=(1,self.blocksPerFile) , chunks = True, dtype=numpy.float64)
884 ds0 = grp.create_dataset(dsInfo['variable'], (1,1), maxshape=(1,self.blocksPerFile) , chunks = True, dtype=numpy.float64)
881 ds.append(ds0)
885 ds.append(ds0)
882 data.append([])
886 data.append([])
883 i += 1
887 i += 1
884 continue
888 continue
885 # nDimsForDs.append(nDims[i])
889 # nDimsForDs.append(nDims[i])
886
890
887 elif dsInfo['mode'] == 2:
891 elif dsInfo['mode'] == 2:
888 grp0 = grp.create_group(dsInfo['variable'])
892 grp0 = grp.create_group(dsInfo['variable'])
889 ds0 = grp0.create_dataset(dsInfo['dsName'], (1,dsInfo['shape']), data = numpy.zeros((1,dsInfo['shape'])) , maxshape=(None,dsInfo['shape']), chunks=True)
893 ds0 = grp0.create_dataset(dsInfo['dsName'], (1,dsInfo['shape']), data = numpy.zeros((1,dsInfo['shape'])) , maxshape=(None,dsInfo['shape']), chunks=True)
890 ds.append(ds0)
894 ds.append(ds0)
891 data.append([])
895 data.append([])
892 i += 1
896 i += 1
893 continue
897 continue
894
898
895 elif dsInfo['mode'] == 1:
899 elif dsInfo['mode'] == 1:
896 grp0 = grp.create_group(dsInfo['variable'])
900 grp0 = grp.create_group(dsInfo['variable'])
897
901
898 for j in range(dsInfo['dsNumber']):
902 for j in range(dsInfo['dsNumber']):
899 dsInfo = dsList[i]
903 dsInfo = dsList[i]
900 tableName = dsInfo['dsName']
904 tableName = dsInfo['dsName']
901 shape = int(dsInfo['shape'])
905 shape = int(dsInfo['shape'])
902
906
903 if dsInfo['nDim'] == 3:
907 if dsInfo['nDim'] == 3:
904 ds0 = grp0.create_dataset(tableName, (shape[0],shape[1],1) , data = numpy.zeros((shape[0],shape[1],1)), maxshape = (None,shape[1],None), chunks=True)
908 ds0 = grp0.create_dataset(tableName, (shape[0],shape[1],1) , data = numpy.zeros((shape[0],shape[1],1)), maxshape = (None,shape[1],None), chunks=True)
905 else:
909 else:
906 ds0 = grp0.create_dataset(tableName, (1,shape), data = numpy.zeros((1,shape)) , maxshape=(None,shape), chunks=True)
910 ds0 = grp0.create_dataset(tableName, (1,shape), data = numpy.zeros((1,shape)) , maxshape=(None,shape), chunks=True)
907
911
908 ds.append(ds0)
912 ds.append(ds0)
909 data.append([])
913 data.append([])
910 i += 1
914 i += 1
911 # nDimsForDs.append(nDims[i])
915 # nDimsForDs.append(nDims[i])
912
916
913 fp.flush()
917 fp.flush()
914 fp.close()
918 fp.close()
915
919
916 # self.nDatas = nDatas
920 # self.nDatas = nDatas
917 # self.nDims = nDims
921 # self.nDims = nDims
918 # self.nDimsForDs = nDimsForDs
922 # self.nDimsForDs = nDimsForDs
919 #Saving variables
923 #Saving variables
920 print 'Writing the file: %s'%filename
924 print 'Writing the file: %s'%filename
921 self.filename = filename
925 self.filename = filename
922 # self.fp = fp
926 # self.fp = fp
923 # self.grp = grp
927 # self.grp = grp
924 # self.grp.attrs.modify('nRecords', 1)
928 # self.grp.attrs.modify('nRecords', 1)
925 self.ds = ds
929 self.ds = ds
926 self.data = data
930 self.data = data
927 # self.setFile = setFile
931 # self.setFile = setFile
928 self.firsttime = True
932 self.firsttime = True
929 self.blockIndex = 0
933 self.blockIndex = 0
930 return
934 return
931
935
932 def putData(self):
936 def putData(self):
933
937
934 if self.blockIndex == self.blocksPerFile or self.timeFlag():
938 if self.blockIndex == self.blocksPerFile or self.timeFlag():
935 self.setNextFile()
939 self.setNextFile()
936
940
937 # if not self.firsttime:
941 # if not self.firsttime:
938 self.readBlock()
942 self.readBlock()
939 self.setBlock() #Prepare data to be written
943 self.setBlock() #Prepare data to be written
940 self.writeBlock() #Write data
944 self.writeBlock() #Write data
941
945
942 return
946 return
943
947
944 def readBlock(self):
948 def readBlock(self):
945
949
946 '''
950 '''
947 data Array configured
951 data Array configured
948
952
949
953
950 self.data
954 self.data
951 '''
955 '''
952 dsList = self.dsList
956 dsList = self.dsList
953 ds = self.ds
957 ds = self.ds
954 #Setting HDF5 File
958 #Setting HDF5 File
955 fp = h5py.File(self.filename,'r+')
959 fp = h5py.File(self.filename,'r+')
956 grp = fp["Data"]
960 grp = fp["Data"]
957 ind = 0
961 ind = 0
958
962
959 # grp.attrs['blocksPerFile'] = 0
963 # grp.attrs['blocksPerFile'] = 0
960 while ind < len(dsList):
964 while ind < len(dsList):
961 dsInfo = dsList[ind]
965 dsInfo = dsList[ind]
962
966
963 if dsInfo['mode'] == 0:
967 if dsInfo['mode'] == 0:
964 ds0 = grp[dsInfo['variable']]
968 ds0 = grp[dsInfo['variable']]
965 ds[ind] = ds0
969 ds[ind] = ds0
966 ind += 1
970 ind += 1
967 else:
971 else:
968
972
969 grp0 = grp[dsInfo['variable']]
973 grp0 = grp[dsInfo['variable']]
970
974
971 for j in range(dsInfo['dsNumber']):
975 for j in range(dsInfo['dsNumber']):
972 dsInfo = dsList[ind]
976 dsInfo = dsList[ind]
973 ds0 = grp0[dsInfo['dsName']]
977 ds0 = grp0[dsInfo['dsName']]
974 ds[ind] = ds0
978 ds[ind] = ds0
975 ind += 1
979 ind += 1
976
980
977 self.fp = fp
981 self.fp = fp
978 self.grp = grp
982 self.grp = grp
979 self.ds = ds
983 self.ds = ds
980
984
981 return
985 return
982
986
983 def setBlock(self):
987 def setBlock(self):
984 '''
988 '''
985 data Array configured
989 data Array configured
986
990
987
991
988 self.data
992 self.data
989 '''
993 '''
990 #Creating Arrays
994 #Creating Arrays
991 dsList = self.dsList
995 dsList = self.dsList
992 data = self.data
996 data = self.data
993 ind = 0
997 ind = 0
994
998
995 while ind < len(dsList):
999 while ind < len(dsList):
996 dsInfo = dsList[ind]
1000 dsInfo = dsList[ind]
997 dataAux = getattr(self.dataOut, dsInfo['variable'])
1001 dataAux = getattr(self.dataOut, dsInfo['variable'])
998
1002
999 mode = dsInfo['mode']
1003 mode = dsInfo['mode']
1000 nDim = dsInfo['nDim']
1004 nDim = dsInfo['nDim']
1001
1005
1002 if mode == 0 or mode == 2 or nDim == 1:
1006 if mode == 0 or mode == 2 or nDim == 1:
1003 data[ind] = dataAux
1007 data[ind] = dataAux
1004 ind += 1
1008 ind += 1
1005 # elif nDim == 1:
1009 # elif nDim == 1:
1006 # data[ind] = numpy.reshape(dataAux,(numpy.size(dataAux),1))
1010 # data[ind] = numpy.reshape(dataAux,(numpy.size(dataAux),1))
1007 # ind += 1
1011 # ind += 1
1008 elif nDim == 2:
1012 elif nDim == 2:
1009 for j in range(dsInfo['dsNumber']):
1013 for j in range(dsInfo['dsNumber']):
1010 data[ind] = dataAux[j,:]
1014 data[ind] = dataAux[j,:]
1011 ind += 1
1015 ind += 1
1012 elif nDim == 3:
1016 elif nDim == 3:
1013 for j in range(dsInfo['dsNumber']):
1017 for j in range(dsInfo['dsNumber']):
1014 data[ind] = dataAux[:,j,:]
1018 data[ind] = dataAux[:,j,:]
1015 ind += 1
1019 ind += 1
1016
1020
1017 self.data = data
1021 self.data = data
1018 return
1022 return
1019
1023
1020 def writeBlock(self):
1024 def writeBlock(self):
1021 '''
1025 '''
1022 Saves the block in the HDF5 file
1026 Saves the block in the HDF5 file
1023 '''
1027 '''
1024 dsList = self.dsList
1028 dsList = self.dsList
1025
1029
1026 for i in range(len(self.ds)):
1030 for i in range(len(self.ds)):
1027 dsInfo = dsList[i]
1031 dsInfo = dsList[i]
1028 nDim = dsInfo['nDim']
1032 nDim = dsInfo['nDim']
1029 mode = dsInfo['mode']
1033 mode = dsInfo['mode']
1030
1034
1031 # First time
1035 # First time
1032 if self.firsttime:
1036 if self.firsttime:
1033 # self.ds[i].resize(self.data[i].shape)
1037 # self.ds[i].resize(self.data[i].shape)
1034 # self.ds[i][self.blockIndex,:] = self.data[i]
1038 # self.ds[i][self.blockIndex,:] = self.data[i]
1035 if type(self.data[i]) == numpy.ndarray:
1039 if type(self.data[i]) == numpy.ndarray:
1036
1040
1037 if nDim == 3:
1041 if nDim == 3:
1038 self.data[i] = self.data[i].reshape((self.data[i].shape[0],self.data[i].shape[1],1))
1042 self.data[i] = self.data[i].reshape((self.data[i].shape[0],self.data[i].shape[1],1))
1039 self.ds[i].resize(self.data[i].shape)
1043 self.ds[i].resize(self.data[i].shape)
1040 if mode == 2:
1044 if mode == 2:
1041 self.ds[i].resize(self.data[i].shape)
1045 self.ds[i].resize(self.data[i].shape)
1042 self.ds[i][:] = self.data[i]
1046 self.ds[i][:] = self.data[i]
1043 else:
1047 else:
1044
1048
1045 # From second time
1049 # From second time
1046 # Meteors!
1050 # Meteors!
1047 if mode == 2:
1051 if mode == 2:
1048 dataShape = self.data[i].shape
1052 dataShape = self.data[i].shape
1049 dsShape = self.ds[i].shape
1053 dsShape = self.ds[i].shape
1050 self.ds[i].resize((self.ds[i].shape[0] + dataShape[0],self.ds[i].shape[1]))
1054 self.ds[i].resize((self.ds[i].shape[0] + dataShape[0],self.ds[i].shape[1]))
1051 self.ds[i][dsShape[0]:,:] = self.data[i]
1055 self.ds[i][dsShape[0]:,:] = self.data[i]
1052 # No dimension
1056 # No dimension
1053 elif mode == 0:
1057 elif mode == 0:
1054 self.ds[i].resize((self.ds[i].shape[0], self.ds[i].shape[1] + 1))
1058 self.ds[i].resize((self.ds[i].shape[0], self.ds[i].shape[1] + 1))
1055 self.ds[i][0,-1] = self.data[i]
1059 self.ds[i][0,-1] = self.data[i]
1056 # One dimension
1060 # One dimension
1057 elif nDim == 1:
1061 elif nDim == 1:
1058 self.ds[i].resize((self.ds[i].shape[0] + 1, self.ds[i].shape[1]))
1062 self.ds[i].resize((self.ds[i].shape[0] + 1, self.ds[i].shape[1]))
1059 self.ds[i][-1,:] = self.data[i]
1063 self.ds[i][-1,:] = self.data[i]
1060 # Two dimension
1064 # Two dimension
1061 elif nDim == 2:
1065 elif nDim == 2:
1062 self.ds[i].resize((self.ds[i].shape[0] + 1,self.ds[i].shape[1]))
1066 self.ds[i].resize((self.ds[i].shape[0] + 1,self.ds[i].shape[1]))
1063 self.ds[i][self.blockIndex,:] = self.data[i]
1067 self.ds[i][self.blockIndex,:] = self.data[i]
1064 # Three dimensions
1068 # Three dimensions
1065 elif nDim == 3:
1069 elif nDim == 3:
1066 self.ds[i].resize((self.ds[i].shape[0],self.ds[i].shape[1],self.ds[i].shape[2]+1))
1070 self.ds[i].resize((self.ds[i].shape[0],self.ds[i].shape[1],self.ds[i].shape[2]+1))
1067 self.ds[i][:,:,-1] = self.data[i]
1071 self.ds[i][:,:,-1] = self.data[i]
1068
1072
1069 self.firsttime = False
1073 self.firsttime = False
1070 self.blockIndex += 1
1074 self.blockIndex += 1
1071
1075
1072 #Close to save changes
1076 #Close to save changes
1073 self.fp.flush()
1077 self.fp.flush()
1074 self.fp.close()
1078 self.fp.close()
1075 return
1079 return
1076
1080
1077 def run(self, dataOut, **kwargs):
1081 def run(self, dataOut, path=None, blocksPerFile=10, metadataList=None, dataList=None, mode=None, **kwargs):
1078
1082
1079 if not(self.isConfig):
1083 if not(self.isConfig):
1080 flagdata = self.setup(dataOut, **kwargs)
1084 flagdata = self.setup(dataOut, path=path, blocksPerFile=blocksPerFile,
1085 metadataList=metadataList, dataList=dataList, mode=mode, **kwargs)
1081
1086
1082 if not(flagdata):
1087 if not(flagdata):
1083 return
1088 return
1084
1089
1085 self.isConfig = True
1090 self.isConfig = True
1086 # self.putMetadata()
1091 # self.putMetadata()
1087 self.setNextFile()
1092 self.setNextFile()
1088
1093
1089 self.putData()
1094 self.putData()
1090 return
1095 return
@@ -1,637 +1,738
1 '''
1 '''
2 Created on Jul 2, 2014
2 Created on Jul 2, 2014
3
3
4 @author: roj-idl71
4 @author: roj-idl71
5 '''
5 '''
6
6
7 import numpy
7 import numpy
8
8
9 from jroIO_base import LOCALTIME, JRODataReader, JRODataWriter
9 from jroIO_base import LOCALTIME, JRODataReader, JRODataWriter
10 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
10 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
11 from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader
11 from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader
12 from schainpy.model.data.jrodata import Voltage
12 from schainpy.model.data.jrodata import Voltage
13 # from _sha import blocksize
13 # from _sha import blocksize
14
14
15 class VoltageReader(JRODataReader, ProcessingUnit):
15 class VoltageReader(JRODataReader, ProcessingUnit):
16 """
16 """
17 Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura
17 Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura
18 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones:
18 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones:
19 perfiles*alturas*canales) son almacenados en la variable "buffer".
19 perfiles*alturas*canales) son almacenados en la variable "buffer".
20
20
21 perfiles * alturas * canales
21 perfiles * alturas * canales
22
22
23 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
23 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
24 RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la
24 RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la
25 cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de
25 cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de
26 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
26 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
27
27
28 Example:
28 Example:
29
29
30 dpath = "/home/myuser/data"
30 dpath = "/home/myuser/data"
31
31
32 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
32 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
33
33
34 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
34 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
35
35
36 readerObj = VoltageReader()
36 readerObj = VoltageReader()
37
37
38 readerObj.setup(dpath, startTime, endTime)
38 readerObj.setup(dpath, startTime, endTime)
39
39
40 while(True):
40 while(True):
41
41
42 #to get one profile
42 #to get one profile
43 profile = readerObj.getData()
43 profile = readerObj.getData()
44
44
45 #print the profile
45 #print the profile
46 print profile
46 print profile
47
47
48 #If you want to see all datablock
48 #If you want to see all datablock
49 print readerObj.datablock
49 print readerObj.datablock
50
50
51 if readerObj.flagNoMoreFiles:
51 if readerObj.flagNoMoreFiles:
52 break
52 break
53
53
54 """
54 """
55
55
56 ext = ".r"
56 ext = ".r"
57
57
58 optchar = "D"
58 optchar = "D"
59 dataOut = None
59 dataOut = None
60
60
61 def __init__(self):
61 def __init__(self):
62 """
62 """
63 Inicializador de la clase VoltageReader para la lectura de datos de voltage.
63 Inicializador de la clase VoltageReader para la lectura de datos de voltage.
64
64
65 Input:
65 Input:
66 dataOut : Objeto de la clase Voltage. Este objeto sera utilizado para
66 dataOut : Objeto de la clase Voltage. Este objeto sera utilizado para
67 almacenar un perfil de datos cada vez que se haga un requerimiento
67 almacenar un perfil de datos cada vez que se haga un requerimiento
68 (getData). El perfil sera obtenido a partir del buffer de datos,
68 (getData). El perfil sera obtenido a partir del buffer de datos,
69 si el buffer esta vacio se hara un nuevo proceso de lectura de un
69 si el buffer esta vacio se hara un nuevo proceso de lectura de un
70 bloque de datos.
70 bloque de datos.
71 Si este parametro no es pasado se creara uno internamente.
71 Si este parametro no es pasado se creara uno internamente.
72
72
73 Variables afectadas:
73 Variables afectadas:
74 self.dataOut
74 self.dataOut
75
75
76 Return:
76 Return:
77 None
77 None
78 """
78 """
79
79
80 ProcessingUnit.__init__(self)
80 ProcessingUnit.__init__(self)
81
81
82 self.isConfig = False
82 self.isConfig = False
83
83
84 self.datablock = None
84 self.datablock = None
85
85
86 self.utc = 0
86 self.utc = 0
87
87
88 self.ext = ".r"
88 self.ext = ".r"
89
89
90 self.optchar = "D"
90 self.optchar = "D"
91
91
92 self.basicHeaderObj = BasicHeader(LOCALTIME)
92 self.basicHeaderObj = BasicHeader(LOCALTIME)
93
93
94 self.systemHeaderObj = SystemHeader()
94 self.systemHeaderObj = SystemHeader()
95
95
96 self.radarControllerHeaderObj = RadarControllerHeader()
96 self.radarControllerHeaderObj = RadarControllerHeader()
97
97
98 self.processingHeaderObj = ProcessingHeader()
98 self.processingHeaderObj = ProcessingHeader()
99
99
100 self.online = 0
100 self.online = 0
101
101
102 self.fp = None
102 self.fp = None
103
103
104 self.idFile = None
104 self.idFile = None
105
105
106 self.dtype = None
106 self.dtype = None
107
107
108 self.fileSizeByHeader = None
108 self.fileSizeByHeader = None
109
109
110 self.filenameList = []
110 self.filenameList = []
111
111
112 self.filename = None
112 self.filename = None
113
113
114 self.fileSize = None
114 self.fileSize = None
115
115
116 self.firstHeaderSize = 0
116 self.firstHeaderSize = 0
117
117
118 self.basicHeaderSize = 24
118 self.basicHeaderSize = 24
119
119
120 self.pathList = []
120 self.pathList = []
121
121
122 self.filenameList = []
122 self.filenameList = []
123
123
124 self.lastUTTime = 0
124 self.lastUTTime = 0
125
125
126 self.maxTimeStep = 30
126 self.maxTimeStep = 30
127
127
128 self.flagNoMoreFiles = 0
128 self.flagNoMoreFiles = 0
129
129
130 self.set = 0
130 self.set = 0
131
131
132 self.path = None
132 self.path = None
133
133
134 self.profileIndex = 2**32-1
134 self.profileIndex = 2**32-1
135
135
136 self.delay = 3 #seconds
136 self.delay = 3 #seconds
137
137
138 self.nTries = 3 #quantity tries
138 self.nTries = 3 #quantity tries
139
139
140 self.nFiles = 3 #number of files for searching
140 self.nFiles = 3 #number of files for searching
141
141
142 self.nReadBlocks = 0
142 self.nReadBlocks = 0
143
143
144 self.flagIsNewFile = 1
144 self.flagIsNewFile = 1
145
145
146 self.__isFirstTimeOnline = 1
146 self.__isFirstTimeOnline = 1
147
147
148 # self.ippSeconds = 0
148 # self.ippSeconds = 0
149
149
150 self.flagDiscontinuousBlock = 0
150 self.flagDiscontinuousBlock = 0
151
151
152 self.flagIsNewBlock = 0
152 self.flagIsNewBlock = 0
153
153
154 self.nTotalBlocks = 0
154 self.nTotalBlocks = 0
155
155
156 self.blocksize = 0
156 self.blocksize = 0
157
157
158 self.dataOut = self.createObjByDefault()
158 self.dataOut = self.createObjByDefault()
159
159
160 self.nTxs = 1
160 self.nTxs = 1
161
161
162 self.txIndex = 0
162 self.txIndex = 0
163
163
164 def createObjByDefault(self):
164 def createObjByDefault(self):
165
165
166 dataObj = Voltage()
166 dataObj = Voltage()
167
167
168 return dataObj
168 return dataObj
169
169
170 def __hasNotDataInBuffer(self):
170 def __hasNotDataInBuffer(self):
171
171
172 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock*self.nTxs:
172 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock*self.nTxs:
173 return 1
173 return 1
174
174
175 return 0
175 return 0
176
176
177
177
178 def getBlockDimension(self):
178 def getBlockDimension(self):
179 """
179 """
180 Obtiene la cantidad de puntos a leer por cada bloque de datos
180 Obtiene la cantidad de puntos a leer por cada bloque de datos
181
181
182 Affected:
182 Affected:
183 self.blocksize
183 self.blocksize
184
184
185 Return:
185 Return:
186 None
186 None
187 """
187 """
188 pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels
188 pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels
189 self.blocksize = pts2read
189 self.blocksize = pts2read
190
190
191
191
192 def readBlock(self):
192 def readBlock(self):
193 """
193 """
194 readBlock lee el bloque de datos desde la posicion actual del puntero del archivo
194 readBlock lee el bloque de datos desde la posicion actual del puntero del archivo
195 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
195 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
196 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
196 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
197 es seteado a 0
197 es seteado a 0
198
199 Inputs:
200 None
201
198
202 Return:
199 Inputs:
203 None
200 None
204
201
205 Affected:
202 Return:
206 self.profileIndex
203 None
207 self.datablock
208 self.flagIsNewFile
209 self.flagIsNewBlock
210 self.nTotalBlocks
211
204
212 Exceptions:
205 Affected:
213 Si un bloque leido no es un bloque valido
206 self.profileIndex
207 self.datablock
208 self.flagIsNewFile
209 self.flagIsNewBlock
210 self.nTotalBlocks
211
212 Exceptions:
213 Si un bloque leido no es un bloque valido
214 """
214 """
215
216 # if self.server is not None:
217 # self.zBlock = self.receiver.recv()
218 # self.zHeader = self.zBlock[:24]
219 # self.zDataBlock = self.zBlock[24:]
220 # junk = numpy.fromstring(self.zDataBlock, numpy.dtype([('real','<i4'),('imag','<i4')]))
221 # self.processingHeaderObj.profilesPerBlock = 240
222 # self.processingHeaderObj.nHeights = 248
223 # self.systemHeaderObj.nChannels
224 # else:
215 current_pointer_location = self.fp.tell()
225 current_pointer_location = self.fp.tell()
216 junk = numpy.fromfile( self.fp, self.dtype, self.blocksize )
226 junk = numpy.fromfile( self.fp, self.dtype, self.blocksize )
217
227
218 try:
228 try:
219 junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) )
229 junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) )
220 except:
230 except:
221 #print "The read block (%3d) has not enough data" %self.nReadBlocks
231 #print "The read block (%3d) has not enough data" %self.nReadBlocks
222
232
223 if self.waitDataBlock(pointer_location=current_pointer_location):
233 if self.waitDataBlock(pointer_location=current_pointer_location):
224 junk = numpy.fromfile( self.fp, self.dtype, self.blocksize )
234 junk = numpy.fromfile( self.fp, self.dtype, self.blocksize )
225 junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) )
235 junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) )
226 # return 0
236 # return 0
227
237
228 #Dimensions : nChannels, nProfiles, nSamples
238 #Dimensions : nChannels, nProfiles, nSamples
229
239
230 junk = numpy.transpose(junk, (2,0,1))
240 junk = numpy.transpose(junk, (2,0,1))
231 self.datablock = junk['real'] + junk['imag']*1j
241 self.datablock = junk['real'] + junk['imag']*1j
232
242
233 self.profileIndex = 0
243 self.profileIndex = 0
234
244
235 self.flagIsNewFile = 0
245 self.flagIsNewFile = 0
236 self.flagIsNewBlock = 1
246 self.flagIsNewBlock = 1
237
247
238 self.nTotalBlocks += 1
248 self.nTotalBlocks += 1
239 self.nReadBlocks += 1
249 self.nReadBlocks += 1
240
250
241 return 1
251 return 1
242
252
243 def getFirstHeader(self):
253 def getFirstHeader(self):
244
254
245 self.getBasicHeader()
255 self.getBasicHeader()
246
256
247 self.dataOut.systemHeaderObj = self.systemHeaderObj.copy()
257 self.dataOut.systemHeaderObj = self.systemHeaderObj.copy()
248
258
249 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
259 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
250
260
251 if self.nTxs > 1:
261 if self.nTxs > 1:
252 self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds/self.nTxs
262 self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds/self.nTxs
253
263
254 #Time interval and code are propierties of dataOut. Its value depends of radarControllerHeaderObj.
264 #Time interval and code are propierties of dataOut. Its value depends of radarControllerHeaderObj.
255
265
256 # self.dataOut.timeInterval = self.radarControllerHeaderObj.ippSeconds * self.processingHeaderObj.nCohInt
266 # self.dataOut.timeInterval = self.radarControllerHeaderObj.ippSeconds * self.processingHeaderObj.nCohInt
257 #
267 #
258 # if self.radarControllerHeaderObj.code is not None:
268 # if self.radarControllerHeaderObj.code is not None:
259 #
269 #
260 # self.dataOut.nCode = self.radarControllerHeaderObj.nCode
270 # self.dataOut.nCode = self.radarControllerHeaderObj.nCode
261 #
271 #
262 # self.dataOut.nBaud = self.radarControllerHeaderObj.nBaud
272 # self.dataOut.nBaud = self.radarControllerHeaderObj.nBaud
263 #
273 #
264 # self.dataOut.code = self.radarControllerHeaderObj.code
274 # self.dataOut.code = self.radarControllerHeaderObj.code
265
275
266 self.dataOut.dtype = self.dtype
276 self.dataOut.dtype = self.dtype
267
277
268 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock
278 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock
269
279
270 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.nHeights) *self.processingHeaderObj.deltaHeight + self.processingHeaderObj.firstHeight
280 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.nHeights) *self.processingHeaderObj.deltaHeight + self.processingHeaderObj.firstHeight
271
281
272 self.dataOut.channelList = range(self.systemHeaderObj.nChannels)
282 self.dataOut.channelList = range(self.systemHeaderObj.nChannels)
273
283
274 self.dataOut.nCohInt = self.processingHeaderObj.nCohInt
284 self.dataOut.nCohInt = self.processingHeaderObj.nCohInt
275
285
276 self.dataOut.flagDecodeData = self.processingHeaderObj.flag_decode #asumo q la data no esta decodificada
286 self.dataOut.flagDecodeData = self.processingHeaderObj.flag_decode #asumo q la data no esta decodificada
277
287
278 self.dataOut.flagDeflipData = self.processingHeaderObj.flag_deflip #asumo q la data no esta sin flip
288 self.dataOut.flagDeflipData = self.processingHeaderObj.flag_deflip #asumo q la data no esta sin flip
279
289
280 self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft
290 self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft
281
291
282 def reshapeData(self):
292 def reshapeData(self):
283
293
284 if self.nTxs < 0:
294 if self.nTxs < 0:
285 return
295 return
286
296
287 if self.nTxs == 1:
297 if self.nTxs == 1:
288 return
298 return
289
299
290 if self.nTxs < 1 and self.processingHeaderObj.profilesPerBlock % (1./self.nTxs) != 0:
300 if self.nTxs < 1 and self.processingHeaderObj.profilesPerBlock % (1./self.nTxs) != 0:
291 raise ValueError, "1./nTxs (=%f), should be a multiple of nProfiles (=%d)" %(1./self.nTxs, self.processingHeaderObj.profilesPerBlock)
301 raise ValueError, "1./nTxs (=%f), should be a multiple of nProfiles (=%d)" %(1./self.nTxs, self.processingHeaderObj.profilesPerBlock)
292
302
293 if self.nTxs > 1 and self.processingHeaderObj.nHeights % self.nTxs != 0:
303 if self.nTxs > 1 and self.processingHeaderObj.nHeights % self.nTxs != 0:
294 raise ValueError, "nTxs (=%d), should be a multiple of nHeights (=%d)" %(self.nTxs, self.processingHeaderObj.nHeights)
304 raise ValueError, "nTxs (=%d), should be a multiple of nHeights (=%d)" %(self.nTxs, self.processingHeaderObj.nHeights)
295
305
296 self.datablock = self.datablock.reshape((self.systemHeaderObj.nChannels, self.processingHeaderObj.profilesPerBlock*self.nTxs, self.processingHeaderObj.nHeights/self.nTxs))
306 self.datablock = self.datablock.reshape((self.systemHeaderObj.nChannels, self.processingHeaderObj.profilesPerBlock*self.nTxs, self.processingHeaderObj.nHeights/self.nTxs))
297
307
298 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock*self.nTxs
308 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock*self.nTxs
299 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.nHeights/self.nTxs) *self.processingHeaderObj.deltaHeight + self.processingHeaderObj.firstHeight
309 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.nHeights/self.nTxs) *self.processingHeaderObj.deltaHeight + self.processingHeaderObj.firstHeight
300 self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds/self.nTxs
310 self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds/self.nTxs
301
311
302 return
312 return
303
313
314 def readFirstHeaderFromServer(self):
315
316 self.getFirstHeader()
317
318 self.firstHeaderSize = self.basicHeaderObj.size
319
320 datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
321 if datatype == 0:
322 datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')])
323 elif datatype == 1:
324 datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')])
325 elif datatype == 2:
326 datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')])
327 elif datatype == 3:
328 datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')])
329 elif datatype == 4:
330 datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')])
331 elif datatype == 5:
332 datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')])
333 else:
334 raise ValueError, 'Data type was not defined'
335
336 self.dtype = datatype_str
337 #self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c
338 self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1)
339 # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels)
340 # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels)
341 self.getBlockDimension()
342
343
344 def getFromServer(self):
345 self.flagDiscontinuousBlock = 0
346 self.profileIndex = 0
347 self.flagIsNewBlock = 1
348 self.dataOut.flagNoData = False
349 self.nTotalBlocks += 1
350 self.nReadBlocks += 1
351 self.blockPointer = 0
352
353 block = self.receiver.recv()
354
355 self.basicHeaderObj.read(block[self.blockPointer:])
356 self.blockPointer += self.basicHeaderObj.length
357 self.systemHeaderObj.read(block[self.blockPointer:])
358 self.blockPointer += self.systemHeaderObj.length
359 self.radarControllerHeaderObj.read(block[self.blockPointer:])
360 self.blockPointer += self.radarControllerHeaderObj.length
361 self.processingHeaderObj.read(block[self.blockPointer:])
362 self.blockPointer += self.processingHeaderObj.length
363 self.readFirstHeaderFromServer()
364
365 timestamp = self.basicHeaderObj.get_datatime()
366 print '[Reading] - Block {} - {}'.format(self.nTotalBlocks, timestamp)
367 current_pointer_location = self.blockPointer
368 junk = numpy.fromstring( block[self.blockPointer:], self.dtype, self.blocksize )
369
370 try:
371 junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) )
372 except:
373 #print "The read block (%3d) has not enough data" %self.nReadBlocks
374 if self.waitDataBlock(pointer_location=current_pointer_location):
375 junk = numpy.fromstring( block[self.blockPointer:], self.dtype, self.blocksize )
376 junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) )
377 # return 0
378
379 #Dimensions : nChannels, nProfiles, nSamples
380
381 junk = numpy.transpose(junk, (2,0,1))
382 self.datablock = junk['real'] + junk['imag'] * 1j
383 self.profileIndex = 0
384 if self.selBlocksize == None: self.selBlocksize = self.dataOut.nProfiles
385 if self.selBlocktime != None:
386 if self.dataOut.nCohInt is not None:
387 nCohInt = self.dataOut.nCohInt
388 else:
389 nCohInt = 1
390 self.selBlocksize = int(self.dataOut.nProfiles*round(self.selBlocktime/(nCohInt*self.dataOut.ippSeconds*self.dataOut.nProfiles)))
391 self.dataOut.data = self.datablock[:,self.profileIndex:self.profileIndex+self.selBlocksize,:]
392 datasize = self.dataOut.data.shape[1]
393 if datasize < self.selBlocksize:
394 buffer = numpy.zeros((self.dataOut.data.shape[0], self.selBlocksize, self.dataOut.data.shape[2]), dtype = 'complex')
395 buffer[:,:datasize,:] = self.dataOut.data
396 self.dataOut.data = buffer
397 self.profileIndex = blockIndex
398
399 self.dataOut.flagDataAsBlock = True
400 self.flagIsNewBlock = 1
401 self.dataOut.realtime = self.online
402
403 return self.dataOut.data
404
304 def getData(self):
405 def getData(self):
305 """
406 """
306 getData obtiene una unidad de datos del buffer de lectura, un perfil, y la copia al objeto self.dataOut
407 getData obtiene una unidad de datos del buffer de lectura, un perfil, y la copia al objeto self.dataOut
307 del tipo "Voltage" con todos los parametros asociados a este (metadata). cuando no hay datos
408 del tipo "Voltage" con todos los parametros asociados a este (metadata). cuando no hay datos
308 en el buffer de lectura es necesario hacer una nueva lectura de los bloques de datos usando
409 en el buffer de lectura es necesario hacer una nueva lectura de los bloques de datos usando
309 "readNextBlock"
410 "readNextBlock"
310
311 Ademas incrementa el contador del buffer "self.profileIndex" en 1.
312
313 Return:
314
315 Si el flag self.getByBlock ha sido seteado el bloque completo es copiado a self.dataOut y el self.profileIndex
316 es igual al total de perfiles leidos desde el archivo.
317
318 Si self.getByBlock == False:
319
411
320 self.dataOut.data = buffer[:, thisProfile, :]
412 Ademas incrementa el contador del buffer "self.profileIndex" en 1.
321
322 shape = [nChannels, nHeis]
323
324 Si self.getByBlock == True:
325
413
326 self.dataOut.data = buffer[:, :, :]
414 Return:
327
328 shape = [nChannels, nProfiles, nHeis]
329
415
330 Variables afectadas:
416 Si el flag self.getByBlock ha sido seteado el bloque completo es copiado a self.dataOut y el self.profileIndex
331 self.dataOut
417 es igual al total de perfiles leidos desde el archivo.
332 self.profileIndex
333
418
334 Affected:
419 Si self.getByBlock == False:
335 self.dataOut
420
336 self.profileIndex
421 self.dataOut.data = buffer[:, thisProfile, :]
337 self.flagDiscontinuousBlock
422
338 self.flagIsNewBlock
423 shape = [nChannels, nHeis]
424
425 Si self.getByBlock == True:
426
427 self.dataOut.data = buffer[:, :, :]
428
429 shape = [nChannels, nProfiles, nHeis]
430
431 Variables afectadas:
432 self.dataOut
433 self.profileIndex
434
435 Affected:
436 self.dataOut
437 self.profileIndex
438 self.flagDiscontinuousBlock
439 self.flagIsNewBlock
339 """
440 """
340
441
341 if self.flagNoMoreFiles:
442 if self.flagNoMoreFiles:
342 self.dataOut.flagNoData = True
443 self.dataOut.flagNoData = True
343 print 'Process finished'
444 print 'Process finished'
344 return 0
445 return 0
345
446
346 self.flagDiscontinuousBlock = 0
447 self.flagDiscontinuousBlock = 0
347 self.flagIsNewBlock = 0
448 self.flagIsNewBlock = 0
348
449
349 if self.__hasNotDataInBuffer():
450 if self.__hasNotDataInBuffer():
350
451
351 if not( self.readNextBlock() ):
452 if not( self.readNextBlock() ):
352 return 0
453 return 0
353
454
354 self.getFirstHeader()
455 self.getFirstHeader()
355
456
356 self.reshapeData()
457 self.reshapeData()
357
458
358 if self.datablock is None:
459 if self.datablock is None:
359 self.dataOut.flagNoData = True
460 self.dataOut.flagNoData = True
360 return 0
461 return 0
361
462
362 if not self.getByBlock:
463 if not self.getByBlock:
363
464
364 """
465 """
365 Return profile by profile
466 Return profile by profile
366
467
367 If nTxs > 1 then one profile is divided by nTxs and number of total
468 If nTxs > 1 then one profile is divided by nTxs and number of total
368 blocks is increased by nTxs (nProfiles *= nTxs)
469 blocks is increased by nTxs (nProfiles *= nTxs)
369 """
470 """
370 self.dataOut.flagDataAsBlock = False
471 self.dataOut.flagDataAsBlock = False
371 self.dataOut.data = self.datablock[:,self.profileIndex,:]
472 self.dataOut.data = self.datablock[:,self.profileIndex,:]
372 self.dataOut.profileIndex = self.profileIndex
473 self.dataOut.profileIndex = self.profileIndex
373
474
374 self.profileIndex += 1
475 self.profileIndex += 1
375
476
376 # elif self.selBlocksize==None or self.selBlocksize==self.dataOut.nProfiles:
477 # elif self.selBlocksize==None or self.selBlocksize==self.dataOut.nProfiles:
377 # """
478 # """
378 # Return all block
479 # Return all block
379 # """
480 # """
380 # self.dataOut.flagDataAsBlock = True
481 # self.dataOut.flagDataAsBlock = True
381 # self.dataOut.data = self.datablock
482 # self.dataOut.data = self.datablock
382 # self.dataOut.profileIndex = self.dataOut.nProfiles - 1
483 # self.dataOut.profileIndex = self.dataOut.nProfiles - 1
383 #
484 #
384 # self.profileIndex = self.dataOut.nProfiles
485 # self.profileIndex = self.dataOut.nProfiles
385
486
386 else:
487 else:
387 """
488 """
388 Return a block
489 Return a block
389 """
490 """
390 if self.selBlocksize == None: self.selBlocksize = self.dataOut.nProfiles
491 if self.selBlocksize == None: self.selBlocksize = self.dataOut.nProfiles
391 if self.selBlocktime != None:
492 if self.selBlocktime != None:
392 if self.dataOut.nCohInt is not None:
493 if self.dataOut.nCohInt is not None:
393 nCohInt = self.dataOut.nCohInt
494 nCohInt = self.dataOut.nCohInt
394 else:
495 else:
395 nCohInt = 1
496 nCohInt = 1
396 self.selBlocksize = int(self.dataOut.nProfiles*round(self.selBlocktime/(nCohInt*self.dataOut.ippSeconds*self.dataOut.nProfiles)))
497 self.selBlocksize = int(self.dataOut.nProfiles*round(self.selBlocktime/(nCohInt*self.dataOut.ippSeconds*self.dataOut.nProfiles)))
397
498
398 self.dataOut.data = self.datablock[:,self.profileIndex:self.profileIndex+self.selBlocksize,:]
499 self.dataOut.data = self.datablock[:,self.profileIndex:self.profileIndex+self.selBlocksize,:]
399 self.profileIndex += self.selBlocksize
500 self.profileIndex += self.selBlocksize
400 datasize = self.dataOut.data.shape[1]
501 datasize = self.dataOut.data.shape[1]
401
502
402 if datasize < self.selBlocksize:
503 if datasize < self.selBlocksize:
403 buffer = numpy.zeros((self.dataOut.data.shape[0],self.selBlocksize,self.dataOut.data.shape[2]), dtype = 'complex')
504 buffer = numpy.zeros((self.dataOut.data.shape[0],self.selBlocksize,self.dataOut.data.shape[2]), dtype = 'complex')
404 buffer[:,:datasize,:] = self.dataOut.data
505 buffer[:,:datasize,:] = self.dataOut.data
405
506
406 while datasize < self.selBlocksize: #Not enough profiles to fill the block
507 while datasize < self.selBlocksize: #Not enough profiles to fill the block
407 if not( self.readNextBlock() ):
508 if not( self.readNextBlock() ):
408 return 0
509 return 0
409 self.getFirstHeader()
510 self.getFirstHeader()
410 self.reshapeData()
511 self.reshapeData()
411 if self.datablock is None:
512 if self.datablock is None:
412 self.dataOut.flagNoData = True
513 self.dataOut.flagNoData = True
413 return 0
514 return 0
414 #stack data
515 #stack data
415 blockIndex = self.selBlocksize - datasize
516 blockIndex = self.selBlocksize - datasize
416 datablock1 = self.datablock[:,:blockIndex,:]
517 datablock1 = self.datablock[:,:blockIndex,:]
417
518
418 buffer[:,datasize:datasize+datablock1.shape[1],:] = datablock1
519 buffer[:,datasize:datasize+datablock1.shape[1],:] = datablock1
419 datasize += datablock1.shape[1]
520 datasize += datablock1.shape[1]
420
521
421 self.dataOut.data = buffer
522 self.dataOut.data = buffer
422 self.profileIndex = blockIndex
523 self.profileIndex = blockIndex
423
524
424 self.dataOut.flagDataAsBlock = True
525 self.dataOut.flagDataAsBlock = True
425 self.dataOut.nProfiles = self.dataOut.data.shape[1]
526 self.dataOut.nProfiles = self.dataOut.data.shape[1]
426
527
427 self.dataOut.flagNoData = False
528 self.dataOut.flagNoData = False
428
529
429 self.getBasicHeader()
530 self.getBasicHeader()
430
531
431 self.dataOut.realtime = self.online
532 self.dataOut.realtime = self.online
432
533
433 return self.dataOut.data
534 return self.dataOut.data
434
535
435 class VoltageWriter(JRODataWriter, Operation):
536 class VoltageWriter(JRODataWriter, Operation):
436 """
537 """
437 Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura
538 Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura
438 de los datos siempre se realiza por bloques.
539 de los datos siempre se realiza por bloques.
439 """
540 """
440
541
441 ext = ".r"
542 ext = ".r"
442
543
443 optchar = "D"
544 optchar = "D"
444
545
445 shapeBuffer = None
546 shapeBuffer = None
446
547
447
548
448 def __init__(self):
549 def __init__(self):
449 """
550 """
450 Inicializador de la clase VoltageWriter para la escritura de datos de espectros.
551 Inicializador de la clase VoltageWriter para la escritura de datos de espectros.
451
552
452 Affected:
553 Affected:
453 self.dataOut
554 self.dataOut
454
555
455 Return: None
556 Return: None
456 """
557 """
457 Operation.__init__(self)
558 Operation.__init__(self)
458
559
459 self.nTotalBlocks = 0
560 self.nTotalBlocks = 0
460
561
461 self.profileIndex = 0
562 self.profileIndex = 0
462
563
463 self.isConfig = False
564 self.isConfig = False
464
565
465 self.fp = None
566 self.fp = None
466
567
467 self.flagIsNewFile = 1
568 self.flagIsNewFile = 1
468
569
469 self.blockIndex = 0
570 self.blockIndex = 0
470
571
471 self.flagIsNewBlock = 0
572 self.flagIsNewBlock = 0
472
573
473 self.setFile = None
574 self.setFile = None
474
575
475 self.dtype = None
576 self.dtype = None
476
577
477 self.path = None
578 self.path = None
478
579
479 self.filename = None
580 self.filename = None
480
581
481 self.basicHeaderObj = BasicHeader(LOCALTIME)
582 self.basicHeaderObj = BasicHeader(LOCALTIME)
482
583
483 self.systemHeaderObj = SystemHeader()
584 self.systemHeaderObj = SystemHeader()
484
585
485 self.radarControllerHeaderObj = RadarControllerHeader()
586 self.radarControllerHeaderObj = RadarControllerHeader()
486
587
487 self.processingHeaderObj = ProcessingHeader()
588 self.processingHeaderObj = ProcessingHeader()
488
589
489 def hasAllDataInBuffer(self):
590 def hasAllDataInBuffer(self):
490 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock:
591 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock:
491 return 1
592 return 1
492 return 0
593 return 0
493
594
494
595
495 def setBlockDimension(self):
596 def setBlockDimension(self):
496 """
597 """
497 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
598 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
498
599
499 Affected:
600 Affected:
500 self.shape_spc_Buffer
601 self.shape_spc_Buffer
501 self.shape_cspc_Buffer
602 self.shape_cspc_Buffer
502 self.shape_dc_Buffer
603 self.shape_dc_Buffer
503
604
504 Return: None
605 Return: None
505 """
606 """
506 self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock,
607 self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock,
507 self.processingHeaderObj.nHeights,
608 self.processingHeaderObj.nHeights,
508 self.systemHeaderObj.nChannels)
609 self.systemHeaderObj.nChannels)
509
610
510 self.datablock = numpy.zeros((self.systemHeaderObj.nChannels,
611 self.datablock = numpy.zeros((self.systemHeaderObj.nChannels,
511 self.processingHeaderObj.profilesPerBlock,
612 self.processingHeaderObj.profilesPerBlock,
512 self.processingHeaderObj.nHeights),
613 self.processingHeaderObj.nHeights),
513 dtype=numpy.dtype('complex64'))
614 dtype=numpy.dtype('complex64'))
514
615
515 def writeBlock(self):
616 def writeBlock(self):
516 """
617 """
517 Escribe el buffer en el file designado
618 Escribe el buffer en el file designado
518
619
519 Affected:
620 Affected:
520 self.profileIndex
621 self.profileIndex
521 self.flagIsNewFile
622 self.flagIsNewFile
522 self.flagIsNewBlock
623 self.flagIsNewBlock
523 self.nTotalBlocks
624 self.nTotalBlocks
524 self.blockIndex
625 self.blockIndex
525
626
526 Return: None
627 Return: None
527 """
628 """
528 data = numpy.zeros( self.shapeBuffer, self.dtype )
629 data = numpy.zeros( self.shapeBuffer, self.dtype )
529
630
530 junk = numpy.transpose(self.datablock, (1,2,0))
631 junk = numpy.transpose(self.datablock, (1,2,0))
531
632
532 data['real'] = junk.real
633 data['real'] = junk.real
533 data['imag'] = junk.imag
634 data['imag'] = junk.imag
534
635
535 data = data.reshape( (-1) )
636 data = data.reshape( (-1) )
536
637
537 data.tofile( self.fp )
638 data.tofile( self.fp )
538
639
539 self.datablock.fill(0)
640 self.datablock.fill(0)
540
641
541 self.profileIndex = 0
642 self.profileIndex = 0
542 self.flagIsNewFile = 0
643 self.flagIsNewFile = 0
543 self.flagIsNewBlock = 1
644 self.flagIsNewBlock = 1
544
645
545 self.blockIndex += 1
646 self.blockIndex += 1
546 self.nTotalBlocks += 1
647 self.nTotalBlocks += 1
547
648
548 # print "[Writing] Block = %04d" %self.blockIndex
649 # print "[Writing] Block = %04d" %self.blockIndex
549
650
550 def putData(self):
651 def putData(self):
551 """
652 """
552 Setea un bloque de datos y luego los escribe en un file
653 Setea un bloque de datos y luego los escribe en un file
553
654
554 Affected:
655 Affected:
555 self.flagIsNewBlock
656 self.flagIsNewBlock
556 self.profileIndex
657 self.profileIndex
557
658
558 Return:
659 Return:
559 0 : Si no hay data o no hay mas files que puedan escribirse
660 0 : Si no hay data o no hay mas files que puedan escribirse
560 1 : Si se escribio la data de un bloque en un file
661 1 : Si se escribio la data de un bloque en un file
561 """
662 """
562 if self.dataOut.flagNoData:
663 if self.dataOut.flagNoData:
563 return 0
664 return 0
564
665
565 self.flagIsNewBlock = 0
666 self.flagIsNewBlock = 0
566
667
567 if self.dataOut.flagDiscontinuousBlock:
668 if self.dataOut.flagDiscontinuousBlock:
568 self.datablock.fill(0)
669 self.datablock.fill(0)
569 self.profileIndex = 0
670 self.profileIndex = 0
570 self.setNextFile()
671 self.setNextFile()
571
672
572 if self.profileIndex == 0:
673 if self.profileIndex == 0:
573 self.setBasicHeader()
674 self.setBasicHeader()
574
675
575 self.datablock[:,self.profileIndex,:] = self.dataOut.data
676 self.datablock[:,self.profileIndex,:] = self.dataOut.data
576
677
577 self.profileIndex += 1
678 self.profileIndex += 1
578
679
579 if self.hasAllDataInBuffer():
680 if self.hasAllDataInBuffer():
580 #if self.flagIsNewFile:
681 #if self.flagIsNewFile:
581 self.writeNextBlock()
682 self.writeNextBlock()
582 # self.setFirstHeader()
683 # self.setFirstHeader()
583
684
584 return 1
685 return 1
585
686
586 def __getBlockSize(self):
687 def __getBlockSize(self):
587 '''
688 '''
588 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage
689 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage
589 '''
690 '''
590
691
591 dtype_width = self.getDtypeWidth()
692 dtype_width = self.getDtypeWidth()
592
693
593 blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels * self.profilesPerBlock * dtype_width * 2)
694 blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels * self.profilesPerBlock * dtype_width * 2)
594
695
595 return blocksize
696 return blocksize
596
697
597 def setFirstHeader(self):
698 def setFirstHeader(self):
598
699
599 """
700 """
600 Obtiene una copia del First Header
701 Obtiene una copia del First Header
601
702
602 Affected:
703 Affected:
603 self.systemHeaderObj
704 self.systemHeaderObj
604 self.radarControllerHeaderObj
705 self.radarControllerHeaderObj
605 self.dtype
706 self.dtype
606
707
607 Return:
708 Return:
608 None
709 None
609 """
710 """
610
711
611 self.systemHeaderObj = self.dataOut.systemHeaderObj.copy()
712 self.systemHeaderObj = self.dataOut.systemHeaderObj.copy()
612 self.systemHeaderObj.nChannels = self.dataOut.nChannels
713 self.systemHeaderObj.nChannels = self.dataOut.nChannels
613 self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy()
714 self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy()
614
715
615 self.processingHeaderObj.dtype = 0 # Voltage
716 self.processingHeaderObj.dtype = 0 # Voltage
616 self.processingHeaderObj.blockSize = self.__getBlockSize()
717 self.processingHeaderObj.blockSize = self.__getBlockSize()
617 self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock
718 self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock
618 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
719 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
619 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows
720 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows
620 self.processingHeaderObj.nCohInt = self.dataOut.nCohInt
721 self.processingHeaderObj.nCohInt = self.dataOut.nCohInt
621 self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage
722 self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage
622 self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage
723 self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage
623
724
624 if self.dataOut.code is not None:
725 if self.dataOut.code is not None:
625 self.processingHeaderObj.code = self.dataOut.code
726 self.processingHeaderObj.code = self.dataOut.code
626 self.processingHeaderObj.nCode = self.dataOut.nCode
727 self.processingHeaderObj.nCode = self.dataOut.nCode
627 self.processingHeaderObj.nBaud = self.dataOut.nBaud
728 self.processingHeaderObj.nBaud = self.dataOut.nBaud
628
729
629 if self.processingHeaderObj.nWindows != 0:
730 if self.processingHeaderObj.nWindows != 0:
630 self.processingHeaderObj.firstHeight = self.dataOut.heightList[0]
731 self.processingHeaderObj.firstHeight = self.dataOut.heightList[0]
631 self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
732 self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
632 self.processingHeaderObj.nHeights = self.dataOut.nHeights
733 self.processingHeaderObj.nHeights = self.dataOut.nHeights
633 self.processingHeaderObj.samplesWin = self.dataOut.nHeights
734 self.processingHeaderObj.samplesWin = self.dataOut.nHeights
634
735
635 self.processingHeaderObj.processFlags = self.getProcessFlags()
736 self.processingHeaderObj.processFlags = self.getProcessFlags()
636
737
637 self.setBasicHeader() No newline at end of file
738 self.setBasicHeader()
@@ -1,58 +1,139
1 #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
2 #define NUM_CPY_THREADS 8
1 #include <Python.h>
3 #include <Python.h>
2 #include <numpy/arrayobject.h>
4 #include <numpy/arrayobject.h>
3 #include <math.h>
5 #include <math.h>
6 #include <complex.h>
7 #include <time.h>
4
8
9 // void printArr(int *array);
5 static PyObject *hildebrand_sekhon(PyObject *self, PyObject *args);
10 static PyObject *hildebrand_sekhon(PyObject *self, PyObject *args);
11 static PyObject *correlateByBlock(PyObject *self, PyObject *args);
12 #ifndef PyMODINIT_FUNC /* declarations for DLL import/export */
13 #define PyMODINIT_FUNC void
14 #endif
6
15
7 static PyMethodDef extensionsMethods[] = {
16 static PyMethodDef extensionsMethods[] = {
8 { "hildebrand_sekhon", (PyCFunction)hildebrand_sekhon, METH_VARARGS, "get noise with" },
17 { "correlateByBlock", (PyCFunction)correlateByBlock, METH_VARARGS, "get correlation by block" },
9 { NULL, NULL, 0, NULL }
18 { "hildebrand_sekhon", (PyCFunction)hildebrand_sekhon, METH_VARARGS, "get noise with hildebrand_sekhon" },
19 { NULL, NULL, 0, NULL }
10 };
20 };
11
21
12 PyMODINIT_FUNC initcSchain() {
22 PyMODINIT_FUNC initcSchain() {
13 Py_InitModule("cSchain", extensionsMethods);
23 Py_InitModule("cSchain", extensionsMethods);
14 import_array();
24 import_array();
15 }
25 }
16
26
27 static PyObject *correlateByBlock(PyObject *self, PyObject *args) {
28
29 // int *x = (int*) malloc(4000000 * 216 * sizeof(int));;
30 // int a = 5;
31 // x = &a;
32 // int b = 6;
33 // x = &b;
34 // printf("Antes de imprimir x \n");
35 // printf("%d \n", x[0]);
36
37 PyObject *data_obj1, *data_obj2;
38 PyArrayObject *data_array1, *data_array2, *correlateRow, *out, *dataRow, *codeRow; //, ,
39 int mode;
40
41 if (!PyArg_ParseTuple(args, "OOi", &data_obj1, &data_obj2, &mode)) return NULL;
42
43 data_array1 = (PyArrayObject *) PyArray_FROM_OTF(data_obj1, NPY_COMPLEX128, NPY_ARRAY_DEFAULT);
44 data_array2 = (PyArrayObject *) PyArray_FROM_OTF(data_obj2, NPY_FLOAT64, NPY_ARRAY_DEFAULT);
45
46 npy_intp dims[1];
47 dims[0] = 200;
48 npy_intp dims_code[1];
49 dims_code[0] = 16;
50
51 double complex * dataRaw;
52 double * codeRaw;
53 dataRaw = (double complex*) PyArray_DATA(data_array1);
54 codeRaw = (double *) PyArray_DATA(data_array2);
55 double complex ** outC = malloc(40000*200*sizeof(double complex));
56 int i;
57
58 clock_t start = clock();
59 for(i=0; i<40000; i++){
60 // codeRow = PyArray_SimpleNewFromData(1, dims_code, NPY_FLOAT64, codeRaw + 16 * i);
61 // dataRow = PyArray_SimpleNewFromData(1, dims, NPY_COMPLEX128, dataRaw + 200 * i);
62 // Py_INCREF(codeRow);
63 // Py_INCREF(dataRow);
64 // PyArray_ENABLEFLAGS(codeRow, NPY_ARRAY_OWNDATA);
65 // PyArray_ENABLEFLAGS(dataRow, NPY_ARRAY_OWNDATA);
66 correlateRow = (PyArrayObject *) PyArray_Correlate2(PyArray_SimpleNewFromData(1, dims_code, NPY_FLOAT64, codeRaw + 16 * i), PyArray_SimpleNewFromData(1, dims, NPY_COMPLEX128, dataRaw + 200 * i), (npy_intp) 2);
67 //Py_INCREF(correlateRow);
68 // PyArray_ENABLEFLAGS(correlateRow, NPY_ARRAY_OWNDATA);
69 memcpy(outC + 200*i, (double complex*) PyArray_DATA(correlateRow), 200 * sizeof(double complex));
70
71 Py_DECREF(correlateRow);
72 // Py_DECREF(codeRow);
73 // Py_DECREF(dataRow);
74 }
75 clock_t end = clock();
76 float seconds = (float)(end - start) / CLOCKS_PER_SEC;
77 printf("%f", seconds);
78 //
79 npy_intp dimsret[2];
80 dimsret[0] = 40000;
81 dimsret[1] = 200;
82 out = PyArray_SimpleNewFromData(2, dimsret, NPY_COMPLEX128, outC);
83 PyArray_ENABLEFLAGS(out, NPY_ARRAY_OWNDATA);
84 //Py_INCREF(out);
85 Py_DECREF(data_array1);
86 Py_DECREF(data_array2);
87 // PyArray_DebugPrint(out);
88 // Py_DECREF(data_obj2);
89 // Py_DECREF(data_obj1);
90 // Py_DECREF(codeRow);
91 // Py_DECREF(dataRow);
92 // free(dataRaw);
93 // free(codeRaw);
94
95 return PyArray_Return(out);
96 }
97
17 static PyObject *hildebrand_sekhon(PyObject *self, PyObject *args) {
98 static PyObject *hildebrand_sekhon(PyObject *self, PyObject *args) {
18 /* Do your stuff here. */
19 double navg;
99 double navg;
20 PyObject *data_obj, *data_array;
100 PyObject *data_obj, *data_array;
21
101
22 if (!PyArg_ParseTuple(args, "Od", &data_obj, &navg)) return NULL;
102 if (!PyArg_ParseTuple(args, "Od", &data_obj, &navg)) return NULL;
23 data_array = PyArray_FROM_OTF(data_obj, NPY_FLOAT64, NPY_IN_ARRAY);
103 data_array = PyArray_FROM_OTF(data_obj, NPY_FLOAT64, NPY_ARRAY_DEFAULT);
24 if (data_array == NULL) {
104 if (data_array == NULL) {
25 Py_XDECREF(data_array);
105 Py_XDECREF(data_array);
26 Py_XDECREF(data_obj);
106 Py_XDECREF(data_obj);
27 return NULL;
107 return NULL;
28 }
108 }
29 double *sortdata = (double*)PyArray_DATA(data_array);
109 double *sortdata = (double*)PyArray_DATA(data_array);
30 int lenOfData = (int)PyArray_SIZE(data_array) ;
110 int lenOfData = (int)PyArray_SIZE(data_array) ;
31 double nums_min = lenOfData*0.2;
111 double nums_min = lenOfData*0.2;
32 if (nums_min <= 5) nums_min = 5;
112 if (nums_min <= 5) nums_min = 5;
33 double sump = 0;
113 double sump = 0;
34 double sumq = 0;
114 double sumq = 0;
35 int j = 0;
115 int j = 0;
36 int cont = 1;
116 int cont = 1;
37 double rtest = 0;
117 double rtest = 0;
38 while ((cont == 1) && (j < lenOfData)) {
118 while ((cont == 1) && (j < lenOfData)) {
39 sump = sump + sortdata[j];
119 sump = sump + sortdata[j];
40 sumq = sumq + pow(sortdata[j], 2);
120 sumq = sumq + pow(sortdata[j], 2);
41 if (j > nums_min) {
121 if (j > nums_min) {
42 rtest = (double)j/(j-1) + 1/navg;
122 rtest = (double)j/(j-1) + 1/navg;
43 if ((sumq*j) > (rtest*pow(sump, 2))) {
123 if ((sumq*j) > (rtest*pow(sump, 2))) {
44 j = j - 1;
124 j = j - 1;
45 sump = sump - sortdata[j];
125 sump = sump - sortdata[j];
46 sumq = sumq - pow(sortdata[j],2);
126 sumq = sumq - pow(sortdata[j],2);
47 cont = 0;
127 cont = 0;
48 }
128 }
49 }
129 }
50 j = j + 1;
130 j = j + 1;
51 }
131 }
52
132
53 double lnoise = sump / j;
133 double lnoise = sump / j;
54
134
55 Py_DECREF(data_array);
135 Py_DECREF(data_array);
56
136
57 return Py_BuildValue("d", lnoise);
137 return Py_BuildValue("d", lnoise);
58 }
138 }
139
@@ -1,349 +1,348
1 '''
1 '''
2
2
3 $Author: murco $
3 $Author: murco $
4 $Id: jroproc_base.py 1 2012-11-12 18:56:07Z murco $
4 $Id: jroproc_base.py 1 2012-11-12 18:56:07Z murco $
5 '''
5 '''
6 import inspect
6 import inspect
7 from fuzzywuzzy import process
7 from fuzzywuzzy import process
8
8
9 def checkKwargs(method, kwargs):
9 def checkKwargs(method, kwargs):
10 currentKwargs = kwargs
10 currentKwargs = kwargs
11 choices = inspect.getargspec(method).args
11 choices = inspect.getargspec(method).args
12 try:
12 try:
13 choices.remove('self')
13 choices.remove('self')
14 except Exception as e:
14 except Exception as e:
15 pass
15 pass
16
16
17 try:
17 try:
18 choices.remove('dataOut')
18 choices.remove('dataOut')
19 except Exception as e:
19 except Exception as e:
20 pass
20 pass
21
21
22 for kwarg in kwargs:
22 for kwarg in kwargs:
23 fuzz = process.extractOne(kwarg, choices)
23 fuzz = process.extractOne(kwarg, choices)
24 if fuzz is None:
24 if fuzz is None:
25 continue
25 continue
26 if fuzz[1] < 100:
26 if fuzz[1] < 100:
27 raise Exception('\x1b[0;32;40mDid you mean {} instead of {} in {}? \x1b[0m'.
27 raise Exception('\x1b[0;32;40mDid you mean {} instead of {} in {}? \x1b[0m'.
28 format(fuzz[0], kwarg, method.__self__.__class__.__name__))
28 format(fuzz[0], kwarg, method.__self__.__class__.__name__))
29
29
30 class ProcessingUnit(object):
30 class ProcessingUnit(object):
31
31
32 """
32 """
33 Esta es la clase base para el procesamiento de datos.
33 Esta es la clase base para el procesamiento de datos.
34
34
35 Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser:
35 Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser:
36 - Metodos internos (callMethod)
36 - Metodos internos (callMethod)
37 - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos
37 - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos
38 tienen que ser agreagados con el metodo "add".
38 tienen que ser agreagados con el metodo "add".
39
39
40 """
40 """
41 # objeto de datos de entrada (Voltage, Spectra o Correlation)
41 # objeto de datos de entrada (Voltage, Spectra o Correlation)
42 dataIn = None
42 dataIn = None
43 dataInList = []
43 dataInList = []
44
44
45 # objeto de datos de entrada (Voltage, Spectra o Correlation)
45 # objeto de datos de entrada (Voltage, Spectra o Correlation)
46 dataOut = None
46 dataOut = None
47
47
48 operations2RunDict = None
48 operations2RunDict = None
49
49
50 isConfig = False
50 isConfig = False
51
51
52
52
53 def __init__(self, *args, **kwargs):
53 def __init__(self, *args, **kwargs):
54
54
55 self.dataIn = None
55 self.dataIn = None
56 self.dataInList = []
56 self.dataInList = []
57
57
58 self.dataOut = None
58 self.dataOut = None
59
59
60 self.operations2RunDict = {}
60 self.operations2RunDict = {}
61 self.operationKwargs = {}
61 self.operationKwargs = {}
62
62
63 self.isConfig = False
63 self.isConfig = False
64
64
65 self.args = args
65 self.args = args
66 self.kwargs = kwargs
66 self.kwargs = kwargs
67 checkKwargs(self.run, kwargs)
67 checkKwargs(self.run, kwargs)
68
68
69 def getAllowedArgs(self):
69 def getAllowedArgs(self):
70 return inspect.getargspec(self.run).args
70 return inspect.getargspec(self.run).args
71
71
72 def addOperationKwargs(self, objId, **kwargs):
72 def addOperationKwargs(self, objId, **kwargs):
73 '''
73 '''
74 '''
74 '''
75
75
76 self.operationKwargs[objId] = kwargs
76 self.operationKwargs[objId] = kwargs
77
77
78
78
79 def addOperation(self, opObj, objId):
79 def addOperation(self, opObj, objId):
80
80
81 """
81 """
82 Agrega un objeto del tipo "Operation" (opObj) a la lista de objetos "self.objectList" y retorna el
82 Agrega un objeto del tipo "Operation" (opObj) a la lista de objetos "self.objectList" y retorna el
83 identificador asociado a este objeto.
83 identificador asociado a este objeto.
84
84
85 Input:
85 Input:
86
86
87 object : objeto de la clase "Operation"
87 object : objeto de la clase "Operation"
88
88
89 Return:
89 Return:
90
90
91 objId : identificador del objeto, necesario para ejecutar la operacion
91 objId : identificador del objeto, necesario para ejecutar la operacion
92 """
92 """
93
93
94 self.operations2RunDict[objId] = opObj
94 self.operations2RunDict[objId] = opObj
95
95
96 return objId
96 return objId
97
97
98 def getOperationObj(self, objId):
98 def getOperationObj(self, objId):
99
99
100 if objId not in self.operations2RunDict.keys():
100 if objId not in self.operations2RunDict.keys():
101 return None
101 return None
102
102
103 return self.operations2RunDict[objId]
103 return self.operations2RunDict[objId]
104
104
105 def operation(self, **kwargs):
105 def operation(self, **kwargs):
106
106
107 """
107 """
108 Operacion directa sobre la data (dataOut.data). Es necesario actualizar los valores de los
108 Operacion directa sobre la data (dataOut.data). Es necesario actualizar los valores de los
109 atributos del objeto dataOut
109 atributos del objeto dataOut
110
110
111 Input:
111 Input:
112
112
113 **kwargs : Diccionario de argumentos de la funcion a ejecutar
113 **kwargs : Diccionario de argumentos de la funcion a ejecutar
114 """
114 """
115
115
116 raise NotImplementedError
116 raise NotImplementedError
117
117
118 def callMethod(self, name, opId):
118 def callMethod(self, name, opId):
119
119
120 """
120 """
121 Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase.
121 Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase.
122
122
123 Input:
123 Input:
124 name : nombre del metodo a ejecutar
124 name : nombre del metodo a ejecutar
125
125
126 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
126 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
127
127
128 """
128 """
129
129
130 #Checking the inputs
130 #Checking the inputs
131 if name == 'run':
131 if name == 'run':
132
132
133 if not self.checkInputs():
133 if not self.checkInputs():
134 self.dataOut.flagNoData = True
134 self.dataOut.flagNoData = True
135 return False
135 return False
136 else:
136 else:
137 #Si no es un metodo RUN la entrada es la misma dataOut (interna)
137 #Si no es un metodo RUN la entrada es la misma dataOut (interna)
138 if self.dataOut is not None and self.dataOut.isEmpty():
138 if self.dataOut is not None and self.dataOut.isEmpty():
139 return False
139 return False
140
140
141 #Getting the pointer to method
141 #Getting the pointer to method
142 methodToCall = getattr(self, name)
142 methodToCall = getattr(self, name)
143
143
144 #Executing the self method
144 #Executing the self method
145
145
146 if hasattr(self, 'mp'):
146 if hasattr(self, 'mp'):
147 if name=='run':
147 if name=='run':
148 if self.mp is False:
148 if self.mp is False:
149 self.mp = True
149 self.mp = True
150 self.start()
150 self.start()
151 else:
151 else:
152 self.operationKwargs[opId]['parent'] = self.kwargs
152 self.operationKwargs[opId]['parent'] = self.kwargs
153 methodToCall(**self.operationKwargs[opId])
153 methodToCall(**self.operationKwargs[opId])
154 else:
154 else:
155 if name=='run':
155 if name=='run':
156 methodToCall(**self.kwargs)
156 methodToCall(**self.kwargs)
157 else:
157 else:
158 methodToCall(**self.operationKwargs[opId])
158 methodToCall(**self.operationKwargs[opId])
159
159
160 if self.dataOut is None:
160 if self.dataOut is None:
161 return False
161 return False
162
162
163 if self.dataOut.isEmpty():
163 if self.dataOut.isEmpty():
164 return False
164 return False
165
165
166 return True
166 return True
167
167
168 def callObject(self, objId):
168 def callObject(self, objId):
169
169
170 """
170 """
171 Ejecuta la operacion asociada al identificador del objeto "objId"
171 Ejecuta la operacion asociada al identificador del objeto "objId"
172
172
173 Input:
173 Input:
174
174
175 objId : identificador del objeto a ejecutar
175 objId : identificador del objeto a ejecutar
176
176
177 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
177 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
178
178
179 Return:
179 Return:
180
180
181 None
181 None
182 """
182 """
183
183
184 if self.dataOut is not None and self.dataOut.isEmpty():
184 if self.dataOut is not None and self.dataOut.isEmpty():
185 return False
185 return False
186
186
187 externalProcObj = self.operations2RunDict[objId]
187 externalProcObj = self.operations2RunDict[objId]
188
188
189 if hasattr(externalProcObj, 'mp'):
189 if hasattr(externalProcObj, 'mp'):
190 if externalProcObj.mp is False:
190 if externalProcObj.mp is False:
191 externalProcObj.kwargs['parent'] = self.kwargs
191 externalProcObj.kwargs['parent'] = self.kwargs
192 self.operationKwargs[objId] = externalProcObj.kwargs
192 self.operationKwargs[objId] = externalProcObj.kwargs
193 externalProcObj.mp = True
193 externalProcObj.mp = True
194 externalProcObj.start()
194 externalProcObj.start()
195 else:
195 else:
196 externalProcObj.run(self.dataOut, **externalProcObj.kwargs)
196 externalProcObj.run(self.dataOut, **externalProcObj.kwargs)
197 self.operationKwargs[objId] = externalProcObj.kwargs
197 self.operationKwargs[objId] = externalProcObj.kwargs
198
198
199
199
200 return True
200 return True
201
201
202 def call(self, opType, opName=None, opId=None):
202 def call(self, opType, opName=None, opId=None):
203
204 """
203 """
205 Return True si ejecuta la operacion interna nombrada "opName" o la operacion externa
204 Return True si ejecuta la operacion interna nombrada "opName" o la operacion externa
206 identificada con el id "opId"; con los argumentos "**kwargs".
205 identificada con el id "opId"; con los argumentos "**kwargs".
207
206
208 False si la operacion no se ha ejecutado.
207 False si la operacion no se ha ejecutado.
209
208
210 Input:
209 Input:
211
210
212 opType : Puede ser "self" o "external"
211 opType : Puede ser "self" o "external"
213
212
214 Depende del tipo de operacion para llamar a:callMethod or callObject:
213 Depende del tipo de operacion para llamar a:callMethod or callObject:
215
214
216 1. If opType = "self": Llama a un metodo propio de esta clase:
215 1. If opType = "self": Llama a un metodo propio de esta clase:
217
216
218 name_method = getattr(self, name)
217 name_method = getattr(self, name)
219 name_method(**kwargs)
218 name_method(**kwargs)
220
219
221
220
222 2. If opType = "other" o"external": Llama al metodo "run()" de una instancia de la
221 2. If opType = "other" o"external": Llama al metodo "run()" de una instancia de la
223 clase "Operation" o de un derivado de ella:
222 clase "Operation" o de un derivado de ella:
224
223
225 instanceName = self.operationList[opId]
224 instanceName = self.operationList[opId]
226 instanceName.run(**kwargs)
225 instanceName.run(**kwargs)
227
226
228 opName : Si la operacion es interna (opType = 'self'), entonces el "opName" sera
227 opName : Si la operacion es interna (opType = 'self'), entonces el "opName" sera
229 usada para llamar a un metodo interno de la clase Processing
228 usada para llamar a un metodo interno de la clase Processing
230
229
231 opId : Si la operacion es externa (opType = 'other' o 'external), entonces el
230 opId : Si la operacion es externa (opType = 'other' o 'external), entonces el
232 "opId" sera usada para llamar al metodo "run" de la clase Operation
231 "opId" sera usada para llamar al metodo "run" de la clase Operation
233 registrada anteriormente con ese Id
232 registrada anteriormente con ese Id
234
233
235 Exception:
234 Exception:
236 Este objeto de tipo Operation debe de haber sido agregado antes con el metodo:
235 Este objeto de tipo Operation debe de haber sido agregado antes con el metodo:
237 "addOperation" e identificado con el valor "opId" = el id de la operacion.
236 "addOperation" e identificado con el valor "opId" = el id de la operacion.
238 De lo contrario retornara un error del tipo ValueError
237 De lo contrario retornara un error del tipo ValueError
239
238
240 """
239 """
241
240
242 if opType == 'self':
241 if opType == 'self':
243
242
244 if not opName:
243 if not opName:
245 raise ValueError, "opName parameter should be defined"
244 raise ValueError, "opName parameter should be defined"
246
245
247 sts = self.callMethod(opName, opId)
246 sts = self.callMethod(opName, opId)
248
247
249 elif opType == 'other' or opType == 'external' or opType == 'plotter':
248 elif opType == 'other' or opType == 'external' or opType == 'plotter':
250
249
251 if not opId:
250 if not opId:
252 raise ValueError, "opId parameter should be defined"
251 raise ValueError, "opId parameter should be defined"
253
252
254 if opId not in self.operations2RunDict.keys():
253 if opId not in self.operations2RunDict.keys():
255 raise ValueError, "Any operation with id=%s has been added" %str(opId)
254 raise ValueError, "Any operation with id=%s has been added" %str(opId)
256
255
257 sts = self.callObject(opId)
256 sts = self.callObject(opId)
258
257
259 else:
258 else:
260 raise ValueError, "opType should be 'self', 'external' or 'plotter'; and not '%s'" %opType
259 raise ValueError, "opType should be 'self', 'external' or 'plotter'; and not '%s'" %opType
261
260
262 return sts
261 return sts
263
262
264 def setInput(self, dataIn):
263 def setInput(self, dataIn):
265
264
266 self.dataIn = dataIn
265 self.dataIn = dataIn
267 self.dataInList.append(dataIn)
266 self.dataInList.append(dataIn)
268
267
269 def getOutputObj(self):
268 def getOutputObj(self):
270
269
271 return self.dataOut
270 return self.dataOut
272
271
273 def checkInputs(self):
272 def checkInputs(self):
274
273
275 for thisDataIn in self.dataInList:
274 for thisDataIn in self.dataInList:
276
275
277 if thisDataIn.isEmpty():
276 if thisDataIn.isEmpty():
278 return False
277 return False
279
278
280 return True
279 return True
281
280
282 def setup(self):
281 def setup(self):
283
282
284 raise NotImplementedError
283 raise NotImplementedError
285
284
286 def run(self):
285 def run(self):
287
286
288 raise NotImplementedError
287 raise NotImplementedError
289
288
290 def close(self):
289 def close(self):
291 #Close every thread, queue or any other object here is it is neccesary.
290 #Close every thread, queue or any other object here is it is neccesary.
292 return
291 return
293
292
294 class Operation(object):
293 class Operation(object):
295
294
296 """
295 """
297 Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit
296 Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit
298 y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de
297 y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de
299 acumulacion dentro de esta clase
298 acumulacion dentro de esta clase
300
299
301 Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer)
300 Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer)
302
301
303 """
302 """
304
303
305 __buffer = None
304 __buffer = None
306 isConfig = False
305 isConfig = False
307
306
308 def __init__(self, **kwargs):
307 def __init__(self, **kwargs):
309
308
310 self.__buffer = None
309 self.__buffer = None
311 self.isConfig = False
310 self.isConfig = False
312 self.kwargs = kwargs
311 self.kwargs = kwargs
313 checkKwargs(self.run, kwargs)
312 checkKwargs(self.run, kwargs)
314
313
315 def getAllowedArgs(self):
314 def getAllowedArgs(self):
316 return inspect.getargspec(self.run).args
315 return inspect.getargspec(self.run).args
317
316
318 def setup(self):
317 def setup(self):
319
318
320 self.isConfig = True
319 self.isConfig = True
321
320
322 raise NotImplementedError
321 raise NotImplementedError
323
322
324 def run(self, dataIn, **kwargs):
323 def run(self, dataIn, **kwargs):
325
324
326 """
325 """
327 Realiza las operaciones necesarias sobre la dataIn.data y actualiza los
326 Realiza las operaciones necesarias sobre la dataIn.data y actualiza los
328 atributos del objeto dataIn.
327 atributos del objeto dataIn.
329
328
330 Input:
329 Input:
331
330
332 dataIn : objeto del tipo JROData
331 dataIn : objeto del tipo JROData
333
332
334 Return:
333 Return:
335
334
336 None
335 None
337
336
338 Affected:
337 Affected:
339 __buffer : buffer de recepcion de datos.
338 __buffer : buffer de recepcion de datos.
340
339
341 """
340 """
342 if not self.isConfig:
341 if not self.isConfig:
343 self.setup(**kwargs)
342 self.setup(**kwargs)
344
343
345 raise NotImplementedError
344 raise NotImplementedError
346
345
347 def close(self):
346 def close(self):
348
347
349 pass
348 pass
@@ -1,178 +1,178
1 import numpy
1 import numpy
2
2
3 from jroproc_base import ProcessingUnit, Operation
3 from jroproc_base import ProcessingUnit, Operation
4 from schainpy.model.data.jrodata import Correlation, hildebrand_sekhon
4 from schainpy.model.data.jrodata import Correlation, hildebrand_sekhon
5
5
6 class CorrelationProc(ProcessingUnit):
6 class CorrelationProc(ProcessingUnit):
7
7
8 pairsList = None
8 pairsList = None
9
9
10 data_cf = None
10 data_cf = None
11
11
12 def __init__(self, **kwargs):
12 def __init__(self, **kwargs):
13
13
14 ProcessingUnit.__init__(self, **kwargs)
14 ProcessingUnit.__init__(self, **kwargs)
15
15
16 self.objectDict = {}
16 self.objectDict = {}
17 self.buffer = None
17 self.buffer = None
18 self.firstdatatime = None
18 self.firstdatatime = None
19 self.profIndex = 0
19 self.profIndex = 0
20 self.dataOut = Correlation()
20 self.dataOut = Correlation()
21
21
22 def __updateObjFromVoltage(self):
22 def __updateObjFromVoltage(self):
23
23
24 self.dataOut.timeZone = self.dataIn.timeZone
24 self.dataOut.timeZone = self.dataIn.timeZone
25 self.dataOut.dstFlag = self.dataIn.dstFlag
25 self.dataOut.dstFlag = self.dataIn.dstFlag
26 self.dataOut.errorCount = self.dataIn.errorCount
26 self.dataOut.errorCount = self.dataIn.errorCount
27 self.dataOut.useLocalTime = self.dataIn.useLocalTime
27 self.dataOut.useLocalTime = self.dataIn.useLocalTime
28
28
29 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
29 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
30 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
30 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
31 self.dataOut.channelList = self.dataIn.channelList
31 self.dataOut.channelList = self.dataIn.channelList
32 self.dataOut.heightList = self.dataIn.heightList
32 self.dataOut.heightList = self.dataIn.heightList
33 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
33 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
34 # self.dataOut.nHeights = self.dataIn.nHeights
34 # self.dataOut.nHeights = self.dataIn.nHeights
35 # self.dataOut.nChannels = self.dataIn.nChannels
35 # self.dataOut.nChannels = self.dataIn.nChannels
36 self.dataOut.nBaud = self.dataIn.nBaud
36 self.dataOut.nBaud = self.dataIn.nBaud
37 self.dataOut.nCode = self.dataIn.nCode
37 self.dataOut.nCode = self.dataIn.nCode
38 self.dataOut.code = self.dataIn.code
38 self.dataOut.code = self.dataIn.code
39 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
39 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
40 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
40 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
41 self.dataOut.utctime = self.firstdatatime
41 self.dataOut.utctime = self.firstdatatime
42 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
42 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
43 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
43 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
44 self.dataOut.nCohInt = self.dataIn.nCohInt
44 self.dataOut.nCohInt = self.dataIn.nCohInt
45 # self.dataOut.nIncohInt = 1
45 # self.dataOut.nIncohInt = 1
46 self.dataOut.ippSeconds = self.dataIn.ippSeconds
46 self.dataOut.ippSeconds = self.dataIn.ippSeconds
47 self.dataOut.nProfiles = self.dataIn.nProfiles
47 self.dataOut.nProfiles = self.dataIn.nProfiles
48 self.dataOut.utctime = self.dataIn.utctime
48 self.dataOut.utctime = self.dataIn.utctime
49 # self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
49 # self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
50
50
51 # self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nPoints
51 # self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nPoints
52
52
53
53
54 def removeDC(self, jspectra):
54 def removeDC(self, jspectra):
55
55
56 nChannel = jspectra.shape[0]
56 nChannel = jspectra.shape[0]
57
57
58 for i in range(nChannel):
58 for i in range(nChannel):
59 jspectra_tmp = jspectra[i,:,:]
59 jspectra_tmp = jspectra[i,:,:]
60 jspectra_DC = numpy.mean(jspectra_tmp,axis = 0)
60 jspectra_DC = numpy.mean(jspectra_tmp,axis = 0)
61
61
62 jspectra_tmp = jspectra_tmp - jspectra_DC
62 jspectra_tmp = jspectra_tmp - jspectra_DC
63 jspectra[i,:,:] = jspectra_tmp
63 jspectra[i,:,:] = jspectra_tmp
64
64
65 return jspectra
65 return jspectra
66
66
67
67
68 def removeNoise(self, mode = 2):
68 def removeNoise(self, mode = 2):
69 indR = numpy.where(self.dataOut.lagR == 0)[0][0]
69 indR = numpy.where(self.dataOut.lagR == 0)[0][0]
70 indT = numpy.where(self.dataOut.lagT == 0)[0][0]
70 indT = numpy.where(self.dataOut.lagT == 0)[0][0]
71
71
72 jspectra = self.dataOut.data_corr[:,:,indR,:]
72 jspectra = self.dataOut.data_corr[:,:,indR,:]
73
73
74 num_chan = jspectra.shape[0]
74 num_chan = jspectra.shape[0]
75 num_hei = jspectra.shape[2]
75 num_hei = jspectra.shape[2]
76
76
77 freq_dc = indT
77 freq_dc = indT
78 ind_vel = numpy.array([-2,-1,1,2]) + freq_dc
78 ind_vel = numpy.array([-2,-1,1,2]) + freq_dc
79
79
80 NPot = self.dataOut.getNoise(mode)
80 NPot = self.dataOut.getNoise(mode)
81 jspectra[:,freq_dc,:] = jspectra[:,freq_dc,:] - NPot
81 jspectra[:,freq_dc,:] = jspectra[:,freq_dc,:] - NPot
82 SPot = jspectra[:,freq_dc,:]
82 SPot = jspectra[:,freq_dc,:]
83 pairsAutoCorr = self.dataOut.getPairsAutoCorr()
83 pairsAutoCorr = self.dataOut.getPairsAutoCorr()
84 # self.dataOut.signalPotency = SPot
84 # self.dataOut.signalPotency = SPot
85 self.dataOut.noise = NPot
85 self.dataOut.noise = NPot
86 self.dataOut.SNR = (SPot/NPot)[pairsAutoCorr]
86 self.dataOut.SNR = (SPot/NPot)[pairsAutoCorr]
87 self.dataOut.data_corr[:,:,indR,:] = jspectra
87 self.dataOut.data_corr[:,:,indR,:] = jspectra
88
88
89 return 1
89 return 1
90
90
91 def run(self, lags=None, mode = 'time', pairsList=None, fullBuffer=False, nAvg = 1, removeDC = False, splitCF=False):
91 def run(self, lags=None, mode = 'time', pairsList=None, fullBuffer=False, nAvg = 1, removeDC = False, splitCF=False):
92
92
93 self.dataOut.flagNoData = True
93 self.dataOut.flagNoData = True
94
94
95 if self.dataIn.type == "Correlation":
95 if self.dataIn.type == "Correlation":
96
96
97 self.dataOut.copy(self.dataIn)
97 self.dataOut.copy(self.dataIn)
98
98
99 return
99 return
100
100
101 if self.dataIn.type == "Voltage":
101 if self.dataIn.type == "Voltage":
102
102
103 nChannels = self.dataIn.nChannels
103 nChannels = self.dataIn.nChannels
104 nProfiles = self.dataIn.nProfiles
104 nProfiles = self.dataIn.nProfiles
105 nHeights = self.dataIn.nHeights
105 nHeights = self.dataIn.nHeights
106 data_pre = self.dataIn.data
106 data_pre = self.dataIn.data
107
107
108 #--------------- Remover DC ------------
108 #--------------- Remover DC ------------
109 if removeDC:
109 if removeDC:
110 data_pre = self.removeDC(data_pre)
110 data_pre = self.removeDC(data_pre)
111
111
112 #---------------------------------------------
112 #---------------------------------------------
113 # pairsList = list(ccfList)
113 # pairsList = list(ccfList)
114 # for i in acfList:
114 # for i in acfList:
115 # pairsList.append((i,i))
115 # pairsList.append((i,i))
116 #
116 #
117 # ccf_pairs = numpy.arange(len(ccfList))
117 # ccf_pairs = numpy.arange(len(ccfList))
118 # acf_pairs = numpy.arange(len(ccfList),len(pairsList))
118 # acf_pairs = numpy.arange(len(ccfList),len(pairsList))
119 self.__updateObjFromVoltage()
119 self.__updateObjFromVoltage()
120 #----------------------------------------------------------------------
120 #----------------------------------------------------------------------
121 #Creating temporal buffers
121 #Creating temporal buffers
122 if fullBuffer:
122 if fullBuffer:
123 tmp = numpy.zeros((len(pairsList), len(lags), nProfiles, nHeights), dtype = 'complex')*numpy.nan
123 tmp = numpy.zeros((len(pairsList), len(lags), nProfiles, nHeights), dtype = 'complex')*numpy.nan
124 elif mode == 'time':
124 elif mode == 'time':
125 if lags == None:
125 if lags == None:
126 lags = numpy.arange(-nProfiles+1, nProfiles)
126 lags = numpy.arange(-nProfiles+1, nProfiles)
127 tmp = numpy.zeros((len(pairsList), len(lags), nHeights),dtype='complex')
127 tmp = numpy.zeros((len(pairsList), len(lags), nHeights),dtype='complex')
128 elif mode == 'height':
128 elif mode == 'height':
129 if lags == None:
129 if lags == None:
130 lags = numpy.arange(-nHeights+1, nHeights)
130 lags = numpy.arange(-nHeights+1, nHeights)
131 tmp = numpy.zeros(len(pairsList), (len(lags), nProfiles),dtype='complex')
131 tmp = numpy.zeros(len(pairsList), (len(lags), nProfiles),dtype='complex')
132
132
133 #For loop
133 #For loop
134 for l in range(len(pairsList)):
134 for l in range(len(pairsList)):
135
135
136 ch0 = pairsList[l][0]
136 ch0 = pairsList[l][0]
137 ch1 = pairsList[l][1]
137 ch1 = pairsList[l][1]
138
138
139 for i in range(len(lags)):
139 for i in range(len(lags)):
140 idx = lags[i]
140 idx = lags[i]
141
141
142 if idx >= 0:
142 if idx >= 0:
143 if mode == 'time':
143 if mode == 'time':
144 ccf0 = data_pre[ch0,:nProfiles-idx,:]*numpy.conj(data_pre[ch1,idx:,:]) #time
144 ccf0 = data_pre[ch0,:nProfiles-idx,:]*numpy.conj(data_pre[ch1,idx:,:]) #time
145 else:
145 else:
146 ccf0 = data_pre[ch0,:,nHeights-idx]*numpy.conj(data_pre[ch1,:,idx:]) #heights
146 ccf0 = data_pre[ch0,:,nHeights-idx]*numpy.conj(data_pre[ch1,:,idx:]) #heights
147 else:
147 else:
148 if mode == 'time':
148 if mode == 'time':
149 ccf0 = data_pre[ch0,-idx:,:]*numpy.conj(data_pre[ch1,:nProfiles+idx,:]) #time
149 ccf0 = data_pre[ch0,-idx:,:]*numpy.conj(data_pre[ch1,:nProfiles+idx,:]) #time
150 else:
150 else:
151 ccf0 = data_pre[ch0,:,-idx:]*numpy.conj(data_pre[ch1,:,:nHeights+idx]) #heights
151 ccf0 = data_pre[ch0,:,-idx:]*numpy.conj(data_pre[ch1,:,:nHeights+idx]) #heights
152
152
153 if fullBuffer:
153 if fullBuffer:
154 tmp[l,i,:ccf0.shape[0],:] = ccf0
154 tmp[l,i,:ccf0.shape[0],:] = ccf0
155 else:
155 else:
156 tmp[l,i,:] = numpy.sum(ccf0, axis=0)
156 tmp[l,i,:] = numpy.sum(ccf0, axis=0)
157
157
158 #-----------------------------------------------------------------
158 #-----------------------------------------------------------------
159 if fullBuffer:
159 if fullBuffer:
160 tmp = numpy.sum(numpy.reshape(tmp,(tmp.shape[0],tmp.shape[1],tmp.shape[2]/nAvg,nAvg,tmp.shape[3])),axis=3)
160 tmp = numpy.sum(numpy.reshape(tmp,(tmp.shape[0],tmp.shape[1],tmp.shape[2]/nAvg,nAvg,tmp.shape[3])),axis=3)
161 self.dataOut.nAvg = nAvg
161 self.dataOut.nAvg = nAvg
162
162
163 self.dataOut.data_cf = tmp
163 self.dataOut.data_cf = tmp
164 self.dataOut.mode = mode
164 self.dataOut.mode = mode
165 self.dataOut.nLags = len(lags)
165 self.dataOut.nLags = len(lags)
166 self.dataOut.pairsList = pairsList
166 self.dataOut.pairsList = pairsList
167 self.dataOut.nPairs = len(pairsList)
167 self.dataOut.nPairs = len(pairsList)
168
168
169 #Se Calcula los factores de Normalizacion
169 #Se Calcula los factores de Normalizacion
170 if mode == 'time':
170 if mode == 'time':
171 delta = self.dataIn.ippSeconds*self.dataIn.nCohInt
171 delta = self.dataIn.ippSeconds*self.dataIn.nCohInt
172 else:
172 else:
173 delta = self.dataIn.heightList[1] - self.dataIn.heightList[0]
173 delta = self.dataIn.heightList[1] - self.dataIn.heightList[0]
174 self.dataOut.lagRange = numpy.array(lags)*delta
174 self.dataOut.lagRange = numpy.array(lags)*delta
175 # self.dataOut.nCohInt = self.dataIn.nCohInt*nAvg
175 # self.dataOut.nCohInt = self.dataIn.nCohInt*nAvg
176 self.dataOut.flagNoData = False
176 self.dataOut.flagNoData = False
177 a = self.dataOut.normFactor
177 # a = self.dataOut.normFactor
178 return
178 return
@@ -1,345 +1,344
1 import numpy
1 import numpy
2
2
3 from jroproc_base import ProcessingUnit, Operation
3 from jroproc_base import ProcessingUnit, Operation
4 from schainpy.model.data.jrodata import SpectraHeis
4 from schainpy.model.data.jrodata import SpectraHeis
5
5
6 class SpectraHeisProc(ProcessingUnit):
6 class SpectraHeisProc(ProcessingUnit):
7
7
8 def __init__(self, **kwargs):
8 def __init__(self, **kwargs):
9
9
10 ProcessingUnit.__init__(self, **kwargs)
10 ProcessingUnit.__init__(self, **kwargs)
11
11
12 # self.buffer = None
12 # self.buffer = None
13 # self.firstdatatime = None
13 # self.firstdatatime = None
14 # self.profIndex = 0
14 # self.profIndex = 0
15 self.dataOut = SpectraHeis()
15 self.dataOut = SpectraHeis()
16
16
17 def __updateObjFromVoltage(self):
17 def __updateObjFromVoltage(self):
18
18
19 self.dataOut.timeZone = self.dataIn.timeZone
19 self.dataOut.timeZone = self.dataIn.timeZone
20 self.dataOut.dstFlag = self.dataIn.dstFlag
20 self.dataOut.dstFlag = self.dataIn.dstFlag
21 self.dataOut.errorCount = self.dataIn.errorCount
21 self.dataOut.errorCount = self.dataIn.errorCount
22 self.dataOut.useLocalTime = self.dataIn.useLocalTime
22 self.dataOut.useLocalTime = self.dataIn.useLocalTime
23
23
24 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()#
24 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()#
25 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()#
25 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()#
26 self.dataOut.channelList = self.dataIn.channelList
26 self.dataOut.channelList = self.dataIn.channelList
27 self.dataOut.heightList = self.dataIn.heightList
27 self.dataOut.heightList = self.dataIn.heightList
28 # self.dataOut.dtype = self.dataIn.dtype
28 # self.dataOut.dtype = self.dataIn.dtype
29 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
29 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
30 # self.dataOut.nHeights = self.dataIn.nHeights
30 # self.dataOut.nHeights = self.dataIn.nHeights
31 # self.dataOut.nChannels = self.dataIn.nChannels
31 # self.dataOut.nChannels = self.dataIn.nChannels
32 self.dataOut.nBaud = self.dataIn.nBaud
32 self.dataOut.nBaud = self.dataIn.nBaud
33 self.dataOut.nCode = self.dataIn.nCode
33 self.dataOut.nCode = self.dataIn.nCode
34 self.dataOut.code = self.dataIn.code
34 self.dataOut.code = self.dataIn.code
35 # self.dataOut.nProfiles = 1
35 # self.dataOut.nProfiles = 1
36 self.dataOut.ippFactor = 1
36 self.dataOut.ippFactor = 1
37 self.dataOut.noise_estimation = None
37 self.dataOut.noise_estimation = None
38 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
38 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
39 self.dataOut.nFFTPoints = self.dataIn.nHeights
39 self.dataOut.nFFTPoints = self.dataIn.nHeights
40 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
40 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
41 # self.dataOut.flagNoData = self.dataIn.flagNoData
41 # self.dataOut.flagNoData = self.dataIn.flagNoData
42 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
42 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
43 self.dataOut.utctime = self.dataIn.utctime
43 self.dataOut.utctime = self.dataIn.utctime
44 # self.dataOut.utctime = self.firstdatatime
44 # self.dataOut.utctime = self.firstdatatime
45 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
45 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
46 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
46 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
47 # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
47 # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
48 self.dataOut.nCohInt = self.dataIn.nCohInt
48 self.dataOut.nCohInt = self.dataIn.nCohInt
49 self.dataOut.nIncohInt = 1
49 self.dataOut.nIncohInt = 1
50 # self.dataOut.ippSeconds= self.dataIn.ippSeconds
50 # self.dataOut.ippSeconds= self.dataIn.ippSeconds
51 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
51 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
52
52
53 # self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nIncohInt
53 # self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nIncohInt
54 # self.dataOut.set=self.dataIn.set
54 # self.dataOut.set=self.dataIn.set
55 # self.dataOut.deltaHeight=self.dataIn.deltaHeight
55 # self.dataOut.deltaHeight=self.dataIn.deltaHeight
56
56
57
57
58 def __updateObjFromFits(self):
58 def __updateObjFromFits(self):
59
59
60 self.dataOut.utctime = self.dataIn.utctime
60 self.dataOut.utctime = self.dataIn.utctime
61 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
61 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
62
62
63 self.dataOut.channelList = self.dataIn.channelList
63 self.dataOut.channelList = self.dataIn.channelList
64 self.dataOut.heightList = self.dataIn.heightList
64 self.dataOut.heightList = self.dataIn.heightList
65 self.dataOut.data_spc = self.dataIn.data
65 self.dataOut.data_spc = self.dataIn.data
66 self.dataOut.ippSeconds = self.dataIn.ippSeconds
66 self.dataOut.ippSeconds = self.dataIn.ippSeconds
67 self.dataOut.nCohInt = self.dataIn.nCohInt
67 self.dataOut.nCohInt = self.dataIn.nCohInt
68 self.dataOut.nIncohInt = self.dataIn.nIncohInt
68 self.dataOut.nIncohInt = self.dataIn.nIncohInt
69 # self.dataOut.timeInterval = self.dataIn.timeInterval
69 # self.dataOut.timeInterval = self.dataIn.timeInterval
70 self.dataOut.timeZone = self.dataIn.timeZone
70 self.dataOut.timeZone = self.dataIn.timeZone
71 self.dataOut.useLocalTime = True
71 self.dataOut.useLocalTime = True
72 # self.dataOut.
72 # self.dataOut.
73 # self.dataOut.
73 # self.dataOut.
74
74
75 def __getFft(self):
75 def __getFft(self):
76
76
77 fft_volt = numpy.fft.fft(self.dataIn.data, axis=1)
77 fft_volt = numpy.fft.fft(self.dataIn.data, axis=1)
78 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
78 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
79 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))/(self.dataOut.nFFTPoints)
79 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))/(self.dataOut.nFFTPoints)
80 self.dataOut.data_spc = spc
80 self.dataOut.data_spc = spc
81
81
82 def run(self):
82 def run(self):
83
83
84 self.dataOut.flagNoData = True
84 self.dataOut.flagNoData = True
85
85
86 if self.dataIn.type == "Fits":
86 if self.dataIn.type == "Fits":
87 self.__updateObjFromFits()
87 self.__updateObjFromFits()
88 self.dataOut.flagNoData = False
88 self.dataOut.flagNoData = False
89 return
89 return
90
90
91 if self.dataIn.type == "SpectraHeis":
91 if self.dataIn.type == "SpectraHeis":
92 self.dataOut.copy(self.dataIn)
92 self.dataOut.copy(self.dataIn)
93 return
93 return
94
94
95 if self.dataIn.type == "Voltage":
95 if self.dataIn.type == "Voltage":
96 self.__updateObjFromVoltage()
96 self.__updateObjFromVoltage()
97 self.__getFft()
97 self.__getFft()
98 self.dataOut.flagNoData = False
98 self.dataOut.flagNoData = False
99
99
100 return
100 return
101
101
102 raise ValueError, "The type object %s is not valid"%(self.dataIn.type)
102 raise ValueError, "The type object %s is not valid"%(self.dataIn.type)
103
103
104
104
105 def selectChannels(self, channelList):
105 def selectChannels(self, channelList):
106
106
107 channelIndexList = []
107 channelIndexList = []
108
108
109 for channel in channelList:
109 for channel in channelList:
110 index = self.dataOut.channelList.index(channel)
110 index = self.dataOut.channelList.index(channel)
111 channelIndexList.append(index)
111 channelIndexList.append(index)
112
112
113 self.selectChannelsByIndex(channelIndexList)
113 self.selectChannelsByIndex(channelIndexList)
114
114
115 def selectChannelsByIndex(self, channelIndexList):
115 def selectChannelsByIndex(self, channelIndexList):
116 """
116 """
117 Selecciona un bloque de datos en base a canales segun el channelIndexList
117 Selecciona un bloque de datos en base a canales segun el channelIndexList
118
118
119 Input:
119 Input:
120 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
120 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
121
121
122 Affected:
122 Affected:
123 self.dataOut.data
123 self.dataOut.data
124 self.dataOut.channelIndexList
124 self.dataOut.channelIndexList
125 self.dataOut.nChannels
125 self.dataOut.nChannels
126 self.dataOut.m_ProcessingHeader.totalSpectra
126 self.dataOut.m_ProcessingHeader.totalSpectra
127 self.dataOut.systemHeaderObj.numChannels
127 self.dataOut.systemHeaderObj.numChannels
128 self.dataOut.m_ProcessingHeader.blockSize
128 self.dataOut.m_ProcessingHeader.blockSize
129
129
130 Return:
130 Return:
131 None
131 None
132 """
132 """
133
133
134 for channelIndex in channelIndexList:
134 for channelIndex in channelIndexList:
135 if channelIndex not in self.dataOut.channelIndexList:
135 if channelIndex not in self.dataOut.channelIndexList:
136 print channelIndexList
136 print channelIndexList
137 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
137 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
138
138
139 # nChannels = len(channelIndexList)
139 # nChannels = len(channelIndexList)
140
140
141 data_spc = self.dataOut.data_spc[channelIndexList,:]
141 data_spc = self.dataOut.data_spc[channelIndexList,:]
142
142
143 self.dataOut.data_spc = data_spc
143 self.dataOut.data_spc = data_spc
144 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
144 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
145
145
146 return 1
146 return 1
147
147
148 class IncohInt4SpectraHeis(Operation):
148 class IncohInt4SpectraHeis(Operation):
149
149
150 isConfig = False
150 isConfig = False
151
151
152 __profIndex = 0
152 __profIndex = 0
153 __withOverapping = False
153 __withOverapping = False
154
154
155 __byTime = False
155 __byTime = False
156 __initime = None
156 __initime = None
157 __lastdatatime = None
157 __lastdatatime = None
158 __integrationtime = None
158 __integrationtime = None
159
159
160 __buffer = None
160 __buffer = None
161
161
162 __dataReady = False
162 __dataReady = False
163
163
164 n = None
164 n = None
165
165
166
167 def __init__(self, **kwargs):
166 def __init__(self, **kwargs):
168
167
169 Operation.__init__(self, **kwargs)
168 Operation.__init__(self, **kwargs)
170 # self.isConfig = False
169 # self.isConfig = False
171
170
172 def setup(self, n=None, timeInterval=None, overlapping=False):
171 def setup(self, n=None, timeInterval=None, overlapping=False):
173 """
172 """
174 Set the parameters of the integration class.
173 Set the parameters of the integration class.
175
174
176 Inputs:
175 Inputs:
177
176
178 n : Number of coherent integrations
177 n : Number of coherent integrations
179 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
178 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
180 overlapping :
179 overlapping :
181
180
182 """
181 """
183
182
184 self.__initime = None
183 self.__initime = None
185 self.__lastdatatime = 0
184 self.__lastdatatime = 0
186 self.__buffer = None
185 self.__buffer = None
187 self.__dataReady = False
186 self.__dataReady = False
188
187
189
188
190 if n == None and timeInterval == None:
189 if n == None and timeInterval == None:
191 raise ValueError, "n or timeInterval should be specified ..."
190 raise ValueError, "n or timeInterval should be specified ..."
192
191
193 if n != None:
192 if n != None:
194 self.n = n
193 self.n = n
195 self.__byTime = False
194 self.__byTime = False
196 else:
195 else:
197 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
196 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
198 self.n = 9999
197 self.n = 9999
199 self.__byTime = True
198 self.__byTime = True
200
199
201 if overlapping:
200 if overlapping:
202 self.__withOverapping = True
201 self.__withOverapping = True
203 self.__buffer = None
202 self.__buffer = None
204 else:
203 else:
205 self.__withOverapping = False
204 self.__withOverapping = False
206 self.__buffer = 0
205 self.__buffer = 0
207
206
208 self.__profIndex = 0
207 self.__profIndex = 0
209
208
210 def putData(self, data):
209 def putData(self, data):
211
210
212 """
211 """
213 Add a profile to the __buffer and increase in one the __profileIndex
212 Add a profile to the __buffer and increase in one the __profileIndex
214
213
215 """
214 """
216
215
217 if not self.__withOverapping:
216 if not self.__withOverapping:
218 self.__buffer += data.copy()
217 self.__buffer += data.copy()
219 self.__profIndex += 1
218 self.__profIndex += 1
220 return
219 return
221
220
222 #Overlapping data
221 #Overlapping data
223 nChannels, nHeis = data.shape
222 nChannels, nHeis = data.shape
224 data = numpy.reshape(data, (1, nChannels, nHeis))
223 data = numpy.reshape(data, (1, nChannels, nHeis))
225
224
226 #If the buffer is empty then it takes the data value
225 #If the buffer is empty then it takes the data value
227 if self.__buffer is None:
226 if self.__buffer is None:
228 self.__buffer = data
227 self.__buffer = data
229 self.__profIndex += 1
228 self.__profIndex += 1
230 return
229 return
231
230
232 #If the buffer length is lower than n then stakcing the data value
231 #If the buffer length is lower than n then stakcing the data value
233 if self.__profIndex < self.n:
232 if self.__profIndex < self.n:
234 self.__buffer = numpy.vstack((self.__buffer, data))
233 self.__buffer = numpy.vstack((self.__buffer, data))
235 self.__profIndex += 1
234 self.__profIndex += 1
236 return
235 return
237
236
238 #If the buffer length is equal to n then replacing the last buffer value with the data value
237 #If the buffer length is equal to n then replacing the last buffer value with the data value
239 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
238 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
240 self.__buffer[self.n-1] = data
239 self.__buffer[self.n-1] = data
241 self.__profIndex = self.n
240 self.__profIndex = self.n
242 return
241 return
243
242
244
243
245 def pushData(self):
244 def pushData(self):
246 """
245 """
247 Return the sum of the last profiles and the profiles used in the sum.
246 Return the sum of the last profiles and the profiles used in the sum.
248
247
249 Affected:
248 Affected:
250
249
251 self.__profileIndex
250 self.__profileIndex
252
251
253 """
252 """
254
253
255 if not self.__withOverapping:
254 if not self.__withOverapping:
256 data = self.__buffer
255 data = self.__buffer
257 n = self.__profIndex
256 n = self.__profIndex
258
257
259 self.__buffer = 0
258 self.__buffer = 0
260 self.__profIndex = 0
259 self.__profIndex = 0
261
260
262 return data, n
261 return data, n
263
262
264 #Integration with Overlapping
263 #Integration with Overlapping
265 data = numpy.sum(self.__buffer, axis=0)
264 data = numpy.sum(self.__buffer, axis=0)
266 n = self.__profIndex
265 n = self.__profIndex
267
266
268 return data, n
267 return data, n
269
268
270 def byProfiles(self, data):
269 def byProfiles(self, data):
271
270
272 self.__dataReady = False
271 self.__dataReady = False
273 avgdata = None
272 avgdata = None
274 # n = None
273 # n = None
275
274
276 self.putData(data)
275 self.putData(data)
277
276
278 if self.__profIndex == self.n:
277 if self.__profIndex == self.n:
279
278
280 avgdata, n = self.pushData()
279 avgdata, n = self.pushData()
281 self.__dataReady = True
280 self.__dataReady = True
282
281
283 return avgdata
282 return avgdata
284
283
285 def byTime(self, data, datatime):
284 def byTime(self, data, datatime):
286
285
287 self.__dataReady = False
286 self.__dataReady = False
288 avgdata = None
287 avgdata = None
289 n = None
288 n = None
290
289
291 self.putData(data)
290 self.putData(data)
292
291
293 if (datatime - self.__initime) >= self.__integrationtime:
292 if (datatime - self.__initime) >= self.__integrationtime:
294 avgdata, n = self.pushData()
293 avgdata, n = self.pushData()
295 self.n = n
294 self.n = n
296 self.__dataReady = True
295 self.__dataReady = True
297
296
298 return avgdata
297 return avgdata
299
298
300 def integrate(self, data, datatime=None):
299 def integrate(self, data, datatime=None):
301
300
302 if self.__initime == None:
301 if self.__initime == None:
303 self.__initime = datatime
302 self.__initime = datatime
304
303
305 if self.__byTime:
304 if self.__byTime:
306 avgdata = self.byTime(data, datatime)
305 avgdata = self.byTime(data, datatime)
307 else:
306 else:
308 avgdata = self.byProfiles(data)
307 avgdata = self.byProfiles(data)
309
308
310
309
311 self.__lastdatatime = datatime
310 self.__lastdatatime = datatime
312
311
313 if avgdata is None:
312 if avgdata is None:
314 return None, None
313 return None, None
315
314
316 avgdatatime = self.__initime
315 avgdatatime = self.__initime
317
316
318 deltatime = datatime -self.__lastdatatime
317 deltatime = datatime -self.__lastdatatime
319
318
320 if not self.__withOverapping:
319 if not self.__withOverapping:
321 self.__initime = datatime
320 self.__initime = datatime
322 else:
321 else:
323 self.__initime += deltatime
322 self.__initime += deltatime
324
323
325 return avgdata, avgdatatime
324 return avgdata, avgdatatime
326
325
327 def run(self, dataOut, **kwargs):
326 def run(self, dataOut, n=None, timeInterval=None, overlapping=False, **kwargs):
328
327
329 if not self.isConfig:
328 if not self.isConfig:
330 self.setup(**kwargs)
329 self.setup(n=n, timeInterval=timeInterval, overlapping=overlapping)
331 self.isConfig = True
330 self.isConfig = True
332
331
333 avgdata, avgdatatime = self.integrate(dataOut.data_spc, dataOut.utctime)
332 avgdata, avgdatatime = self.integrate(dataOut.data_spc, dataOut.utctime)
334
333
335 # dataOut.timeInterval *= n
334 # dataOut.timeInterval *= n
336 dataOut.flagNoData = True
335 dataOut.flagNoData = True
337
336
338 if self.__dataReady:
337 if self.__dataReady:
339 dataOut.data_spc = avgdata
338 dataOut.data_spc = avgdata
340 dataOut.nIncohInt *= self.n
339 dataOut.nIncohInt *= self.n
341 # dataOut.nCohInt *= self.n
340 # dataOut.nCohInt *= self.n
342 dataOut.utctime = avgdatatime
341 dataOut.utctime = avgdatatime
343 # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nIncohInt
342 # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nIncohInt
344 # dataOut.timeInterval = self.__timeInterval*self.n
343 # dataOut.timeInterval = self.__timeInterval*self.n
345 dataOut.flagNoData = False
344 dataOut.flagNoData = False
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: file renamed from schainpy/trash to schainpy/utils/trash
NO CONTENT: file renamed from schainpy/trash to schainpy/utils/trash
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: file was removed
NO CONTENT: file was removed
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: file was removed
NO CONTENT: file was removed
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: file was removed
NO CONTENT: file was removed
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: file was removed
NO CONTENT: file was removed
The requested commit or file is too big and content was truncated. Show full diff
General Comments 0
You need to be logged in to leave comments. Login now