##// END OF EJS Templates
merge with v2.3
jespinoza -
r1063:ecbe1f26c35b merge
parent child
Show More

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

@@ -0,0 +1,109
1 ## CHANGELOG:
2
3 ### 2.3
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).
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.
8 * GUI command `schain` is now `schainGUI`.
9 * Added a CLI tool named `schain`.
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.
12 * `schain xml` to run xml scripts.
13 * Added suggestions when parameters are poorly written.
14 * `Controller.start()` now runs in a different process than the process calling it.
15 * Added `schainpy.utils.log` for log standarization.
16 * Running script on online mode no longer ignores date and hour. Issue #1109.
17 * Added support for receving voltage data directly from JARS (tcp, ipc).
18 * Updated README for MAC OS GUI installation.
19 * Setup now installs numpy.
20
21 ### 2.2.6
22 * Graphics generated by the GUI are now the same as generated by scripts. Issue #1074.
23 * Added support for C extensions.
24 * function `hildebrand_sehkon` optimized with a C wrapper.
25 * Numpy version updated.
26 * Migration to GIT.
27
28 ### 2.2.5:
29 * splitProfiles and combineProfiles modules were added to VoltageProc and Signal Chain GUI.
30 * nProfiles of USRP data (hdf5) is the number of profiles thera are in one second.
31 * jroPlotter works directly with data objects instead of dictionaries
32 * script "schain" was added to Signal Chain installer
33
34 ### 2.2.4.1:
35 * jroIO_usrp.py is update to read Sandra's data
36 * decimation in Spectra and RTI plots is always enabled.
37 * time* window option added to GUI
38
39 ### 2.2.4:
40 * jroproc_spectra_lags.py added to schainpy
41 * Bug fixed in schainGUI: ProcUnit was created with the same id in some cases.
42 * Bug fixed in jroHeaderIO: Header size validation.
43
44 ### 2.2.3.1:
45 * Filtering block by time has been added.
46 * Bug fixed plotting RTI, CoherenceMap and others using xmin and xmax parameters. The first day worked
47 properly but the next days did not.
48
49 ### 2.2.3:
50 * Bug fixed in GUI: Error getting(reading) Code value
51 * Bug fixed in GUI: Flip option always needs channelList field
52 * Bug fixed in jrodata: when one branch modified a value in "dataOut" (example: dataOut.code) this value
53 was modified for every branch (because this was a reference). It was modified in data.copy()
54 * Bug fixed in jroproc_voltage.profileSelector(): rangeList replaces to profileRangeList.
55
56 ### 2.2.2:
57 * VoltageProc: ProfileSelector, Reshape, Decoder with nTxs!=1 and getblock=True was tested
58 * Rawdata and testRawdata.py added to Signal Chain project
59
60 ### 2.2.1:
61 * Bugs fixed in GUI
62 * Views were improved in GUI
63 * Support to MST* ISR experiments
64 * Bug fixed getting noise using hyldebrant. (minimum number of points > 20%)
65 * handleError added to jroplotter.py
66
67 ### 2.2.0:
68 * GUI: use of external plotter
69 * Compatible with matplotlib 1.5.0
70
71 ### 2.1.5:
72 * serializer module added to Signal Chain
73 * jroplotter.py added to Signal Chain
74
75 ### 2.1.4.2:
76 * A new Plotter Class was added
77 * Project.start() does not accept filename as a parameter anymore
78
79 ### 2.1.4.1:
80 * Send notifications when an error different to ValueError is detected
81
82 ### 2.1.4:
83 * Sending error notifications to signal chain administrator
84 * Login to email server added
85
86 ### 2.1.3.3:
87 * Colored Button Icons were added to GUI
88
89 ### 2.1.3.2:
90 * GUI: user interaction enhanced
91 * controller_api.py: Safe access to ControllerThead
92
93 ### 2.1.3.1:
94 * GUI: every icon were resized
95 * jroproc_voltage.py: Print a message when "Read from code" option is selected and the code is not defined inside data file
96
97 ### 2.1.3:
98 * jroplot_heispectra.py: SpectraHeisScope was not showing the right channels
99 * jroproc_voltage.py: Bug fixed selecting profiles (self.nProfiles took a wrong value),
100 Bug fixed selecting heights by block (selecting profiles instead heights)
101 * jroproc_voltage.py: New feature added: decoding data by block using FFT.
102 * jroIO_heispectra.py: Bug fixed in FitsReader. Using local Fits instance instead schainpy.mode.data.jrodata.Fits.
103 * jroIO_heispectra.py: Channel index list does not exist.
104
105 ### 2.1.2:
106 * jroutils_ftp.py: Bug fixed, Any error sending file stopped the Server Thread
107 Server thread opens and closes remote server each time file list is sent
108 * jroplot_spectra.py: Noise path was not being created when noise data is saved.
109 * jroIO_base.py: startTime can be greater than endTime. Example: SpreadF [18:00 * 07:00] No newline at end of file
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 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,113 +1,115
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
103
104 # vscode
104 # vscode
105
105
106 .vscode
106 .vscode
107
107
108 schainpy/scripts/
109 schaingui/node_modules/
108 .svn/
110 .svn/
109 *.png
111 *.png
110 *.pyc
112 *.pyc
111 schainpy/scripts
113 *.xml
112
114 *.log
113 schaingui/node_modules
115 trash No newline at end of file
@@ -1,132 +1,147
1 # Signal Chain
1 # Signal Chain
2
2
3 ## Introduction
3 ## Introduction
4
4
5 Signal Chain (SCh) is a radar data processing library developed using [Python](www.python.org) at JRO. SCh provides modules to read, write, process and plot data.
5 Signal Chain (SCh) is a radar data processing library developed using [Python](www.python.org) at JRO. SCh provides modules to read, write, process and plot data.
6
6
7 ## Installation
7 ## Installation
8
8
9 Install system dependencies, clone the latest version from [git](http://jro-dev.igp.gob.pe/rhodecode/schain/) and install it as a normal python package.
9 Install system dependencies, clone the latest version from [git](http://jro-dev.igp.gob.pe/rhodecode/schain/) and install it as a normal python package.
10
10
11 ### Linux based system
11 ```
12 ```
12 $ sudo apt-get install python-pip python-dev gfortran libpng-dev freetype* libblas-dev liblapack-dev libatlas-base-dev python-qt4 python-tk libssl-dev libhdf5-dev
13 $ sudo apt-get install python-pip python-dev gfortran libpng-dev freetype* libblas-dev liblapack-dev libatlas-base-dev python-qt4 python-tk libssl-dev libhdf5-dev
13 $ sudo pip install numpy
14 $ sudo pip install numpy
14 $ git clone http://jro-dev.igp.gob.pe/rhodecode/schain/
15 $ git clone http://jro-dev.igp.gob.pe/rhodecode/schain/
15 $ cd schain
16 $ cd schain
16 $ sudo pip install ./
17 $ sudo pip install ./
17 ```
18
19 **Its recommended to install schain in a virtual environment**
20
18
21 ```
19 ```
20 **It is recommended to install schain in a virtual environment**
21 ```
22 $ sudo pip install virtualenv
22 $ sudo pip install virtualenv
23 $ virtualenv /path/to/virtual --system-site-packages
23 $ virtualenv /path/to/virtual --system-site-packages
24 $ source /path/to/virtual/bin/activate
24 $ source /path/to/virtual/bin/activate
25 (virtual) $ cd schain
25 (virtual) $ cd schain
26 (virtual) $ pip install ./
26 (virtual) $ pip install ./
27
27 ```
28 ```
28
29
30 ### MAC Os
31 ```
32 $ brew install cartr/qt4/pyqt
33 $ git clone http://jro-dev.igp.gob.pe/rhodecode/schain/
34 $ cd schain
35 $ pip install ./
36 ```
37
38 if ```pip install ./``` does not work, install a proper python enviroment, and repeat the steps.
39 ```
40 $ brew install python
41 ```
42
43
29 ## First Script
44 ## First Script
30
45
31 Read Spectra data (.pdata) - remove dc - plot spectra & RTI
46 Read Spectra data (.pdata) - remove dc - plot spectra & RTI
32
47
33 Import SCh and creating a project
48 Import SCh and creating a project
34
49
35 ```python
50 ```python
36 #!/usr/bin/python
51 #!/usr/bin/python
37
52
38 from schainpy.controller import Project
53 from schainpy.controller import Project
39
54
40 controller = Project()
55 controller = Project()
41 controller.setup(id = '100',
56 controller.setup(id = '100',
42 name='test',
57 name='test',
43 description='Basic experiment')
58 description='Basic experiment')
44
59
45
60
46 ```
61 ```
47
62
48 Adding read unit and operations
63 Adding read unit and operations
49
64
50 ```python
65 ```python
51 read_unit = controller.addReadUnit(datatype='Spectra',
66 read_unit = controller.addReadUnit(datatype='Spectra',
52 path='/path/to/pdata/',
67 path='/path/to/pdata/',
53 startDate='2014/01/31',
68 startDate='2014/01/31',
54 endDate='2014/03/31',
69 endDate='2014/03/31',
55 startTime='00:00:00',
70 startTime='00:00:00',
56 endTime='23:59:59',
71 endTime='23:59:59',
57 online=0,
72 online=0,
58 walk=0)
73 walk=0)
59
74
60 proc_unit = controller.addProcUnit(datatype='Spectra',
75 proc_unit = controller.addProcUnit(datatype='Spectra',
61 inputId=read_unit.getId())
76 inputId=read_unit.getId())
62
77
63 op = proc_unit.addOperation(name='selectChannels')
78 op = proc_unit.addOperation(name='selectChannels')
64 op.addParameter(name='channelList', value='0,1', format='intlist')
79 op.addParameter(name='channelList', value='0,1', format='intlist')
65
80
66 op = proc_unit.addOperation(name='selectHeights')
81 op = proc_unit.addOperation(name='selectHeights')
67 op.addParameter(name='minHei', value='80', format='float')
82 op.addParameter(name='minHei', value='80', format='float')
68 op.addParameter(name='maxHei', value='200', format='float')
83 op.addParameter(name='maxHei', value='200', format='float')
69
84
70 op = proc_unit.addOperation(name='removeDC')
85 op = proc_unit.addOperation(name='removeDC')
71
86
72 ```
87 ```
73
88
74 Plotting data & start project
89 Plotting data & start project
75
90
76 ```python
91 ```python
77 op = proc_unit.addOperation(name='SpectraPlot', optype='other')
92 op = proc_unit.addOperation(name='SpectraPlot', optype='other')
78 op.addParameter(name='id', value='1', format='int')
93 op.addParameter(name='id', value='1', format='int')
79 op.addParameter(name='wintitle', value='Spectra', format='str')
94 op.addParameter(name='wintitle', value='Spectra', format='str')
80
95
81 op = procUnitConfObj1.addOperation(name='RTIPlot', optype='other')
96 op = procUnitConfObj1.addOperation(name='RTIPlot', optype='other')
82 op.addParameter(name='id', value='2', format='int')
97 op.addParameter(name='id', value='2', format='int')
83 op.addParameter(name='wintitle', value='RTI', format='str')
98 op.addParameter(name='wintitle', value='RTI', format='str')
84
99
85 controller.start()
100 controller.start()
86
101
87 ```
102 ```
88
103
89 Full script
104 Full script
90
105
91
106
92 ```python
107 ```python
93 #!/usr/bin/python
108 #!/usr/bin/python
94
109
95 from schainpy.controller import Project
110 from schainpy.controller import Project
96
111
97 controller = Project()
112 controller = Project()
98 controller.setup(id = '100',
113 controller.setup(id = '100',
99 name='test',
114 name='test',
100 description='Basic experiment')
115 description='Basic experiment')
101 read_unit = controller.addReadUnit(datatype='Spectra',
116 read_unit = controller.addReadUnit(datatype='Spectra',
102 path='/path/to/pdata/',
117 path='/path/to/pdata/',
103 startDate='2014/01/31',
118 startDate='2014/01/31',
104 endDate='2014/03/31',
119 endDate='2014/03/31',
105 startTime='00:00:00',
120 startTime='00:00:00',
106 endTime='23:59:59',
121 endTime='23:59:59',
107 online=0,
122 online=0,
108 walk=0)
123 walk=0)
109
124
110 proc_unit = controller.addProcUnit(datatype='Spectra',
125 proc_unit = controller.addProcUnit(datatype='Spectra',
111 inputId=read_unit.getId())
126 inputId=read_unit.getId())
112
127
113 op = proc_unit.addOperation(name='selectChannels')
128 op = proc_unit.addOperation(name='selectChannels')
114 op.addParameter(name='channelList', value='0,1', format='intlist')
129 op.addParameter(name='channelList', value='0,1', format='intlist')
115
130
116 op = proc_unit.addOperation(name='selectHeights')
131 op = proc_unit.addOperation(name='selectHeights')
117 op.addParameter(name='minHei', value='80', format='float')
132 op.addParameter(name='minHei', value='80', format='float')
118 op.addParameter(name='maxHei', value='200', format='float')
133 op.addParameter(name='maxHei', value='200', format='float')
119
134
120 op = proc_unit.addOperation(name='removeDC')
135 op = proc_unit.addOperation(name='removeDC')
121
136
122 op = proc_unit.addOperation(name='SpectraPlot', optype='other')
137 op = proc_unit.addOperation(name='SpectraPlot', optype='other')
123 op.addParameter(name='id', value='6', format='int')
138 op.addParameter(name='id', value='6', format='int')
124 op.addParameter(name='wintitle', value='Spectra', format='str')
139 op.addParameter(name='wintitle', value='Spectra', format='str')
125
140
126 op = procUnitConfObj1.addOperation(name='RTIPlot', optype='other')
141 op = procUnitConfObj1.addOperation(name='RTIPlot', optype='other')
127 op.addParameter(name='id', value='2', format='int')
142 op.addParameter(name='id', value='2', format='int')
128 op.addParameter(name='wintitle', value='RTI', format='str')
143 op.addParameter(name='wintitle', value='RTI', format='str')
129
144
130 controller.start()
145 controller.start()
131
146
132 ``` No newline at end of file
147 ```
@@ -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,7 +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 __version__ = "2.3" No newline at end of file
7 __version__ = "2.3"
@@ -1,1319 +1,1297
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 math
10 import math
11 import time
11 import time
12 from multiprocessing import Process, Queue, cpu_count
12 from multiprocessing import Process, cpu_count
13
14 import schainpy
15 import schainpy.admin
16
13
17 from xml.etree.ElementTree import ElementTree, Element, SubElement, tostring
14 from xml.etree.ElementTree import ElementTree, Element, SubElement, tostring
18 from xml.dom import minidom
15 from xml.dom import minidom
19
16
17 import schainpy
18 import schainpy.admin
20 from schainpy.model import *
19 from schainpy.model import *
21 from time import sleep
20 from schainpy.utils import log
22
21
23 def prettify(elem):
22 DTYPES = {
24 """Return a pretty-printed XML string for the Element.
23 'Voltage': '.r',
25 """
24 'Spectra': '.pdata'
26 rough_string = tostring(elem, 'utf-8')
25 }
27 reparsed = minidom.parseString(rough_string)
26
28 return reparsed.toprettyxml(indent=" ")
27 def MPProject(project, n=cpu_count()):
29
28 '''
30 def multiSchain(child, nProcess=cpu_count(), startDate=None, endDate=None, by_day=False):
29 Project wrapper to run schain in n processes
31 skip = 0
30 '''
32 cursor = 0
31
33 nFiles = None
32 rconf = project.getReadUnitObj()
34 processes = []
33 op = rconf.getOperationObj('run')
35 dt1 = datetime.datetime.strptime(startDate, '%Y/%m/%d')
34 dt1 = op.getParameterValue('startDate')
36 dt2 = datetime.datetime.strptime(endDate, '%Y/%m/%d')
35 dt2 = op.getParameterValue('endDate')
37 days = (dt2 - dt1).days
36 days = (dt2 - dt1).days
38
37
39 for day in range(days+1):
38 for day in range(days+1):
40 skip = 0
39 skip = 0
41 cursor = 0
40 cursor = 0
42 q = Queue()
43 processes = []
41 processes = []
44 dt = (dt1 + datetime.timedelta(day)).strftime('%Y/%m/%d')
42 dt = dt1 + datetime.timedelta(day)
45 firstProcess = Process(target=child, args=(cursor, skip, q, dt))
43 dt_str = dt.strftime('%Y/%m/%d')
46 firstProcess.start()
44 reader = JRODataReader()
47 if by_day:
45 paths, files = reader.searchFilesOffLine(path=rconf.path,
48 continue
46 startDate=dt,
49 nFiles = q.get()
47 endDate=dt,
50 if nFiles==0:
48 ext=DTYPES[rconf.datatype])
49 nFiles = len(files)
50 if nFiles == 0:
51 continue
51 continue
52 firstProcess.terminate()
52 skip = int(math.ceil(nFiles/n))
53 skip = int(math.ceil(nFiles/nProcess))
53 while nFiles > cursor*skip:
54 while True:
54 rconf.update(startDate=dt_str, endDate=dt_str, cursor=cursor,
55 processes.append(Process(target=child, args=(cursor, skip, q, dt)))
55 skip=skip)
56 processes[cursor].start()
56 p = project.clone()
57 if nFiles < cursor*skip:
57 p.start()
58 break
58 processes.append(p)
59 cursor += 1
59 cursor += 1
60
60
61 def beforeExit(exctype, value, trace):
61 def beforeExit(exctype, value, trace):
62 for process in processes:
62 for process in processes:
63 process.terminate()
63 process.terminate()
64 process.join()
64 process.join()
65 print traceback.print_tb(trace)
65 print traceback.print_tb(trace)
66
66
67 sys.excepthook = beforeExit
67 sys.excepthook = beforeExit
68
68
69 for process in processes:
69 for process in processes:
70 process.join()
70 process.join()
71 process.terminate()
71 process.terminate()
72
72
73 time.sleep(3)
73 time.sleep(3)
74
74
75
76 class ParameterConf():
75 class ParameterConf():
77
76
78 id = None
77 id = None
79 name = None
78 name = None
80 value = None
79 value = None
81 format = None
80 format = None
82
81
83 __formated_value = None
82 __formated_value = None
84
83
85 ELEMENTNAME = 'Parameter'
84 ELEMENTNAME = 'Parameter'
86
85
87 def __init__(self):
86 def __init__(self):
88
87
89 self.format = 'str'
88 self.format = 'str'
90
89
91 def getElementName(self):
90 def getElementName(self):
92
91
93 return self.ELEMENTNAME
92 return self.ELEMENTNAME
94
93
95 def getValue(self):
94 def getValue(self):
96
95
97 value = self.value
96 value = self.value
98 format = self.format
97 format = self.format
99
98
100 if self.__formated_value != None:
99 if self.__formated_value != None:
101
100
102 return self.__formated_value
101 return self.__formated_value
103
102
104 if format == 'obj':
103 if format == 'obj':
105 return value
104 return value
106
105
107 if format == 'str':
106 if format == 'str':
108 self.__formated_value = str(value)
107 self.__formated_value = str(value)
109 return self.__formated_value
108 return self.__formated_value
110
109
111 if value == '':
110 if value == '':
112 raise ValueError, "%s: This parameter value is empty" %self.name
111 raise ValueError, '%s: This parameter value is empty' %self.name
113
112
114 if format == 'list':
113 if format == 'list':
115 strList = value.split(',')
114 strList = value.split(',')
116
115
117 self.__formated_value = strList
116 self.__formated_value = strList
118
117
119 return self.__formated_value
118 return self.__formated_value
120
119
121 if format == 'intlist':
120 if format == 'intlist':
122 """
121 '''
123 Example:
122 Example:
124 value = (0,1,2)
123 value = (0,1,2)
125 """
124 '''
126
125
127 new_value = ast.literal_eval(value)
126 new_value = ast.literal_eval(value)
128
127
129 if type(new_value) not in (tuple, list):
128 if type(new_value) not in (tuple, list):
130 new_value = [int(new_value)]
129 new_value = [int(new_value)]
131
130
132 self.__formated_value = new_value
131 self.__formated_value = new_value
133
132
134 return self.__formated_value
133 return self.__formated_value
135
134
136 if format == 'floatlist':
135 if format == 'floatlist':
137 """
136 '''
138 Example:
137 Example:
139 value = (0.5, 1.4, 2.7)
138 value = (0.5, 1.4, 2.7)
140 """
139 '''
141
140
142 new_value = ast.literal_eval(value)
141 new_value = ast.literal_eval(value)
143
142
144 if type(new_value) not in (tuple, list):
143 if type(new_value) not in (tuple, list):
145 new_value = [float(new_value)]
144 new_value = [float(new_value)]
146
145
147 self.__formated_value = new_value
146 self.__formated_value = new_value
148
147
149 return self.__formated_value
148 return self.__formated_value
150
149
151 if format == 'date':
150 if format == 'date':
152 strList = value.split('/')
151 strList = value.split('/')
153 intList = [int(x) for x in strList]
152 intList = [int(x) for x in strList]
154 date = datetime.date(intList[0], intList[1], intList[2])
153 date = datetime.date(intList[0], intList[1], intList[2])
155
154
156 self.__formated_value = date
155 self.__formated_value = date
157
156
158 return self.__formated_value
157 return self.__formated_value
159
158
160 if format == 'time':
159 if format == 'time':
161 strList = value.split(':')
160 strList = value.split(':')
162 intList = [int(x) for x in strList]
161 intList = [int(x) for x in strList]
163 time = datetime.time(intList[0], intList[1], intList[2])
162 time = datetime.time(intList[0], intList[1], intList[2])
164
163
165 self.__formated_value = time
164 self.__formated_value = time
166
165
167 return self.__formated_value
166 return self.__formated_value
168
167
169 if format == 'pairslist':
168 if format == 'pairslist':
170 """
169 '''
171 Example:
170 Example:
172 value = (0,1),(1,2)
171 value = (0,1),(1,2)
173 """
172 '''
174
173
175 new_value = ast.literal_eval(value)
174 new_value = ast.literal_eval(value)
176
175
177 if type(new_value) not in (tuple, list):
176 if type(new_value) not in (tuple, list):
178 raise ValueError, "%s has to be a tuple or list of pairs" %value
177 raise ValueError, '%s has to be a tuple or list of pairs' %value
179
178
180 if type(new_value[0]) not in (tuple, list):
179 if type(new_value[0]) not in (tuple, list):
181 if len(new_value) != 2:
180 if len(new_value) != 2:
182 raise ValueError, "%s has to be a tuple or list of pairs" %value
181 raise ValueError, '%s has to be a tuple or list of pairs' %value
183 new_value = [new_value]
182 new_value = [new_value]
184
183
185 for thisPair in new_value:
184 for thisPair in new_value:
186 if len(thisPair) != 2:
185 if len(thisPair) != 2:
187 raise ValueError, "%s has to be a tuple or list of pairs" %value
186 raise ValueError, '%s has to be a tuple or list of pairs' %value
188
187
189 self.__formated_value = new_value
188 self.__formated_value = new_value
190
189
191 return self.__formated_value
190 return self.__formated_value
192
191
193 if format == 'multilist':
192 if format == 'multilist':
194 """
193 '''
195 Example:
194 Example:
196 value = (0,1,2),(3,4,5)
195 value = (0,1,2),(3,4,5)
197 """
196 '''
198 multiList = ast.literal_eval(value)
197 multiList = ast.literal_eval(value)
199
198
200 if type(multiList[0]) == int:
199 if type(multiList[0]) == int:
201 multiList = ast.literal_eval("(" + value + ")")
200 multiList = ast.literal_eval('(' + value + ')')
202
201
203 self.__formated_value = multiList
202 self.__formated_value = multiList
204
203
205 return self.__formated_value
204 return self.__formated_value
206
205
207 if format == 'bool':
206 if format == 'bool':
208 value = int(value)
207 value = int(value)
209
208
210 if format == 'int':
209 if format == 'int':
211 value = float(value)
210 value = float(value)
212
211
213 format_func = eval(format)
212 format_func = eval(format)
214
213
215 self.__formated_value = format_func(value)
214 self.__formated_value = format_func(value)
216
215
217 return self.__formated_value
216 return self.__formated_value
218
217
219 def updateId(self, new_id):
218 def updateId(self, new_id):
220
219
221 self.id = str(new_id)
220 self.id = str(new_id)
222
221
223 def setup(self, id, name, value, format='str'):
222 def setup(self, id, name, value, format='str'):
224 self.id = str(id)
223 self.id = str(id)
225 self.name = name
224 self.name = name
226 if format == 'obj':
225 if format == 'obj':
227 self.value = value
226 self.value = value
228 else:
227 else:
229 self.value = str(value)
228 self.value = str(value)
230 self.format = str.lower(format)
229 self.format = str.lower(format)
231
230
232 self.getValue()
231 self.getValue()
233
232
234 return 1
233 return 1
235
234
236 def update(self, name, value, format='str'):
235 def update(self, name, value, format='str'):
237
236
238 self.name = name
237 self.name = name
239 self.value = str(value)
238 self.value = str(value)
240 self.format = format
239 self.format = format
241
240
242 def makeXml(self, opElement):
241 def makeXml(self, opElement):
243 if self.name not in ('queue',):
242 if self.name not in ('queue',):
244 parmElement = SubElement(opElement, self.ELEMENTNAME)
243 parmElement = SubElement(opElement, self.ELEMENTNAME)
245 parmElement.set('id', str(self.id))
244 parmElement.set('id', str(self.id))
246 parmElement.set('name', self.name)
245 parmElement.set('name', self.name)
247 parmElement.set('value', self.value)
246 parmElement.set('value', self.value)
248 parmElement.set('format', self.format)
247 parmElement.set('format', self.format)
249
248
250 def readXml(self, parmElement):
249 def readXml(self, parmElement):
251
250
252 self.id = parmElement.get('id')
251 self.id = parmElement.get('id')
253 self.name = parmElement.get('name')
252 self.name = parmElement.get('name')
254 self.value = parmElement.get('value')
253 self.value = parmElement.get('value')
255 self.format = str.lower(parmElement.get('format'))
254 self.format = str.lower(parmElement.get('format'))
256
255
257 #Compatible with old signal chain version
256 #Compatible with old signal chain version
258 if self.format == 'int' and self.name == 'idfigure':
257 if self.format == 'int' and self.name == 'idfigure':
259 self.name = 'id'
258 self.name = 'id'
260
259
261 def printattr(self):
260 def printattr(self):
262
261
263 print "Parameter[%s]: name = %s, value = %s, format = %s" %(self.id, self.name, self.value, self.format)
262 print 'Parameter[%s]: name = %s, value = %s, format = %s' %(self.id, self.name, self.value, self.format)
264
263
265 class OperationConf():
264 class OperationConf():
266
265
267 id = None
266 id = None
268 name = None
267 name = None
269 priority = None
268 priority = None
270 type = None
269 type = None
271
270
272 parmConfObjList = []
271 parmConfObjList = []
273
272
274 ELEMENTNAME = 'Operation'
273 ELEMENTNAME = 'Operation'
275
274
276 def __init__(self):
275 def __init__(self):
277
276
278 self.id = '0'
277 self.id = '0'
279 self.name = None
278 self.name = None
280 self.priority = None
279 self.priority = None
281 self.type = 'self'
280 self.type = 'self'
282
281
283
282
284 def __getNewId(self):
283 def __getNewId(self):
285
284
286 return int(self.id)*10 + len(self.parmConfObjList) + 1
285 return int(self.id)*10 + len(self.parmConfObjList) + 1
287
286
288 def updateId(self, new_id):
287 def updateId(self, new_id):
289
288
290 self.id = str(new_id)
289 self.id = str(new_id)
291
290
292 n = 1
291 n = 1
293 for parmObj in self.parmConfObjList:
292 for parmObj in self.parmConfObjList:
294
293
295 idParm = str(int(new_id)*10 + n)
294 idParm = str(int(new_id)*10 + n)
296 parmObj.updateId(idParm)
295 parmObj.updateId(idParm)
297
296
298 n += 1
297 n += 1
299
298
300 def getElementName(self):
299 def getElementName(self):
301
300
302 return self.ELEMENTNAME
301 return self.ELEMENTNAME
303
302
304 def getParameterObjList(self):
303 def getParameterObjList(self):
305
304
306 return self.parmConfObjList
305 return self.parmConfObjList
307
306
308 def getParameterObj(self, parameterName):
307 def getParameterObj(self, parameterName):
309
308
310 for parmConfObj in self.parmConfObjList:
309 for parmConfObj in self.parmConfObjList:
311
310
312 if parmConfObj.name != parameterName:
311 if parmConfObj.name != parameterName:
313 continue
312 continue
314
313
315 return parmConfObj
314 return parmConfObj
316
315
317 return None
316 return None
318
317
319 def getParameterObjfromValue(self, parameterValue):
318 def getParameterObjfromValue(self, parameterValue):
320
319
321 for parmConfObj in self.parmConfObjList:
320 for parmConfObj in self.parmConfObjList:
322
321
323 if parmConfObj.getValue() != parameterValue:
322 if parmConfObj.getValue() != parameterValue:
324 continue
323 continue
325
324
326 return parmConfObj.getValue()
325 return parmConfObj.getValue()
327
326
328 return None
327 return None
329
328
330 def getParameterValue(self, parameterName):
329 def getParameterValue(self, parameterName):
331
330
332 parameterObj = self.getParameterObj(parameterName)
331 parameterObj = self.getParameterObj(parameterName)
333
332
334 # if not parameterObj:
333 # if not parameterObj:
335 # return None
334 # return None
336
335
337 value = parameterObj.getValue()
336 value = parameterObj.getValue()
338
337
339 return value
338 return value
340
339
341
340
342 def getKwargs(self):
341 def getKwargs(self):
343
342
344 kwargs = {}
343 kwargs = {}
345
344
346 for parmConfObj in self.parmConfObjList:
345 for parmConfObj in self.parmConfObjList:
347 if self.name == 'run' and parmConfObj.name == 'datatype':
346 if self.name == 'run' and parmConfObj.name == 'datatype':
348 continue
347 continue
349
348
350 kwargs[parmConfObj.name] = parmConfObj.getValue()
349 kwargs[parmConfObj.name] = parmConfObj.getValue()
351
350
352 return kwargs
351 return kwargs
353
352
354 def setup(self, id, name, priority, type):
353 def setup(self, id, name, priority, type):
355
354
356 self.id = str(id)
355 self.id = str(id)
357 self.name = name
356 self.name = name
358 self.type = type
357 self.type = type
359 self.priority = priority
358 self.priority = priority
360
359
361 self.parmConfObjList = []
360 self.parmConfObjList = []
362
361
363 def removeParameters(self):
362 def removeParameters(self):
364
363
365 for obj in self.parmConfObjList:
364 for obj in self.parmConfObjList:
366 del obj
365 del obj
367
366
368 self.parmConfObjList = []
367 self.parmConfObjList = []
369
368
370 def addParameter(self, name, value, format='str'):
369 def addParameter(self, name, value, format='str'):
371
370
371 if value is None:
372 return None
372 id = self.__getNewId()
373 id = self.__getNewId()
373
374
374 parmConfObj = ParameterConf()
375 parmConfObj = ParameterConf()
375 if not parmConfObj.setup(id, name, value, format):
376 if not parmConfObj.setup(id, name, value, format):
376 return None
377 return None
377
378
378 self.parmConfObjList.append(parmConfObj)
379 self.parmConfObjList.append(parmConfObj)
379
380
380 return parmConfObj
381 return parmConfObj
381
382
382 def changeParameter(self, name, value, format='str'):
383 def changeParameter(self, name, value, format='str'):
383
384
384 parmConfObj = self.getParameterObj(name)
385 parmConfObj = self.getParameterObj(name)
385 parmConfObj.update(name, value, format)
386 parmConfObj.update(name, value, format)
386
387
387 return parmConfObj
388 return parmConfObj
388
389
389 def makeXml(self, procUnitElement):
390 def makeXml(self, procUnitElement):
390
391
391 opElement = SubElement(procUnitElement, self.ELEMENTNAME)
392 opElement = SubElement(procUnitElement, self.ELEMENTNAME)
392 opElement.set('id', str(self.id))
393 opElement.set('id', str(self.id))
393 opElement.set('name', self.name)
394 opElement.set('name', self.name)
394 opElement.set('type', self.type)
395 opElement.set('type', self.type)
395 opElement.set('priority', str(self.priority))
396 opElement.set('priority', str(self.priority))
396
397
397 for parmConfObj in self.parmConfObjList:
398 for parmConfObj in self.parmConfObjList:
398 parmConfObj.makeXml(opElement)
399 parmConfObj.makeXml(opElement)
399
400
400 def readXml(self, opElement):
401 def readXml(self, opElement):
401
402
402 self.id = opElement.get('id')
403 self.id = opElement.get('id')
403 self.name = opElement.get('name')
404 self.name = opElement.get('name')
404 self.type = opElement.get('type')
405 self.type = opElement.get('type')
405 self.priority = opElement.get('priority')
406 self.priority = opElement.get('priority')
406
407
407 #Compatible with old signal chain version
408 #Compatible with old signal chain version
408 #Use of 'run' method instead 'init'
409 #Use of 'run' method instead 'init'
409 if self.type == 'self' and self.name == 'init':
410 if self.type == 'self' and self.name == 'init':
410 self.name = 'run'
411 self.name = 'run'
411
412
412 self.parmConfObjList = []
413 self.parmConfObjList = []
413
414
414 parmElementList = opElement.iter(ParameterConf().getElementName())
415 parmElementList = opElement.iter(ParameterConf().getElementName())
415
416
416 for parmElement in parmElementList:
417 for parmElement in parmElementList:
417 parmConfObj = ParameterConf()
418 parmConfObj = ParameterConf()
418 parmConfObj.readXml(parmElement)
419 parmConfObj.readXml(parmElement)
419
420
420 #Compatible with old signal chain version
421 #Compatible with old signal chain version
421 #If an 'plot' OPERATION is found, changes name operation by the value of its type PARAMETER
422 #If an 'plot' OPERATION is found, changes name operation by the value of its type PARAMETER
422 if self.type != 'self' and self.name == 'Plot':
423 if self.type != 'self' and self.name == 'Plot':
423 if parmConfObj.format == 'str' and parmConfObj.name == 'type':
424 if parmConfObj.format == 'str' and parmConfObj.name == 'type':
424 self.name = parmConfObj.value
425 self.name = parmConfObj.value
425 continue
426 continue
426
427
427 self.parmConfObjList.append(parmConfObj)
428 self.parmConfObjList.append(parmConfObj)
428
429
429 def printattr(self):
430 def printattr(self):
430
431
431 print "%s[%s]: name = %s, type = %s, priority = %s" %(self.ELEMENTNAME,
432 print '%s[%s]: name = %s, type = %s, priority = %s' %(self.ELEMENTNAME,
432 self.id,
433 self.id,
433 self.name,
434 self.name,
434 self.type,
435 self.type,
435 self.priority)
436 self.priority)
436
437
437 for parmConfObj in self.parmConfObjList:
438 for parmConfObj in self.parmConfObjList:
438 parmConfObj.printattr()
439 parmConfObj.printattr()
439
440
440 def createObject(self, plotter_queue=None):
441 def createObject(self, plotter_queue=None):
441
442
442
443
443 if self.type == 'self':
444 if self.type == 'self':
444 raise ValueError, "This operation type cannot be created"
445 raise ValueError, 'This operation type cannot be created'
445
446
446 if self.type == 'plotter':
447 if self.type == 'plotter':
447 #Plotter(plotter_name)
448 if not plotter_queue:
448 if not plotter_queue:
449 raise ValueError, "plotter_queue is not defined. Use:\nmyProject = Project()\nmyProject.setPlotterQueue(plotter_queue)"
449 raise ValueError, 'plotter_queue is not defined. Use:\nmyProject = Project()\nmyProject.setPlotterQueue(plotter_queue)'
450
450
451 opObj = Plotter(self.name, plotter_queue)
451 opObj = Plotter(self.name, plotter_queue)
452
452
453 if self.type == 'external' or self.type == 'other':
453 if self.type == 'external' or self.type == 'other':
454
454
455 className = eval(self.name)
455 className = eval(self.name)
456 kwargs = self.getKwargs()
456 kwargs = self.getKwargs()
457
457
458 opObj = className(**kwargs)
458 opObj = className(**kwargs)
459
459
460 return opObj
460 return opObj
461
461
462
462
463 class ProcUnitConf():
463 class ProcUnitConf():
464
464
465 id = None
465 id = None
466 name = None
466 name = None
467 datatype = None
467 datatype = None
468 inputId = None
468 inputId = None
469 parentId = None
469 parentId = None
470
470
471 opConfObjList = []
471 opConfObjList = []
472
472
473 procUnitObj = None
473 procUnitObj = None
474 opObjList = []
474 opObjList = []
475
475
476 ELEMENTNAME = 'ProcUnit'
476 ELEMENTNAME = 'ProcUnit'
477
477
478 def __init__(self):
478 def __init__(self):
479
479
480 self.id = None
480 self.id = None
481 self.datatype = None
481 self.datatype = None
482 self.name = None
482 self.name = None
483 self.inputId = None
483 self.inputId = None
484
484
485 self.opConfObjList = []
485 self.opConfObjList = []
486
486
487 self.procUnitObj = None
487 self.procUnitObj = None
488 self.opObjDict = {}
488 self.opObjDict = {}
489
489
490 def __getPriority(self):
490 def __getPriority(self):
491
491
492 return len(self.opConfObjList)+1
492 return len(self.opConfObjList)+1
493
493
494 def __getNewId(self):
494 def __getNewId(self):
495
495
496 return int(self.id)*10 + len(self.opConfObjList) + 1
496 return int(self.id)*10 + len(self.opConfObjList) + 1
497
497
498 def getElementName(self):
498 def getElementName(self):
499
499
500 return self.ELEMENTNAME
500 return self.ELEMENTNAME
501
501
502 def getId(self):
502 def getId(self):
503
503
504 return self.id
504 return self.id
505
505
506 def updateId(self, new_id, parentId=parentId):
506 def updateId(self, new_id, parentId=parentId):
507
507
508
508
509 new_id = int(parentId)*10 + (int(self.id) % 10)
509 new_id = int(parentId)*10 + (int(self.id) % 10)
510 new_inputId = int(parentId)*10 + (int(self.inputId) % 10)
510 new_inputId = int(parentId)*10 + (int(self.inputId) % 10)
511
511
512 #If this proc unit has not inputs
512 #If this proc unit has not inputs
513 if self.inputId == '0':
513 if self.inputId == '0':
514 new_inputId = 0
514 new_inputId = 0
515
515
516 n = 1
516 n = 1
517 for opConfObj in self.opConfObjList:
517 for opConfObj in self.opConfObjList:
518
518
519 idOp = str(int(new_id)*10 + n)
519 idOp = str(int(new_id)*10 + n)
520 opConfObj.updateId(idOp)
520 opConfObj.updateId(idOp)
521
521
522 n += 1
522 n += 1
523
523
524 self.parentId = str(parentId)
524 self.parentId = str(parentId)
525 self.id = str(new_id)
525 self.id = str(new_id)
526 self.inputId = str(new_inputId)
526 self.inputId = str(new_inputId)
527
527
528
528
529 def getInputId(self):
529 def getInputId(self):
530
530
531 return self.inputId
531 return self.inputId
532
532
533 def getOperationObjList(self):
533 def getOperationObjList(self):
534
534
535 return self.opConfObjList
535 return self.opConfObjList
536
536
537 def getOperationObj(self, name=None):
537 def getOperationObj(self, name=None):
538
538
539 for opConfObj in self.opConfObjList:
539 for opConfObj in self.opConfObjList:
540
540
541 if opConfObj.name != name:
541 if opConfObj.name != name:
542 continue
542 continue
543
543
544 return opConfObj
544 return opConfObj
545
545
546 return None
546 return None
547
547
548 def getOpObjfromParamValue(self, value=None):
548 def getOpObjfromParamValue(self, value=None):
549
549
550 for opConfObj in self.opConfObjList:
550 for opConfObj in self.opConfObjList:
551 if opConfObj.getParameterObjfromValue(parameterValue=value) != value:
551 if opConfObj.getParameterObjfromValue(parameterValue=value) != value:
552 continue
552 continue
553 return opConfObj
553 return opConfObj
554 return None
554 return None
555
555
556 def getProcUnitObj(self):
556 def getProcUnitObj(self):
557
557
558 return self.procUnitObj
558 return self.procUnitObj
559
559
560 def setup(self, id, name, datatype, inputId, parentId=None):
560 def setup(self, id, name, datatype, inputId, parentId=None):
561
561
562 #Compatible with old signal chain version
562 #Compatible with old signal chain version
563 if datatype==None and name==None:
563 if datatype==None and name==None:
564 raise ValueError, "datatype or name should be defined"
564 raise ValueError, 'datatype or name should be defined'
565
565
566 if name==None:
566 if name==None:
567 if 'Proc' in datatype:
567 if 'Proc' in datatype:
568 name = datatype
568 name = datatype
569 else:
569 else:
570 name = '%sProc' %(datatype)
570 name = '%sProc' %(datatype)
571
571
572 if datatype==None:
572 if datatype==None:
573 datatype = name.replace('Proc','')
573 datatype = name.replace('Proc','')
574
574
575 self.id = str(id)
575 self.id = str(id)
576 self.name = name
576 self.name = name
577 self.datatype = datatype
577 self.datatype = datatype
578 self.inputId = inputId
578 self.inputId = inputId
579 self.parentId = parentId
579 self.parentId = parentId
580
580
581 self.opConfObjList = []
581 self.opConfObjList = []
582
582
583 self.addOperation(name='run', optype='self')
583 self.addOperation(name='run', optype='self')
584
584
585 def removeOperations(self):
585 def removeOperations(self):
586
586
587 for obj in self.opConfObjList:
587 for obj in self.opConfObjList:
588 del obj
588 del obj
589
589
590 self.opConfObjList = []
590 self.opConfObjList = []
591 self.addOperation(name='run')
591 self.addOperation(name='run')
592
592
593 def addParameter(self, **kwargs):
593 def addParameter(self, **kwargs):
594 '''
594 '''
595 Add parameters to "run" operation
595 Add parameters to 'run' operation
596 '''
596 '''
597 opObj = self.opConfObjList[0]
597 opObj = self.opConfObjList[0]
598
598
599 opObj.addParameter(**kwargs)
599 opObj.addParameter(**kwargs)
600
600
601 return opObj
601 return opObj
602
602
603 def addOperation(self, name, optype='self'):
603 def addOperation(self, name, optype='self'):
604
604
605 id = self.__getNewId()
605 id = self.__getNewId()
606 priority = self.__getPriority()
606 priority = self.__getPriority()
607
607
608 opConfObj = OperationConf()
608 opConfObj = OperationConf()
609 opConfObj.setup(id, name=name, priority=priority, type=optype)
609 opConfObj.setup(id, name=name, priority=priority, type=optype)
610
610
611 self.opConfObjList.append(opConfObj)
611 self.opConfObjList.append(opConfObj)
612
612
613 return opConfObj
613 return opConfObj
614
614
615 def makeXml(self, projectElement):
615 def makeXml(self, projectElement):
616
616
617 procUnitElement = SubElement(projectElement, self.ELEMENTNAME)
617 procUnitElement = SubElement(projectElement, self.ELEMENTNAME)
618 procUnitElement.set('id', str(self.id))
618 procUnitElement.set('id', str(self.id))
619 procUnitElement.set('name', self.name)
619 procUnitElement.set('name', self.name)
620 procUnitElement.set('datatype', self.datatype)
620 procUnitElement.set('datatype', self.datatype)
621 procUnitElement.set('inputId', str(self.inputId))
621 procUnitElement.set('inputId', str(self.inputId))
622
622
623 for opConfObj in self.opConfObjList:
623 for opConfObj in self.opConfObjList:
624 opConfObj.makeXml(procUnitElement)
624 opConfObj.makeXml(procUnitElement)
625
625
626 def readXml(self, upElement):
626 def readXml(self, upElement):
627
627
628 self.id = upElement.get('id')
628 self.id = upElement.get('id')
629 self.name = upElement.get('name')
629 self.name = upElement.get('name')
630 self.datatype = upElement.get('datatype')
630 self.datatype = upElement.get('datatype')
631 self.inputId = upElement.get('inputId')
631 self.inputId = upElement.get('inputId')
632
632
633 if self.ELEMENTNAME == "ReadUnit":
633 if self.ELEMENTNAME == 'ReadUnit':
634 self.datatype = self.datatype.replace("Reader", "")
634 self.datatype = self.datatype.replace('Reader', '')
635
635
636 if self.ELEMENTNAME == "ProcUnit":
636 if self.ELEMENTNAME == 'ProcUnit':
637 self.datatype = self.datatype.replace("Proc", "")
637 self.datatype = self.datatype.replace('Proc', '')
638
638
639 if self.inputId == 'None':
639 if self.inputId == 'None':
640 self.inputId = '0'
640 self.inputId = '0'
641
641
642 self.opConfObjList = []
642 self.opConfObjList = []
643
643
644 opElementList = upElement.iter(OperationConf().getElementName())
644 opElementList = upElement.iter(OperationConf().getElementName())
645
645
646 for opElement in opElementList:
646 for opElement in opElementList:
647 opConfObj = OperationConf()
647 opConfObj = OperationConf()
648 opConfObj.readXml(opElement)
648 opConfObj.readXml(opElement)
649 self.opConfObjList.append(opConfObj)
649 self.opConfObjList.append(opConfObj)
650
650
651 def printattr(self):
651 def printattr(self):
652
652
653 print "%s[%s]: name = %s, datatype = %s, inputId = %s" %(self.ELEMENTNAME,
653 print '%s[%s]: name = %s, datatype = %s, inputId = %s' %(self.ELEMENTNAME,
654 self.id,
654 self.id,
655 self.name,
655 self.name,
656 self.datatype,
656 self.datatype,
657 self.inputId)
657 self.inputId)
658
658
659 for opConfObj in self.opConfObjList:
659 for opConfObj in self.opConfObjList:
660 opConfObj.printattr()
660 opConfObj.printattr()
661
661
662
662
663 def getKwargs(self):
663 def getKwargs(self):
664
664
665 opObj = self.opConfObjList[0]
665 opObj = self.opConfObjList[0]
666 kwargs = opObj.getKwargs()
666 kwargs = opObj.getKwargs()
667
667
668 return kwargs
668 return kwargs
669
669
670 def createObjects(self, plotter_queue=None):
670 def createObjects(self, plotter_queue=None):
671
671
672 className = eval(self.name)
672 className = eval(self.name)
673 kwargs = self.getKwargs()
673 kwargs = self.getKwargs()
674 procUnitObj = className(**kwargs)
674 procUnitObj = className(**kwargs)
675
675
676 for opConfObj in self.opConfObjList:
676 for opConfObj in self.opConfObjList:
677
677
678 if opConfObj.type=='self' and self.name=='run':
678 if opConfObj.type=='self' and self.name=='run':
679 continue
679 continue
680 elif opConfObj.type=='self':
680 elif opConfObj.type=='self':
681 procUnitObj.addOperationKwargs(opConfObj.id, **opConfObj.getKwargs())
681 procUnitObj.addOperationKwargs(opConfObj.id, **opConfObj.getKwargs())
682 continue
682 continue
683
683
684 opObj = opConfObj.createObject(plotter_queue)
684 opObj = opConfObj.createObject(plotter_queue)
685
685
686 self.opObjDict[opConfObj.id] = opObj
686 self.opObjDict[opConfObj.id] = opObj
687
687
688 procUnitObj.addOperation(opObj, opConfObj.id)
688 procUnitObj.addOperation(opObj, opConfObj.id)
689
689
690 self.procUnitObj = procUnitObj
690 self.procUnitObj = procUnitObj
691
691
692 return procUnitObj
692 return procUnitObj
693
693
694 def run(self):
694 def run(self):
695
695
696 is_ok = False
696 is_ok = False
697
697
698 for opConfObj in self.opConfObjList:
698 for opConfObj in self.opConfObjList:
699
699
700 kwargs = {}
700 kwargs = {}
701 for parmConfObj in opConfObj.getParameterObjList():
701 for parmConfObj in opConfObj.getParameterObjList():
702 if opConfObj.name == 'run' and parmConfObj.name == 'datatype':
702 if opConfObj.name == 'run' and parmConfObj.name == 'datatype':
703 continue
703 continue
704
704
705 kwargs[parmConfObj.name] = parmConfObj.getValue()
705 kwargs[parmConfObj.name] = parmConfObj.getValue()
706
706
707 sts = self.procUnitObj.call(opType = opConfObj.type,
707 sts = self.procUnitObj.call(opType = opConfObj.type,
708 opName = opConfObj.name,
708 opName = opConfObj.name,
709 opId = opConfObj.id)
709 opId = opConfObj.id)
710
710
711 is_ok = is_ok or sts
711 is_ok = is_ok or sts
712
712
713 return is_ok
713 return is_ok
714
714
715 def close(self):
715 def close(self):
716
716
717 for opConfObj in self.opConfObjList:
717 for opConfObj in self.opConfObjList:
718 if opConfObj.type == 'self':
718 if opConfObj.type == 'self':
719 continue
719 continue
720
720
721 opObj = self.procUnitObj.getOperationObj(opConfObj.id)
721 opObj = self.procUnitObj.getOperationObj(opConfObj.id)
722 opObj.close()
722 opObj.close()
723
723
724 self.procUnitObj.close()
724 self.procUnitObj.close()
725
725
726 return
726 return
727
727
728 class ReadUnitConf(ProcUnitConf):
728 class ReadUnitConf(ProcUnitConf):
729
729
730 path = None
730 path = None
731 startDate = None
731 startDate = None
732 endDate = None
732 endDate = None
733 startTime = None
733 startTime = None
734 endTime = None
734 endTime = None
735
735
736 ELEMENTNAME = 'ReadUnit'
736 ELEMENTNAME = 'ReadUnit'
737
737
738 def __init__(self):
738 def __init__(self):
739
739
740 self.id = None
740 self.id = None
741 self.datatype = None
741 self.datatype = None
742 self.name = None
742 self.name = None
743 self.inputId = None
743 self.inputId = None
744
744
745 self.parentId = None
745 self.parentId = None
746
746
747 self.opConfObjList = []
747 self.opConfObjList = []
748 self.opObjList = []
748 self.opObjList = []
749
749
750 def getElementName(self):
750 def getElementName(self):
751
751
752 return self.ELEMENTNAME
752 return self.ELEMENTNAME
753
753
754 def setup(self, id, name, datatype, path='', startDate="", endDate="", startTime="",
754 def setup(self, id, name, datatype, path='', startDate='', endDate='',
755 endTime="", parentId=None, queue=None, server=None, **kwargs):
755 startTime='', endTime='', parentId=None, server=None, **kwargs):
756
756
757 #Compatible with old signal chain version
757 #Compatible with old signal chain version
758 if datatype==None and name==None:
758 if datatype==None and name==None:
759 raise ValueError, "datatype or name should be defined"
759 raise ValueError, 'datatype or name should be defined'
760
760
761 if name==None:
761 if name==None:
762 if 'Reader' in datatype:
762 if 'Reader' in datatype:
763 name = datatype
763 name = datatype
764 else:
764 else:
765 name = '%sReader' %(datatype)
765 name = '%sReader' %(datatype)
766 if datatype==None:
766 if datatype==None:
767 datatype = name.replace('Reader','')
767 datatype = name.replace('Reader','')
768
768
769 self.id = id
769 self.id = id
770 self.name = name
770 self.name = name
771 self.datatype = datatype
771 self.datatype = datatype
772 if path != '':
772 if path != '':
773 self.path = os.path.abspath(path)
773 self.path = os.path.abspath(path)
774 self.startDate = startDate
774 self.startDate = startDate
775 self.endDate = endDate
775 self.endDate = endDate
776 self.startTime = startTime
776 self.startTime = startTime
777 self.endTime = endTime
777 self.endTime = endTime
778
779 self.inputId = '0'
778 self.inputId = '0'
780 self.parentId = parentId
779 self.parentId = parentId
781 self.queue = queue
782 self.server = server
780 self.server = server
783 self.addRunOperation(**kwargs)
781 self.addRunOperation(**kwargs)
784
782
785 def update(self, datatype, path, startDate, endDate, startTime, endTime, parentId=None, name=None, **kwargs):
783 def update(self, **kwargs):
786
784
787 #Compatible with old signal chain version
785 if 'datatype' in kwargs:
788 if datatype==None and name==None:
786 datatype = kwargs.pop('datatype')
789 raise ValueError, "datatype or name should be defined"
790
791 if name==None:
792 if 'Reader' in datatype:
787 if 'Reader' in datatype:
793 name = datatype
788 self.name = datatype
794 else:
789 else:
795 name = '%sReader' %(datatype)
790 self.name = '%sReader' %(datatype)
796
791 self.datatype = self.name.replace('Reader', '')
797 if datatype==None:
798 datatype = name.replace('Reader','')
799
800 self.datatype = datatype
801 self.name = name
802 self.path = path
803 self.startDate = startDate
804 self.endDate = endDate
805 self.startTime = startTime
806 self.endTime = endTime
807
792
793 attrs = ('path', 'startDate', 'endDate', 'startTime', 'endTime', 'parentId')
794
795 for attr in attrs:
796 if attr in kwargs:
797 setattr(self, attr, kwargs.pop(attr))
798
808 self.inputId = '0'
799 self.inputId = '0'
809 self.parentId = parentId
810
811 self.updateRunOperation(**kwargs)
800 self.updateRunOperation(**kwargs)
812
801
813 def removeOperations(self):
802 def removeOperations(self):
814
803
815 for obj in self.opConfObjList:
804 for obj in self.opConfObjList:
816 del obj
805 del obj
817
806
818 self.opConfObjList = []
807 self.opConfObjList = []
819
808
820 def addRunOperation(self, **kwargs):
809 def addRunOperation(self, **kwargs):
821
810
822 opObj = self.addOperation(name = 'run', optype = 'self')
811 opObj = self.addOperation(name = 'run', optype = 'self')
823
812
824 if self.server is None:
813 if self.server is None:
825 opObj.addParameter(name='datatype' , value=self.datatype, format='str')
814 opObj.addParameter(name='datatype', value=self.datatype, format='str')
826 opObj.addParameter(name='path' , value=self.path, format='str')
815 opObj.addParameter(name='path', value=self.path, format='str')
827 opObj.addParameter(name='startDate' , value=self.startDate, format='date')
816 opObj.addParameter(name='startDate', value=self.startDate, format='date')
828 opObj.addParameter(name='endDate' , value=self.endDate, format='date')
817 opObj.addParameter(name='endDate', value=self.endDate, format='date')
829 opObj.addParameter(name='startTime' , value=self.startTime, format='time')
818 opObj.addParameter(name='startTime', value=self.startTime, format='time')
830 opObj.addParameter(name='endTime' , value=self.endTime, format='time')
819 opObj.addParameter(name='endTime', value=self.endTime, format='time')
831 opObj.addParameter(name='queue' , value=self.queue, format='obj')
820
832 for key, value in kwargs.items():
821 for key, value in kwargs.items():
833 opObj.addParameter(name=key, value=value, format=type(value).__name__)
822 opObj.addParameter(name=key, value=value, format=type(value).__name__)
834 else:
823 else:
835 opObj.addParameter(name='server' , value=self.server, format='str')
824 opObj.addParameter(name='server' , value=self.server, format='str')
836
825
837
826
838 return opObj
827 return opObj
839
828
840 def updateRunOperation(self, **kwargs):
829 def updateRunOperation(self, **kwargs):
841
830
842 opObj = self.getOperationObj(name = 'run')
831 opObj = self.getOperationObj(name='run')
843 opObj.removeParameters()
832 opObj.removeParameters()
844
833
845 opObj.addParameter(name='datatype' , value=self.datatype, format='str')
834 opObj.addParameter(name='datatype', value=self.datatype, format='str')
846 opObj.addParameter(name='path' , value=self.path, format='str')
835 opObj.addParameter(name='path', value=self.path, format='str')
847 opObj.addParameter(name='startDate' , value=self.startDate, format='date')
836 opObj.addParameter(name='startDate', value=self.startDate, format='date')
848 opObj.addParameter(name='endDate' , value=self.endDate, format='date')
837 opObj.addParameter(name='endDate', value=self.endDate, format='date')
849 opObj.addParameter(name='startTime' , value=self.startTime, format='time')
838 opObj.addParameter(name='startTime', value=self.startTime, format='time')
850 opObj.addParameter(name='endTime' , value=self.endTime, format='time')
839 opObj.addParameter(name='endTime', value=self.endTime, format='time')
851
840
852 for key, value in kwargs.items():
841 for key, value in kwargs.items():
853 opObj.addParameter(name=key, value=value, format=type(value).__name__)
842 opObj.addParameter(name=key, value=value, format=type(value).__name__)
854
843
855 return opObj
844 return opObj
856
845
857 # def makeXml(self, projectElement):
858 #
859 # procUnitElement = SubElement(projectElement, self.ELEMENTNAME)
860 # procUnitElement.set('id', str(self.id))
861 # procUnitElement.set('name', self.name)
862 # procUnitElement.set('datatype', self.datatype)
863 # procUnitElement.set('inputId', str(self.inputId))
864 #
865 # for opConfObj in self.opConfObjList:
866 # opConfObj.makeXml(procUnitElement)
867
868 def readXml(self, upElement):
846 def readXml(self, upElement):
869
847
870 self.id = upElement.get('id')
848 self.id = upElement.get('id')
871 self.name = upElement.get('name')
849 self.name = upElement.get('name')
872 self.datatype = upElement.get('datatype')
850 self.datatype = upElement.get('datatype')
873 self.inputId = upElement.get('inputId')
851 self.inputId = upElement.get('inputId')
874
852
875 if self.ELEMENTNAME == "ReadUnit":
853 if self.ELEMENTNAME == 'ReadUnit':
876 self.datatype = self.datatype.replace("Reader", "")
854 self.datatype = self.datatype.replace('Reader', '')
877
855
878 if self.inputId == 'None':
856 if self.inputId == 'None':
879 self.inputId = '0'
857 self.inputId = '0'
880
858
881 self.opConfObjList = []
859 self.opConfObjList = []
882
860
883 opElementList = upElement.iter(OperationConf().getElementName())
861 opElementList = upElement.iter(OperationConf().getElementName())
884
862
885 for opElement in opElementList:
863 for opElement in opElementList:
886 opConfObj = OperationConf()
864 opConfObj = OperationConf()
887 opConfObj.readXml(opElement)
865 opConfObj.readXml(opElement)
888 self.opConfObjList.append(opConfObj)
866 self.opConfObjList.append(opConfObj)
889
867
890 if opConfObj.name == 'run':
868 if opConfObj.name == 'run':
891 self.path = opConfObj.getParameterValue('path')
869 self.path = opConfObj.getParameterValue('path')
892 self.startDate = opConfObj.getParameterValue('startDate')
870 self.startDate = opConfObj.getParameterValue('startDate')
893 self.endDate = opConfObj.getParameterValue('endDate')
871 self.endDate = opConfObj.getParameterValue('endDate')
894 self.startTime = opConfObj.getParameterValue('startTime')
872 self.startTime = opConfObj.getParameterValue('startTime')
895 self.endTime = opConfObj.getParameterValue('endTime')
873 self.endTime = opConfObj.getParameterValue('endTime')
896
874
897 class Project():
875 class Project(Process):
898
876
899 id = None
877 id = None
900 name = None
878 # name = None
901 description = None
879 description = None
902 filename = None
880 filename = None
903
881
904 procUnitConfObjDict = None
882 procUnitConfObjDict = None
905
883
906 ELEMENTNAME = 'Project'
884 ELEMENTNAME = 'Project'
907
885
908 plotterQueue = None
886 plotterQueue = None
909
887
910 def __init__(self, plotter_queue=None):
888 def __init__(self, plotter_queue=None):
911
889
890 Process.__init__(self)
912 self.id = None
891 self.id = None
913 self.name = None
892 # self.name = None
914 self.description = None
893 self.description = None
915
894
916 self.plotterQueue = plotter_queue
895 self.plotterQueue = plotter_queue
917
896
918 self.procUnitConfObjDict = {}
897 self.procUnitConfObjDict = {}
919
898
920 def __getNewId(self):
899 def __getNewId(self):
921
900
922 idList = self.procUnitConfObjDict.keys()
901 idList = self.procUnitConfObjDict.keys()
923
902
924 id = int(self.id)*10
903 id = int(self.id)*10
925
904
926 while True:
905 while True:
927 id += 1
906 id += 1
928
907
929 if str(id) in idList:
908 if str(id) in idList:
930 continue
909 continue
931
910
932 break
911 break
933
912
934 return str(id)
913 return str(id)
935
914
936 def getElementName(self):
915 def getElementName(self):
937
916
938 return self.ELEMENTNAME
917 return self.ELEMENTNAME
939
918
940 def getId(self):
919 def getId(self):
941
920
942 return self.id
921 return self.id
943
922
944 def updateId(self, new_id):
923 def updateId(self, new_id):
945
924
946 self.id = str(new_id)
925 self.id = str(new_id)
947
926
948 keyList = self.procUnitConfObjDict.keys()
927 keyList = self.procUnitConfObjDict.keys()
949 keyList.sort()
928 keyList.sort()
950
929
951 n = 1
930 n = 1
952 newProcUnitConfObjDict = {}
931 newProcUnitConfObjDict = {}
953
932
954 for procKey in keyList:
933 for procKey in keyList:
955
934
956 procUnitConfObj = self.procUnitConfObjDict[procKey]
935 procUnitConfObj = self.procUnitConfObjDict[procKey]
957 idProcUnit = str(int(self.id)*10 + n)
936 idProcUnit = str(int(self.id)*10 + n)
958 procUnitConfObj.updateId(idProcUnit, parentId = self.id)
937 procUnitConfObj.updateId(idProcUnit, parentId = self.id)
959
938
960 newProcUnitConfObjDict[idProcUnit] = procUnitConfObj
939 newProcUnitConfObjDict[idProcUnit] = procUnitConfObj
961 n += 1
940 n += 1
962
941
963 self.procUnitConfObjDict = newProcUnitConfObjDict
942 self.procUnitConfObjDict = newProcUnitConfObjDict
964
943
965 def setup(self, id, name, description):
944 def setup(self, id, name='', description=''):
966
945
946 print
947 print '*'*60
948 print ' Starting SIGNAL CHAIN PROCESSING v%s ' % schainpy.__version__
949 print '*'*60
950 print
967 self.id = str(id)
951 self.id = str(id)
968 self.name = name
969 self.description = description
952 self.description = description
970
953
971 def update(self, name, description):
954 def update(self, name, description):
972
955
973 self.name = name
974 self.description = description
956 self.description = description
975
957
958 def clone(self):
959
960 p = Project()
961 p.procUnitConfObjDict = self.procUnitConfObjDict
962 return p
963
976 def addReadUnit(self, id=None, datatype=None, name=None, **kwargs):
964 def addReadUnit(self, id=None, datatype=None, name=None, **kwargs):
977
965
978 if id is None:
966 if id is None:
979 idReadUnit = self.__getNewId()
967 idReadUnit = self.__getNewId()
980 else:
968 else:
981 idReadUnit = str(id)
969 idReadUnit = str(id)
982
970
983 readUnitConfObj = ReadUnitConf()
971 readUnitConfObj = ReadUnitConf()
984 readUnitConfObj.setup(idReadUnit, name, datatype, parentId=self.id, **kwargs)
972 readUnitConfObj.setup(idReadUnit, name, datatype, parentId=self.id, **kwargs)
985
973
986 self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj
974 self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj
987
975
988 return readUnitConfObj
976 return readUnitConfObj
989
977
990 def addProcUnit(self, inputId='0', datatype=None, name=None):
978 def addProcUnit(self, inputId='0', datatype=None, name=None):
991
979
992 idProcUnit = self.__getNewId()
980 idProcUnit = self.__getNewId()
993
981
994 procUnitConfObj = ProcUnitConf()
982 procUnitConfObj = ProcUnitConf()
995 procUnitConfObj.setup(idProcUnit, name, datatype, inputId, parentId=self.id)
983 procUnitConfObj.setup(idProcUnit, name, datatype, inputId, parentId=self.id)
996
984
997 self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj
985 self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj
998
986
999 return procUnitConfObj
987 return procUnitConfObj
1000
988
1001 def removeProcUnit(self, id):
989 def removeProcUnit(self, id):
1002
990
1003 if id in self.procUnitConfObjDict.keys():
991 if id in self.procUnitConfObjDict.keys():
1004 self.procUnitConfObjDict.pop(id)
992 self.procUnitConfObjDict.pop(id)
1005
993
1006 def getReadUnitId(self):
994 def getReadUnitId(self):
1007
995
1008 readUnitConfObj = self.getReadUnitObj()
996 readUnitConfObj = self.getReadUnitObj()
1009
997
1010 return readUnitConfObj.id
998 return readUnitConfObj.id
1011
999
1012 def getReadUnitObj(self):
1000 def getReadUnitObj(self):
1013
1001
1014 for obj in self.procUnitConfObjDict.values():
1002 for obj in self.procUnitConfObjDict.values():
1015 if obj.getElementName() == "ReadUnit":
1003 if obj.getElementName() == 'ReadUnit':
1016 return obj
1004 return obj
1017
1005
1018 return None
1006 return None
1019
1007
1020 def getProcUnitObj(self, id=None, name=None):
1008 def getProcUnitObj(self, id=None, name=None):
1021
1009
1022 if id != None:
1010 if id != None:
1023 return self.procUnitConfObjDict[id]
1011 return self.procUnitConfObjDict[id]
1024
1012
1025 if name != None:
1013 if name != None:
1026 return self.getProcUnitObjByName(name)
1014 return self.getProcUnitObjByName(name)
1027
1015
1028 return None
1016 return None
1029
1017
1030 def getProcUnitObjByName(self, name):
1018 def getProcUnitObjByName(self, name):
1031
1019
1032 for obj in self.procUnitConfObjDict.values():
1020 for obj in self.procUnitConfObjDict.values():
1033 if obj.name == name:
1021 if obj.name == name:
1034 return obj
1022 return obj
1035
1023
1036 return None
1024 return None
1037
1025
1038 def procUnitItems(self):
1026 def procUnitItems(self):
1039
1027
1040 return self.procUnitConfObjDict.items()
1028 return self.procUnitConfObjDict.items()
1041
1029
1042 def makeXml(self):
1030 def makeXml(self):
1043
1031
1044 projectElement = Element('Project')
1032 projectElement = Element('Project')
1045 projectElement.set('id', str(self.id))
1033 projectElement.set('id', str(self.id))
1046 projectElement.set('name', self.name)
1034 projectElement.set('name', self.name)
1047 projectElement.set('description', self.description)
1035 projectElement.set('description', self.description)
1048
1036
1049 for procUnitConfObj in self.procUnitConfObjDict.values():
1037 for procUnitConfObj in self.procUnitConfObjDict.values():
1050 procUnitConfObj.makeXml(projectElement)
1038 procUnitConfObj.makeXml(projectElement)
1051
1039
1052 self.projectElement = projectElement
1040 self.projectElement = projectElement
1053
1041
1054 def writeXml(self, filename=None):
1042 def writeXml(self, filename=None):
1055
1043
1056 if filename == None:
1044 if filename == None:
1057 if self.filename:
1045 if self.filename:
1058 filename = self.filename
1046 filename = self.filename
1059 else:
1047 else:
1060 filename = "schain.xml"
1048 filename = 'schain.xml'
1061
1049
1062 if not filename:
1050 if not filename:
1063 print "filename has not been defined. Use setFilename(filename) for do it."
1051 print 'filename has not been defined. Use setFilename(filename) for do it.'
1064 return 0
1052 return 0
1065
1053
1066 abs_file = os.path.abspath(filename)
1054 abs_file = os.path.abspath(filename)
1067
1055
1068 if not os.access(os.path.dirname(abs_file), os.W_OK):
1056 if not os.access(os.path.dirname(abs_file), os.W_OK):
1069 print "No write permission on %s" %os.path.dirname(abs_file)
1057 print 'No write permission on %s' %os.path.dirname(abs_file)
1070 return 0
1058 return 0
1071
1059
1072 if os.path.isfile(abs_file) and not(os.access(abs_file, os.W_OK)):
1060 if os.path.isfile(abs_file) and not(os.access(abs_file, os.W_OK)):
1073 print "File %s already exists and it could not be overwriten" %abs_file
1061 print 'File %s already exists and it could not be overwriten' %abs_file
1074 return 0
1062 return 0
1075
1063
1076 self.makeXml()
1064 self.makeXml()
1077
1065
1078 ElementTree(self.projectElement).write(abs_file, method='xml')
1066 ElementTree(self.projectElement).write(abs_file, method='xml')
1079
1067
1080 self.filename = abs_file
1068 self.filename = abs_file
1081
1069
1082 return 1
1070 return 1
1083
1071
1084 def readXml(self, filename = None):
1072 def readXml(self, filename = None):
1085
1073
1086 if not filename:
1074 if not filename:
1087 print "filename is not defined"
1075 print 'filename is not defined'
1088 return 0
1076 return 0
1089
1077
1090 abs_file = os.path.abspath(filename)
1078 abs_file = os.path.abspath(filename)
1091
1079
1092 if not os.path.isfile(abs_file):
1080 if not os.path.isfile(abs_file):
1093 print "%s file does not exist" %abs_file
1081 print '%s file does not exist' %abs_file
1094 return 0
1082 return 0
1095
1083
1096 self.projectElement = None
1084 self.projectElement = None
1097 self.procUnitConfObjDict = {}
1085 self.procUnitConfObjDict = {}
1098
1086
1099 try:
1087 try:
1100 self.projectElement = ElementTree().parse(abs_file)
1088 self.projectElement = ElementTree().parse(abs_file)
1101 except:
1089 except:
1102 print "Error reading %s, verify file format" %filename
1090 print 'Error reading %s, verify file format' %filename
1103 return 0
1091 return 0
1104
1092
1105 self.project = self.projectElement.tag
1093 self.project = self.projectElement.tag
1106
1094
1107 self.id = self.projectElement.get('id')
1095 self.id = self.projectElement.get('id')
1108 self.name = self.projectElement.get('name')
1096 self.name = self.projectElement.get('name')
1109 self.description = self.projectElement.get('description')
1097 self.description = self.projectElement.get('description')
1110
1098
1111 readUnitElementList = self.projectElement.iter(ReadUnitConf().getElementName())
1099 readUnitElementList = self.projectElement.iter(ReadUnitConf().getElementName())
1112
1100
1113 for readUnitElement in readUnitElementList:
1101 for readUnitElement in readUnitElementList:
1114 readUnitConfObj = ReadUnitConf()
1102 readUnitConfObj = ReadUnitConf()
1115 readUnitConfObj.readXml(readUnitElement)
1103 readUnitConfObj.readXml(readUnitElement)
1116
1104
1117 if readUnitConfObj.parentId == None:
1105 if readUnitConfObj.parentId == None:
1118 readUnitConfObj.parentId = self.id
1106 readUnitConfObj.parentId = self.id
1119
1107
1120 self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj
1108 self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj
1121
1109
1122 procUnitElementList = self.projectElement.iter(ProcUnitConf().getElementName())
1110 procUnitElementList = self.projectElement.iter(ProcUnitConf().getElementName())
1123
1111
1124 for procUnitElement in procUnitElementList:
1112 for procUnitElement in procUnitElementList:
1125 procUnitConfObj = ProcUnitConf()
1113 procUnitConfObj = ProcUnitConf()
1126 procUnitConfObj.readXml(procUnitElement)
1114 procUnitConfObj.readXml(procUnitElement)
1127
1115
1128 if procUnitConfObj.parentId == None:
1116 if procUnitConfObj.parentId == None:
1129 procUnitConfObj.parentId = self.id
1117 procUnitConfObj.parentId = self.id
1130
1118
1131 self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj
1119 self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj
1132
1120
1133 self.filename = abs_file
1121 self.filename = abs_file
1134
1122
1135 return 1
1123 return 1
1136
1124
1137 def printattr(self):
1125 def printattr(self):
1138
1126
1139 print "Project[%s]: name = %s, description = %s" %(self.id,
1127 print 'Project[%s]: name = %s, description = %s' %(self.id,
1140 self.name,
1128 self.name,
1141 self.description)
1129 self.description)
1142
1130
1143 for procUnitConfObj in self.procUnitConfObjDict.values():
1131 for procUnitConfObj in self.procUnitConfObjDict.values():
1144 procUnitConfObj.printattr()
1132 procUnitConfObj.printattr()
1145
1133
1146 def createObjects(self):
1134 def createObjects(self):
1147
1135
1148 for procUnitConfObj in self.procUnitConfObjDict.values():
1136 for procUnitConfObj in self.procUnitConfObjDict.values():
1149 procUnitConfObj.createObjects(self.plotterQueue)
1137 procUnitConfObj.createObjects(self.plotterQueue)
1150
1138
1151 def __connect(self, objIN, thisObj):
1139 def __connect(self, objIN, thisObj):
1152
1140
1153 thisObj.setInput(objIN.getOutputObj())
1141 thisObj.setInput(objIN.getOutputObj())
1154
1142
1155 def connectObjects(self):
1143 def connectObjects(self):
1156
1144
1157 for thisPUConfObj in self.procUnitConfObjDict.values():
1145 for thisPUConfObj in self.procUnitConfObjDict.values():
1158
1146
1159 inputId = thisPUConfObj.getInputId()
1147 inputId = thisPUConfObj.getInputId()
1160
1148
1161 if int(inputId) == 0:
1149 if int(inputId) == 0:
1162 continue
1150 continue
1163
1151
1164 #Get input object
1152 #Get input object
1165 puConfINObj = self.procUnitConfObjDict[inputId]
1153 puConfINObj = self.procUnitConfObjDict[inputId]
1166 puObjIN = puConfINObj.getProcUnitObj()
1154 puObjIN = puConfINObj.getProcUnitObj()
1167
1155
1168 #Get current object
1156 #Get current object
1169 thisPUObj = thisPUConfObj.getProcUnitObj()
1157 thisPUObj = thisPUConfObj.getProcUnitObj()
1170
1158
1171 self.__connect(puObjIN, thisPUObj)
1159 self.__connect(puObjIN, thisPUObj)
1172
1160
1173 def __handleError(self, procUnitConfObj, send_email=True):
1161 def __handleError(self, procUnitConfObj, send_email=False):
1174
1162
1175 import socket
1163 import socket
1176
1164
1177 err = traceback.format_exception(sys.exc_info()[0],
1165 err = traceback.format_exception(sys.exc_info()[0],
1178 sys.exc_info()[1],
1166 sys.exc_info()[1],
1179 sys.exc_info()[2])
1167 sys.exc_info()[2])
1180
1168
1181 print "***** Error occurred in %s *****" %(procUnitConfObj.name)
1169 print '***** Error occurred in %s *****' %(procUnitConfObj.name)
1182 print "***** %s" %err[-1]
1170 print '***** %s' %err[-1]
1183
1171
1184 message = "".join(err)
1172 message = ''.join(err)
1185
1173
1186 sys.stderr.write(message)
1174 sys.stderr.write(message)
1187
1175
1188 if not send_email:
1176 if not send_email:
1189 return
1177 return
1190
1178
1191 subject = "SChain v%s: Error running %s\n" %(schainpy.__version__, procUnitConfObj.name)
1179 subject = 'SChain v%s: Error running %s\n' %(schainpy.__version__, procUnitConfObj.name)
1192
1180
1193 subtitle = "%s: %s\n" %(procUnitConfObj.getElementName() ,procUnitConfObj.name)
1181 subtitle = '%s: %s\n' %(procUnitConfObj.getElementName() ,procUnitConfObj.name)
1194 subtitle += "Hostname: %s\n" %socket.gethostbyname(socket.gethostname())
1182 subtitle += 'Hostname: %s\n' %socket.gethostbyname(socket.gethostname())
1195 subtitle += "Working directory: %s\n" %os.path.abspath("./")
1183 subtitle += 'Working directory: %s\n' %os.path.abspath('./')
1196 subtitle += "Configuration file: %s\n" %self.filename
1184 subtitle += 'Configuration file: %s\n' %self.filename
1197 subtitle += "Time: %s\n" %str(datetime.datetime.now())
1185 subtitle += 'Time: %s\n' %str(datetime.datetime.now())
1198
1186
1199 readUnitConfObj = self.getReadUnitObj()
1187 readUnitConfObj = self.getReadUnitObj()
1200 if readUnitConfObj:
1188 if readUnitConfObj:
1201 subtitle += "\nInput parameters:\n"
1189 subtitle += '\nInput parameters:\n'
1202 subtitle += "[Data path = %s]\n" %readUnitConfObj.path
1190 subtitle += '[Data path = %s]\n' %readUnitConfObj.path
1203 subtitle += "[Data type = %s]\n" %readUnitConfObj.datatype
1191 subtitle += '[Data type = %s]\n' %readUnitConfObj.datatype
1204 subtitle += "[Start date = %s]\n" %readUnitConfObj.startDate
1192 subtitle += '[Start date = %s]\n' %readUnitConfObj.startDate
1205 subtitle += "[End date = %s]\n" %readUnitConfObj.endDate
1193 subtitle += '[End date = %s]\n' %readUnitConfObj.endDate
1206 subtitle += "[Start time = %s]\n" %readUnitConfObj.startTime
1194 subtitle += '[Start time = %s]\n' %readUnitConfObj.startTime
1207 subtitle += "[End time = %s]\n" %readUnitConfObj.endTime
1195 subtitle += '[End time = %s]\n' %readUnitConfObj.endTime
1208
1196
1209 adminObj = schainpy.admin.SchainNotify()
1197 adminObj = schainpy.admin.SchainNotify()
1210 adminObj.sendAlert(message=message,
1198 adminObj.sendAlert(message=message,
1211 subject=subject,
1199 subject=subject,
1212 subtitle=subtitle,
1200 subtitle=subtitle,
1213 filename=self.filename)
1201 filename=self.filename)
1214
1202
1215 def isPaused(self):
1203 def isPaused(self):
1216 return 0
1204 return 0
1217
1205
1218 def isStopped(self):
1206 def isStopped(self):
1219 return 0
1207 return 0
1220
1208
1221 def runController(self):
1209 def runController(self):
1222 """
1210 '''
1223 returns 0 when this process has been stopped, 1 otherwise
1211 returns 0 when this process has been stopped, 1 otherwise
1224 """
1212 '''
1225
1213
1226 if self.isPaused():
1214 if self.isPaused():
1227 print "Process suspended"
1215 print 'Process suspended'
1228
1216
1229 while True:
1217 while True:
1230 sleep(0.1)
1218 time.sleep(0.1)
1231
1219
1232 if not self.isPaused():
1220 if not self.isPaused():
1233 break
1221 break
1234
1222
1235 if self.isStopped():
1223 if self.isStopped():
1236 break
1224 break
1237
1225
1238 print "Process reinitialized"
1226 print 'Process reinitialized'
1239
1227
1240 if self.isStopped():
1228 if self.isStopped():
1241 print "Process stopped"
1229 print 'Process stopped'
1242 return 0
1230 return 0
1243
1231
1244 return 1
1232 return 1
1245
1233
1246 def setFilename(self, filename):
1234 def setFilename(self, filename):
1247
1235
1248 self.filename = filename
1236 self.filename = filename
1249
1237
1250 def setPlotterQueue(self, plotter_queue):
1238 def setPlotterQueue(self, plotter_queue):
1251
1239
1252 raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class"
1240 raise NotImplementedError, 'Use schainpy.controller_api.ControllerThread instead Project class'
1253
1241
1254 def getPlotterQueue(self):
1242 def getPlotterQueue(self):
1255
1243
1256 raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class"
1244 raise NotImplementedError, 'Use schainpy.controller_api.ControllerThread instead Project class'
1257
1245
1258 def useExternalPlotter(self):
1246 def useExternalPlotter(self):
1259
1247
1260 raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class"
1248 raise NotImplementedError, 'Use schainpy.controller_api.ControllerThread instead Project class'
1261
1249
1262 def run(self):
1250 def run(self):
1263
1251
1264 print
1252 log.success('Starting {}'.format(self.name))
1265 print "*"*60
1253
1266 print " Starting SIGNAL CHAIN PROCESSING v%s " %schainpy.__version__
1254 self.createObjects()
1267 print "*"*60
1255 self.connectObjects()
1268 print
1269
1256
1270 keyList = self.procUnitConfObjDict.keys()
1257 keyList = self.procUnitConfObjDict.keys()
1271 keyList.sort()
1258 keyList.sort()
1272
1259
1273 while(True):
1260 while(True):
1274
1261
1275 is_ok = False
1262 is_ok = False
1276
1263
1277 for procKey in keyList:
1264 for procKey in keyList:
1278 # print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id)
1279
1265
1280 procUnitConfObj = self.procUnitConfObjDict[procKey]
1266 procUnitConfObj = self.procUnitConfObjDict[procKey]
1281
1267
1282 try:
1268 try:
1283 sts = procUnitConfObj.run()
1269 sts = procUnitConfObj.run()
1284 is_ok = is_ok or sts
1270 is_ok = is_ok or sts
1285 except KeyboardInterrupt:
1271 except KeyboardInterrupt:
1286 is_ok = False
1272 is_ok = False
1287 break
1273 break
1288 except ValueError, e:
1274 except ValueError, e:
1289 sleep(0.5)
1275 time.sleep(0.5)
1290 self.__handleError(procUnitConfObj, send_email=True)
1276 self.__handleError(procUnitConfObj, send_email=True)
1291 is_ok = False
1277 is_ok = False
1292 break
1278 break
1293 except:
1279 except:
1294 sleep(0.5)
1280 time.sleep(0.5)
1295 self.__handleError(procUnitConfObj)
1281 self.__handleError(procUnitConfObj)
1296 is_ok = False
1282 is_ok = False
1297 break
1283 break
1298
1284
1299 #If every process unit finished so end process
1285 #If every process unit finished so end process
1300 if not(is_ok):
1286 if not(is_ok):
1301 # print "Every process unit have finished"
1302 break
1287 break
1303
1288
1304 if not self.runController():
1289 if not self.runController():
1305 break
1290 break
1306
1291
1307 #Closing every process
1292 #Closing every process
1308 for procKey in keyList:
1293 for procKey in keyList:
1309 procUnitConfObj = self.procUnitConfObjDict[procKey]
1294 procUnitConfObj = self.procUnitConfObjDict[procKey]
1310 procUnitConfObj.close()
1295 procUnitConfObj.close()
1311
1296
1312 print "Process finished"
1297 log.success('{} finished'.format(self.name))
1313
1314 def start(self, filename=None):
1315
1316 self.writeXml(filename)
1317 self.createObjects()
1318 self.connectObjects()
1319 self.run()
@@ -1,179 +1,179
1 import threading
1 import threading
2 from Queue import Queue
2 from Queue import Queue
3
3
4 from schainpy.controller import Project
4 from schainpy.controller import Project
5 from schainpy.model.graphics.jroplotter import PlotManager
5 from schainpy.model.graphics.jroplotter import PlotManager
6
6
7 class ControllerThread(threading.Thread, Project):
7 class ControllerThread(threading.Thread, Project):
8
8
9 def __init__(self, plotter_queue=None):
9 def __init__(self, plotter_queue=None):
10
10
11 threading.Thread.__init__(self)
11 threading.Thread.__init__(self)
12 Project.__init__(self, plotter_queue)
12 Project.__init__(self, plotter_queue)
13
13
14 self.setDaemon(True)
14 self.setDaemon(True)
15
15
16 self.lock = threading.Lock()
16 self.lock = threading.Lock()
17 self.control = {'stop':False, 'pause':False}
17 self.control = { 'stop':False, 'pause':False }
18
18
19 def __del__(self):
19 def __del__(self):
20
20
21 self.control['stop'] = True
21 self.control['stop'] = True
22
22
23 def stop(self):
23 def stop(self):
24
24
25 self.lock.acquire()
25 self.lock.acquire()
26
26
27 self.control['stop'] = True
27 self.control['stop'] = True
28
28
29 self.lock.release()
29 self.lock.release()
30
30
31 def pause(self):
31 def pause(self):
32
32
33 self.lock.acquire()
33 self.lock.acquire()
34
34
35 self.control['pause'] = not(self.control['pause'])
35 self.control['pause'] = not(self.control['pause'])
36 paused = self.control['pause']
36 paused = self.control['pause']
37
37
38 self.lock.release()
38 self.lock.release()
39
39
40 return paused
40 return paused
41
41
42 def isPaused(self):
42 def isPaused(self):
43
43
44 self.lock.acquire()
44 self.lock.acquire()
45 paused = self.control['pause']
45 paused = self.control['pause']
46 self.lock.release()
46 self.lock.release()
47
47
48 return paused
48 return paused
49
49
50 def isStopped(self):
50 def isStopped(self):
51
51
52 self.lock.acquire()
52 self.lock.acquire()
53 stopped = self.control['stop']
53 stopped = self.control['stop']
54 self.lock.release()
54 self.lock.release()
55
55
56 return stopped
56 return stopped
57
57
58 def run(self):
58 def run(self):
59 self.control['stop'] = False
59 self.control['stop'] = False
60 self.control['pause'] = False
60 self.control['pause'] = False
61
61
62 self.writeXml()
62 self.writeXml()
63
63
64 self.createObjects()
64 self.createObjects()
65 self.connectObjects()
65 self.connectObjects()
66 Project.run(self)
66 Project.run(self)
67
67
68 def isRunning(self):
68 def isRunning(self):
69
69
70 return self.is_alive()
70 return self.is_alive()
71
71
72 def isFinished(self):
72 def isFinished(self):
73
73
74 return not self.is_alive()
74 return not self.is_alive()
75
75
76 def setPlotters(self):
76 def setPlotters(self):
77
77
78 plotterList = PlotManager.plotterList
78 plotterList = PlotManager.plotterList
79
79
80 for thisPUConfObj in self.procUnitConfObjDict.values():
80 for thisPUConfObj in self.procUnitConfObjDict.values():
81
81
82 inputId = thisPUConfObj.getInputId()
82 inputId = thisPUConfObj.getInputId()
83
83
84 if int(inputId) == 0:
84 if int(inputId) == 0:
85 continue
85 continue
86
86
87 for thisOpObj in thisPUConfObj.getOperationObjList():
87 for thisOpObj in thisPUConfObj.getOperationObjList():
88
88
89 if thisOpObj.type == "self":
89 if thisOpObj.type == "self":
90 continue
90 continue
91
91
92 if thisOpObj.name in plotterList:
92 if thisOpObj.name in plotterList:
93 thisOpObj.type = "other"
93 thisOpObj.type = "other"
94
94
95 def setPlotterQueue(self, plotter_queue):
95 def setPlotterQueue(self, plotter_queue):
96
96
97 self.plotterQueue = plotter_queue
97 self.plotterQueue = plotter_queue
98
98
99 def getPlotterQueue(self):
99 def getPlotterQueue(self):
100
100
101 return self.plotterQueue
101 return self.plotterQueue
102
102
103 def useExternalPlotter(self):
103 def useExternalPlotter(self):
104
104
105 self.plotterQueue = Queue(10)
105 self.plotterQueue = Queue(10)
106 self.setPlotters()
106 self.setPlotters()
107
107
108 plotManagerObj = PlotManager(self.plotterQueue)
108 plotManagerObj = PlotManager(self.plotterQueue)
109 plotManagerObj.setController(self)
109 plotManagerObj.setController(self)
110
110
111 return plotManagerObj
111 return plotManagerObj
112
112
113 # from PyQt4 import QtCore
113 # from PyQt4 import QtCore
114 # from PyQt4.QtCore import SIGNAL
114 # from PyQt4.QtCore import SIGNAL
115 #
115 #
116 # class ControllerQThread(QtCore.QThread, Project):
116 # class ControllerQThread(QtCore.QThread, Project):
117 #
117 #
118 # def __init__(self, filename):
118 # def __init__(self, filename):
119 #
119 #
120 # QtCore.QThread.__init__(self)
120 # QtCore.QThread.__init__(self)
121 # Project.__init__(self)
121 # Project.__init__(self)
122 #
122 #
123 # self.filename = filename
123 # self.filename = filename
124 #
124 #
125 # self.lock = threading.Lock()
125 # self.lock = threading.Lock()
126 # self.control = {'stop':False, 'pause':False}
126 # self.control = {'stop':False, 'pause':False}
127 #
127 #
128 # def __del__(self):
128 # def __del__(self):
129 #
129 #
130 # self.control['stop'] = True
130 # self.control['stop'] = True
131 # self.wait()
131 # self.wait()
132 #
132 #
133 # def stop(self):
133 # def stop(self):
134 #
134 #
135 # self.lock.acquire()
135 # self.lock.acquire()
136 #
136 #
137 # self.control['stop'] = True
137 # self.control['stop'] = True
138 #
138 #
139 # self.lock.release()
139 # self.lock.release()
140 #
140 #
141 # def pause(self):
141 # def pause(self):
142 #
142 #
143 # self.lock.acquire()
143 # self.lock.acquire()
144 #
144 #
145 # self.control['pause'] = not(self.control['pause'])
145 # self.control['pause'] = not(self.control['pause'])
146 # paused = self.control['pause']
146 # paused = self.control['pause']
147 #
147 #
148 # self.lock.release()
148 # self.lock.release()
149 #
149 #
150 # return paused
150 # return paused
151 #
151 #
152 # def isPaused(self):
152 # def isPaused(self):
153 #
153 #
154 # self.lock.acquire()
154 # self.lock.acquire()
155 # paused = self.control['pause']
155 # paused = self.control['pause']
156 # self.lock.release()
156 # self.lock.release()
157 #
157 #
158 # return paused
158 # return paused
159 #
159 #
160 # def isStopped(self):
160 # def isStopped(self):
161 #
161 #
162 # self.lock.acquire()
162 # self.lock.acquire()
163 # stopped = self.control['stop']
163 # stopped = self.control['stop']
164 # self.lock.release()
164 # self.lock.release()
165 #
165 #
166 # return stopped
166 # return stopped
167 #
167 #
168 # def run(self):
168 # def run(self):
169 #
169 #
170 # self.control['stop'] = False
170 # self.control['stop'] = False
171 # self.control['pause'] = False
171 # self.control['pause'] = False
172 #
172 #
173 # self.readXml(self.filename)
173 # self.readXml(self.filename)
174 # self.createObjects()
174 # self.createObjects()
175 # self.connectObjects()
175 # self.connectObjects()
176 # self.emit( SIGNAL( "jobStarted( PyQt_PyObject )" ), 1)
176 # self.emit( SIGNAL( "jobStarted( PyQt_PyObject )" ), 1)
177 # Project.run(self)
177 # Project.run(self)
178 # self.emit( SIGNAL( "jobFinished( PyQt_PyObject )" ), 1)
178 # self.emit( SIGNAL( "jobFinished( PyQt_PyObject )" ), 1)
179 #
179 #
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,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,1229 +1,1229
1 '''
1 '''
2
2
3 $Author: murco $
3 $Author: murco $
4 $Id: JROData.py 173 2012-11-20 15:06:21Z murco $
4 $Id: JROData.py 173 2012-11-20 15:06:21Z murco $
5 '''
5 '''
6
6
7 import copy
7 import copy
8 import numpy
8 import numpy
9 import datetime
9 import datetime
10
10
11 from jroheaderIO import SystemHeader, RadarControllerHeader
11 from jroheaderIO import SystemHeader, RadarControllerHeader
12 from schainpy import cSchain
12 from schainpy import cSchain
13
13
14
14
15 def getNumpyDtype(dataTypeCode):
15 def getNumpyDtype(dataTypeCode):
16
16
17 if dataTypeCode == 0:
17 if dataTypeCode == 0:
18 numpyDtype = numpy.dtype([('real','<i1'),('imag','<i1')])
18 numpyDtype = numpy.dtype([('real','<i1'),('imag','<i1')])
19 elif dataTypeCode == 1:
19 elif dataTypeCode == 1:
20 numpyDtype = numpy.dtype([('real','<i2'),('imag','<i2')])
20 numpyDtype = numpy.dtype([('real','<i2'),('imag','<i2')])
21 elif dataTypeCode == 2:
21 elif dataTypeCode == 2:
22 numpyDtype = numpy.dtype([('real','<i4'),('imag','<i4')])
22 numpyDtype = numpy.dtype([('real','<i4'),('imag','<i4')])
23 elif dataTypeCode == 3:
23 elif dataTypeCode == 3:
24 numpyDtype = numpy.dtype([('real','<i8'),('imag','<i8')])
24 numpyDtype = numpy.dtype([('real','<i8'),('imag','<i8')])
25 elif dataTypeCode == 4:
25 elif dataTypeCode == 4:
26 numpyDtype = numpy.dtype([('real','<f4'),('imag','<f4')])
26 numpyDtype = numpy.dtype([('real','<f4'),('imag','<f4')])
27 elif dataTypeCode == 5:
27 elif dataTypeCode == 5:
28 numpyDtype = numpy.dtype([('real','<f8'),('imag','<f8')])
28 numpyDtype = numpy.dtype([('real','<f8'),('imag','<f8')])
29 else:
29 else:
30 raise ValueError, 'dataTypeCode was not defined'
30 raise ValueError, 'dataTypeCode was not defined'
31
31
32 return numpyDtype
32 return numpyDtype
33
33
34 def getDataTypeCode(numpyDtype):
34 def getDataTypeCode(numpyDtype):
35
35
36 if numpyDtype == numpy.dtype([('real','<i1'),('imag','<i1')]):
36 if numpyDtype == numpy.dtype([('real','<i1'),('imag','<i1')]):
37 datatype = 0
37 datatype = 0
38 elif numpyDtype == numpy.dtype([('real','<i2'),('imag','<i2')]):
38 elif numpyDtype == numpy.dtype([('real','<i2'),('imag','<i2')]):
39 datatype = 1
39 datatype = 1
40 elif numpyDtype == numpy.dtype([('real','<i4'),('imag','<i4')]):
40 elif numpyDtype == numpy.dtype([('real','<i4'),('imag','<i4')]):
41 datatype = 2
41 datatype = 2
42 elif numpyDtype == numpy.dtype([('real','<i8'),('imag','<i8')]):
42 elif numpyDtype == numpy.dtype([('real','<i8'),('imag','<i8')]):
43 datatype = 3
43 datatype = 3
44 elif numpyDtype == numpy.dtype([('real','<f4'),('imag','<f4')]):
44 elif numpyDtype == numpy.dtype([('real','<f4'),('imag','<f4')]):
45 datatype = 4
45 datatype = 4
46 elif numpyDtype == numpy.dtype([('real','<f8'),('imag','<f8')]):
46 elif numpyDtype == numpy.dtype([('real','<f8'),('imag','<f8')]):
47 datatype = 5
47 datatype = 5
48 else:
48 else:
49 datatype = None
49 datatype = None
50
50
51 return datatype
51 return datatype
52
52
53 def hildebrand_sekhon(data, navg):
53 def hildebrand_sekhon(data, navg):
54 """
54 """
55 This method is for the objective determination of the noise level in Doppler spectra. This
55 This method is for the objective determination of the noise level in Doppler spectra. This
56 implementation technique is based on the fact that the standard deviation of the spectral
56 implementation technique is based on the fact that the standard deviation of the spectral
57 densities is equal to the mean spectral density for white Gaussian noise
57 densities is equal to the mean spectral density for white Gaussian noise
58
58
59 Inputs:
59 Inputs:
60 Data : heights
60 Data : heights
61 navg : numbers of averages
61 navg : numbers of averages
62
62
63 Return:
63 Return:
64 -1 : any error
64 -1 : any error
65 anoise : noise's level
65 anoise : noise's level
66 """
66 """
67
67
68 sortdata = numpy.sort(data, axis=None)
68 sortdata = numpy.sort(data, axis=None)
69 # lenOfData = len(sortdata)
69 # lenOfData = len(sortdata)
70 # nums_min = lenOfData*0.2
70 # nums_min = lenOfData*0.2
71 #
71 #
72 # if nums_min <= 5:
72 # if nums_min <= 5:
73 # nums_min = 5
73 # nums_min = 5
74 #
74 #
75 # sump = 0.
75 # sump = 0.
76 #
76 #
77 # sumq = 0.
77 # sumq = 0.
78 #
78 #
79 # j = 0
79 # j = 0
80 #
80 #
81 # cont = 1
81 # cont = 1
82 #
82 #
83 # while((cont==1)and(j<lenOfData)):
83 # while((cont==1)and(j<lenOfData)):
84 #
84 #
85 # sump += sortdata[j]
85 # sump += sortdata[j]
86 #
86 #
87 # sumq += sortdata[j]**2
87 # sumq += sortdata[j]**2
88 #
88 #
89 # if j > nums_min:
89 # if j > nums_min:
90 # rtest = float(j)/(j-1) + 1.0/navg
90 # rtest = float(j)/(j-1) + 1.0/navg
91 # if ((sumq*j) > (rtest*sump**2)):
91 # if ((sumq*j) > (rtest*sump**2)):
92 # j = j - 1
92 # j = j - 1
93 # sump = sump - sortdata[j]
93 # sump = sump - sortdata[j]
94 # sumq = sumq - sortdata[j]**2
94 # sumq = sumq - sortdata[j]**2
95 # cont = 0
95 # cont = 0
96 #
96 #
97 # j += 1
97 # j += 1
98 #
98 #
99 # lnoise = sump /j
99 # lnoise = sump /j
100 #
100 #
101 # return lnoise
101 # return lnoise
102
102
103 return cSchain.hildebrand_sekhon(sortdata, navg)
103 return cSchain.hildebrand_sekhon(sortdata, navg)
104
104
105
105
106 class Beam:
106 class Beam:
107
107
108 def __init__(self):
108 def __init__(self):
109 self.codeList = []
109 self.codeList = []
110 self.azimuthList = []
110 self.azimuthList = []
111 self.zenithList = []
111 self.zenithList = []
112
112
113 class GenericData(object):
113 class GenericData(object):
114
114
115 flagNoData = True
115 flagNoData = True
116
116
117 def copy(self, inputObj=None):
117 def copy(self, inputObj=None):
118
118
119 if inputObj == None:
119 if inputObj == None:
120 return copy.deepcopy(self)
120 return copy.deepcopy(self)
121
121
122 for key in inputObj.__dict__.keys():
122 for key in inputObj.__dict__.keys():
123
123
124 attribute = inputObj.__dict__[key]
124 attribute = inputObj.__dict__[key]
125
125
126 #If this attribute is a tuple or list
126 #If this attribute is a tuple or list
127 if type(inputObj.__dict__[key]) in (tuple, list):
127 if type(inputObj.__dict__[key]) in (tuple, list):
128 self.__dict__[key] = attribute[:]
128 self.__dict__[key] = attribute[:]
129 continue
129 continue
130
130
131 #If this attribute is another object or instance
131 #If this attribute is another object or instance
132 if hasattr(attribute, '__dict__'):
132 if hasattr(attribute, '__dict__'):
133 self.__dict__[key] = attribute.copy()
133 self.__dict__[key] = attribute.copy()
134 continue
134 continue
135
135
136 self.__dict__[key] = inputObj.__dict__[key]
136 self.__dict__[key] = inputObj.__dict__[key]
137
137
138 def deepcopy(self):
138 def deepcopy(self):
139
139
140 return copy.deepcopy(self)
140 return copy.deepcopy(self)
141
141
142 def isEmpty(self):
142 def isEmpty(self):
143
143
144 return self.flagNoData
144 return self.flagNoData
145
145
146 class JROData(GenericData):
146 class JROData(GenericData):
147
147
148 # m_BasicHeader = BasicHeader()
148 # m_BasicHeader = BasicHeader()
149 # m_ProcessingHeader = ProcessingHeader()
149 # m_ProcessingHeader = ProcessingHeader()
150
150
151 systemHeaderObj = SystemHeader()
151 systemHeaderObj = SystemHeader()
152
152
153 radarControllerHeaderObj = RadarControllerHeader()
153 radarControllerHeaderObj = RadarControllerHeader()
154
154
155 # data = None
155 # data = None
156
156
157 type = None
157 type = None
158
158
159 datatype = None #dtype but in string
159 datatype = None #dtype but in string
160
160
161 # dtype = None
161 # dtype = None
162
162
163 # nChannels = None
163 # nChannels = None
164
164
165 # nHeights = None
165 # nHeights = None
166
166
167 nProfiles = None
167 nProfiles = None
168
168
169 heightList = None
169 heightList = None
170
170
171 channelList = None
171 channelList = None
172
172
173 flagDiscontinuousBlock = False
173 flagDiscontinuousBlock = False
174
174
175 useLocalTime = False
175 useLocalTime = False
176
176
177 utctime = None
177 utctime = None
178
178
179 timeZone = None
179 timeZone = None
180
180
181 dstFlag = None
181 dstFlag = None
182
182
183 errorCount = None
183 errorCount = None
184
184
185 blocksize = None
185 blocksize = None
186
186
187 # nCode = None
187 # nCode = None
188 #
188 #
189 # nBaud = None
189 # nBaud = None
190 #
190 #
191 # code = None
191 # code = None
192
192
193 flagDecodeData = False #asumo q la data no esta decodificada
193 flagDecodeData = False #asumo q la data no esta decodificada
194
194
195 flagDeflipData = False #asumo q la data no esta sin flip
195 flagDeflipData = False #asumo q la data no esta sin flip
196
196
197 flagShiftFFT = False
197 flagShiftFFT = False
198
198
199 # ippSeconds = None
199 # ippSeconds = None
200
200
201 # timeInterval = None
201 # timeInterval = None
202
202
203 nCohInt = None
203 nCohInt = None
204
204
205 # noise = None
205 # noise = None
206
206
207 windowOfFilter = 1
207 windowOfFilter = 1
208
208
209 #Speed of ligth
209 #Speed of ligth
210 C = 3e8
210 C = 3e8
211
211
212 frequency = 49.92e6
212 frequency = 49.92e6
213
213
214 realtime = False
214 realtime = False
215
215
216 beacon_heiIndexList = None
216 beacon_heiIndexList = None
217
217
218 last_block = None
218 last_block = None
219
219
220 blocknow = None
220 blocknow = None
221
221
222 azimuth = None
222 azimuth = None
223
223
224 zenith = None
224 zenith = None
225
225
226 beam = Beam()
226 beam = Beam()
227
227
228 profileIndex = None
228 profileIndex = None
229
229
230 def getNoise(self):
230 def getNoise(self):
231
231
232 raise NotImplementedError
232 raise NotImplementedError
233
233
234 def getNChannels(self):
234 def getNChannels(self):
235
235
236 return len(self.channelList)
236 return len(self.channelList)
237
237
238 def getChannelIndexList(self):
238 def getChannelIndexList(self):
239
239
240 return range(self.nChannels)
240 return range(self.nChannels)
241
241
242 def getNHeights(self):
242 def getNHeights(self):
243
243
244 return len(self.heightList)
244 return len(self.heightList)
245
245
246 def getHeiRange(self, extrapoints=0):
246 def getHeiRange(self, extrapoints=0):
247
247
248 heis = self.heightList
248 heis = self.heightList
249 # deltah = self.heightList[1] - self.heightList[0]
249 # deltah = self.heightList[1] - self.heightList[0]
250 #
250 #
251 # heis.append(self.heightList[-1])
251 # heis.append(self.heightList[-1])
252
252
253 return heis
253 return heis
254
254
255 def getDeltaH(self):
255 def getDeltaH(self):
256
256
257 delta = self.heightList[1] - self.heightList[0]
257 delta = self.heightList[1] - self.heightList[0]
258
258
259 return delta
259 return delta
260
260
261 def getltctime(self):
261 def getltctime(self):
262
262
263 if self.useLocalTime:
263 if self.useLocalTime:
264 return self.utctime - self.timeZone*60
264 return self.utctime - self.timeZone*60
265
265
266 return self.utctime
266 return self.utctime
267
267
268 def getDatatime(self):
268 def getDatatime(self):
269
269
270 datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime)
270 datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime)
271 return datatimeValue
271 return datatimeValue
272
272
273 def getTimeRange(self):
273 def getTimeRange(self):
274
274
275 datatime = []
275 datatime = []
276
276
277 datatime.append(self.ltctime)
277 datatime.append(self.ltctime)
278 datatime.append(self.ltctime + self.timeInterval+1)
278 datatime.append(self.ltctime + self.timeInterval+1)
279
279
280 datatime = numpy.array(datatime)
280 datatime = numpy.array(datatime)
281
281
282 return datatime
282 return datatime
283
283
284 def getFmaxTimeResponse(self):
284 def getFmaxTimeResponse(self):
285
285
286 period = (10**-6)*self.getDeltaH()/(0.15)
286 period = (10**-6)*self.getDeltaH()/(0.15)
287
287
288 PRF = 1./(period * self.nCohInt)
288 PRF = 1./(period * self.nCohInt)
289
289
290 fmax = PRF
290 fmax = PRF
291
291
292 return fmax
292 return fmax
293
293
294 def getFmax(self):
294 def getFmax(self):
295
295
296 PRF = 1./(self.ippSeconds * self.nCohInt)
296 PRF = 1./(self.ippSeconds * self.nCohInt)
297
297
298 fmax = PRF
298 fmax = PRF
299
299
300 return fmax
300 return fmax
301
301
302 def getVmax(self):
302 def getVmax(self):
303
303
304 _lambda = self.C/self.frequency
304 _lambda = self.C/self.frequency
305
305
306 vmax = self.getFmax() * _lambda/2
306 vmax = self.getFmax() * _lambda/2
307
307
308 return vmax
308 return vmax
309
309
310 def get_ippSeconds(self):
310 def get_ippSeconds(self):
311 '''
311 '''
312 '''
312 '''
313 return self.radarControllerHeaderObj.ippSeconds
313 return self.radarControllerHeaderObj.ippSeconds
314
314
315 def set_ippSeconds(self, ippSeconds):
315 def set_ippSeconds(self, ippSeconds):
316 '''
316 '''
317 '''
317 '''
318
318
319 self.radarControllerHeaderObj.ippSeconds = ippSeconds
319 self.radarControllerHeaderObj.ippSeconds = ippSeconds
320
320
321 return
321 return
322
322
323 def get_dtype(self):
323 def get_dtype(self):
324 '''
324 '''
325 '''
325 '''
326 return getNumpyDtype(self.datatype)
326 return getNumpyDtype(self.datatype)
327
327
328 def set_dtype(self, numpyDtype):
328 def set_dtype(self, numpyDtype):
329 '''
329 '''
330 '''
330 '''
331
331
332 self.datatype = getDataTypeCode(numpyDtype)
332 self.datatype = getDataTypeCode(numpyDtype)
333
333
334 def get_code(self):
334 def get_code(self):
335 '''
335 '''
336 '''
336 '''
337 return self.radarControllerHeaderObj.code
337 return self.radarControllerHeaderObj.code
338
338
339 def set_code(self, code):
339 def set_code(self, code):
340 '''
340 '''
341 '''
341 '''
342 self.radarControllerHeaderObj.code = code
342 self.radarControllerHeaderObj.code = code
343
343
344 return
344 return
345
345
346 def get_ncode(self):
346 def get_ncode(self):
347 '''
347 '''
348 '''
348 '''
349 return self.radarControllerHeaderObj.nCode
349 return self.radarControllerHeaderObj.nCode
350
350
351 def set_ncode(self, nCode):
351 def set_ncode(self, nCode):
352 '''
352 '''
353 '''
353 '''
354 self.radarControllerHeaderObj.nCode = nCode
354 self.radarControllerHeaderObj.nCode = nCode
355
355
356 return
356 return
357
357
358 def get_nbaud(self):
358 def get_nbaud(self):
359 '''
359 '''
360 '''
360 '''
361 return self.radarControllerHeaderObj.nBaud
361 return self.radarControllerHeaderObj.nBaud
362
362
363 def set_nbaud(self, nBaud):
363 def set_nbaud(self, nBaud):
364 '''
364 '''
365 '''
365 '''
366 self.radarControllerHeaderObj.nBaud = nBaud
366 self.radarControllerHeaderObj.nBaud = nBaud
367
367
368 return
368 return
369
369
370 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
370 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
371 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
371 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
372 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
372 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
373 #noise = property(getNoise, "I'm the 'nHeights' property.")
373 #noise = property(getNoise, "I'm the 'nHeights' property.")
374 datatime = property(getDatatime, "I'm the 'datatime' property")
374 datatime = property(getDatatime, "I'm the 'datatime' property")
375 ltctime = property(getltctime, "I'm the 'ltctime' property")
375 ltctime = property(getltctime, "I'm the 'ltctime' property")
376 ippSeconds = property(get_ippSeconds, set_ippSeconds)
376 ippSeconds = property(get_ippSeconds, set_ippSeconds)
377 dtype = property(get_dtype, set_dtype)
377 dtype = property(get_dtype, set_dtype)
378 # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
378 # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
379 code = property(get_code, set_code)
379 code = property(get_code, set_code)
380 nCode = property(get_ncode, set_ncode)
380 nCode = property(get_ncode, set_ncode)
381 nBaud = property(get_nbaud, set_nbaud)
381 nBaud = property(get_nbaud, set_nbaud)
382
382
383 class Voltage(JROData):
383 class Voltage(JROData):
384
384
385 #data es un numpy array de 2 dmensiones (canales, alturas)
385 #data es un numpy array de 2 dmensiones (canales, alturas)
386 data = None
386 data = None
387
387
388 def __init__(self):
388 def __init__(self):
389 '''
389 '''
390 Constructor
390 Constructor
391 '''
391 '''
392
392
393 self.useLocalTime = True
393 self.useLocalTime = True
394
394
395 self.radarControllerHeaderObj = RadarControllerHeader()
395 self.radarControllerHeaderObj = RadarControllerHeader()
396
396
397 self.systemHeaderObj = SystemHeader()
397 self.systemHeaderObj = SystemHeader()
398
398
399 self.type = "Voltage"
399 self.type = "Voltage"
400
400
401 self.data = None
401 self.data = None
402
402
403 # self.dtype = None
403 # self.dtype = None
404
404
405 # self.nChannels = 0
405 # self.nChannels = 0
406
406
407 # self.nHeights = 0
407 # self.nHeights = 0
408
408
409 self.nProfiles = None
409 self.nProfiles = None
410
410
411 self.heightList = None
411 self.heightList = None
412
412
413 self.channelList = None
413 self.channelList = None
414
414
415 # self.channelIndexList = None
415 # self.channelIndexList = None
416
416
417 self.flagNoData = True
417 self.flagNoData = True
418
418
419 self.flagDiscontinuousBlock = False
419 self.flagDiscontinuousBlock = False
420
420
421 self.utctime = None
421 self.utctime = None
422
422
423 self.timeZone = None
423 self.timeZone = None
424
424
425 self.dstFlag = None
425 self.dstFlag = None
426
426
427 self.errorCount = None
427 self.errorCount = None
428
428
429 self.nCohInt = None
429 self.nCohInt = None
430
430
431 self.blocksize = None
431 self.blocksize = None
432
432
433 self.flagDecodeData = False #asumo q la data no esta decodificada
433 self.flagDecodeData = False #asumo q la data no esta decodificada
434
434
435 self.flagDeflipData = False #asumo q la data no esta sin flip
435 self.flagDeflipData = False #asumo q la data no esta sin flip
436
436
437 self.flagShiftFFT = False
437 self.flagShiftFFT = False
438
438
439 self.flagDataAsBlock = False #Asumo que la data es leida perfil a perfil
439 self.flagDataAsBlock = False #Asumo que la data es leida perfil a perfil
440
440
441 self.profileIndex = 0
441 self.profileIndex = 0
442
442
443 def getNoisebyHildebrand(self, channel = None):
443 def getNoisebyHildebrand(self, channel = None):
444 """
444 """
445 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
445 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
446
446
447 Return:
447 Return:
448 noiselevel
448 noiselevel
449 """
449 """
450
450
451 if channel != None:
451 if channel != None:
452 data = self.data[channel]
452 data = self.data[channel]
453 nChannels = 1
453 nChannels = 1
454 else:
454 else:
455 data = self.data
455 data = self.data
456 nChannels = self.nChannels
456 nChannels = self.nChannels
457
457
458 noise = numpy.zeros(nChannels)
458 noise = numpy.zeros(nChannels)
459 power = data * numpy.conjugate(data)
459 power = data * numpy.conjugate(data)
460
460
461 for thisChannel in range(nChannels):
461 for thisChannel in range(nChannels):
462 if nChannels == 1:
462 if nChannels == 1:
463 daux = power[:].real
463 daux = power[:].real
464 else:
464 else:
465 daux = power[thisChannel,:].real
465 daux = power[thisChannel,:].real
466 noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt)
466 noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt)
467
467
468 return noise
468 return noise
469
469
470 def getNoise(self, type = 1, channel = None):
470 def getNoise(self, type = 1, channel = None):
471
471
472 if type == 1:
472 if type == 1:
473 noise = self.getNoisebyHildebrand(channel)
473 noise = self.getNoisebyHildebrand(channel)
474
474
475 return noise
475 return noise
476
476
477 def getPower(self, channel = None):
477 def getPower(self, channel = None):
478
478
479 if channel != None:
479 if channel != None:
480 data = self.data[channel]
480 data = self.data[channel]
481 else:
481 else:
482 data = self.data
482 data = self.data
483
483
484 power = data * numpy.conjugate(data)
484 power = data * numpy.conjugate(data)
485 powerdB = 10*numpy.log10(power.real)
485 powerdB = 10*numpy.log10(power.real)
486 powerdB = numpy.squeeze(powerdB)
486 powerdB = numpy.squeeze(powerdB)
487
487
488 return powerdB
488 return powerdB
489
489
490 def getTimeInterval(self):
490 def getTimeInterval(self):
491
491
492 timeInterval = self.ippSeconds * self.nCohInt
492 timeInterval = self.ippSeconds * self.nCohInt
493
493
494 return timeInterval
494 return timeInterval
495
495
496 noise = property(getNoise, "I'm the 'nHeights' property.")
496 noise = property(getNoise, "I'm the 'nHeights' property.")
497 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
497 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
498
498
499 class Spectra(JROData):
499 class Spectra(JROData):
500
500
501 #data spc es un numpy array de 2 dmensiones (canales, perfiles, alturas)
501 #data spc es un numpy array de 2 dmensiones (canales, perfiles, alturas)
502 data_spc = None
502 data_spc = None
503
503
504 #data cspc es un numpy array de 2 dmensiones (canales, pares, alturas)
504 #data cspc es un numpy array de 2 dmensiones (canales, pares, alturas)
505 data_cspc = None
505 data_cspc = None
506
506
507 #data dc es un numpy array de 2 dmensiones (canales, alturas)
507 #data dc es un numpy array de 2 dmensiones (canales, alturas)
508 data_dc = None
508 data_dc = None
509
509
510 #data power
510 #data power
511 data_pwr = None
511 data_pwr = None
512
512
513 nFFTPoints = None
513 nFFTPoints = None
514
514
515 # nPairs = None
515 # nPairs = None
516
516
517 pairsList = None
517 pairsList = None
518
518
519 nIncohInt = None
519 nIncohInt = None
520
520
521 wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia
521 wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia
522
522
523 nCohInt = None #se requiere para determinar el valor de timeInterval
523 nCohInt = None #se requiere para determinar el valor de timeInterval
524
524
525 ippFactor = None
525 ippFactor = None
526
526
527 profileIndex = 0
527 profileIndex = 0
528
528
529 plotting = "spectra"
529 plotting = "spectra"
530
530
531 def __init__(self):
531 def __init__(self):
532 '''
532 '''
533 Constructor
533 Constructor
534 '''
534 '''
535
535
536 self.useLocalTime = True
536 self.useLocalTime = True
537
537
538 self.radarControllerHeaderObj = RadarControllerHeader()
538 self.radarControllerHeaderObj = RadarControllerHeader()
539
539
540 self.systemHeaderObj = SystemHeader()
540 self.systemHeaderObj = SystemHeader()
541
541
542 self.type = "Spectra"
542 self.type = "Spectra"
543
543
544 # self.data = None
544 # self.data = None
545
545
546 # self.dtype = None
546 # self.dtype = None
547
547
548 # self.nChannels = 0
548 # self.nChannels = 0
549
549
550 # self.nHeights = 0
550 # self.nHeights = 0
551
551
552 self.nProfiles = None
552 self.nProfiles = None
553
553
554 self.heightList = None
554 self.heightList = None
555
555
556 self.channelList = None
556 self.channelList = None
557
557
558 # self.channelIndexList = None
558 # self.channelIndexList = None
559
559
560 self.pairsList = None
560 self.pairsList = None
561
561
562 self.flagNoData = True
562 self.flagNoData = True
563
563
564 self.flagDiscontinuousBlock = False
564 self.flagDiscontinuousBlock = False
565
565
566 self.utctime = None
566 self.utctime = None
567
567
568 self.nCohInt = None
568 self.nCohInt = None
569
569
570 self.nIncohInt = None
570 self.nIncohInt = None
571
571
572 self.blocksize = None
572 self.blocksize = None
573
573
574 self.nFFTPoints = None
574 self.nFFTPoints = None
575
575
576 self.wavelength = None
576 self.wavelength = None
577
577
578 self.flagDecodeData = False #asumo q la data no esta decodificada
578 self.flagDecodeData = False #asumo q la data no esta decodificada
579
579
580 self.flagDeflipData = False #asumo q la data no esta sin flip
580 self.flagDeflipData = False #asumo q la data no esta sin flip
581
581
582 self.flagShiftFFT = False
582 self.flagShiftFFT = False
583
583
584 self.ippFactor = 1
584 self.ippFactor = 1
585
585
586 #self.noise = None
586 #self.noise = None
587
587
588 self.beacon_heiIndexList = []
588 self.beacon_heiIndexList = []
589
589
590 self.noise_estimation = None
590 self.noise_estimation = None
591
591
592
592
593 def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
593 def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
594 """
594 """
595 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
595 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
596
596
597 Return:
597 Return:
598 noiselevel
598 noiselevel
599 """
599 """
600
600
601 noise = numpy.zeros(self.nChannels)
601 noise = numpy.zeros(self.nChannels)
602
602
603 for channel in range(self.nChannels):
603 for channel in range(self.nChannels):
604 daux = self.data_spc[channel,xmin_index:xmax_index,ymin_index:ymax_index]
604 daux = self.data_spc[channel,xmin_index:xmax_index,ymin_index:ymax_index]
605 noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
605 noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
606
606
607 return noise
607 return noise
608
608
609 def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
609 def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
610
610
611 if self.noise_estimation is not None:
611 if self.noise_estimation is not None:
612 return self.noise_estimation #this was estimated by getNoise Operation defined in jroproc_spectra.py
612 return self.noise_estimation #this was estimated by getNoise Operation defined in jroproc_spectra.py
613 else:
613 else:
614 noise = self.getNoisebyHildebrand(xmin_index, xmax_index, ymin_index, ymax_index)
614 noise = self.getNoisebyHildebrand(xmin_index, xmax_index, ymin_index, ymax_index)
615 return noise
615 return noise
616
616
617 def getFreqRangeTimeResponse(self, extrapoints=0):
617 def getFreqRangeTimeResponse(self, extrapoints=0):
618
618
619 deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints*self.ippFactor)
619 deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints*self.ippFactor)
620 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
620 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
621
621
622 return freqrange
622 return freqrange
623
623
624 def getAcfRange(self, extrapoints=0):
624 def getAcfRange(self, extrapoints=0):
625
625
626 deltafreq = 10./(self.getFmax() / (self.nFFTPoints*self.ippFactor))
626 deltafreq = 10./(self.getFmax() / (self.nFFTPoints*self.ippFactor))
627 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
627 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
628
628
629 return freqrange
629 return freqrange
630
630
631 def getFreqRange(self, extrapoints=0):
631 def getFreqRange(self, extrapoints=0):
632
632
633 deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor)
633 deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor)
634 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
634 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
635
635
636 return freqrange
636 return freqrange
637
637
638 def getVelRange(self, extrapoints=0):
638 def getVelRange(self, extrapoints=0):
639
639
640 deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor)
640 deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor)
641 velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) #- deltav/2
641 velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) #- deltav/2
642
642
643 return velrange
643 return velrange
644
644
645 def getNPairs(self):
645 def getNPairs(self):
646
646
647 return len(self.pairsList)
647 return len(self.pairsList)
648
648
649 def getPairsIndexList(self):
649 def getPairsIndexList(self):
650
650
651 return range(self.nPairs)
651 return range(self.nPairs)
652
652
653 def getNormFactor(self):
653 def getNormFactor(self):
654
654
655 pwcode = 1
655 pwcode = 1
656
656
657 if self.flagDecodeData:
657 if self.flagDecodeData:
658 pwcode = numpy.sum(self.code[0]**2)
658 pwcode = numpy.sum(self.code[0]**2)
659 #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
659 #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
660 normFactor = self.nProfiles*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
660 normFactor = self.nProfiles*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
661
661
662 return normFactor
662 return normFactor
663
663
664 def getFlagCspc(self):
664 def getFlagCspc(self):
665
665
666 if self.data_cspc is None:
666 if self.data_cspc is None:
667 return True
667 return True
668
668
669 return False
669 return False
670
670
671 def getFlagDc(self):
671 def getFlagDc(self):
672
672
673 if self.data_dc is None:
673 if self.data_dc is None:
674 return True
674 return True
675
675
676 return False
676 return False
677
677
678 def getTimeInterval(self):
678 def getTimeInterval(self):
679
679
680 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles
680 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles
681
681
682 return timeInterval
682 return timeInterval
683
683
684 def getPower(self):
684 def getPower(self):
685
685
686 factor = self.normFactor
686 factor = self.normFactor
687 z = self.data_spc/factor
687 z = self.data_spc/factor
688 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
688 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
689 avg = numpy.average(z, axis=1)
689 avg = numpy.average(z, axis=1)
690
690
691 return 10*numpy.log10(avg)
691 return 10*numpy.log10(avg)
692
692
693 def getCoherence(self, pairsList=None, phase=False):
693 def getCoherence(self, pairsList=None, phase=False):
694
694
695 z = []
695 z = []
696 if pairsList is None:
696 if pairsList is None:
697 pairsIndexList = self.pairsIndexList
697 pairsIndexList = self.pairsIndexList
698 else:
698 else:
699 pairsIndexList = []
699 pairsIndexList = []
700 for pair in pairsList:
700 for pair in pairsList:
701 if pair not in self.pairsList:
701 if pair not in self.pairsList:
702 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
702 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
703 pairsIndexList.append(self.pairsList.index(pair))
703 pairsIndexList.append(self.pairsList.index(pair))
704 for i in range(len(pairsIndexList)):
704 for i in range(len(pairsIndexList)):
705 pair = self.pairsList[pairsIndexList[i]]
705 pair = self.pairsList[pairsIndexList[i]]
706 ccf = numpy.average(self.data_cspc[pairsIndexList[i], :, :], axis=0)
706 ccf = numpy.average(self.data_cspc[pairsIndexList[i], :, :], axis=0)
707 powa = numpy.average(self.data_spc[pair[0], :, :], axis=0)
707 powa = numpy.average(self.data_spc[pair[0], :, :], axis=0)
708 powb = numpy.average(self.data_spc[pair[1], :, :], axis=0)
708 powb = numpy.average(self.data_spc[pair[1], :, :], axis=0)
709 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
709 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
710 if phase:
710 if phase:
711 data = numpy.arctan2(avgcoherenceComplex.imag,
711 data = numpy.arctan2(avgcoherenceComplex.imag,
712 avgcoherenceComplex.real)*180/numpy.pi
712 avgcoherenceComplex.real)*180/numpy.pi
713 else:
713 else:
714 data = numpy.abs(avgcoherenceComplex)
714 data = numpy.abs(avgcoherenceComplex)
715
715
716 z.append(data)
716 z.append(data)
717
717
718 return numpy.array(z)
718 return numpy.array(z)
719
719
720 def setValue(self, value):
720 def setValue(self, value):
721
721
722 print "This property should not be initialized"
722 print "This property should not be initialized"
723
723
724 return
724 return
725
725
726 nPairs = property(getNPairs, setValue, "I'm the 'nPairs' property.")
726 nPairs = property(getNPairs, setValue, "I'm the 'nPairs' property.")
727 pairsIndexList = property(getPairsIndexList, setValue, "I'm the 'pairsIndexList' property.")
727 pairsIndexList = property(getPairsIndexList, setValue, "I'm the 'pairsIndexList' property.")
728 normFactor = property(getNormFactor, setValue, "I'm the 'getNormFactor' property.")
728 normFactor = property(getNormFactor, setValue, "I'm the 'getNormFactor' property.")
729 flag_cspc = property(getFlagCspc, setValue)
729 flag_cspc = property(getFlagCspc, setValue)
730 flag_dc = property(getFlagDc, setValue)
730 flag_dc = property(getFlagDc, setValue)
731 noise = property(getNoise, setValue, "I'm the 'nHeights' property.")
731 noise = property(getNoise, setValue, "I'm the 'nHeights' property.")
732 timeInterval = property(getTimeInterval, setValue, "I'm the 'timeInterval' property")
732 timeInterval = property(getTimeInterval, setValue, "I'm the 'timeInterval' property")
733
733
734 class SpectraHeis(Spectra):
734 class SpectraHeis(Spectra):
735
735
736 data_spc = None
736 data_spc = None
737
737
738 data_cspc = None
738 data_cspc = None
739
739
740 data_dc = None
740 data_dc = None
741
741
742 nFFTPoints = None
742 nFFTPoints = None
743
743
744 # nPairs = None
744 # nPairs = None
745
745
746 pairsList = None
746 pairsList = None
747
747
748 nCohInt = None
748 nCohInt = None
749
749
750 nIncohInt = None
750 nIncohInt = None
751
751
752 def __init__(self):
752 def __init__(self):
753
753
754 self.radarControllerHeaderObj = RadarControllerHeader()
754 self.radarControllerHeaderObj = RadarControllerHeader()
755
755
756 self.systemHeaderObj = SystemHeader()
756 self.systemHeaderObj = SystemHeader()
757
757
758 self.type = "SpectraHeis"
758 self.type = "SpectraHeis"
759
759
760 # self.dtype = None
760 # self.dtype = None
761
761
762 # self.nChannels = 0
762 # self.nChannels = 0
763
763
764 # self.nHeights = 0
764 # self.nHeights = 0
765
765
766 self.nProfiles = None
766 self.nProfiles = None
767
767
768 self.heightList = None
768 self.heightList = None
769
769
770 self.channelList = None
770 self.channelList = None
771
771
772 # self.channelIndexList = None
772 # self.channelIndexList = None
773
773
774 self.flagNoData = True
774 self.flagNoData = True
775
775
776 self.flagDiscontinuousBlock = False
776 self.flagDiscontinuousBlock = False
777
777
778 # self.nPairs = 0
778 # self.nPairs = 0
779
779
780 self.utctime = None
780 self.utctime = None
781
781
782 self.blocksize = None
782 self.blocksize = None
783
783
784 self.profileIndex = 0
784 self.profileIndex = 0
785
785
786 self.nCohInt = 1
786 self.nCohInt = 1
787
787
788 self.nIncohInt = 1
788 self.nIncohInt = 1
789
789
790 def getNormFactor(self):
790 def getNormFactor(self):
791 pwcode = 1
791 pwcode = 1
792 if self.flagDecodeData:
792 if self.flagDecodeData:
793 pwcode = numpy.sum(self.code[0]**2)
793 pwcode = numpy.sum(self.code[0]**2)
794
794
795 normFactor = self.nIncohInt*self.nCohInt*pwcode
795 normFactor = self.nIncohInt*self.nCohInt*pwcode
796
796
797 return normFactor
797 return normFactor
798
798
799 def getTimeInterval(self):
799 def getTimeInterval(self):
800
800
801 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
801 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
802
802
803 return timeInterval
803 return timeInterval
804
804
805 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
805 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
806 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
806 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
807
807
808 class Fits(JROData):
808 class Fits(JROData):
809
809
810 heightList = None
810 heightList = None
811
811
812 channelList = None
812 channelList = None
813
813
814 flagNoData = True
814 flagNoData = True
815
815
816 flagDiscontinuousBlock = False
816 flagDiscontinuousBlock = False
817
817
818 useLocalTime = False
818 useLocalTime = False
819
819
820 utctime = None
820 utctime = None
821
821
822 timeZone = None
822 timeZone = None
823
823
824 # ippSeconds = None
824 # ippSeconds = None
825
825
826 # timeInterval = None
826 # timeInterval = None
827
827
828 nCohInt = None
828 nCohInt = None
829
829
830 nIncohInt = None
830 nIncohInt = None
831
831
832 noise = None
832 noise = None
833
833
834 windowOfFilter = 1
834 windowOfFilter = 1
835
835
836 #Speed of ligth
836 #Speed of ligth
837 C = 3e8
837 C = 3e8
838
838
839 frequency = 49.92e6
839 frequency = 49.92e6
840
840
841 realtime = False
841 realtime = False
842
842
843
843
844 def __init__(self):
844 def __init__(self):
845
845
846 self.type = "Fits"
846 self.type = "Fits"
847
847
848 self.nProfiles = None
848 self.nProfiles = None
849
849
850 self.heightList = None
850 self.heightList = None
851
851
852 self.channelList = None
852 self.channelList = None
853
853
854 # self.channelIndexList = None
854 # self.channelIndexList = None
855
855
856 self.flagNoData = True
856 self.flagNoData = True
857
857
858 self.utctime = None
858 self.utctime = None
859
859
860 self.nCohInt = 1
860 self.nCohInt = 1
861
861
862 self.nIncohInt = 1
862 self.nIncohInt = 1
863
863
864 self.useLocalTime = True
864 self.useLocalTime = True
865
865
866 self.profileIndex = 0
866 self.profileIndex = 0
867
867
868 # self.utctime = None
868 # self.utctime = None
869 # self.timeZone = None
869 # self.timeZone = None
870 # self.ltctime = None
870 # self.ltctime = None
871 # self.timeInterval = None
871 # self.timeInterval = None
872 # self.header = None
872 # self.header = None
873 # self.data_header = None
873 # self.data_header = None
874 # self.data = None
874 # self.data = None
875 # self.datatime = None
875 # self.datatime = None
876 # self.flagNoData = False
876 # self.flagNoData = False
877 # self.expName = ''
877 # self.expName = ''
878 # self.nChannels = None
878 # self.nChannels = None
879 # self.nSamples = None
879 # self.nSamples = None
880 # self.dataBlocksPerFile = None
880 # self.dataBlocksPerFile = None
881 # self.comments = ''
881 # self.comments = ''
882 #
882 #
883
883
884
884
885 def getltctime(self):
885 def getltctime(self):
886
886
887 if self.useLocalTime:
887 if self.useLocalTime:
888 return self.utctime - self.timeZone*60
888 return self.utctime - self.timeZone*60
889
889
890 return self.utctime
890 return self.utctime
891
891
892 def getDatatime(self):
892 def getDatatime(self):
893
893
894 datatime = datetime.datetime.utcfromtimestamp(self.ltctime)
894 datatime = datetime.datetime.utcfromtimestamp(self.ltctime)
895 return datatime
895 return datatime
896
896
897 def getTimeRange(self):
897 def getTimeRange(self):
898
898
899 datatime = []
899 datatime = []
900
900
901 datatime.append(self.ltctime)
901 datatime.append(self.ltctime)
902 datatime.append(self.ltctime + self.timeInterval)
902 datatime.append(self.ltctime + self.timeInterval)
903
903
904 datatime = numpy.array(datatime)
904 datatime = numpy.array(datatime)
905
905
906 return datatime
906 return datatime
907
907
908 def getHeiRange(self):
908 def getHeiRange(self):
909
909
910 heis = self.heightList
910 heis = self.heightList
911
911
912 return heis
912 return heis
913
913
914 def getNHeights(self):
914 def getNHeights(self):
915
915
916 return len(self.heightList)
916 return len(self.heightList)
917
917
918 def getNChannels(self):
918 def getNChannels(self):
919
919
920 return len(self.channelList)
920 return len(self.channelList)
921
921
922 def getChannelIndexList(self):
922 def getChannelIndexList(self):
923
923
924 return range(self.nChannels)
924 return range(self.nChannels)
925
925
926 def getNoise(self, type = 1):
926 def getNoise(self, type = 1):
927
927
928 #noise = numpy.zeros(self.nChannels)
928 #noise = numpy.zeros(self.nChannels)
929
929
930 if type == 1:
930 if type == 1:
931 noise = self.getNoisebyHildebrand()
931 noise = self.getNoisebyHildebrand()
932
932
933 if type == 2:
933 if type == 2:
934 noise = self.getNoisebySort()
934 noise = self.getNoisebySort()
935
935
936 if type == 3:
936 if type == 3:
937 noise = self.getNoisebyWindow()
937 noise = self.getNoisebyWindow()
938
938
939 return noise
939 return noise
940
940
941 def getTimeInterval(self):
941 def getTimeInterval(self):
942
942
943 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
943 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
944
944
945 return timeInterval
945 return timeInterval
946
946
947 datatime = property(getDatatime, "I'm the 'datatime' property")
947 datatime = property(getDatatime, "I'm the 'datatime' property")
948 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
948 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
949 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
949 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
950 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
950 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
951 noise = property(getNoise, "I'm the 'nHeights' property.")
951 noise = property(getNoise, "I'm the 'nHeights' property.")
952
952
953 ltctime = property(getltctime, "I'm the 'ltctime' property")
953 ltctime = property(getltctime, "I'm the 'ltctime' property")
954 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
954 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
955
955
956
956
957 class Correlation(JROData):
957 class Correlation(JROData):
958
958
959 noise = None
959 noise = None
960
960
961 SNR = None
961 SNR = None
962
962
963 #--------------------------------------------------
963 #--------------------------------------------------
964
964
965 mode = None
965 mode = None
966
966
967 split = False
967 split = False
968
968
969 data_cf = None
969 data_cf = None
970
970
971 lags = None
971 lags = None
972
972
973 lagRange = None
973 lagRange = None
974
974
975 pairsList = None
975 pairsList = None
976
976
977 normFactor = None
977 normFactor = None
978
978
979 #--------------------------------------------------
979 #--------------------------------------------------
980
980
981 # calculateVelocity = None
981 # calculateVelocity = None
982
982
983 nLags = None
983 nLags = None
984
984
985 nPairs = None
985 nPairs = None
986
986
987 nAvg = None
987 nAvg = None
988
988
989
989
990 def __init__(self):
990 def __init__(self):
991 '''
991 '''
992 Constructor
992 Constructor
993 '''
993 '''
994 self.radarControllerHeaderObj = RadarControllerHeader()
994 self.radarControllerHeaderObj = RadarControllerHeader()
995
995
996 self.systemHeaderObj = SystemHeader()
996 self.systemHeaderObj = SystemHeader()
997
997
998 self.type = "Correlation"
998 self.type = "Correlation"
999
999
1000 self.data = None
1000 self.data = None
1001
1001
1002 self.dtype = None
1002 self.dtype = None
1003
1003
1004 self.nProfiles = None
1004 self.nProfiles = None
1005
1005
1006 self.heightList = None
1006 self.heightList = None
1007
1007
1008 self.channelList = None
1008 self.channelList = None
1009
1009
1010 self.flagNoData = True
1010 self.flagNoData = True
1011
1011
1012 self.flagDiscontinuousBlock = False
1012 self.flagDiscontinuousBlock = False
1013
1013
1014 self.utctime = None
1014 self.utctime = None
1015
1015
1016 self.timeZone = None
1016 self.timeZone = None
1017
1017
1018 self.dstFlag = None
1018 self.dstFlag = None
1019
1019
1020 self.errorCount = None
1020 self.errorCount = None
1021
1021
1022 self.blocksize = None
1022 self.blocksize = None
1023
1023
1024 self.flagDecodeData = False #asumo q la data no esta decodificada
1024 self.flagDecodeData = False #asumo q la data no esta decodificada
1025
1025
1026 self.flagDeflipData = False #asumo q la data no esta sin flip
1026 self.flagDeflipData = False #asumo q la data no esta sin flip
1027
1027
1028 self.pairsList = None
1028 self.pairsList = None
1029
1029
1030 self.nPoints = None
1030 self.nPoints = None
1031
1031
1032 def getPairsList(self):
1032 def getPairsList(self):
1033
1033
1034 return self.pairsList
1034 return self.pairsList
1035
1035
1036 def getNoise(self, mode = 2):
1036 def getNoise(self, mode = 2):
1037
1037
1038 indR = numpy.where(self.lagR == 0)[0][0]
1038 indR = numpy.where(self.lagR == 0)[0][0]
1039 indT = numpy.where(self.lagT == 0)[0][0]
1039 indT = numpy.where(self.lagT == 0)[0][0]
1040
1040
1041 jspectra0 = self.data_corr[:,:,indR,:]
1041 jspectra0 = self.data_corr[:,:,indR,:]
1042 jspectra = copy.copy(jspectra0)
1042 jspectra = copy.copy(jspectra0)
1043
1043
1044 num_chan = jspectra.shape[0]
1044 num_chan = jspectra.shape[0]
1045 num_hei = jspectra.shape[2]
1045 num_hei = jspectra.shape[2]
1046
1046
1047 freq_dc = jspectra.shape[1]/2
1047 freq_dc = jspectra.shape[1]/2
1048 ind_vel = numpy.array([-2,-1,1,2]) + freq_dc
1048 ind_vel = numpy.array([-2,-1,1,2]) + freq_dc
1049
1049
1050 if ind_vel[0]<0:
1050 if ind_vel[0]<0:
1051 ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof
1051 ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof
1052
1052
1053 if mode == 1:
1053 if mode == 1:
1054 jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION
1054 jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION
1055
1055
1056 if mode == 2:
1056 if mode == 2:
1057
1057
1058 vel = numpy.array([-2,-1,1,2])
1058 vel = numpy.array([-2,-1,1,2])
1059 xx = numpy.zeros([4,4])
1059 xx = numpy.zeros([4,4])
1060
1060
1061 for fil in range(4):
1061 for fil in range(4):
1062 xx[fil,:] = vel[fil]**numpy.asarray(range(4))
1062 xx[fil,:] = vel[fil]**numpy.asarray(range(4))
1063
1063
1064 xx_inv = numpy.linalg.inv(xx)
1064 xx_inv = numpy.linalg.inv(xx)
1065 xx_aux = xx_inv[0,:]
1065 xx_aux = xx_inv[0,:]
1066
1066
1067 for ich in range(num_chan):
1067 for ich in range(num_chan):
1068 yy = jspectra[ich,ind_vel,:]
1068 yy = jspectra[ich,ind_vel,:]
1069 jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy)
1069 jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy)
1070
1070
1071 junkid = jspectra[ich,freq_dc,:]<=0
1071 junkid = jspectra[ich,freq_dc,:]<=0
1072 cjunkid = sum(junkid)
1072 cjunkid = sum(junkid)
1073
1073
1074 if cjunkid.any():
1074 if cjunkid.any():
1075 jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2
1075 jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2
1076
1076
1077 noise = jspectra0[:,freq_dc,:] - jspectra[:,freq_dc,:]
1077 noise = jspectra0[:,freq_dc,:] - jspectra[:,freq_dc,:]
1078
1078
1079 return noise
1079 return noise
1080
1080
1081 def getTimeInterval(self):
1081 def getTimeInterval(self):
1082
1082
1083 timeInterval = self.ippSeconds * self.nCohInt * self.nProfiles
1083 timeInterval = self.ippSeconds * self.nCohInt * self.nProfiles
1084
1084
1085 return timeInterval
1085 return timeInterval
1086
1086
1087 def splitFunctions(self):
1087 def splitFunctions(self):
1088
1088
1089 pairsList = self.pairsList
1089 pairsList = self.pairsList
1090 ccf_pairs = []
1090 ccf_pairs = []
1091 acf_pairs = []
1091 acf_pairs = []
1092 ccf_ind = []
1092 ccf_ind = []
1093 acf_ind = []
1093 acf_ind = []
1094 for l in range(len(pairsList)):
1094 for l in range(len(pairsList)):
1095 chan0 = pairsList[l][0]
1095 chan0 = pairsList[l][0]
1096 chan1 = pairsList[l][1]
1096 chan1 = pairsList[l][1]
1097
1097
1098 #Obteniendo pares de Autocorrelacion
1098 #Obteniendo pares de Autocorrelacion
1099 if chan0 == chan1:
1099 if chan0 == chan1:
1100 acf_pairs.append(chan0)
1100 acf_pairs.append(chan0)
1101 acf_ind.append(l)
1101 acf_ind.append(l)
1102 else:
1102 else:
1103 ccf_pairs.append(pairsList[l])
1103 ccf_pairs.append(pairsList[l])
1104 ccf_ind.append(l)
1104 ccf_ind.append(l)
1105
1105
1106 data_acf = self.data_cf[acf_ind]
1106 data_acf = self.data_cf[acf_ind]
1107 data_ccf = self.data_cf[ccf_ind]
1107 data_ccf = self.data_cf[ccf_ind]
1108
1108
1109 return acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf
1109 return acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf
1110
1110
1111 def getNormFactor(self):
1111 def getNormFactor(self):
1112 acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.splitFunctions()
1112 acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.splitFunctions()
1113 acf_pairs = numpy.array(acf_pairs)
1113 acf_pairs = numpy.array(acf_pairs)
1114 normFactor = numpy.zeros((self.nPairs,self.nHeights))
1114 normFactor = numpy.zeros((self.nPairs,self.nHeights))
1115
1115
1116 for p in range(self.nPairs):
1116 for p in range(self.nPairs):
1117 pair = self.pairsList[p]
1117 pair = self.pairsList[p]
1118
1118
1119 ch0 = pair[0]
1119 ch0 = pair[0]
1120 ch1 = pair[1]
1120 ch1 = pair[1]
1121
1121
1122 ch0_max = numpy.max(data_acf[acf_pairs==ch0,:,:], axis=1)
1122 ch0_max = numpy.max(data_acf[acf_pairs==ch0,:,:], axis=1)
1123 ch1_max = numpy.max(data_acf[acf_pairs==ch1,:,:], axis=1)
1123 ch1_max = numpy.max(data_acf[acf_pairs==ch1,:,:], axis=1)
1124 normFactor[p,:] = numpy.sqrt(ch0_max*ch1_max)
1124 normFactor[p,:] = numpy.sqrt(ch0_max*ch1_max)
1125
1125
1126 return normFactor
1126 return normFactor
1127
1127
1128 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
1128 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
1129 normFactor = property(getNormFactor, "I'm the 'normFactor property'")
1129 normFactor = property(getNormFactor, "I'm the 'normFactor property'")
1130
1130
1131 class Parameters(Spectra):
1131 class Parameters(Spectra):
1132
1132
1133 experimentInfo = None #Information about the experiment
1133 experimentInfo = None #Information about the experiment
1134
1134
1135 #Information from previous data
1135 #Information from previous data
1136
1136
1137 inputUnit = None #Type of data to be processed
1137 inputUnit = None #Type of data to be processed
1138
1138
1139 operation = None #Type of operation to parametrize
1139 operation = None #Type of operation to parametrize
1140
1140
1141 #normFactor = None #Normalization Factor
1141 #normFactor = None #Normalization Factor
1142
1142
1143 groupList = None #List of Pairs, Groups, etc
1143 groupList = None #List of Pairs, Groups, etc
1144
1144
1145 #Parameters
1145 #Parameters
1146
1146
1147 data_param = None #Parameters obtained
1147 data_param = None #Parameters obtained
1148
1148
1149 data_pre = None #Data Pre Parametrization
1149 data_pre = None #Data Pre Parametrization
1150
1150
1151 data_SNR = None #Signal to Noise Ratio
1151 data_SNR = None #Signal to Noise Ratio
1152
1152
1153 # heightRange = None #Heights
1153 # heightRange = None #Heights
1154
1154
1155 abscissaList = None #Abscissa, can be velocities, lags or time
1155 abscissaList = None #Abscissa, can be velocities, lags or time
1156
1156
1157 # noise = None #Noise Potency
1157 # noise = None #Noise Potency
1158
1158
1159 utctimeInit = None #Initial UTC time
1159 utctimeInit = None #Initial UTC time
1160
1160
1161 paramInterval = None #Time interval to calculate Parameters in seconds
1161 paramInterval = None #Time interval to calculate Parameters in seconds
1162
1162
1163 useLocalTime = True
1163 useLocalTime = True
1164
1164
1165 #Fitting
1165 #Fitting
1166
1166
1167 data_error = None #Error of the estimation
1167 data_error = None #Error of the estimation
1168
1168
1169 constants = None
1169 constants = None
1170
1170
1171 library = None
1171 library = None
1172
1172
1173 #Output signal
1173 #Output signal
1174
1174
1175 outputInterval = None #Time interval to calculate output signal in seconds
1175 outputInterval = None #Time interval to calculate output signal in seconds
1176
1176
1177 data_output = None #Out signal
1177 data_output = None #Out signal
1178
1178
1179 nAvg = None
1179 nAvg = None
1180
1180
1181 noise_estimation = None
1181 noise_estimation = None
1182
1182
1183 GauSPC = None #Fit gaussian SPC
1183 GauSPC = None #Fit gaussian SPC
1184
1184
1185
1185
1186 def __init__(self):
1186 def __init__(self):
1187 '''
1187 '''
1188 Constructor
1188 Constructor
1189 '''
1189 '''
1190 self.radarControllerHeaderObj = RadarControllerHeader()
1190 self.radarControllerHeaderObj = RadarControllerHeader()
1191
1191
1192 self.systemHeaderObj = SystemHeader()
1192 self.systemHeaderObj = SystemHeader()
1193
1193
1194 self.type = "Parameters"
1194 self.type = "Parameters"
1195
1195
1196 def getTimeRange1(self, interval):
1196 def getTimeRange1(self, interval):
1197
1197
1198 datatime = []
1198 datatime = []
1199
1199
1200 if self.useLocalTime:
1200 if self.useLocalTime:
1201 time1 = self.utctimeInit - self.timeZone*60
1201 time1 = self.utctimeInit - self.timeZone*60
1202 else:
1202 else:
1203 time1 = self.utctimeInit
1203 time1 = self.utctimeInit
1204
1204
1205 datatime.append(time1)
1205 datatime.append(time1)
1206 datatime.append(time1 + interval)
1206 datatime.append(time1 + interval)
1207 datatime = numpy.array(datatime)
1207 datatime = numpy.array(datatime)
1208
1208
1209 return datatime
1209 return datatime
1210
1210
1211 def getTimeInterval(self):
1211 def getTimeInterval(self):
1212
1212
1213 if hasattr(self, 'timeInterval1'):
1213 if hasattr(self, 'timeInterval1'):
1214 return self.timeInterval1
1214 return self.timeInterval1
1215 else:
1215 else:
1216 return self.paramInterval
1216 return self.paramInterval
1217
1217
1218 def setValue(self, value):
1218 def setValue(self, value):
1219
1219
1220 print "This property should not be initialized"
1220 print "This property should not be initialized"
1221
1221
1222 return
1222 return
1223
1223
1224 def getNoise(self):
1224 def getNoise(self):
1225
1225
1226 return self.spc_noise
1226 return self.spc_noise
1227
1227
1228 timeInterval = property(getTimeInterval)
1228 timeInterval = property(getTimeInterval)
1229 noise = property(getNoise, setValue, "I'm the 'Noise' property.")
1229 noise = property(getNoise, setValue, "I'm the 'Noise' property.")
@@ -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):
16 def __init__(self):
18
17
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)
This diff has been collapsed as it changes many lines, (1201 lines changed) Show them Hide them
@@ -1,955 +1,782
1
1
2 import os
2 import os
3 import zmq
4 import time
3 import time
5 import numpy
4 import glob
6 import datetime
5 import datetime
7 import numpy as np
6 from multiprocessing import Process
7
8 import zmq
9 import numpy
8 import matplotlib
10 import matplotlib
9 import glob
10 matplotlib.use('TkAgg')
11 import matplotlib.pyplot as plt
11 import matplotlib.pyplot as plt
12 from mpl_toolkits.axes_grid1 import make_axes_locatable
12 from mpl_toolkits.axes_grid1 import make_axes_locatable
13 from matplotlib.ticker import FuncFormatter, LinearLocator
13 from matplotlib.ticker import FuncFormatter, LinearLocator, MultipleLocator
14 from multiprocessing import Process
15
14
16 from schainpy.model.proc.jroproc_base import Operation
15 from schainpy.model.proc.jroproc_base import Operation
17
16 from schainpy.utils import log
18 plt.ion()
19
17
20 func = lambda x, pos: ('%s') %(datetime.datetime.fromtimestamp(x).strftime('%H:%M'))
18 func = lambda x, pos: ('%s') %(datetime.datetime.fromtimestamp(x).strftime('%H:%M'))
21
19
22 d1970 = datetime.datetime(1970,1,1)
20 d1970 = datetime.datetime(1970, 1, 1)
21
23
22
24 class PlotData(Operation, Process):
23 class PlotData(Operation, Process):
24 '''
25 Base class for Schain plotting operations
26 '''
25
27
26 CODE = 'Figure'
28 CODE = 'Figure'
27 colormap = 'jro'
29 colormap = 'jro'
30 bgcolor = 'white'
28 CONFLATE = False
31 CONFLATE = False
29 __MAXNUMX = 80
32 __MAXNUMX = 80
30 __missing = 1E30
33 __missing = 1E30
31
34
32 def __init__(self, **kwargs):
35 def __init__(self, **kwargs):
33
36
34 Operation.__init__(self, plot=True, **kwargs)
37 Operation.__init__(self, plot=True, **kwargs)
35 Process.__init__(self)
38 Process.__init__(self)
36 self.kwargs['code'] = self.CODE
39 self.kwargs['code'] = self.CODE
37 self.mp = False
40 self.mp = False
38 self.dataOut = None
41 self.data = None
39 self.isConfig = False
42 self.isConfig = False
40 self.figure = None
43 self.figures = []
41 self.axes = []
44 self.axes = []
45 self.cb_axes = []
42 self.localtime = kwargs.pop('localtime', True)
46 self.localtime = kwargs.pop('localtime', True)
43 self.show = kwargs.get('show', True)
47 self.show = kwargs.get('show', True)
44 self.save = kwargs.get('save', False)
48 self.save = kwargs.get('save', False)
45 self.colormap = kwargs.get('colormap', self.colormap)
49 self.colormap = kwargs.get('colormap', self.colormap)
46 self.colormap_coh = kwargs.get('colormap_coh', 'jet')
50 self.colormap_coh = kwargs.get('colormap_coh', 'jet')
47 self.colormap_phase = kwargs.get('colormap_phase', 'RdBu_r')
51 self.colormap_phase = kwargs.get('colormap_phase', 'RdBu_r')
48 self.showprofile = kwargs.get('showprofile', True)
52 self.colormaps = kwargs.get('colormaps', None)
49 self.title = kwargs.get('wintitle', '')
53 self.bgcolor = kwargs.get('bgcolor', self.bgcolor)
54 self.showprofile = kwargs.get('showprofile', False)
55 self.title = kwargs.get('wintitle', self.CODE.upper())
56 self.cb_label = kwargs.get('cb_label', None)
57 self.cb_labels = kwargs.get('cb_labels', None)
50 self.xaxis = kwargs.get('xaxis', 'frequency')
58 self.xaxis = kwargs.get('xaxis', 'frequency')
51 self.zmin = kwargs.get('zmin', None)
59 self.zmin = kwargs.get('zmin', None)
52 self.zmax = kwargs.get('zmax', None)
60 self.zmax = kwargs.get('zmax', None)
61 self.zlimits = kwargs.get('zlimits', None)
53 self.xmin = kwargs.get('xmin', None)
62 self.xmin = kwargs.get('xmin', None)
63 if self.xmin is not None:
64 self.xmin += 5
54 self.xmax = kwargs.get('xmax', None)
65 self.xmax = kwargs.get('xmax', None)
55 self.xrange = kwargs.get('xrange', 24)
66 self.xrange = kwargs.get('xrange', 24)
56 self.ymin = kwargs.get('ymin', None)
67 self.ymin = kwargs.get('ymin', None)
57 self.ymax = kwargs.get('ymax', None)
68 self.ymax = kwargs.get('ymax', None)
58 self.__MAXNUMY = kwargs.get('decimation', 80)
69 self.xlabel = kwargs.get('xlabel', None)
59 self.throttle_value = 5
70 self.__MAXNUMY = kwargs.get('decimation', 100)
60 self.times = []
71 self.showSNR = kwargs.get('showSNR', False)
61 #self.interactive = self.kwargs['parent']
72 self.oneFigure = kwargs.get('oneFigure', True)
73 self.width = kwargs.get('width', None)
74 self.height = kwargs.get('height', None)
75 self.colorbar = kwargs.get('colorbar', True)
76 self.factors = kwargs.get('factors', [1, 1, 1, 1, 1, 1, 1, 1])
77 self.titles = ['' for __ in range(16)]
78
79 def __setup(self):
80 '''
81 Common setup for all figures, here figures and axes are created
82 '''
83
84 self.setup()
62
85
86 if self.width is None:
87 self.width = 8
88
89 self.figures = []
90 self.axes = []
91 self.cb_axes = []
92 self.pf_axes = []
93 self.cmaps = []
94
95 size = '15%' if self.ncols==1 else '30%'
96 pad = '4%' if self.ncols==1 else '8%'
97
98 if self.oneFigure:
99 if self.height is None:
100 self.height = 1.4*self.nrows + 1
101 fig = plt.figure(figsize=(self.width, self.height),
102 edgecolor='k',
103 facecolor='w')
104 self.figures.append(fig)
105 for n in range(self.nplots):
106 ax = fig.add_subplot(self.nrows, self.ncols, n+1)
107 ax.tick_params(labelsize=8)
108 ax.firsttime = True
109 self.axes.append(ax)
110 if self.showprofile:
111 cax = self.__add_axes(ax, size=size, pad=pad)
112 cax.tick_params(labelsize=8)
113 self.pf_axes.append(cax)
114 else:
115 if self.height is None:
116 self.height = 3
117 for n in range(self.nplots):
118 fig = plt.figure(figsize=(self.width, self.height),
119 edgecolor='k',
120 facecolor='w')
121 ax = fig.add_subplot(1, 1, 1)
122 ax.tick_params(labelsize=8)
123 ax.firsttime = True
124 self.figures.append(fig)
125 self.axes.append(ax)
126 if self.showprofile:
127 cax = self.__add_axes(ax, size=size, pad=pad)
128 cax.tick_params(labelsize=8)
129 self.pf_axes.append(cax)
130
131 for n in range(self.nrows):
132 if self.colormaps is not None:
133 cmap = plt.get_cmap(self.colormaps[n])
134 else:
135 cmap = plt.get_cmap(self.colormap)
136 cmap.set_bad(self.bgcolor, 1.)
137 self.cmaps.append(cmap)
138
139 def __add_axes(self, ax, size='30%', pad='8%'):
63 '''
140 '''
64 this new parameter is created to plot data from varius channels at different figures
141 Add new axes to the given figure
65 1. crear una lista de figuras donde se puedan plotear las figuras,
66 2. dar las opciones de configuracion a cada figura, estas opciones son iguales para ambas figuras
67 3. probar?
68 '''
142 '''
69 self.ind_plt_ch = kwargs.get('ind_plt_ch', False)
143 divider = make_axes_locatable(ax)
70 self.figurelist = None
144 nax = divider.new_horizontal(size=size, pad=pad)
145 ax.figure.add_axes(nax)
146 return nax
71
147
72
148
73 def fill_gaps(self, x_buffer, y_buffer, z_buffer):
149 def setup(self):
150 '''
151 This method should be implemented in the child class, the following
152 attributes should be set:
153
154 self.nrows: number of rows
155 self.ncols: number of cols
156 self.nplots: number of plots (channels or pairs)
157 self.ylabel: label for Y axes
158 self.titles: list of axes title
159
160 '''
161 raise(NotImplementedError, 'Implement this method in child class')
74
162
163 def fill_gaps(self, x_buffer, y_buffer, z_buffer):
164 '''
165 Create a masked array for missing data
166 '''
75 if x_buffer.shape[0] < 2:
167 if x_buffer.shape[0] < 2:
76 return x_buffer, y_buffer, z_buffer
168 return x_buffer, y_buffer, z_buffer
77
169
78 deltas = x_buffer[1:] - x_buffer[0:-1]
170 deltas = x_buffer[1:] - x_buffer[0:-1]
79 x_median = np.median(deltas)
171 x_median = numpy.median(deltas)
80
172
81 index = np.where(deltas > 5*x_median)
173 index = numpy.where(deltas > 5*x_median)
82
174
83 if len(index[0]) != 0:
175 if len(index[0]) != 0:
84 z_buffer[::, index[0], ::] = self.__missing
176 z_buffer[::, index[0], ::] = self.__missing
85 z_buffer = np.ma.masked_inside(z_buffer,
177 z_buffer = numpy.ma.masked_inside(z_buffer,
86 0.99*self.__missing,
178 0.99*self.__missing,
87 1.01*self.__missing)
179 1.01*self.__missing)
88
180
89 return x_buffer, y_buffer, z_buffer
181 return x_buffer, y_buffer, z_buffer
90
182
91 def decimate(self):
183 def decimate(self):
92
184
93 # dx = int(len(self.x)/self.__MAXNUMX) + 1
185 # dx = int(len(self.x)/self.__MAXNUMX) + 1
94 dy = int(len(self.y)/self.__MAXNUMY) + 1
186 dy = int(len(self.y)/self.__MAXNUMY) + 1
95
187
96 # x = self.x[::dx]
188 # x = self.x[::dx]
97 x = self.x
189 x = self.x
98 y = self.y[::dy]
190 y = self.y[::dy]
99 z = self.z[::, ::, ::dy]
191 z = self.z[::, ::, ::dy]
100
192
101 return x, y, z
193 return x, y, z
102
194
103 '''
195 def format(self):
104 JM:
196 '''
105 elimana las otras imagenes generadas debido a que lso workers no llegan en orden y le pueden
197 Set min and max values, labels, ticks and titles
106 poner otro tiempo a la figura q no necesariamente es el ultimo.
198 '''
107 Solo se realiza cuando termina la imagen.
108 Problemas:
109
199
110 File "/home/ci-81/workspace/schainv2.3/schainpy/model/graphics/jroplot_data.py", line 145, in __plot
200 if self.xmin is None:
111 for n, eachfigure in enumerate(self.figurelist):
201 xmin = self.min_time
112 TypeError: 'NoneType' object is not iterable
202 else:
203 if self.xaxis is 'time':
204 dt = datetime.datetime.fromtimestamp(self.min_time)
205 xmin = (datetime.datetime.combine(dt.date(),
206 datetime.time(int(self.xmin), 0, 0))-d1970).total_seconds()
207 else:
208 xmin = self.xmin
113
209
114 '''
210 if self.xmax is None:
115 def deleteanotherfiles(self):
211 xmax = xmin+self.xrange*60*60
116 figurenames=[]
212 else:
117 if self.figurelist != None:
213 if self.xaxis is 'time':
118 for n, eachfigure in enumerate(self.figurelist):
214 dt = datetime.datetime.fromtimestamp(self.min_time)
119 #add specific name for each channel in channelList
215 xmax = (datetime.datetime.combine(dt.date(),
120 ghostfigname = os.path.join(self.save, '{}_{}_{}'.format(self.titles[n].replace(' ',''),self.CODE,
216 datetime.time(int(self.xmax), 0, 0))-d1970).total_seconds()
121 datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d')))
217 else:
122 figname = os.path.join(self.save, '{}_{}_{}.png'.format(self.titles[n].replace(' ',''),self.CODE,
218 xmax = self.xmax
123 datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S')))
219
124
220 ymin = self.ymin if self.ymin else numpy.nanmin(self.y)
125 for ghostfigure in glob.glob(ghostfigname+'*'): #ghostfigure will adopt all posible names of figures
221 ymax = self.ymax if self.ymax else numpy.nanmax(self.y)
126 if ghostfigure != figname:
222
127 os.remove(ghostfigure)
223 ystep = 200 if ymax>= 800 else 100 if ymax>=400 else 50 if ymax>=200 else 20
128 print 'Removing GhostFigures:' , figname
224
129 else :
225 for n, ax in enumerate(self.axes):
130 '''Erasing ghost images for just on******************'''
226 if ax.firsttime:
131 ghostfigname = os.path.join(self.save, '{}_{}'.format(self.CODE,datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d')))
227 ax.set_facecolor(self.bgcolor)
132 figname = os.path.join(self.save, '{}_{}.png'.format(self.CODE,datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S')))
228 ax.yaxis.set_major_locator(MultipleLocator(ystep))
133 for ghostfigure in glob.glob(ghostfigname+'*'): #ghostfigure will adopt all posible names of figures
229 if self.xaxis is 'time':
134 if ghostfigure != figname:
230 ax.xaxis.set_major_formatter(FuncFormatter(func))
135 os.remove(ghostfigure)
231 ax.xaxis.set_major_locator(LinearLocator(9))
136 print 'Removing GhostFigures:' , figname
232 if self.xlabel is not None:
233 ax.set_xlabel(self.xlabel)
234 ax.set_ylabel(self.ylabel)
235 ax.firsttime = False
236 if self.showprofile:
237 self.pf_axes[n].set_ylim(ymin, ymax)
238 self.pf_axes[n].set_xlim(self.zmin, self.zmax)
239 self.pf_axes[n].set_xlabel('dB')
240 self.pf_axes[n].grid(b=True, axis='x')
241 [tick.set_visible(False) for tick in self.pf_axes[n].get_yticklabels()]
242 if self.colorbar:
243 cb = plt.colorbar(ax.plt, ax=ax, pad=0.02)
244 cb.ax.tick_params(labelsize=8)
245 if self.cb_label:
246 cb.set_label(self.cb_label, size=8)
247 elif self.cb_labels:
248 cb.set_label(self.cb_labels[n], size=8)
249
250 ax.set_title('{} - {} UTC'.format(
251 self.titles[n],
252 datetime.datetime.fromtimestamp(self.max_time).strftime('%H:%M:%S')),
253 size=8)
254 ax.set_xlim(xmin, xmax)
255 ax.set_ylim(ymin, ymax)
256
137
257
138 def __plot(self):
258 def __plot(self):
139
259 '''
140 print 'plotting...{}'.format(self.CODE)
260 '''
141 if self.ind_plt_ch is False : #standard
261 log.success('Plotting', self.name)
262
263 self.plot()
264 self.format()
265
266 for n, fig in enumerate(self.figures):
267 if self.nrows == 0 or self.nplots == 0:
268 log.warning('No data', self.name)
269 continue
142 if self.show:
270 if self.show:
143 self.figure.show()
271 fig.show()
144 self.plot()
272
145 plt.tight_layout()
273 fig.tight_layout()
146 self.figure.canvas.manager.set_window_title('{} {} - {}'.format(self.title, self.CODE.upper(),
274 fig.canvas.manager.set_window_title('{} - {}'.format(self.title,
147 datetime.datetime.fromtimestamp(self.max_time).strftime('%Y/%m/%d')))
275 datetime.datetime.fromtimestamp(self.max_time).strftime('%Y/%m/%d')))
148 else :
276 # fig.canvas.draw()
149 print 'len(self.figurelist): ',len(self.figurelist)
277
150 for n, eachfigure in enumerate(self.figurelist):
278 if self.save and self.data.ended:
151 if self.show:
279 channels = range(self.nrows)
152 eachfigure.show()
280 if self.oneFigure:
153
281 label = ''
154 self.plot()
282 else:
155 eachfigure.tight_layout() # ajuste de cada subplot
283 label = '_{}'.format(channels[n])
156 eachfigure.canvas.manager.set_window_title('{} {} - {}'.format(self.title[n], self.CODE.upper(),
284 figname = os.path.join(
157 datetime.datetime.fromtimestamp(self.max_time).strftime('%Y/%m/%d')))
285 self.save,
158
286 '{}{}_{}.png'.format(
159 # if self.save:
287 self.CODE,
160 # if self.ind_plt_ch is False : #standard
288 label,
161 # figname = os.path.join(self.save, '{}_{}.png'.format(self.CODE,
289 datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S')
162 # datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S')))
290 )
163 # print 'Saving figure: {}'.format(figname)
291 )
164 # self.figure.savefig(figname)
165 # else :
166 # for n, eachfigure in enumerate(self.figurelist):
167 # #add specific name for each channel in channelList
168 # figname = os.path.join(self.save, '{}_{}_{}.png'.format(self.titles[n],self.CODE,
169 # datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S')))
170 #
171 # print 'Saving figure: {}'.format(figname)
172 # eachfigure.savefig(figname)
173
174 if self.ind_plt_ch is False :
175 self.figure.canvas.draw()
176 else :
177 for eachfigure in self.figurelist:
178 eachfigure.canvas.draw()
179
180 if self.save:
181 if self.ind_plt_ch is False : #standard
182 figname = os.path.join(self.save, '{}_{}.png'.format(self.CODE,
183 datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S')))
184 print 'Saving figure: {}'.format(figname)
292 print 'Saving figure: {}'.format(figname)
185 self.figure.savefig(figname)
293 fig.savefig(figname)
186 else :
187 for n, eachfigure in enumerate(self.figurelist):
188 #add specific name for each channel in channelList
189 figname = os.path.join(self.save, '{}_{}_{}.png'.format(self.titles[n].replace(' ',''),self.CODE,
190 datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S')))
191
192 print 'Saving figure: {}'.format(figname)
193 eachfigure.savefig(figname)
194
195
294
196 def plot(self):
295 def plot(self):
197
296 '''
198 print 'plotting...{}'.format(self.CODE.upper())
297 '''
199 return
298 raise(NotImplementedError, 'Implement this method in child class')
200
299
201 def run(self):
300 def run(self):
202
301
203 print '[Starting] {}'.format(self.name)
302 log.success('Starting', self.name)
204
303
205 context = zmq.Context()
304 context = zmq.Context()
206 receiver = context.socket(zmq.SUB)
305 receiver = context.socket(zmq.SUB)
207 receiver.setsockopt(zmq.SUBSCRIBE, '')
306 receiver.setsockopt(zmq.SUBSCRIBE, '')
208 receiver.setsockopt(zmq.CONFLATE, self.CONFLATE)
307 receiver.setsockopt(zmq.CONFLATE, self.CONFLATE)
209
308
210 if 'server' in self.kwargs['parent']:
309 if 'server' in self.kwargs['parent']:
211 receiver.connect('ipc:///tmp/{}.plots'.format(self.kwargs['parent']['server']))
310 receiver.connect('ipc:///tmp/{}.plots'.format(self.kwargs['parent']['server']))
212 else:
311 else:
213 receiver.connect("ipc:///tmp/zmq.plots")
312 receiver.connect("ipc:///tmp/zmq.plots")
214
215 seconds_passed = 0
216
313
217 while True:
314 while True:
218 try:
315 try:
219 self.data = receiver.recv_pyobj(flags=zmq.NOBLOCK)#flags=zmq.NOBLOCK
316 self.data = receiver.recv_pyobj(flags=zmq.NOBLOCK)
220 self.started = self.data['STARTED']
317
221 self.dataOut = self.data['dataOut']
318 self.min_time = self.data.times[0]
222
319 self.max_time = self.data.times[-1]
223 if (len(self.times) < len(self.data['times']) and not self.started and self.data['ENDED']):
224 continue
225
226 self.times = self.data['times']
227 self.times.sort()
228 self.throttle_value = self.data['throttle']
229 self.min_time = self.times[0]
230 self.max_time = self.times[-1]
231
320
232 if self.isConfig is False:
321 if self.isConfig is False:
233 print 'setting up'
322 self.__setup()
234 self.setup()
235 self.isConfig = True
323 self.isConfig = True
236 self.__plot()
324
237
325 self.__plot()
238 if self.data['ENDED'] is True:
239 print '********GRAPHIC ENDED********'
240 self.ended = True
241 self.isConfig = False
242 self.__plot()
243 self.deleteanotherfiles() #CLPDG
244 elif seconds_passed >= self.data['throttle']:
245 print 'passed', seconds_passed
246 self.__plot()
247 seconds_passed = 0
248
326
249 except zmq.Again as e:
327 except zmq.Again as e:
250 print 'Waiting for data...'
328 log.log('Waiting for data...')
251 plt.pause(2)
329 if self.data:
252 seconds_passed += 2
330 plt.pause(self.data.throttle)
331 else:
332 time.sleep(2)
253
333
254 def close(self):
334 def close(self):
255 if self.dataOut:
335 if self.data:
256 self.__plot()
336 self.__plot()
257
337
258
338
259 class PlotSpectraData(PlotData):
339 class PlotSpectraData(PlotData):
340 '''
341 Plot for Spectra data
342 '''
260
343
261 CODE = 'spc'
344 CODE = 'spc'
262 colormap = 'jro'
345 colormap = 'jro'
263 CONFLATE = False
264
346
265 def setup(self):
347 def setup(self):
266
348 self.nplots = len(self.data.channels)
267 ncolspan = 1
349 self.ncols = int(numpy.sqrt(self.nplots)+ 0.9)
268 colspan = 1
350 self.nrows = int((1.0*self.nplots/self.ncols) + 0.9)
269 self.ncols = int(numpy.sqrt(self.dataOut.nChannels)+0.9)
351 self.width = 3.4*self.ncols
270 self.nrows = int(self.dataOut.nChannels*1./self.ncols + 0.9)
352 self.height = 3*self.nrows
271 self.width = 3.6*self.ncols
353 self.cb_label = 'dB'
272 self.height = 3.2*self.nrows
354 if self.showprofile:
273 if self.showprofile:
355 self.width += 0.8*self.ncols
274 ncolspan = 3
275 colspan = 2
276 self.width += 1.2*self.ncols
277
356
278 self.ylabel = 'Range [Km]'
357 self.ylabel = 'Range [Km]'
279 self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList]
280
281 if self.figure is None:
282 self.figure = plt.figure(figsize=(self.width, self.height),
283 edgecolor='k',
284 facecolor='w')
285 else:
286 self.figure.clf()
287
288 n = 0
289 for y in range(self.nrows):
290 for x in range(self.ncols):
291 if n >= self.dataOut.nChannels:
292 break
293 ax = plt.subplot2grid((self.nrows, self.ncols*ncolspan), (y, x*ncolspan), 1, colspan)
294 if self.showprofile:
295 ax.ax_profile = plt.subplot2grid((self.nrows, self.ncols*ncolspan), (y, x*ncolspan+colspan), 1, 1)
296
297 ax.firsttime = True
298 self.axes.append(ax)
299 n += 1
300
358
301 def plot(self):
359 def plot(self):
302
303 if self.xaxis == "frequency":
360 if self.xaxis == "frequency":
304 x = self.dataOut.getFreqRange(1)/1000.
361 x = self.data.xrange[0]
305 xlabel = "Frequency (kHz)"
362 self.xlabel = "Frequency (kHz)"
306 elif self.xaxis == "time":
363 elif self.xaxis == "time":
307 x = self.dataOut.getAcfRange(1)
364 x = self.data.xrange[1]
308 xlabel = "Time (ms)"
365 self.xlabel = "Time (ms)"
309 else:
366 else:
310 x = self.dataOut.getVelRange(1)
367 x = self.data.xrange[2]
311 xlabel = "Velocity (m/s)"
368 self.xlabel = "Velocity (m/s)"
312
369
313 y = self.dataOut.getHeiRange()
370 if self.CODE == 'spc_mean':
314 z = self.data[self.CODE]
371 x = self.data.xrange[2]
372 self.xlabel = "Velocity (m/s)"
315
373
374 self.titles = []
375
376 y = self.data.heights
377 self.y = y
378 z = self.data['spc']
379
316 for n, ax in enumerate(self.axes):
380 for n, ax in enumerate(self.axes):
381 noise = self.data['noise'][n][-1]
382 if self.CODE == 'spc_mean':
383 mean = self.data['mean'][n][-1]
317 if ax.firsttime:
384 if ax.firsttime:
318 self.xmax = self.xmax if self.xmax else np.nanmax(x)
385 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
319 self.xmin = self.xmin if self.xmin else -self.xmax
386 self.xmin = self.xmin if self.xmin else -self.xmax
320 self.ymin = self.ymin if self.ymin else np.nanmin(y)
387 self.zmin = self.zmin if self.zmin else numpy.nanmin(z)
321 self.ymax = self.ymax if self.ymax else np.nanmax(y)
388 self.zmax = self.zmax if self.zmax else numpy.nanmax(z)
322 self.zmin = self.zmin if self.zmin else np.nanmin(z)
389 ax.plt = ax.pcolormesh(x, y, z[n].T,
323 self.zmax = self.zmax if self.zmax else np.nanmax(z)
390 vmin=self.zmin,
324 ax.plot = ax.pcolormesh(x, y, z[n].T,
391 vmax=self.zmax,
325 vmin=self.zmin,
392 cmap=plt.get_cmap(self.colormap)
326 vmax=self.zmax,
393 )
327 cmap=plt.get_cmap(self.colormap)
328 )
329 divider = make_axes_locatable(ax)
330 cax = divider.new_horizontal(size='3%', pad=0.05)
331 self.figure.add_axes(cax)
332 plt.colorbar(ax.plot, cax)
333
334 ax.set_xlim(self.xmin, self.xmax)
335 ax.set_ylim(self.ymin, self.ymax)
336
337 ax.set_ylabel(self.ylabel)
338 ax.set_xlabel(xlabel)
339
340 ax.firsttime = False
341
394
342 if self.showprofile:
395 if self.showprofile:
343 ax.plot_profile= ax.ax_profile.plot(self.data['rti'][self.max_time][n], y)[0]
396 ax.plt_profile= self.pf_axes[n].plot(self.data['rti'][n][-1], y)[0]
344 ax.ax_profile.set_xlim(self.zmin, self.zmax)
397 ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y,
345 ax.ax_profile.set_ylim(self.ymin, self.ymax)
398 color="k", linestyle="dashed", lw=1)[0]
346 ax.ax_profile.set_xlabel('dB')
399 if self.CODE == 'spc_mean':
347 ax.ax_profile.grid(b=True, axis='x')
400 ax.plt_mean = ax.plot(mean, y, color='k')[0]
348 ax.plot_noise = ax.ax_profile.plot(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y,
349 color="k", linestyle="dashed", lw=2)[0]
350 [tick.set_visible(False) for tick in ax.ax_profile.get_yticklabels()]
351 else:
401 else:
352 ax.plot.set_array(z[n].T.ravel())
402 ax.plt.set_array(z[n].T.ravel())
353 if self.showprofile:
403 if self.showprofile:
354 ax.plot_profile.set_data(self.data['rti'][self.max_time][n], y)
404 ax.plt_profile.set_data(self.data['rti'][n][-1], y)
355 ax.plot_noise.set_data(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y)
405 ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y)
406 if self.CODE == 'spc_mean':
407 ax.plt_mean.set_data(mean, y)
356
408
357 ax.set_title('{} - Noise: {:.2f} dB'.format(self.titles[n], self.data['noise'][self.max_time][n]),
409 self.titles.append('CH {}: {:3.2f}dB'.format(n, noise))
358 size=8)
359 self.saveTime = self.max_time
410 self.saveTime = self.max_time
360
411
361
412
362 class PlotCrossSpectraData(PlotData):
413 class PlotCrossSpectraData(PlotData):
363
414
364 CODE = 'cspc'
415 CODE = 'cspc'
365 zmin_coh = None
416 zmin_coh = None
366 zmax_coh = None
417 zmax_coh = None
367 zmin_phase = None
418 zmin_phase = None
368 zmax_phase = None
419 zmax_phase = None
369 CONFLATE = False
370
420
371 def setup(self):
421 def setup(self):
372
422
373 ncolspan = 1
423 self.ncols = 4
374 colspan = 1
424 self.nrows = len(self.data.pairs)
375 self.ncols = 2
425 self.nplots = self.nrows*4
376 self.nrows = self.dataOut.nPairs
426 self.width = 3.4*self.ncols
377 self.width = 3.6*self.ncols
427 self.height = 3*self.nrows
378 self.height = 3.2*self.nrows
379
380 self.ylabel = 'Range [Km]'
428 self.ylabel = 'Range [Km]'
381 self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList]
429 self.showprofile = False
382
383 if self.figure is None:
384 self.figure = plt.figure(figsize=(self.width, self.height),
385 edgecolor='k',
386 facecolor='w')
387 else:
388 self.figure.clf()
389
390 for y in range(self.nrows):
391 for x in range(self.ncols):
392 ax = plt.subplot2grid((self.nrows, self.ncols), (y, x), 1, 1)
393 ax.firsttime = True
394 self.axes.append(ax)
395
430
396 def plot(self):
431 def plot(self):
397
432
398 if self.xaxis == "frequency":
433 if self.xaxis == "frequency":
399 x = self.dataOut.getFreqRange(1)/1000.
434 x = self.data.xrange[0]
400 xlabel = "Frequency (kHz)"
435 self.xlabel = "Frequency (kHz)"
401 elif self.xaxis == "time":
436 elif self.xaxis == "time":
402 x = self.dataOut.getAcfRange(1)
437 x = self.data.xrange[1]
403 xlabel = "Time (ms)"
438 self.xlabel = "Time (ms)"
404 else:
439 else:
405 x = self.dataOut.getVelRange(1)
440 x = self.data.xrange[2]
406 xlabel = "Velocity (m/s)"
441 self.xlabel = "Velocity (m/s)"
407
442
408 y = self.dataOut.getHeiRange()
443 self.titles = []
409 z_coh = self.data['cspc_coh']
444
410 z_phase = self.data['cspc_phase']
445 y = self.data.heights
446 self.y = y
447 spc = self.data['spc']
448 cspc = self.data['cspc']
411
449
412 for n in range(self.nrows):
450 for n in range(self.nrows):
413 ax = self.axes[2*n]
451 noise = self.data['noise'][n][-1]
414 ax1 = self.axes[2*n+1]
452 pair = self.data.pairs[n]
453 ax = self.axes[4*n]
454 ax3 = self.axes[4*n+3]
415 if ax.firsttime:
455 if ax.firsttime:
416 self.xmax = self.xmax if self.xmax else np.nanmax(x)
456 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
417 self.xmin = self.xmin if self.xmin else -self.xmax
457 self.xmin = self.xmin if self.xmin else -self.xmax
418 self.ymin = self.ymin if self.ymin else np.nanmin(y)
458 self.zmin = self.zmin if self.zmin else numpy.nanmin(spc)
419 self.ymax = self.ymax if self.ymax else np.nanmax(y)
459 self.zmax = self.zmax if self.zmax else numpy.nanmax(spc)
420 self.zmin_coh = self.zmin_coh if self.zmin_coh else 0.0
460 ax.plt = ax.pcolormesh(x, y, spc[pair[0]].T,
421 self.zmax_coh = self.zmax_coh if self.zmax_coh else 1.0
461 vmin=self.zmin,
422 self.zmin_phase = self.zmin_phase if self.zmin_phase else -180
462 vmax=self.zmax,
423 self.zmax_phase = self.zmax_phase if self.zmax_phase else 180
463 cmap=plt.get_cmap(self.colormap)
424
464 )
425 ax.plot = ax.pcolormesh(x, y, z_coh[n].T,
426 vmin=self.zmin_coh,
427 vmax=self.zmax_coh,
428 cmap=plt.get_cmap(self.colormap_coh)
429 )
430 divider = make_axes_locatable(ax)
431 cax = divider.new_horizontal(size='3%', pad=0.05)
432 self.figure.add_axes(cax)
433 plt.colorbar(ax.plot, cax)
434
435 ax.set_xlim(self.xmin, self.xmax)
436 ax.set_ylim(self.ymin, self.ymax)
437
438 ax.set_ylabel(self.ylabel)
439 ax.set_xlabel(xlabel)
440 ax.firsttime = False
441
442 ax1.plot = ax1.pcolormesh(x, y, z_phase[n].T,
443 vmin=self.zmin_phase,
444 vmax=self.zmax_phase,
445 cmap=plt.get_cmap(self.colormap_phase)
446 )
447 divider = make_axes_locatable(ax1)
448 cax = divider.new_horizontal(size='3%', pad=0.05)
449 self.figure.add_axes(cax)
450 plt.colorbar(ax1.plot, cax)
451
452 ax1.set_xlim(self.xmin, self.xmax)
453 ax1.set_ylim(self.ymin, self.ymax)
454
455 ax1.set_ylabel(self.ylabel)
456 ax1.set_xlabel(xlabel)
457 ax1.firsttime = False
458 else:
465 else:
459 ax.plot.set_array(z_coh[n].T.ravel())
466 ax.plt.set_array(spc[pair[0]].T.ravel())
460 ax1.plot.set_array(z_phase[n].T.ravel())
467 self.titles.append('CH {}: {:3.2f}dB'.format(n, noise))
461
462 ax.set_title('Coherence Ch{} * Ch{}'.format(self.dataOut.pairsList[n][0], self.dataOut.pairsList[n][1]), size=8)
463 ax1.set_title('Phase Ch{} * Ch{}'.format(self.dataOut.pairsList[n][0], self.dataOut.pairsList[n][1]), size=8)
464 self.saveTime = self.max_time
465
466
467 class PlotSpectraMeanData(PlotSpectraData):
468
468
469 CODE = 'spc_mean'
469 ax = self.axes[4*n+1]
470 colormap = 'jet'
470 if ax.firsttime:
471
471 ax.plt = ax.pcolormesh(x, y, spc[pair[1]].T,
472 def plot(self):
473
474 if self.xaxis == "frequency":
475 x = self.dataOut.getFreqRange(1)/1000.
476 xlabel = "Frequency (kHz)"
477 elif self.xaxis == "time":
478 x = self.dataOut.getAcfRange(1)
479 xlabel = "Time (ms)"
480 else:
481 x = self.dataOut.getVelRange(1)
482 xlabel = "Velocity (m/s)"
483
484 y = self.dataOut.getHeiRange()
485 z = self.data['spc']
486 mean = self.data['mean'][self.max_time]
487
488 for n, ax in enumerate(self.axes):
489
490 if ax.firsttime:
491 self.xmax = self.xmax if self.xmax else np.nanmax(x)
492 self.xmin = self.xmin if self.xmin else -self.xmax
493 self.ymin = self.ymin if self.ymin else np.nanmin(y)
494 self.ymax = self.ymax if self.ymax else np.nanmax(y)
495 self.zmin = self.zmin if self.zmin else np.nanmin(z)
496 self.zmax = self.zmax if self.zmax else np.nanmax(z)
497 ax.plt = ax.pcolormesh(x, y, z[n].T,
498 vmin=self.zmin,
472 vmin=self.zmin,
499 vmax=self.zmax,
473 vmax=self.zmax,
500 cmap=plt.get_cmap(self.colormap)
474 cmap=plt.get_cmap(self.colormap)
501 )
475 )
502 ax.plt_dop = ax.plot(mean[n], y,
503 color='k')[0]
504
505 divider = make_axes_locatable(ax)
506 cax = divider.new_horizontal(size='3%', pad=0.05)
507 self.figure.add_axes(cax)
508 plt.colorbar(ax.plt, cax)
509
510 ax.set_xlim(self.xmin, self.xmax)
511 ax.set_ylim(self.ymin, self.ymax)
512
513 ax.set_ylabel(self.ylabel)
514 ax.set_xlabel(xlabel)
515
516 ax.firsttime = False
517
518 if self.showprofile:
519 ax.plt_profile= ax.ax_profile.plot(self.data['rti'][self.max_time][n], y)[0]
520 ax.ax_profile.set_xlim(self.zmin, self.zmax)
521 ax.ax_profile.set_ylim(self.ymin, self.ymax)
522 ax.ax_profile.set_xlabel('dB')
523 ax.ax_profile.grid(b=True, axis='x')
524 ax.plt_noise = ax.ax_profile.plot(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y,
525 color="k", linestyle="dashed", lw=2)[0]
526 [tick.set_visible(False) for tick in ax.ax_profile.get_yticklabels()]
527 else:
476 else:
528 ax.plt.set_array(z[n].T.ravel())
477 ax.plt.set_array(spc[pair[1]].T.ravel())
529 ax.plt_dop.set_data(mean[n], y)
478 self.titles.append('CH {}: {:3.2f}dB'.format(n, noise))
530 if self.showprofile:
479
531 ax.plt_profile.set_data(self.data['rti'][self.max_time][n], y)
480 out = cspc[n]/numpy.sqrt(spc[pair[0]]*spc[pair[1]])
532 ax.plt_noise.set_data(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y)
481 coh = numpy.abs(out)
482 phase = numpy.arctan2(out.imag, out.real)*180/numpy.pi
483
484 ax = self.axes[4*n+2]
485 if ax.firsttime:
486 ax.plt = ax.pcolormesh(x, y, coh.T,
487 vmin=0,
488 vmax=1,
489 cmap=plt.get_cmap(self.colormap_coh)
490 )
491 else:
492 ax.plt.set_array(coh.T.ravel())
493 self.titles.append('Coherence Ch{} * Ch{}'.format(pair[0], pair[1]))
533
494
534 ax.set_title('{} - Noise: {:.2f} dB'.format(self.titles[n], self.data['noise'][self.max_time][n]),
495 ax = self.axes[4*n+3]
535 size=8)
496 if ax.firsttime:
497 ax.plt = ax.pcolormesh(x, y, phase.T,
498 vmin=-180,
499 vmax=180,
500 cmap=plt.get_cmap(self.colormap_phase)
501 )
502 else:
503 ax.plt.set_array(phase.T.ravel())
504 self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1]))
505
536 self.saveTime = self.max_time
506 self.saveTime = self.max_time
537
507
538
508
509 class PlotSpectraMeanData(PlotSpectraData):
510 '''
511 Plot for Spectra and Mean
512 '''
513 CODE = 'spc_mean'
514 colormap = 'jro'
515
516
539 class PlotRTIData(PlotData):
517 class PlotRTIData(PlotData):
518 '''
519 Plot for RTI data
520 '''
540
521
541 CODE = 'rti'
522 CODE = 'rti'
542 colormap = 'jro'
523 colormap = 'jro'
543
524
544 def setup(self):
525 def setup(self):
545 self.ncols = 1
526 self.xaxis = 'time'
546 self.nrows = self.dataOut.nChannels
527 self.ncols = 1
547 self.width = 10
528 self.nrows = len(self.data.channels)
548 #TODO : arreglar la altura de la figura, esta hardcodeada.
529 self.nplots = len(self.data.channels)
549 #Se arreglo, testear!
550 if self.ind_plt_ch:
551 self.height = 3.2#*self.nrows if self.nrows<6 else 12
552 else:
553 self.height = 2.2*self.nrows if self.nrows<6 else 12
554
555 '''
556 if self.nrows==1:
557 self.height += 1
558 '''
559 self.ylabel = 'Range [Km]'
530 self.ylabel = 'Range [Km]'
560 self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList]
531 self.cb_label = 'dB'
561
532 self.titles = ['{} Channel {}'.format(self.CODE.upper(), x) for x in range(self.nrows)]
562 '''
563 Logica:
564 1) Si la variable ind_plt_ch es True, va a crear mas de 1 figura
565 2) guardamos "Figures" en una lista y "axes" en otra, quizas se deberia guardar el
566 axis dentro de "Figures" como un diccionario.
567 '''
568 if self.ind_plt_ch is False: #standard mode
569
570 if self.figure is None: #solo para la priemra vez
571 self.figure = plt.figure(figsize=(self.width, self.height),
572 edgecolor='k',
573 facecolor='w')
574 else:
575 self.figure.clf()
576 self.axes = []
577
578
579 for n in range(self.nrows):
580 ax = self.figure.add_subplot(self.nrows, self.ncols, n+1)
581 #ax = self.figure(n+1)
582 ax.firsttime = True
583 self.axes.append(ax)
584
585 else : #append one figure foreach channel in channelList
586 if self.figurelist == None:
587 self.figurelist = []
588 for n in range(self.nrows):
589 self.figure = plt.figure(figsize=(self.width, self.height),
590 edgecolor='k',
591 facecolor='w')
592 #add always one subplot
593 self.figurelist.append(self.figure)
594
595 else : # cada dia nuevo limpia el axes, pero mantiene el figure
596 for eachfigure in self.figurelist:
597 eachfigure.clf() # eliminaria todas las figuras de la lista?
598 self.axes = []
599
600 for eachfigure in self.figurelist:
601 ax = eachfigure.add_subplot(1,1,1) #solo 1 axis por figura
602 #ax = self.figure(n+1)
603 ax.firsttime = True
604 #Cada figura tiene un distinto puntero
605 self.axes.append(ax)
606 #plt.close(eachfigure)
607
608
533
609 def plot(self):
534 def plot(self):
535 self.x = self.data.times
536 self.y = self.data.heights
537 self.z = self.data[self.CODE]
538 self.z = numpy.ma.masked_invalid(self.z)
610
539
611 if self.ind_plt_ch is False: #standard mode
540 for n, ax in enumerate(self.axes):
612 self.x = np.array(self.times)
541 x, y, z = self.fill_gaps(*self.decimate())
613 self.y = self.dataOut.getHeiRange()
542 self.zmin = self.zmin if self.zmin else numpy.min(self.z)
614 self.z = []
543 self.zmax = self.zmax if self.zmax else numpy.max(self.z)
615
544 if ax.firsttime:
616 for ch in range(self.nrows):
545 ax.plt = ax.pcolormesh(x, y, z[n].T,
617 self.z.append([self.data[self.CODE][t][ch] for t in self.times])
546 vmin=self.zmin,
618
547 vmax=self.zmax,
619 self.z = np.array(self.z)
548 cmap=plt.get_cmap(self.colormap)
620 for n, ax in enumerate(self.axes):
549 )
621 x, y, z = self.fill_gaps(*self.decimate())
550 if self.showprofile:
622 xmin = self.min_time
551 ax.plot_profile= self.pf_axes[n].plot(self.data['rti'][n][-1], self.y)[0]
623 xmax = xmin+self.xrange*60*60
552 ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(self.data['noise'][n][-1], len(self.y)), self.y,
624 self.zmin = self.zmin if self.zmin else np.min(self.z)
553 color="k", linestyle="dashed", lw=1)[0]
625 self.zmax = self.zmax if self.zmax else np.max(self.z)
554 else:
626 if ax.firsttime:
555 ax.collections.remove(ax.collections[0])
627 self.ymin = self.ymin if self.ymin else np.nanmin(self.y)
556 ax.plt = ax.pcolormesh(x, y, z[n].T,
628 self.ymax = self.ymax if self.ymax else np.nanmax(self.y)
557 vmin=self.zmin,
629 plot = ax.pcolormesh(x, y, z[n].T,
558 vmax=self.zmax,
630 vmin=self.zmin,
559 cmap=plt.get_cmap(self.colormap)
631 vmax=self.zmax,
560 )
632 cmap=plt.get_cmap(self.colormap)
561 if self.showprofile:
633 )
562 ax.plot_profile.set_data(self.data['rti'][n][-1], self.y)
634 divider = make_axes_locatable(ax)
563 ax.plot_noise.set_data(numpy.repeat(self.data['noise'][n][-1], len(self.y)), self.y)
635 cax = divider.new_horizontal(size='2%', pad=0.05)
636 self.figure.add_axes(cax)
637 plt.colorbar(plot, cax)
638 ax.set_ylim(self.ymin, self.ymax)
639 ax.xaxis.set_major_formatter(FuncFormatter(func))
640 ax.xaxis.set_major_locator(LinearLocator(6))
641 ax.set_ylabel(self.ylabel)
642 if self.xmin is None:
643 xmin = self.min_time
644 else:
645 xmin = (datetime.datetime.combine(self.dataOut.datatime.date(),
646 datetime.time(self.xmin, 0, 0))-d1970).total_seconds()
647 ax.set_xlim(xmin, xmax)
648 ax.firsttime = False
649 else:
650 ax.collections.remove(ax.collections[0])
651 ax.set_xlim(xmin, xmax)
652 plot = ax.pcolormesh(x, y, z[n].T,
653 vmin=self.zmin,
654 vmax=self.zmax,
655 cmap=plt.get_cmap(self.colormap)
656 )
657 ax.set_title('{} {}'.format(self.titles[n],
658 datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')),
659 size=8)
660
661 self.saveTime = self.min_time
662 else :
663 self.x = np.array(self.times)
664 self.y = self.dataOut.getHeiRange()
665 self.z = []
666
667 for ch in range(self.nrows):
668 self.z.append([self.data[self.CODE][t][ch] for t in self.times])
669
670 self.z = np.array(self.z)
671 for n, eachfigure in enumerate(self.figurelist): #estaba ax in axes
672
673 x, y, z = self.fill_gaps(*self.decimate())
674 xmin = self.min_time
675 xmax = xmin+self.xrange*60*60
676 self.zmin = self.zmin if self.zmin else np.min(self.z)
677 self.zmax = self.zmax if self.zmax else np.max(self.z)
678 if self.axes[n].firsttime:
679 self.ymin = self.ymin if self.ymin else np.nanmin(self.y)
680 self.ymax = self.ymax if self.ymax else np.nanmax(self.y)
681 plot = self.axes[n].pcolormesh(x, y, z[n].T,
682 vmin=self.zmin,
683 vmax=self.zmax,
684 cmap=plt.get_cmap(self.colormap)
685 )
686 divider = make_axes_locatable(self.axes[n])
687 cax = divider.new_horizontal(size='2%', pad=0.05)
688 eachfigure.add_axes(cax)
689 #self.figure2.add_axes(cax)
690 plt.colorbar(plot, cax)
691 self.axes[n].set_ylim(self.ymin, self.ymax)
692
693 self.axes[n].xaxis.set_major_formatter(FuncFormatter(func))
694 self.axes[n].xaxis.set_major_locator(LinearLocator(6))
695
696 self.axes[n].set_ylabel(self.ylabel)
697
698 if self.xmin is None:
699 xmin = self.min_time
700 else:
701 xmin = (datetime.datetime.combine(self.dataOut.datatime.date(),
702 datetime.time(self.xmin, 0, 0))-d1970).total_seconds()
703
704 self.axes[n].set_xlim(xmin, xmax)
705 self.axes[n].firsttime = False
706 else:
707 self.axes[n].collections.remove(self.axes[n].collections[0])
708 self.axes[n].set_xlim(xmin, xmax)
709 plot = self.axes[n].pcolormesh(x, y, z[n].T,
710 vmin=self.zmin,
711 vmax=self.zmax,
712 cmap=plt.get_cmap(self.colormap)
713 )
714 self.axes[n].set_title('{} {}'.format(self.titles[n],
715 datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')),
716 size=8)
717
564
718 self.saveTime = self.min_time
565 self.saveTime = self.min_time
719
566
720
567
721 class PlotCOHData(PlotRTIData):
568 class PlotCOHData(PlotRTIData):
569 '''
570 Plot for Coherence data
571 '''
722
572
723 CODE = 'coh'
573 CODE = 'coh'
724
574
725 def setup(self):
575 def setup(self):
726
576 self.xaxis = 'time'
727 self.ncols = 1
577 self.ncols = 1
728 self.nrows = self.dataOut.nPairs
578 self.nrows = len(self.data.pairs)
729 self.width = 10
579 self.nplots = len(self.data.pairs)
730 self.height = 2.2*self.nrows if self.nrows<6 else 12
580 self.ylabel = 'Range [Km]'
731 self.ind_plt_ch = False #just for coherence and phase
581 if self.CODE == 'coh':
732 if self.nrows==1:
582 self.cb_label = ''
733 self.height += 1
583 self.titles = ['Coherence Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
734 self.ylabel = 'Range [Km]'
735 self.titles = ['{} Ch{} * Ch{}'.format(self.CODE.upper(), x[0], x[1]) for x in self.dataOut.pairsList]
736
737 if self.figure is None:
738 self.figure = plt.figure(figsize=(self.width, self.height),
739 edgecolor='k',
740 facecolor='w')
741 else:
584 else:
742 self.figure.clf()
585 self.cb_label = 'Degrees'
743 self.axes = []
586 self.titles = ['Phase Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
744
587
745 for n in range(self.nrows):
588
746 ax = self.figure.add_subplot(self.nrows, self.ncols, n+1)
589 class PlotPHASEData(PlotCOHData):
747 ax.firsttime = True
590 '''
748 self.axes.append(ax)
591 Plot for Phase map data
592 '''
593
594 CODE = 'phase'
595 colormap = 'seismic'
749
596
750
597
751 class PlotNoiseData(PlotData):
598 class PlotNoiseData(PlotData):
599 '''
600 Plot for noise
601 '''
602
752 CODE = 'noise'
603 CODE = 'noise'
753
604
754 def setup(self):
605 def setup(self):
755
606 self.xaxis = 'time'
756 self.ncols = 1
607 self.ncols = 1
757 self.nrows = 1
608 self.nrows = 1
758 self.width = 10
609 self.nplots = 1
759 self.height = 3.2
760 self.ylabel = 'Intensity [dB]'
610 self.ylabel = 'Intensity [dB]'
761 self.titles = ['Noise']
611 self.titles = ['Noise']
762
612 self.colorbar = False
763 if self.figure is None:
764 self.figure = plt.figure(figsize=(self.width, self.height),
765 edgecolor='k',
766 facecolor='w')
767 else:
768 self.figure.clf()
769 self.axes = []
770
771 self.ax = self.figure.add_subplot(self.nrows, self.ncols, 1)
772 self.ax.firsttime = True
773
613
774 def plot(self):
614 def plot(self):
775
615
776 x = self.times
616 x = self.data.times
777 xmin = self.min_time
617 xmin = self.min_time
778 xmax = xmin+self.xrange*60*60
618 xmax = xmin+self.xrange*60*60
779 if self.ax.firsttime:
619 Y = self.data[self.CODE]
780 for ch in self.dataOut.channelList:
620
781 y = [self.data[self.CODE][t][ch] for t in self.times]
621 if self.axes[0].firsttime:
782 self.ax.plot(x, y, lw=1, label='Ch{}'.format(ch))
622 for ch in self.data.channels:
783 self.ax.firsttime = False
623 y = Y[ch]
784 self.ax.xaxis.set_major_formatter(FuncFormatter(func))
624 self.axes[0].plot(x, y, lw=1, label='Ch{}'.format(ch))
785 self.ax.xaxis.set_major_locator(LinearLocator(6))
786 self.ax.set_ylabel(self.ylabel)
787 plt.legend()
625 plt.legend()
788 else:
626 else:
789 for ch in self.dataOut.channelList:
627 for ch in self.data.channels:
790 y = [self.data[self.CODE][t][ch] for t in self.times]
628 y = Y[ch]
791 self.ax.lines[ch].set_data(x, y)
629 self.axes[0].lines[ch].set_data(x, y)
792
630
793 self.ax.set_xlim(xmin, xmax)
631 self.ymin = numpy.nanmin(Y) - 5
794 self.ax.set_ylim(min(y)-5, max(y)+5)
632 self.ymax = numpy.nanmax(Y) + 5
795 self.saveTime = self.min_time
633 self.saveTime = self.min_time
796
634
797
635
798 class PlotWindProfilerData(PlotRTIData):
799
800 CODE = 'wind'
801 colormap = 'seismic'
802
803 def setup(self):
804 self.ncols = 1
805 self.nrows = self.dataOut.data_output.shape[0]
806 self.width = 10
807 self.height = 2.2*self.nrows
808 self.ylabel = 'Height [Km]'
809 self.titles = ['Zonal Wind' ,'Meridional Wind', 'Vertical Wind']
810 self.clabels = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)']
811 self.windFactor = [1, 1, 100]
812
813 if self.figure is None:
814 self.figure = plt.figure(figsize=(self.width, self.height),
815 edgecolor='k',
816 facecolor='w')
817 else:
818 self.figure.clf()
819 self.axes = []
820
821 for n in range(self.nrows):
822 ax = self.figure.add_subplot(self.nrows, self.ncols, n+1)
823 ax.firsttime = True
824 self.axes.append(ax)
825
826 def plot(self):
827
828 self.x = np.array(self.times)
829 self.y = self.dataOut.heightList
830 self.z = []
831
832 for ch in range(self.nrows):
833 self.z.append([self.data['output'][t][ch] for t in self.times])
834
835 self.z = np.array(self.z)
836 self.z = numpy.ma.masked_invalid(self.z)
837
838 cmap=plt.get_cmap(self.colormap)
839 cmap.set_bad('black', 1.)
840
841 for n, ax in enumerate(self.axes):
842 x, y, z = self.fill_gaps(*self.decimate())
843 xmin = self.min_time
844 xmax = xmin+self.xrange*60*60
845 if ax.firsttime:
846 self.ymin = self.ymin if self.ymin else np.nanmin(self.y)
847 self.ymax = self.ymax if self.ymax else np.nanmax(self.y)
848 self.zmax = self.zmax if self.zmax else numpy.nanmax(abs(self.z[:-1, :]))
849 self.zmin = self.zmin if self.zmin else -self.zmax
850
851 plot = ax.pcolormesh(x, y, z[n].T*self.windFactor[n],
852 vmin=self.zmin,
853 vmax=self.zmax,
854 cmap=cmap
855 )
856 divider = make_axes_locatable(ax)
857 cax = divider.new_horizontal(size='2%', pad=0.05)
858 self.figure.add_axes(cax)
859 cb = plt.colorbar(plot, cax)
860 cb.set_label(self.clabels[n])
861 ax.set_ylim(self.ymin, self.ymax)
862
863 ax.xaxis.set_major_formatter(FuncFormatter(func))
864 ax.xaxis.set_major_locator(LinearLocator(6))
865
866 ax.set_ylabel(self.ylabel)
867
868 ax.set_xlim(xmin, xmax)
869 ax.firsttime = False
870 else:
871 ax.collections.remove(ax.collections[0])
872 ax.set_xlim(xmin, xmax)
873 plot = ax.pcolormesh(x, y, z[n].T*self.windFactor[n],
874 vmin=self.zmin,
875 vmax=self.zmax,
876 cmap=plt.get_cmap(self.colormap)
877 )
878 ax.set_title('{} {}'.format(self.titles[n],
879 datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')),
880 size=8)
881
882 self.saveTime = self.min_time
883
884
885 class PlotSNRData(PlotRTIData):
636 class PlotSNRData(PlotRTIData):
637 '''
638 Plot for SNR Data
639 '''
640
886 CODE = 'snr'
641 CODE = 'snr'
887 colormap = 'jet'
642 colormap = 'jet'
888
643
644
889 class PlotDOPData(PlotRTIData):
645 class PlotDOPData(PlotRTIData):
646 '''
647 Plot for DOPPLER Data
648 '''
649
890 CODE = 'dop'
650 CODE = 'dop'
891 colormap = 'jet'
651 colormap = 'jet'
892
652
893
653
894 class PlotPHASEData(PlotCOHData):
895 CODE = 'phase'
896 colormap = 'seismic'
897
898
899 class PlotSkyMapData(PlotData):
654 class PlotSkyMapData(PlotData):
655 '''
656 Plot for meteors detection data
657 '''
900
658
901 CODE = 'met'
659 CODE = 'met'
902
660
903 def setup(self):
661 def setup(self):
904
662
905 self.ncols = 1
663 self.ncols = 1
906 self.nrows = 1
664 self.nrows = 1
907 self.width = 7.2
665 self.width = 7.2
908 self.height = 7.2
666 self.height = 7.2
909
667
910 self.xlabel = 'Zonal Zenith Angle (deg)'
668 self.xlabel = 'Zonal Zenith Angle (deg)'
911 self.ylabel = 'Meridional Zenith Angle (deg)'
669 self.ylabel = 'Meridional Zenith Angle (deg)'
912
670
913 if self.figure is None:
671 if self.figure is None:
914 self.figure = plt.figure(figsize=(self.width, self.height),
672 self.figure = plt.figure(figsize=(self.width, self.height),
915 edgecolor='k',
673 edgecolor='k',
916 facecolor='w')
674 facecolor='w')
917 else:
675 else:
918 self.figure.clf()
676 self.figure.clf()
919
677
920 self.ax = plt.subplot2grid((self.nrows, self.ncols), (0, 0), 1, 1, polar=True)
678 self.ax = plt.subplot2grid((self.nrows, self.ncols), (0, 0), 1, 1, polar=True)
921 self.ax.firsttime = True
679 self.ax.firsttime = True
922
680
923
681
924 def plot(self):
682 def plot(self):
925
683
926 arrayParameters = np.concatenate([self.data['param'][t] for t in self.times])
684 arrayParameters = numpy.concatenate([self.data['param'][t] for t in self.data.times])
927 error = arrayParameters[:,-1]
685 error = arrayParameters[:,-1]
928 indValid = numpy.where(error == 0)[0]
686 indValid = numpy.where(error == 0)[0]
929 finalMeteor = arrayParameters[indValid,:]
687 finalMeteor = arrayParameters[indValid,:]
930 finalAzimuth = finalMeteor[:,3]
688 finalAzimuth = finalMeteor[:,3]
931 finalZenith = finalMeteor[:,4]
689 finalZenith = finalMeteor[:,4]
932
690
933 x = finalAzimuth*numpy.pi/180
691 x = finalAzimuth*numpy.pi/180
934 y = finalZenith
692 y = finalZenith
935
693
936 if self.ax.firsttime:
694 if self.ax.firsttime:
937 self.ax.plot = self.ax.plot(x, y, 'bo', markersize=5)[0]
695 self.ax.plot = self.ax.plot(x, y, 'bo', markersize=5)[0]
938 self.ax.set_ylim(0,90)
696 self.ax.set_ylim(0,90)
939 self.ax.set_yticks(numpy.arange(0,90,20))
697 self.ax.set_yticks(numpy.arange(0,90,20))
940 self.ax.set_xlabel(self.xlabel)
698 self.ax.set_xlabel(self.xlabel)
941 self.ax.set_ylabel(self.ylabel)
699 self.ax.set_ylabel(self.ylabel)
942 self.ax.yaxis.labelpad = 40
700 self.ax.yaxis.labelpad = 40
943 self.ax.firsttime = False
701 self.ax.firsttime = False
944 else:
702 else:
945 self.ax.plot.set_data(x, y)
703 self.ax.plot.set_data(x, y)
946
704
947
705
948 dt1 = datetime.datetime.fromtimestamp(self.min_time).strftime('%y/%m/%d %H:%M:%S')
706 dt1 = datetime.datetime.fromtimestamp(self.min_time).strftime('%y/%m/%d %H:%M:%S')
949 dt2 = datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')
707 dt2 = datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')
950 title = 'Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n' % (dt1,
708 title = 'Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n' % (dt1,
951 dt2,
709 dt2,
952 len(x))
710 len(x))
953 self.ax.set_title(title, size=8)
711 self.ax.set_title(title, size=8)
954
712
955 self.saveTime = self.max_time
713 self.saveTime = self.max_time
714
715 class PlotParamData(PlotRTIData):
716 '''
717 Plot for data_param object
718 '''
719
720 CODE = 'param'
721 colormap = 'seismic'
722
723 def setup(self):
724 self.xaxis = 'time'
725 self.ncols = 1
726 self.nrows = self.data.shape(self.CODE)[0]
727 self.nplots = self.nrows
728 if self.showSNR:
729 self.nrows += 1
730
731 self.ylabel = 'Height [Km]'
732 self.titles = self.data.parameters \
733 if self.data.parameters else ['Param {}'.format(x) for x in xrange(self.nrows)]
734 if self.showSNR:
735 self.titles.append('SNR')
736
737 def plot(self):
738 self.data.normalize_heights()
739 self.x = self.data.times
740 self.y = self.data.heights
741 if self.showSNR:
742 self.z = numpy.concatenate(
743 (self.data[self.CODE], self.data['snr'])
744 )
745 else:
746 self.z = self.data[self.CODE]
747
748 self.z = numpy.ma.masked_invalid(self.z)
749
750 for n, ax in enumerate(self.axes):
751
752 x, y, z = self.fill_gaps(*self.decimate())
753
754 if ax.firsttime:
755 if self.zlimits is not None:
756 self.zmin, self.zmax = self.zlimits[n]
757 self.zmax = self.zmax if self.zmax is not None else numpy.nanmax(abs(self.z[:-1, :]))
758 self.zmin = self.zmin if self.zmin is not None else -self.zmax
759 ax.plt = ax.pcolormesh(x, y, z[n, :, :].T*self.factors[n],
760 vmin=self.zmin,
761 vmax=self.zmax,
762 cmap=self.cmaps[n]
763 )
764 else:
765 if self.zlimits is not None:
766 self.zmin, self.zmax = self.zlimits[n]
767 ax.collections.remove(ax.collections[0])
768 ax.plt = ax.pcolormesh(x, y, z[n, :, :].T*self.factors[n],
769 vmin=self.zmin,
770 vmax=self.zmax,
771 cmap=self.cmaps[n]
772 )
773
774 self.saveTime = self.min_time
775
776 class PlotOuputData(PlotParamData):
777 '''
778 Plot data_output object
779 '''
780
781 CODE = 'output'
782 colormap = 'seismic' No newline at end of file
@@ -1,2154 +1,2154
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 FitGauPlot(Figure):
9 class FitGauPlot(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 = 'fitgau'
16 PREFIX = 'fitgau'
17
17
18 def __init__(self, **kwargs):
18 def __init__(self, **kwargs):
19 Figure.__init__(self, **kwargs)
19 Figure.__init__(self, **kwargs)
20 self.isConfig = False
20 self.isConfig = False
21 self.__nsubplots = 1
21 self.__nsubplots = 1
22
22
23 self.WIDTH = 250
23 self.WIDTH = 250
24 self.HEIGHT = 250
24 self.HEIGHT = 250
25 self.WIDTHPROF = 120
25 self.WIDTHPROF = 120
26 self.HEIGHTPROF = 0
26 self.HEIGHTPROF = 0
27 self.counter_imagwr = 0
27 self.counter_imagwr = 0
28
28
29 self.PLOT_CODE = SPEC_CODE
29 self.PLOT_CODE = SPEC_CODE
30
30
31 self.FTP_WEI = None
31 self.FTP_WEI = None
32 self.EXP_CODE = None
32 self.EXP_CODE = None
33 self.SUB_EXP_CODE = None
33 self.SUB_EXP_CODE = None
34 self.PLOT_POS = None
34 self.PLOT_POS = None
35
35
36 self.__xfilter_ena = False
36 self.__xfilter_ena = False
37 self.__yfilter_ena = False
37 self.__yfilter_ena = False
38
38
39 def getSubplots(self):
39 def getSubplots(self):
40
40
41 ncol = int(numpy.sqrt(self.nplots)+0.9)
41 ncol = int(numpy.sqrt(self.nplots)+0.9)
42 nrow = int(self.nplots*1./ncol + 0.9)
42 nrow = int(self.nplots*1./ncol + 0.9)
43
43
44 return nrow, ncol
44 return nrow, ncol
45
45
46 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
46 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
47
47
48 self.__showprofile = showprofile
48 self.__showprofile = showprofile
49 self.nplots = nplots
49 self.nplots = nplots
50
50
51 ncolspan = 1
51 ncolspan = 1
52 colspan = 1
52 colspan = 1
53 if showprofile:
53 if showprofile:
54 ncolspan = 3
54 ncolspan = 3
55 colspan = 2
55 colspan = 2
56 self.__nsubplots = 2
56 self.__nsubplots = 2
57
57
58 self.createFigure(id = id,
58 self.createFigure(id = id,
59 wintitle = wintitle,
59 wintitle = wintitle,
60 widthplot = self.WIDTH + self.WIDTHPROF,
60 widthplot = self.WIDTH + self.WIDTHPROF,
61 heightplot = self.HEIGHT + self.HEIGHTPROF,
61 heightplot = self.HEIGHT + self.HEIGHTPROF,
62 show=show)
62 show=show)
63
63
64 nrow, ncol = self.getSubplots()
64 nrow, ncol = self.getSubplots()
65
65
66 counter = 0
66 counter = 0
67 for y in range(nrow):
67 for y in range(nrow):
68 for x in range(ncol):
68 for x in range(ncol):
69
69
70 if counter >= self.nplots:
70 if counter >= self.nplots:
71 break
71 break
72
72
73 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
73 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
74
74
75 if showprofile:
75 if showprofile:
76 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
76 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
77
77
78 counter += 1
78 counter += 1
79
79
80 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
80 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
81 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
81 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
82 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
82 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
83 server=None, folder=None, username=None, password=None,
83 server=None, folder=None, username=None, password=None,
84 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
84 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
85 xaxis="frequency", colormap='jet', normFactor=None , GauSelector = 1):
85 xaxis="frequency", colormap='jet', normFactor=None , GauSelector = 1):
86
86
87 """
87 """
88
88
89 Input:
89 Input:
90 dataOut :
90 dataOut :
91 id :
91 id :
92 wintitle :
92 wintitle :
93 channelList :
93 channelList :
94 showProfile :
94 showProfile :
95 xmin : None,
95 xmin : None,
96 xmax : None,
96 xmax : None,
97 ymin : None,
97 ymin : None,
98 ymax : None,
98 ymax : None,
99 zmin : None,
99 zmin : None,
100 zmax : None
100 zmax : None
101 """
101 """
102 if realtime:
102 if realtime:
103 if not(isRealtime(utcdatatime = dataOut.utctime)):
103 if not(isRealtime(utcdatatime = dataOut.utctime)):
104 print 'Skipping this plot function'
104 print 'Skipping this plot function'
105 return
105 return
106
106
107 if channelList == None:
107 if channelList == None:
108 channelIndexList = dataOut.channelIndexList
108 channelIndexList = dataOut.channelIndexList
109 else:
109 else:
110 channelIndexList = []
110 channelIndexList = []
111 for channel in channelList:
111 for channel in channelList:
112 if channel not in dataOut.channelList:
112 if channel not in dataOut.channelList:
113 raise ValueError, "Channel %d is not in dataOut.channelList" %channel
113 raise ValueError, "Channel %d is not in dataOut.channelList" %channel
114 channelIndexList.append(dataOut.channelList.index(channel))
114 channelIndexList.append(dataOut.channelList.index(channel))
115
115
116 # if normFactor is None:
116 # if normFactor is None:
117 # factor = dataOut.normFactor
117 # factor = dataOut.normFactor
118 # else:
118 # else:
119 # factor = normFactor
119 # factor = normFactor
120 if xaxis == "frequency":
120 if xaxis == "frequency":
121 x = dataOut.spc_range[0]
121 x = dataOut.spc_range[0]
122 xlabel = "Frequency (kHz)"
122 xlabel = "Frequency (kHz)"
123
123
124 elif xaxis == "time":
124 elif xaxis == "time":
125 x = dataOut.spc_range[1]
125 x = dataOut.spc_range[1]
126 xlabel = "Time (ms)"
126 xlabel = "Time (ms)"
127
127
128 else:
128 else:
129 x = dataOut.spc_range[2]
129 x = dataOut.spc_range[2]
130 xlabel = "Velocity (m/s)"
130 xlabel = "Velocity (m/s)"
131
131
132 ylabel = "Range (Km)"
132 ylabel = "Range (Km)"
133
133
134 y = dataOut.getHeiRange()
134 y = dataOut.getHeiRange()
135
135
136 z = dataOut.GauSPC[:,GauSelector,:,:] #GauSelector] #dataOut.data_spc/factor
136 z = dataOut.GauSPC[:,GauSelector,:,:] #GauSelector] #dataOut.data_spc/factor
137 print 'GausSPC', z[0,32,10:40]
137 print 'GausSPC', z[0,32,10:40]
138 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
138 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
139 zdB = 10*numpy.log10(z)
139 zdB = 10*numpy.log10(z)
140
140
141 avg = numpy.average(z, axis=1)
141 avg = numpy.average(z, axis=1)
142 avgdB = 10*numpy.log10(avg)
142 avgdB = 10*numpy.log10(avg)
143
143
144 noise = dataOut.spc_noise
144 noise = dataOut.spc_noise
145 noisedB = 10*numpy.log10(noise)
145 noisedB = 10*numpy.log10(noise)
146
146
147 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
147 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
148 title = wintitle + " Spectra"
148 title = wintitle + " Spectra"
149 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
149 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
150 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
150 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
151
151
152 if not self.isConfig:
152 if not self.isConfig:
153
153
154 nplots = len(channelIndexList)
154 nplots = len(channelIndexList)
155
155
156 self.setup(id=id,
156 self.setup(id=id,
157 nplots=nplots,
157 nplots=nplots,
158 wintitle=wintitle,
158 wintitle=wintitle,
159 showprofile=showprofile,
159 showprofile=showprofile,
160 show=show)
160 show=show)
161
161
162 if xmin == None: xmin = numpy.nanmin(x)
162 if xmin == None: xmin = numpy.nanmin(x)
163 if xmax == None: xmax = numpy.nanmax(x)
163 if xmax == None: xmax = numpy.nanmax(x)
164 if ymin == None: ymin = numpy.nanmin(y)
164 if ymin == None: ymin = numpy.nanmin(y)
165 if ymax == None: ymax = numpy.nanmax(y)
165 if ymax == None: ymax = numpy.nanmax(y)
166 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
166 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
167 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
167 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
168
168
169 self.FTP_WEI = ftp_wei
169 self.FTP_WEI = ftp_wei
170 self.EXP_CODE = exp_code
170 self.EXP_CODE = exp_code
171 self.SUB_EXP_CODE = sub_exp_code
171 self.SUB_EXP_CODE = sub_exp_code
172 self.PLOT_POS = plot_pos
172 self.PLOT_POS = plot_pos
173
173
174 self.isConfig = True
174 self.isConfig = True
175
175
176 self.setWinTitle(title)
176 self.setWinTitle(title)
177
177
178 for i in range(self.nplots):
178 for i in range(self.nplots):
179 index = channelIndexList[i]
179 index = channelIndexList[i]
180 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
180 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
181 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime)
181 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime)
182 if len(dataOut.beam.codeList) != 0:
182 if len(dataOut.beam.codeList) != 0:
183 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)
183 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)
184
184
185 axes = self.axesList[i*self.__nsubplots]
185 axes = self.axesList[i*self.__nsubplots]
186 axes.pcolor(x, y, zdB[index,:,:],
186 axes.pcolor(x, y, zdB[index,:,:],
187 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
187 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
188 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
188 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
189 ticksize=9, cblabel='')
189 ticksize=9, cblabel='')
190
190
191 if self.__showprofile:
191 if self.__showprofile:
192 axes = self.axesList[i*self.__nsubplots +1]
192 axes = self.axesList[i*self.__nsubplots +1]
193 axes.pline(avgdB[index,:], y,
193 axes.pline(avgdB[index,:], y,
194 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
194 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
195 xlabel='dB', ylabel='', title='',
195 xlabel='dB', ylabel='', title='',
196 ytick_visible=False,
196 ytick_visible=False,
197 grid='x')
197 grid='x')
198
198
199 noiseline = numpy.repeat(noisedB[index], len(y))
199 noiseline = numpy.repeat(noisedB[index], len(y))
200 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
200 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
201
201
202 self.draw()
202 self.draw()
203
203
204 if figfile == None:
204 if figfile == None:
205 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
205 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
206 name = str_datetime
206 name = str_datetime
207 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
207 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
208 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
208 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
209 figfile = self.getFilename(name)
209 figfile = self.getFilename(name)
210
210
211 self.save(figpath=figpath,
211 self.save(figpath=figpath,
212 figfile=figfile,
212 figfile=figfile,
213 save=save,
213 save=save,
214 ftp=ftp,
214 ftp=ftp,
215 wr_period=wr_period,
215 wr_period=wr_period,
216 thisDatetime=thisDatetime)
216 thisDatetime=thisDatetime)
217
217
218
218
219
219
220 class MomentsPlot(Figure):
220 class MomentsPlot(Figure):
221
221
222 isConfig = None
222 isConfig = None
223 __nsubplots = None
223 __nsubplots = None
224
224
225 WIDTHPROF = None
225 WIDTHPROF = None
226 HEIGHTPROF = None
226 HEIGHTPROF = None
227 PREFIX = 'prm'
227 PREFIX = 'prm'
228
229 def __init__(self, **kwargs):
228 def __init__(self, **kwargs):
230 Figure.__init__(self, **kwargs)
229 Figure.__init__(self, **kwargs)
231 self.isConfig = False
230 self.isConfig = False
232 self.__nsubplots = 1
231 self.__nsubplots = 1
233
232
234 self.WIDTH = 280
233 self.WIDTH = 280
235 self.HEIGHT = 250
234 self.HEIGHT = 250
236 self.WIDTHPROF = 120
235 self.WIDTHPROF = 120
237 self.HEIGHTPROF = 0
236 self.HEIGHTPROF = 0
238 self.counter_imagwr = 0
237 self.counter_imagwr = 0
239
238
240 self.PLOT_CODE = MOMENTS_CODE
239 self.PLOT_CODE = MOMENTS_CODE
241
240
242 self.FTP_WEI = None
241 self.FTP_WEI = None
243 self.EXP_CODE = None
242 self.EXP_CODE = None
244 self.SUB_EXP_CODE = None
243 self.SUB_EXP_CODE = None
245 self.PLOT_POS = None
244 self.PLOT_POS = None
246
245
247 def getSubplots(self):
246 def getSubplots(self):
248
247
249 ncol = int(numpy.sqrt(self.nplots)+0.9)
248 ncol = int(numpy.sqrt(self.nplots)+0.9)
250 nrow = int(self.nplots*1./ncol + 0.9)
249 nrow = int(self.nplots*1./ncol + 0.9)
251
250
252 return nrow, ncol
251 return nrow, ncol
253
252
254 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
253 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
255
254
256 self.__showprofile = showprofile
255 self.__showprofile = showprofile
257 self.nplots = nplots
256 self.nplots = nplots
258
257
259 ncolspan = 1
258 ncolspan = 1
260 colspan = 1
259 colspan = 1
261 if showprofile:
260 if showprofile:
262 ncolspan = 3
261 ncolspan = 3
263 colspan = 2
262 colspan = 2
264 self.__nsubplots = 2
263 self.__nsubplots = 2
265
264
266 self.createFigure(id = id,
265 self.createFigure(id = id,
267 wintitle = wintitle,
266 wintitle = wintitle,
268 widthplot = self.WIDTH + self.WIDTHPROF,
267 widthplot = self.WIDTH + self.WIDTHPROF,
269 heightplot = self.HEIGHT + self.HEIGHTPROF,
268 heightplot = self.HEIGHT + self.HEIGHTPROF,
270 show=show)
269 show=show)
271
270
272 nrow, ncol = self.getSubplots()
271 nrow, ncol = self.getSubplots()
273
272
274 counter = 0
273 counter = 0
275 for y in range(nrow):
274 for y in range(nrow):
276 for x in range(ncol):
275 for x in range(ncol):
277
276
278 if counter >= self.nplots:
277 if counter >= self.nplots:
279 break
278 break
280
279
281 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
280 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
282
281
283 if showprofile:
282 if showprofile:
284 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
283 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
285
284
286 counter += 1
285 counter += 1
287
286
288 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
287 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
289 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
288 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
290 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
289 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
291 server=None, folder=None, username=None, password=None,
290 server=None, folder=None, username=None, password=None,
292 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
291 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
293
292
294 """
293 """
295
294
296 Input:
295 Input:
297 dataOut :
296 dataOut :
298 id :
297 id :
299 wintitle :
298 wintitle :
300 channelList :
299 channelList :
301 showProfile :
300 showProfile :
302 xmin : None,
301 xmin : None,
303 xmax : None,
302 xmax : None,
304 ymin : None,
303 ymin : None,
305 ymax : None,
304 ymax : None,
306 zmin : None,
305 zmin : None,
307 zmax : None
306 zmax : None
308 """
307 """
309
308
310 if dataOut.flagNoData:
309 if dataOut.flagNoData:
311 return None
310 return None
312
311
313 if realtime:
312 if realtime:
314 if not(isRealtime(utcdatatime = dataOut.utctime)):
313 if not(isRealtime(utcdatatime = dataOut.utctime)):
315 print 'Skipping this plot function'
314 print 'Skipping this plot function'
316 return
315 return
317
316
318 if channelList == None:
317 if channelList == None:
319 channelIndexList = dataOut.channelIndexList
318 channelIndexList = dataOut.channelIndexList
320 else:
319 else:
321 channelIndexList = []
320 channelIndexList = []
322 for channel in channelList:
321 for channel in channelList:
323 if channel not in dataOut.channelList:
322 if channel not in dataOut.channelList:
324 raise ValueError, "Channel %d is not in dataOut.channelList"
323 raise ValueError, "Channel %d is not in dataOut.channelList"
325 channelIndexList.append(dataOut.channelList.index(channel))
324 channelIndexList.append(dataOut.channelList.index(channel))
326
325
327 factor = dataOut.normFactor
326 factor = dataOut.normFactor
328 x = dataOut.abscissaList
327 x = dataOut.abscissaList
329 y = dataOut.heightList
328 y = dataOut.heightList
330
329
331 z = dataOut.data_pre[channelIndexList,:,:]/factor
330 z = dataOut.data_pre[channelIndexList,:,:]/factor
332 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
331 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
333 avg = numpy.average(z, axis=1)
332 avg = numpy.average(z, axis=1)
334 noise = dataOut.noise/factor
333 noise = dataOut.noise/factor
335
334
336 zdB = 10*numpy.log10(z)
335 zdB = 10*numpy.log10(z)
337 avgdB = 10*numpy.log10(avg)
336 avgdB = 10*numpy.log10(avg)
338 noisedB = 10*numpy.log10(noise)
337 noisedB = 10*numpy.log10(noise)
339
338
340 #thisDatetime = dataOut.datatime
339 #thisDatetime = dataOut.datatime
341 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
340 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
342 title = wintitle + " Parameters"
341 title = wintitle + " Parameters"
343 xlabel = "Velocity (m/s)"
342 xlabel = "Velocity (m/s)"
344 ylabel = "Range (Km)"
343 ylabel = "Range (Km)"
345
344
346 update_figfile = False
345 update_figfile = False
347
346
348 if not self.isConfig:
347 if not self.isConfig:
349
348
350 nplots = len(channelIndexList)
349 nplots = len(channelIndexList)
351
350
352 self.setup(id=id,
351 self.setup(id=id,
353 nplots=nplots,
352 nplots=nplots,
354 wintitle=wintitle,
353 wintitle=wintitle,
355 showprofile=showprofile,
354 showprofile=showprofile,
356 show=show)
355 show=show)
357
356
358 if xmin == None: xmin = numpy.nanmin(x)
357 if xmin == None: xmin = numpy.nanmin(x)
359 if xmax == None: xmax = numpy.nanmax(x)
358 if xmax == None: xmax = numpy.nanmax(x)
360 if ymin == None: ymin = numpy.nanmin(y)
359 if ymin == None: ymin = numpy.nanmin(y)
361 if ymax == None: ymax = numpy.nanmax(y)
360 if ymax == None: ymax = numpy.nanmax(y)
362 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
361 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
363 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
362 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
364
363
365 self.FTP_WEI = ftp_wei
364 self.FTP_WEI = ftp_wei
366 self.EXP_CODE = exp_code
365 self.EXP_CODE = exp_code
367 self.SUB_EXP_CODE = sub_exp_code
366 self.SUB_EXP_CODE = sub_exp_code
368 self.PLOT_POS = plot_pos
367 self.PLOT_POS = plot_pos
369
368
370 self.isConfig = True
369 self.isConfig = True
371 update_figfile = True
370 update_figfile = True
372
371
373 self.setWinTitle(title)
372 self.setWinTitle(title)
374
373
375 for i in range(self.nplots):
374 for i in range(self.nplots):
376 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
375 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
377 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i], noisedB[i], str_datetime)
376 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i], noisedB[i], str_datetime)
378 axes = self.axesList[i*self.__nsubplots]
377 axes = self.axesList[i*self.__nsubplots]
379 axes.pcolor(x, y, zdB[i,:,:],
378 axes.pcolor(x, y, zdB[i,:,:],
380 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
379 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
381 xlabel=xlabel, ylabel=ylabel, title=title,
380 xlabel=xlabel, ylabel=ylabel, title=title,
382 ticksize=9, cblabel='')
381 ticksize=9, cblabel='')
383 #Mean Line
382 #Mean Line
384 mean = dataOut.data_param[i, 1, :]
383 mean = dataOut.data_param[i, 1, :]
385 axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1)
384 axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1)
386
385
387 if self.__showprofile:
386 if self.__showprofile:
388 axes = self.axesList[i*self.__nsubplots +1]
387 axes = self.axesList[i*self.__nsubplots +1]
389 axes.pline(avgdB[i], y,
388 axes.pline(avgdB[i], y,
390 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
389 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
391 xlabel='dB', ylabel='', title='',
390 xlabel='dB', ylabel='', title='',
392 ytick_visible=False,
391 ytick_visible=False,
393 grid='x')
392 grid='x')
394
393
395 noiseline = numpy.repeat(noisedB[i], len(y))
394 noiseline = numpy.repeat(noisedB[i], len(y))
396 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
395 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
397
396
398 self.draw()
397 self.draw()
399
398
400 self.save(figpath=figpath,
399 self.save(figpath=figpath,
401 figfile=figfile,
400 figfile=figfile,
402 save=save,
401 save=save,
403 ftp=ftp,
402 ftp=ftp,
404 wr_period=wr_period,
403 wr_period=wr_period,
405 thisDatetime=thisDatetime)
404 thisDatetime=thisDatetime)
406
405
407
406
408
407
409 class SkyMapPlot(Figure):
408 class SkyMapPlot(Figure):
410
409
411 __isConfig = None
410 __isConfig = None
412 __nsubplots = None
411 __nsubplots = None
413
412
414 WIDTHPROF = None
413 WIDTHPROF = None
415 HEIGHTPROF = None
414 HEIGHTPROF = None
416 PREFIX = 'mmap'
415 PREFIX = 'mmap'
417
416
418 def __init__(self, **kwargs):
417 def __init__(self, **kwargs):
419 Figure.__init__(self, **kwargs)
418 Figure.__init__(self, **kwargs)
420 self.isConfig = False
419 self.isConfig = False
421 self.__nsubplots = 1
420 self.__nsubplots = 1
422
421
423 # self.WIDTH = 280
422 # self.WIDTH = 280
424 # self.HEIGHT = 250
423 # self.HEIGHT = 250
425 self.WIDTH = 600
424 self.WIDTH = 600
426 self.HEIGHT = 600
425 self.HEIGHT = 600
427 self.WIDTHPROF = 120
426 self.WIDTHPROF = 120
428 self.HEIGHTPROF = 0
427 self.HEIGHTPROF = 0
429 self.counter_imagwr = 0
428 self.counter_imagwr = 0
430
429
431 self.PLOT_CODE = MSKYMAP_CODE
430 self.PLOT_CODE = MSKYMAP_CODE
432
431
433 self.FTP_WEI = None
432 self.FTP_WEI = None
434 self.EXP_CODE = None
433 self.EXP_CODE = None
435 self.SUB_EXP_CODE = None
434 self.SUB_EXP_CODE = None
436 self.PLOT_POS = None
435 self.PLOT_POS = None
437
436
438 def getSubplots(self):
437 def getSubplots(self):
439
438
440 ncol = int(numpy.sqrt(self.nplots)+0.9)
439 ncol = int(numpy.sqrt(self.nplots)+0.9)
441 nrow = int(self.nplots*1./ncol + 0.9)
440 nrow = int(self.nplots*1./ncol + 0.9)
442
441
443 return nrow, ncol
442 return nrow, ncol
444
443
445 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
444 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
446
445
447 self.__showprofile = showprofile
446 self.__showprofile = showprofile
448 self.nplots = nplots
447 self.nplots = nplots
449
448
450 ncolspan = 1
449 ncolspan = 1
451 colspan = 1
450 colspan = 1
452
451
453 self.createFigure(id = id,
452 self.createFigure(id = id,
454 wintitle = wintitle,
453 wintitle = wintitle,
455 widthplot = self.WIDTH, #+ self.WIDTHPROF,
454 widthplot = self.WIDTH, #+ self.WIDTHPROF,
456 heightplot = self.HEIGHT,# + self.HEIGHTPROF,
455 heightplot = self.HEIGHT,# + self.HEIGHTPROF,
457 show=show)
456 show=show)
458
457
459 nrow, ncol = 1,1
458 nrow, ncol = 1,1
460 counter = 0
459 counter = 0
461 x = 0
460 x = 0
462 y = 0
461 y = 0
463 self.addAxes(1, 1, 0, 0, 1, 1, True)
462 self.addAxes(1, 1, 0, 0, 1, 1, True)
464
463
465 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
464 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
466 tmin=0, tmax=24, timerange=None,
465 tmin=0, tmax=24, timerange=None,
467 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
466 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
468 server=None, folder=None, username=None, password=None,
467 server=None, folder=None, username=None, password=None,
469 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
468 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
470
469
471 """
470 """
472
471
473 Input:
472 Input:
474 dataOut :
473 dataOut :
475 id :
474 id :
476 wintitle :
475 wintitle :
477 channelList :
476 channelList :
478 showProfile :
477 showProfile :
479 xmin : None,
478 xmin : None,
480 xmax : None,
479 xmax : None,
481 ymin : None,
480 ymin : None,
482 ymax : None,
481 ymax : None,
483 zmin : None,
482 zmin : None,
484 zmax : None
483 zmax : None
485 """
484 """
486
485
487 arrayParameters = dataOut.data_param
486 arrayParameters = dataOut.data_param
488 error = arrayParameters[:,-1]
487 error = arrayParameters[:,-1]
489 indValid = numpy.where(error == 0)[0]
488 indValid = numpy.where(error == 0)[0]
490 finalMeteor = arrayParameters[indValid,:]
489 finalMeteor = arrayParameters[indValid,:]
491 finalAzimuth = finalMeteor[:,3]
490 finalAzimuth = finalMeteor[:,3]
492 finalZenith = finalMeteor[:,4]
491 finalZenith = finalMeteor[:,4]
493
492
494 x = finalAzimuth*numpy.pi/180
493 x = finalAzimuth*numpy.pi/180
495 y = finalZenith
494 y = finalZenith
496 x1 = [dataOut.ltctime, dataOut.ltctime]
495 x1 = [dataOut.ltctime, dataOut.ltctime]
497
496
498 #thisDatetime = dataOut.datatime
497 #thisDatetime = dataOut.datatime
499 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
498 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
500 title = wintitle + " Parameters"
499 title = wintitle + " Parameters"
501 xlabel = "Zonal Zenith Angle (deg) "
500 xlabel = "Zonal Zenith Angle (deg) "
502 ylabel = "Meridional Zenith Angle (deg)"
501 ylabel = "Meridional Zenith Angle (deg)"
503 update_figfile = False
502 update_figfile = False
504
503
505 if not self.isConfig:
504 if not self.isConfig:
506
505
507 nplots = 1
506 nplots = 1
508
507
509 self.setup(id=id,
508 self.setup(id=id,
510 nplots=nplots,
509 nplots=nplots,
511 wintitle=wintitle,
510 wintitle=wintitle,
512 showprofile=showprofile,
511 showprofile=showprofile,
513 show=show)
512 show=show)
514
513
515 if self.xmin is None and self.xmax is None:
514 if self.xmin is None and self.xmax is None:
516 self.xmin, self.xmax = self.getTimeLim(x1, tmin, tmax, timerange)
515 self.xmin, self.xmax = self.getTimeLim(x1, tmin, tmax, timerange)
517
516
518 if timerange != None:
517 if timerange != None:
519 self.timerange = timerange
518 self.timerange = timerange
520 else:
519 else:
521 self.timerange = self.xmax - self.xmin
520 self.timerange = self.xmax - self.xmin
522
521
523 self.FTP_WEI = ftp_wei
522 self.FTP_WEI = ftp_wei
524 self.EXP_CODE = exp_code
523 self.EXP_CODE = exp_code
525 self.SUB_EXP_CODE = sub_exp_code
524 self.SUB_EXP_CODE = sub_exp_code
526 self.PLOT_POS = plot_pos
525 self.PLOT_POS = plot_pos
527 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
526 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
528 self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
527 self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
529 self.isConfig = True
528 self.isConfig = True
530 update_figfile = True
529 update_figfile = True
531
530
532 self.setWinTitle(title)
531 self.setWinTitle(title)
533
532
534 i = 0
533 i = 0
535 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
534 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
536
535
537 axes = self.axesList[i*self.__nsubplots]
536 axes = self.axesList[i*self.__nsubplots]
538 nevents = axes.x_buffer.shape[0] + x.shape[0]
537 nevents = axes.x_buffer.shape[0] + x.shape[0]
539 title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents)
538 title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents)
540 axes.polar(x, y,
539 axes.polar(x, y,
541 title=title, xlabel=xlabel, ylabel=ylabel,
540 title=title, xlabel=xlabel, ylabel=ylabel,
542 ticksize=9, cblabel='')
541 ticksize=9, cblabel='')
543
542
544 self.draw()
543 self.draw()
545
544
546 self.save(figpath=figpath,
545 self.save(figpath=figpath,
547 figfile=figfile,
546 figfile=figfile,
548 save=save,
547 save=save,
549 ftp=ftp,
548 ftp=ftp,
550 wr_period=wr_period,
549 wr_period=wr_period,
551 thisDatetime=thisDatetime,
550 thisDatetime=thisDatetime,
552 update_figfile=update_figfile)
551 update_figfile=update_figfile)
553
552
554 if dataOut.ltctime >= self.xmax:
553 if dataOut.ltctime >= self.xmax:
555 self.isConfigmagwr = wr_period
554 self.isConfigmagwr = wr_period
556 self.isConfig = False
555 self.isConfig = False
557 update_figfile = True
556 update_figfile = True
558 axes.__firsttime = True
557 axes.__firsttime = True
559 self.xmin += self.timerange
558 self.xmin += self.timerange
560 self.xmax += self.timerange
559 self.xmax += self.timerange
561
560
562
561
563
562
564
563
565 class WindProfilerPlot(Figure):
564 class WindProfilerPlot(Figure):
566
565
567 __isConfig = None
566 __isConfig = None
568 __nsubplots = None
567 __nsubplots = None
569
568
570 WIDTHPROF = None
569 WIDTHPROF = None
571 HEIGHTPROF = None
570 HEIGHTPROF = None
572 PREFIX = 'wind'
571 PREFIX = 'wind'
573
572
574 def __init__(self, **kwargs):
573 def __init__(self, **kwargs):
575 Figure.__init__(self, **kwargs)
574 Figure.__init__(self, **kwargs)
576 self.timerange = None
575 self.timerange = None
577 self.isConfig = False
576 self.isConfig = False
578 self.__nsubplots = 1
577 self.__nsubplots = 1
579
578
580 self.WIDTH = 800
579 self.WIDTH = 800
581 self.HEIGHT = 300
580 self.HEIGHT = 300
582 self.WIDTHPROF = 120
581 self.WIDTHPROF = 120
583 self.HEIGHTPROF = 0
582 self.HEIGHTPROF = 0
584 self.counter_imagwr = 0
583 self.counter_imagwr = 0
585
584
586 self.PLOT_CODE = WIND_CODE
585 self.PLOT_CODE = WIND_CODE
587
586
588 self.FTP_WEI = None
587 self.FTP_WEI = None
589 self.EXP_CODE = None
588 self.EXP_CODE = None
590 self.SUB_EXP_CODE = None
589 self.SUB_EXP_CODE = None
591 self.PLOT_POS = None
590 self.PLOT_POS = None
592 self.tmin = None
591 self.tmin = None
593 self.tmax = None
592 self.tmax = None
594
593
595 self.xmin = None
594 self.xmin = None
596 self.xmax = None
595 self.xmax = None
597
596
598 self.figfile = None
597 self.figfile = None
599
598
600 def getSubplots(self):
599 def getSubplots(self):
601
600
602 ncol = 1
601 ncol = 1
603 nrow = self.nplots
602 nrow = self.nplots
604
603
605 return nrow, ncol
604 return nrow, ncol
606
605
607 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
606 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
608
607
609 self.__showprofile = showprofile
608 self.__showprofile = showprofile
610 self.nplots = nplots
609 self.nplots = nplots
611
610
612 ncolspan = 1
611 ncolspan = 1
613 colspan = 1
612 colspan = 1
614
613
615 self.createFigure(id = id,
614 self.createFigure(id = id,
616 wintitle = wintitle,
615 wintitle = wintitle,
617 widthplot = self.WIDTH + self.WIDTHPROF,
616 widthplot = self.WIDTH + self.WIDTHPROF,
618 heightplot = self.HEIGHT + self.HEIGHTPROF,
617 heightplot = self.HEIGHT + self.HEIGHTPROF,
619 show=show)
618 show=show)
620
619
621 nrow, ncol = self.getSubplots()
620 nrow, ncol = self.getSubplots()
622
621
623 counter = 0
622 counter = 0
624 for y in range(nrow):
623 for y in range(nrow):
625 if counter >= self.nplots:
624 if counter >= self.nplots:
626 break
625 break
627
626
628 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
627 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
629 counter += 1
628 counter += 1
630
629
631 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='False',
630 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='False',
632 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
631 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
633 zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None,
632 zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None,
634 timerange=None, SNRthresh = None,
633 timerange=None, SNRthresh = None,
635 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
634 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
636 server=None, folder=None, username=None, password=None,
635 server=None, folder=None, username=None, password=None,
637 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
636 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
638 """
637 """
639
638
640 Input:
639 Input:
641 dataOut :
640 dataOut :
642 id :
641 id :
643 wintitle :
642 wintitle :
644 channelList :
643 channelList :
645 showProfile :
644 showProfile :
646 xmin : None,
645 xmin : None,
647 xmax : None,
646 xmax : None,
648 ymin : None,
647 ymin : None,
649 ymax : None,
648 ymax : None,
650 zmin : None,
649 zmin : None,
651 zmax : None
650 zmax : None
652 """
651 """
653
652
654 # if timerange is not None:
653 # if timerange is not None:
655 # self.timerange = timerange
654 # self.timerange = timerange
656 #
655 #
657 # tmin = None
656 # tmin = None
658 # tmax = None
657 # tmax = None
659
658
660 x = dataOut.getTimeRange1(dataOut.paramInterval)
659 x = dataOut.getTimeRange1(dataOut.paramInterval)
661 y = dataOut.heightList
660 y = dataOut.heightList
662 z = dataOut.data_output.copy()
661 z = dataOut.data_output.copy()
663 nplots = z.shape[0] #Number of wind dimensions estimated
662 nplots = z.shape[0] #Number of wind dimensions estimated
664 nplotsw = nplots
663 nplotsw = nplots
665
664
666
665
667 #If there is a SNR function defined
666 #If there is a SNR function defined
668 if dataOut.data_SNR is not None:
667 if dataOut.data_SNR is not None:
669 nplots += 1
668 nplots += 1
670 SNR = dataOut.data_SNR
669 SNR = dataOut.data_SNR
671 SNRavg = numpy.average(SNR, axis=0)
670 SNRavg = numpy.average(SNR, axis=0)
672
671
673 SNRdB = 10*numpy.log10(SNR)
672 SNRdB = 10*numpy.log10(SNR)
674 SNRavgdB = 10*numpy.log10(SNRavg)
673 SNRavgdB = 10*numpy.log10(SNRavg)
675
674
676 if SNRthresh == None: SNRthresh = -5.0
675 if SNRthresh == None: SNRthresh = -5.0
677 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
676 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
678
677
679 for i in range(nplotsw):
678 for i in range(nplotsw):
680 z[i,ind] = numpy.nan
679 z[i,ind] = numpy.nan
681
680
682 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
681 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
683 #thisDatetime = datetime.datetime.now()
682 #thisDatetime = datetime.datetime.now()
684 title = wintitle + "Wind"
683 title = wintitle + "Wind"
685 xlabel = ""
684 xlabel = ""
686 ylabel = "Height (km)"
685 ylabel = "Height (km)"
687 update_figfile = False
686 update_figfile = False
688
687
689 if not self.isConfig:
688 if not self.isConfig:
690
689
691 self.setup(id=id,
690 self.setup(id=id,
692 nplots=nplots,
691 nplots=nplots,
693 wintitle=wintitle,
692 wintitle=wintitle,
694 showprofile=showprofile,
693 showprofile=showprofile,
695 show=show)
694 show=show)
696
695
697 if timerange is not None:
696 if timerange is not None:
698 self.timerange = timerange
697 self.timerange = timerange
699
698
700 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
699 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
701
700
702 if ymin == None: ymin = numpy.nanmin(y)
701 if ymin == None: ymin = numpy.nanmin(y)
703 if ymax == None: ymax = numpy.nanmax(y)
702 if ymax == None: ymax = numpy.nanmax(y)
704
703
705 if zmax == None: zmax = numpy.nanmax(abs(z[range(2),:]))
704 if zmax == None: zmax = numpy.nanmax(abs(z[range(2),:]))
706 #if numpy.isnan(zmax): zmax = 50
705 #if numpy.isnan(zmax): zmax = 50
707 if zmin == None: zmin = -zmax
706 if zmin == None: zmin = -zmax
708
707
709 if nplotsw == 3:
708 if nplotsw == 3:
710 if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:]))
709 if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:]))
711 if zmin_ver == None: zmin_ver = -zmax_ver
710 if zmin_ver == None: zmin_ver = -zmax_ver
712
711
713 if dataOut.data_SNR is not None:
712 if dataOut.data_SNR is not None:
714 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
713 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
715 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
714 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
716
715
717
716
718 self.FTP_WEI = ftp_wei
717 self.FTP_WEI = ftp_wei
719 self.EXP_CODE = exp_code
718 self.EXP_CODE = exp_code
720 self.SUB_EXP_CODE = sub_exp_code
719 self.SUB_EXP_CODE = sub_exp_code
721 self.PLOT_POS = plot_pos
720 self.PLOT_POS = plot_pos
722
721
723 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
722 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
724 self.isConfig = True
723 self.isConfig = True
725 self.figfile = figfile
724 self.figfile = figfile
726 update_figfile = True
725 update_figfile = True
727
726
728 self.setWinTitle(title)
727 self.setWinTitle(title)
729
728
730 if ((self.xmax - x[1]) < (x[1]-x[0])):
729 if ((self.xmax - x[1]) < (x[1]-x[0])):
731 x[1] = self.xmax
730 x[1] = self.xmax
732
731
733 strWind = ['Zonal', 'Meridional', 'Vertical']
732 strWind = ['Zonal', 'Meridional', 'Vertical']
734 strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)']
733 strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)']
735 zmaxVector = [zmax, zmax, zmax_ver]
734 zmaxVector = [zmax, zmax, zmax_ver]
736 zminVector = [zmin, zmin, zmin_ver]
735 zminVector = [zmin, zmin, zmin_ver]
737 windFactor = [1,1,100]
736 windFactor = [1,1,100]
738
737
739 for i in range(nplotsw):
738 for i in range(nplotsw):
740
739
741 title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
740 title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
742 axes = self.axesList[i*self.__nsubplots]
741 axes = self.axesList[i*self.__nsubplots]
743
742
744 z1 = z[i,:].reshape((1,-1))*windFactor[i]
743 z1 = z[i,:].reshape((1,-1))*windFactor[i]
745 #z1=numpy.ma.masked_where(z1==0.,z1)
744 #z1=numpy.ma.masked_where(z1==0.,z1)
746
745
747 axes.pcolorbuffer(x, y, z1,
746 axes.pcolorbuffer(x, y, z1,
748 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
747 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
749 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
748 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
750 ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="seismic" )
749 ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="seismic" )
751
750
752 if dataOut.data_SNR is not None:
751 if dataOut.data_SNR is not None:
753 i += 1
752 i += 1
754 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
753 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
755 axes = self.axesList[i*self.__nsubplots]
754 axes = self.axesList[i*self.__nsubplots]
756 SNRavgdB = SNRavgdB.reshape((1,-1))
755 SNRavgdB = SNRavgdB.reshape((1,-1))
757 axes.pcolorbuffer(x, y, SNRavgdB,
756 axes.pcolorbuffer(x, y, SNRavgdB,
758 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
757 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
759 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
758 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
760 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
759 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
761
760
762 self.draw()
761 self.draw()
763
762
764 self.save(figpath=figpath,
763 self.save(figpath=figpath,
765 figfile=figfile,
764 figfile=figfile,
766 save=save,
765 save=save,
767 ftp=ftp,
766 ftp=ftp,
768 wr_period=wr_period,
767 wr_period=wr_period,
769 thisDatetime=thisDatetime,
768 thisDatetime=thisDatetime,
770 update_figfile=update_figfile)
769 update_figfile=update_figfile)
771
770
772 if dataOut.ltctime + dataOut.paramInterval >= self.xmax:
771 if dataOut.ltctime + dataOut.paramInterval >= self.xmax:
773 self.counter_imagwr = wr_period
772 self.counter_imagwr = wr_period
774 self.isConfig = False
773 self.isConfig = False
775 update_figfile = True
774 update_figfile = True
776
775
777
776
778 class ParametersPlot(Figure):
777 class ParametersPlot(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 = 'param'
784 PREFIX = 'param'
786
785
787 nplots = None
786 nplots = None
788 nchan = None
787 nchan = None
789
788
790 def __init__(self, **kwargs):
789 def __init__(self, **kwargs):
791 Figure.__init__(self, **kwargs)
790 Figure.__init__(self, **kwargs)
792 self.timerange = None
791 self.timerange = None
793 self.isConfig = False
792 self.isConfig = False
794 self.__nsubplots = 1
793 self.__nsubplots = 1
795
794
796 self.WIDTH = 800
795 self.WIDTH = 800
797 self.HEIGHT = 180
796 self.HEIGHT = 180
798 self.WIDTHPROF = 120
797 self.WIDTHPROF = 120
799 self.HEIGHTPROF = 0
798 self.HEIGHTPROF = 0
800 self.counter_imagwr = 0
799 self.counter_imagwr = 0
801
800
802 self.PLOT_CODE = RTI_CODE
801 self.PLOT_CODE = RTI_CODE
803
802
804 self.FTP_WEI = None
803 self.FTP_WEI = None
805 self.EXP_CODE = None
804 self.EXP_CODE = None
806 self.SUB_EXP_CODE = None
805 self.SUB_EXP_CODE = None
807 self.PLOT_POS = None
806 self.PLOT_POS = None
808 self.tmin = None
807 self.tmin = None
809 self.tmax = None
808 self.tmax = None
810
809
811 self.xmin = None
810 self.xmin = None
812 self.xmax = None
811 self.xmax = None
813
812
814 self.figfile = None
813 self.figfile = None
815
814
816 def getSubplots(self):
815 def getSubplots(self):
817
816
818 ncol = 1
817 ncol = 1
819 nrow = self.nplots
818 nrow = self.nplots
820
819
821 return nrow, ncol
820 return nrow, ncol
822
821
823 def setup(self, id, nplots, wintitle, show=True):
822 def setup(self, id, nplots, wintitle, show=True):
824
823
825 self.nplots = nplots
824 self.nplots = nplots
826
825
827 ncolspan = 1
826 ncolspan = 1
828 colspan = 1
827 colspan = 1
829
828
830 self.createFigure(id = id,
829 self.createFigure(id = id,
831 wintitle = wintitle,
830 wintitle = wintitle,
832 widthplot = self.WIDTH + self.WIDTHPROF,
831 widthplot = self.WIDTH + self.WIDTHPROF,
833 heightplot = self.HEIGHT + self.HEIGHTPROF,
832 heightplot = self.HEIGHT + self.HEIGHTPROF,
834 show=show)
833 show=show)
835
834
836 nrow, ncol = self.getSubplots()
835 nrow, ncol = self.getSubplots()
837
836
838 counter = 0
837 counter = 0
839 for y in range(nrow):
838 for y in range(nrow):
840 for x in range(ncol):
839 for x in range(ncol):
841
840
842 if counter >= self.nplots:
841 if counter >= self.nplots:
843 break
842 break
844
843
845 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
844 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
846
845
847 counter += 1
846 counter += 1
848
847
849 def run(self, dataOut, id, wintitle="", channelList=None, paramIndex = 0, colormap="jet",
848 def run(self, dataOut, id, wintitle="", channelList=None, paramIndex = 0, colormap="jet",
850 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, timerange=None,
849 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, timerange=None,
851 showSNR=False, SNRthresh = -numpy.inf, SNRmin=None, SNRmax=None,
850 showSNR=False, SNRthresh = -numpy.inf, SNRmin=None, SNRmax=None,
852 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
851 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
853 server=None, folder=None, username=None, password=None,
852 server=None, folder=None, username=None, password=None,
854 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, HEIGHT=None):
853 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, HEIGHT=None):
855 """
854 """
856
855
857 Input:
856 Input:
858 dataOut :
857 dataOut :
859 id :
858 id :
860 wintitle :
859 wintitle :
861 channelList :
860 channelList :
862 showProfile :
861 showProfile :
863 xmin : None,
862 xmin : None,
864 xmax : None,
863 xmax : None,
865 ymin : None,
864 ymin : None,
866 ymax : None,
865 ymax : None,
867 zmin : None,
866 zmin : None,
868 zmax : None
867 zmax : None
869 """
868 """
870
869
871 if HEIGHT is not None:
870 if HEIGHT is not None:
872 self.HEIGHT = HEIGHT
871 self.HEIGHT = HEIGHT
873
872
874
873
875 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
874 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
876 return
875 return
877
876
878 if channelList == None:
877 if channelList == None:
879 channelIndexList = range(dataOut.data_param.shape[0])
878 channelIndexList = range(dataOut.data_param.shape[0])
880 else:
879 else:
881 channelIndexList = []
880 channelIndexList = []
882 for channel in channelList:
881 for channel in channelList:
883 if channel not in dataOut.channelList:
882 if channel not in dataOut.channelList:
884 raise ValueError, "Channel %d is not in dataOut.channelList"
883 raise ValueError, "Channel %d is not in dataOut.channelList"
885 channelIndexList.append(dataOut.channelList.index(channel))
884 channelIndexList.append(dataOut.channelList.index(channel))
886
885
887 x = dataOut.getTimeRange1(dataOut.paramInterval)
886 x = dataOut.getTimeRange1(dataOut.paramInterval)
888 y = dataOut.getHeiRange()
887 y = dataOut.getHeiRange()
889
888
890 if dataOut.data_param.ndim == 3:
889 if dataOut.data_param.ndim == 3:
891 z = dataOut.data_param[channelIndexList,paramIndex,:]
890 z = dataOut.data_param[channelIndexList,paramIndex,:]
892 else:
891 else:
893 z = dataOut.data_param[channelIndexList,:]
892 z = dataOut.data_param[channelIndexList,:]
894
893
895 if showSNR:
894 if showSNR:
896 #SNR data
895 #SNR data
897 SNRarray = dataOut.data_SNR[channelIndexList,:]
896 SNRarray = dataOut.data_SNR[channelIndexList,:]
898 SNRdB = 10*numpy.log10(SNRarray)
897 SNRdB = 10*numpy.log10(SNRarray)
899 ind = numpy.where(SNRdB < SNRthresh)
898 ind = numpy.where(SNRdB < SNRthresh)
900 z[ind] = numpy.nan
899 z[ind] = numpy.nan
901
900
902 thisDatetime = dataOut.datatime
901 thisDatetime = dataOut.datatime
903 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
902 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
904 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
903 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
905 xlabel = ""
904 xlabel = ""
906 ylabel = "Range (Km)"
905 ylabel = "Range (Km)"
907
906
908 update_figfile = False
907 update_figfile = False
909
908
910 if not self.isConfig:
909 if not self.isConfig:
911
910
912 nchan = len(channelIndexList)
911 nchan = len(channelIndexList)
913 self.nchan = nchan
912 self.nchan = nchan
914 self.plotFact = 1
913 self.plotFact = 1
915 nplots = nchan
914 nplots = nchan
916
915
917 if showSNR:
916 if showSNR:
918 nplots = nchan*2
917 nplots = nchan*2
919 self.plotFact = 2
918 self.plotFact = 2
920 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
919 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
921 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
920 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
922
921
923 self.setup(id=id,
922 self.setup(id=id,
924 nplots=nplots,
923 nplots=nplots,
925 wintitle=wintitle,
924 wintitle=wintitle,
926 show=show)
925 show=show)
927
926
928 if timerange != None:
927 if timerange != None:
929 self.timerange = timerange
928 self.timerange = timerange
930
929
931 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
930 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
932
931
933 if ymin == None: ymin = numpy.nanmin(y)
932 if ymin == None: ymin = numpy.nanmin(y)
934 if ymax == None: ymax = numpy.nanmax(y)
933 if ymax == None: ymax = numpy.nanmax(y)
935 if zmin == None: zmin = numpy.nanmin(z)
934 if zmin == None: zmin = numpy.nanmin(z)
936 if zmax == None: zmax = numpy.nanmax(z)
935 if zmax == None: zmax = numpy.nanmax(z)
937
936
938 self.FTP_WEI = ftp_wei
937 self.FTP_WEI = ftp_wei
939 self.EXP_CODE = exp_code
938 self.EXP_CODE = exp_code
940 self.SUB_EXP_CODE = sub_exp_code
939 self.SUB_EXP_CODE = sub_exp_code
941 self.PLOT_POS = plot_pos
940 self.PLOT_POS = plot_pos
942
941
943 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
942 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
944 self.isConfig = True
943 self.isConfig = True
945 self.figfile = figfile
944 self.figfile = figfile
946 update_figfile = True
945 update_figfile = True
947
946
948 self.setWinTitle(title)
947 self.setWinTitle(title)
949
948
950 for i in range(self.nchan):
949 for i in range(self.nchan):
951 index = channelIndexList[i]
950 index = channelIndexList[i]
952 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
951 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
953 axes = self.axesList[i*self.plotFact]
952 axes = self.axesList[i*self.plotFact]
954 z1 = z[i,:].reshape((1,-1))
953 z1 = z[i,:].reshape((1,-1))
955 axes.pcolorbuffer(x, y, z1,
954 axes.pcolorbuffer(x, y, z1,
956 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
955 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
957 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
956 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
958 ticksize=9, cblabel='', cbsize="1%",colormap=colormap)
957 ticksize=9, cblabel='', cbsize="1%",colormap=colormap)
959
958
960 if showSNR:
959 if showSNR:
961 title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
960 title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
962 axes = self.axesList[i*self.plotFact + 1]
961 axes = self.axesList[i*self.plotFact + 1]
963 SNRdB1 = SNRdB[i,:].reshape((1,-1))
962 SNRdB1 = SNRdB[i,:].reshape((1,-1))
964 axes.pcolorbuffer(x, y, SNRdB1,
963 axes.pcolorbuffer(x, y, SNRdB1,
965 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
964 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
966 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
965 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
967 ticksize=9, cblabel='', cbsize="1%",colormap='jet')
966 ticksize=9, cblabel='', cbsize="1%",colormap='jet')
968
967
969
968
970 self.draw()
969 self.draw()
971
970
972 if dataOut.ltctime >= self.xmax:
971 if dataOut.ltctime >= self.xmax:
973 self.counter_imagwr = wr_period
972 self.counter_imagwr = wr_period
974 self.isConfig = False
973 self.isConfig = False
975 update_figfile = True
974 update_figfile = True
976
975
977 self.save(figpath=figpath,
976 self.save(figpath=figpath,
978 figfile=figfile,
977 figfile=figfile,
979 save=save,
978 save=save,
980 ftp=ftp,
979 ftp=ftp,
981 wr_period=wr_period,
980 wr_period=wr_period,
982 thisDatetime=thisDatetime,
981 thisDatetime=thisDatetime,
983 update_figfile=update_figfile)
982 update_figfile=update_figfile)
984
983
985
984
986
985
987 class Parameters1Plot(Figure):
986 class Parameters1Plot(Figure):
988
987
989 __isConfig = None
988 __isConfig = None
990 __nsubplots = None
989 __nsubplots = None
991
990
992 WIDTHPROF = None
991 WIDTHPROF = None
993 HEIGHTPROF = None
992 HEIGHTPROF = None
994 PREFIX = 'prm'
993 PREFIX = 'prm'
995
994
996 def __init__(self, **kwargs):
995 def __init__(self, **kwargs):
997 Figure.__init__(self, **kwargs)
996 Figure.__init__(self, **kwargs)
998 self.timerange = 2*60*60
997 self.timerange = 2*60*60
999 self.isConfig = False
998 self.isConfig = False
1000 self.__nsubplots = 1
999 self.__nsubplots = 1
1001
1000
1002 self.WIDTH = 800
1001 self.WIDTH = 800
1003 self.HEIGHT = 180
1002 self.HEIGHT = 180
1004 self.WIDTHPROF = 120
1003 self.WIDTHPROF = 120
1005 self.HEIGHTPROF = 0
1004 self.HEIGHTPROF = 0
1006 self.counter_imagwr = 0
1005 self.counter_imagwr = 0
1007
1006
1008 self.PLOT_CODE = PARMS_CODE
1007 self.PLOT_CODE = PARMS_CODE
1009
1008
1010 self.FTP_WEI = None
1009 self.FTP_WEI = None
1011 self.EXP_CODE = None
1010 self.EXP_CODE = None
1012 self.SUB_EXP_CODE = None
1011 self.SUB_EXP_CODE = None
1013 self.PLOT_POS = None
1012 self.PLOT_POS = None
1014 self.tmin = None
1013 self.tmin = None
1015 self.tmax = None
1014 self.tmax = None
1016
1015
1017 self.xmin = None
1016 self.xmin = None
1018 self.xmax = None
1017 self.xmax = None
1019
1018
1020 self.figfile = None
1019 self.figfile = None
1021
1020
1022 def getSubplots(self):
1021 def getSubplots(self):
1023
1022
1024 ncol = 1
1023 ncol = 1
1025 nrow = self.nplots
1024 nrow = self.nplots
1026
1025
1027 return nrow, ncol
1026 return nrow, ncol
1028
1027
1029 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1028 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1030
1029
1031 self.__showprofile = showprofile
1030 self.__showprofile = showprofile
1032 self.nplots = nplots
1031 self.nplots = nplots
1033
1032
1034 ncolspan = 1
1033 ncolspan = 1
1035 colspan = 1
1034 colspan = 1
1036
1035
1037 self.createFigure(id = id,
1036 self.createFigure(id = id,
1038 wintitle = wintitle,
1037 wintitle = wintitle,
1039 widthplot = self.WIDTH + self.WIDTHPROF,
1038 widthplot = self.WIDTH + self.WIDTHPROF,
1040 heightplot = self.HEIGHT + self.HEIGHTPROF,
1039 heightplot = self.HEIGHT + self.HEIGHTPROF,
1041 show=show)
1040 show=show)
1042
1041
1043 nrow, ncol = self.getSubplots()
1042 nrow, ncol = self.getSubplots()
1044
1043
1045 counter = 0
1044 counter = 0
1046 for y in range(nrow):
1045 for y in range(nrow):
1047 for x in range(ncol):
1046 for x in range(ncol):
1048
1047
1049 if counter >= self.nplots:
1048 if counter >= self.nplots:
1050 break
1049 break
1051
1050
1052 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1051 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1053
1052
1054 if showprofile:
1053 if showprofile:
1055 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1054 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1056
1055
1057 counter += 1
1056 counter += 1
1058
1057
1059 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
1058 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
1060 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None,
1059 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None,
1061 parameterIndex = None, onlyPositive = False,
1060 parameterIndex = None, onlyPositive = False,
1062 SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None, onlySNR = False,
1061 SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None, onlySNR = False,
1063 DOP = True,
1062 DOP = True,
1064 zlabel = "", parameterName = "", parameterObject = "data_param",
1063 zlabel = "", parameterName = "", parameterObject = "data_param",
1065 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1064 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1066 server=None, folder=None, username=None, password=None,
1065 server=None, folder=None, username=None, password=None,
1067 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1066 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1068 #print inspect.getargspec(self.run).args
1067 #print inspect.getargspec(self.run).args
1069 """
1068 """
1070
1069
1071 Input:
1070 Input:
1072 dataOut :
1071 dataOut :
1073 id :
1072 id :
1074 wintitle :
1073 wintitle :
1075 channelList :
1074 channelList :
1076 showProfile :
1075 showProfile :
1077 xmin : None,
1076 xmin : None,
1078 xmax : None,
1077 xmax : None,
1079 ymin : None,
1078 ymin : None,
1080 ymax : None,
1079 ymax : None,
1081 zmin : None,
1080 zmin : None,
1082 zmax : None
1081 zmax : None
1083 """
1082 """
1084
1083
1085 data_param = getattr(dataOut, parameterObject)
1084 data_param = getattr(dataOut, parameterObject)
1086
1085
1087 if channelList == None:
1086 if channelList == None:
1088 channelIndexList = numpy.arange(data_param.shape[0])
1087 channelIndexList = numpy.arange(data_param.shape[0])
1089 else:
1088 else:
1090 channelIndexList = numpy.array(channelList)
1089 channelIndexList = numpy.array(channelList)
1091
1090
1092 nchan = len(channelIndexList) #Number of channels being plotted
1091 nchan = len(channelIndexList) #Number of channels being plotted
1093
1092
1094 if nchan < 1:
1093 if nchan < 1:
1095 return
1094 return
1096
1095
1097 nGraphsByChannel = 0
1096 nGraphsByChannel = 0
1098
1097
1099 if SNR:
1098 if SNR:
1100 nGraphsByChannel += 1
1099 nGraphsByChannel += 1
1101 if DOP:
1100 if DOP:
1102 nGraphsByChannel += 1
1101 nGraphsByChannel += 1
1103
1102
1104 if nGraphsByChannel < 1:
1103 if nGraphsByChannel < 1:
1105 return
1104 return
1106
1105
1107 nplots = nGraphsByChannel*nchan
1106 nplots = nGraphsByChannel*nchan
1108
1107
1109 if timerange is not None:
1108 if timerange is not None:
1110 self.timerange = timerange
1109 self.timerange = timerange
1111
1110
1112 #tmin = None
1111 #tmin = None
1113 #tmax = None
1112 #tmax = None
1114 if parameterIndex == None:
1113 if parameterIndex == None:
1115 parameterIndex = 1
1114 parameterIndex = 1
1116
1115
1117 x = dataOut.getTimeRange1(dataOut.paramInterval)
1116 x = dataOut.getTimeRange1(dataOut.paramInterval)
1118 y = dataOut.heightList
1117 y = dataOut.heightList
1119 z = data_param[channelIndexList,parameterIndex,:].copy()
1118 z = data_param[channelIndexList,parameterIndex,:].copy()
1120
1119
1121 zRange = dataOut.abscissaList
1120 zRange = dataOut.abscissaList
1122 # nChannels = z.shape[0] #Number of wind dimensions estimated
1121 # nChannels = z.shape[0] #Number of wind dimensions estimated
1123 # thisDatetime = dataOut.datatime
1122 # thisDatetime = dataOut.datatime
1124
1123
1125 if dataOut.data_SNR is not None:
1124 if dataOut.data_SNR is not None:
1126 SNRarray = dataOut.data_SNR[channelIndexList,:]
1125 SNRarray = dataOut.data_SNR[channelIndexList,:]
1127 SNRdB = 10*numpy.log10(SNRarray)
1126 SNRdB = 10*numpy.log10(SNRarray)
1128 # SNRavgdB = 10*numpy.log10(SNRavg)
1127 # SNRavgdB = 10*numpy.log10(SNRavg)
1129 ind = numpy.where(SNRdB < 10**(SNRthresh/10))
1128 ind = numpy.where(SNRdB < 10**(SNRthresh/10))
1130 z[ind] = numpy.nan
1129 z[ind] = numpy.nan
1131
1130
1132 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1131 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1133 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
1132 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
1134 xlabel = ""
1133 xlabel = ""
1135 ylabel = "Range (Km)"
1134 ylabel = "Range (Km)"
1136
1135
1137 if (SNR and not onlySNR): nplots = 2*nplots
1136 if (SNR and not onlySNR): nplots = 2*nplots
1138
1137
1139 if onlyPositive:
1138 if onlyPositive:
1140 colormap = "jet"
1139 colormap = "jet"
1141 zmin = 0
1140 zmin = 0
1142 else: colormap = "RdBu_r"
1141 else: colormap = "RdBu_r"
1143
1142
1144 if not self.isConfig:
1143 if not self.isConfig:
1145
1144
1146 self.setup(id=id,
1145 self.setup(id=id,
1147 nplots=nplots,
1146 nplots=nplots,
1148 wintitle=wintitle,
1147 wintitle=wintitle,
1149 showprofile=showprofile,
1148 showprofile=showprofile,
1150 show=show)
1149 show=show)
1151
1150
1152 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1151 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1153
1152
1154 if ymin == None: ymin = numpy.nanmin(y)
1153 if ymin == None: ymin = numpy.nanmin(y)
1155 if ymax == None: ymax = numpy.nanmax(y)
1154 if ymax == None: ymax = numpy.nanmax(y)
1156 if zmin == None: zmin = numpy.nanmin(zRange)
1155 if zmin == None: zmin = numpy.nanmin(zRange)
1157 if zmax == None: zmax = numpy.nanmax(zRange)
1156 if zmax == None: zmax = numpy.nanmax(zRange)
1158
1157
1159 if SNR:
1158 if SNR:
1160 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
1159 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
1161 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
1160 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
1162
1161
1163 self.FTP_WEI = ftp_wei
1162 self.FTP_WEI = ftp_wei
1164 self.EXP_CODE = exp_code
1163 self.EXP_CODE = exp_code
1165 self.SUB_EXP_CODE = sub_exp_code
1164 self.SUB_EXP_CODE = sub_exp_code
1166 self.PLOT_POS = plot_pos
1165 self.PLOT_POS = plot_pos
1167
1166
1168 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1167 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1169 self.isConfig = True
1168 self.isConfig = True
1170 self.figfile = figfile
1169 self.figfile = figfile
1171
1170
1172 self.setWinTitle(title)
1171 self.setWinTitle(title)
1173
1172
1174 if ((self.xmax - x[1]) < (x[1]-x[0])):
1173 if ((self.xmax - x[1]) < (x[1]-x[0])):
1175 x[1] = self.xmax
1174 x[1] = self.xmax
1176
1175
1177 for i in range(nchan):
1176 for i in range(nchan):
1178
1177
1179 if (SNR and not onlySNR): j = 2*i
1178 if (SNR and not onlySNR): j = 2*i
1180 else: j = i
1179 else: j = i
1181
1180
1182 j = nGraphsByChannel*i
1181 j = nGraphsByChannel*i
1183
1182
1184 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1183 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1185 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
1184 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
1186
1185
1187 if not onlySNR:
1186 if not onlySNR:
1188 axes = self.axesList[j*self.__nsubplots]
1187 axes = self.axesList[j*self.__nsubplots]
1189 z1 = z[i,:].reshape((1,-1))
1188 z1 = z[i,:].reshape((1,-1))
1190 axes.pcolorbuffer(x, y, z1,
1189 axes.pcolorbuffer(x, y, z1,
1191 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1190 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1192 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
1191 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
1193 ticksize=9, cblabel=zlabel, cbsize="1%")
1192 ticksize=9, cblabel=zlabel, cbsize="1%")
1194
1193
1195 if DOP:
1194 if DOP:
1196 title = "%s Channel %d: %s" %(parameterName, channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1195 title = "%s Channel %d: %s" %(parameterName, channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1197
1196
1198 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1197 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1199 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
1198 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
1200 axes = self.axesList[j]
1199 axes = self.axesList[j]
1201 z1 = z[i,:].reshape((1,-1))
1200 z1 = z[i,:].reshape((1,-1))
1202 axes.pcolorbuffer(x, y, z1,
1201 axes.pcolorbuffer(x, y, z1,
1203 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1202 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1204 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
1203 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
1205 ticksize=9, cblabel=zlabel, cbsize="1%")
1204 ticksize=9, cblabel=zlabel, cbsize="1%")
1206
1205
1207 if SNR:
1206 if SNR:
1208 title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1207 title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1209 axes = self.axesList[(j)*self.__nsubplots]
1208 axes = self.axesList[(j)*self.__nsubplots]
1210 if not onlySNR:
1209 if not onlySNR:
1211 axes = self.axesList[(j + 1)*self.__nsubplots]
1210 axes = self.axesList[(j + 1)*self.__nsubplots]
1212
1211
1213 axes = self.axesList[(j + nGraphsByChannel-1)]
1212 axes = self.axesList[(j + nGraphsByChannel-1)]
1214
1213
1215 z1 = SNRdB[i,:].reshape((1,-1))
1214 z1 = SNRdB[i,:].reshape((1,-1))
1216 axes.pcolorbuffer(x, y, z1,
1215 axes.pcolorbuffer(x, y, z1,
1217 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1216 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1218 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet",
1217 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet",
1219 ticksize=9, cblabel=zlabel, cbsize="1%")
1218 ticksize=9, cblabel=zlabel, cbsize="1%")
1220
1219
1221
1220
1222
1221
1223 self.draw()
1222 self.draw()
1224
1223
1225 if x[1] >= self.axesList[0].xmax:
1224 if x[1] >= self.axesList[0].xmax:
1226 self.counter_imagwr = wr_period
1225 self.counter_imagwr = wr_period
1227 self.isConfig = False
1226 self.isConfig = False
1228 self.figfile = None
1227 self.figfile = None
1229
1228
1230 self.save(figpath=figpath,
1229 self.save(figpath=figpath,
1231 figfile=figfile,
1230 figfile=figfile,
1232 save=save,
1231 save=save,
1233 ftp=ftp,
1232 ftp=ftp,
1234 wr_period=wr_period,
1233 wr_period=wr_period,
1235 thisDatetime=thisDatetime,
1234 thisDatetime=thisDatetime,
1236 update_figfile=False)
1235 update_figfile=False)
1237
1236
1238 class SpectralFittingPlot(Figure):
1237 class SpectralFittingPlot(Figure):
1239
1238
1240 __isConfig = None
1239 __isConfig = None
1241 __nsubplots = None
1240 __nsubplots = None
1242
1241
1243 WIDTHPROF = None
1242 WIDTHPROF = None
1244 HEIGHTPROF = None
1243 HEIGHTPROF = None
1245 PREFIX = 'prm'
1244 PREFIX = 'prm'
1246
1245
1247
1246
1248 N = None
1247 N = None
1249 ippSeconds = None
1248 ippSeconds = None
1250
1249
1251 def __init__(self, **kwargs):
1250 def __init__(self, **kwargs):
1252 Figure.__init__(self, **kwargs)
1251 Figure.__init__(self, **kwargs)
1253 self.isConfig = False
1252 self.isConfig = False
1254 self.__nsubplots = 1
1253 self.__nsubplots = 1
1255
1254
1256 self.PLOT_CODE = SPECFIT_CODE
1255 self.PLOT_CODE = SPECFIT_CODE
1257
1256
1258 self.WIDTH = 450
1257 self.WIDTH = 450
1259 self.HEIGHT = 250
1258 self.HEIGHT = 250
1260 self.WIDTHPROF = 0
1259 self.WIDTHPROF = 0
1261 self.HEIGHTPROF = 0
1260 self.HEIGHTPROF = 0
1262
1261
1263 def getSubplots(self):
1262 def getSubplots(self):
1264
1263
1265 ncol = int(numpy.sqrt(self.nplots)+0.9)
1264 ncol = int(numpy.sqrt(self.nplots)+0.9)
1266 nrow = int(self.nplots*1./ncol + 0.9)
1265 nrow = int(self.nplots*1./ncol + 0.9)
1267
1266
1268 return nrow, ncol
1267 return nrow, ncol
1269
1268
1270 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
1269 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
1271
1270
1272 showprofile = False
1271 showprofile = False
1273 self.__showprofile = showprofile
1272 self.__showprofile = showprofile
1274 self.nplots = nplots
1273 self.nplots = nplots
1275
1274
1276 ncolspan = 5
1275 ncolspan = 5
1277 colspan = 4
1276 colspan = 4
1278 if showprofile:
1277 if showprofile:
1279 ncolspan = 5
1278 ncolspan = 5
1280 colspan = 4
1279 colspan = 4
1281 self.__nsubplots = 2
1280 self.__nsubplots = 2
1282
1281
1283 self.createFigure(id = id,
1282 self.createFigure(id = id,
1284 wintitle = wintitle,
1283 wintitle = wintitle,
1285 widthplot = self.WIDTH + self.WIDTHPROF,
1284 widthplot = self.WIDTH + self.WIDTHPROF,
1286 heightplot = self.HEIGHT + self.HEIGHTPROF,
1285 heightplot = self.HEIGHT + self.HEIGHTPROF,
1287 show=show)
1286 show=show)
1288
1287
1289 nrow, ncol = self.getSubplots()
1288 nrow, ncol = self.getSubplots()
1290
1289
1291 counter = 0
1290 counter = 0
1292 for y in range(nrow):
1291 for y in range(nrow):
1293 for x in range(ncol):
1292 for x in range(ncol):
1294
1293
1295 if counter >= self.nplots:
1294 if counter >= self.nplots:
1296 break
1295 break
1297
1296
1298 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1297 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1299
1298
1300 if showprofile:
1299 if showprofile:
1301 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1300 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1302
1301
1303 counter += 1
1302 counter += 1
1304
1303
1305 def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True,
1304 def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True,
1306 xmin=None, xmax=None, ymin=None, ymax=None,
1305 xmin=None, xmax=None, ymin=None, ymax=None,
1307 save=False, figpath='./', figfile=None, show=True):
1306 save=False, figpath='./', figfile=None, show=True):
1308
1307
1309 """
1308 """
1310
1309
1311 Input:
1310 Input:
1312 dataOut :
1311 dataOut :
1313 id :
1312 id :
1314 wintitle :
1313 wintitle :
1315 channelList :
1314 channelList :
1316 showProfile :
1315 showProfile :
1317 xmin : None,
1316 xmin : None,
1318 xmax : None,
1317 xmax : None,
1319 zmin : None,
1318 zmin : None,
1320 zmax : None
1319 zmax : None
1321 """
1320 """
1322
1321
1323 if cutHeight==None:
1322 if cutHeight==None:
1324 h=270
1323 h=270
1325 heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin()
1324 heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin()
1326 cutHeight = dataOut.heightList[heightindex]
1325 cutHeight = dataOut.heightList[heightindex]
1327
1326
1328 factor = dataOut.normFactor
1327 factor = dataOut.normFactor
1329 x = dataOut.abscissaList[:-1]
1328 x = dataOut.abscissaList[:-1]
1330 #y = dataOut.getHeiRange()
1329 #y = dataOut.getHeiRange()
1331
1330
1332 z = dataOut.data_pre[:,:,heightindex]/factor
1331 z = dataOut.data_pre[:,:,heightindex]/factor
1333 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1332 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1334 avg = numpy.average(z, axis=1)
1333 avg = numpy.average(z, axis=1)
1335 listChannels = z.shape[0]
1334 listChannels = z.shape[0]
1336
1335
1337 #Reconstruct Function
1336 #Reconstruct Function
1338 if fit==True:
1337 if fit==True:
1339 groupArray = dataOut.groupList
1338 groupArray = dataOut.groupList
1340 listChannels = groupArray.reshape((groupArray.size))
1339 listChannels = groupArray.reshape((groupArray.size))
1341 listChannels.sort()
1340 listChannels.sort()
1342 spcFitLine = numpy.zeros(z.shape)
1341 spcFitLine = numpy.zeros(z.shape)
1343 constants = dataOut.constants
1342 constants = dataOut.constants
1344
1343
1345 nGroups = groupArray.shape[0]
1344 nGroups = groupArray.shape[0]
1346 nChannels = groupArray.shape[1]
1345 nChannels = groupArray.shape[1]
1347 nProfiles = z.shape[1]
1346 nProfiles = z.shape[1]
1348
1347
1349 for f in range(nGroups):
1348 for f in range(nGroups):
1350 groupChann = groupArray[f,:]
1349 groupChann = groupArray[f,:]
1351 p = dataOut.data_param[f,:,heightindex]
1350 p = dataOut.data_param[f,:,heightindex]
1352 # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167])
1351 # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167])
1353 fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles
1352 fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles
1354 fitLineAux = fitLineAux.reshape((nChannels,nProfiles))
1353 fitLineAux = fitLineAux.reshape((nChannels,nProfiles))
1355 spcFitLine[groupChann,:] = fitLineAux
1354 spcFitLine[groupChann,:] = fitLineAux
1356 # spcFitLine = spcFitLine/factor
1355 # spcFitLine = spcFitLine/factor
1357
1356
1358 z = z[listChannels,:]
1357 z = z[listChannels,:]
1359 spcFitLine = spcFitLine[listChannels,:]
1358 spcFitLine = spcFitLine[listChannels,:]
1360 spcFitLinedB = 10*numpy.log10(spcFitLine)
1359 spcFitLinedB = 10*numpy.log10(spcFitLine)
1361
1360
1362 zdB = 10*numpy.log10(z)
1361 zdB = 10*numpy.log10(z)
1363 #thisDatetime = dataOut.datatime
1362 #thisDatetime = dataOut.datatime
1364 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1363 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1365 title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1364 title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1366 xlabel = "Velocity (m/s)"
1365 xlabel = "Velocity (m/s)"
1367 ylabel = "Spectrum"
1366 ylabel = "Spectrum"
1368
1367
1369 if not self.isConfig:
1368 if not self.isConfig:
1370
1369
1371 nplots = listChannels.size
1370 nplots = listChannels.size
1372
1371
1373 self.setup(id=id,
1372 self.setup(id=id,
1374 nplots=nplots,
1373 nplots=nplots,
1375 wintitle=wintitle,
1374 wintitle=wintitle,
1376 showprofile=showprofile,
1375 showprofile=showprofile,
1377 show=show)
1376 show=show)
1378
1377
1379 if xmin == None: xmin = numpy.nanmin(x)
1378 if xmin == None: xmin = numpy.nanmin(x)
1380 if xmax == None: xmax = numpy.nanmax(x)
1379 if xmax == None: xmax = numpy.nanmax(x)
1381 if ymin == None: ymin = numpy.nanmin(zdB)
1380 if ymin == None: ymin = numpy.nanmin(zdB)
1382 if ymax == None: ymax = numpy.nanmax(zdB)+2
1381 if ymax == None: ymax = numpy.nanmax(zdB)+2
1383
1382
1384 self.isConfig = True
1383 self.isConfig = True
1385
1384
1386 self.setWinTitle(title)
1385 self.setWinTitle(title)
1387 for i in range(self.nplots):
1386 for i in range(self.nplots):
1388 # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i])
1387 # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i])
1389 title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i])
1388 title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i])
1390 axes = self.axesList[i*self.__nsubplots]
1389 axes = self.axesList[i*self.__nsubplots]
1391 if fit == False:
1390 if fit == False:
1392 axes.pline(x, zdB[i,:],
1391 axes.pline(x, zdB[i,:],
1393 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1392 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1394 xlabel=xlabel, ylabel=ylabel, title=title
1393 xlabel=xlabel, ylabel=ylabel, title=title
1395 )
1394 )
1396 if fit == True:
1395 if fit == True:
1397 fitline=spcFitLinedB[i,:]
1396 fitline=spcFitLinedB[i,:]
1398 y=numpy.vstack([zdB[i,:],fitline] )
1397 y=numpy.vstack([zdB[i,:],fitline] )
1399 legendlabels=['Data','Fitting']
1398 legendlabels=['Data','Fitting']
1400 axes.pmultilineyaxis(x, y,
1399 axes.pmultilineyaxis(x, y,
1401 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1400 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1402 xlabel=xlabel, ylabel=ylabel, title=title,
1401 xlabel=xlabel, ylabel=ylabel, title=title,
1403 legendlabels=legendlabels, marker=None,
1402 legendlabels=legendlabels, marker=None,
1404 linestyle='solid', grid='both')
1403 linestyle='solid', grid='both')
1405
1404
1406 self.draw()
1405 self.draw()
1407
1406
1408 self.save(figpath=figpath,
1407 self.save(figpath=figpath,
1409 figfile=figfile,
1408 figfile=figfile,
1410 save=save,
1409 save=save,
1411 ftp=ftp,
1410 ftp=ftp,
1412 wr_period=wr_period,
1411 wr_period=wr_period,
1413 thisDatetime=thisDatetime)
1412 thisDatetime=thisDatetime)
1414
1413
1415
1414
1416 class EWDriftsPlot(Figure):
1415 class EWDriftsPlot(Figure):
1417
1416
1418 __isConfig = None
1417 __isConfig = None
1419 __nsubplots = None
1418 __nsubplots = None
1420
1419
1421 WIDTHPROF = None
1420 WIDTHPROF = None
1422 HEIGHTPROF = None
1421 HEIGHTPROF = None
1423 PREFIX = 'drift'
1422 PREFIX = 'drift'
1424
1423
1425 def __init__(self, **kwargs):
1424 def __init__(self, **kwargs):
1426 Figure.__init__(self, **kwargs)
1425 Figure.__init__(self, **kwargs)
1427 self.timerange = 2*60*60
1426 self.timerange = 2*60*60
1428 self.isConfig = False
1427 self.isConfig = False
1429 self.__nsubplots = 1
1428 self.__nsubplots = 1
1430
1429
1431 self.WIDTH = 800
1430 self.WIDTH = 800
1432 self.HEIGHT = 150
1431 self.HEIGHT = 150
1433 self.WIDTHPROF = 120
1432 self.WIDTHPROF = 120
1434 self.HEIGHTPROF = 0
1433 self.HEIGHTPROF = 0
1435 self.counter_imagwr = 0
1434 self.counter_imagwr = 0
1436
1435
1437 self.PLOT_CODE = EWDRIFT_CODE
1436 self.PLOT_CODE = EWDRIFT_CODE
1438
1437
1439 self.FTP_WEI = None
1438 self.FTP_WEI = None
1440 self.EXP_CODE = None
1439 self.EXP_CODE = None
1441 self.SUB_EXP_CODE = None
1440 self.SUB_EXP_CODE = None
1442 self.PLOT_POS = None
1441 self.PLOT_POS = None
1443 self.tmin = None
1442 self.tmin = None
1444 self.tmax = None
1443 self.tmax = None
1445
1444
1446 self.xmin = None
1445 self.xmin = None
1447 self.xmax = None
1446 self.xmax = None
1448
1447
1449 self.figfile = None
1448 self.figfile = None
1450
1449
1451 def getSubplots(self):
1450 def getSubplots(self):
1452
1451
1453 ncol = 1
1452 ncol = 1
1454 nrow = self.nplots
1453 nrow = self.nplots
1455
1454
1456 return nrow, ncol
1455 return nrow, ncol
1457
1456
1458 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1457 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1459
1458
1460 self.__showprofile = showprofile
1459 self.__showprofile = showprofile
1461 self.nplots = nplots
1460 self.nplots = nplots
1462
1461
1463 ncolspan = 1
1462 ncolspan = 1
1464 colspan = 1
1463 colspan = 1
1465
1464
1466 self.createFigure(id = id,
1465 self.createFigure(id = id,
1467 wintitle = wintitle,
1466 wintitle = wintitle,
1468 widthplot = self.WIDTH + self.WIDTHPROF,
1467 widthplot = self.WIDTH + self.WIDTHPROF,
1469 heightplot = self.HEIGHT + self.HEIGHTPROF,
1468 heightplot = self.HEIGHT + self.HEIGHTPROF,
1470 show=show)
1469 show=show)
1471
1470
1472 nrow, ncol = self.getSubplots()
1471 nrow, ncol = self.getSubplots()
1473
1472
1474 counter = 0
1473 counter = 0
1475 for y in range(nrow):
1474 for y in range(nrow):
1476 if counter >= self.nplots:
1475 if counter >= self.nplots:
1477 break
1476 break
1478
1477
1479 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
1478 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
1480 counter += 1
1479 counter += 1
1481
1480
1482 def run(self, dataOut, id, wintitle="", channelList=None,
1481 def run(self, dataOut, id, wintitle="", channelList=None,
1483 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
1482 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
1484 zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None,
1483 zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None,
1485 timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False,
1484 timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False,
1486 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1485 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1487 server=None, folder=None, username=None, password=None,
1486 server=None, folder=None, username=None, password=None,
1488 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1487 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1489 """
1488 """
1490
1489
1491 Input:
1490 Input:
1492 dataOut :
1491 dataOut :
1493 id :
1492 id :
1494 wintitle :
1493 wintitle :
1495 channelList :
1494 channelList :
1496 showProfile :
1495 showProfile :
1497 xmin : None,
1496 xmin : None,
1498 xmax : None,
1497 xmax : None,
1499 ymin : None,
1498 ymin : None,
1500 ymax : None,
1499 ymax : None,
1501 zmin : None,
1500 zmin : None,
1502 zmax : None
1501 zmax : None
1503 """
1502 """
1504
1503
1505 if timerange is not None:
1504 if timerange is not None:
1506 self.timerange = timerange
1505 self.timerange = timerange
1507
1506
1508 tmin = None
1507 tmin = None
1509 tmax = None
1508 tmax = None
1510
1509
1511 x = dataOut.getTimeRange1(dataOut.outputInterval)
1510 x = dataOut.getTimeRange1(dataOut.outputInterval)
1512 # y = dataOut.heightList
1511 # y = dataOut.heightList
1513 y = dataOut.heightList
1512 y = dataOut.heightList
1514
1513
1515 z = dataOut.data_output
1514 z = dataOut.data_output
1516 nplots = z.shape[0] #Number of wind dimensions estimated
1515 nplots = z.shape[0] #Number of wind dimensions estimated
1517 nplotsw = nplots
1516 nplotsw = nplots
1518
1517
1519 #If there is a SNR function defined
1518 #If there is a SNR function defined
1520 if dataOut.data_SNR is not None:
1519 if dataOut.data_SNR is not None:
1521 nplots += 1
1520 nplots += 1
1522 SNR = dataOut.data_SNR
1521 SNR = dataOut.data_SNR
1523
1522
1524 if SNR_1:
1523 if SNR_1:
1525 SNR += 1
1524 SNR += 1
1526
1525
1527 SNRavg = numpy.average(SNR, axis=0)
1526 SNRavg = numpy.average(SNR, axis=0)
1528
1527
1529 SNRdB = 10*numpy.log10(SNR)
1528 SNRdB = 10*numpy.log10(SNR)
1530 SNRavgdB = 10*numpy.log10(SNRavg)
1529 SNRavgdB = 10*numpy.log10(SNRavg)
1531
1530
1532 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
1531 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
1533
1532
1534 for i in range(nplotsw):
1533 for i in range(nplotsw):
1535 z[i,ind] = numpy.nan
1534 z[i,ind] = numpy.nan
1536
1535
1537
1536
1538 showprofile = False
1537 showprofile = False
1539 # thisDatetime = dataOut.datatime
1538 # thisDatetime = dataOut.datatime
1540 thisDatetime = datetime.datetime.utcfromtimestamp(x[1])
1539 thisDatetime = datetime.datetime.utcfromtimestamp(x[1])
1541 title = wintitle + " EW Drifts"
1540 title = wintitle + " EW Drifts"
1542 xlabel = ""
1541 xlabel = ""
1543 ylabel = "Height (Km)"
1542 ylabel = "Height (Km)"
1544
1543
1545 if not self.isConfig:
1544 if not self.isConfig:
1546
1545
1547 self.setup(id=id,
1546 self.setup(id=id,
1548 nplots=nplots,
1547 nplots=nplots,
1549 wintitle=wintitle,
1548 wintitle=wintitle,
1550 showprofile=showprofile,
1549 showprofile=showprofile,
1551 show=show)
1550 show=show)
1552
1551
1553 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1552 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1554
1553
1555 if ymin == None: ymin = numpy.nanmin(y)
1554 if ymin == None: ymin = numpy.nanmin(y)
1556 if ymax == None: ymax = numpy.nanmax(y)
1555 if ymax == None: ymax = numpy.nanmax(y)
1557
1556
1558 if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:]))
1557 if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:]))
1559 if zminZonal == None: zminZonal = -zmaxZonal
1558 if zminZonal == None: zminZonal = -zmaxZonal
1560 if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:]))
1559 if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:]))
1561 if zminVertical == None: zminVertical = -zmaxVertical
1560 if zminVertical == None: zminVertical = -zmaxVertical
1562
1561
1563 if dataOut.data_SNR is not None:
1562 if dataOut.data_SNR is not None:
1564 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
1563 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
1565 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
1564 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
1566
1565
1567 self.FTP_WEI = ftp_wei
1566 self.FTP_WEI = ftp_wei
1568 self.EXP_CODE = exp_code
1567 self.EXP_CODE = exp_code
1569 self.SUB_EXP_CODE = sub_exp_code
1568 self.SUB_EXP_CODE = sub_exp_code
1570 self.PLOT_POS = plot_pos
1569 self.PLOT_POS = plot_pos
1571
1570
1572 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1571 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1573 self.isConfig = True
1572 self.isConfig = True
1574
1573
1575
1574
1576 self.setWinTitle(title)
1575 self.setWinTitle(title)
1577
1576
1578 if ((self.xmax - x[1]) < (x[1]-x[0])):
1577 if ((self.xmax - x[1]) < (x[1]-x[0])):
1579 x[1] = self.xmax
1578 x[1] = self.xmax
1580
1579
1581 strWind = ['Zonal','Vertical']
1580 strWind = ['Zonal','Vertical']
1582 strCb = 'Velocity (m/s)'
1581 strCb = 'Velocity (m/s)'
1583 zmaxVector = [zmaxZonal, zmaxVertical]
1582 zmaxVector = [zmaxZonal, zmaxVertical]
1584 zminVector = [zminZonal, zminVertical]
1583 zminVector = [zminZonal, zminVertical]
1585
1584
1586 for i in range(nplotsw):
1585 for i in range(nplotsw):
1587
1586
1588 title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1587 title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1589 axes = self.axesList[i*self.__nsubplots]
1588 axes = self.axesList[i*self.__nsubplots]
1590
1589
1591 z1 = z[i,:].reshape((1,-1))
1590 z1 = z[i,:].reshape((1,-1))
1592
1591
1593 axes.pcolorbuffer(x, y, z1,
1592 axes.pcolorbuffer(x, y, z1,
1594 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
1593 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
1595 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1594 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1596 ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r")
1595 ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r")
1597
1596
1598 if dataOut.data_SNR is not None:
1597 if dataOut.data_SNR is not None:
1599 i += 1
1598 i += 1
1600 if SNR_1:
1599 if SNR_1:
1601 title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1600 title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1602 else:
1601 else:
1603 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1602 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1604 axes = self.axesList[i*self.__nsubplots]
1603 axes = self.axesList[i*self.__nsubplots]
1605 SNRavgdB = SNRavgdB.reshape((1,-1))
1604 SNRavgdB = SNRavgdB.reshape((1,-1))
1606
1605
1607 axes.pcolorbuffer(x, y, SNRavgdB,
1606 axes.pcolorbuffer(x, y, SNRavgdB,
1608 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1607 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1609 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1608 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1610 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
1609 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
1611
1610
1612 self.draw()
1611 self.draw()
1613
1612
1614 if x[1] >= self.axesList[0].xmax:
1613 if x[1] >= self.axesList[0].xmax:
1615 self.counter_imagwr = wr_period
1614 self.counter_imagwr = wr_period
1616 self.isConfig = False
1615 self.isConfig = False
1617 self.figfile = None
1616 self.figfile = None
1618
1617
1619
1618
1620
1619
1621
1620
1622 class PhasePlot(Figure):
1621 class PhasePlot(Figure):
1623
1622
1624 __isConfig = None
1623 __isConfig = None
1625 __nsubplots = None
1624 __nsubplots = None
1626
1625
1627 PREFIX = 'mphase'
1626 PREFIX = 'mphase'
1628
1627
1628
1629 def __init__(self, **kwargs):
1629 def __init__(self, **kwargs):
1630 Figure.__init__(self, **kwargs)
1630 Figure.__init__(self, **kwargs)
1631 self.timerange = 24*60*60
1631 self.timerange = 24*60*60
1632 self.isConfig = False
1632 self.isConfig = False
1633 self.__nsubplots = 1
1633 self.__nsubplots = 1
1634 self.counter_imagwr = 0
1634 self.counter_imagwr = 0
1635 self.WIDTH = 600
1635 self.WIDTH = 600
1636 self.HEIGHT = 300
1636 self.HEIGHT = 300
1637 self.WIDTHPROF = 120
1637 self.WIDTHPROF = 120
1638 self.HEIGHTPROF = 0
1638 self.HEIGHTPROF = 0
1639 self.xdata = None
1639 self.xdata = None
1640 self.ydata = None
1640 self.ydata = None
1641
1641
1642 self.PLOT_CODE = MPHASE_CODE
1642 self.PLOT_CODE = MPHASE_CODE
1643
1643
1644 self.FTP_WEI = None
1644 self.FTP_WEI = None
1645 self.EXP_CODE = None
1645 self.EXP_CODE = None
1646 self.SUB_EXP_CODE = None
1646 self.SUB_EXP_CODE = None
1647 self.PLOT_POS = None
1647 self.PLOT_POS = None
1648
1648
1649
1649
1650 self.filename_phase = None
1650 self.filename_phase = None
1651
1651
1652 self.figfile = None
1652 self.figfile = None
1653
1653
1654 def getSubplots(self):
1654 def getSubplots(self):
1655
1655
1656 ncol = 1
1656 ncol = 1
1657 nrow = 1
1657 nrow = 1
1658
1658
1659 return nrow, ncol
1659 return nrow, ncol
1660
1660
1661 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1661 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1662
1662
1663 self.__showprofile = showprofile
1663 self.__showprofile = showprofile
1664 self.nplots = nplots
1664 self.nplots = nplots
1665
1665
1666 ncolspan = 7
1666 ncolspan = 7
1667 colspan = 6
1667 colspan = 6
1668 self.__nsubplots = 2
1668 self.__nsubplots = 2
1669
1669
1670 self.createFigure(id = id,
1670 self.createFigure(id = id,
1671 wintitle = wintitle,
1671 wintitle = wintitle,
1672 widthplot = self.WIDTH+self.WIDTHPROF,
1672 widthplot = self.WIDTH+self.WIDTHPROF,
1673 heightplot = self.HEIGHT+self.HEIGHTPROF,
1673 heightplot = self.HEIGHT+self.HEIGHTPROF,
1674 show=show)
1674 show=show)
1675
1675
1676 nrow, ncol = self.getSubplots()
1676 nrow, ncol = self.getSubplots()
1677
1677
1678 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1678 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1679
1679
1680
1680
1681 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1681 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1682 xmin=None, xmax=None, ymin=None, ymax=None,
1682 xmin=None, xmax=None, ymin=None, ymax=None,
1683 timerange=None,
1683 timerange=None,
1684 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1684 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1685 server=None, folder=None, username=None, password=None,
1685 server=None, folder=None, username=None, password=None,
1686 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1686 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1687
1687
1688
1688
1689 tmin = None
1689 tmin = None
1690 tmax = None
1690 tmax = None
1691 x = dataOut.getTimeRange1(dataOut.outputInterval)
1691 x = dataOut.getTimeRange1(dataOut.outputInterval)
1692 y = dataOut.getHeiRange()
1692 y = dataOut.getHeiRange()
1693
1693
1694
1694
1695 #thisDatetime = dataOut.datatime
1695 #thisDatetime = dataOut.datatime
1696 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1696 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1697 title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1697 title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1698 xlabel = "Local Time"
1698 xlabel = "Local Time"
1699 ylabel = "Phase"
1699 ylabel = "Phase"
1700
1700
1701
1701
1702 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1702 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1703 phase_beacon = dataOut.data_output
1703 phase_beacon = dataOut.data_output
1704 update_figfile = False
1704 update_figfile = False
1705
1705
1706 if not self.isConfig:
1706 if not self.isConfig:
1707
1707
1708 self.nplots = phase_beacon.size
1708 self.nplots = phase_beacon.size
1709
1709
1710 self.setup(id=id,
1710 self.setup(id=id,
1711 nplots=self.nplots,
1711 nplots=self.nplots,
1712 wintitle=wintitle,
1712 wintitle=wintitle,
1713 showprofile=showprofile,
1713 showprofile=showprofile,
1714 show=show)
1714 show=show)
1715
1715
1716 if timerange is not None:
1716 if timerange is not None:
1717 self.timerange = timerange
1717 self.timerange = timerange
1718
1718
1719 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1719 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1720
1720
1721 if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0
1721 if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0
1722 if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0
1722 if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0
1723
1723
1724 self.FTP_WEI = ftp_wei
1724 self.FTP_WEI = ftp_wei
1725 self.EXP_CODE = exp_code
1725 self.EXP_CODE = exp_code
1726 self.SUB_EXP_CODE = sub_exp_code
1726 self.SUB_EXP_CODE = sub_exp_code
1727 self.PLOT_POS = plot_pos
1727 self.PLOT_POS = plot_pos
1728
1728
1729 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1729 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1730 self.isConfig = True
1730 self.isConfig = True
1731 self.figfile = figfile
1731 self.figfile = figfile
1732 self.xdata = numpy.array([])
1732 self.xdata = numpy.array([])
1733 self.ydata = numpy.array([])
1733 self.ydata = numpy.array([])
1734
1734
1735 #open file beacon phase
1735 #open file beacon phase
1736 path = '%s%03d' %(self.PREFIX, self.id)
1736 path = '%s%03d' %(self.PREFIX, self.id)
1737 beacon_file = os.path.join(path,'%s.txt'%self.name)
1737 beacon_file = os.path.join(path,'%s.txt'%self.name)
1738 self.filename_phase = os.path.join(figpath,beacon_file)
1738 self.filename_phase = os.path.join(figpath,beacon_file)
1739 update_figfile = True
1739 update_figfile = True
1740
1740
1741
1741
1742 #store data beacon phase
1742 #store data beacon phase
1743 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1743 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1744
1744
1745 self.setWinTitle(title)
1745 self.setWinTitle(title)
1746
1746
1747
1747
1748 title = "Phase Offset %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1748 title = "Phase Offset %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1749
1749
1750 legendlabels = ["phase %d"%(chan) for chan in numpy.arange(self.nplots)]
1750 legendlabels = ["phase %d"%(chan) for chan in numpy.arange(self.nplots)]
1751
1751
1752 axes = self.axesList[0]
1752 axes = self.axesList[0]
1753
1753
1754 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1754 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1755
1755
1756 if len(self.ydata)==0:
1756 if len(self.ydata)==0:
1757 self.ydata = phase_beacon.reshape(-1,1)
1757 self.ydata = phase_beacon.reshape(-1,1)
1758 else:
1758 else:
1759 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1759 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1760
1760
1761
1761
1762 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1762 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1763 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1763 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1764 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1764 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1765 XAxisAsTime=True, grid='both'
1765 XAxisAsTime=True, grid='both'
1766 )
1766 )
1767
1767
1768 self.draw()
1768 self.draw()
1769
1769
1770 self.save(figpath=figpath,
1770 self.save(figpath=figpath,
1771 figfile=figfile,
1771 figfile=figfile,
1772 save=save,
1772 save=save,
1773 ftp=ftp,
1773 ftp=ftp,
1774 wr_period=wr_period,
1774 wr_period=wr_period,
1775 thisDatetime=thisDatetime,
1775 thisDatetime=thisDatetime,
1776 update_figfile=update_figfile)
1776 update_figfile=update_figfile)
1777
1777
1778 if dataOut.ltctime + dataOut.outputInterval >= self.xmax:
1778 if dataOut.ltctime + dataOut.outputInterval >= self.xmax:
1779 self.counter_imagwr = wr_period
1779 self.counter_imagwr = wr_period
1780 self.isConfig = False
1780 self.isConfig = False
1781 update_figfile = True
1781 update_figfile = True
1782
1782
1783
1783
1784
1784
1785 class NSMeteorDetection1Plot(Figure):
1785 class NSMeteorDetection1Plot(Figure):
1786
1786
1787 isConfig = None
1787 isConfig = None
1788 __nsubplots = None
1788 __nsubplots = None
1789
1789
1790 WIDTHPROF = None
1790 WIDTHPROF = None
1791 HEIGHTPROF = None
1791 HEIGHTPROF = None
1792 PREFIX = 'nsm'
1792 PREFIX = 'nsm'
1793
1793
1794 zminList = None
1794 zminList = None
1795 zmaxList = None
1795 zmaxList = None
1796 cmapList = None
1796 cmapList = None
1797 titleList = None
1797 titleList = None
1798 nPairs = None
1798 nPairs = None
1799 nChannels = None
1799 nChannels = None
1800 nParam = None
1800 nParam = None
1801
1801
1802 def __init__(self, **kwargs):
1802 def __init__(self, **kwargs):
1803 Figure.__init__(self, **kwargs)
1803 Figure.__init__(self, **kwargs)
1804 self.isConfig = False
1804 self.isConfig = False
1805 self.__nsubplots = 1
1805 self.__nsubplots = 1
1806
1806
1807 self.WIDTH = 750
1807 self.WIDTH = 750
1808 self.HEIGHT = 250
1808 self.HEIGHT = 250
1809 self.WIDTHPROF = 120
1809 self.WIDTHPROF = 120
1810 self.HEIGHTPROF = 0
1810 self.HEIGHTPROF = 0
1811 self.counter_imagwr = 0
1811 self.counter_imagwr = 0
1812
1812
1813 self.PLOT_CODE = SPEC_CODE
1813 self.PLOT_CODE = SPEC_CODE
1814
1814
1815 self.FTP_WEI = None
1815 self.FTP_WEI = None
1816 self.EXP_CODE = None
1816 self.EXP_CODE = None
1817 self.SUB_EXP_CODE = None
1817 self.SUB_EXP_CODE = None
1818 self.PLOT_POS = None
1818 self.PLOT_POS = None
1819
1819
1820 self.__xfilter_ena = False
1820 self.__xfilter_ena = False
1821 self.__yfilter_ena = False
1821 self.__yfilter_ena = False
1822
1822
1823 def getSubplots(self):
1823 def getSubplots(self):
1824
1824
1825 ncol = 3
1825 ncol = 3
1826 nrow = int(numpy.ceil(self.nplots/3.0))
1826 nrow = int(numpy.ceil(self.nplots/3.0))
1827
1827
1828 return nrow, ncol
1828 return nrow, ncol
1829
1829
1830 def setup(self, id, nplots, wintitle, show=True):
1830 def setup(self, id, nplots, wintitle, show=True):
1831
1831
1832 self.nplots = nplots
1832 self.nplots = nplots
1833
1833
1834 ncolspan = 1
1834 ncolspan = 1
1835 colspan = 1
1835 colspan = 1
1836
1836
1837 self.createFigure(id = id,
1837 self.createFigure(id = id,
1838 wintitle = wintitle,
1838 wintitle = wintitle,
1839 widthplot = self.WIDTH + self.WIDTHPROF,
1839 widthplot = self.WIDTH + self.WIDTHPROF,
1840 heightplot = self.HEIGHT + self.HEIGHTPROF,
1840 heightplot = self.HEIGHT + self.HEIGHTPROF,
1841 show=show)
1841 show=show)
1842
1842
1843 nrow, ncol = self.getSubplots()
1843 nrow, ncol = self.getSubplots()
1844
1844
1845 counter = 0
1845 counter = 0
1846 for y in range(nrow):
1846 for y in range(nrow):
1847 for x in range(ncol):
1847 for x in range(ncol):
1848
1848
1849 if counter >= self.nplots:
1849 if counter >= self.nplots:
1850 break
1850 break
1851
1851
1852 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1852 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1853
1853
1854 counter += 1
1854 counter += 1
1855
1855
1856 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
1856 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
1857 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
1857 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
1858 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
1858 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
1859 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1859 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1860 server=None, folder=None, username=None, password=None,
1860 server=None, folder=None, username=None, password=None,
1861 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
1861 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
1862 xaxis="frequency"):
1862 xaxis="frequency"):
1863
1863
1864 """
1864 """
1865
1865
1866 Input:
1866 Input:
1867 dataOut :
1867 dataOut :
1868 id :
1868 id :
1869 wintitle :
1869 wintitle :
1870 channelList :
1870 channelList :
1871 showProfile :
1871 showProfile :
1872 xmin : None,
1872 xmin : None,
1873 xmax : None,
1873 xmax : None,
1874 ymin : None,
1874 ymin : None,
1875 ymax : None,
1875 ymax : None,
1876 zmin : None,
1876 zmin : None,
1877 zmax : None
1877 zmax : None
1878 """
1878 """
1879 #SEPARAR EN DOS PLOTS
1879 #SEPARAR EN DOS PLOTS
1880 nParam = dataOut.data_param.shape[1] - 3
1880 nParam = dataOut.data_param.shape[1] - 3
1881
1881
1882 utctime = dataOut.data_param[0,0]
1882 utctime = dataOut.data_param[0,0]
1883 tmet = dataOut.data_param[:,1].astype(int)
1883 tmet = dataOut.data_param[:,1].astype(int)
1884 hmet = dataOut.data_param[:,2].astype(int)
1884 hmet = dataOut.data_param[:,2].astype(int)
1885
1885
1886 x = dataOut.abscissaList
1886 x = dataOut.abscissaList
1887 y = dataOut.heightList
1887 y = dataOut.heightList
1888
1888
1889 z = numpy.zeros((nParam, y.size, x.size - 1))
1889 z = numpy.zeros((nParam, y.size, x.size - 1))
1890 z[:,:] = numpy.nan
1890 z[:,:] = numpy.nan
1891 z[:,hmet,tmet] = dataOut.data_param[:,3:].T
1891 z[:,hmet,tmet] = dataOut.data_param[:,3:].T
1892 z[0,:,:] = 10*numpy.log10(z[0,:,:])
1892 z[0,:,:] = 10*numpy.log10(z[0,:,:])
1893
1893
1894 xlabel = "Time (s)"
1894 xlabel = "Time (s)"
1895 ylabel = "Range (km)"
1895 ylabel = "Range (km)"
1896
1896
1897 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1897 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1898
1898
1899 if not self.isConfig:
1899 if not self.isConfig:
1900
1900
1901 nplots = nParam
1901 nplots = nParam
1902
1902
1903 self.setup(id=id,
1903 self.setup(id=id,
1904 nplots=nplots,
1904 nplots=nplots,
1905 wintitle=wintitle,
1905 wintitle=wintitle,
1906 show=show)
1906 show=show)
1907
1907
1908 if xmin is None: xmin = numpy.nanmin(x)
1908 if xmin is None: xmin = numpy.nanmin(x)
1909 if xmax is None: xmax = numpy.nanmax(x)
1909 if xmax is None: xmax = numpy.nanmax(x)
1910 if ymin is None: ymin = numpy.nanmin(y)
1910 if ymin is None: ymin = numpy.nanmin(y)
1911 if ymax is None: ymax = numpy.nanmax(y)
1911 if ymax is None: ymax = numpy.nanmax(y)
1912 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
1912 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
1913 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
1913 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
1914 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
1914 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
1915 if vmin is None: vmin = -vmax
1915 if vmin is None: vmin = -vmax
1916 if wmin is None: wmin = 0
1916 if wmin is None: wmin = 0
1917 if wmax is None: wmax = 50
1917 if wmax is None: wmax = 50
1918
1918
1919 pairsList = dataOut.groupList
1919 pairsList = dataOut.groupList
1920 self.nPairs = len(dataOut.groupList)
1920 self.nPairs = len(dataOut.groupList)
1921
1921
1922 zminList = [SNRmin, vmin, cmin] + [pmin]*self.nPairs
1922 zminList = [SNRmin, vmin, cmin] + [pmin]*self.nPairs
1923 zmaxList = [SNRmax, vmax, cmax] + [pmax]*self.nPairs
1923 zmaxList = [SNRmax, vmax, cmax] + [pmax]*self.nPairs
1924 titleList = ["SNR","Radial Velocity","Coherence"]
1924 titleList = ["SNR","Radial Velocity","Coherence"]
1925 cmapList = ["jet","RdBu_r","jet"]
1925 cmapList = ["jet","RdBu_r","jet"]
1926
1926
1927 for i in range(self.nPairs):
1927 for i in range(self.nPairs):
1928 strAux1 = "Phase Difference "+ str(pairsList[i][0]) + str(pairsList[i][1])
1928 strAux1 = "Phase Difference "+ str(pairsList[i][0]) + str(pairsList[i][1])
1929 titleList = titleList + [strAux1]
1929 titleList = titleList + [strAux1]
1930 cmapList = cmapList + ["RdBu_r"]
1930 cmapList = cmapList + ["RdBu_r"]
1931
1931
1932 self.zminList = zminList
1932 self.zminList = zminList
1933 self.zmaxList = zmaxList
1933 self.zmaxList = zmaxList
1934 self.cmapList = cmapList
1934 self.cmapList = cmapList
1935 self.titleList = titleList
1935 self.titleList = titleList
1936
1936
1937 self.FTP_WEI = ftp_wei
1937 self.FTP_WEI = ftp_wei
1938 self.EXP_CODE = exp_code
1938 self.EXP_CODE = exp_code
1939 self.SUB_EXP_CODE = sub_exp_code
1939 self.SUB_EXP_CODE = sub_exp_code
1940 self.PLOT_POS = plot_pos
1940 self.PLOT_POS = plot_pos
1941
1941
1942 self.isConfig = True
1942 self.isConfig = True
1943
1943
1944 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
1944 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
1945
1945
1946 for i in range(nParam):
1946 for i in range(nParam):
1947 title = self.titleList[i] + ": " +str_datetime
1947 title = self.titleList[i] + ": " +str_datetime
1948 axes = self.axesList[i]
1948 axes = self.axesList[i]
1949 axes.pcolor(x, y, z[i,:].T,
1949 axes.pcolor(x, y, z[i,:].T,
1950 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
1950 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
1951 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
1951 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
1952 self.draw()
1952 self.draw()
1953
1953
1954 if figfile == None:
1954 if figfile == None:
1955 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1955 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1956 name = str_datetime
1956 name = str_datetime
1957 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1957 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1958 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
1958 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
1959 figfile = self.getFilename(name)
1959 figfile = self.getFilename(name)
1960
1960
1961 self.save(figpath=figpath,
1961 self.save(figpath=figpath,
1962 figfile=figfile,
1962 figfile=figfile,
1963 save=save,
1963 save=save,
1964 ftp=ftp,
1964 ftp=ftp,
1965 wr_period=wr_period,
1965 wr_period=wr_period,
1966 thisDatetime=thisDatetime)
1966 thisDatetime=thisDatetime)
1967
1967
1968
1968
1969 class NSMeteorDetection2Plot(Figure):
1969 class NSMeteorDetection2Plot(Figure):
1970
1970
1971 isConfig = None
1971 isConfig = None
1972 __nsubplots = None
1972 __nsubplots = None
1973
1973
1974 WIDTHPROF = None
1974 WIDTHPROF = None
1975 HEIGHTPROF = None
1975 HEIGHTPROF = None
1976 PREFIX = 'nsm'
1976 PREFIX = 'nsm'
1977
1977
1978 zminList = None
1978 zminList = None
1979 zmaxList = None
1979 zmaxList = None
1980 cmapList = None
1980 cmapList = None
1981 titleList = None
1981 titleList = None
1982 nPairs = None
1982 nPairs = None
1983 nChannels = None
1983 nChannels = None
1984 nParam = None
1984 nParam = None
1985
1985
1986 def __init__(self, **kwargs):
1986 def __init__(self, **kwargs):
1987 Figure.__init__(self, **kwargs)
1987 Figure.__init__(self, **kwargs)
1988 self.isConfig = False
1988 self.isConfig = False
1989 self.__nsubplots = 1
1989 self.__nsubplots = 1
1990
1990
1991 self.WIDTH = 750
1991 self.WIDTH = 750
1992 self.HEIGHT = 250
1992 self.HEIGHT = 250
1993 self.WIDTHPROF = 120
1993 self.WIDTHPROF = 120
1994 self.HEIGHTPROF = 0
1994 self.HEIGHTPROF = 0
1995 self.counter_imagwr = 0
1995 self.counter_imagwr = 0
1996
1996
1997 self.PLOT_CODE = SPEC_CODE
1997 self.PLOT_CODE = SPEC_CODE
1998
1998
1999 self.FTP_WEI = None
1999 self.FTP_WEI = None
2000 self.EXP_CODE = None
2000 self.EXP_CODE = None
2001 self.SUB_EXP_CODE = None
2001 self.SUB_EXP_CODE = None
2002 self.PLOT_POS = None
2002 self.PLOT_POS = None
2003
2003
2004 self.__xfilter_ena = False
2004 self.__xfilter_ena = False
2005 self.__yfilter_ena = False
2005 self.__yfilter_ena = False
2006
2006
2007 def getSubplots(self):
2007 def getSubplots(self):
2008
2008
2009 ncol = 3
2009 ncol = 3
2010 nrow = int(numpy.ceil(self.nplots/3.0))
2010 nrow = int(numpy.ceil(self.nplots/3.0))
2011
2011
2012 return nrow, ncol
2012 return nrow, ncol
2013
2013
2014 def setup(self, id, nplots, wintitle, show=True):
2014 def setup(self, id, nplots, wintitle, show=True):
2015
2015
2016 self.nplots = nplots
2016 self.nplots = nplots
2017
2017
2018 ncolspan = 1
2018 ncolspan = 1
2019 colspan = 1
2019 colspan = 1
2020
2020
2021 self.createFigure(id = id,
2021 self.createFigure(id = id,
2022 wintitle = wintitle,
2022 wintitle = wintitle,
2023 widthplot = self.WIDTH + self.WIDTHPROF,
2023 widthplot = self.WIDTH + self.WIDTHPROF,
2024 heightplot = self.HEIGHT + self.HEIGHTPROF,
2024 heightplot = self.HEIGHT + self.HEIGHTPROF,
2025 show=show)
2025 show=show)
2026
2026
2027 nrow, ncol = self.getSubplots()
2027 nrow, ncol = self.getSubplots()
2028
2028
2029 counter = 0
2029 counter = 0
2030 for y in range(nrow):
2030 for y in range(nrow):
2031 for x in range(ncol):
2031 for x in range(ncol):
2032
2032
2033 if counter >= self.nplots:
2033 if counter >= self.nplots:
2034 break
2034 break
2035
2035
2036 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
2036 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
2037
2037
2038 counter += 1
2038 counter += 1
2039
2039
2040 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
2040 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
2041 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
2041 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
2042 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
2042 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
2043 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
2043 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
2044 server=None, folder=None, username=None, password=None,
2044 server=None, folder=None, username=None, password=None,
2045 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
2045 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
2046 xaxis="frequency"):
2046 xaxis="frequency"):
2047
2047
2048 """
2048 """
2049
2049
2050 Input:
2050 Input:
2051 dataOut :
2051 dataOut :
2052 id :
2052 id :
2053 wintitle :
2053 wintitle :
2054 channelList :
2054 channelList :
2055 showProfile :
2055 showProfile :
2056 xmin : None,
2056 xmin : None,
2057 xmax : None,
2057 xmax : None,
2058 ymin : None,
2058 ymin : None,
2059 ymax : None,
2059 ymax : None,
2060 zmin : None,
2060 zmin : None,
2061 zmax : None
2061 zmax : None
2062 """
2062 """
2063 #Rebuild matrix
2063 #Rebuild matrix
2064 utctime = dataOut.data_param[0,0]
2064 utctime = dataOut.data_param[0,0]
2065 cmet = dataOut.data_param[:,1].astype(int)
2065 cmet = dataOut.data_param[:,1].astype(int)
2066 tmet = dataOut.data_param[:,2].astype(int)
2066 tmet = dataOut.data_param[:,2].astype(int)
2067 hmet = dataOut.data_param[:,3].astype(int)
2067 hmet = dataOut.data_param[:,3].astype(int)
2068
2068
2069 nParam = 3
2069 nParam = 3
2070 nChan = len(dataOut.groupList)
2070 nChan = len(dataOut.groupList)
2071 x = dataOut.abscissaList
2071 x = dataOut.abscissaList
2072 y = dataOut.heightList
2072 y = dataOut.heightList
2073
2073
2074 z = numpy.full((nChan, nParam, y.size, x.size - 1),numpy.nan)
2074 z = numpy.full((nChan, nParam, y.size, x.size - 1),numpy.nan)
2075 z[cmet,:,hmet,tmet] = dataOut.data_param[:,4:]
2075 z[cmet,:,hmet,tmet] = dataOut.data_param[:,4:]
2076 z[:,0,:,:] = 10*numpy.log10(z[:,0,:,:]) #logarithmic scale
2076 z[:,0,:,:] = 10*numpy.log10(z[:,0,:,:]) #logarithmic scale
2077 z = numpy.reshape(z, (nChan*nParam, y.size, x.size-1))
2077 z = numpy.reshape(z, (nChan*nParam, y.size, x.size-1))
2078
2078
2079 xlabel = "Time (s)"
2079 xlabel = "Time (s)"
2080 ylabel = "Range (km)"
2080 ylabel = "Range (km)"
2081
2081
2082 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
2082 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
2083
2083
2084 if not self.isConfig:
2084 if not self.isConfig:
2085
2085
2086 nplots = nParam*nChan
2086 nplots = nParam*nChan
2087
2087
2088 self.setup(id=id,
2088 self.setup(id=id,
2089 nplots=nplots,
2089 nplots=nplots,
2090 wintitle=wintitle,
2090 wintitle=wintitle,
2091 show=show)
2091 show=show)
2092
2092
2093 if xmin is None: xmin = numpy.nanmin(x)
2093 if xmin is None: xmin = numpy.nanmin(x)
2094 if xmax is None: xmax = numpy.nanmax(x)
2094 if xmax is None: xmax = numpy.nanmax(x)
2095 if ymin is None: ymin = numpy.nanmin(y)
2095 if ymin is None: ymin = numpy.nanmin(y)
2096 if ymax is None: ymax = numpy.nanmax(y)
2096 if ymax is None: ymax = numpy.nanmax(y)
2097 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
2097 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
2098 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
2098 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
2099 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
2099 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
2100 if vmin is None: vmin = -vmax
2100 if vmin is None: vmin = -vmax
2101 if wmin is None: wmin = 0
2101 if wmin is None: wmin = 0
2102 if wmax is None: wmax = 50
2102 if wmax is None: wmax = 50
2103
2103
2104 self.nChannels = nChan
2104 self.nChannels = nChan
2105
2105
2106 zminList = []
2106 zminList = []
2107 zmaxList = []
2107 zmaxList = []
2108 titleList = []
2108 titleList = []
2109 cmapList = []
2109 cmapList = []
2110 for i in range(self.nChannels):
2110 for i in range(self.nChannels):
2111 strAux1 = "SNR Channel "+ str(i)
2111 strAux1 = "SNR Channel "+ str(i)
2112 strAux2 = "Radial Velocity Channel "+ str(i)
2112 strAux2 = "Radial Velocity Channel "+ str(i)
2113 strAux3 = "Spectral Width Channel "+ str(i)
2113 strAux3 = "Spectral Width Channel "+ str(i)
2114
2114
2115 titleList = titleList + [strAux1,strAux2,strAux3]
2115 titleList = titleList + [strAux1,strAux2,strAux3]
2116 cmapList = cmapList + ["jet","RdBu_r","jet"]
2116 cmapList = cmapList + ["jet","RdBu_r","jet"]
2117 zminList = zminList + [SNRmin,vmin,wmin]
2117 zminList = zminList + [SNRmin,vmin,wmin]
2118 zmaxList = zmaxList + [SNRmax,vmax,wmax]
2118 zmaxList = zmaxList + [SNRmax,vmax,wmax]
2119
2119
2120 self.zminList = zminList
2120 self.zminList = zminList
2121 self.zmaxList = zmaxList
2121 self.zmaxList = zmaxList
2122 self.cmapList = cmapList
2122 self.cmapList = cmapList
2123 self.titleList = titleList
2123 self.titleList = titleList
2124
2124
2125 self.FTP_WEI = ftp_wei
2125 self.FTP_WEI = ftp_wei
2126 self.EXP_CODE = exp_code
2126 self.EXP_CODE = exp_code
2127 self.SUB_EXP_CODE = sub_exp_code
2127 self.SUB_EXP_CODE = sub_exp_code
2128 self.PLOT_POS = plot_pos
2128 self.PLOT_POS = plot_pos
2129
2129
2130 self.isConfig = True
2130 self.isConfig = True
2131
2131
2132 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
2132 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
2133
2133
2134 for i in range(self.nplots):
2134 for i in range(self.nplots):
2135 title = self.titleList[i] + ": " +str_datetime
2135 title = self.titleList[i] + ": " +str_datetime
2136 axes = self.axesList[i]
2136 axes = self.axesList[i]
2137 axes.pcolor(x, y, z[i,:].T,
2137 axes.pcolor(x, y, z[i,:].T,
2138 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
2138 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
2139 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
2139 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
2140 self.draw()
2140 self.draw()
2141
2141
2142 if figfile == None:
2142 if figfile == None:
2143 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
2143 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
2144 name = str_datetime
2144 name = str_datetime
2145 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
2145 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
2146 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
2146 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
2147 figfile = self.getFilename(name)
2147 figfile = self.getFilename(name)
2148
2148
2149 self.save(figpath=figpath,
2149 self.save(figpath=figpath,
2150 figfile=figfile,
2150 figfile=figfile,
2151 save=save,
2151 save=save,
2152 ftp=ftp,
2152 ftp=ftp,
2153 wr_period=wr_period,
2153 wr_period=wr_period,
2154 thisDatetime=thisDatetime)
2154 thisDatetime=thisDatetime)
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: 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: 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 was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now