<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def generate_seasonal_intitialization( self, qinit_file, datetime_start_initialization=datetime.datetime.utcnow() ):
 """This creates a seasonal qinit file from a RAPID qout file. This requires a simulation Qout file with a longer time period of record and to be CF compliant. It takes the average of the current date +- 3 days and goes back as far as possible. Parameters qinit_file: str Path to output qinit_file. datetime_start_initialization: :obj:`datetime.datetime`, optional Datetime object with date of simulation to go back through the years and get a running average to generate streamflow initialization. Default is utcnow. Example: .. code:: python from RAPIDpy.rapid import RAPID rapid_manager = RAPID( Qout_file='/output_mississippi-nfie/Qout_2000to2015.nc', rapid_connect_file='/input_mississippi_nfie/rapid_connect.csv' ) rapid_manager.generate_seasonal_intitialization( qinit_file='/input_mississippi_nfie/Qinit_seasonal_avg.csv' ) """

        if not self.Qout_file or not os.path.exists(self.Qout_file):
            log("Missing Qout_file. "
                "Please set before running this function ...",
                "ERROR")

        if not self.rapid_connect_file or not self.rapid_connect_file:
            log("Missing rapid_connect file. "
                "Please set before running this function ...",
                "ERROR")

        day_of_year = datetime_start_initialization.timetuple().tm_yday
        min_day = day_of_year - 3
        max_day = day_of_year + 3

        with RAPIDDataset(self.Qout_file) as qout_hist_nc:
            if not qout_hist_nc.is_time_variable_valid():
                log("File must be CF 1.6 compliant "
                    "with valid time variable ...",
                    "ERROR")

            log("Generating seasonal average qinit file from qout file ...",
                "INFO")

            log("Determining dates with streamflows of interest ...",
                "INFO")

            time_indices = []
            for idx, ttt in enumerate(qout_hist_nc.get_time_array()):
                var_time = gmtime(ttt)
                compare_yday = var_time.tm_yday
                # move day back one past because of leap year adds
                # a day after feb 29 (day 60)
                if isleap(var_time.tm_year) and compare_yday > 60:
                    compare_yday -= 1
                # check if date within range of season
                if min_day <= compare_yday < max_day:
                    time_indices.append(idx)

            if not time_indices:
                log("No time steps found within range ...",
                    "ERROR")

            log("Extracting data ...",
                "INFO")

            streamflow_array = \
                qout_hist_nc.get_qout(time_index_array=time_indices)

            log("Reordering data...",
                "INFO")
            stream_id_array = np.loadtxt(self.rapid_connect_file,
                                         ndmin=1, delimiter=",",
                                         usecols=(0,), dtype=int)
            init_flows_array = np.zeros(stream_id_array.size)
            for riv_bas_index, riv_bas_id in enumerate(
                    qout_hist_nc.get_river_id_array()):
                try:
                    data_index = np.where(stream_id_array == riv_bas_id)[0][0]
                    init_flows_array[data_index] = \
                        np.mean(streamflow_array[riv_bas_index])
                except IndexError:
                    log('riv_bas_id {0} not found in connectivity list.'
                        .format(riv_bas_id),
                        "WARNING")

            log("Writing to file ...",
                "INFO")
            with open_csv(qinit_file, 'w') as qinit_out:
                for init_flow in init_flows_array:
                    qinit_out.write('{}\n'.format(init_flow))

            log("Initialization Complete!",
                "INFO")