How to put conditions to find peaks in NDVI time series?

4 Ansichten (letzte 30 Tage)
Devendra
Devendra am 6 Apr. 2024
Kommentiert: gauri am 26 Apr. 2024
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
Manikanta Aditya am 7 Apr. 2024
Thank you! Feel free to reach out if needed any help!
Devendra
Devendra am 25 Apr. 2024
Thank you very much for your kind help. I will try to understand it and will try to resolve it. Certainly I will approach you at the critical time.
Once again I am very much thankful to you for your generous and kind help.
Devendra

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Manikanta Aditya
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.
Thanks @Devendra!
  24 Kommentare
Manikanta Aditya
Manikanta Aditya am 25 Apr. 2024
% Extract map information
map_info = sprintf('UTM, %f, %f, %f, %f, %f, %f, %s, %s, units=Meters', ...
R.XIntrinsicLimits(1), R.YIntrinsicLimits(1), ...
R.XWorldLimits(1), R.YWorldLimits(2), ...
R.CellExtentInWorldX, R.CellExtentInWorldY, ...
R.ColumnsStartFrom, R.CoordinateSystemType);
% Extract projection information
projection_info = char(R.ProjectedCRS);
% Extract the required coordinate system string
pattern = 'PROJCS\["(.*?)"\]';
matches = regexp(projection_info, pattern, 'tokens');
if ~isempty(matches)
coordinate_system_string = ['coordinate system string = {' matches{1}{1} '}'];
else
coordinate_system_string = '';
end
% Create coordinate_information struct
coordinate_information = struct('map_info', map_info, 'projection_info', coordinate_system_string);
% Write the ENVI file
stacked_image(:,:,j+1) = data;
fname = convertStringsToChars(string(img_names) + '_' + '6Bands.dat');
wavelength_data = str2double({'560.00', '665.00', '705.00', '740.00', '783.00', '842.00'});
custom_enviwrite(stacked_image, fname, coordinate_information, wavelength_data);
gauri
gauri am 26 Apr. 2024
Aditya, I want to extract full file name using following lines
for example file name is T43RGN_20210119T053141_B03_10m.jp2
fn = {files(i + j).name};
img_names = regexp(fn,'_([\dT]+)_','tokens','once');
img_names = [img_names{:}];
and want to store in a variable named as band_names. I request you to please suggest me how to extract full name of files and define the variable band_names to store the full file names.
Thank you for your support and help.
Devendra

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Digital and Analog Filters finden Sie in Help Center und File Exchange

Produkte


Version

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by