フィルターのクリア

How to seasonalise daily weather classification and precipitation data

1 回表示 (過去 30 日間)
Ed Harrison
Ed Harrison 2019 年 3 月 31 日
編集済み: Andrei Bobrov 2019 年 3 月 31 日
Hi,
I'm working on a climate data set for Svalbard from August 1957 to May 2015. I have daily rainall data (mm) and an associated weather classification number (1-11) which corresponds to a weather type for that day.
I'm trying to seasonalise this, for e.g. I want to see how much Rainfall fell on days associated with weather type 1 in spring but I'm having no luck.
Can anyone help?
I've managed to create whole time periods of weather type 1 precipitation for e.g my reference period 1971-00, but I need to seasonalise it first.
Data is attached, with KNG01date_d being the day, and KNG01rain_d being the rainfall (both start 1957.09).
In the attached data, column 1 represents weather type (1-11) and column 2 is the daily rainfall for that data.
For example. My script for finding total rain from weather type 1 between 1971 to 2000:
WC1_1971_00_KNG01_rain = find(KNG01rain_d(4871:15828,1)==1);
Sum_Rain7100_KNG01 = sum(KNG01rain_d(WC1_1971_00_KNG01_rain, :));
WC1_7100 = Sum_Rain7100_KNG01(2);
My question is, how can I seasonalise this to have Spring Summer Autumn Winter and then create weather types 1-11 with corresponding precipiation from that?
Sorry for the long winded and perhaps difficult to understand explanation
Thanks to anyone who can help!
  1 件のコメント
dpb
dpb 2019 年 3 月 31 日
So which months of the year are considered to be which seasons?
See findgroups and splitapply and friends.
I'd suggest using a timeseries object to hold the data or table

サインインしてコメントする。

採用された回答

Guillaume
Guillaume 2019 年 3 月 31 日
編集済み: Guillaume 2019 年 3 月 31 日
Up on the right of the page, there is a field for you to tell your version of matlab. Since it's not filled, I'm assuming a modern enough version that my answer below will work:
The simplest way to do what you want is to store your data in a timetable.
raindata = array2timetable(KNG01rain_d, 'StartTime', datetime(1957, 8,1, 'Format', 'dd-MMM-yyyy'), ...
'TimeStep', days(1), ...
'VariableNames', {'weathertype', 'rainfall'});
Then we can easily add information to the table, such as season:
raindata.season = quarter(raindata.Time);
And if we want to know the sum of rainfall for each season and weather time:
rainfall_per_season_and_weather = groupsummary(raindata, {'season', 'weathertype'}, 'sum')
There are plenty more functions to perform calculations on groups, such as rowfun, splitapply, etc., in modern matlab.
If you want to perform the above just for a certain period:
groupsummary(raindata(isbetween(raindata.Time, datetime(1971,1,1), datetime(1999, 12, 31)), :), ...
{'season', 'weathertype'}, 'sum')
edit: Now that you've attached your date matrix (I thought you left it up to us to work out the date range), you can also build the timetable with:
raindata = array2timetable(KNG01rain_d, ...
'RowTimes', datetime(KNG01date_d, 'ConvertFrom', 'datenum', 'Format', 'dd-MMM-yyyy'), ...
'VariableNames', {'weathertype', 'rainfall'});
According to this, your data starts in september, not august.
Also, I forgot to say, the find in your original code is completely unnecessary
WC1_1971_00_KNG01_rain = KNG01rain_d(4871:15828,1)==1; %no need for find use the logical array directly
Sum_Rain7100_KNG01 = sum(KNG01rain_d(WC1_1971_00_KNG01_rain, :));

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2019 年 3 月 31 日
編集済み: Andrei Bobrov 2019 年 3 月 31 日
Where KNG01date_d?
date1 = datetime(KNG01date_d,'ConvertFrom','datenum');
TT = array2timetable(KNG01rain_d,'RowTimes',date1,...
'v',{' weather_type','rainfall'});
TT.season = discretize(month(TT.Time),[1,3:3:12,13],'categorical',...
{'Winter','Spring','Summer','Autumn','Winter'});
TT_out = varfun(@sum,TT,'GroupingVariables',{'season','weather_type'});
or
TT_out2 = groupsummary(TT,{'season','weather_type'},'sum');
  3 件のコメント
dpb
dpb 2019 年 3 月 31 日
Please attach to original Q?...
Ed Harrison
Ed Harrison 2019 年 3 月 31 日
Done :)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeWeather and Atmospheric Science についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by