Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Philipp Sommer
BSRN-conversion
Commits
d4174731
Commit
d4174731
authored
Jun 23, 2020
by
Philipp Sommer
Browse files
Include fill data
parent
4eede1e8
Changes
1
Hide whitespace changes
Inline
Side-by-side
meta/convert-metadata.py
View file @
d4174731
# coding: utf-8
import
pandas
as
pd
import
numpy
as
np
import
re
# read BSRN meta data file
df
=
pd
.
read_csv
(
'bsrn_stations.tab'
,
'
\t
'
,
encoding
=
'latin1'
)
staff
=
pd
.
read_csv
(
'bsrn_staffs.tab'
,
'
\t
'
,
encoding
=
'latin1'
)
df
=
pd
.
read_csv
(
'bsrn_stations.tab'
,
'
\t
'
)
staff
=
pd
.
read_csv
(
'bsrn_staffs.tab'
,
'
\t
'
)
mapping
=
pd
.
read_csv
(
'colnames-mapping-BG.csv'
,
index_col
=
0
)
staff
.
index
=
staff
[
'First name'
]
+
' '
+
staff
[
'Last name'
]
...
...
@@ -81,8 +82,23 @@ if 'Plain terrain, Soil type' in joined:
'Plain terrain, Soil type'
]
del
joined
[
'Plain terrain, Soil type'
]
if
'Station no'
in
joined
:
joined
.
loc
[
joined
[
'Station no'
].
notnull
(),
'BSRN Station no'
]
=
joined
.
loc
[
joined
[
'Station no'
].
notnull
(),
'Station no'
]
del
joined
[
'Station no'
]
ds
=
joined
.
set_index
(
'Event label'
).
to_xarray
()
insert_station_no_fill
=
False
if
'BSRN Station no'
in
joined
:
try
:
joined
[
'BSRN Station no'
]
=
joined
[
'BSRN Station no'
].
astype
(
int
)
except
ValueError
:
joined
[
'BSRN Station no'
]
=
joined
[
'BSRN Station no'
].
fillna
(
'-9999'
).
astype
(
int
)
insert_station_no_fill
=
True
joined
.
index
=
pd
.
Index
(
np
.
arange
(
1
,
len
(
joined
)
+
1
),
name
=
'stationid'
)
ds
=
joined
.
to_xarray
()
for
key
in
list
(
ds
.
variables
):
var
=
ds
[
key
]
...
...
@@ -105,7 +121,12 @@ for key, var in ds.variables.items():
var
.
attrs
[
'derived_from'
]
=
'Comment'
else
:
var
.
attrs
[
'derived_from'
]
=
var
.
attrs
[
'bsrn_name'
]
new_names
[
key
]
=
patt
.
sub
(
'_'
,
key
.
lower
())
new_names
[
key
]
=
patt
.
sub
(
'_'
,
key
.
lower
()).
replace
(
','
,
''
)
if
insert_station_no_fill
:
ds
[
'BSRN Station no'
].
encoding
[
'_FillValue'
]
=
-
9999
ds
=
ds
.
rename
(
new_names
)
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment