def plot_summary(model, to_file=False, mapbox_access_token=None): """ Plot a summary containing timeseries, installed capacities, and transmission plots. Returns a HTML string by default, returns None if ``to_file`` given (and saves the HTML string to file). Parameters ---------- to_file : str, optional Path to output file to save HTML to. mapbox_access_token : str, optional (passed to plot_transmission) If given and a valid Mapbox API key, a Mapbox map is drawn for lat-lon coordinates, else (by default), a more simple built-in map. """ subset = {'costs': ['monetary']} timeseries = _plot(*plot_timeseries(model, subset=subset), html_only=True) capacity = _plot(*plot_capacity(model, subset=subset), html_only=True) if 'loc_coordinates' in model._model_data: transmission = _plot(*plot_transmission( model, html_only=True, mapbox_access_token=mapbox_access_token ), html_only=True) else: transmission = '<br><br><p>No location coordinates defined -<br>not plotting transmission.</p>' template_path = os.path.join( os.path.dirname(__file__), '..', '..', 'config', 'plots_template.html' ) with open(template_path, 'r') as f: html_template = jinja2.Template(f.read()) if 'solution_time' in model._model_data.attrs: solution_time = model._model_data.attrs['solution_time'] / 60 time_finished = model._model_data.attrs['time_finished'] result_stats = 'taking {:.2f} minutes to solve, completed at {}'.format( solution_time, time_finished ) else: result_stats = 'inputs only' html = html_template.render( model_name=model._model_data.attrs['model.name'], calliope_version=model._model_data.attrs['calliope_version'], result_stats=result_stats, top=timeseries, bottom_left=capacity, bottom_right=transmission, ) # Strip plotly-inserted style="..." attributes html = re.sub(r'style=".+?"', '', html) if to_file: with open(to_file, 'w') as f: f.write(html) else: return html
def plot_summary(model, out_file=None, mapbox_access_token=None): """ Plot a summary containing timeseries, installed capacities, and transmission plots. Returns a HTML string if ``out_file`` not given, else None. Parameters ---------- out_file : str, optional Path to output file to save HTML to. mapbox_access_token : str, optional (passed to plot_transmission) If given and a valid Mapbox API key, a Mapbox map is drawn for lat-lon coordinates, else (by default), a more simple built-in map. """ timeseries = _plot(*plot_timeseries(model), html_only=True) capacity = _plot(*plot_capacity(model), html_only=True) transmission = _plot(*plot_transmission( model, html_only=True, mapbox_access_token=mapbox_access_token ), html_only=True) template_path = os.path.join( os.path.dirname(__file__), '..', '..', 'config', 'plots_template.html' ) with open(template_path, 'r') as f: html_template = jinja2.Template(f.read()) html = html_template.render( model_name=model._model_data.attrs['model.name'], calliope_version=model._model_data.attrs['calliope_version'], solution_time=(model._model_data.attrs['solution_time'] / 60), time_finished=model._model_data.attrs['time_finished'], top=timeseries, bottom_left=capacity, bottom_right=transmission, ) # Strip plotly-inserted style="..." attributes html = re.sub(r'style=".+?"', '', html) if out_file: with open(out_file, 'w') as f: f.write(html) else: return html
def capacity(self, **kwargs): data, layout = plot_capacity(self._model, **kwargs) return _plot(data, layout, **kwargs)
def capacity(self, **kwargs): self.check_optimality() data, layout = plot_capacity(self._model, **kwargs) return _plot(data, layout, **kwargs)
def capacity(self, **kwargs): self.check_optimality() data, layout = plot_capacity(self._model, **kwargs) return _plot(data, layout, **kwargs)