JGCRI / an2month

Use CMIP 5 data to approximate monthly data from annual data.
0 stars 0 forks source link

add other sampling schemes #16

Closed abigailsnyder closed 4 years ago

abigailsnyder commented 4 years ago

Forgot to open issue on Jul 06, 2020, when work started: currently, from the code, it appears that the monthly fractions are sampled from a distribution once for each realization of annual data. So every year in realization 1 is the same kind of year, every year in realization 2 is the same kind of year (but different from the kind of year in realization 1).

rplzzz commented 4 years ago

currently, from the code, it appears that the monthly fractions are sampled from a distribution once for each realization of annual data. So every year in realization 1 is the same kind of year, every year in realization 2 is the same kind of year (but different from the kind of year in realization 1).

I don't think that's what's happening. Here is the code that calculates the monthly fractions: https://github.com/JGCRI/an2month/blob/229b4deb8e50a462df8ee8dd9271f16496cbf29f/R/monthly_downscaling.R#L121

This should produce nyear distinct sets of 12 monthly fractions, which are subsequently multiplied by the annual totals to get monthly totals. For example, for nyear = 10:

> alpha <- seq(1,12)
> yrs10 <- gtools::rdirichlet(10, alpha)
> round(yrs10,4)
        [,1]   [,2]   [,3]   [,4]   [,5]   [,6]   [,7]   [,8]   [,9]  [,10]  [,11]  [,12]
 [1,] 0.0167 0.0240 0.0429 0.0175 0.0535 0.1124 0.0848 0.0682 0.1773 0.1497 0.0727 0.1802
 [2,] 0.0085 0.0299 0.0530 0.0951 0.0538 0.0807 0.1000 0.0847 0.1098 0.0952 0.1362 0.1530
 [3,] 0.0065 0.0243 0.0045 0.0727 0.0955 0.1721 0.0658 0.0339 0.0548 0.2302 0.1346 0.1051
 [4,] 0.0331 0.0314 0.0221 0.0690 0.0556 0.0487 0.0717 0.1458 0.1131 0.1415 0.1844 0.0834
 [5,] 0.0125 0.0066 0.0496 0.0559 0.0658 0.1015 0.0364 0.0828 0.1786 0.1142 0.0844 0.2117
 [6,] 0.0366 0.0148 0.0158 0.0173 0.0458 0.1023 0.0585 0.0966 0.1201 0.1516 0.1422 0.1983
 [7,] 0.0071 0.0025 0.0491 0.0829 0.0620 0.0745 0.0827 0.1170 0.0873 0.0910 0.1860 0.1581
 [8,] 0.0001 0.0423 0.0439 0.0262 0.0877 0.1008 0.0652 0.1211 0.0915 0.1442 0.1348 0.1420
 [9,] 0.0074 0.0407 0.0857 0.0541 0.0866 0.0314 0.1105 0.1502 0.1123 0.0992 0.1241 0.0979
[10,] 0.0035 0.0043 0.0461 0.0583 0.1280 0.0378 0.0968 0.0536 0.1275 0.1614 0.1745 0.1081

Unless there is something else that I've missed, this should give the desired result: nyear different years, each with its annual total apportioned according to a different draw from the same Dirichlet distribution.