Skip to content

Module fordead.dieback_detection

Created on Mon Nov 2 09:34:34 2020

@author: Raphael Dutrieux

Functions

detection_anomalies

def detection_anomalies(
    vegetation_index,
    mask,
    predicted_vi,
    threshold_anomaly,
    vi,
    path_dict_vi=None
)
Detects anomalies by comparison between predicted and calculated vegetation index. The array returns contains True where the difference between the vegetation index and its prediction is above the threshold in the direction of the specified dieback change direction of the vegetation index. 

Parameters
----------
vegetation_index : xarray DataArray
    DataArray containing uncorrected vegetation index values
mask : xarray DataArray
    DataArray containing mask values.
predicted_vi : array (x,y)
    Array containing the vegetation index predicted by the model
threshold_anomaly : float
    Threshold used to compare predicted and calculated vegetation index.
vi : str
    Name of the used vegetation index
path_dict_vi : str, optional
    Path to a text file containing vegetation indices information, where is indicated whether the index rises of falls in case of forest dieback. See get_dict_vi documentation. The default is None.

Returns
-------
anomalies : array (x,y) (bool)
    Array, pixel value is True if an anomaly is detected.
diff_vi : array (x,y) (float)
    Array containing the difference between the vegetation index and its prediction

detection_dieback

def detection_dieback(
    dieback_data,
    anomalies,
    mask,
    date_index
)
Updates dieback data using anomalies. Successive anomalies are counted for pixels considered healthy, and successive dates without anomalies are counted for pixels considered suffering from dieback. The state of the pixel changes when the count reaches 3.

Parameters
----------
dieback_data : Dataset with four arrays : 
    "count" which is the number of successive anomalies, 
    "state" which is True where pixels are detected as suffering from dieback, False where they are considered healthy.
    "first_date" contains the index of the date of the first anomaly then confirmed
    "first_date_unconfirmed" containing the date of pixel change, first anomaly if pixel is not detected as dieback, first non-anomaly if pixel is detected as dieback
anomalies : array (x,y) (bool)
    Array, pixel value is True if an anomaly is detected.
mask : array (x,y) (bool)
    Array, True where pixels are masked
date_index : int
    Index of the date

Returns
-------
dieback_data : Dataset
    Dataset with the four arrays updated with the results from the date being analysed
changing_pixels : DataArray
    Binary array (x,y) containing True where pixels change state is confirmed with a third successive anomaly

save_stress

def save_stress(
    stress_data,
    dieback_data,
    changing_pixels,
    diff_vi,
    mask,
    stress_index_mode
)
Updates stress data, saves the date of pixel state changes,
adds one to the number of stress periods when pixels change back to normal,
adds the difference between vegetation index and its prediction multiplied by
the weight of the date if "stress_index_mode" is "weighted_mean",
iterates the number of dates in the stress periods for unmasked pixels.

Parameters
----------
stress_data : xarray DataSet or dask DataSet
    DataSet containing four DataArrays, "date" containing the date index of each pixel state change, "nb_periods" containing the total number of stress periods detected for each pixel, "cum_diff" containing for each stress period the sum of the difference between the vegetation index and its prediction, multiplied by the weight if stress_index_mode is "weighted_mean", and "nb_dates" containing the number of valid dates of each stress period.
dieback_data : Dataset with four arrays : 
    "count" which is the number of successive anomalies, 
    "state" which is True where pixels are detected as suffering from dieback, False where they are considered healthy.
    "first_date" contains the index of the date of the first anomaly then confirmed
    "first_date_unconfirmed" containing the date of pixel change, first anomaly if pixel is not detected as dieback, first non-anomaly if pixel is detected as dieback
changing_pixels : DataArray
    Binary array (x,y) containing True where pixels change state is confirmed with a third successive anomaly
diff_vi : array (x,y) (float)
    Array containing the difference between the vegetation index and its prediction
mask : array (x,y) (bool)
    Array containing the mask values (True if masked)
stress_index_mode : str
    Chosen stress index, if 'mean', diff_vi is simply added to "cum_diff", if 'weighted_mean', diff_vi is added to "cum_diff" after being multiplied with "nb_dates", the number of the date from the first anomaly.

Returns
-------
stress_data : xarray DataSet or dask DataSet
    Updated dataSet containing four DataArrays, "date" containing the date index of each pixel state change, "nb_periods" containing the total number of stress periods detected for each pixel, "cum_diff" containing for each stress period the sum of the difference between the vegetation index and its prediction, multiplied by the weight if stress_index_mode is "weighted_mean", and "nb_dates" containing the number of valid dates of each stress period.