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
d58df64f
Commit
d58df64f
authored
6 years ago
by
jacques.grelet_ird.fr
Browse files
Options
Downloads
Patches
Plain Diff
first test with XBT
parent
2dec9f6d
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
docs/Readme-Python.txt
+7
-1
7 additions, 1 deletion
docs/Readme-Python.txt
file_extractor.py
+49
-14
49 additions, 14 deletions
file_extractor.py
oceano.py
+24
-15
24 additions, 15 deletions
oceano.py
tests/test.toml
+1
-1
1 addition, 1 deletion
tests/test.toml
with
81 additions
and
31 deletions
docs/Readme-Python.txt
+
7
−
1
View file @
d58df64f
...
...
@@ -31,13 +31,19 @@ D={}
D={'un': 1, "deux: 2}
D['un']
1
D.has_key(
'deux'
)
'deux'
in D
True
D.keys()
['un', 'deux']
D.values()
[1,2]
len(D)
Return the number of items in the dictionary d.
d[key]
Return the item of d with key key. Raises a KeyError if key is not in the map.
d[key] = value
Set d[key] to value.
...
...
This diff is collapsed.
Click to expand it.
file_extractor.py
+
49
−
14
View file @
d58df64f
...
...
@@ -13,27 +13,35 @@ class FileExtractor:
'''
This class read multiple ASCII file, extract physical parameter from ROSCOP codification at the given column
and fill arrays
and fill arrays.
Parameters
----------
fname : file, str, pathlib.Path, list of str
File, filename, or list to read.
skip_header : int, optional
The number of lines to skip at the beginning of the file.
'''
# constructor with values by default
def
__init__
(
self
,
f
iles
):
def
__init__
(
self
,
f
name
,
skip_header
=
0
):
# attibutes
# public:
self
.
f
iles
=
files
self
.
f
name
=
fname
self
.
n
=
0
self
.
m
=
0
# replace this constante with roscop fill value
self
.
FillValue
=
1e36
# private:
self
.
__headeer
=
{}
self
.
skip_header
=
skip_header
self
.
__header
=
{}
self
.
__data
=
{}
# overloading operators
def
__str__
(
self
):
'''
overload string representation
'''
return
'
Class FileExtractor, file: %s, size = %d
'
%
(
self
.
f
iles
,
len
(
self
))
return
'
Class FileExtractor, file: %s, size = %d
'
%
(
self
.
f
name
,
len
(
self
))
def
disp
(
self
,
keys
):
# for key in keys:
...
...
@@ -47,11 +55,17 @@ class FileExtractor:
# first pass on file(s)
def
firstPass
(
self
):
'''
Returns
------
out : [n,m]
The size of array.
'''
lineRead
=
0
filesRead
=
0
indMax
=
0
for
file
in
self
.
f
iles
:
for
file
in
self
.
f
name
:
with
fileinput
.
input
(
file
,
openhook
=
fileinput
.
hook_encoded
(
"
ISO-8859-1
"
))
as
f
:
filesRead
+=
1
...
...
@@ -73,13 +87,32 @@ class FileExtractor:
self
.
m
=
indMax
return
self
.
n
,
self
.
m
# second pass, extract data from roscop code in files and fill array
def
secondPass
(
self
,
keys
,
cfg
,
type
):
# second pass, extract data from roscop code in fname and fill array
def
secondPass
(
self
,
keys
,
cfg
,
device
):
'''
Read the file to its internal dict
Parameters
----------
keys: sequence, a list of physical parameter to read.
ex: [
'
PRES
'
,
'
TEMP
'
,
'
PSAL
'
]
cfg: toml.load() instance, configuration file
device: str, instrument
ex: CTD,XBT or LADCP
'''
n
=
0
m
=
0
# get the dictionary from toml block, type instrument is in lower case
hash
=
cfg
[
'
split
'
][
type
.
lower
()]
#print(device, cfg[device.lower()])
print
(
device
)
# set skip_header is declared in toml section, 0 by default
if
'
skikHeader
'
in
cfg
[
device
.
lower
()]:
self
.
skip_header
=
cfg
[
device
.
lower
()][
'
skipHeader
'
]
#
logging
.
debug
(
self
.
skip_header
)
# get the dictionary from toml block, device must be is in lower case
hash
=
cfg
[
'
split
'
][
device
.
lower
()]
# initialize arrays, move at the end of firstPass ?
for
key
in
keys
:
...
...
@@ -87,10 +120,12 @@ class FileExtractor:
# the shape parameter has to be an int or sequence of ints
self
.
__data
[
key
]
=
np
.
ones
((
self
.
n
,
self
.
m
))
*
self
.
FillValue
for
file
in
self
.
f
iles
:
for
file
in
self
.
f
name
:
with
fileinput
.
input
(
file
,
openhook
=
fileinput
.
hook_encoded
(
"
ISO-8859-1
"
))
as
f
:
for
line
in
f
:
if
f
.
filelineno
()
<
self
.
skip_header
+
1
:
continue
if
line
[
0
]
==
'
#
'
or
line
[
0
]
==
'
*
'
:
continue
# split the line
...
...
@@ -129,7 +164,7 @@ if __name__ == "__main__":
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
(
'
f
iles
'
,
nargs
=
'
*
'
,
parser
.
add_argument
(
'
f
name
'
,
nargs
=
'
*
'
,
help
=
'
cnv file(s) to parse, (default: data/cnv/dfr29*.cnv)
'
)
# display extra logging info
...
...
@@ -140,8 +175,8 @@ if __name__ == "__main__":
logging
.
basicConfig
(
format
=
'
%(levelname)s:%(message)s
'
,
level
=
logging
.
DEBUG
)
fe
=
FileExtractor
(
args
.
f
iles
)
print
(
"
File(s): {}, Config: {}
"
.
format
(
args
.
f
iles
,
args
.
config
))
fe
=
FileExtractor
(
args
.
f
name
)
print
(
"
File(s): {}, Config: {}
"
.
format
(
args
.
f
name
,
args
.
config
))
cfg
=
toml
.
load
(
args
.
config
)
[
n
,
m
]
=
fe
.
firstPass
()
print
(
"
Indices:
"
,
n
,
m
)
...
...
This diff is collapsed.
Click to expand it.
oceano.py
+
24
−
15
View file @
d58df64f
...
...
@@ -51,13 +51,17 @@ def process(args, cfg, ti):
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
> python oceano.py data/
CTD/
cnv/dfr2900[1-3].cnv -d
> python oceano.py data/
CTD/
cnv/dfr2900[1-3].cnv -k PRES TEMP PSAL DOX2 DENS
> python oceano.py data/
CTD/
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
'
,
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
'
'
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_000*.cnv -i XBT -k DEPTH TEMP SVEL
\n
'
,
epilog
=
'
J. Grelet IRD US191 - March 2019
'
)
parser
.
add_argument
(
'
-d
'
,
'
--debug
'
,
help
=
'
display debug informations
'
,
action
=
'
store_true
'
)
...
...
@@ -83,8 +87,9 @@ if __name__ == "__main__":
# read config Toml file and get the physical parameter list (Roscop code) for the specified instrument
cfg
=
toml
.
load
(
args
.
config
)
instru
=
args
.
instrument
[
0
]
keys
=
cfg
[
'
split
'
][
instru
.
lower
()].
keys
()
device
=
str
(
args
.
instrument
[
0
])
# convert one element list to str
print
(
device
)
keys
=
cfg
[
'
split
'
][
device
.
lower
()].
keys
()
# test arguements from sys.argv, args is never to None with default option set
if
args
.
gui
or
len
(
sys
.
argv
)
==
1
:
...
...
@@ -99,11 +104,9 @@ if __name__ == "__main__":
enable_events
=
True
),
sg
.
FilesBrowse
(
key
=
'
_HIDDEN_
'
,
tooltip
=
'
Choose one or more files
'
,
initial_folder
=
'
data/{}
'
.
format
(
ti
[
instru
]),
file_types
=
((
"
{} files
"
.
format
(
ti
[
instru
]),
"
*.{}
"
.
format
(
ti
[
instru
])),))],
[
sg
.
Input
(
key
=
'
_COMBO_
'
,
visible
=
False
,
enable_events
=
True
),
sg
.
Combo
([
'
CTD
'
,
'
XBT
'
,
'
LADCP
'
,
'
TSG
'
],
initial_folder
=
'
data/{}
'
.
format
(
ti
[
device
]),
file_types
=
((
"
{} files
"
.
format
(
ti
[
device
]),
"
*.{}
"
.
format
(
ti
[
device
])),))],
[
sg
.
Combo
(
ti
.
keys
(),
enable_events
=
True
,
key
=
'
_COMBO_
'
,
tooltip
=
'
Select the instrument
'
)],
*
[[
sg
.
Checkbox
(
k
,
key
=
k
,
tooltip
=
'
Select the extract the physical parameter {}
'
.
format
(
k
))]
for
k
in
keys
],
...
...
@@ -119,7 +122,7 @@ if __name__ == "__main__":
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
"
)
...
...
@@ -128,8 +131,14 @@ if __name__ == "__main__":
break
if
event
is
'
_COMBO_
'
:
window
.
FindElement
(
'
_HIDDEN_
'
).
File_types
=
(
(
"
{} files
"
.
format
(
ti
[
values
[
'
_COMBO_
'
]]),
"
*.{}
"
.
format
(
ti
[
values
[
'
_COMBO_
'
]])),)
e
=
window
.
Rows
[
1
][
2
]
# print(e.FileTypes)
e
.
FileTypes
=
((
"
{} files
"
.
format
(
ti
[
values
[
'
_COMBO_
'
]]),
"
*.{}
"
.
format
(
ti
[
values
[
'
_COMBO_
'
]])),)
window
.
Finalize
# print(e.FileTypes)
# window.FindElement('_HIDDEN_').File_types = (
# ("{} files".format(ti[values['_COMBO_']]), "*.{}".format(ti[values['_COMBO_']])),)
if
event
is
'
_HIDDEN_
'
:
window
.
Element
(
'
_IN_
'
).
Update
(
...
...
@@ -177,6 +186,6 @@ if __name__ == "__main__":
parser
.
print_help
(
sys
.
stderr
)
sys
.
exit
(
1
)
# in command line mode (console)
fe
,
n
,
m
=
process
(
args
,
cfg
,
ti
[
instru
]
)
fe
,
n
,
m
=
process
(
args
,
cfg
,
device
)
print
(
"
Dimensions: {} x {}
"
.
format
(
m
,
n
))
print
(
fe
.
disp
(
args
.
key
))
This diff is collapsed.
Click to expand it.
tests/test.toml
+
1
−
1
View file @
d58df64f
...
...
@@ -41,7 +41,7 @@ comment = "CTD bottles water sampling with temperature, salinity and oxyg
cruisePrefix
=
"fr29"
stationPrefixLength
=
3
h
eader
=
40
skipH
eader
=
40
acquisitionSoftware
=
"WinMK21"
acquisitionVersion
=
"2.10.1"
processingSoftware
=
""
...
...
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