Ejemplo n.º 1
0
    def get_results(self, n_iter, rmse):

        print('v{}'.format(self.ver))

        # randomize functions are out of this class, they are just recalled in CreateOZN.fire()

        self.rs.open_ozone()

        # this is main loop for stochastic analyses
        # n_iter is maximum number of iterations
        for sim in range(int(n_iter)):
            sim_no = sim + self.sim_time  # unique simulation ID based on time mask

            print('\n\nSimulation #{} -- {}/{}'.format(sim_no, sim + 1,
                                                       n_iter))

            # creating OZN file and writing essentials to the list
            self.to_write.clear()

            # redirect data to CSV and create OZN file for beam
            self.to_write, no_beam = CreateOZN(*self.paths,
                                               self.f_type).write_ozn()

            # beam simulation
            if not no_beam:
                if not self.single_sim(self.to_write, sim_no):
                    self.falses += 1
            self.details(sim_no)  # moving Ozone files named by simulation ID

            # column simulation
            sim_no = '{}col'.format(sim_no)
            print('\nSimulation #{} -- {}/{}'.format(sim_no, sim + 1, n_iter))
            if self.b2c(sim_no[:10]):  # change coordinates to column
                print('There is no column available')
                no_beam = True
            if not self.single_sim(self.to_write, sim_no.split('a')[0]):
                self.falses += 1
            self.details(sim_no)  # saving column simulation details

            # choosing worse scenario as single iteration output and checking its correctness
            if not no_beam:
                print('beam: {}, col: {}'.format(self.results[-2][1],
                                                 self.results[-1][1]))
                self.worse()

            print("Step finished OK")

            # exporting results every (self.save_samp) repetitions
            if (sim + 1) % self.save_samp == 0:
                e = Export(self.results, self.paths[1], self.ver)
                e.csv_write('stoch_rest')
                # check if RMSE is low enough to stop simulation
                if e.save(self.rset, self.t_crit,
                          self.falses) and rmse == "rmse":
                    print('Multisimulation finished due to RMSE condition')
                    break
                self.results.clear()

        # safe closing code:
        self.rs.close_ozn()

        print("Multisimulation finished OK, well done engineer!")