oemof / tespy

Thermal Engineering Systems in Python (TESPy). This package provides a powerful simulation toolkit for thermal engineering plants such as power plants, district heating systems or heat pumps.
https://tespy.readthedocs.io
MIT License
272 stars 85 forks source link

latex report errors #281

Closed NicholasFry closed 3 years ago

NicholasFry commented 3 years ago

This is a note. The latex report is missing a begin{document} and end{document} segment that will not allow for direct use in a compiler, that I know of. Perhaps that is an easy fix for the latex output, though that is far from my document style preference.

fwitte commented 3 years ago

Hi, thank you for reporting! I'll check the examples in this repository. In one of the more recent versions of TESPy I added some formatters to the report, maybe I forgot to update here or the defaults are chosen poorly. Did you specify 'latex_body': True in the formatting dictionary? The default value is False, which generates a report without the LaTeX body to include within a different file (which to be hones is not too convenient... At first I was thinking about using the report feature to generate tables etc. to include somewhere different, now I only use the report to quickly have a look at the inputs/results, thus 'latex_body': True should be the default!). Your formatting dictionary could look like this (see https://tespy.readthedocs.io/en/main/tespy_modules.html#automatic-model-documentation):

fmt = {
    'latex_body': True,  # adds LaTeX body to compile report out of the box
    'include_results': True,  # include parameter specification and results
    'HeatExchanger': {  # for components of class HeatExchanger
        'params': ['Q', 'ttd_l', 'ttd_u', 'pr1', 'pr2']},  # change columns displayed
    'Condenser': {  # for components of class HeatExchanger
        'params': ['Q', 'ttd_l', 'ttd_u', 'pr1', 'pr2']
        'float_fmt': '{:,.2f}'},  # change float format of data
    'Connection': {  # for Connection instances
        'p': {'float_fmt': '{:,.4f}'},  # change float format of pressure
        's': {'float_fmt': '{:,.4f}'},
        'h': {'float_fmt': '{:,.2f}'},
        'params': ['m', 'p', 'h', 's']  # list results of mass flow, ...
        'fluid': {'include_results': False}  # exclude results of fluid composition
    },
    'include_results': True,  # include results
    'draft': False  # disable draft mode
}
document_model(mynetwork, fmt=fmt)

I will change the default value and will move this issue into the TESPy repo.

Btw: All the results and specifications are available as dictionary containing pandas DataFrames after a simulation. The dictionary's keys are the class name of the respective instance, e.g. 'HeatExchanger' or 'Connection':

mynetwork.results['HeatExchanger']
mynetwork.results['Connection']
mynetwork.specifications['Connection']
NicholasFry commented 3 years ago

Thanks for this @fwitte I will take another look at the documentation. I would not normally use the latex, but I am hoping to make a web application for a heat pump configuration in TESPy. Ideally, it should output the report and some matplotlib or seaborn plots to the user. If I get it deployed, I will be sure to cite your work.

fwitte commented 3 years ago

That sounds interesting, let me know if you need any assistance. I would be glad to help you. We could also link that as an example/tutorial in the documentation of the software. My initial idea of the report feature was to enable easy and transparent communication of model specifications and results for publications in scientific journals. However, in many cases e.g. markdown would be useful, too, I think. Or maybe some dash/plotly integration, which has very nice features especially for web applications (https://dash-gallery.plotly.host/Portal/). Running tespy from a dash web application should actually be quite easy, I think.

In any case, if you create something similar to the LaTeX report, maybe some parts or features of that might be interesting for other users as well and we can integrate the code into the software.

Best regards, have a nice day

NicholasFry commented 3 years ago

@fwitte I did get some better outputs by following your instruction. I do not currently know of a compiler to run on the backend before delivering simulation results to a user. This should be ok, however. I have a minimum viable product working for a single stage heat pump. It is not deployed yet as I do intend to add some of the plotly features, etc. This is what I came up with over the last few days: https://github.com/NicholasFry/Heat-pump-DH-web-application

Thanks again!