Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
Oceano2python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
US191
Oceano2python
Commits
8f66044f
Commit
8f66044f
authored
3 years ago
by
jacques.grelet_ird.fr
Browse files
Options
Downloads
Patches
Plain Diff
move gui code into process_gui
parent
823ba89e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
oceano.py
+99
-89
99 additions, 89 deletions
oceano.py
with
99 additions
and
89 deletions
oceano.py
+
99
−
89
View file @
8f66044f
...
...
@@ -61,7 +61,7 @@ def processArgs():
parser
.
add_argument
(
'
-g
'
,
'
--gui
'
,
action
=
'
store_true
'
,
help
=
'
use GUI interface
'
)
# type=argparse.FileType('r') don't work with under DOS
parser
.
add_argument
(
'
files
'
,
nargs
=
'
+
'
,
parser
.
add_argument
(
'
files
'
,
nargs
=
'
*
'
,
help
=
'
ASCII file(s) to parse
'
)
return
parser
...
...
@@ -72,7 +72,9 @@ def processArgs():
def
defineGUI
():
'''
function to define and create the graphical interface, written with PySimpleGUI
'''
# check if GUI config file exist
if
args
.
instrument
!=
None
:
instrument_default_value
=
args
.
instrument
...
...
@@ -116,9 +118,10 @@ def defineGUI():
return
window
def
updateFilesBrowseCombo
(
extentions
,
x
,
y
):
'''
# special function used to update the FilesBrowseCombo with canvas poisition
# instead of key because the same key is assign to shadow input object
def
updateFilesBrowseCombo
(
window
,
extentions
,
x
,
y
):
'''
special function used to update the FilesBrowseCombo with canvas poisition
instead of key because the same key is assign to shadow input object
'''
e
=
window
.
Rows
[
x
][
y
]
# hardcoded
e
.
FileTypes
=
[]
# init to empty list
...
...
@@ -128,93 +131,15 @@ def updateFilesBrowseCombo(extentions, x, y):
e
.
initial_folder
=
'
data/{}
'
.
format
(
extentions
[
0
])
window
.
Finalize
def
process
(
args
,
cfg
,
ti
):
'''
Extract data from ASCII files and return FileExtractor instannce and array size of extracted data
Parameters
----------
args : ConfigParser
cfg : dict
toml instance describing the file structure to decode
ti : str {
'
CNV
'
,
'
XBT
'
,
'
LADCP
'
,
'
TSG
'
,}
The typeInstrument key
Returns
-------
fe: FileExtractor
n, m: array size
'''
print
(
'
processing...
'
)
# check if no file selected or cancel button pressed
logging
.
debug
(
"
File(s): {}, config: {}, Keys: {}
"
.
format
(
args
.
files
,
args
.
config
,
args
.
keys
))
# if physical parameters are not given from cmd line, option -k, use the toml <device>.split values
if
args
.
keys
==
None
:
args
.
keys
=
cfg
[
'
split
'
][
device
.
lower
()].
keys
()
# extract header and data from files
fe
=
FileExtractor
(
args
.
files
,
r
,
args
.
keys
)
# prepare (compile) each regular expression inside toml file under section [<device=ti>.header]
fe
.
set_regex
(
cfg
,
ti
)
# the first pass skip headers and return data dimensions size
fe
.
first_pass
()
# fe.secondPass(['PRES', 'TEMP', 'PSAL', 'DOX2'], cfg, 'ctd')
fe
.
second_pass
(
cfg
,
ti
,
variables_1D
)
# fe.disp(['PRES', 'TEMP', 'PSAL', 'DOX2'])
return
fe
if
__name__
==
"
__main__
"
:
'''
usage:
> python oceano.py data/CTD/cnv/dfr2900[1-3].cnv -i CTD
> python oceano.py data/CTD/cnv/dfr29*.cnv -i CTD -k PRES TEMP PSAL DOX2 DENS -d
'''
# recover and process line arguments
parser
=
processArgs
()
args
=
parser
.
parse_args
()
# if not args.files:
# print('Ok')
# parser.print_usage()
# sys.exit(EXIT_FAILURE)
# set looging mode if debug
if
args
.
debug
:
logging
.
basicConfig
(
format
=
'
%(levelname)s:%(message)s
'
,
level
=
logging
.
DEBUG
)
# read config Toml file and get the physical parameter list (Roscop code) for the specified instrument
cfg
=
toml
.
load
(
args
.
config
)
# this the select device from command line !
device
=
str
(
args
.
instrument
)
# convert one element list to str
# get roscop file
if
cfg
[
'
global
'
][
'
codeRoscop
'
]
!=
None
:
defaultRoscop
=
Path
(
cfg
[
'
global
'
][
'
codeRoscop
'
])
if
args
.
roscop
!=
None
:
defaultRoscop
=
args
.
roscop
r
=
Roscop
(
defaultRoscop
)
# test arguements from sys.argv, args is never to None with default option set
if
args
.
gui
or
len
(
sys
.
argv
)
==
1
:
# setup the GUI windows Layout
def
process_gui
():
# setup the GUI windows Layout
window
=
defineGUI
()
device
=
window
.
find_element
(
'
_DEVICE_
'
).
DefaultValue
keys
=
cfg
[
'
split
'
][
device
.
lower
()].
keys
()
# can't update combo with FindElement('_HIDDEN_').Update(), we use this function
# with hardcoded FilesBrowseCombo position
updateFilesBrowseCombo
(
updateFilesBrowseCombo
(
window
,
ti
[
device
],
filesBrowsePosition_column
,
filesBrowsePosition_row
)
# set the rigth frame for device visible, dosn't work
...
...
@@ -253,7 +178,7 @@ if __name__ == "__main__":
# you have to go into the bowels of the pygi code, to get the instance of the Combo
# by the line and column number of the window to update its "fileType" property.
device
=
values
[
'
_DEVICE_
'
]
updateFilesBrowseCombo
(
updateFilesBrowseCombo
(
window
,
ti
[
device
],
filesBrowsePosition_column
,
filesBrowsePosition_row
)
# TODOS: reset checkbox
...
...
@@ -292,6 +217,89 @@ if __name__ == "__main__":
# or
# print = sg.Print(size=(80,40))
return
window
,
fe
,
device
def
process
(
args
,
cfg
,
ti
):
'''
Extract data from ASCII files and return FileExtractor instannce and array size of extracted data
Parameters
----------
args : ConfigParser
cfg : dict
toml instance describing the file structure to decode
ti : str {
'
CNV
'
,
'
XBT
'
,
'
LADCP
'
,
'
TSG
'
,}
The typeInstrument key
Returns
-------
fe: FileExtractor
n, m: array size
'''
print
(
'
processing...
'
)
# check if no file selected or cancel button pressed
logging
.
debug
(
"
File(s): {}, config: {}, Keys: {}
"
.
format
(
args
.
files
,
args
.
config
,
args
.
keys
))
# if physical parameters are not given from cmd line, option -k, use the toml <device>.split values
if
args
.
keys
==
None
:
args
.
keys
=
cfg
[
'
split
'
][
device
.
lower
()].
keys
()
# extract header and data from files
fe
=
FileExtractor
(
args
.
files
,
r
,
args
.
keys
)
# prepare (compile) each regular expression inside toml file under section [<device=ti>.header]
fe
.
set_regex
(
cfg
,
ti
)
# the first pass skip headers and return data dimensions size
fe
.
first_pass
()
# fe.secondPass(['PRES', 'TEMP', 'PSAL', 'DOX2'], cfg, 'ctd')
fe
.
second_pass
(
cfg
,
ti
,
variables_1D
)
# fe.disp(['PRES', 'TEMP', 'PSAL', 'DOX2'])
return
fe
if
__name__
==
"
__main__
"
:
'''
usage:
> python oceano.py data/CTD/cnv/dfr2900[1-3].cnv -i CTD
> python oceano.py data/CTD/cnv/dfr29*.cnv -i CTD -k PRES TEMP PSAL DOX2 DENS -d
'''
# recover and process line arguments
parser
=
processArgs
()
args
=
parser
.
parse_args
()
# if not args.files:
# print('Ok')
# parser.print_usage()
# sys.exit(EXIT_FAILURE)
# set looging mode if debug
if
args
.
debug
:
logging
.
basicConfig
(
format
=
'
%(levelname)s:%(message)s
'
,
level
=
logging
.
DEBUG
)
# read config Toml file and get the physical parameter list (Roscop code) for the specified instrument
cfg
=
toml
.
load
(
args
.
config
)
# this the select device from command line !
device
=
str
(
args
.
instrument
)
# convert one element list to str
# get roscop file
if
cfg
[
'
global
'
][
'
codeRoscop
'
]
!=
None
:
defaultRoscop
=
Path
(
cfg
[
'
global
'
][
'
codeRoscop
'
])
if
args
.
roscop
!=
None
:
defaultRoscop
=
args
.
roscop
r
=
Roscop
(
defaultRoscop
)
# test arguments from sys.argv, args is never to None with default option set
if
args
.
gui
or
len
(
sys
.
argv
)
==
1
:
# define graphical interface
window
,
fe
,
device
=
process_gui
()
else
:
# demo mode, only in command line
if
args
.
demo
!=
None
:
...
...
@@ -322,9 +330,11 @@ if __name__ == "__main__":
#print("Dimensions: {} x {}".format(fe.m, fe.n))
# print(fe.disp())
# write ASCII hdr and data files
ascii
.
writeAscii
(
cfg
,
device
,
fe
,
r
,
variables_1D
)
# write the NetCDF file
netcdf
.
writeNetCDF
(
cfg
,
device
,
fe
,
r
,
variables_1D
)
# write ASCII hdr and data files
ascii
.
writeAscii
(
cfg
,
device
,
fe
,
r
,
variables_1D
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment