# calculating total # of consecutive dry and wet days using NASA's TRMM daily precipitation data

6 views (last 30 days)
Jocelyn on 22 Aug 2019
Commented: Jocelyn on 25 Aug 2019
Hello everyone.
I have 21 years (1998-2018) of daily precipitation data (individual nc4 files, each with lon, lat, precip and time variables).
I need to find the total # of events of consecutive dry/wet days per month during the summer season for each year in the US (June,July,August), if at all possible. For example: June 1998, July 1998, August 1998, June 1999, July 1999, August 1999, ... June 2018, July 2018, August 2018.
Wet days are precip > 1mm and dry days is precip < 0.1 mm. Unfortunately, I couldn't attach a file because it is not supported.
I am brand new to this, and unfortunately, my advisor only uses fortran and can't guide me with this task.

Jess Lovering on 22 Aug 2019
Without seeing the data and how you read in the file, it is a bit difficult to give precise advice, but I would start would these steps and looking into the help for these functions:
Read in the data, convert the time data into a datetime format using the datetime() command:
precip_date = datetime(inputvariable);
You can trim down all of your data to only the summer months using the month() and find() functions:
summer_indices = find(month(precip_date)==6|month(precip_date)==7|month(precip_date)==8)
summer_dates = precip_date(summer_indices);
summer_precip = precip(summer_indices);
Make a varible to classify the data as wet or dry, then assign a value of 1 or 0 to determine if it is a wet or dry day from the precipitation value with something similar to this:
day_class = zeros(1,length(precip); day_class(precip>1) = 1;
Use the diff(day_class) function to see where the values change from wet to dry (-1 or 1 when it changes and zero when it is constant). Hopefully this will at least give you a starting point of where to look in the help.
Jocelyn on 25 Aug 2019
Hello Jessica,
This is how I am reading my data.
d1 = datenum('1998-01-01','yyyy-mm-dd');
d2 = datenum('2018-12-31','yyyy-mm-dd');
d = d1:d2;
datevector = datevec(d);
trmm_dailyUSA = zeros(100,240,numel(d));
for i = 1:numel(d)
data = ['3B42_Daily.',sprintf('%4d',datevector(i,1)),sprintf('%2.2d',datevector(i,2)),sprintf('%2.2d',datevector(i,3)),'.7.nc4'];
hhUSA = hh(lat_trmm>25 & lat_trmm<50 ,lon_trmm>-125 & lon_trmm<-65);
trmm_dailyUSA(:,:,i) = flipud(hhUSA);
end;