Loop over rasters to calculate mean values for weekly

1348
9
08-10-2017 01:23 PM
DuminduJayasekera
New Contributor III

Hi,

I have multiple rasters named as follows for each year. But, I need to calculate mean for weekly ONLY for 09, 10 and 11 months based on the following week definition.

Week 1: Day 01, 02, 03, 04, 05, 06

Week 2: Day 07, 08, 09, 10, 11, 12

Week 3: Day 13, 14, 15, 16, 17, 18

Week 4: Day 19, 20, 21, 22, 23, 24

Week 5: Day 25, 26, 27, 28, 29, 30, 31

Can anybody suggest me a way to process months 9, 10 and 11 in one go for the following script.?

 

Thanks in advance,

import arcpy
import arcpy.sa
from arcpy.sa import *
from arcpy import env
import os

arcpy.CheckOutExtension("Spatial")
arcpy.OverwriteOutput = True

arcpy.env.workspace = r'H:\Test_ONLY'
scratch = r'H:\Test_ONLY\scratch'

year = 1998
month = 01
fmaskrasters = arcpy.ListRasters()
fmaskrasters.sort()


if year % 4 > 0 and month == 9:
     fmaskrasters1 = fmaskrasters[243:249]
     fmaskrasters2 = fmaskrasters[249:255]
     fmaskrasters3 = fmaskrasters[255:261]
     fmaskrasters4 = fmaskrasters[261:267]
     fmaskrasters5 = fmaskrasters[267:273]
elif year % 4 == 0 and month == 9:
     fmaskrasters1 = fmaskrasters[244:250]
     fmaskrasters2 = fmaskrasters[250:256]
     fmaskrasters3 = fmaskrasters[256:262]
     fmaskrasters4 = fmaskrasters[262:268]
     fmaskrasters5 = fmaskrasters[268:274]
elif year % 4 > 0 and month == 10:
     fmaskrasters1 = fmaskrasters[273:279]
     fmaskrasters2 = fmaskrasters[279:285]
     fmaskrasters3 = fmaskrasters[285:291]
     fmaskrasters4 = fmaskrasters[291:297]
     fmaskrasters5 = fmaskrasters[297:304]
elif year % 4 == 0 and month == 10:
     fmaskrasters1 = fmaskrasters[274:280]
     fmaskrasters2 = fmaskrasters[280:286]
     fmaskrasters3 = fmaskrasters[286:292]
     fmaskrasters4 = fmaskrasters[292:298]
     fmaskrasters5 = fmaskrasters[298:305]
elif year % 4 > 0 and month == 11:
     fmaskrasters1 = fmaskrasters[304:310]
     fmaskrasters2 = fmaskrasters[310:316]
     fmaskrasters3 = fmaskrasters[316:322]
     fmaskrasters4 = fmaskrasters[322:328]
     fmaskrasters5 = fmaskrasters[328:334]
elif year % 4 == 0 and month == 11:
     fmaskrasters1 = fmaskrasters[305:311]
     fmaskrasters2 = fmaskrasters[311:317]
     fmaskrasters3 = fmaskrasters[317:323]
     fmaskrasters4 = fmaskrasters[323:329]
     fmaskrasters5 = fmaskrasters[329:335]
else:
     print("Not configured in the script!")


number = len(fmaskrasters)

# Week 1
finras1 = scratch + "\\" + "Week_1_Avg" + str(year) + "_" + str(month) + ".tif"
calc1 = arcpy.sa.CellStatistics([fmaskrasters1], statistics_type = "MEAN")
arcpy.CopyRaster_management(calc1,finras1,"","","","","","32_BIT_FLOAT")

# Week 2
finras2 = scratch + "\\" + "Week_2_Avg" + str(year) + "_" + str(month) + ".tif"
calc2 = arcpy.sa.CellStatistics([fmaskrasters2], statistics_type = "MEAN")
arcpy.CopyRaster_management(calc2,finras2,"","","","","","32_BIT_FLOAT")

