def plot_comparison(self, file=None): """ Creates a plot with a comparison of simulation results (fittest individual) vs. measured result. :param file: string, path to the file. If ``None``, file not created. :return: Axes """ simulated = self.get_sim_res() measured = self.pop.ideal.copy() return plots.plot_comparison(simulated, measured, file)
def validate(self, vp=None): """ Performs a simulation with estimated parameters for the previously selected validation period. Other period can be chosen with the `vp` argument. User chosen `vp` in this method does not override the validation period chosen during instantiation of this class. Parameters ---------- vp: tuple or None Validation period given as a tuple of start and stop time in seconds. Returns ------- dict Validation error, keys: 'tot', '<var1>', '<var2>', ... pandas.DataFrame Simulation result """ # Get estimates est = self.final est.index = [0] # Reset index (needed by model.set_param()) self.logger.info("Validation of parameters: {}".format( str(est.iloc[0].to_dict()))) # Slice data if vp is None: start, stop = self.vp[0], self.vp[1] else: start, stop = vp[0], vp[1] inp_slice = self.inp.loc[start:stop] ideal_slice = self.ideal.loc[start:stop] # Initialize IC parameters and add to known if self.ic_param: for par in self.ic_param: ic = ideal_slice[self.ic_param[par]].iloc[0] self.known[par] = ic # Initialize model model = Model(self.fmu_path) model.set_input(inp_slice) model.set_param(est) model.set_param(self.known) model.set_outputs(list(self.ideal.columns)) # Simulate and get error try: result = model.simulate() except Exception as e: msg = "Problem found inside FMU. Did you set all parameters?" self.logger.error(str(e)) self.logger.error(msg) raise e err = modestpy.estim.error.calc_err(result, ideal_slice) # Create validation plot ax = plot_comparison(result, ideal_slice, f=None) fig = figures.get_figure(ax) fig.set_size_inches(Estimation.FIG_SIZE) fig.savefig(os.path.join(self.workdir, "validation.png"), dpi=Estimation.FIG_DPI) # Remove temp dirs self._clean() # Return return err, result
def plot_comparison(self, file=None): return plots.plot_comparison(self.res, self.ideal, file)