How to put conditions to find peaks in NDVI time series?
Ältere Kommentare anzeigen
I am using following matlab code findpeaks(data,days'MinPeakProminence',60) xlabel('days’) ylabel('NDVI') title('Find Prominent Peaks') here the data is NDVI time series attached here.
9 Kommentare
Manikanta Aditya
am 6 Apr. 2024
Bearbeitet: Manikanta Aditya
am 6 Apr. 2024
To find peaks in an NDVI time series data using MATLAB, you can use the findpeaks function. The findpeaks function allows you to set various parameters to control the peak detection process.
% Load the NDVI time series data
ndvi_data = [
% add your NDVI data
];
% Define the date vector (assuming the dates are in the order provided)
dates = datetime(2023, 4, 9) + calmonths(0:size(ndvi_data, 2)-1);
% Loop over each location
for i = 1:size(ndvi_data, 1)
% Extract the NDVI time series for the current location
location_data = ndvi_data(i, :);
% Find prominent peaks with a minimum prominence of 0.1
[pks, locs] = findpeaks(location_data, dates, 'MinPeakProminence', 0.1);
% Plot the NDVI time series and the detected peaks
figure;
plot(dates, location_data);
hold on;
plot(dates(locs), pks, 'r*');
% Add labels and title
xlabel('Date');
ylabel('NDVI');
title(sprintf('Find Prominent Peaks for Location %d', i));
% Adjust the x-axis ticks for better visibility
xtickangle(45);
datetick('x', 'mmm yyyy', 'keeplimits');
end
Devendra
am 6 Apr. 2024
Manikanta Aditya
am 6 Apr. 2024
Hi,
To modify the code to find peaks with NDVI values greater than 0.4 and a minimum distance of 60 days between peaks, and to return the number of peaks as a vector, you can make the following changes:
% Load the NDVI time series data
ndvi_data = [
% add your NDVI data
];
% Define the date vector (assuming the dates are in the order provided)
dates = datetime(2023, 4, 9) + calmonths(0:size(ndvi_data, 2)-1);
% Preallocate a vector to store the number of peaks for each location
num_peaks = zeros(size(ndvi_data, 1), 1);
% Loop over each location
for i = 1:size(ndvi_data, 1)
% Extract the NDVI time series for the current location
location_data = ndvi_data(i, :);
% Find peaks with a minimum prominence of 0.1, NDVI value greater than 0.4,
% and a minimum distance of 60 days between peaks
[pks, locs, ~, prominences] = findpeaks(location_data, dates, ...
'MinPeakProminence', 0.1, ...
'MinPeakHeight', 0.4, ...
'MinPeakDistance', 60);
% Count the number of peaks for the current location
num_peaks(i) = numel(pks);
% Plot the NDVI time series and the detected peaks (optional)
figure;
plot(dates, location_data);
hold on;
plot(dates(locs), pks, 'r*');
xlabel('Date');
ylabel('NDVI');
title(sprintf('Find Prominent Peaks for Location %d', i));
xtickangle(45);
datetick('x', 'mmm yyyy', 'keeplimits');
end
The findpeaks function is used with specific parameters to detect peaks in NDVI values greater than 0.4 and at least 60 days apart. The number of these peaks is counted and stored.
Hope this helps, let me know, I will post as an answer, then you can accept the answer.
Devendra
am 6 Apr. 2024
Manikanta Aditya
am 7 Apr. 2024
Bearbeitet: Manikanta Aditya
am 7 Apr. 2024
Hi,
Check this, based on your explaination this is what I was able to come up with:
Replace with correct file, and if any small issues you should be able to fix them.
% Load the NDVI time series data
ndvi_data = readmatrix('ndvi_time_series_input 2.csv');
% Define the date vector (assuming the dates are in the order provided)
dates = datetime(2023, 4, 9) + calmonths(0:size(ndvi_data, 2)-1);
% Initialize an array to store the phenology parameters
phenology_params = nan(size(ndvi_data, 1), 10); % Only numeric values
phenology_dates = NaT(size(ndvi_data, 1), 3); % Only datetime values
% Loop over each location
for i = 1:size(ndvi_data, 1)
% Extract the NDVI time series for the current location
location_data = ndvi_data(i, :);
% Find peaks with a minimum prominence of 0.1, NDVI value greater than 0.4,
% and a minimum distance of 10 days between peaks
[pks, locs, ~, prominences] = findpeaks(location_data, 'MinPeakProminence', 0.1, 'MinPeakHeight', 0.4, 'MinPeakDistance', 10);
% Count the number of peaks for the current location
num_peaks = numel(pks);
% Determine SOS, POS, and EOS
sos_idx = find(location_data >= 0.2, 1, 'first');
pos_idx = locs(location_data(locs) == max(pks));
eos_idx = find(location_data(pos_idx:end) < 0.2, 1, 'first') + pos_idx - 1;
% Calculate other phenology parameters
pos_value = location_data(pos_idx);
max_sum = sum(max(location_data));
avg_sum = sum(location_data);
base = max(location_data) - min(location_data);
duration = eos_idx - sos_idx + 1;
first_half = pos_idx - sos_idx;
second_half = eos_idx - pos_idx;
growth_rate = (pos_value - location_data(sos_idx)) / first_half;
senescence_rate = (location_data(eos_idx) - pos_value) / second_half;
% Store the phenology parameters
phenology_params(i, :) = [pos_value, max_sum, avg_sum, base, duration, first_half, second_half, growth_rate, senescence_rate, num_peaks];
phenology_dates(i, :) = [dates(sos_idx), dates(pos_idx), dates(eos_idx)];
end
The code calculates various phenology parameters such as POS value, MAX sum, AVG sum, SOS, POS, EOS, Base, Duration, First half, Second half, Growth rate, Senescence rate, and Number of peaks for each location. These parameters are stored in the phenology_params array for future use or analysis.
Devendra
am 7 Apr. 2024
Manikanta Aditya
am 7 Apr. 2024
Thank you! Feel free to reach out if needed any help!
Devendra
am 25 Apr. 2024
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Data Import and Analysis finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!