import copy


def calc_aet(PET, AWHC, W, p=1, a=0.0073):
    """
    calculate AET for new zealand pasture from
    # from woodward 2010, https://www.tandfonline.com/doi/pdf/10.1080/00288233.2001.9513464
    :param PET: potential evapotranspriation (mm/day)
    :param p: proportion of readilay avalible water (RAW) abe to be extracted in one day (d-1)
              default value from woodward 2010
    :param a: "readily available" water coefficient (d mm-1)
              default value from woodward 2010
    :param AWHC: available water holding capacity of soil to rooting depth (mm)
    :param W: soil water deficit (usually negative) (mm)
    :return:
    """

    RAW = a * PET * (AWHC + W) * p

    AET = copy.deepcopy(PET)
    AET[AET > RAW] = RAW[AET > RAW]

    return AET