Visualization¶
Plotting facade, Mollier-style refrigerant diagrams (T-h, P-h, T-s) and the fixed compressor-map and calibration figures.
Plotting facade¶
Visualization and summary output functions (Facade for backward compatibility).
- tmhp.visualization.print_simulation_summary(df, simulation_time_step, dV_ou_a_design)[source]¶
Print a comprehensive summary of simulation results.
A boiler result also gets the hot-water service section (
print_dhw_service_summary()): requested, delivered and unmet heat and the number of draw steps left short. A result with afailure_reasoncolumn gets the operating-limit section (print_operating_limit_summary()): steps on which the compressor was called but did not run, or ran below the request.- Parameters:
df (
DataFrame) – Simulation result DataFrame.simulation_time_step (
int) – Time step [s].dV_ou_a_design (
float) – Design airflow rate of outdoor unit [m3/s].
- Return type:
None
- tmhp.visualization.plot_ph_diagram(ax, result, refrigerant, fontsize=None, tick_pad=None, sat_liquid_label='Sat. liquid', sat_vapor_label='Sat. vapor', ref_cycle_label='Ref. cycle', point_labels=None)[source]¶
Plot P-h diagram on given axis.
- Parameters:
ax (
Axes)result (
dict[str,float])refrigerant (
str)fontsize (
float|None)tick_pad (
float|None)sat_liquid_label (
str)sat_vapor_label (
str)ref_cycle_label (
str)point_labels (
dict[str,str] |None)
- Return type:
None
- tmhp.visualization.plot_th_diagram(ax, result, refrigerant, T_cond_bound=None, T_evap_bound=None, fontsize=None, tick_pad=None, sat_liquid_label='Sat. liquid', sat_vapor_label='Sat. vapor', ref_cycle_label='Ref. cycle', point_labels=None)[source]¶
Plot T-h diagram on given axis.
- Parameters:
ax (
Axes)result (
dict[str,float])refrigerant (
str)T_cond_bound (
dict[str,float|str] |None)T_evap_bound (
dict[str,float|str] |None)fontsize (
float|None)tick_pad (
float|None)sat_liquid_label (
str)sat_vapor_label (
str)ref_cycle_label (
str)point_labels (
dict[str,str] |None)
- Return type:
None
- tmhp.visualization.plot_ts_diagram(ax, result, refrigerant, T_cond_bound=None, T_evap_bound=None, sat_liquid_label='Sat. liquid', sat_vapor_label='Sat. vapor', ref_cycle_label='Ref. cycle', point_labels=None)[source]¶
Plot T-s diagram on given axis with super heating/cooling considered.
- Parameters:
ax (
Axes)result (
dict[str,float])refrigerant (
str)T_cond_bound (
dict[str,float|str] |None)T_evap_bound (
dict[str,float|str] |None)sat_liquid_label (
str)sat_vapor_label (
str)ref_cycle_label (
str)point_labels (
dict[str,str] |None)
- Return type:
None
Mollier diagrams¶
Mollier diagram visualization functions.
- tmhp.mollier_diagram.plot_th_diagram(ax, result, refrigerant, T_cond_bound=None, T_evap_bound=None, fontsize=None, tick_pad=None, sat_liquid_label='Sat. liquid', sat_vapor_label='Sat. vapor', ref_cycle_label='Ref. cycle', point_labels=None)[source]¶
Plot T-h diagram on given axis.
- Parameters:
ax (
Axes)result (
dict[str,float])refrigerant (
str)T_cond_bound (
dict[str,float|str] |None)T_evap_bound (
dict[str,float|str] |None)fontsize (
float|None)tick_pad (
float|None)sat_liquid_label (
str)sat_vapor_label (
str)ref_cycle_label (
str)point_labels (
dict[str,str] |None)
- Return type:
None
- tmhp.mollier_diagram.plot_ph_diagram(ax, result, refrigerant, fontsize=None, tick_pad=None, sat_liquid_label='Sat. liquid', sat_vapor_label='Sat. vapor', ref_cycle_label='Ref. cycle', point_labels=None)[source]¶
Plot P-h diagram on given axis.
- Parameters:
ax (
Axes)result (
dict[str,float])refrigerant (
str)fontsize (
float|None)tick_pad (
float|None)sat_liquid_label (
str)sat_vapor_label (
str)ref_cycle_label (
str)point_labels (
dict[str,str] |None)
- Return type:
None
- tmhp.mollier_diagram.plot_ts_diagram(ax, result, refrigerant, T_cond_bound=None, T_evap_bound=None, sat_liquid_label='Sat. liquid', sat_vapor_label='Sat. vapor', ref_cycle_label='Ref. cycle', point_labels=None)[source]¶
Plot T-s diagram on given axis with super heating/cooling considered.
- Parameters:
ax (
Axes)result (
dict[str,float])refrigerant (
str)T_cond_bound (
dict[str,float|str] |None)T_evap_bound (
dict[str,float|str] |None)sat_liquid_label (
str)sat_vapor_label (
str)ref_cycle_label (
str)point_labels (
dict[str,str] |None)
- Return type:
None
Compressor maps and calibration figures¶
Three figures, always drawn the same way, for recording a compressor map
change or a catalogue calibration (#256). Each is drawn in the dartwork-mpl
scientific preset at the width of two journal columns (17 cm), whatever
style the caller has set, and leaves the caller’s rcParams as they were;
every panel has its own tick labels (#258). They also follow the
style-independent figure rules of the figma-plot skill: every linear axis
has an explicit (min, max, interval) with ticks at both ends (the log
pressure-ratio axis is exempt), tick labels carry only the decimals the
interval needs, percent is written (%) and units [unit], panel titles
name quantities in words, and each map row has its own upright colour bar
right of its last panel that shows its two end values, with no triangular
ends (values beyond the fixed levels take the end colours).
plot_compressor_map()– one compressor quantity (eta_ov,eta_vorf_loss) over pressure ratio and speed at fixed evaporating temperatures (−15, 0 and 10 °C by default); row 1 before, row 2 after. Every heat-pump model has it as a method,model.plot_compressor_map(), with the model’s scaled maps as after and the default maps as before.plot_calibration_stages()– COP RMSE and MAPE after each calibration stage, fitted and cross-validated.plot_cop_parity()– model against catalogue COP, before and after, with the error scores.
from tmhp import AirSourceHeatPumpBoiler
from tmhp.compressor_efficiency import CompressorMapScale
scale = CompressorMapScale(k_ov=1.2, delta_N=10.0)
model = AirSourceHeatPumpBoiler(hp_capacity=9000.0, ref="R290", compressor_scale=scale)
fig = model.plot_compressor_map() # default maps (top) vs this model's scaled maps (bottom)
Fixed-form figures of the compressor efficiency maps and of a calibration’s performance (#256).
Three figures, always drawn the same way so that results recorded in different issues can be compared at a glance:
plot_compressor_map()One compressor quantity (
eta_ov,eta_vorf_loss) over (pressure ratio, speed) at a few fixed evaporating temperatures: row 1 before, row 2 after, one column perT_evap, each row the default maps under aCompressorMapScale. Axis ranges and colour levels are fixed per quantity. Every heat-pump model also has it as a method (CompressorMapPlotMixin), with its own scaled maps as after and the default maps as before.plot_calibration_stages()COP error after each calibration stage: RMSE of
ln(COP_model / COP_catalogue)on the left, MAPE on the right; a line for the fit to all points and markers for the cross-validated value (filled = adopted).plot_cop_parity()Model against catalogue COP, before on the left and after on the right, on the same axes, with the error scores in the panel titles.
Each function returns a matplotlib.figure.Figure drawn in the
dartwork-mpl scientific preset (FIGURE_STYLE) at the width of two
journal columns (17 cm), whatever style the caller has set; the caller’s
global rcParams are left as they were (#258). Every panel carries its own
tick labels. Colours: grey = before (default maps), violet = after
(calibrated), orange = the data range of the default maps, blue = efficiency
magnitude.
Axes follow the figure drawing rules of the figma-plot skill that do not
depend on the style (#258): every linear axis, the colour bars included, has
an explicit (min, max, interval) with ticks at both ends; tick labels carry only the decimals the
interval needs; percent is written (%) and physical units [unit];
titles name quantities in words; a colour bar stands upright to the right of
its panel, placed from the panel’s final position, and shows its two end
values only, with no triangular ends.
- tmhp.compressor_plots.DEFAULT_T_EVAP_C: tuple[float, ...] = (-15.0, 0.0, 10.0)¶
cold heating, mild heating, cooling.
- Type:
Evaporating temperatures [°C] of the map columns
- tmhp.compressor_plots.FIGURE_STYLE = 'scientific'¶
The dartwork-mpl preset every figure of this module is drawn in.
- tmhp.compressor_plots.MAP_QUANTITIES: dict[str, _MapQuantity] = {'eta_ov': _MapQuantity(label='Overall efficiency', symbol='η_ov', levels=(0.3, 0.325, 0.35, 0.375, 0.4, 0.425, 0.45, 0.475, 0.5, 0.525, 0.55, 0.575, 0.6, 0.625, 0.65, 0.675, 0.7, 0.725, 0.75, 0.775, 0.8, 0.825, 0.85), bar_label='Overall efficiency (%)'), 'eta_v': _MapQuantity(label='Volumetric efficiency', symbol='η_v', levels=(0.7, 0.72, 0.74, 0.76, 0.78, 0.8, 0.82, 0.84, 0.86, 0.88, 0.9, 0.92, 0.94, 0.96, 0.98, 1.0, 1.02, 1.04), bar_label='Volumetric efficiency (%)'), 'f_loss': _MapQuantity(label='Heat-loss share', symbol='f_loss', levels=(0.0, 0.02, 0.04, 0.06, 0.08, 0.1, 0.12, 0.14, 0.16, 0.18, 0.2, 0.22, 0.24, 0.26, 0.28, 0.3, 0.32, 0.34, 0.36, 0.38, 0.4), bar_label='Heat-loss share (%)')}¶
the three quantities of
tmhp.compressor_efficiencyas the cycle evaluates them.- Type:
Quantities
plot_compressor_map()can draw
- class tmhp.compressor_plots.CompressorMapPlotMixin[source]¶
Bases:
objectGives a heat-pump model
plot_compressor_map()over its own (scaled) compressor maps.- compressor_scale: CompressorMapScale¶
- plot_compressor_map(before=None, *, labels=('Default maps', 'This model'), **kwargs)[source]¶
This model’s compressor map (row 2) against
before(row 1; default maps when None).beforeis aCompressorMapScaleor another model. Other keywords go toplot_compressor_map()(T_evap_C,quantity,points,pr_range,rps_range,title,resolution). Returns the figure.- Parameters:
before (
CompressorMapScale|_HasCompressorScale|None)labels (
tuple[str,str])kwargs (
Any)
- Return type:
Figure
- class tmhp.compressor_plots.CopErrors(n, n_failed, rmse, mape, bias)[source]¶
Bases:
objectCOP error scores of a model against reference (catalogue) values, as fractions.
rmse: root mean square ofln(COP_model / COP_ref);mape: mean of|COP_model / COP_ref - 1|;bias: mean ofCOP_model / COP_ref - 1. All over thenpoints with a finite, positive model value;n_failedpoints had none (the model did not solve them). NaN scores whennis 0.- Parameters:
n (
int)n_failed (
int)rmse (
float)mape (
float)bias (
float)
- n: int¶
- n_failed: int¶
- rmse: float¶
- mape: float¶
- bias: float¶
- __init__(n, n_failed, rmse, mape, bias)¶
- Parameters:
n (
int)n_failed (
int)rmse (
float)mape (
float)bias (
float)
- class tmhp.compressor_plots.OperatingPoints(pressure_ratio, rps, T_evap_C)[source]¶
Bases:
objectCompressor operating points to overlay on the map: pressure ratio, speed [rev/s], T_evap [°C].
Equal-length 1-D arrays; points with a non-finite value are dropped. Build one from model results with
from_results().- Parameters:
pressure_ratio (
ndarray)rps (
ndarray)T_evap_C (
ndarray)
- pressure_ratio: ndarray¶
- rps: ndarray¶
- T_evap_C: ndarray¶
- classmethod from_results(results)[source]¶
Points from model result rows (a DataFrame or a mapping of columns).
Uses
pr_cmp [-]when present, elseP_ref_cmp_out [Pa] / P_ref_cmp_in [Pa];cmp_rpm [rpm]/ 60;T_ref_evap_sat [°C]. RaisesKeyErrornaming a missing column.- Parameters:
results (
DataFrame|Mapping[str,Any])- Return type:
- __init__(pressure_ratio, rps, T_evap_C)¶
- Parameters:
pressure_ratio (
ndarray)rps (
ndarray)T_evap_C (
ndarray)
- class tmhp.compressor_plots.StageScore(label, rmse_fit, mape_fit, rmse_cv=None, mape_cv=None, adopted=False)[source]¶
Bases:
objectCOP errors after one calibration stage, as fractions (0.05 = 5 %).
rmse_fit/mape_fit: with the parameters fitted to all points.rmse_cv/mape_cv: from the held-out predictions of a k-fold cross validation, or None when the stage was not cross-validated.adopted: whether the stage was kept. The first stage is normally the uncalibrated model (“Default”).- Parameters:
label (
str)rmse_fit (
float)mape_fit (
float)rmse_cv (
float|None)mape_cv (
float|None)adopted (
bool)
- label: str¶
- rmse_fit: float¶
- mape_fit: float¶
- rmse_cv: float | None = None¶
- mape_cv: float | None = None¶
- adopted: bool = False¶
- __init__(label, rmse_fit, mape_fit, rmse_cv=None, mape_cv=None, adopted=False)¶
- Parameters:
label (
str)rmse_fit (
float)mape_fit (
float)rmse_cv (
float|None)mape_cv (
float|None)adopted (
bool)
- tmhp.compressor_plots.cop_errors(cop_reference, cop_model)[source]¶
Score
cop_modelagainstcop_reference(equal-length arrays; seeCopErrors).Raises
ValueErrorfor unequal lengths or a non-positive or non-finite reference value.- Parameters:
cop_reference (
Sequence[float] |ndarray)cop_model (
Sequence[float] |ndarray)
- Return type:
- tmhp.compressor_plots.efficiency_grid(source, quantity, pressure_ratio, rps, T_evap_C)[source]¶
quantityon the gridrpsxpressure_ratioat one evaporating temperature.Returns an array of shape
(len(rps), len(pressure_ratio)). Each value is what the cycle would use; a point where the quantity is outside its range (an infeasible point) is NaN.sourceis as forplot_compressor_map(). RaisesValueErrorfor an unknown quantity.- Parameters:
source (
CompressorMapScale|_HasCompressorScale|None)quantity (
str)pressure_ratio (
Sequence[float] |ndarray)rps (
Sequence[float] |ndarray)T_evap_C (
float)
- Return type:
ndarray
- tmhp.compressor_plots.plot_calibration_stages(stages, *, title=None)[source]¶
COP RMSE (left) and MAPE (right) (%) after each calibration stage, in the given order.
Line: the fit to all points. Markers: the cross-validated value, filled for an adopted stage and open for a rejected one (none where the stage was not cross-validated). The first stage’s markers are grey (the uncalibrated model), the rest violet. Each error axis runs from 0 to a round value just above the largest error, with ticks at a round interval. Raises
ValueErrorfor no stages.- Parameters:
stages (
Sequence[StageScore])title (
str|None)
- Return type:
Figure
- tmhp.compressor_plots.plot_compressor_map(before, after, *, T_evap_C=(-15.0, 0.0, 10.0), quantity='eta_ov', points=None, labels=('Default maps', 'Calibrated'), pr_range=(1.0, 12.0), rps_range=(15.0, 120.0), title=None, resolution=(140, 120))[source]¶
Efficiency map before (row 1) and after (row 2), one column per evaporating temperature.
beforeandafterare each aCompressorMapScale, a heat-pump model (itscompressor_scale), orNonefor the default maps as they are.quantityis a key ofMAP_QUANTITIES; its colour levels are fixed, values beyond them take the end colours. Axes: pressure ratior_p(linear,pr_rangerounded out to whole numbers, a tick at each) and speedN[rev/s] (rps_range, with ticks at a round interval; a range that no such interval divides is widened to one, the default 15 to 120 has ticks every 15), the same on every panel.Each row is a block of its own, headed by its label (
labels) and set apart from the other row; no axis is shared, so every panel has its own tick labels. Drawn on every panel: the efficiency (filled contours, labelled lines), the data range of the default maps at thatT_evap(orange; foreta_ovwhere the scaled coordinates read the map inside its data), the grid peak (diamond, in the row’s colour), andpointsas small black dots with a thin white rim. The panel’s left title is its evaporating temperature, the right title the peak value and place. One legend under the figure names the outline, the peak and the points at their drawn sizes; the figure has no title unlesstitleis given. Each row has its own colour bar right of its last panel, the same levels in both rows, showing the two end values.points(anOperatingPointsor model result rows) are drawn on the column whoseT_evapis nearest to each point’s.resolutionis the grid size (pressure ratio, speed).Returns the figure: 2 x
len(T_evap_C)map axes and a colour bar for each row. RaisesValueErrorfor an unknown quantity or no temperatures, andTypeErrorfor a source that is neither a scale nor a model with one.- Parameters:
before (
CompressorMapScale|_HasCompressorScale|None)after (
CompressorMapScale|_HasCompressorScale|None)T_evap_C (
Sequence[float])quantity (
str)points (
OperatingPoints|DataFrame|None)labels (
tuple[str,str])pr_range (
tuple[float,float])rps_range (
tuple[float,float])title (
str|None)resolution (
tuple[int,int])
- Return type:
Figure
- tmhp.compressor_plots.plot_cop_parity(cop_catalogue, cop_before, cop_after, *, mode=None, labels=('Default maps', 'Calibrated'), band=0.1, title=None)[source]¶
Model against catalogue COP: before (left) and after (right) on square axes of the same range.
Equal-length arrays; a non-finite or non-positive model value is a point the model did not solve, left out of the plot, the axis range and the scores alike and counted in the title. Each panel’s left title is its label, the right title its MAPE, bias and RMSE (
cop_errors()). The panels share no axis: each has its own tick labels. Both axes of both panels run over the drawn values rounded outward to a round interval (the same(min, max, interval)everywhere). Lines: y = x and±band(dashed). Every point is an opaque circle with a hairline white rim, so overlapping points stay apart;modeper point sets its colour:"heating"red,"cooling"blue, anything else grey. RaisesValueErrorascop_errors()or whenmodehas another length.- Parameters:
cop_catalogue (
Sequence[float] |ndarray)cop_before (
Sequence[float] |ndarray)cop_after (
Sequence[float] |ndarray)mode (
Sequence[str] |ndarray|None)labels (
tuple[str,str])band (
float)title (
str|None)
- Return type:
Figure