Skip to content

Commit

Permalink
Merge pull request #96 from TUW-GEO/dev
Browse files Browse the repository at this point in the history
merge for v1.2
  • Loading branch information
raphaelquast committed Jul 28, 2020
2 parents 365c66c + eb6ef2a commit b64a87f
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 97 deletions.
2 changes: 1 addition & 1 deletion rt1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
Import module for RT1 module
"""

__version__ = '1.1.9'
__version__ = '1.2'
__author__ = 'Raphael Quast'
52 changes: 52 additions & 0 deletions rt1/general_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,55 @@ def groupby_unsorted(a, key=lambda x: x, sort=False, get=lambda x: x):
return OrderedDict(sorted(d.items()))
else:
return d


def interpolate_to_index(data, index, data_index=None, **interp1d_kwargs):
'''
A wrapper around scipy.interp1d to interpolate a dataset to a given index
Parameters
----------
data : list, array-like, pandas.Series or pandas.DataFrame
The input-data as list, array, pandas.Series or pandas.DataFrame
If the data is provided as pandas Series or DataFrame, the index
must support a method .to_julian_date() to convert the timestamps
into numerical values.
index : array-like
the index to which the dataset should be interpolated.
It must support a method .to_julian_date()
data_index : TYPE, optional
DESCRIPTION. The default is None.
**interp1d_kwargs :
additional keyword-arguments passed to scipy.interpolate.interp1d
the default is (fill_value=None, bounds_error=False)
Returns
-------
TYPE
DESCRIPTION.
'''
from pandas import Series, DataFrame
from scipy.interpolate import interp1d

kwargs = dict(fill_value=None, bounds_error=False)
kwargs.update(interp1d_kwargs)

if isinstance(data, Series):
# perform a linear interpolation to the timestamps of the auxiliary data
f = interp1d(data.index.to_julian_date(), data.values, **kwargs)
x = f(index.to_julian_date())
return Series(x, index)
elif isinstance(data, DataFrame):
f = interp1d(data.index.to_julian_date(), data.values, axis=0,
**kwargs)
x = f(index.to_julian_date())
return DataFrame(x, index, columns=data.columns)

elif isinstance(data, (list, np.ndarray)):
assert data_index is not None, ('you must provide "data_index"' +
'if data is provided as list or array')

f = interp1d(data_index.to_julian_date(), data.values, **kwargs)
x = f(index.to_julian_date())
return Series(x, index)
2 changes: 1 addition & 1 deletion rt1/processing_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def preprocess(self, **kwargs):
return


def reader(self, **reader_arg):
def reader(self, reader_arg):
'''
a function that is called for each site to obtain the dataset
'''
Expand Down
12 changes: 10 additions & 2 deletions rt1/rtparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,17 @@ def _parse_dict(self, section, int_keys=[], float_keys=[], bool_keys=[],
#assert inp[key].startswith('['), f'{key} must start with "[" '
#assert inp[key].endswith(']'), f'{key} must end with "]" '
#val = inp[key][1:-1].replace(' ', '').split(',')
if inp[key] is None:
if inp[key] == 'None':
val = []
else:
val = inp[key].replace(' ', '').split(',')
val = [i for i in val if len(i) > 0]
else:
val = inp[key]
# parse None as "real" None
if inp[key] == 'None':
val = None
else:
val = inp[key]

parsed_dict[key] = val
return parsed_dict
Expand Down Expand Up @@ -432,6 +436,10 @@ def get_process_specs(self):

process_specs = dict()
for key, val in inp.items():
# parse None as a 'real' None and not as the string 'None'
if val == 'None':
val = None

if key.startswith('datetime__'):
date = dict(zip(['s', 'fmt'],
[i.strip() for i in val.split('fmt=')]))
Expand Down
Loading

0 comments on commit b64a87f

Please sign in to comment.