**Count lightning strikes detected within a defined time_step**

    Generate time intervals according to the time_step defined and count
    lightning strikes in these intervals. Statistics are also calculated for
    lightning detection errors and the number of stations and added to an
    output dataframe. Time stamps in output dataframe correspond to center of
    time periods in which lightning are counted.

    :paramter datain: dataframe (lightning data)
    :parameter time_step: integer (time step in minutes)

    :Example:

     >>> count_lightning(LN_data, time_step)

def count_lightning(datain, time_step):
    """**Count lightning strikes detected within a defined time_step**

    Generate time intervals according to the time_step defined and count
    lightning strikes in these intervals. Statistics are also calculated for
    lightning detection errors and the number of stations and added to an
    output dataframe. Time stamps in output dataframe correspond to center of
    time periods in which lightning are counted.

    :paramter datain: dataframe (lightning data)
    :parameter time_step: integer (time step in minutes)

    :Example:

     >>> count_lightning(LN_data, time_step)
     """
    if(1440 % time_step == 0):  # check if time_step is multiple of 1 day
        i = 0
        # run for loop for all time steps in one day
        for time_interval in gen_time_intervals(extract_date(datain['datetime'].iloc[0]),
                                                (extract_date(datain['datetime'].iloc[0])+timedelta(days=1)),
                                                timedelta(minutes=time_step)):
            # select data in given time_interval
            tmp_LN_data = datain.loc[(datain['datetime'] >= time_interval) &
                                     (datain['datetime'] < time_interval +
                                      timedelta(minutes=time_step))]
            # calculate stats
            stats_err = gen_stats(tmp_LN_data['err'])
            stats_sta = gen_stats(tmp_LN_data['#sta'])
            d = {'count': stats_err['count'],
                 'err_mean': stats_err['mean'],
                 'err_std': stats_err['std'],
                 'err_min': stats_err['min'],
                 'err_max': stats_err['max'],
                 '#sta_mean': stats_sta['mean'],
                 '#sta_std': stats_sta['std'],
                 '#sta_min': stats_sta['min'],
                 '#sta_max': stats_sta['max']}
            col_names = [k for k in d.keys()]
            df_index = time_interval+timedelta(minutes=(time_step/2))
            temp_LN_count = pd.DataFrame(d, index=[df_index],
                                         columns=col_names)
            # add data to existing df
            if(i >= 1):
                LN_count = LN_count.append(temp_LN_count)
            else:
                LN_count = temp_LN_count
            i = i + 1
        return LN_count
    else:
        print("time_step {0} multiple of 1 day (1400 min)".format(time_step))