s2spy.preprocess ================ .. py:module:: s2spy.preprocess .. autoapi-nested-parse:: Preprocessor for s2spy workflow. Classes ------- .. autoapisummary:: s2spy.preprocess.Preprocessor Functions --------- .. autoapisummary:: s2spy.preprocess._linregress s2spy.preprocess._trend_linear s2spy.preprocess._subtract_linear_trend s2spy.preprocess._get_trend s2spy.preprocess._subtract_trend s2spy.preprocess._get_climatology s2spy.preprocess._subtract_climatology s2spy.preprocess._check_input_data s2spy.preprocess._check_temporal_resolution s2spy.preprocess._check_data_resolution_match Module Contents --------------- .. py:function:: _linregress(x: numpy.ndarray, y: numpy.ndarray) -> tuple[float, float] Calculate the slope and intercept between two arrays using scipy's linregress. Used to make linregress more ufunc-friendly. :param x: First array. :param y: Second array. :returns: slope, intercept .. py:function:: _trend_linear(data: Union[xarray.DataArray, xarray.Dataset]) -> dict Calculate the linear trend over time. :param data: The input data of which you want to know the trend. :returns: Dictionary containing the linear trend information (slope and intercept) .. py:function:: _subtract_linear_trend(data: Union[xarray.DataArray, xarray.Dataset], trend: dict) Subtract a previously calclulated linear trend from (new) data. .. py:function:: _get_trend(data: Union[xarray.DataArray, xarray.Dataset], method: str) Calculate the trend, with a certain method. Only linear is implemented. .. py:function:: _subtract_trend(data: Union[xarray.DataArray, xarray.Dataset], method: str, trend: dict) Subtract the previously calculated trend from (new) data. Only linear is implemented. .. py:function:: _get_climatology(data: Union[xarray.Dataset, xarray.DataArray], timescale: Literal['monthly', 'weekly', 'daily']) Calculate the climatology of timeseries data. .. py:function:: _subtract_climatology(data: Union[xarray.Dataset, xarray.DataArray], timescale: Literal['monthly', 'weekly', 'daily'], climatology: Union[xarray.Dataset, xarray.DataArray]) .. py:function:: _check_input_data(data: Union[xarray.DataArray, xarray.Dataset]) Check the input data for compatiblity with the preprocessor. :param data: Data to validate. :raises ValueError: If the input data is of the wrong type. :raises ValueError: If the input data does not have a 'time' dimension. .. py:function:: _check_temporal_resolution(timescale: Literal['monthly', 'weekly', 'daily']) -> Literal['monthly', 'weekly', 'daily'] .. py:function:: _check_data_resolution_match(data: Union[xarray.DataArray, xarray.Dataset], timescale: Literal['monthly', 'weekly', 'daily']) Check if the temporal resolution of input is the same as given timescale. .. py:class:: Preprocessor(rolling_window_size: Union[int, None], timescale: Literal['monthly', 'weekly', 'daily'], rolling_min_periods: int = 1, subtract_climatology: bool = True, detrend: Union[str, None] = 'linear') Preprocessor for s2s data. .. py:attribute:: _window_size .. py:attribute:: _min_periods .. py:attribute:: _detrend .. py:attribute:: _subtract_climatology .. py:attribute:: _climatology :type: Union[xarray.DataArray, xarray.Dataset] .. py:attribute:: _trend :type: dict .. py:attribute:: _is_fit :value: False .. py:method:: fit(data: Union[xarray.DataArray, xarray.Dataset]) -> None Fit this Preprocessor to input data. :param data: Input data for fitting. .. py:method:: transform(data: Union[xarray.DataArray, xarray.Dataset]) -> Union[xarray.DataArray, xarray.Dataset] Apply the preprocessing steps to the input data. :param data: Input data to perform preprocessing. :returns: Preprocessed data. .. py:method:: fit_transform(data: Union[xarray.DataArray, xarray.Dataset]) -> Union[xarray.DataArray, xarray.Dataset] Fit this Preprocessor to input data, and then apply the steps to the data. :param data: Input data for fit and transform. :returns: Preprocessed data. .. py:property:: trend :type: dict Return the stored trend (dictionary). .. py:property:: climatology :type: Union[xarray.DataArray, xarray.Dataset] Return the stored climatology data.