# Week 3
finras3 = scratch + "\\" + "Week_3_Avg" + str(year) + "_" + str(month) + ".tif"
calc3 = arcpy.sa.CellStatistics([fmaskrasters3], statistics_type = "MEAN")
arcpy.CopyRaster_management(calc3,finras3,"","","","","","32_BIT_FLOAT")

# Week 4
finras4 = scratch + "\\" + "Week_4_Avg" + str(year) + "_" + str(month) + ".tif"
calc4 = arcpy.sa.CellStatistics([fmaskrasters4], statistics_type = "MEAN")
arcpy.CopyRaster_management(calc4,finras4,"","","","","","32_BIT_FLOAT")

# Week 5
finras5 = scratch + "\\" + "Week_5_Avg" + str(year) + "_" + str(month) + ".tif"
calc5 = arcpy.sa.CellStatistics([fmaskrasters5], statistics_type = "MEAN")
arcpy.CopyRaster_management(calc5,finras5,"","","","","","32_BIT_FLOAT")
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
Tags (3)
0 Kudos
9 Replies
IanMurray
Frequent Contributor

Could you give some examples on how you named the files?  I feel like if they are named in a uniform easy to parse manner it would fairly simple to make separate lists for years and months and weeks and then use them as input for Cell Statistics.

0 Kudos
DuminduJayasekera
New Contributor III

Thanks Ian for the reply. The file names are as follows:

prism_ppt_us_30s_19980101.bil

prism_ppt_us_30s_19980102.bil

prism_ppt_us_30s_19980103.bil

.

.

prism_ppt_us_30s_19981231.bil

These files are in H:/Test_ONLY folder. I have years from 1998 to 2016.

Hope this helps.

0 Kudos
XanderBakker
Esri Esteemed Contributor

It would be good to learn something more about the definition of the weeks from months 9 till 11. Should these start on Sunday or Monday or what day? In different years you may end up with a different amount of weeks that "intersect" with those 3 months.

Look at the code below:

def main():
    from datetime import date, datetime, timedelta
    from calendar import monthrange

    # settings foro years and months
    years = range(1998, 2017)
    months = [9, 10, 11]

    # Let's assume that a week starts on Monday (0) and ends on Sunday (6)

    for year in years:
        min_month = min(months)
        max_month = max(months)
        first_date = date(year, min_month, 1)
        first_week = first_date.isocalendar()[1]-1
        first_week_day = first_date.isoweekday() # Monday is 0 and Sunday is 6
        # to start that week on monday
        days_less = timedelta(days=(-1*first_week_day))
        first_date += days_less

        last_day = monthrange(year, max_month)[1]
        last_date = date(year, max_month, last_day)
        last_week = last_date.isocalendar()[1]-1
        last_week_day = last_date.isoweekday() # Monday is 0 and Sunday is 6
        days_more = timedelta(days=(6-last_week_day))
        last_date += days_more

        cnt_weeks = last_week - first_week + 1

        print "Year: {0}, first week: {1}, last week: {2}, week count: {3}, first date: {4}, last date: {5}".format(
                year, first_week, last_week, cnt_weeks, first_date, last_date)


if __name__ == '__main__':
    main()

This will print out:

