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
8afef4ec
Commit
8afef4ec
authored
5 years ago
by
jacques.grelet_ird.fr
Browse files
Options
Downloads
Patches
Plain Diff
test files existent with argparse
parent
ff642144
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
docs/Readme-Python.txt
+4
-1
4 additions, 1 deletion
docs/Readme-Python.txt
file_extractor.py
+2
-2
2 additions, 2 deletions
file_extractor.py
oceano.py
+59
-28
59 additions, 28 deletions
oceano.py
with
65 additions
and
31 deletions
docs/Readme-Python.txt
+
4
−
1
View file @
8afef4ec
...
...
@@ -544,6 +544,9 @@ Developpement:
Pour utiliser QT au lieu de Tk
> pip install PySimpleGUIQt
> pip install PySide2
> pip install PyAstronomy
> pip install sciPy
> pip install basemap
Puis remplacer le :
import PySimpleGUI as gs
...
...
@@ -606,4 +609,4 @@ From https://github.com/jgrelet/oceano2python
Merge made by the 'recursive' strategy.
README.md | 2 ++
1 file changed, 2 insertions(+)
create mode 100644 README.md
\ No newline at end of file
create mode 100644 README.md
This diff is collapsed.
Click to expand it.
file_extractor.py
+
2
−
2
View file @
8afef4ec
...
...
@@ -69,7 +69,7 @@ class FileExtractor:
for
file
in
self
.
fname
:
with
fileinput
.
input
(
file
,
openhook
=
fileinput
.
hook_encoded
(
"
ISO-8859-1
"
))
as
f
:
file
.
name
,
openhook
=
fileinput
.
hook_encoded
(
"
ISO-8859-1
"
))
as
f
:
filesRead
+=
1
for
line
in
f
:
if
line
[
0
]
==
'
#
'
or
line
[
0
]
==
'
*
'
:
...
...
@@ -123,7 +123,7 @@ class FileExtractor:
for
file
in
self
.
fname
:
with
fileinput
.
input
(
file
,
openhook
=
fileinput
.
hook_encoded
(
"
ISO-8859-1
"
))
as
f
:
file
.
name
,
openhook
=
fileinput
.
hook_encoded
(
"
ISO-8859-1
"
))
as
f
:
for
line
in
f
:
if
f
.
filelineno
()
<
self
.
__skip_header
+
1
:
continue
...
...
This diff is collapsed.
Click to expand it.
oceano.py
+
59
−
28
View file @
8afef4ec
import
argparse
import
sys
import
myPySimpleGUI
as
sg
#
import PySimpleGUI
Qt
as sg
#
import myPySimpleGUI as sg
import
PySimpleGUI
as
sg
import
toml
import
logging
from
file_extractor
import
FileExtractor
...
...
@@ -24,24 +24,30 @@ def processArgs():
'
python oceano.py data/CTD/cnv/dfr2900[1-3].cnv -i CTD -k PRES TEMP PSAL DOX2 DENS
\n
'
'
python oceano.py data/CTDcnv/dfr29*.cnv -d
\n
'
'
python oceano.py data/XBT/T7_0000*.EDF -i XBT -k DEPTH TEMP SVEL
\n
'
"
python oceano.py data/LADCP/*.lad -i LADCP -k DEPTH EWCT NSCT
"
,
'
python oceano.py data/LADCP/*.lad - i LADCP - k DEPTH EWCT NSCT
\n
'
'
\n
'
,
epilog
=
'
J. Grelet IRD US191 - March 2019
'
)
parser
.
add_argument
(
'
-d
'
,
'
--debug
'
,
help
=
'
display debug informations
'
,
action
=
'
store_true
'
)
parser
.
add_argument
(
'
--demo
'
,
nargs
=
'
?
'
,
default
=
'
CTD
'
,
help
=
'
specify the commande line for instrument, eg CTD, XBT, TSG, LADCP
(default: %(default)s)
'
)
parser
.
add_argument
(
'
--demo
'
,
nargs
=
'
?
'
,
help
=
'
specify the commande line for instrument, eg CTD, XBT, TSG, LADCP
'
)
parser
.
add_argument
(
'
-c
'
,
'
--config
'
,
help
=
"
toml configuration file, (default: %(default)s)
"
,
default
=
'
tests/test.toml
'
)
parser
.
add_argument
(
'
-i
'
,
'
--instrument
'
,
nargs
=
'
?
'
,
default
=
'
CTD
'
,
help
=
'
specify the instrument that produce files, eg CTD, XBT, TSG, LADCP
(default: %(default)s)
'
)
parser
.
add_argument
(
'
-i
'
,
'
--instrument
'
,
nargs
=
'
?
'
,
help
=
'
specify the instrument that produce files, eg CTD, XBT, TSG, LADCP
'
)
parser
.
add_argument
(
'
-k
'
,
'
--key
'
,
nargs
=
'
+
'
,
default
=
[
'
PRES
'
,
'
TEMP
'
,
'
PSAL
'
],
help
=
'
display dictionary for key(s), (default: %(default)s)
'
)
parser
.
add_argument
(
'
-g
'
,
'
--gui
'
,
action
=
'
store_true
'
,
help
=
'
use GUI interface
'
)
parser
.
add_argument
(
'
files
'
,
nargs
=
'
*
'
,
help
=
'
cnv
file(s) to parse
, (default: data/cnv/dfr29*.cnv)
'
)
parser
.
add_argument
(
'
files
'
,
nargs
=
'
*
'
,
type
=
argparse
.
FileType
(
'
r
'
,
encoding
=
'
ISO-8859-1
'
),
help
=
'
ASCII
file(s) to parse
'
)
return
parser
# TODOS:
# DEPTH is missing
# file name is not clear at startup
# if no file selected, don't leave the program
def
defineGUI
():
...
...
@@ -51,15 +57,14 @@ def defineGUI():
# change look and feel color scheme
sg
.
ChangeLookAndFeel
(
'
SandyBeach
'
)
frameLayout
=
{}
deviceLayout
=
[]
# define a frame layout for each instrument (device)
for
d
in
devices
:
keys
=
cfg
[
'
split
'
][
d
evice
.
lower
()].
keys
()
keys
=
cfg
[
'
split
'
][
d
.
lower
()].
keys
()
frameLayout
[
d
]
=
[
*
[[
sg
.
Checkbox
(
k
,
key
=
k
,
tooltip
=
'
Select the extract the physical parameter {}
'
.
format
(
k
))]
for
k
in
keys
]]
for
d
in
devices
:
deviceLayout
.
append
(
sg
.
Frame
(
d
,
frameLayout
[
d
])
)
#
for d in devices:
#
deviceLayout
[d] = [
sg.Frame(d, frameLayout[d])
]
# define GUI layout
layout
=
([[
sg
.
Text
(
'
File(s) to read and convert
'
)],
...
...
@@ -71,7 +76,15 @@ def defineGUI():
initial_folder
=
'
data/{}
'
.
format
(
ti
[
device
][
0
]))],
[
sg
.
Combo
(
list
(
ti
.
keys
()),
enable_events
=
True
,
size
=
(
8
,
1
),
key
=
'
_COMBO_
'
,
tooltip
=
'
Select the instrument
'
)],
[
deviceLayout
],
# [[sg.Frame(d, frameLayout[d])] for d in devices],
# for d in devices],
[
sg
.
Frame
(
'
CTD
'
,
frameLayout
[
'
CTD
'
],
key
=
'
_FRAME_CTD
'
,
visible
=
False
),
sg
.
Frame
(
'
XBT
'
,
frameLayout
[
'
XBT
'
],
key
=
'
_FRAME_XBT
'
,
visible
=
False
),
sg
.
Frame
(
'
LADCP
'
,
frameLayout
[
'
LADCP
'
],
key
=
'
_FRAME_LADCP
'
,
visible
=
False
),
sg
.
Frame
(
'
TSG
'
,
frameLayout
[
'
TSG
'
],
key
=
'
_FRAME_TSG
'
,
visible
=
False
)],
[
sg
.
OK
(),
sg
.
CloseButton
(
'
Cancel
'
)]])
# [sg.CloseButton('Run'), sg.CloseButton('Cancel')]])
...
...
@@ -146,6 +159,11 @@ if __name__ == "__main__":
cfg
=
toml
.
load
(
args
.
config
)
# this the select device from command line !
device
=
str
(
args
.
instrument
)
# convert one element list to str
if
device
==
'
None
'
:
print
(
'
Missing option --key or -k, key = {}
'
.
format
(
device
))
print
(
'
usage:
'
)
print
(
parser
.
usage
)
sys
.
exit
(
0
)
keys
=
cfg
[
'
split
'
][
device
.
lower
()].
keys
()
# test arguements from sys.argv, args is never to None with default option set
...
...
@@ -155,17 +173,34 @@ if __name__ == "__main__":
window
=
defineGUI
()
device
=
window
.
FindElement
(
'
_COMBO_
'
).
DefaultValue
updateFilesBrowseCombo
(
ti
[
device
])
# get all devices
for
d
in
list
(
ti
.
keys
()):
frame
=
'
_FRAME_
'
+
d
print
(
frame
)
if
d
==
device
:
print
(
d
)
window
.
FindElement
(
frame
).
Update
(
visible
=
True
)
# main GUI loop
while
True
:
# display the main windows
event
,
values
=
window
.
Read
()
#
print(event, values)
print
(
event
,
values
)
if
event
is
'
Cancel
'
or
event
==
None
:
raise
SystemExit
(
"
Cancelling: user exit
"
)
if
event
is
'
OK
'
:
# end of initialization, process data now
# values['_HIDDEN_'] is a string with files separated by ';' and fileExtractor need a list
files
=
values
[
'
_HIDDEN_
'
].
split
(
'
;
'
)
args
.
files
=
files
# test if a or more file are selected
if
not
all
(
args
.
files
):
sg
.
Popup
(
"
Cancel
"
,
"
No filename supplied
"
)
#raise SystemExit("Cancelling: no filename supplied")
continue
break
if
event
is
'
_COMBO_
'
:
...
...
@@ -191,15 +226,6 @@ if __name__ == "__main__":
del
new_values
[
k
]
args
.
key
=
new_values
.
keys
()
# values['_HIDDEN_'] is a string with files separated by ';' and fileExtractor need a list
files
=
values
[
'
_HIDDEN_
'
].
split
(
'
;
'
)
args
.
files
=
files
# test if a or more file are selected
if
not
all
(
args
.
files
):
sg
.
Popup
(
"
Cancel
"
,
"
No filename supplied
"
)
raise
SystemExit
(
"
Cancelling: no filename supplied
"
)
# process of files start here
fe
,
n
,
m
=
process
(
args
,
cfg
,
values
[
'
_COMBO_
'
])
...
...
@@ -214,11 +240,16 @@ if __name__ == "__main__":
# print = sg.Print(size=(80,40))
else
:
# test if a or more file are selected
if
args
.
files
==
[]:
print
(
'
You need to specify one or more files to process !!!
'
,
end
=
'
\n\n
'
)
parser
.
print_help
(
sys
.
stderr
)
# demo mode, only in command line
if
args
.
demo
!=
None
:
print
(
'
demo mode: {}
'
.
format
(
args
.
demo
))
sys
.
exit
(
1
)
# test if a or more file are selected
else
:
if
args
.
files
==
[]:
print
(
'
You need to specify one or more files to process !!!
'
,
end
=
'
\n\n
'
)
parser
.
print_help
(
sys
.
stderr
)
sys
.
exit
(
1
)
# in command line mode (console)
fe
,
n
,
m
=
process
(
args
,
cfg
,
device
)
print
(
"
Dimensions: {} x {}
"
.
format
(
m
,
n
))
...
...
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