GroupStation
- class weatherdb.station.GroupStation(id, error_if_missing=True, **kwargs)[source]
Bases:
objectA class to group all possible parameters of one station.
So if you want to create the input files for a simulation, where you need T, ET and N, use this class to download the data for one station.
- get_filled_period(kinds='best', from_meta=True, join_how='inner')[source]
Get the combined filled period for all 3 stations.
This is the maximum possible timerange for these stations.
- Parameters:
kind (str) – The data kind to look for filled period. Must be a column in the timeseries DB. Must be one of “raw”, “qc”, “filled”, “adj”. If “best” is given, then depending on the parameter of the station the best kind is selected. For Precipitation this is “corr” and for the other this is “filled”. For the precipitation also “qn” and “corr” are valid.
from_meta (bool, optional) – Should the period be from the meta table? If False: the period is returned from the timeserie. In this case this function is only a wrapper for .get_period_meta. The default is True.
join_how (str, optional) – How should the different periods get joined. If “inner” then the minimal period that is inside of all the filled_periods is returned. If “outer” then the maximal possible period is returned. The default is “inner”.
- Returns:
The maximum filled period for the 3 parameters for this station.
- Return type:
- get_df(period=(None, None), kinds='best', paras='all', agg_to='day', nas_allowed=True, add_na_share=False, add_t_min=False, add_t_max=False, **kwargs)[source]
Get a DataFrame with the corresponding data.
- Parameters:
period (TimestampPeriod or (tuple or list of datetime.datetime or None), optional) – The minimum and maximum Timestamp for which to get the timeseries. If None is given, the maximum or minimal possible Timestamp is taken. The default is (None, None).
kinds (str or list of str) – The data kind to look for filled period. Must be a column in the timeseries DB. Must be one of “raw”, “qc”, “filled”, “adj”, “filled_by”, “best”(“corr” for N and “filled” for T and ET). If “best” is given, then depending on the parameter of the station the best kind is selected. For Precipitation this is “corr” and for the other this is “filled”. For the precipitation also “qn” and “corr” are valid.
agg_to (str, optional) – To what aggregation level should the timeseries get aggregated to. The minimum aggregation for Temperatur and ET is daily and for the precipitation it is 10 minutes. If a smaller aggregation is selected the minimum possible aggregation for the respective parameter is returned. So if 10 minutes is selected, than precipitation is returned in 10 minuets and T and ET as daily. The default is “10 min”.
nas_allowed (bool, optional) – Should NAs be allowed? If True, then the maximum possible period is returned, even if there are NAs in the timeserie. If False, then the minimal filled period is returned. The default is True.
paras (list of str or str, optional) – Give the parameters for which to get the meta information. Can be “p”, “t”, “et” or “all”. If “all”, then every available station parameter is returned. The default is “all”
add_na_share (bool, optional) – Should one or several columns be added to the Dataframe with the share of NAs in the data. This is especially important, when the stations data get aggregated, because the aggregation doesn’t make sense if there are a lot of NAs in the original data. If True, one column per asked kind is added with the respective share of NAs, if the aggregation step is not the smallest. The “kind”_na_share column is in percentage. The default is False.
add_t_min (bool, optional) – Should the minimal temperature value get added? The default is False.
add_t_max (bool, optional) – Should the maximal temperature value get added? The default is False.
- Returns:
A DataFrame with the timeseries for this station and the given period.
- Return type:
pd.Dataframe
- classmethod get_meta_explanation(infos='all')[source]
Get the explanations of the available meta fields.
- Parameters:
infos (list or string, optional) – The infos you wish to get an explanation for. If “all” then all the available information get returned. The default is “all”
- Returns:
a pandas Series with the information names as index and the explanation as values.
- Return type:
pd.Series
- get_max_period(kinds, nas_allowed=False)[source]
Get the maximum available period for this stations timeseries.
If nas_allowed is True, then the maximum range of the timeserie is returned. Else the minimal filled period is returned
- Parameters:
kinds (str or list of str) – The data kinds to update. Must be a column in the timeseries DB. Must be one of “raw”, “qc”, “filled”, “adj”. For the precipitation also “qn” and “corr” are valid.
nas_allowed (bool, optional) – Should NAs be allowed? If True, then the maximum possible period is returned, even if there are NAs in the timeserie. If False, then the minimal filled period is returned. The default is False.
- Returns:
The maximum Timestamp Period
- Return type:
- get_meta(paras='all', **kwargs)[source]
Get the meta information for every parameter of this station.
- Parameters:
paras (list of str or str, optional) – Give the parameters for which to get the meta information. Can be “p”, “t”, “et” or “all”. If “all”, then every available station parameter is returned. The default is “all”
**kwargs (dict, optional) – The optional keyword arguments are handed to the single Station get_meta methods. Can be e.g. “info”.
- Returns:
dict with the information. there is one subdict per parameter. If only one parameter is asked for, then there is no subdict, but only a single value.
- Return type:
- get_geom(crs=None)[source]
Get the point geometry of the station.
- Parameters:
crs (str, int or None, optional) – The coordinate reference system of the geometry. If None, then the geometry is returned in WGS84 (EPSG:4326). If string, then it should be in a pyproj readable format. If int, then it should be the EPSG code. The default is None.
- Returns:
The location of the station as shapely Point in the given coordinate reference system.
- Return type:
shapely.geometries.Point
- create_roger_ts(dir, period=(None, None), kind='best', r_r0=1, add_t_min=False, add_t_max=False, do_toolbox_format=False, **kwargs)[source]
Create the timeserie files for roger as csv.
This is only a wrapper function for create_ts with some standard settings.
- Parameters:
dir (pathlib like object or zipfile.ZipFile) – The directory or Zipfile to store the timeseries in. If a zipfile is given a folder with the statiopns ID is added to the filepath.
period (TimestampPeriod like object, optional) – The period for which to get the timeseries. If (None, None) is entered, then the maximal possible period is computed. The default is (None, None)
kind (str) – The data kind to look for filled period. Must be a column in the timeseries DB. Must be one of “raw”, “qc”, “filled”, “adj”. If “best” is given, then depending on the parameter of the station the best kind is selected. For Precipitation this is “corr” and for the other this is “filled”. For the precipitation also “qn” and “corr” are valid.
r_r0 (int or float, list of int or float or None, optional) – Should the ET timeserie contain a column with R/R0. If None, then no column is added. If int or float, then a R/R0 column is appended with this number as standard value. If list of int or floats, then the list should have the same length as the ET-timeserie and is appanded to the Timeserie. If pd.Series, then the index should be a timestamp index. The serie is then joined to the ET timeserie. The default is 1.
add_t_min=False (bool, optional) – Schould the minimal temperature value get added? The default is False.
add_t_max=False (bool, optional) – Schould the maximal temperature value get added? The default is False.
do_toolbox_format (bool, optional) – Should the timeseries be saved in the RoGeR toolbox format? (have a look at the RoGeR examples in https://github.com/Hydrology-IFH/roger) The default is False.
**kwargs – additional parameters for Station.get_df
- Raises:
Warning – If there are NAs in the timeseries or the period got changed.
- create_ts(dir, period=(None, None), kinds='best', paras='all', agg_to='10 min', r_r0=None, split_date=False, nas_allowed=True, add_na_share=False, add_t_min=False, add_t_max=False, add_meta=True, file_names={}, col_names={}, keep_date_parts=False, **kwargs)[source]
Create the timeserie files as csv.
- Parameters:
dir (pathlib like object or zipfile.ZipFile) – The directory or Zipfile to store the timeseries in. If a zipfile is given a folder with the statiopns ID is added to the filepath.
period (TimestampPeriod like object, optional) – The period for which to get the timeseries. If (None, None) is entered, then the maximal possible period is computed. The default is (None, None)
kinds (str or list of str) – The data kinds to look for filled period. Must be a column in the timeseries DB. Must be one of “raw”, “qc”, “filled”, “adj”, “filled_by”, “filled_share”, “best”. If “best” is given, then depending on the parameter of the station the best kind is selected. For precipitation this is “corr” and for the other this is “filled”. For the precipitation also “qn” and “corr” are valid. If only one kind is asked for, then the columns get renamed to only have the parameter name as column name.
paras (list of str or str, optional) – Give the parameters for which to get the meta information. Can be “p”, “t”, “et” or “all”. If “all”, then every available station parameter is returned. The default is “all”
agg_to (str, optional) – To what aggregation level should the timeseries get aggregated to. The minimum aggregation for Temperatur and ET is daily and for the precipitation it is 10 minutes. If a smaller aggregation is selected the minimum possible aggregation for the respective parameter is returned. So if 10 minutes is selected, than precipitation is returned in 10 minuets and T and ET as daily. The default is “10 min”.
r_r0 (int or float or None or pd.Series or list, optional) – Should the ET timeserie contain a column with R/R0. If None, then no column is added. If int, then a R/R0 column is appended with this number as standard value. If list of int or floats, then the list should have the same length as the ET-timeserie and is appanded to the Timeserie. If pd.Series, then the index should be a timestamp index. The serie is then joined to the ET timeserie. The default is None.
split_date (bool, optional) – Should the timestamp get splitted into parts, so one column for year, one for month etc.? If False the timestamp is saved in one column as string.
nas_allowed (bool, optional) – Should NAs be allowed? If True, then the maximum possible period is returned, even if there are NAs in the timeserie. If False, then the minimal filled period is returned. The default is True.
add_na_share (bool, optional) – Should one or several columns be added to the Dataframe with the share of NAs in the data. This is especially important, when the stations data get aggregated, because the aggregation doesn’t make sense if there are a lot of NAs in the original data. If True, one column per asked kind is added with the respective share of NAs, if the aggregation step is not the smallest. The “kind”_na_share column is in percentage. The default is False.
add_t_min=False (bool, optional) – Should the minimal temperature value get added? The default is False.
add_t_max=False (bool, optional) – Should the maximal temperature value get added? The default is False.
add_meta (bool, optional) – Should station Meta information like name and Location (lat, long) be added to the file? The default is True.
file_names (dict, optional) – A dictionary with the file names for the different parameters. e.g.{“P”:”PREC.txt”, “T”:”TA.txt”, “ET”:”ET.txt”} Additionally, the station ID (“{id}” as int) and period ({period} as TimestampPeriod) are available as placeholders. If an empty dictionary is given, then the standard names are used. The default is {}.
col_names (dict, optional) – A dictionary with the column names for the different parameters. e.g.{“P”:”PREC”, “T”:”TA”, “ET”:”ET”, “Jahr”:”YYYY”, “Monat”:”MM”, “Tag”:”DD”, “Stunde”:”HH”, “Minute”:”MN”} If an empty dictionary is given, then the standard names are used. The default is {}.
keep_date_parts (bool, optional) – only used if split_date is True. Should the date parts that are not needed, e.g. hour value for daily timeseries, be kept? If False, then the columns that are not needed are dropped. The default is False.
**kwargs – additional parameters for Station.get_df
- Raises:
Warning – If there are NAs in the timeseries and nas_allowed is False or the period got changed.