satellitetools.common.timeseries

Functions for timeseries data handling.

@author: Olli Nevalainen (Finnish Meteorological Institute)

Attributes

logger

Classes

StrEnum

str(object='') -> str

ConfidenceLevel

Confidence level for calculating the confidence interval bounds.

Functions

xr_dataset_to_timeseries(→ pandas.DataFrame)

Compute timeseries dataframe from xarray dataset.

_adjust_sample_size(→ float)

Get sample size for uncertainty calculation.

propagate_rmse(→ float)

Propagate RMSE for the mean value.

compute_uncertainty(→ pandas.DataFrame)

Compute uncertainty for the variable.

compute_confidence_intervals(→ pandas.DataFrame)

Compute confidence intervals for the variable.

Module Contents

class satellitetools.common.timeseries.StrEnum[source]

Bases: str, enum.Enum

str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.

Initialize self. See help(type(self)) for accurate signature.

satellitetools.common.timeseries.logger[source]
class satellitetools.common.timeseries.ConfidenceLevel[source]

Bases: enum.StrEnum

Confidence level for calculating the confidence interval bounds.

Initialize self. See help(type(self)) for accurate signature.

C90 = '90'[source]
C95 = '95'[source]
C99 = '99'[source]
satellitetools.common.timeseries.xr_dataset_to_timeseries(xr_dataset: xarray.Dataset, variables: List[satellitetools.biophys.biophys.BiophysVariable | satellitetools.biophys.biophys.VegetationIndex], add_uncertainty: bool = False, add_confidence_intervals: bool = False, confidence_level: ConfidenceLevel = ConfidenceLevel.C95) pandas.DataFrame[source]

Compute timeseries dataframe from xarray dataset.

Parameters:
  • xr_dataset (xr.Dataset) – xarray dataset with Sentinel-2 data.

  • variables (List[BiophysVariable]) – List of variables to compute timeseries for.

  • add_uncertainty (bool, default False) – Adds variable {variable}_uncertainty and confidence intervals to dataframe. Currently, uncertainty is equal to standar error (se) or if variable is biophysical variable from biophys_xarray, it sqrt(se^2 + RMSE_mean^2) where RMSE_mean is propagated uncertainty for the individual observations/pixels uncertainties. Uncertainty for the individual pixels is considered to be the variable RMSE from the SNAP biophysical processor developers (see biophys_xarray.py and linked ATBD) (i.e. same for all pixels).

  • confidence_level (ConfidenceLevel, default ConfidenceLevel.C95) – Confidence level (%) for calculating the confidence interval bounds. Options “90”, “95” & “99”

Returns:

df – Pandas dataframe with mean, std, se and percentage of NaNs inside AOI.

Return type:

pandas dataframe

satellitetools.common.timeseries._adjust_sample_size(xr_dataset: xarray.Dataset, sample_n: float) float[source]

Get sample size for uncertainty calculation.

Parameters:
  • xr_dataset (xr.Dataset) – xarray dataset with Sentinel-2 data.

  • sample_n (float) – Original sample size.

Returns:

sample_n – Adjusted sample size.

Return type:

float

satellitetools.common.timeseries.propagate_rmse(n: int, rmse: float) float[source]

Propagate RMSE for the mean value.

Parameters:
  • n (int) – Sample size.

  • rmse (float) – Root mean square error.

Returns:

propagated_rmse – Propagated RMSE for the mean value.

Return type:

float

satellitetools.common.timeseries.compute_uncertainty(df: pandas.DataFrame, xr_dataset: xarray.Dataset, var: satellitetools.biophys.biophys.BiophysVariable, sample_n: float) pandas.DataFrame[source]

Compute uncertainty for the variable.

Parameters:
  • df (pd.DataFrame) – Dataframe with the variable.

  • xr_dataset (xr.Dataset) – xarray dataset with Sentinel-2 data.

  • var (BiophysVariable) – Biophysical variable.

  • sample_n (float) – Sample size for uncertainty calculation.

Returns:

df – Dataframe with the variable and uncertainty.

Return type:

pd.DataFrame

satellitetools.common.timeseries.compute_confidence_intervals(df: pandas.DataFrame, var: satellitetools.biophys.biophys.BiophysVariable, confidence_level=ConfidenceLevel.C95) pandas.DataFrame[source]

Compute confidence intervals for the variable.

Parameters:
  • df (pd.DataFrame) – Dataframe with the variable.

  • var (BiophysVariable) – Biophysical variable.

  • confidence_level (ConfidenceLevel, default ConfidenceLevel.C95) – Confidence level (%) for calculating the confidence interval bounds. Options “90”, “95” & “99”

Returns:

df – Dataframe with the variable and confidence intervals.

Return type:

pd.DataFrame