Year: 1998, first week: 35, last week: 48, week count: 14, first date: 1998-08-30, last date: 1998-12-05
Year: 1999, first week: 34, last week: 47, week count: 14, first date: 1999-08-29, last date: 1999-12-04
Year: 2000, first week: 34, last week: 47, week count: 14, first date: 2000-08-27, last date: 2000-12-02
Year: 2001, first week: 34, last week: 47, week count: 14, first date: 2001-08-26, last date: 2001-12-01
Year: 2002, first week: 34, last week: 47, week count: 14, first date: 2002-08-25, last date: 2002-11-30
Year: 2003, first week: 35, last week: 47, week count: 13, first date: 2003-08-31, last date: 2003-11-29
Year: 2004, first week: 35, last week: 48, week count: 14, first date: 2004-08-29, last date: 2004-12-04
Year: 2005, first week: 34, last week: 47, week count: 14, first date: 2005-08-28, last date: 2005-12-03
Year: 2006, first week: 34, last week: 47, week count: 14, first date: 2006-08-27, last date: 2006-12-02
Year: 2007, first week: 34, last week: 47, week count: 14, first date: 2007-08-26, last date: 2007-12-01
Year: 2008, first week: 35, last week: 47, week count: 13, first date: 2008-08-31, last date: 2008-11-29
Year: 2009, first week: 35, last week: 48, week count: 14, first date: 2009-08-30, last date: 2009-12-05
Year: 2010, first week: 34, last week: 47, week count: 14, first date: 2010-08-29, last date: 2010-12-04
Year: 2011, first week: 34, last week: 47, week count: 14, first date: 2011-08-28, last date: 2011-12-03
Year: 2012, first week: 34, last week: 47, week count: 14, first date: 2012-08-26, last date: 2012-12-01
Year: 2013, first week: 34, last week: 47, week count: 14, first date: 2013-08-25, last date: 2013-11-30
Year: 2014, first week: 35, last week: 47, week count: 13, first date: 2014-08-31, last date: 2014-11-29
Year: 2015, first week: 35, last week: 48, week count: 14, first date: 2015-08-30, last date: 2015-12-05
Year: 2016, first week: 34, last week: 47, week count: 14, first date: 2016-08-28, last date: 2016-12-03

I just noticed that in some case (2003, 2008 and 2014) the last date is including November 30st. Will check in that, but the idea is to get a clearer definition of what you mean with the week that are part of months 9 to 11. 

XanderBakker
Esri Esteemed Contributor

my bad, I used "isoweekday" (1 to 7) on lines 16 and 26 and used the definition (0 to 6) which corresponds to the definition used by "weekday". Change isoweekday to "weekday" and you will get this result:

Year: 1998, first week: 35, last week: 48, week count: 14, first date: 1998-08-31, last date: 1998-12-06
Year: 1999, first week: 34, last week: 47, week count: 14, first date: 1999-08-30, last date: 1999-12-05
Year: 2000, first week: 34, last week: 47, week count: 14, first date: 2000-08-28, last date: 2000-12-03
Year: 2001, first week: 34, last week: 47, week count: 14, first date: 2001-08-27, last date: 2001-12-02
Year: 2002, first week: 34, last week: 47, week count: 14, first date: 2002-08-26, last date: 2002-12-01
Year: 2003, first week: 35, last week: 47, week count: 13, first date: 2003-09-01, last date: 2003-11-30
Year: 2004, first week: 35, last week: 48, week count: 14, first date: 2004-08-30, last date: 2004-12-05
Year: 2005, first week: 34, last week: 47, week count: 14, first date: 2005-08-29, last date: 2005-12-04
Year: 2006, first week: 34, last week: 47, week count: 14, first date: 2006-08-28, last date: 2006-12-03
Year: 2007, first week: 34, last week: 47, week count: 14, first date: 2007-08-27, last date: 2007-12-02
Year: 2008, first week: 35, last week: 47, week count: 13, first date: 2008-09-01, last date: 2008-11-30
Year: 2009, first week: 35, last week: 48, week count: 14, first date: 2009-08-31, last date: 2009-12-06
Year: 2010, first week: 34, last week: 47, week count: 14, first date: 2010-08-30, last date: 2010-12-05
Year: 2011, first week: 34, last week: 47, week count: 14, first date: 2011-08-29, last date: 2011-12-04
Year: 2012, first week: 34, last week: 47, week count: 14, first date: 2012-08-27, last date: 2012-12-02
Year: 2013, first week: 34, last week: 47, week count: 14, first date: 2013-08-26, last date: 2013-12-01
Year: 2014, first week: 35, last week: 47, week count: 13, first date: 2014-09-01, last date: 2014-11-30
Year: 2015, first week: 35, last week: 48, week count: 14, first date: 2015-08-31, last date: 2015-12-06
Year: 2016, first week: 34, last week: 47, week count: 14, first date: 2016-08-29, last date: 2016-12-04

