def tmy_noontime_from_ghi(ghi_list):
    """
    calculate the weighed time for ghi maximum on a day
    

    from the TMY ghi parameter calculate the weighed time for the ghi
    maximum on each day. Return a list with the calculated noon time
    for each day of the year [0..364].
    
    From a plot of the estimated noon time over the year can be
    recognized the constant shift that depends on timezone and longitude
    as well as the variable deviation of the equation of time.

    input data:
    - list with 8760 ghi values from a TMY dataset, integer/float
    
    output: tuple with
    - list with 365 values for noon time in decimal format or 'None'
    when the value could not be calculated
    - average of the valid values in the list = estimated noon time
    expressed as local time

    NOTE: in the "previous" TMY format the hour is indexed [0..23]. For
    cumulative data, such as GHI, DNI, DHI, it refers to the following
    one-hour period, i.e., '0' is the pointer to the full hour starting
    at 0 and ending at 1, '1' points to the hour between 1 and 2, etc.

    In the newer EPW and updated TMY datasets hours are in range [1..24]
    and refer to the hour period terminating at the timestamp.

    This function operates on the TMY "previous" format. The hour
    timestamp for the weighed average are therefore corrected with
    a factor = +0.5 to refer to the time midpoint of accumulated values.
    
    """
    noon_year_avg = 0
    noon_count = 0
    noon_average = []
    for d in range(0, 365):
        d_idx = d * 24
        ghi_day = 0
        noon_weighed = 0
        for h in range(0, 12):
            h_idx = d_idx + h
            ghi_hour = ghi_list[h_idx]
            ghi_day = ghi_day + ghi_hour
            noon_weighed = noon_weighed + ghi_hour * (h + 0.5)
        ghi_noon = ghi_day
        for h in range(12, 24):
            h_idx = d_idx + h
            ghi_hour = ghi_list[h_idx]
            ghi_day = ghi_day + ghi_hour
            noon_weighed = noon_weighed + ghi_hour * (h + 0.5)
        if ghi_day > 0:
            ghi_dev = ghi_noon / ghi_day
        if ghi_day == 0 or ghi_dev < 0.3 or ghi_dev > 0.7:
            noon_average.append(None)
        else:
            noon_calc = round(noon_weighed / ghi_day, 2)
            noon_average.append(noon_calc)
            noon_year_avg = noon_year_avg + noon_calc
            noon_count = noon_count + 1
    return noon_average, round(noon_year_avg / noon_count, 2)
