Commit d4174731 authored by Philipp Sommer's avatar Philipp Sommer
Browse files

Include fill data

parent 4eede1e8
# coding: utf-8 # coding: utf-8
import pandas as pd import pandas as pd
import numpy as np
import re import re
# read BSRN meta data file # read BSRN meta data file
df = pd.read_csv('bsrn_stations.tab', '\t', encoding='latin1') df = pd.read_csv('bsrn_stations.tab', '\t')
staff = pd.read_csv('bsrn_staffs.tab', '\t', encoding='latin1') staff = pd.read_csv('bsrn_staffs.tab', '\t')
mapping = pd.read_csv('colnames-mapping-BG.csv', index_col=0) mapping = pd.read_csv('colnames-mapping-BG.csv', index_col=0)
staff.index = staff['First name'] + ' ' + staff['Last name'] staff.index = staff['First name'] + ' ' + staff['Last name']
...@@ -81,8 +82,23 @@ if 'Plain terrain, Soil type' in joined: ...@@ -81,8 +82,23 @@ if 'Plain terrain, Soil type' in joined:
'Plain terrain, Soil type'] 'Plain terrain, Soil type']
del 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): for key in list(ds.variables):
var = ds[key] var = ds[key]
...@@ -105,7 +121,12 @@ for key, var in ds.variables.items(): ...@@ -105,7 +121,12 @@ for key, var in ds.variables.items():
var.attrs['derived_from'] = 'Comment' var.attrs['derived_from'] = 'Comment'
else: else:
var.attrs['derived_from'] = var.attrs['bsrn_name'] 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) ds = ds.rename(new_names)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment