def calc_iam(a_1, a_2, a_3, a_4, a_5, a_6, aoi, loss_method):
    """
    Calculates the incidence angle modifier depending on the loss method

    .. calc_iam_equation:

    method 'Janotte':

    :math:`\\kappa(\\varTheta) = 1 - a_1 \\cdot \\vert\\varTheta\\vert- a_2
    \\cdot \\vert\\varTheta\\vert^2`

    method 'Andasol':

    :math:`\\kappa(\\varTheta) = 1 - a_1 \\cdot \\vert\\varTheta\\vert - a_2
    \\cdot \\vert\\varTheta\\vert^2- a_3 \\cdot \\vert\\varTheta\\vert^3
    - a_4 \\cdot \\vert\\varTheta\\vert^4 - a_5 \\cdot \\vert\\varTheta\\vert^5
    - a_6 \\cdot \\vert\\varTheta\\vert^6`

    Parameters
    ----------
    a_1, a_2, a_3, a_4, a_5, a_6: numeric
        Parameters for the incident angle modifier. For loss method 'Janotte'
        a_1 and a_2 are required, for 'Andasol' a_1 to a_6 are required.

    aoi: series of numeric
        Angle of incidence.

    loss_method: string, default 'Janotte'
        Valid values are: 'Janotte' or 'Andasol'. Describes, how the thermal
        losses and the incidence angle modifier are calculated.

    Returns
    -------
    Incidence angle modifier: series of numeric

    """
    if loss_method == 'Janotte':
        iam = 1 - a_1 * abs(aoi) - a_2 * aoi ** 2
    if loss_method == 'Andasol':
        iam = (1 - a_1 * abs(aoi) - a_2 * aoi ** 2 - a_3 * aoi ** 3 - a_4 *
            aoi ** 4 - a_5 * aoi ** 5 - a_6 * aoi ** 6)
    return iam
