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
1 次查看(过去 30 天)
显示 更早的评论
Hello,
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?
Variables:
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)
Thank you,
James
0 个评论
回答(2 个)
Matt J
2023-5-9
编辑:Matt J
2023-5-9
One way:
sz=size(ls);
[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
0 个评论
Eric Sofen
2023-6-5
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.
zeros(1,5)
lightning(1:4,:)
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)
0 个评论
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!