Station
This module contains the Station
class, which is the main
component of a Network
and contains
Timeseries
, Model
and
associated fits.
- class disstans.station.Station(name, location)[source]
Representation of a station, which contains both metadata such as location as well as timeseries, models and fits.
Timeseries are saved in the
timeseries
dictionary, and their associated models and fits are saved in themodels
andfits
dictionaries, respectively.- Parameters
- __contains__(ts_description)[source]
Special function that allows to check whether a certain timeseries is in the station.
- Return type
Example
If
mystat
is aStation
instance, and we want to see whether'myts'
is contained by the station, the following two are equivalent:# long version 'myts' in station.timeseries # short version 'myts' in station
- __delitem__(ts_description)[source]
Convenience special function that allows a dictionary-like removing of timeseries from the station by wrapping
remove_timeseries()
. :rtype:None
See also
remove_timeseries
Remove a timeseries from the station instance.
- __getitem__(ts_description)[source]
Convenience special function that provides a shorthand notation to access the station’s timeseries.
- Parameters
ts_description (
str
) – Description of the timeseries.- Return type
- Returns
Timeseries in station.
Example
If
stat
is aStation
instance andts_description
the ts_description of a station, the following two are equivalent:stat.timeseries[ts_description] stat[ts_description]
- __iter__()[source]
Convenience special function that allows for a shorthand notation to quickly iterate over all timeseries.
- Return type
Example
If
stat
is aStation
instance,then the following two loops are equivalent:# long version for ts in stat.timeseries.values(): pass # shorthand for ts in stat: pass
- __setitem__(ts_description, timeseries)[source]
Convenience special function that allows a dictionary-like adding of timeseries to the station by wrapping
add_timeseries()
. :rtype:None
See also
add_timeseries
Add a timeseries to the station instance.
- __str__()[source]
Special function that returns a readable summary of the station. Accessed, for example, by Python’s
print()
built-in function.- Return type
- Returns
Station summary.
- add_fit(ts_description, fit, model_description=None, return_ts=False)[source]
Add a fit dictionary to a timeseries’ model (overwrites the fit if it has already been added for the model).
- Parameters
ts_description (
str
) – Timeseries to add the fit to.fit (
dict
[str
,Optional
[ndarray
]]) – Dictionary with the keys'time'
,'fit'
,'var'
and'cov'
(the latter two can be set toNone
).model_description (
Optional
[str
], default:None
) – Model description the fit applies to. IfNone
, the fit is the sum of all individual model fits.return_ts (
bool
, default:False
) – IfTrue
, return the created timeseries.
- Return type
- Returns
(If
return_ts=True
.) The fit as a Timeseries object.
See also
disstans.timeseries.Timeseries.from_fit
Convert a fit dictionary to a
Timeseries
object.
- add_local_model(ts_description, model_description, model)[source]
Add a model to a timeseries (overwrites the model if it has already been added with the same description).
- add_local_model_dict(ts_description, model_dict)[source]
Add a dictionary of models to a timeseries (overwrites the models if they have already been added with the same description).
Wraps
add_local_model()
.
- add_local_model_kwargs(ts_description, model_kw_args)[source]
Add models to a timeseries from a dictionary of keyword arguments needed to create them (overwrites the models if they have already been added with the same description).
Wraps
add_local_model()
.- Parameters
- Return type
- add_timeseries(ts_description, timeseries, uncertainties_from=None, override_src=None, override_data_unit=None, override_data_cols=None, override_var_cols=None, override_cov_cols=None, add_models=None, warn_existing=True)[source]
Add a timeseries to the station.
Optionally, can override some Timeseries attributes when adding the object, and add models.
- Parameters
ts_description (
str
) – Description of the timeseries.timeseries (
Timeseries
) – Timeseries object to add.uncertainties_from (
Optional
[Timeseries
], default:None
) – If the variance and covariance data should come from another timeseries, specify the source timeseries here.override_src (
Optional
[str
], default:None
) – Override thesrc
attribute oftimeseries
.override_data_unit (
Optional
[str
], default:None
) – Override thedata_unit
attribute oftimeseries
.override_data_cols (
Optional
[str
], default:None
) – Override thedata_cols
attribute oftimeseries
.override_var_cols (
Optional
[str
], default:None
) – Override thevar_cols
attribute oftimeseries
.override_cov_cols (
Optional
[str
], default:None
) – Override thecov_cols
attribute oftimeseries
.add_models (
Optional
[dict
[str
,Model
]], default:None
) – Dictionary of models to add to the timeseries, where the keys are the model description and the values areModel
objects.warn_existing (
bool
, default:True
) – Issue a warning if a station’s timeseries is being overwritten.
- Return type
See also
__setitem__
Shorthand notation wrapper when no optional arguments are necessary.
Example
If
stat
is aStation
instance,ts_description
the ts_description of a new timeseries, andts
aTimeseries
instance, then the following two are equivalent:stat.add_timeseries(ts_description, timeseries) stat[ts_description] = timeseries
- analyze_residuals(ts_description, verbose=False, t_start=None, t_end=None, mean=False, std=False, rms=False, n_observations=False, std_outlier=0, max_rolling_dev=0)[source]
Analyze, print and return the residuals of a station’s timeseries according to certain metrics defined in the arguments.
- Parameters
ts_description (
str
) – Timeseries to analyze. Method assumes it already is a residual.verbose (
bool
, default:False
) – If True, additionally print the results.t_start (
UnionType
[str
,Timestamp
,None
], default:None
) – If set, specify a lower bound for the analysis.t_start
should be a Timestamp-convertible string of the start time, or a datetime-like object.None
defaults to the first timestamp present in the timeseries.t_end (
UnionType
[str
,Timestamp
,None
], default:None
) – If set, specify an upper bound for the analysis.t_end
should be a Timestamp-convertible string of the end time, or a datetime-like object.None
defaults to the last timestamp present in the timeseries.mean (
bool
, default:False
) – IfTrue
, calculate the mean of the timeseries. Adds the key'Mean'
to the output dictionary.std (
bool
, default:False
) – IfTrue
, calculate the standard deviation of the timeseries. Adds the key'Standard Deviation'
to the output dictionary.rms (
bool
, default:False
) – IfTrue
, calculate the root-mean-squared over all components combined, or ifrms
is a list, only using those components. Adds the key'RMS'
to the output dictionary.n_observations (
bool
, default:False
) – IfTrue
, count the number of observations (excluding NaNs) and NaNs. Adds the keys'Observations'
and'Gaps'
to the output dictionary.std_outlier (
int
|float
, default:0
) – Ifstd_outlier > 0
, count the number of non-NaN outliers, defined by the number of standard deviations they are away from the mean. Adds the key'Outliers'
to the output dictionary.max_rolling_dev (
int
, default:0
) – Ifmax_rolling_dev > 0
, calculate the (sign-aware) maximum of the rolling deviation from the mean with window sizemax_rolling_dev
for each component. If this is significantly larger than the standard deviation, this is an indicator of model inadequacies, as not all the data trends can be captured.
- Return type
- Returns
Dictionary that includes the results as defined by the arguments. Empty by default.
- fits
Dictionary of
FitCollection
objects associated with a timeseries saved intimeseries
.Example
If
'myts'
is a timeseries saved in the stationstat
, and'mymodel'
is the name of a model that is associated with it, then the fitted timeseries is saved as:stat.fits['myts']['mymodel']
- get_arch()[source]
Build a dictionary describing the architecture of this station, to be used when creating a network JSON configuration file.
See also
disstans.network.Network.to_json
Export the Network configuration as a JSON file.
disstans.timeseries.Timeseries.get_arch
Get the architecture dictionary of a
Timeseries
instance.disstans.models.Model.get_arch
Get the architecture dictionary of a
Model
instance.
- get_trend(ts_description, fit_list=None, components=None, total=False, t_start=None, t_end=None, use_formal_variance=None, include_sigma=False, time_unit='D', ignore_missing=False)[source]
Calculates a linear trend through the desired model fits (or timeseries data) and over some time span.
- Parameters
ts_description (
str
) – Timeseries whose fits to use.fit_list (
Optional
[list
[str
]], default:None
) – List of strings containing the model names of the subset of the fitted models to be used.None
defaults to all fitted models. Ifts_description
the trend of the timeseries itself is to be calculated, pass an empty list ([]
).components (
Optional
[list
[int
]], default:None
) – List of the numerical indices of which components of the timeseries to use.None
defaults to all components.total (
bool
, default:False
) – By default, the function will return the trend pertime_unit
. IfTrue
, the function will instead give the total difference over the entire timespan.t_start (
UnionType
[str
,Timestamp
,None
], default:None
) – Timestamp-convertible string of the start time.None
defaults to the first timestamp present in the timeseries.t_end (
UnionType
[str
,Timestamp
,None
], default:None
) – Timestamp-convertible string of the end time.None
defaults to the last timestamp present in the timeseries.use_formal_variance (
Optional
[bool
], default:None
) – By default, the trend fitting will use variance information if present. This usually makes sense for actual timeseries, but not for fitted models where the formal variance can be very unphysical. Setting this parameter overrides the default behavior.include_sigma (
bool
, default:False
) – IfTrue
, also calculate the formal standard deviation on the trend estimate.time_unit (
str
, default:'D'
) – Time unit for output (only required iftotal=False
).ignore_missing (
bool
, default:False
) – By default, this method will throw an error if the timeseries or the models are not present in the station. Set toTrue
if the method should return(None, None)
instead (as done when the requested timespan is outside the observed one).
- Return type
- Returns
trend – 1D array of size
len(components)
containing the trends.trend_sigma – 1D array of size
len(components)
containing the standard deviation of the trend estimate. ReturnsNone
if no standard deviations are available.
- location
Location of the station (Latitude [°], Longitude [°], Altitude [m]).
- models
Dictionary of
ModelCollection
objects associated with a timeseries saved intimeseries
.Example
If
'myts'
is a timeseries saved in the stationstat
, then the model collection object for that timeseries is stored in:stat.models['myts']
- name
Name of the station.
- remove_local_models(ts_description, model_descriptions, verbose=False)[source]
Remove models from a timeseries.
- remove_timeseries(ts_description)[source]
Remove a timeseries (including associated fits and models) from the station.
See also
__delitem__
Shorthand notation wrapper.
Example
If
stat
is aStation
instance,ts_description
the ts_description of the timeseries to remove, then the following two are equivalent:stat.remove_timeseries(ts_description) del stat[ts_description]
- sum_fits(ts_description, fit_list=None)[source]
Method to quickly sum fits of a timeseries.
- Parameters
- Return type
- Returns
fit_sum – 2D array of shape \((\text{n_observations},\text{n_components})\)
fit_sum_var – 2D array of shape \((\text{n_observations},\text{n_components})\). Returns
None
if no standard deviations are available.
- timeseries
Dictionary of timeseries, where the keys are their string descriptions and the values are
Timeseries
instances.
- property ts: dict[str, disstans.timeseries.Timeseries]
Abbreviation for
timeseries
.
- unused_models
Same as
models
but for models whose timeseries is not present intimeseries
.