So there are a few years that will have 13 weeks (13 mean rasters) and the rest will have 14 weeks. Is that what you are after or do you want to have a fixed number of weeks?

0 Kudos
XanderBakker
Esri Esteemed Contributor

After you have the weeks defined you can do something like this (see code below) to get the individual rasters for a week into a list

def main():
    from datetime import date, datetime, timedelta
    from calendar import monthrange
    import os

    # settings foro years and months
    years = range(1998, 2017)
    months = [9, 10, 11]
    name_template = 'prism_ppt_us_30s_{0}.bil'
    ws = r'H:\Test_ONLY'

    # Let's assume that a week starts on Monday (0) and ends on Sunday (6)
    for year in years:
        min_month = min(months)
        max_month = max(months)
        first_date = date(year, min_month, 1)
        first_week = first_date.isocalendar()[1]-1
        first_week_day = first_date.weekday() # Monday is 0 and Sunday is 6
        # to start that week on monday
        days_less = timedelta(days=(-1*first_week_day))
        first_date += days_less

        last_day = monthrange(year, max_month)[1]
        last_date = date(year, max_month, last_day)
        last_week = last_date.isocalendar()[1]-1
        last_week_day = last_date.weekday() # Monday is 0 and Sunday is 6
        days_more = timedelta(days=(6-last_week_day))
        last_date += days_more

        cnt_weeks = last_week - first_week + 1

        print "Year: {0}, first week: {1}, last week: {2}, week count: {3}, first date: {4}, last date: {5}".format(
                year, first_week, last_week, cnt_weeks, first_date, last_date)

        for week in range(cnt_weeks):
            print " - week:", first_week + week
            days_more = timedelta(days=(week*7))
            start_date = first_date + days_more
            rasters = []
            for day in range(7):
                days_more = timedelta(days=day)
                current_date = start_date + days_more
                ras_name = name_template.format(current_date.strftime('%Y%m%d'))
                print "   - raster:", ras_name
                rasters.append(os.path.join(ws, ras_name))
            print "   - do something with rasters list:",rasters


if __name__ == '__main__':
    main()

Which will print out this:

Year: 1998, first week: 35, last week: 48, week count: 14, first date: 1998-08-31, last date: 1998-12-06
 - week: 35
   - raster: prism_ppt_us_30s_19980831.bil
   - raster: prism_ppt_us_30s_19980901.bil
   - raster: prism_ppt_us_30s_19980902.bil
   - raster: prism_ppt_us_30s_19980903.bil
   - raster: prism_ppt_us_30s_19980904.bil
   - raster: prism_ppt_us_30s_19980905.bil
   - raster: prism_ppt_us_30s_19980906.bil
   - do something with rasters list: ['H:\\Test_ONLY\\prism_ppt_us_30s_19980831.bil', 'H:\\Test_ONLY\\prism_ppt_us_30s_19980901.bil', 'H:\\Test_ONLY\\prism_ppt_us_30s_19980902.bil', 'H:\\Test_ONLY\\prism_ppt_us_30s_19980903.bil', 'H:\\Test_ONLY\\prism_ppt_us_30s_19980904.bil', 'H:\\Test_ONLY\\prism_ppt_us_30s_19980905.bil', 'H:\\Test_ONLY\\prism_ppt_us_30s_19980906.bil']
 - week: 36
   - raster: prism_ppt_us_30s_19980907.bil
   - raster: prism_ppt_us_30s_19980908.bil
   - raster: prism_ppt_us_30s_19980909.bil
   - raster: prism_ppt_us_30s_19980910.bil
   - raster: prism_ppt_us_30s_19980911.bil
   - raster: prism_ppt_us_30s_19980912.bil
   - raster: prism_ppt_us_30s_19980913.bil
   - do something with rasters list: ['H:\\Test_ONLY\\prism_ppt_us_30s_19980907.bil', 'H:\\Test_ONLY\\prism_ppt_us_30s_19980908.bil', 'H:\\Test_ONLY\\prism_ppt_us_30s_19980909.bil', 'H:\\Test_ONLY\\prism_ppt_us_30s_19980910.bil', 'H:\\Test_ONLY\\prism_ppt_us_30s_19980911.bil', 'H:\\Test_ONLY\\prism_ppt_us_30s_19980912.bil', 'H:\\Test_ONLY\\prism_ppt_us_30s_19980913.bil']

