how to take out extreme event annually from the data.

2 Ansichten (letzte 30 Tage)
ravi
ravi am 11 Apr. 2014
Bearbeitet: ravi am 18 Mai 2014
sir i have program who calculate extreme event for whole 95 years but i want to calculate extreme event annually (it mean 365 then 365 ....each separate years) then what will be change in this program for doing this? my data size is (prec_all_years) 20x22x34675(lon,lat,time).this is daily data.
prec_all_years = prec_all_years*86400; % rainfall in mm/day
xx = []
for ii= 1:95;
for i = 1:length(X1);
for j = 1:length(Y1);
xx = [xx (i-1)*[1:365]];
prec1 = prec_all_years(i,j,xx);
inds1 = find(prec1 >=64.5 & prec1 <= 124.5); inds2 = find(prec1 > 124.5 & prec1 <=244.5); inds3 = find(prec1 > 244.5);
hr(i,j) = length(inds1); vhr(i,j)= length(inds2); ehr(i,j)= length(inds3);
end end end % now find frequency of rainfall in different regions
% western region
xe = [13:20]; ye = [11:16]; xw = [1:8]; yw = [11:16]; xn = [5:9]; yn = [15:20]; xs = [5:9]; ys = [3:7];
% eastern region
freq_east_hr = hr(xe,ye);
count_hr_east = sum(freq_east_hr(:))
freq_east_vhr = vhr(xe,ye);
count_vhr_east = sum(freq_east_vhr(:))
freq_east_ehr = ehr(xe,ye);
count_ehr_east = sum(freq_east_ehr(:))
  1 Kommentar
Walter Roberson
Walter Roberson am 11 Apr. 2014
Bearbeitet: Walter Roberson am 11 Apr. 2014
Please do not tag individuals. Volunteers respond if and when they feel like responding, and should not be pressured into it.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Matt Tearle
Matt Tearle am 11 Apr. 2014
Slightly new approach, given your comment on the previous answer. This one creates hr, vhr, and ehr, which are 20-by-22-by-95 (lat/lon/year) arrays holding the counts over each year, for each lat/lon location. These are then summed over all locations to give count_X_east, which are 95-element vectors (one total for each year).
prec_all_years = prec_all_years*86400; % rainfall in mm/day
bins = [64.5 124.5 244.5 Inf];
% Reshape into lat/lon/day/year, and bin over 3rd dimension (days)
counts = histc(reshape(prec_all_years,20,22,365,95),bins,3);
% Extract the counts for each of the 3 categories
hr = squeeze(counts(:,:,1,:));
vhr = squeeze(counts(:,:,2,:));
ehr = squeeze(counts(:,:,3,:));
% Extract a region
xe = 13:20; ye = 11:16;% xe is x for east,ye is y for east
% Extract counts for each category
count_hr_east = sum(reshape(hr(xe,ye,:),[],95));
count_vhr_east = sum(reshape(vhr(xe,ye,:),[],95));
count_ehr_east = sum(reshape(ehr(xe,ye,:),[],95));
  4 Kommentare
Matt Tearle
Matt Tearle am 18 Apr. 2014
I'm afraid I don't understand your first comment. You seem to be talking about doing some calculation at each lat, each lon, and each time. But that's how the data already is. I thought the point of your question was to count the number of occurrences in given ranges. If you do that at each point, your "count" will be 0 or 1 (ie true or false). If that's what you want, just use a logical comparison.
If you need to deal with leap years, then the problem changes completely because the data that you're aggregating isn't uniformly sized. You'll need some way to know which data point corresponds to which year (there's no way to figure out whether a year is 365 or 366 observations without knowing which year it is). If you have a 34698-element vector that holds the years (the datevec function might help here), you could perhaps use accumarray to accumulate the data based on year.
You should start a new question about this, because it's not the same as this one. Feel free to link it from a comment here.
ravi
ravi am 20 Apr. 2014
Bearbeitet: ravi am 18 Mai 2014
sir i have different-different model data output one model data output occur leap years i mean data size is (95*365+23=34698) i want to do same work for every model data output. i mean i want to also count extreme event annually for this model data but i am unable to this work.i am trying last 2 week but every time i got wrong result please sir help me.thank you sir.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Matt Tearle
Matt Tearle am 11 Apr. 2014
The reshape function is going to be your friend here. I think I've interpreted your intention correctly, in which case, your code can be simplified to:
% Change to lon/lat/day/year
prec_all_years = reshape(prec_all_years,20,22,365,95);
prec_all_years = prec_all_years*86400; % rainfall in mm/day
bins = [64.5 124.5 244.5 Inf];
% Extract a region
xe = 13:20; ye = 11:16;% xe is x for east,ye is y for east
% Reshape into matrix of observations-by-year and bin into ranges
counts = histc(reshape(prec_all_years(xe,ye,:,:),[],95),bins);
% Extract counts for each category
count_hr_east = counts(1,:);
count_vhr_east = counts(2,:);
count_ehr_east = counts(3,:);
The result is three vectors, one for each category, each with 95 elements (one per year). Repeat for the different regions.
  4 Kommentare
Sean de Wolski
Sean de Wolski am 11 Apr. 2014
Matt, I've gone ahead and tagged you for this :)
Image Analyst
Image Analyst am 11 Apr. 2014
Hey can I get in on the party? I commented to him here and I didn't win fame, admiration, and glory there, so I'm taking another shot at it here.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Variables finden Sie in Help Center und File Exchange

Tags

Noch keine Tags eingegeben.

Community Treasure Hunt

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

Start Hunting!

Translated by