Find locations of a value in 3-D matrix (lat x lon x time) and take the two time steps before and after those selected values
2 visualizaciones (últimos 30 días)
I am trying to filter out my dataset using another dataset. I have one dataset made up of 1's (lightning occured) and 0's (no lightning) telling me when lightning strike occur at a given lat x lon point. The data is 3-D (lat x lon x time). I have another dataset of precipitation values that is the same dimensions (lat x lon x time).
My goal is to look at these storms and see how much precipitation occurs during them over a specific area. Right now, my code finds when lightning strikes (ls =1) in my area, and then I multiply the lightning data by my precipitation data and get a precipitation value for that time step.
This works great, however I am looking to also select the few time steps before and the few after the lightning strikes to gather that precipitation data as well. Currently, I am only getting the precipitation values at the time the lightning occurs, not through the whole storm.
Is it possible to find times of lightning strikes, and take the two hours (timesteps) before and after is occurs in my region?
lightning strikes (ls) - lat x lon x time (316 x 332 x 2160 hours)
precipitation (precip) - lat x lon x time (316 x 332 x 2160 hours)
my_study_region - lat x lon (316 x 332)
Matt J el 9 de Mayo de 2023
Editada: Matt J el 9 de Mayo de 2023
[I,J,K]=ind2sub(sz, find(ls) );
A=precip(sub2ind(sz,I,J,K-2)); %2 hours before
B=precip(sub2ind(sz,I,J,K-1)); %1 hours before
C=precip(sub2ind(sz,I,J,K-0)); %0 hours before
D=precip(sub2ind(sz,I,J,K+1)); %1 hours after
E=precip(sub2ind(sz,I,J,K+2)); %2 hours after
Eric Sofen el 5 de Jun. de 2023
Since you're using lighting as a logical mask on the precipitation data, you can shift the array one or two time steps and re-apply it. You just need to pad the other end of the time dimension so that dimensions match. For example, in 2D (say lat x time):
precip = rand(5)
lightning = rand(5) > 0.8; % just to get a few 1s in an array of 0s.
lag1lightning = [zeros(1,5); lightning(1:4,:)] % in general in 3d, this would be something like..
% sz = size(lightining);
% lag1lighting = cat(3, zeros(sz(1:2)), lightning(:,:,1:end-1));
lightningMask = lightning | lag1lightning
inStorm = precip(lightningMask)