...

 - week: 46
   - raster: prism_ppt_us_30s_20161121.bil
   - raster: prism_ppt_us_30s_20161122.bil
   - raster: prism_ppt_us_30s_20161123.bil
   - raster: prism_ppt_us_30s_20161124.bil
   - raster: prism_ppt_us_30s_20161125.bil
   - raster: prism_ppt_us_30s_20161126.bil
   - raster: prism_ppt_us_30s_20161127.bil
   - do something with rasters list: ['H:\\Test_ONLY\\prism_ppt_us_30s_20161121.bil', 'H:\\Test_ONLY\\prism_ppt_us_30s_20161122.bil', 'H:\\Test_ONLY\\prism_ppt_us_30s_20161123.bil', 'H:\\Test_ONLY\\prism_ppt_us_30s_20161124.bil', 'H:\\Test_ONLY\\prism_ppt_us_30s_20161125.bil', 'H:\\Test_ONLY\\prism_ppt_us_30s_20161126.bil', 'H:\\Test_ONLY\\prism_ppt_us_30s_20161127.bil']
 - week: 47
   - raster: prism_ppt_us_30s_20161128.bil
   - raster: prism_ppt_us_30s_20161129.bil
   - raster: prism_ppt_us_30s_20161130.bil
   - raster: prism_ppt_us_30s_20161201.bil
   - raster: prism_ppt_us_30s_20161202.bil
   - raster: prism_ppt_us_30s_20161203.bil
   - raster: prism_ppt_us_30s_20161204.bil
   - do something with rasters list: ['H:\\Test_ONLY\\prism_ppt_us_30s_20161128.bil', 'H:\\Test_ONLY\\prism_ppt_us_30s_20161129.bil', 'H:\\Test_ONLY\\prism_ppt_us_30s_20161130.bil', 'H:\\Test_ONLY\\prism_ppt_us_30s_20161201.bil', 'H:\\Test_ONLY\\prism_ppt_us_30s_20161202.bil', 'H:\\Test_ONLY\\prism_ppt_us_30s_20161203.bil', 'H:\\Test_ONLY\\prism_ppt_us_30s_20161204.bil']
DuminduJayasekera
New Contributor III

Thanks Xander for the reply. The starting day does not matter for me. I just need to take the average for the weekly definition. For the week 5 it should take the remaining day for that month to average it. Let's say for the month of February it should take day 25 to 28 and average it. If it is a leap year up to 29. If the month is August 25 to 31 and for September 25 to 30 etc. I do not mind which day it starts Monday or Sunday. This week definition is defined with particular interest for the project I work on. 

0 Kudos
XanderBakker
Esri Esteemed Contributor

Thanks for the reply, but I'm still not completely sure how the weeks should be defined:

I just ran a small snippet of code:

import calendar
for month in range(9, 12):
    print "\n", calendar.month(1998, month)‍‍‍

Which prints:

   September 1998
Mo Tu We Th Fr Sa Su
    1  2  3  4  5  6
 7  8  9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30


    October 1998
Mo Tu We Th Fr Sa Su
          1  2  3  4
 5  6  7  8  9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31


   November 1998
Mo Tu We Th Fr Sa Su
                   1
 2  3  4  5  6  7  8
 9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

How will your weeks in this case be defined?

0 Kudos
DuminduJayasekera
New Contributor III

