[Thread Prev][Thread Next][Index]

Re: [ferret_users] Multiplying by days in month



Hi Sam,
The Julian axis makes it a bit tricky.  If you don't mind treating all the February's as having length 28.25, the average length in a Julian calendar, then here's a method:

! Define a variables with the number of days per month
yes? let days = tsequence({31,28.25,31,30,31,30,31,31,30,31,30,31})
! Define a monthly modulo axis, using the /EDGES qualifier, and the running sum of days per
! month, starting with zero at the beginning of January.  I've referenced this to year
! 0000, but you could have the time origin in January of any year.
yes? let edges_days = tsequence({0,31,28.25,31,30,31,30,31,31,30,31,30,31})
yes? define axis/modulo/EDGES/calendar=julian/t0="1-jan-0000:00:00"/units=days \
 monthly_julian = edges_days[l=@iin]


yes? list/prec=6 t[gt=monthly_julian]
             VARIABLE : T
                        axis MONTHLY_JULIAN
             SUBSET   : 12 points (TIME)
             CALENDAR : JULIAN
 16-JAN-1501 12 /  1:   15.500
 15-FEB-1501 03 /  2:   45.125
 16-MAR-1501 18 /  3:   74.750
 16-APR-1501 06 /  4:  105.250
 16-MAY-1501 18 /  5:  135.750
 16-JUN-1501 06 /  6:  166.250
 16-JUL-1501 18 /  7:  196.750
 16-AUG-1501 18 /  8:  227.750
 16-SEP-1501 06 /  9:  258.250
 16-OCT-1501 18 / 10:  288.750
 16-NOV-1501 06 / 11:  319.250
 16-DEC-1501 18 / 12:  349.750


yes? let days_in_months = 
days[gt=monthly_julian@asn]

yes? ! try this to check the time axis:
yes? !
list/t=1-jan-1501:31-dec-1624 days_in_months
! Now this variable is on a monthly Julian axis that should be compatible with your time axis.
yes? let ba_rate_month = ba_rate* days_in_months[gt=ba_rate]



On 10/22/2014 6:56 AM, Sam Rabin wrote:
Ferret gurus —

I have a NetCDF dataset that shows, for each month, the mean daily burned area in each grid cell. I want to convert these daily rates to monthly values, which requires multiplying them by the number of days in each month. As a kludge, I’ve just been multiplying the entire dataset by 365.25/12, but I’d like to do it properly. That is, I want to multiply the values for each January by 31, each February by 28 (29 in leap years!), etc.

I will need to do this regularly in the future, so any advice pertinent to making an external function and/or .jnl script would be much appreciated. Please note that the length of the time axis can differ wildly between instances, so I’d need something general. (Although if it helps, the time axis will almost always be a multiple of 12 months starting in January.)

If it helps, info on the variable (BA_RATE) can be found after my signature.

Thanks in advance!

Sam





yes? show grid BA_RATE
    GRID GKY2
 name       axis              # pts   start                end
 LON       LONGITUDE          144mr   1.25E                1.25W
 LAT       LATITUDE            90 i   89.494S              89.494N
 normal    Z
 TIME      TIME              1488 i   16-JAN-1501 12:00    16-DEC-1624 12:00
yes? list BA_RATE[i=@sum,j=@sum,l=1:5]
             VARIABLE : Burned area (km2/day)
             DATA SET : SSR_force30_luN_esm2mb-FIREunpacked_meanFx_avgProper
             FILENAME : land_month_meanFxAvgProper_1_1501-1624.nc
             SUBSET   : 5 points (TIME)
             CALENDAR : JULIAN
             LONGITUDE: 0E to 0E(360) (XY summed)
             LATITUDE : 90S to 90N (XY summed)
 16-JAN-1501 12 / 1:     80.
 15-FEB-1501 00 / 2:   2339.
 16-MAR-1501 12 / 3:   9201.
 16-APR-1501 00 / 4:  13500.
 16-MAY-1501 12 / 5:  14870.



[Thread Prev][Thread Next][Index]
Contact Us
Dept of Commerce / NOAA / OAR / PMEL / Ferret

Privacy Policy | Disclaimer | Accessibility Statement