Prepares RAPID streamflow for GSSHA simulation

def prepare_rapid_streamflow(self, path_to_rapid_qout, connection_list_file):
        """
        Prepares RAPID streamflow for GSSHA simulation
        """
        ihg_filename = '{0}.ihg'.format(self.project_manager.name)
        with tmp_chdir(self.project_manager.project_directory):
            # write out IHG file
            time_index_range = []
            with RAPIDDataset(path_to_rapid_qout, out_tzinfo=self.tz) as qout_nc:

                time_index_range = qout_nc.get_time_index_range(date_search_start=self.simulation_start,
                                                                date_search_end=self.simulation_end)

                if len(time_index_range) > 0:
                    time_array = qout_nc.get_time_array(return_datetime=True,
                                                        time_index_array=time_index_range)

                    # GSSHA STARTS INGESTING STREAMFLOW AT SECOND TIME STEP
                    if self.simulation_start is not None:
                        if self.simulation_start == time_array[0]:
                            log.warning("First timestep of streamflow skipped "
                                     "in order for GSSHA to capture the streamflow.")
                            time_index_range = time_index_range[1:]
                            time_array = time_array[1:]

                if len(time_index_range) > 0:
                    start_datetime = time_array[0]

                    if self.simulation_start is None:
                       self._update_simulation_start(start_datetime)

                    if self.simulation_end is None:
                        self.simulation_end = time_array[-1]

                    qout_nc.write_flows_to_gssha_time_series_ihg(ihg_filename,
                                                                 connection_list_file,
                                                                 date_search_start=start_datetime,
                                                                 date_search_end=self.simulation_end,
                                                                 )
                else:
                    log.warning("No streamflow values found in time range ...")

            if len(time_index_range) > 0:
                # update cards
                self._update_simulation_start_cards()

                self._update_card("END_TIME", self.simulation_end.strftime("%Y %m %d %H %M"))
                self._update_card("CHAN_POINT_INPUT", ihg_filename, True)

                # update duration
                self.set_simulation_duration(self.simulation_end-self.simulation_start)

                # UPDATE GMT CARD
                self._update_gmt()
            else:
                # cleanup
                os.remove(ihg_filename)
                self.project_manager.deleteCard('CHAN_POINT_INPUT', self.db_session)