# SUMMARY:      channelclass.py
# USAGE:        Part of python version createstreamnetwork. Classify
#		channel based on slope and average contributing area.
#		Requires mannual modification of channel classification   
#		criteria.
# ORG:          Pacific Northwest National Laboratorys
# E-MAIL:       zhuoran.duan@pnnl.gov
# ORIG-DATE:    Apr-2017
# DESCRIPTION:  Python version of original createstreamnetwork aml
# DESCRIP-END.
# COMMENTS:     This python script is created based on original 
#		AML scripts createstreamnetwork.aml as part of DHSVM
#
#   Stream classification from Nicoleta Cristea based on Castro et al. 2001 6/24/20

import arcpy
from arcpy import env
from arcpy.sa import *
import arcgisscripting

def channelclassfun(streamnet):
    
    fields=['slope','meanmsq','chanclass','hyddepth','hydwidth','effwidth']
    
    with arcpy.da.UpdateCursor(streamnet, fields) as cursor:

        # row[0] - 'slope'
        # row[1] - 'meanmsq' - mean contributing area to channel segment
        # row[2] - 'chanclass' - channel class reference number
        # row[3] - 'hyddepth'
        # row[4] - 'hydwidth'
        # row[5] - 'effwidth'
        
        for row in cursor:
            if (row[0] <= 0.0001 and row[1] <= 120000):
                row[2] = 1
                row[3] = 0.3
                row[4] = 6.1
                row[5] = 4.9
            elif (row[0] <= 0.0001 and (row[1] > 120,000 and row[1] <= 500,000)):
                row[2] = 2
                row[3] = 0.5
                row[4] = 11.3
                row[5] = 9.1
            elif (row[0] <= 0.0001 and (row[1] > 500,000 and row[1] <= 5,000,000)):
                row[2] = 3
                row[3] = 1.3
                row[4] = 30.5
                row[5] = 24.4
            elif (row[0] <= 0.0001 and (row[1] > 5,000,000 and row[1] <= 20,000,000)):
                row[2] = 4
                row[3] = 2.2
                row[4] = 55.4
                row[5] = 44.3
            elif (row[0] <= 0.0001 and (row[1] > 20,000,000 and row[1] <= 170,000,000)):
                row[2] = 5
                row[3] = 5.5
                row[4] = 119.2
                row[5] = 119.2
            elif (row[0] <= 0.0001 and row[1] > 170,000,000):
                row[2] = 6
                row[3] = 5.5
                row[4] = 119.2
                row[5] = 119.2
            elif ((row[0] > 0.0001 and row[0] <= 0.0025) and row[1] <= 120000):
                row[2] = 7
                row[3] = 0.3
                row[4] = 4.9
                row[5] = 3.9
            elif ((row[0] > 0.0001 and row[0] <= 0.0025) and (row[1] > 120000 and row[1] <= 500000)):
                row[2] = 8
                row[3] = 0.5
                row[4] = 9.1
                row[5] = 7.3
            elif ((row[0] > 0.0001 and row[0] <= 0.0025) and (row[1] > 500000 and row[1] <= 5000000)):
                row[2] = 9
                row[3] = 1.1
                row[4] = 24.4
                row[5] = 19.5
            elif ((row[0] > 0.0001 and row[0] <= 0.0025) and (row[1] > 5000000 and row[1] <= 20000000)):
                row[2] = 10
                row[3] = 2.0
                row[4] = 44.3
                row[5] = 35.4
            elif ((row[0] > 0.0001 and row[0] <= 0.0025) and (row[1] > 20000000 and row[1] <= 170000000)):
                row[2] = 11
                row[3] = 4.8
                row[4] = 119.2
                row[5] = 95.4
            elif ((row[0] > 0.0001 and row[0] <= 0.0025) and row[1] > 170000000):
                row[2] = 12
                row[3] = 4.8
                row[4] = 119.2
                row[5] = 95.4
            elif ((row[0] > 0.0025 and row[0] <= 0.005) and row[1] <= 120000):
                row[2] = 13
                row[3] = 0.3
                row[4] = 4.3
                row[5] = 3.4
            elif ((row[0] > 0.0025 and row[0] <= 0.005) and (row[1] > 120000 and row[1] <= 500000)):
                row[2] = 14
                row[3] = 0.5
                row[4] = 7.9
                row[5] = 6.3
            elif ((row[0] > 0.0025 and row[0] <= 0.005) and (row[1] > 500000 and row[1] <= 5000000)):
                row[2] = 15
                row[3] = 1.1
                row[4] = 21.4
                row[5] = 17.1
            elif ((row[0] > 0.0025 and row[0] <= 0.005) and (row[1] > 5000000 and row[1] <= 20000000)):
                row[2] = 16
                row[3] = 2.0
                row[4] = 38.8
                row[5] = 31.0
            elif ((row[0] > 0.0025 and row[0] <= 0.005) and (row[1] > 20000000 and row[1] <= 170000000)):
                row[2] = 17
                row[3] = 4.8
                row[4] = 104.3
                row[5] = 83.5
            elif ((row[0] > 0.0025 and row[0] <= 0.005) and row[1] > 170000000):
                row[2] = 18
                row[3] = 4.8
                row[4] = 104.3
                row[5] = 83.5
            elif ((row[0] > 0.005 and row[0] <= 0.015) and row[1] <= 120000):
                row[2] = 19
                row[3] = 0.2
                row[4] = 3.7
                row[5] = 2.9
            elif ((row[0] > 0.005 and row[0] <= 0.015) and (row[1] > 120000 and row[1] <= 500000)):
                row[2] = 20
                row[3] = 0.4
                row[4] = 6.8
                row[5] = 5.4
            elif ((row[0] > 0.005 and row[0] <= 0.015) and (row[1] > 500000 and row[1] <= 5000000)):
                row[2] = 21
                row[3] = 1.0
                row[4] = 18.3
                row[5] = 14.6
            elif ((row[0] > 0.005 and row[0] <= 0.015) and (row[1] > 5000000 and row[1] <= 20000000)):
                row[2] = 22
                row[3] = 1.7
                row[4] = 33.2
                row[5] = 26.6
            elif ((row[0] > 0.005 and row[0] <= 0.015) and (row[1] > 20000000 and row[1] <= 170000000)):
                row[2] = 23
                row[3] = 4.1
                row[4] = 89.4
                row[5] = 71.5
            elif ((row[0] > 0.005 and row[0] <= 0.015) and row[1] > 170000000):
                row[2] = 24
                row[3] = 4.1
                row[4] = 89.4
                row[5] = 71.5
            elif ((row[0] > 0.015 and row[0] <= 0.035) and row[1] <= 120000):
                row[2] = 25
                row[3] = 0.2
                row[4] = 3.1
                row[5] = 2.5
            elif ((row[0] > 0.015 and row[0] <= 0.035) and (row[1] > 120000 and row[1] <= 500000)):
                row[2] = 26
                row[3] = 0.3
                row[4] = 5.7
                row[5] = 4.5
            elif ((row[0] > 0.015 and row[0] <= 0.035) and (row[1] > 500000 and row[1] <= 5000000)):
                row[2] = 27
                row[3] = 0.8
                row[4] = 15.3
                row[5] = 12.2
            elif ((row[0] > 0.015 and row[0] <= 0.035) and (row[1] > 5000000 and row[1] <= 20000000)):
                row[2] = 28
                row[3] = 1.4
                row[4] = 27.7
                row[5] = 22.1
            elif ((row[0] > 0.015 and row[0] <= 0.035) and (row[1] > 20000000 and row[1] <= 170000000)):
                row[2] = 29
                row[3] = 3.4
                row[4] = 74.5
                row[5] = 59.6
            elif ((row[0] > 0.015 and row[0] <= 0.035) and row[1] > 170000000):
                row[2] = 30
                row[3] = 3.4
                row[4] = 74.5
                row[5] = 59.6                
            elif (row[0] > 0.035 and row[1] <= 120000):
                row[2] = 31
                row[3] = 0.2
                row[4] = 2.5
                row[5] = 2.0
            elif (row[0] > 0.035 and (row[1] > 120000 and row[1] <= 500000)):
                row[2] = 32
                row[3] = 0.3
                row[4] = 4.5
                row[5] = 3.6
            elif (row[0] > 0.035 and (row[1] > 500000 and row[1] <= 5000000)):
                row[2] = 33
                row[3] = 0.7
                row[4] = 12.2
                row[5] = 9.8
            elif (row[0] > 0.035 and (row[1] > 5000000 and row[1] <= 20000000)):
                row[2] = 34
                row[3] = 1.1
                row[4] = 22.1
                row[5] = 17.7
            elif (row[0] > 0.035 and (row[1] > 20000000 and row[1] <= 170000000)):
                row[2] = 35
                row[3] = 2.7
                row[4] = 59.6
                row[5] = 47.7
            elif (row[0] > 0.035 and row[1] > 170000000) :
                row[2] = 36
                row[3] = 2.7
                row[4] = 59.6
                row[5] = 47.7

            # Update the cursor with the updated list
            cursor.updateRow(row)
