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
fdde2570
Commit
fdde2570
authored
2 years ago
by
Jacques Grelet
Browse files
Options
Downloads
Patches
Plain Diff
add station extraction number from file name
parent
9f15bfc7
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
config.toml
+2
-0
2 additions, 0 deletions
config.toml
profile.py
+20
-3
20 additions, 3 deletions
profile.py
with
22 additions
and
3 deletions
config.toml
+
2
−
0
View file @
fdde2570
...
@@ -87,6 +87,8 @@ julianOrigin = 1
...
@@ -87,6 +87,8 @@ julianOrigin = 1
[btl]
[btl]
cruisePrefix
=
"fr29"
stationPrefixLength
=
3
typeInstrument
=
"SBE32 standard 24 Niskin bottles"
typeInstrument
=
"SBE32 standard 24 Niskin bottles"
instrumentNumber
=
"unknown"
instrumentNumber
=
"unknown"
titleSummary
=
"Water sample during PIRATA-FR32 cruise with 22 levels"
titleSummary
=
"Water sample during PIRATA-FR32 cruise with 22 levels"
...
...
This diff is collapsed.
Click to expand it.
profile.py
+
20
−
3
View file @
fdde2570
...
@@ -246,14 +246,31 @@ class Profile:
...
@@ -246,14 +246,31 @@ class Profile:
if
'
julianOrigin
'
in
cfg
[
device
.
lower
()]:
if
'
julianOrigin
'
in
cfg
[
device
.
lower
()]:
self
.
__julianOrigin
=
cfg
[
device
.
lower
()][
'
julianOrigin
'
]
self
.
__julianOrigin
=
cfg
[
device
.
lower
()][
'
julianOrigin
'
]
# prepare the regex to extract station number from filename
# by default, station or profile number is extract from the filename
if
'
cruisePrefix
'
in
cfg
[
device
.
lower
()]:
cruisePrefix
=
cfg
[
device
.
lower
()][
'
cruisePrefix
'
]
print
(
cruisePrefix
)
if
'
stationPrefixLength
'
in
cfg
[
device
.
lower
()]:
stationPrefixLength
=
cfg
[
device
.
lower
()][
'
stationPrefixLength
'
]
print
(
stationPrefixLength
)
station_regex
=
re
.
compile
(
f
"
{
cruisePrefix
}
(\d{{
{
stationPrefixLength
}
}})
"
)
# read each file and extract header and data and fill sqlite tables
# read each file and extract header and data and fill sqlite tables
for
file
in
self
.
fname
:
for
file
in
self
.
fname
:
process_header
=
False
process_header
=
False
process_data
=
False
process_data
=
False
station
=
[]
sql
=
{}
# by default, station or profile number is extract from the filename
if
station_regex
.
search
(
file
):
[
station
]
=
station_regex
.
search
(
file
).
groups
()
sql
[
'
station
'
]
=
int
(
station
)
logging
.
debug
(
f
"
Station match:
{
sql
[
'
station
'
]
}
"
)
with
fileinput
.
input
(
with
fileinput
.
input
(
file
,
openhook
=
fileinput
.
hook_encoded
(
"
ISO-8859-1
"
))
as
f
:
file
,
openhook
=
fileinput
.
hook_encoded
(
"
ISO-8859-1
"
))
as
f
:
sql
=
{}
self
.
__header
=
''
self
.
__header
=
''
print
(
f
"
Reading file:
{
file
}
"
)
print
(
f
"
Reading file:
{
file
}
"
)
# read all lines in file
# read all lines in file
...
@@ -284,7 +301,7 @@ class Profile:
...
@@ -284,7 +301,7 @@ class Profile:
# toml file, section [device.header]
# toml file, section [device.header]
for
k
in
self
.
__regex
.
keys
():
for
k
in
self
.
__regex
.
keys
():
# extract STATION number
# extract STATION number
if [device][header][station] is defined
if
k
==
"
station
"
and
self
.
__regex
[
k
].
search
(
self
.
__header
):
if
k
==
"
station
"
and
self
.
__regex
[
k
].
search
(
self
.
__header
):
[
station
]
=
self
.
__regex
[
k
].
search
(
self
.
__header
).
groups
()
[
station
]
=
self
.
__regex
[
k
].
search
(
self
.
__header
).
groups
()
#print("station: {}, type: {}".format(station, type(station)))
#print("station: {}, type: {}".format(station, type(station)))
...
...
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