SUM range of fields and find largest

03-01-2016 10:46 AM
New Contributor

I have a point feature class with fields representing hourly precipitation amounts for a particular storm and many thousands of records.  The number of fields will vary from storm to storm.  I am trying to get the max 6 hour precipitation amounts.  I need it to list fields, SUM row for 1st-6th field, and assign it to Max Precip Field.  Then SUM row for fields 2-7 and if it is larger than 1-6 assign that value, if not leave it the 1-6 value.  Need this to loop till the end of the fields and for every record.  Can somebody recommend the best way and some syntax to accomplish this?  Would this be best accomplished with a numpy array or Update cursor? 

Tags (3)
0 Kudos
2 Replies
MVP Honored Contributor

This can be done in any number of ways - as you've mentioned numpy, or Update Cursor, and also Field Calculator. You just need to choose one, get started, and then post what you've got for more help.

0 Kudos
MVP Esteemed Contributor

What version of ArcMap are you using?  I ask because new support for several useful Python packages was included at 10.4.  Specifically, Pandas is now supported and pandas.rolling_max was built for this type of situation.  If you are working with 10.3.1 or earlier, there is a moving average recipe in the Python deque Recipes ​that can be easily modified to return the sum instead of average and then used to find the maximum:

>>> def moving_sum(iterable, window_size=1):
    from collections import deque
    from itertools import islice
    it = iter(iterable)
    d = deque(islice(it, window_size-1))
    s = sum(d)
    for elem in it:
        s += elem - d.popleft()
        yield s  
>>> rain_hour = (0.25, 0.8, 0.13, 0.08, 0.55, 0.34, 0.35, 0.17, 0.02, 0.6, 0.14)
>>> max(moving_sum(rain_hour, 6))