<commit_before># -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division

"""
Imported from CalcCNErosRunoffSed.bas
"""

import math
import logging

from .enums import GrowFlag, LandUse


log = logging.getLogger(__name__)


def CalcCN(z, i, Y, j):
    """
    z - data model (public variables)
    i - month
    Y - year
    j - number of days in month
    """
    log.debug('CalcCN')

    z.UncontrolledQ = 0
    z.RetentionEff = 0

    # Calculate Curve Number (CN)
    for l in range(z.NRur):
        z.Qrun = 0
        grow_factor = GrowFlag.intval(z.Grow[i])

        if z.CN[l] > 0:
            if z.Melt <= 0:
                if grow_factor > 0:
                    # growing season
                    if z.AMC5 >= 5.33:
                        z.CNum = z.NewCN[2][l]
                    elif z.AMC5 < 3.56:
                        z.CNum = z.NewCN[0][l] + (z.CN[l] - z.NewCN[0][l]) * z.AMC5 / 3.56
                    else:
                        z.CNum = z.CN[l] + (z.NewCN[2][l] - z.CN[l]) * (z.AMC5 - 3.56) / 1.77
                else:
                    # dormant season
                    if z.AMC5 >= 2.79:
                        z.CNum = z.NewCN[2][l]
                    elif z.AMC5 < 1.27:
                        z.CNum = z.NewCN[0][l] + (z.CN[l] - z.NewCN[0][l]) * z.AMC5 / 1.27
                    else:
                        z.CNum = z.CN[l] + (z.NewCN[2][l] - z.CN[l]) * (z.AMC5 - 1.27) / 1.52
            else:
                z.CNum = z.NewCN[2][l]

            z.Retention = 2540 / z.CNum - 25.4
            if z.Retention < 0:
                z.Retention = 0

            # z.Water balance and runoff calculation
            if z.Water >= 0.2 * z.Retention:
                z.Qrun = (z.Water - 0.2 * z.Retention) ** 2 / (z.Water + 0.8 * z.Retention)
                z.RuralQTotal += z.Qrun * z.Area[l] / z.RurAreaTotal
                z.RurQRunoff[l][i] += z.Qrun
                # TODO: (what is done with "DayQRunoff"? - appears not to be used)
                z.DayQRunoff[Y][i][j] = z.Qrun
                # TODO: (What is done with "AgQRunoff? - apparently nothing)
                if z.Landuse[l] is LandUse.CROPLAND:
                    # (Maybe used for STREAMPLAN?)
                    z.AgQTotal += z.Qrun * z.Area[l]
                    z.AgQRunoff[l][i] += z.Qrun
                elif z.Landuse[l] is LandUse.HAY_PAST:
                    z.AgQTotal += z.Qrun * z.Area[l]
                    z.AgQRunoff[l][i] += z.Qrun
                elif z.Landuse[l] is LandUse.TURFGRASS:
                    z.AgQTotal = z.Qrun * z.Area[l]
                    z.AgQRunoff[l][i] += z.Qrun
            else:
                z.Qrun = 0

        # EROSION, SEDIMENT WASHOFF FOR RURAL AND URBAN LANDUSE
        z.RurEros = 1.32 * z.Erosiv * z.KF[l] * z.LS[l] * z.C[l] * z.P[l] * z.Area[l]

        z.Erosion[Y][i] = z.Erosion[Y][i] + z.RurEros
        z.ErosWashoff[l][i] = z.ErosWashoff[l][i] + z.RurEros
        z.DayErWashoff[l][Y][i][j] = z.RurEros

        if z.SedDelivRatio == 0:
            z.SedDelivRatio = 0.0001
<commit_msg>Fix wrong AgQTotal for Turfgrass land use<commit_after># -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division

"""
Imported from CalcCNErosRunoffSed.bas
"""

import math
import logging

from .enums import GrowFlag, LandUse


log = logging.getLogger(__name__)


def CalcCN(z, i, Y, j):
    """
    z - data model (public variables)
    i - month
    Y - year
    j - number of days in month
    """
    log.debug('CalcCN')

    z.UncontrolledQ = 0
    z.RetentionEff = 0

    # Calculate Curve Number (CN)
    for l in range(z.NRur):
        z.Qrun = 0
        grow_factor = GrowFlag.intval(z.Grow[i])

        if z.CN[l] > 0:
            if z.Melt <= 0:
                if grow_factor > 0:
                    # growing season
                    if z.AMC5 >= 5.33:
                        z.CNum = z.NewCN[2][l]
                    elif z.AMC5 < 3.56:
                        z.CNum = z.NewCN[0][l] + (z.CN[l] - z.NewCN[0][l]) * z.AMC5 / 3.56
                    else:
                        z.CNum = z.CN[l] + (z.NewCN[2][l] - z.CN[l]) * (z.AMC5 - 3.56) / 1.77
                else:
                    # dormant season
                    if z.AMC5 >= 2.79:
                        z.CNum = z.NewCN[2][l]
                    elif z.AMC5 < 1.27:
                        z.CNum = z.NewCN[0][l] + (z.CN[l] - z.NewCN[0][l]) * z.AMC5 / 1.27
                    else:
                        z.CNum = z.CN[l] + (z.NewCN[2][l] - z.CN[l]) * (z.AMC5 - 1.27) / 1.52
            else:
                z.CNum = z.NewCN[2][l]

            z.Retention = 2540 / z.CNum - 25.4
            if z.Retention < 0:
                z.Retention = 0

            # z.Water balance and runoff calculation
            if z.Water >= 0.2 * z.Retention:
                z.Qrun = (z.Water - 0.2 * z.Retention) ** 2 / (z.Water + 0.8 * z.Retention)
                z.RuralQTotal += z.Qrun * z.Area[l] / z.RurAreaTotal
                z.RurQRunoff[l][i] += z.Qrun
                # TODO: (what is done with "DayQRunoff"? - appears not to be used)
                z.DayQRunoff[Y][i][j] = z.Qrun
                # TODO: (What is done with "AgQRunoff? - apparently nothing)
                if z.Landuse[l] is LandUse.CROPLAND:
                    # (Maybe used for STREAMPLAN?)
                    z.AgQTotal += z.Qrun * z.Area[l]
                    z.AgQRunoff[l][i] += z.Qrun
                elif z.Landuse[l] is LandUse.HAY_PAST:
                    z.AgQTotal += z.Qrun * z.Area[l]
                    z.AgQRunoff[l][i] += z.Qrun
                elif z.Landuse[l] is LandUse.TURFGRASS:
                    z.AgQTotal += z.Qrun * z.Area[l]
                    z.AgQRunoff[l][i] += z.Qrun
            else:
                z.Qrun = 0

        # EROSION, SEDIMENT WASHOFF FOR RURAL AND URBAN LANDUSE
        z.RurEros = 1.32 * z.Erosiv * z.KF[l] * z.LS[l] * z.C[l] * z.P[l] * z.Area[l]

        z.Erosion[Y][i] = z.Erosion[Y][i] + z.RurEros
        z.ErosWashoff[l][i] = z.ErosWashoff[l][i] + z.RurEros
        z.DayErWashoff[l][Y][i][j] = z.RurEros

        if z.SedDelivRatio == 0:
            z.SedDelivRatio = 0.0001

{'fraction_non_alphanumeric': 0.13995878903154224, 'fraction_numerical': 0.02536059597400539, 'mean_word_length': 1.2788010111953774, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1180553', 'n_tokens_mistral': 2518, 'n_tokens_neox': 2320, 'n_words': 492}