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
f865945d
Commit
f865945d
authored
5 years ago
by
jacques.grelet_ird.fr
Browse files
Options
Downloads
Patches
Plain Diff
to many change
parent
8afef4ec
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
file_extractor.py
+2
-2
2 additions, 2 deletions
file_extractor.py
oceano.py
+58
-46
58 additions, 46 deletions
oceano.py
with
60 additions
and
48 deletions
file_extractor.py
+
2
−
2
View file @
f865945d
...
@@ -69,7 +69,7 @@ class FileExtractor:
...
@@ -69,7 +69,7 @@ class FileExtractor:
for
file
in
self
.
fname
:
for
file
in
self
.
fname
:
with
fileinput
.
input
(
with
fileinput
.
input
(
file
.
name
,
openhook
=
fileinput
.
hook_encoded
(
"
ISO-8859-1
"
))
as
f
:
file
,
openhook
=
fileinput
.
hook_encoded
(
"
ISO-8859-1
"
))
as
f
:
filesRead
+=
1
filesRead
+=
1
for
line
in
f
:
for
line
in
f
:
if
line
[
0
]
==
'
#
'
or
line
[
0
]
==
'
*
'
:
if
line
[
0
]
==
'
#
'
or
line
[
0
]
==
'
*
'
:
...
@@ -123,7 +123,7 @@ class FileExtractor:
...
@@ -123,7 +123,7 @@ class FileExtractor:
for
file
in
self
.
fname
:
for
file
in
self
.
fname
:
with
fileinput
.
input
(
with
fileinput
.
input
(
file
.
name
,
openhook
=
fileinput
.
hook_encoded
(
"
ISO-8859-1
"
))
as
f
:
file
,
openhook
=
fileinput
.
hook_encoded
(
"
ISO-8859-1
"
))
as
f
:
for
line
in
f
:
for
line
in
f
:
if
f
.
filelineno
()
<
self
.
__skip_header
+
1
:
if
f
.
filelineno
()
<
self
.
__skip_header
+
1
:
continue
continue
...
...
This diff is collapsed.
Click to expand it.
oceano.py
+
58
−
46
View file @
f865945d
...
@@ -14,6 +14,8 @@ import distutils.util as du
...
@@ -14,6 +14,8 @@ import distutils.util as du
typeInstrument
=
{
'
CTD
'
:
(
'
cnv
'
,
'
CNV
'
),
'
XBT
'
:
(
typeInstrument
=
{
'
CTD
'
:
(
'
cnv
'
,
'
CNV
'
),
'
XBT
'
:
(
'
EDF
'
,
'
edf
'
),
'
LADCP
'
:
(
'
lad
'
,
'
LAD
'
),
'
TSG
'
:
'
COLCOR
'
}
'
EDF
'
,
'
edf
'
),
'
LADCP
'
:
(
'
lad
'
,
'
LAD
'
),
'
TSG
'
:
'
COLCOR
'
}
ti
=
typeInstrument
# an alias
ti
=
typeInstrument
# an alias
filesBrowsePosition_row
=
2
filesBrowsePosition_column
=
1
def
processArgs
():
def
processArgs
():
...
@@ -22,18 +24,18 @@ def processArgs():
...
@@ -22,18 +24,18 @@ def processArgs():
following ROSCOP codification at the given column, fill arrays, write header file
'
,
following ROSCOP codification at the given column, fill arrays, write header file
'
,
usage
=
'
\n
python oceano.py data/CTD/cnv/dfr2900[1-3].cnv -i CTD -d
\n
'
usage
=
'
\n
python oceano.py data/CTD/cnv/dfr2900[1-3].cnv -i CTD -d
\n
'
'
python oceano.py data/CTD/cnv/dfr2900[1-3].cnv -i CTD -k PRES TEMP PSAL DOX2 DENS
\n
'
'
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/CTDcnv/dfr29*.cnv
-i CTD
-d
\n
'
'
python oceano.py data/XBT/T7_0000*.EDF -i XBT -k DEPTH TEMP SVEL
\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
\n
'
'
python oceano.py data/LADCP/*.lad - i LADCP - k DEPTH EWCT NSCT
\n
'
'
\n
'
,
'
\n
'
,
epilog
=
'
J. Grelet IRD US191 - March 2019
'
)
epilog
=
'
J. Grelet IRD US191 - March 2019
'
)
parser
.
add_argument
(
'
-d
'
,
'
--debug
'
,
help
=
'
display debug informations
'
,
parser
.
add_argument
(
'
-d
'
,
'
--debug
'
,
help
=
'
display debug informations
'
,
action
=
'
store_true
'
)
action
=
'
store_true
'
)
parser
.
add_argument
(
'
--demo
'
,
nargs
=
'
?
'
,
parser
.
add_argument
(
'
--demo
'
,
nargs
=
'
?
'
,
choices
=
ti
.
keys
(),
help
=
'
specify the commande line for instrument, eg CTD, XBT, TSG, LADCP
'
)
help
=
'
specify the commande line for instrument, eg CTD, XBT, TSG, LADCP
'
)
parser
.
add_argument
(
'
-c
'
,
'
--config
'
,
help
=
"
toml configuration file, (default: %(default)s)
"
,
parser
.
add_argument
(
'
-c
'
,
'
--config
'
,
help
=
"
toml configuration file, (default: %(default)s)
"
,
default
=
'
tests/test.toml
'
)
default
=
'
tests/test.toml
'
)
parser
.
add_argument
(
'
-i
'
,
'
--instrument
'
,
nargs
=
'
?
'
,
parser
.
add_argument
(
'
-i
'
,
'
--instrument
'
,
nargs
=
'
?
'
,
choices
=
ti
.
keys
(),
help
=
'
specify the instrument that produce files, eg CTD, XBT, TSG, LADCP
'
)
help
=
'
specify the instrument that produce files, eg CTD, XBT, TSG, LADCP
'
)
parser
.
add_argument
(
'
-k
'
,
'
--key
'
,
nargs
=
'
+
'
,
default
=
[
'
PRES
'
,
'
TEMP
'
,
'
PSAL
'
],
parser
.
add_argument
(
'
-k
'
,
'
--key
'
,
nargs
=
'
+
'
,
default
=
[
'
PRES
'
,
'
TEMP
'
,
'
PSAL
'
],
help
=
'
display dictionary for key(s), (default: %(default)s)
'
)
help
=
'
display dictionary for key(s), (default: %(default)s)
'
)
...
@@ -61,32 +63,23 @@ def defineGUI():
...
@@ -61,32 +63,23 @@ def defineGUI():
# define a frame layout for each instrument (device)
# define a frame layout for each instrument (device)
for
d
in
devices
:
for
d
in
devices
:
keys
=
cfg
[
'
split
'
][
d
.
lower
()].
keys
()
keys
=
cfg
[
'
split
'
][
d
.
lower
()].
keys
()
frameLayout
[
d
]
=
[
*
[[
sg
.
Checkbox
(
k
,
key
=
k
,
# List comprehensions
tooltip
=
'
Select the extract the physical parameter {}
'
.
format
(
k
))]
for
k
in
keys
]]
frameLayout
[
d
]
=
[[
sg
.
Checkbox
(
k
,
key
=
k
,
# for d in devices:
tooltip
=
'
Select the extract the physical parameter {}
'
.
format
(
k
))]
for
k
in
keys
]
# deviceLayout[d] = [sg.Frame(d, frameLayout[d])]
# define GUI layout
# define GUI layout
layout
=
([[
sg
.
Text
(
'
File(s) to read and convert
'
)],
layout
=
([[
sg
.
Text
(
'
File(s) to read and convert
'
)],
# row 0
[
sg
.
Multiline
(
size
=
(
40
,
5
),
key
=
'
_IN_
'
),
[
sg
.
Multiline
(
size
=
(
40
,
5
),
key
=
'
_IN_
'
),
# row 1, col 0
sg
.
Input
(
key
=
'
_HIDDEN_
'
,
visible
=
False
,
sg
.
Input
(
key
=
'
_HIDDEN_
'
,
visible
=
False
,
# row 1, col 1
enable_events
=
True
),
enable_events
=
True
),
sg
.
FilesBrowse
(
key
=
'
_HIDDEN_
'
,
sg
.
FilesBrowse
(
key
=
'
_HIDDEN_
'
,
initial_folder
=
None
,
# row 1, col 2
tooltip
=
'
Choose one or more files
'
,
tooltip
=
'
Choose one or more files
'
)],
initial_folder
=
'
data/{}
'
.
format
(
ti
[
device
][
0
]))],
[
sg
.
Combo
(
list
(
ti
.
keys
()),
enable_events
=
True
,
size
=
(
8
,
1
),
# row 2
[
sg
.
Combo
(
list
(
ti
.
keys
()),
enable_events
=
True
,
size
=
(
8
,
1
),
key
=
'
_COMBO_
'
,
tooltip
=
'
Select the instrument
'
)],
key
=
'
_COMBO_
'
,
tooltip
=
'
Select the instrument
'
)],
# [[sg.Frame(d, frameLayout[d])] for d in devices],
[
sg
.
Frame
(
d
,
frameLayout
[
d
],
key
=
'
_FRAME_{:s}
'
.
format
(
d
)
,
visible
=
True
)
# row 3
# for d in devices],
for
d
in
devices
],
[
sg
.
Frame
(
'
CTD
'
,
frameLayout
[
'
CTD
'
],
key
=
'
_FRAME_CTD
'
,
visible
=
False
),
[
sg
.
OK
(),
sg
.
CloseButton
(
'
Cancel
'
)]])
# row 4
sg
.
Frame
(
'
XBT
'
,
frameLayout
[
'
XBT
'
],
# [sg.CloseButton('Run'), sg.CloseButton('Cancel')]])
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')]])
# create a local instance windows used to reload the saved config from file
# create a local instance windows used to reload the saved config from file
window
=
sg
.
Window
(
'
Oceano converter
'
).
Layout
(
layout
)
window
=
sg
.
Window
(
'
Oceano converter
'
).
Layout
(
layout
)
...
@@ -95,11 +88,16 @@ def defineGUI():
...
@@ -95,11 +88,16 @@ def defineGUI():
return
window
return
window
def
updateFilesBrowseCombo
(
extentions
):
def
updateFilesBrowseCombo
(
extentions
,
x
,
y
):
e
=
window
.
Rows
[
1
][
2
]
# hardcoded
'''
# special function used to update the FilesBrowseCombo with canvas poisition
e
.
FileTypes
=
[]
# init to empty list
# 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
for
ext
in
extentions
:
for
ext
in
extentions
:
e
.
FileTypes
.
append
((
"
{} files
"
.
format
(
ext
),
"
*.{}
"
.
format
(
ext
)))
e
.
FileTypes
.
append
((
"
{} files
"
.
format
(
ext
),
"
*.{}
"
.
format
(
ext
)))
e
.
initial_folder
=
'
data/{}
'
.
format
(
extentions
[
0
])
window
.
Finalize
window
.
Finalize
...
@@ -159,12 +157,6 @@ if __name__ == "__main__":
...
@@ -159,12 +157,6 @@ if __name__ == "__main__":
cfg
=
toml
.
load
(
args
.
config
)
cfg
=
toml
.
load
(
args
.
config
)
# this the select device from command line !
# this the select device from command line !
device
=
str
(
args
.
instrument
)
# convert one element list to str
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
# test arguements from sys.argv, args is never to None with default option set
if
args
.
gui
or
len
(
sys
.
argv
)
==
1
:
if
args
.
gui
or
len
(
sys
.
argv
)
==
1
:
...
@@ -172,15 +164,21 @@ if __name__ == "__main__":
...
@@ -172,15 +164,21 @@ if __name__ == "__main__":
# setup the GUI windows Layout
# setup the GUI windows Layout
window
=
defineGUI
()
window
=
defineGUI
()
device
=
window
.
FindElement
(
'
_COMBO_
'
).
DefaultValue
device
=
window
.
FindElement
(
'
_COMBO_
'
).
DefaultValue
updateFilesBrowseCombo
(
ti
[
device
])
keys
=
cfg
[
'
split
'
][
device
.
lower
()].
keys
()
# get all devices
# can't update combo with FindElement('_HIDDEN_').Update(), we use this function
# with hardcoded FilesBrowseCombo position
for
d
in
list
(
ti
.
keys
()):
updateFilesBrowseCombo
(
frame
=
'
_FRAME_
'
+
d
ti
[
device
],
filesBrowsePosition_column
,
filesBrowsePosition_row
)
print
(
frame
)
if
d
==
device
:
# set the rigth frame for device visible, dosn't work
print
(
d
)
# File "C:\git\python\PySimpleGUI\PySimpleGUI.py", line 2362, in Update
window
.
FindElement
(
frame
).
Update
(
visible
=
True
)
# self.TKFrame.pack()
# AttributeError: 'NoneType' object has no attribute 'pack'
# for d in list(ti.keys()):
# print(d)
# if d == device:
# window.FindElement(
# '_FRAME_{:s}'.format(d)).Update(visible=True)
# main GUI loop
# main GUI loop
while
True
:
while
True
:
...
@@ -199,14 +197,15 @@ if __name__ == "__main__":
...
@@ -199,14 +197,15 @@ if __name__ == "__main__":
# test if a or more file are selected
# test if a or more file are selected
if
not
all
(
args
.
files
):
if
not
all
(
args
.
files
):
sg
.
Popup
(
"
Cancel
"
,
"
No filename supplied
"
)
sg
.
Popup
(
"
Cancel
"
,
"
No filename supplied
"
)
#raise SystemExit("Cancelling: no filename supplied")
#
raise SystemExit("Cancelling: no filename supplied")
continue
continue
break
break
if
event
is
'
_COMBO_
'
:
if
event
is
'
_COMBO_
'
:
# you have to go into the bowels of the pygi code, to get the instance of the Combo
# 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.
# by the line and column number of the window to update its "fileType" property.
updateFilesBrowseCombo
(
ti
[
values
[
'
_COMBO_
'
]])
updateFilesBrowseCombo
(
ti
[
values
[
'
_COMBO_
'
]],
filesBrowsePosition_column
,
filesBrowsePosition_row
)
# update the Multilines instance from FilesBrowse return
# update the Multilines instance from FilesBrowse return
if
event
is
'
_HIDDEN_
'
:
if
event
is
'
_HIDDEN_
'
:
...
@@ -247,9 +246,22 @@ if __name__ == "__main__":
...
@@ -247,9 +246,22 @@ if __name__ == "__main__":
# test if a or more file are selected
# test if a or more file are selected
else
:
else
:
if
args
.
files
==
[]:
if
args
.
files
==
[]:
print
(
'
You need to specify one or more files to process !!!
'
,
end
=
'
\n\n
'
)
print
(
'
Error, you need to specify one or more files to process !!!
'
,
end
=
'
\n\n
'
)
parser
.
print_help
(
sys
.
stderr
)
parser
.
print_help
(
sys
.
stderr
)
sys
.
exit
(
1
)
sys
.
exit
(
1
)
else
:
files
=
[]
for
f
in
args
.
files
:
files
.
append
(
f
.
name
)
args
.
files
=
files
if
device
==
'
None
'
:
print
(
'
Error: missing option -i or --instrument, instrument = {}
\n
'
.
format
(
device
))
parser
.
print_help
(
sys
.
stderr
)
sys
.
exit
(
1
)
keys
=
cfg
[
'
split
'
][
device
.
lower
()].
keys
()
# in command line mode (console)
# in command line mode (console)
fe
,
n
,
m
=
process
(
args
,
cfg
,
device
)
fe
,
n
,
m
=
process
(
args
,
cfg
,
device
)
print
(
"
Dimensions: {} x {}
"
.
format
(
m
,
n
))
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