May-19-2018, 05:16 PM
(This post was last modified: May-19-2018, 05:16 PM by Lightning1800.)
Hi killerrex,
Thank you so much for this response!
Would this also apply to calculating the "cumulative" values for 5 consecutive day periods? For example, Day 0+Day 1+Day 2+Day 3+Day 4. For my particular case, what I was envisioning would be to begin deriving the cumulative value over Day 0 to Day 4 (so, the first 5 days in year 0), and then move to the next group of 5 consecutive days, from Day 1 to Day 5 (i.e. Day 1+Day 2+Day 3+Day 4+Day 5), and then Day 2 to Day 6 (i.e. Day 2+Day 3+Day 4+Day 5+Day 6), and then Day 3 to Day 7, and then Day 4 to Day 8.....etc....all the way to the end of the 51,100 day period (140 years). In this case, would you use the np.sum function to derive cumulative values, and then have the previously generated code (see below) to generate the annual maximum cumulative values?
The output would be similar to before, as the previously generated loop that contains the "np.max" function (as shown in the following code) would derive the "annual" maximum cumulative 5 consecutive day values, so nothing to the previous code would need to be deleted, just expanded on. Based on the existing code (just modified a little, as shown below), but using the np.sum function in a separate loop:
And incorporating this before the previous for loop to define "Quantity2":
Ultimately, the goal is still to obtain maximum values at an annual time scale, as before (which the existing code will do already), but here I would try to specifically obtain the maximum "cumulative" values for every year for each 5 consecutive day periods - there would be about 50,000-51,000 5-consecutive day periods over the 140 years, but the existing np.max function would allow the output to return the maximum cumulative values for each year for each grid cell.
What do you think? Does that make sense?
I apologize for the inconvenience, but I really do appreciate your above response!
Thank you so much for this response!
Would this also apply to calculating the "cumulative" values for 5 consecutive day periods? For example, Day 0+Day 1+Day 2+Day 3+Day 4. For my particular case, what I was envisioning would be to begin deriving the cumulative value over Day 0 to Day 4 (so, the first 5 days in year 0), and then move to the next group of 5 consecutive days, from Day 1 to Day 5 (i.e. Day 1+Day 2+Day 3+Day 4+Day 5), and then Day 2 to Day 6 (i.e. Day 2+Day 3+Day 4+Day 5+Day 6), and then Day 3 to Day 7, and then Day 4 to Day 8.....etc....all the way to the end of the 51,100 day period (140 years). In this case, would you use the np.sum function to derive cumulative values, and then have the previously generated code (see below) to generate the annual maximum cumulative values?
The output would be similar to before, as the previously generated loop that contains the "np.max" function (as shown in the following code) would derive the "annual" maximum cumulative 5 consecutive day values, so nothing to the previous code would need to be deleted, just expanded on. Based on the existing code (just modified a little, as shown below), but using the np.sum function in a separate loop:
# Quantity.shape = [N_time, N_lat, N_lon] year = np.arange(Quantity.shape[0]) // 365 n_year = max(year) + 1 grid = np.empty((n_year, ) + Quantity.shape[1:3]) grid2 = np.empty((n_year, ) + Quantity2.shape[1:3]) for y in range(n_year): # grid [N_lat x N_lon] grid[y, ...] = np.max(Quantity[year == y, ...], axis=0) grid2[y, ...] = np.max(Quantity2[year == y, ...], axis=0)
And incorporating this before the previous for loop to define "Quantity2":
Quantity2=np.zeros(Quantity.shape)#contains all zerosAnd this:
for time in Quantity2 Quantity2[time,...] fiveconsecutivedays=np.sum(Quantity[time-2:time+2,...], axis=0)"Quantity" is the original 3D matrix that was used previously. The "time-2" and "time+2" gives a range of days relative to a specified day. For example, at Day 2, the range would be Day 0 to Day 4 (because 2-2=0 and 2+2=4, so Day 0 to Day 4, relative to Day 2). Using that approach, though, I cannot use Day 0 and Day 1, as well as the final two days in the period, since that would lead to a range that contains days that do not exist. For instance, if you subtract 2 from Day 0 or Day 1, you will end up with a negative day (-2 and -1, respectively). Likewise, you will end up with days that exceed 51100 for the final two days due to time+2 (Day 51,101 and Day 51,102). Thus, some kind of condition would need to be used to tell the loop to ignore those particular days (the very first two days and the very last two days), but I'm just uncertain how to specify the conditions in the for loop and wanted to know of a way to use them for this case?
Ultimately, the goal is still to obtain maximum values at an annual time scale, as before (which the existing code will do already), but here I would try to specifically obtain the maximum "cumulative" values for every year for each 5 consecutive day periods - there would be about 50,000-51,000 5-consecutive day periods over the 140 years, but the existing np.max function would allow the output to return the maximum cumulative values for each year for each grid cell.
What do you think? Does that make sense?
I apologize for the inconvenience, but I really do appreciate your above response!