Thanks again. Weeks should be defined by the Julian day of the year. Please take a look at my revised code above. Hope you can understand. For example, if year is 1998 then September 01 to September 06 (Julian days are from 243 to 249. 

I need to revised my above code if I have all the files in one folder (Test_ONLY). My code above does the job but I need to change years and month after each run and replace the files in the Test_ONLY folder for the corresponding year. 

I would like to place all the files (From 1998 to 2016) in Test_ONLY folder and automate the process above.

Hope this helps to understand. 

0 Kudos
XanderBakker
Esri Esteemed Contributor

OK, have a look at the following code:

from datetime import datetime, timedelta, date

def main():
    import calendar
    import os

    # locations and naming
    name_template = 'prism_ppt_us_30s_{0}.bil'
    ws = r'H:\Test_ONLY'

    # setting
    years = range(1998, 2017)
    months = range(9, 12)
    days_in_week = 6  # are you sure?
    number_of_weeks = 15

    for year in years:
        print '\n', year
        if calendar.isleap(year):
            start_ord = 244
        else:
            start_ord = 243

        for week in range(number_of_weeks):
            ordinal = start_ord + (week * days_in_week)
            month, day = GetDayAndMonthFromOrdinal(ordinal)
            rasters = []
            for day_num in range(days_in_week):
                days_more = timedelta(days=day_num)
                current_day = date(year, month, day) + days_more
                ras_name = name_template.format(current_day.strftime('%Y%m%d'))
                #rasters.append(os.path.join(ws, ras_name))
                rasters.append(ras_name)

            print week + 1, rasters


def GetDayAndMonthFromOrdinal(ordinal):
    d = datetime.fromordinal(ordinal)
    return d.month, d.day


if __name__ == '__main__':
    main()‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

This will print:

1998
1 ['prism_ppt_us_30s_19980831.bil', 'prism_ppt_us_30s_19980901.bil', 'prism_ppt_us_30s_19980902.bil', 'prism_ppt_us_30s_19980903.bil', 'prism_ppt_us_30s_19980904.bil', 'prism_ppt_us_30s_19980905.bil']
2 ['prism_ppt_us_30s_19980906.bil', 'prism_ppt_us_30s_19980907.bil', 'prism_ppt_us_30s_19980908.bil', 'prism_ppt_us_30s_19980909.bil', 'prism_ppt_us_30s_19980910.bil', 'prism_ppt_us_30s_19980911.bil']
3 ['prism_ppt_us_30s_19980912.bil', 'prism_ppt_us_30s_19980913.bil', 'prism_ppt_us_30s_19980914.bil', 'prism_ppt_us_30s_19980915.bil', 'prism_ppt_us_30s_19980916.bil', 'prism_ppt_us_30s_19980917.bil']
4 ['prism_ppt_us_30s_19980918.bil', 'prism_ppt_us_30s_19980919.bil', 'prism_ppt_us_30s_19980920.bil', 'prism_ppt_us_30s_19980921.bil', 'prism_ppt_us_30s_19980922.bil', 'prism_ppt_us_30s_19980923.bil']
5 ['prism_ppt_us_30s_19980924.bil', 'prism_ppt_us_30s_19980925.bil', 'prism_ppt_us_30s_19980926.bil', 'prism_ppt_us_30s_19980927.bil', 'prism_ppt_us_30s_19980928.bil', 'prism_ppt_us_30s_19980929.bil']
6 ['prism_ppt_us_30s_19980930.bil', 'prism_ppt_us_30s_19981001.bil', 'prism_ppt_us_30s_19981002.bil', 'prism_ppt_us_30s_19981003.bil', 'prism_ppt_us_30s_19981004.bil', 'prism_ppt_us_30s_19981005.bil']
7 ['prism_ppt_us_30s_19981006.bil', 'prism_ppt_us_30s_19981007.bil', 'prism_ppt_us_30s_19981008.bil', 'prism_ppt_us_30s_19981009.bil', 'prism_ppt_us_30s_19981010.bil', 'prism_ppt_us_30s_19981011.bil']
8 ['prism_ppt_us_30s_19981012.bil', 'prism_ppt_us_30s_19981013.bil', 'prism_ppt_us_30s_19981014.bil', 'prism_ppt_us_30s_19981015.bil', 'prism_ppt_us_30s_19981016.bil', 'prism_ppt_us_30s_19981017.bil']
9 ['prism_ppt_us_30s_19981018.bil', 'prism_ppt_us_30s_19981019.bil', 'prism_ppt_us_30s_19981020.bil', 'prism_ppt_us_30s_19981021.bil', 'prism_ppt_us_30s_19981022.bil', 'prism_ppt_us_30s_19981023.bil']
10 ['prism_ppt_us_30s_19981024.bil', 'prism_ppt_us_30s_19981025.bil', 'prism_ppt_us_30s_19981026.bil', 'prism_ppt_us_30s_19981027.bil', 'prism_ppt_us_30s_19981028.bil', 'prism_ppt_us_30s_19981029.bil']
11 ['prism_ppt_us_30s_19981030.bil', 'prism_ppt_us_30s_19981031.bil', 'prism_ppt_us_30s_19981101.bil', 'prism_ppt_us_30s_19981102.bil', 'prism_ppt_us_30s_19981103.bil', 'prism_ppt_us_30s_19981104.bil']
12 ['prism_ppt_us_30s_19981105.bil', 'prism_ppt_us_30s_19981106.bil', 'prism_ppt_us_30s_19981107.bil', 'prism_ppt_us_30s_19981108.bil', 'prism_ppt_us_30s_19981109.bil', 'prism_ppt_us_30s_19981110.bil']
13 ['prism_ppt_us_30s_19981111.bil', 'prism_ppt_us_30s_19981112.bil', 'prism_ppt_us_30s_19981113.bil', 'prism_ppt_us_30s_19981114.bil', 'prism_ppt_us_30s_19981115.bil', 'prism_ppt_us_30s_19981116.bil']
14 ['prism_ppt_us_30s_19981117.bil', 'prism_ppt_us_30s_19981118.bil', 'prism_ppt_us_30s_19981119.bil', 'prism_ppt_us_30s_19981120.bil', 'prism_ppt_us_30s_19981121.bil', 'prism_ppt_us_30s_19981122.bil']
15 ['prism_ppt_us_30s_19981123.bil', 'prism_ppt_us_30s_19981124.bil', 'prism_ppt_us_30s_19981125.bil', 'prism_ppt_us_30s_19981126.bil', 'prism_ppt_us_30s_19981127.bil', 'prism_ppt_us_30s_19981128.bil']

...

1 ['prism_ppt_us_30s_20160901.bil', 'prism_ppt_us_30s_20160902.bil', 'prism_ppt_us_30s_20160903.bil', 'prism_ppt_us_30s_20160904.bil', 'prism_ppt_us_30s_20160905.bil', 'prism_ppt_us_30s_20160906.bil']
2 ['prism_ppt_us_30s_20160907.bil', 'prism_ppt_us_30s_20160908.bil', 'prism_ppt_us_30s_20160909.bil', 'prism_ppt_us_30s_20160910.bil', 'prism_ppt_us_30s_20160911.bil', 'prism_ppt_us_30s_20160912.bil']
3 ['prism_ppt_us_30s_20160913.bil', 'prism_ppt_us_30s_20160914.bil', 'prism_ppt_us_30s_20160915.bil', 'prism_ppt_us_30s_20160916.bil', 'prism_ppt_us_30s_20160917.bil', 'prism_ppt_us_30s_20160918.bil']
4 ['prism_ppt_us_30s_20160919.bil', 'prism_ppt_us_30s_20160920.bil', 'prism_ppt_us_30s_20160921.bil', 'prism_ppt_us_30s_20160922.bil', 'prism_ppt_us_30s_20160923.bil', 'prism_ppt_us_30s_20160924.bil']
5 ['prism_ppt_us_30s_20160925.bil', 'prism_ppt_us_30s_20160926.bil', 'prism_ppt_us_30s_20160927.bil', 'prism_ppt_us_30s_20160928.bil', 'prism_ppt_us_30s_20160929.bil', 'prism_ppt_us_30s_20160930.bil']
6 ['prism_ppt_us_30s_20161001.bil', 'prism_ppt_us_30s_20161002.bil', 'prism_ppt_us_30s_20161003.bil', 'prism_ppt_us_30s_20161004.bil', 'prism_ppt_us_30s_20161005.bil', 'prism_ppt_us_30s_20161006.bil']
7 ['prism_ppt_us_30s_20161007.bil', 'prism_ppt_us_30s_20161008.bil', 'prism_ppt_us_30s_20161009.bil', 'prism_ppt_us_30s_20161010.bil', 'prism_ppt_us_30s_20161011.bil', 'prism_ppt_us_30s_20161012.bil']
8 ['prism_ppt_us_30s_20161013.bil', 'prism_ppt_us_30s_20161014.bil', 'prism_ppt_us_30s_20161015.bil', 'prism_ppt_us_30s_20161016.bil', 'prism_ppt_us_30s_20161017.bil', 'prism_ppt_us_30s_20161018.bil']
9 ['prism_ppt_us_30s_20161019.bil', 'prism_ppt_us_30s_20161020.bil', 'prism_ppt_us_30s_20161021.bil', 'prism_ppt_us_30s_20161022.bil', 'prism_ppt_us_30s_20161023.bil', 'prism_ppt_us_30s_20161024.bil']
10 ['prism_ppt_us_30s_20161025.bil', 'prism_ppt_us_30s_20161026.bil', 'prism_ppt_us_30s_20161027.bil', 'prism_ppt_us_30s_20161028.bil', 'prism_ppt_us_30s_20161029.bil', 'prism_ppt_us_30s_20161030.bil']
11 ['prism_ppt_us_30s_20161031.bil', 'prism_ppt_us_30s_20161101.bil', 'prism_ppt_us_30s_20161102.bil', 'prism_ppt_us_30s_20161103.bil', 'prism_ppt_us_30s_20161104.bil', 'prism_ppt_us_30s_20161105.bil']
12 ['prism_ppt_us_30s_20161106.bil', 'prism_ppt_us_30s_20161107.bil', 'prism_ppt_us_30s_20161108.bil', 'prism_ppt_us_30s_20161109.bil', 'prism_ppt_us_30s_20161110.bil', 'prism_ppt_us_30s_20161111.bil']
13 ['prism_ppt_us_30s_20161112.bil', 'prism_ppt_us_30s_20161113.bil', 'prism_ppt_us_30s_20161114.bil', 'prism_ppt_us_30s_20161115.bil', 'prism_ppt_us_30s_20161116.bil', 'prism_ppt_us_30s_20161117.bil']
14 ['prism_ppt_us_30s_20161118.bil', 'prism_ppt_us_30s_20161119.bil', 'prism_ppt_us_30s_20161120.bil', 'prism_ppt_us_30s_20161121.bil', 'prism_ppt_us_30s_20161122.bil', 'prism_ppt_us_30s_20161123.bil']
15 ['prism_ppt_us_30s_20161124.bil', 'prism_ppt_us_30s_20161125.bil', 'prism_ppt_us_30s_20161126.bil', 'prism_ppt_us_30s_20161127.bil', 'prism_ppt_us_30s_20161128.bil', 'prism_ppt_us_30s_20161129.bil']

So you have a list of 6 rasters for each week (are you sure you want to work with 6 days in each week?) and you have 15 "weeks" in those 3 months. When it is a leap year the start ordinal (it's not really Julian) will be 244 otherwise it will be 243 (following your code). 

If you need the rasters including the path (work space) you can un-comment line 32 and comment line 33.

On line 35 you would perform your cel statistics to calculate the mean. I noticed that you have raster in the BIL (band interleaved by line) format. I assume that each raster has a single band?