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
4fa5b00a
Commit
4fa5b00a
authored
6 years ago
by
jacques.grelet_ird.fr
Browse files
Options
Downloads
Patches
Plain Diff
PopupScrolled
parent
b32dc5f4
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
docs/Readme-Python.txt
+12
-1
12 additions, 1 deletion
docs/Readme-Python.txt
file_extractor.py
+9
-4
9 additions, 4 deletions
file_extractor.py
oceano.py
+106
-87
106 additions, 87 deletions
oceano.py
with
128 additions
and
92 deletions
.gitignore
+
1
−
0
View file @
4fa5b00a
/.vscode
.vscode
.vstags
*.exe
*.o
*.a
...
...
This diff is collapsed.
Click to expand it.
docs/Readme-Python.txt
+
12
−
1
View file @
4fa5b00a
...
...
@@ -532,4 +532,15 @@ assertAlmostEqual()
assertNotAlmostEqual()
assertRegex()
assertNotRegex()
assertRaisesRegex()
\ No newline at end of file
assertRaisesRegex()
Git:
-------
Pour mettre à jour le depot distant après l'avoir créé sur github.com
> git pull origin master --allow-unrelated-histories
From https://github.com/jgrelet/oceano2python
* branch master -> FETCH_HEAD
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
This diff is collapsed.
Click to expand it.
file_extractor.py
+
9
−
4
View file @
4fa5b00a
...
...
@@ -36,9 +36,14 @@ class FileExtractor:
return
'
Class FileExtractor, file: %s, size = %d
'
%
(
self
.
files
,
len
(
self
))
def
disp
(
self
,
keys
):
# for key in keys:
# print("{}:".format(key))
# print(self.__data[key])
buf
=
''
for
key
in
keys
:
print
(
"
{}:
"
.
format
(
key
))
print
(
self
.
__data
[
key
])
buf
+=
"
{}:
\n
"
.
format
(
key
)
buf
+=
"
{}
\n
"
.
format
(
self
.
__data
[
key
])
return
buf
# first pass on file(s)
def
firstPass
(
self
):
...
...
@@ -140,6 +145,6 @@ if __name__ == "__main__":
[
n
,
m
]
=
fe
.
firstPass
()
print
(
"
Indices:
"
,
n
,
m
)
fe
.
secondPass
(
args
.
key
,
cfg
,
'
ctd
'
)
#fe.secondPass(['PRES', 'TEMP', 'PSAL', 'DOX2'], cdf, 'ctd')
#
fe.secondPass(['PRES', 'TEMP', 'PSAL', 'DOX2'], cdf, 'ctd')
fe
.
disp
(
args
.
key
)
#fe.disp(['PRES', 'TEMP', 'PSAL', 'DOX2'])
#
fe.disp(['PRES', 'TEMP', 'PSAL', 'DOX2'])
This diff is collapsed.
Click to expand it.
oceano.py
+
106
−
87
View file @
4fa5b00a
...
...
@@ -10,90 +10,109 @@ from configparser import ConfigParser
import
os
import
distutils.util
as
du
# usage:
# > python oceano.py data/cnv/dfr2900[1-3].cnv -d
# > python oceano.py data/cnv/dfr2900[1-3].cnv -k PRES TEMP PSAL DOX2 DENS
# > python oceano.py data/cnv/dfr29*.cnv -d
parser
=
argparse
.
ArgumentParser
(
description
=
'
This program read multiple ASCII file, extract physical parameter
\
following ROSCOP codification at the given column, fill arrays, write header file
'
,
epilog
=
'
J. Grelet IRD US191 - March 2019
'
)
parser
.
add_argument
(
'
-d
'
,
'
--debug
'
,
help
=
'
display debug informations
'
,
action
=
'
store_true
'
)
parser
.
add_argument
(
'
-c
'
,
'
--config
'
,
help
=
"
toml configuration file, (default: %(default)s)
"
,
default
=
'
tests/test.toml
'
)
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)
'
)
args
=
parser
.
parse_args
()
# initialize filename use to save GUI configuration
configfile
=
'
oceano.cfg
'
# 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, Roscop code
cfg
=
toml
.
load
(
args
.
config
)
keys
=
cfg
[
'
split
'
][
'
ctd
'
].
keys
()
# test arguements from sys.argv, args is never to None with default option set
if
args
.
gui
or
args
.
debug
or
len
(
sys
.
argv
)
==
1
:
# change look and feel color scheme
sg
.
ChangeLookAndFeel
(
'
SandyBeach
'
)
# define GUI layout
layout
=
([[
sg
.
Text
(
'
File(s) to read and convert
'
)],
[
sg
.
FilesBrowse
(
key
=
'
_FILE
'
,
initial_folder
=
'
data/cnv
'
,
file_types
=
((
"
cnv files
"
,
"
*.cnv
"
),))],
*
[[
sg
.
Checkbox
(
k
,
key
=
k
)]
for
k
in
keys
],
[
sg
.
CloseButton
(
'
Run
'
),
sg
.
CloseButton
(
'
Cancel
'
)]])
# create a local instance windows used to reload the saved config from file
window
=
sg
.
Window
(
'
Oceano converter
'
).
Layout
(
layout
)
window
.
LoadFromDisk
(
configfile
)
# display the main windows
event
,
values
=
window
.
Read
()
# save program configuration
window
.
SaveToDisk
(
configfile
)
# debug return values from GUI
logging
.
debug
(
"
Event: {}, Values: {}
"
.
format
(
event
,
values
))
# extract selected parameters (true) from dict values
new_values
=
values
.
copy
()
for
k
in
values
.
keys
():
if
k
==
'
_FILE
'
or
values
[
k
]
==
False
:
del
new_values
[
k
]
args
.
key
=
new_values
.
keys
()
# values['_FILE'] is a string with files separated by ';' and fileExtractor need a list
files
=
values
[
'
_FILE
'
].
split
(
'
;
'
)
args
.
files
=
files
else
:
# in command line mode (console)
args
.
files
# check if no file selected or cancel button pressed
logging
.
debug
(
"
File(s): {}, config: {}, Keys: {}
"
.
format
(
args
.
files
,
args
.
config
,
args
.
key
))
if
not
all
(
args
.
files
):
sg
.
Popup
(
"
Cancel
"
,
"
No filename supplied
"
)
raise
SystemExit
(
"
Cancelling: no filename supplied
"
)
# fileExtractor
fe
=
FileExtractor
(
args
.
files
)
# cfg = toml.load(args.config)
[
n
,
m
]
=
fe
.
firstPass
()
fe
.
secondPass
(
args
.
key
,
cfg
,
'
ctd
'
)
# fe.secondPass(['PRES', 'TEMP', 'PSAL', 'DOX2'], cdf, 'ctd')
fe
.
disp
(
args
.
key
)
# fe.disp(['PRES', 'TEMP', 'PSAL', 'DOX2'])
def
process
(
args
,
cfg
,
type
):
# check if no file selected or cancel button pressed
logging
.
debug
(
"
File(s): {}, config: {}, Keys: {}
"
.
format
(
args
.
files
,
args
.
config
,
args
.
key
))
# fileExtractor
fe
=
FileExtractor
(
args
.
files
)
# cfg = toml.load(args.config)
[
n
,
m
]
=
fe
.
firstPass
()
fe
.
secondPass
(
args
.
key
,
cfg
,
type
)
# fe.secondPass(['PRES', 'TEMP', 'PSAL', 'DOX2'], cdf, 'ctd')
# fe.disp(['PRES', 'TEMP', 'PSAL', 'DOX2'])
return
fe
,
n
,
m
if
__name__
==
"
__main__
"
:
'''
usage:
> python oceano.py data/cnv/dfr2900[1-3].cnv -d
> python oceano.py data/cnv/dfr2900[1-3].cnv -k PRES TEMP PSAL DOX2 DENS
> python oceano.py data/cnv/dfr29*.cnv -d
'''
parser
=
argparse
.
ArgumentParser
(
description
=
'
This program read multiple ASCII file, extract physical parameter
\
following ROSCOP codification at the given column, fill arrays, write header file
'
,
epilog
=
'
J. Grelet IRD US191 - March 2019
'
)
parser
.
add_argument
(
'
-d
'
,
'
--debug
'
,
help
=
'
display debug informations
'
,
action
=
'
store_true
'
)
parser
.
add_argument
(
'
-c
'
,
'
--config
'
,
help
=
"
toml configuration file, (default: %(default)s)
"
,
default
=
'
tests/test.toml
'
)
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)
'
)
args
=
parser
.
parse_args
()
# initialize filename use to save GUI configuration
configfile
=
'
oceano.cfg
'
# 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, Roscop code
cfg
=
toml
.
load
(
args
.
config
)
keys
=
cfg
[
'
split
'
][
'
ctd
'
].
keys
()
# test arguements from sys.argv, args is never to None with default option set
if
args
.
gui
or
args
.
debug
or
len
(
sys
.
argv
)
==
1
:
# change look and feel color scheme
sg
.
ChangeLookAndFeel
(
'
SandyBeach
'
)
# define GUI layout
layout
=
([[
sg
.
Text
(
'
File(s) to read and convert
'
)],
[
sg
.
FilesBrowse
(
key
=
'
_FILE
'
,
initial_folder
=
'
data/cnv
'
,
file_types
=
((
"
cnv files
"
,
"
*.cnv
"
),))],
*
[[
sg
.
Checkbox
(
k
,
key
=
k
)]
for
k
in
keys
],
[
sg
.
CloseButton
(
'
Run
'
),
sg
.
CloseButton
(
'
Cancel
'
)]])
# create a local instance windows used to reload the saved config from file
window
=
sg
.
Window
(
'
Oceano converter
'
).
Layout
(
layout
)
window
.
LoadFromDisk
(
configfile
)
# display the main windows
event
,
values
=
window
.
Read
()
# save program configuration
window
.
SaveToDisk
(
configfile
)
# debug return values from GUI
logging
.
debug
(
"
Event: {}, Values: {}
"
.
format
(
event
,
values
))
# extract selected parameters (true) from dict values
new_values
=
values
.
copy
()
for
k
in
values
.
keys
():
if
k
==
'
_FILE
'
or
values
[
k
]
==
False
:
del
new_values
[
k
]
args
.
key
=
new_values
.
keys
()
# values['_FILE'] is a string with files separated by ';' and fileExtractor need a list
files
=
values
[
'
_FILE
'
].
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
,
'
ctd
'
)
# display result in popup GUI
dims
=
"
Dimensions: {} x {}
"
.
format
(
m
,
n
)
sg
.
PopupScrolled
(
'
Oceano2python
'
,
dims
,
fe
.
disp
(
args
.
key
),
size
=
(
50
,
60
))
else
:
# in command line mode (console)
fe
,
n
,
m
=
process
(
args
,
cfg
,
'
ctd
'
)
print
(
"
Dimensions: {} x {}
"
.
format
(
m
,
n
))
print
(
fe
.
disp
(
args
.
key
))
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