Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
VERIFY
CIF
Commits
89f59960
Commit
89f59960
authored
Feb 04, 2020
by
Espen Sollum
Browse files
Issue with string.split()
parent
3f1b90fc
Changes
3
Hide whitespace changes
Inline
Side-by-side
pycif/plugins/obsparsers/wdcgg/headers.py
View file @
89f59960
...
...
@@ -3,7 +3,6 @@
from
__future__
import
print_function
from
__future__
import
absolute_import
from
.utils
import
remap_extract
,
find_header
import
string
import
pycif.utils.check
as
check
...
...
@@ -32,7 +31,7 @@ def get_header(obs_file, maxlen):
return
lines
if
'HEADER LINES'
in
line
:
nheader
=
int
(
str
in
g
.
split
(
line
,
':'
)[
1
])
nheader
=
int
(
l
in
e
.
split
(
':'
)[
1
])
if
len
(
lines
)
>
maxlen
:
break
...
...
@@ -44,7 +43,7 @@ def get_header(obs_file, maxlen):
# on the first line of the document
if
nheader
==
0
:
try
:
nheader
=
int
(
string
.
split
(
lines
[
0
])[
1
])
nheader
=
int
(
lines
[
0
]
.
split
(
)[
1
])
except
:
raise
ValueError
(
"More than {} Header Lines in WDCGG File. "
\
...
...
@@ -78,7 +77,7 @@ def parse_header(header, spec, list_extract,
"""
# Minimize all characters to facilitate comparisons
head
=
[
s
.
lower
()
for
s
in
string
.
split
(
header
[
-
1
])[
1
:]]
head
=
[
s
.
lower
()
for
s
in
header
[
-
1
]
.
split
(
)[
1
:]]
# Parsing time information
try
:
...
...
pycif/plugins/obsparsers/wdcgg/utils.py
View file @
89f59960
# -*- coding: utf-8 -*-
from
__future__
import
absolute_import
import
string
import
os
from
dateutil.tz
import
tzoffset
import
numpy
as
np
...
...
@@ -39,7 +38,8 @@ def find_header(id_extract, header):
for
ln
in
header
:
if
remap_head
(
id_extract
)
in
ln
.
lower
():
value
=
string
.
split
(
ln
.
lower
(),
':'
)[
1
].
strip
()
# value = string.split(ln.lower(), ':')[1].strip()
value
=
ln
.
lower
().
split
(
':'
)[
1
].
strip
()
try
:
return
float
(
value
)
except
ValueError
:
...
...
@@ -96,7 +96,7 @@ def parse_file(obs_file):
http://ds.data.jma.go.jp/gmd/wdcgg/pub/data/WDCGG_filename_format.pdf
"""
filesplit
=
string
.
split
(
os
.
path
.
basename
(
obs_file
)
,
'.'
)
filesplit
=
os
.
path
.
basename
(
obs_file
)
.
split
(
'.'
)
infos
=
{}
infos
[
'stat'
]
=
filesplit
[
0
][:
3
]
...
...
pycif/utils/dates.py
View file @
89f59960
from
builtins
import
zip
import
datetime
import
numpy
as
np
import
pandas
as
pd
...
...
@@ -48,7 +49,7 @@ def date_range(datei, datef, period='1000000H', subperiod=''):
return
np
.
array
(
list_dates
)
# Otherwise, split simulation window along base periods
d
ate_
range
=
pd
.
date_range
(
datei
,
datef
,
freq
=
period
)
drange
=
pd
.
date_range
(
datei
,
datef
,
freq
=
period
)
# If period is longer than the length of the simulation window,
# returns a very far away end date
...
...
@@ -56,20 +57,20 @@ def date_range(datei, datef, period='1000000H', subperiod=''):
# This is done in case the last time stamp should be use
# for interpolation in the last hours of the run
if
datei
+
pd
.
to_timedelta
(
period
)
>
datef
:
return
d
ate_
range
.
union
([
d
ate_
range
[
-
1
]
+
pd
.
to_timedelta
(
period
)])
\
.
to_pydatetime
()
return
drange
.
union
([
drange
[
-
1
]
+
pd
.
to_timedelta
(
period
)])
\
.
to_series
().
dt
.
to_pydatetime
()
else
:
d
ate_
range
=
d
ate_
range
.
union
([
datef
])
drange
=
drange
.
union
([
datef
])
# One can specify sub-periods to split main periods
if
subperiod
==
''
:
list_dates
=
d
ate_
range
.
to_pydatetime
()
list_dates
=
drange
.
to_series
().
dt
.
to_pydatetime
()
else
:
list_dates
=
[]
for
d0
,
d1
in
zip
(
d
ate_
range
[:
-
1
],
d
ate_
range
[
1
:]):
for
d0
,
d1
in
zip
(
drange
[:
-
1
],
drange
[
1
:]):
drange
=
pd
.
date_range
(
d0
,
d1
,
freq
=
subperiod
.
format
(
period
))
list_dates
.
extend
(
drange
.
to_pydatetime
())
list_dates
.
extend
(
drange
.
to_
series
().
dt
.
to_
pydatetime
())
if
datef
not
in
list_dates
:
list_dates
.
append
(
datef
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment