CoolPlot 1.3.0__tar.gz → 1.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {coolplot-1.3.0/src/CoolPlot.egg-info → coolplot-1.4.0}/PKG-INFO +2 -2
- {coolplot-1.3.0 → coolplot-1.4.0}/README.md +1 -1
- {coolplot-1.3.0 → coolplot-1.4.0/src/CoolPlot.egg-info}/PKG-INFO +2 -2
- {coolplot-1.3.0 → coolplot-1.4.0}/src/CoolPlot.egg-info/SOURCES.txt +1 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/__version__.py +1 -1
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/chart.py +51 -9
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/compose/builder.py +17 -6
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/core/cycle.py +19 -1
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/core/quantities.py +3 -1
- coolplot-1.4.0/src/coolplot/core/symbols.py +63 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/corelib.py +2 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/spec/diagram.py +1 -1
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/spec/settings.py +15 -1
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/thermo/cycles/models.py +3 -3
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/thermo/fluid.py +49 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/thermo/references.py +116 -11
- {coolplot-1.3.0 → coolplot-1.4.0}/tests/test_architecture.py +19 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/tests/test_branding.py +25 -1
- {coolplot-1.3.0 → coolplot-1.4.0}/tests/test_cycles.py +132 -1
- {coolplot-1.3.0 → coolplot-1.4.0}/tests/test_diagram.py +17 -1
- {coolplot-1.3.0 → coolplot-1.4.0}/tests/test_engine.py +1 -1
- {coolplot-1.3.0 → coolplot-1.4.0}/tests/test_examples.py +15 -5
- {coolplot-1.3.0 → coolplot-1.4.0}/tests/test_layout.py +1 -1
- {coolplot-1.3.0 → coolplot-1.4.0}/tests/test_native_core.py +42 -5
- {coolplot-1.3.0 → coolplot-1.4.0}/tests/test_pdf.py +1 -1
- {coolplot-1.3.0 → coolplot-1.4.0}/tests/test_psychro.py +7 -7
- {coolplot-1.3.0 → coolplot-1.4.0}/tests/test_rails.py +2 -2
- {coolplot-1.3.0 → coolplot-1.4.0}/tests/test_saturation_anchors.py +5 -5
- {coolplot-1.3.0 → coolplot-1.4.0}/tests/test_spec.py +15 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/tests/test_style.py +1 -1
- {coolplot-1.3.0 → coolplot-1.4.0}/LICENSE +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/pyproject.toml +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/setup.cfg +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/CoolPlot.egg-info/dependency_links.txt +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/CoolPlot.egg-info/requires.txt +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/CoolPlot.egg-info/top_level.txt +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/__init__.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/compose/__init__.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/compose/branding.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/compose/corners.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/compose/layout.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/compose/rails.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/core/__init__.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/core/diagram_type.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/core/errors.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/core/events.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/core/floats.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/core/images.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/core/implementation.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/core/limits.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/core/numbers.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/core/state.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/core/textwidth.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/core/units.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/diagram.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/engine/__init__.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/engine/background.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/engine/cache.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/engine/engine.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/engine/planning.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/engine/store.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/export.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/interaction.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/psychrometric.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/py.typed +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/render/__init__.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/render/base.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/render/mpl.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/render/pdf.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/render/plotly.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/render/static/scene_svg.js +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/render/svg.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/render/ticks.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/render/web.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/scene.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/spec/__init__.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/spec/fluid.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/style/__init__.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/style/theme.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/style/values.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/testing/__init__.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/testing/kit.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/testing/pdf_reader.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/thermo/__init__.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/thermo/cycles/__init__.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/thermo/cycles/paths.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/thermo/humid_air.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/thermo/isolines.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/thermo/limits.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/thermo/native.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/thermo/process.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/thermo/provider.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/thermo/stepping.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/src/coolplot/thermo/tracer.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/tests/test_api_vocabulary.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/tests/test_backend_conformance.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/tests/test_background.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/tests/test_contracts.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/tests/test_curve_store.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/tests/test_events.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/tests/test_native.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/tests/test_numerics.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/tests/test_plotly.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/tests/test_scene_js.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/tests/test_scene_render.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/tests/test_thermo.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/tests/test_typing.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/tests/test_web.py +0 -0
- {coolplot-1.3.0 → coolplot-1.4.0}/tests/test_web_server.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: CoolPlot
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.4.0
|
|
4
4
|
Summary: Thermodynamic property diagrams with CoolProp as data source.
|
|
5
5
|
Author-email: Jorrit Wronski <coolplot@jorrit.org>
|
|
6
6
|
License: MIT License
|
|
@@ -71,7 +71,7 @@ from coolplot import PropertyDiagram
|
|
|
71
71
|
from coolplot.thermo.cycles import simple_compression
|
|
72
72
|
|
|
73
73
|
diagram = PropertyDiagram("R290", "ph", units="engineering", tp_limits="ACHP")
|
|
74
|
-
diagram.set_default_lines(labels=True)
|
|
74
|
+
diagram.set_default_lines(labels=True, rounding=True)
|
|
75
75
|
diagram.add_cycle(simple_compression("R290", T_evap_C=-5, T_cond_C=45, dT_sh_K=5))
|
|
76
76
|
diagram.save("R290_ph.png") # or .pdf, .svg; show() opens a window
|
|
77
77
|
```
|
|
@@ -22,7 +22,7 @@ from coolplot import PropertyDiagram
|
|
|
22
22
|
from coolplot.thermo.cycles import simple_compression
|
|
23
23
|
|
|
24
24
|
diagram = PropertyDiagram("R290", "ph", units="engineering", tp_limits="ACHP")
|
|
25
|
-
diagram.set_default_lines(labels=True)
|
|
25
|
+
diagram.set_default_lines(labels=True, rounding=True)
|
|
26
26
|
diagram.add_cycle(simple_compression("R290", T_evap_C=-5, T_cond_C=45, dT_sh_K=5))
|
|
27
27
|
diagram.save("R290_ph.png") # or .pdf, .svg; show() opens a window
|
|
28
28
|
```
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: CoolPlot
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.4.0
|
|
4
4
|
Summary: Thermodynamic property diagrams with CoolProp as data source.
|
|
5
5
|
Author-email: Jorrit Wronski <coolplot@jorrit.org>
|
|
6
6
|
License: MIT License
|
|
@@ -71,7 +71,7 @@ from coolplot import PropertyDiagram
|
|
|
71
71
|
from coolplot.thermo.cycles import simple_compression
|
|
72
72
|
|
|
73
73
|
diagram = PropertyDiagram("R290", "ph", units="engineering", tp_limits="ACHP")
|
|
74
|
-
diagram.set_default_lines(labels=True)
|
|
74
|
+
diagram.set_default_lines(labels=True, rounding=True)
|
|
75
75
|
diagram.add_cycle(simple_compression("R290", T_evap_C=-5, T_cond_C=45, dT_sh_K=5))
|
|
76
76
|
diagram.save("R290_ph.png") # or .pdf, .svg; show() opens a window
|
|
77
77
|
```
|
|
@@ -60,6 +60,7 @@ from .spec.diagram import ANCHOR_KEYS
|
|
|
60
60
|
from .style.theme import Theme, get_theme
|
|
61
61
|
from .style.values import LineStyle, MarkerStyle
|
|
62
62
|
from .thermo.cycles.paths import resolve_state
|
|
63
|
+
from .thermo.fluid import Fluid
|
|
63
64
|
from .thermo.provider import PropertyProvider
|
|
64
65
|
|
|
65
66
|
if TYPE_CHECKING: # only for the type checker: the renderers are imported when a chart is drawn
|
|
@@ -201,6 +202,38 @@ REMOVED_NAMES = {
|
|
|
201
202
|
}
|
|
202
203
|
|
|
203
204
|
|
|
205
|
+
def _fluid_text(name: str, model: Tuple) -> str:
|
|
206
|
+
"""A fluid for a message: its name, and the basis of a mixture's fractions when that is mass or volume.
|
|
207
|
+
|
|
208
|
+
"HEOS::R32[0.5]&R125[0.5]" reads as mole fractions; given by mass it is
|
|
209
|
+
written "HEOS::R32[0.5]&R125[0.5] (fractions by mass)". A fluid of one
|
|
210
|
+
component keeps its name; so does an INCOMP fluid, which is one
|
|
211
|
+
component in CoolProp ("MEG" in "INCOMP::MEG[0.3]").
|
|
212
|
+
"""
|
|
213
|
+
if not model or len(model[1]) < 2 or model[3] not in ("mass", "volu"):
|
|
214
|
+
return name
|
|
215
|
+
return "{0} (fractions by {1})".format(name, "volume" if model[3] == "volu" else "mass")
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def _model_name(model: Tuple) -> str:
|
|
219
|
+
"""A fluid string for a model key, "HEOS::R32[0.5]&R125[0.5]", for a cycle that kept no name."""
|
|
220
|
+
backend, components, fractions, basis = model[:4]
|
|
221
|
+
try:
|
|
222
|
+
return str(FluidSpec(backend=backend, components=tuple(components), fractions=tuple(fractions), basis=basis))
|
|
223
|
+
except (TypeError, ValueError): # a model FluidSpec does not take: the components at least
|
|
224
|
+
return "&".join(components)
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
def _other_fluid_message(cycle: Cycle, chart_fluid: str, chart_model: Tuple) -> str:
|
|
228
|
+
"""Why a cycle does not belong on a chart; says so when the two fluids print alike."""
|
|
229
|
+
theirs = _fluid_text(cycle.fluid or _model_name(cycle.fluid_model), cycle.fluid_model)
|
|
230
|
+
mine = _fluid_text(chart_fluid, chart_model)
|
|
231
|
+
if theirs == mine:
|
|
232
|
+
return ("Cycle '{0}' was computed for another model of {1} than this chart's (other fractions, "
|
|
233
|
+
"basis of the fractions or interaction parameters).".format(cycle.name, mine))
|
|
234
|
+
return "Cycle '{0}' was computed for {1}, but this chart shows {2}.".format(cycle.name, theirs, mine)
|
|
235
|
+
|
|
236
|
+
|
|
204
237
|
class Chart:
|
|
205
238
|
"""A chart built from a spec; see :class:`PropertyDiagram` and :class:`PsychrometricChart`
|
|
206
239
|
|
|
@@ -470,7 +503,7 @@ class Chart:
|
|
|
470
503
|
``"range": (lo, hi)`` limits the saturation temperatures or
|
|
471
504
|
pressures. Steps and range are in ``units``. The labels show the
|
|
472
505
|
lines' own values ("s=2.321 kJ/kg/K"); ``"label": "saturation"``
|
|
473
|
-
shows the saturation state instead ("T_sat=0
|
|
506
|
+
shows the saturation state instead ("T_sat=0" with its unit). Charts of
|
|
474
507
|
a fluid only.
|
|
475
508
|
|
|
476
509
|
Examples
|
|
@@ -656,9 +689,10 @@ class Chart:
|
|
|
656
689
|
line_style: Optional[LineStyle], marker_style: Optional[MarkerStyle], steps: int,
|
|
657
690
|
labels: Labels = None) -> CycleSpec:
|
|
658
691
|
"""A CycleSpec for a computed Cycle, after checking that it belongs to this chart's fluid."""
|
|
659
|
-
if cycle.fluid and self._other_fluid(cycle
|
|
660
|
-
|
|
661
|
-
|
|
692
|
+
if (cycle.fluid or cycle.fluid_model) and self._other_fluid(cycle):
|
|
693
|
+
own = self.fluid
|
|
694
|
+
chart_model = own.model_key if isinstance(own, Fluid) else ()
|
|
695
|
+
raise ValueError(_other_fluid_message(cycle, str(self.spec.fluid), chart_model))
|
|
662
696
|
states = tuple((n, check_state(state, self.fluid)) for n, state in cycle.states)
|
|
663
697
|
cycle = replace(cycle, states=states) # with v filled in for a cycle computed before 0.7
|
|
664
698
|
return CycleSpec.from_cycle(cycle, name=name, loops=loops, paths=paths, numbers=numbers,
|
|
@@ -681,12 +715,20 @@ class Chart:
|
|
|
681
715
|
where = "{0} '{1}'".format(e.where, cycle.name) if e.where else "Cycle '{0}'".format(cycle.name)
|
|
682
716
|
raise self._in_units(e).with_where(where) from None
|
|
683
717
|
|
|
684
|
-
def _other_fluid(self,
|
|
685
|
-
"""Whether
|
|
686
|
-
|
|
687
|
-
|
|
718
|
+
def _other_fluid(self, cycle: Cycle) -> bool:
|
|
719
|
+
"""Whether ``cycle`` was computed for another fluid than this chart's.
|
|
720
|
+
|
|
721
|
+
The cycle's fluid is rebuilt from its model (:attr:`Cycle.fluid_model`,
|
|
722
|
+
which the cycle models fill in), or from its name for a cycle without
|
|
723
|
+
one, and compared with :meth:`coolplot.thermo.Fluid.same_fluid`: the
|
|
724
|
+
same mixture given by mass, by mole or as a predefined blend, with
|
|
725
|
+
its components in the same order, counts as one fluid.
|
|
726
|
+
"""
|
|
727
|
+
own = self.fluid
|
|
728
|
+
if not isinstance(own, Fluid): # humid air: a cycle of a fluid does not belong on it
|
|
688
729
|
return True
|
|
689
|
-
|
|
730
|
+
theirs = Fluid.from_model(cycle.fluid_model, cycle.fluid) if cycle.fluid_model else Fluid(cycle.fluid)
|
|
731
|
+
return not theirs.same_fluid(own)
|
|
690
732
|
|
|
691
733
|
def move_cycle_state(self, name: str, number: int, x: float, y: float,
|
|
692
734
|
units: Optional[UnitsLike] = None) -> None:
|
|
@@ -24,6 +24,7 @@ from typing import Dict, List, Optional, Sequence, Tuple
|
|
|
24
24
|
import numpy as np
|
|
25
25
|
|
|
26
26
|
from ..core.quantities import get_quantity
|
|
27
|
+
from ..core.symbols import symbol_text, unit_text
|
|
27
28
|
from ..scene import AxesSpec, SceneItem, Line, Markers, Text, drawable_limits
|
|
28
29
|
from ..spec.diagram import SATURATION_KEY, CycleSpec, DiagramSpec, ProcessSpec
|
|
29
30
|
from ..style.theme import Theme
|
|
@@ -57,9 +58,19 @@ def scaled_theme(theme: Theme, factor: float) -> Theme:
|
|
|
57
58
|
return theme if same_number(factor, 1.0) else _scaled(theme, factor)
|
|
58
59
|
|
|
59
60
|
|
|
61
|
+
def shown_symbol(spec: DiagramSpec, key: str) -> str:
|
|
62
|
+
"""The symbol of a quantity as the chart writes it, see ``LabelSettings.symbols``."""
|
|
63
|
+
return symbol_text(spec.diagram.symbol(key), spec.settings.labels.symbols)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def shown_unit(spec: DiagramSpec, key: str) -> str:
|
|
67
|
+
"""The unit label of a quantity as the chart writes it, see ``LabelSettings.symbols``."""
|
|
68
|
+
return unit_text(spec.units[key].label, spec.settings.labels.symbols)
|
|
69
|
+
|
|
70
|
+
|
|
60
71
|
def axis_label(spec: DiagramSpec, key: str) -> str:
|
|
61
72
|
"""Axis title with symbol and unit, e.g. "Specific enthalpy h / kJ/kg"."""
|
|
62
|
-
return "{0} {1} / {2}".format(spec.diagram.quantity_label(key), spec
|
|
73
|
+
return "{0} {1} / {2}".format(spec.diagram.quantity_label(key), shown_symbol(spec, key), shown_unit(spec, key))
|
|
63
74
|
|
|
64
75
|
|
|
65
76
|
def _include(limits, values, log: bool, pad: float = 0.04):
|
|
@@ -138,18 +149,18 @@ def legend_with_unit(spec: DiagramSpec, key: str, legend: str) -> str:
|
|
|
138
149
|
family labelled by its saturation states says so, with the unit of
|
|
139
150
|
those: "Specific entropy s at T_sat / deg C".
|
|
140
151
|
"""
|
|
141
|
-
text = "{0} {1}".format(legend, spec
|
|
152
|
+
text = "{0} {1}".format(legend, shown_symbol(spec, key))
|
|
142
153
|
anchor = _saturation_anchor(spec, key)
|
|
143
154
|
if anchor is not None:
|
|
144
155
|
text += " at " + saturation_symbol(spec, anchor)
|
|
145
156
|
key = anchor.by
|
|
146
|
-
unit = spec
|
|
157
|
+
unit = shown_unit(spec, key)
|
|
147
158
|
return text if unit in ("-", "") else text + " / " + unit
|
|
148
159
|
|
|
149
160
|
|
|
150
161
|
def saturation_symbol(spec: DiagramSpec, anchor) -> str:
|
|
151
162
|
"""The symbol of the saturation state lines are labelled by: "T_sat", "T_sat,liq" or "T(x=0.5)"."""
|
|
152
|
-
symbol = spec
|
|
163
|
+
symbol = shown_symbol(spec, anchor.by)
|
|
153
164
|
if same_number(anchor.Q, 1.0):
|
|
154
165
|
return symbol + "_sat"
|
|
155
166
|
if is_zero(anchor.Q):
|
|
@@ -179,11 +190,11 @@ def label_text(spec: DiagramSpec, key: str, value_SI: float, anchor_SI: Optional
|
|
|
179
190
|
key, value_SI = anchor.by, anchor_SI
|
|
180
191
|
symbol = saturation_symbol(spec, anchor)
|
|
181
192
|
else:
|
|
182
|
-
symbol = spec
|
|
193
|
+
symbol = shown_symbol(spec, key)
|
|
183
194
|
unit = spec.units[key]
|
|
184
195
|
text = "{0}={1}".format(symbol, labels.format_value(unit.label_value(value_SI)))
|
|
185
196
|
if labels.show_units and unit.label not in ("-", ""):
|
|
186
|
-
text += " " +
|
|
197
|
+
text += " " + shown_unit(spec, key)
|
|
187
198
|
return text
|
|
188
199
|
|
|
189
200
|
|
|
@@ -141,6 +141,13 @@ def check_paths(paths) -> Tuple[Tuple[Tuple[int, int], str], ...]:
|
|
|
141
141
|
return tuple(sorted(out))
|
|
142
142
|
|
|
143
143
|
|
|
144
|
+
def _frozen(value: Any) -> Any:
|
|
145
|
+
"""``value`` with every list and tuple in it turned into a tuple, recursively."""
|
|
146
|
+
if isinstance(value, (list, tuple)):
|
|
147
|
+
return tuple(_frozen(item) for item in value)
|
|
148
|
+
return value
|
|
149
|
+
|
|
150
|
+
|
|
144
151
|
@dataclass(frozen=True)
|
|
145
152
|
class Cycle:
|
|
146
153
|
"""A computed cycle: numbered states, routes and results
|
|
@@ -162,7 +169,15 @@ class Cycle:
|
|
|
162
169
|
Results in SI units, named like the quantities they hold, for
|
|
163
170
|
example ("COP_heating", 3.9) or ("q_evap_J_kg", 2.6e5).
|
|
164
171
|
fluid : str
|
|
165
|
-
The fluid the states were computed for.
|
|
172
|
+
The fluid the states were computed for, as :attr:`coolplot.thermo.Fluid.name`
|
|
173
|
+
gives it; shown in messages.
|
|
174
|
+
fluid_model : tuple
|
|
175
|
+
The model of that fluid, :attr:`coolplot.thermo.Fluid.model_key`:
|
|
176
|
+
backend, components, fractions, their basis and interaction
|
|
177
|
+
parameters, which the name may not hold (a mixture given by mass
|
|
178
|
+
has a name CoolProp reads by mole). The cycle models fill it in;
|
|
179
|
+
a chart checks a cycle against its fluid with it, or with the name
|
|
180
|
+
when it is empty.
|
|
166
181
|
"""
|
|
167
182
|
name: str
|
|
168
183
|
states: Tuple[Tuple[int, StatePoint], ...]
|
|
@@ -170,6 +185,7 @@ class Cycle:
|
|
|
170
185
|
paths: Tuple[Tuple[Tuple[int, int], str], ...] = ()
|
|
171
186
|
results: Tuple[Tuple[str, float], ...] = ()
|
|
172
187
|
fluid: str = ""
|
|
188
|
+
fluid_model: Tuple[Any, ...] = ()
|
|
173
189
|
|
|
174
190
|
def __post_init__(self):
|
|
175
191
|
states = tuple(sorted((int(n), s) for n, s in (self.states.items() if isinstance(self.states, dict)
|
|
@@ -180,6 +196,8 @@ class Cycle:
|
|
|
180
196
|
object.__setattr__(self, "paths", check_paths(self.paths))
|
|
181
197
|
results = self.results.items() if isinstance(self.results, dict) else self.results
|
|
182
198
|
object.__setattr__(self, "results", tuple((str(k), float(v)) for k, v in results))
|
|
199
|
+
# Lists anywhere in the model become tuples, so that the Cycle stays hashable
|
|
200
|
+
object.__setattr__(self, "fluid_model", _frozen(self.fluid_model))
|
|
183
201
|
|
|
184
202
|
def state(self, number: int) -> StatePoint:
|
|
185
203
|
"""The state with the given number."""
|
|
@@ -31,7 +31,9 @@ class Quantity:
|
|
|
31
31
|
Name understood by ``CoolProp.HumidAirProp.HAPropsSI``, or None
|
|
32
32
|
for a quantity that humid air does not have.
|
|
33
33
|
symbol : str
|
|
34
|
-
Symbol used in axis labels, plain ASCII.
|
|
34
|
+
Symbol used in axis labels, plain ASCII. Charts write some of
|
|
35
|
+
them with their own characters ("rho" as the Greek letter), see
|
|
36
|
+
:mod:`coolplot.core.symbols`.
|
|
35
37
|
label : str
|
|
36
38
|
Human readable name used in axis labels.
|
|
37
39
|
log_scale : bool
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""How symbols and units are written in the texts of a chart.
|
|
3
|
+
|
|
4
|
+
CoolPlot keeps its symbols and unit labels in plain ASCII ("rho",
|
|
5
|
+
"deg C", "kg/m3"), so that they are easy to type, compare and store. The
|
|
6
|
+
texts a chart shows (axis titles, legends, line labels) use the proper
|
|
7
|
+
characters by default: rho becomes the Greek letter, deg C the degree
|
|
8
|
+
sign with C, m3 the cubed metre. ``LabelSettings.symbols = "ascii"``
|
|
9
|
+
keeps the plain spelling on the chart as well.
|
|
10
|
+
|
|
11
|
+
The characters are written as escapes ("\\u03c1"), so that this source
|
|
12
|
+
file stays ASCII. Only whole symbols and whole unit labels are replaced:
|
|
13
|
+
"rho" turns into the Greek letter, a label such as "rhoX" stays as it is.
|
|
14
|
+
|
|
15
|
+
This module is plain data and imports nothing of CoolPlot.
|
|
16
|
+
"""
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
#: The values of ``LabelSettings.symbols``: "unicode" (the default since
|
|
20
|
+
#: 1.4) writes rho, phi, deg C, m3 and the like with their proper
|
|
21
|
+
#: characters, "ascii" as plain letters (the look before 1.4).
|
|
22
|
+
SYMBOL_STYLES = ("unicode", "ascii")
|
|
23
|
+
|
|
24
|
+
#: Quantity symbols, as CoolPlot spells them in ASCII, and how they are
|
|
25
|
+
#: written in "unicode" style. Relative humidity is phi on both humid air
|
|
26
|
+
#: charts, as in the ASHRAE Handbook and ISO 80000-5.
|
|
27
|
+
UNICODE_SYMBOLS = {
|
|
28
|
+
"rho": "\u03c1", # Greek small letter rho, density
|
|
29
|
+
"phi": "\u03c6", # Greek small letter phi, relative humidity
|
|
30
|
+
"RH": "\u03c6",
|
|
31
|
+
"Twb": "T_wb", # wet-bulb temperature, written like T_sat
|
|
32
|
+
"Tdp": "T_dp", # dew-point temperature
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
#: Unit labels of the unit systems in ASCII, and how they are written in
|
|
36
|
+
#: "unicode" style. The same texts in a custom unit are replaced too.
|
|
37
|
+
UNICODE_UNITS = {
|
|
38
|
+
"deg C": "\u00b0C", # degree sign
|
|
39
|
+
"deg F": "\u00b0F",
|
|
40
|
+
"R": "\u00b0R", # degree Rankine
|
|
41
|
+
"Btu/lb/R": "Btu/lb/\u00b0R",
|
|
42
|
+
"kg/m3": "kg/m\u00b3", # superscript three
|
|
43
|
+
"m3/kg": "m\u00b3/kg",
|
|
44
|
+
"lb/ft3": "lb/ft\u00b3",
|
|
45
|
+
"ft3/lb": "ft\u00b3/lb",
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def check_symbol_style(style: str) -> str:
|
|
50
|
+
"""``style`` if it is one of :data:`SYMBOL_STYLES`, else a ValueError."""
|
|
51
|
+
if style not in SYMBOL_STYLES:
|
|
52
|
+
raise ValueError("Unknown symbol style '{0}', expected one of {1}.".format(style, SYMBOL_STYLES))
|
|
53
|
+
return style
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def symbol_text(symbol: str, style: str) -> str:
|
|
57
|
+
"""A quantity symbol as the chart shows it, e.g. "rho" in "unicode" style is the Greek letter."""
|
|
58
|
+
return UNICODE_SYMBOLS.get(symbol, symbol) if style == "unicode" else symbol
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def unit_text(label: str, style: str) -> str:
|
|
62
|
+
"""A unit label as the chart shows it, e.g. "deg C" in "unicode" style is the degree sign and C."""
|
|
63
|
+
return UNICODE_UNITS.get(label, label) if style == "unicode" else label
|
|
@@ -153,6 +153,8 @@ _NEEDS_A_NEWER_CORE = (
|
|
|
153
153
|
"lay out labels on rails or place a legend by itself"),
|
|
154
154
|
((1, 2), lambda spec: spec.diagram.is_mollier, "compose the Mollier h,x chart"),
|
|
155
155
|
((1, 3), _restyles_the_dome, "restyle the saturation curve or the quality lines"),
|
|
156
|
+
((1, 4), lambda spec: spec.settings.labels.symbols == "unicode", "write symbols and units with their own "
|
|
157
|
+
"characters (rho, deg C, m3)"),
|
|
156
158
|
)
|
|
157
159
|
|
|
158
160
|
|
|
@@ -69,7 +69,7 @@ class SaturationAnchor:
|
|
|
69
69
|
label : str
|
|
70
70
|
"value" (the default) labels each line with its own value, e.g.
|
|
71
71
|
"s=2.321 kJ/kg/K"; "saturation" with the saturation state it was
|
|
72
|
-
placed through, e.g. "T_sat=0
|
|
72
|
+
placed through, e.g. "T_sat=0" with its unit.
|
|
73
73
|
"""
|
|
74
74
|
by: str = "T"
|
|
75
75
|
step_SI: float = 10.0
|
|
@@ -24,6 +24,7 @@ from dataclasses import asdict, dataclass, field, fields, replace
|
|
|
24
24
|
from typing import Optional, Tuple, Union
|
|
25
25
|
|
|
26
26
|
from ..core.numbers import format_number
|
|
27
|
+
from ..core.symbols import check_symbol_style
|
|
27
28
|
from ..style.theme import Theme, get_theme
|
|
28
29
|
|
|
29
30
|
SATURATION_SPACINGS = ("critical", "linear")
|
|
@@ -147,6 +148,12 @@ class LabelSettings:
|
|
|
147
148
|
Significant digits of the values shown in labels.
|
|
148
149
|
show_units : bool
|
|
149
150
|
Append the unit to every label value.
|
|
151
|
+
symbols : str
|
|
152
|
+
How symbols and units are written in axis titles, legends and
|
|
153
|
+
labels: "unicode" (the default since 1.4) with their proper
|
|
154
|
+
characters (the Greek rho and phi, the degree sign, m3 with a
|
|
155
|
+
superscript 3), "ascii" in plain letters ("rho", "deg C", "kg/m3"),
|
|
156
|
+
as before 1.4. See :mod:`coolplot.core.symbols`.
|
|
150
157
|
tick_digits : int
|
|
151
158
|
Significant digits of tick labels; every backend writes them with
|
|
152
159
|
:func:`coolplot.core.numbers.format_number`.
|
|
@@ -161,6 +168,7 @@ class LabelSettings:
|
|
|
161
168
|
digits: int = 4
|
|
162
169
|
show_units: bool = True
|
|
163
170
|
tick_digits: int = 6
|
|
171
|
+
symbols: str = "unicode"
|
|
164
172
|
|
|
165
173
|
def __post_init__(self):
|
|
166
174
|
if self.mode not in LABEL_MODES:
|
|
@@ -176,6 +184,7 @@ class LabelSettings:
|
|
|
176
184
|
if not 1 <= int(getattr(self, name)) <= 12:
|
|
177
185
|
raise ValueError("LabelSettings.{0} has to be between 1 and 12.".format(name))
|
|
178
186
|
object.__setattr__(self, name, int(getattr(self, name)))
|
|
187
|
+
check_symbol_style(self.symbols)
|
|
179
188
|
object.__setattr__(self, "keep_out_pt", float(self.keep_out_pt))
|
|
180
189
|
object.__setattr__(self, "edges", edges)
|
|
181
190
|
object.__setattr__(self, "margin_edges", margin_edges)
|
|
@@ -393,9 +402,14 @@ class Settings:
|
|
|
393
402
|
raise ValueError("Unknown {0} fields: {1}.".format(part_cls.__name__, sorted(unknown)))
|
|
394
403
|
return part_cls(**(values or {}))
|
|
395
404
|
look = data.get("look")
|
|
405
|
+
labels = dict(data.get("labels") or {})
|
|
406
|
+
if data.get("labels") is not None and "symbols" not in labels:
|
|
407
|
+
# A record before 1.4 always holds its labels, never the symbol
|
|
408
|
+
# style: it keeps the plain spelling it was drawn with
|
|
409
|
+
labels["symbols"] = "ascii"
|
|
396
410
|
return cls(calc=part(CalcSettings, data.get("calc")),
|
|
397
411
|
look=Theme.from_dict(look) if isinstance(look, dict) else get_theme(look or "default"),
|
|
398
|
-
labels=part(LabelSettings,
|
|
412
|
+
labels=part(LabelSettings, labels),
|
|
399
413
|
page=part(PageSettings, data.get("page")),
|
|
400
414
|
branding=part(BrandingSettings, data.get("branding")))
|
|
401
415
|
|
|
@@ -103,7 +103,7 @@ def simple_compression(fluid, T_evap_C: float, T_cond_C: float, dT_sh_K: float =
|
|
|
103
103
|
"T_comp_out_K": s2.T}
|
|
104
104
|
return Cycle(name, ((1, s1), (2, s2), (3, s3), (4, s4)), paths=(((1, 2), "polytropic"),),
|
|
105
105
|
results=tuple(results.items()),
|
|
106
|
-
fluid=fluid.name)
|
|
106
|
+
fluid=fluid.name, fluid_model=fluid.model_key)
|
|
107
107
|
|
|
108
108
|
|
|
109
109
|
def two_stage(fluid, T_evap_C: float, T_cond_C: float, intermediate: str = "flash_tank",
|
|
@@ -188,7 +188,7 @@ def two_stage(fluid, T_evap_C: float, T_cond_C: float, intermediate: str = "flas
|
|
|
188
188
|
COP_heating=q_cond_J_kg / w_comp_J_kg)
|
|
189
189
|
default_name = "Two-stage, " + ("flash tank" if intermediate == "flash_tank" else "economizer")
|
|
190
190
|
return Cycle(name or default_name, tuple(states.items()), tuple(tuple(chain) for chain in loops),
|
|
191
|
-
tuple(paths.items()), tuple(results.items()), fluid.name)
|
|
191
|
+
tuple(paths.items()), tuple(results.items()), fluid.name, fluid.model_key)
|
|
192
192
|
|
|
193
193
|
|
|
194
194
|
def rankine(fluid, p_high_Pa: float, p_low_Pa: float, T_live_C: Optional[float] = None,
|
|
@@ -238,4 +238,4 @@ def rankine(fluid, p_high_Pa: float, p_low_Pa: float, T_live_C: Optional[float]
|
|
|
238
238
|
"w_pump_J_kg": w_pump_J_kg, "eta_th": (w_turbine_J_kg - w_pump_J_kg) / q_in_J_kg}
|
|
239
239
|
return Cycle(name, ((1, s1), (2, s2), (3, s3), (4, s4)), paths=(((1, 2), "polytropic"), ((3, 4), "polytropic")),
|
|
240
240
|
results=tuple(results.items()),
|
|
241
|
-
fluid=fluid.name)
|
|
241
|
+
fluid=fluid.name, fluid_model=fluid.model_key)
|
|
@@ -14,6 +14,7 @@ from __future__ import annotations
|
|
|
14
14
|
|
|
15
15
|
import hashlib
|
|
16
16
|
import json
|
|
17
|
+
import math
|
|
17
18
|
import os
|
|
18
19
|
from functools import lru_cache
|
|
19
20
|
from typing import Optional, Tuple, Union
|
|
@@ -202,6 +203,38 @@ class Fluid:
|
|
|
202
203
|
that determines the properties, so it can serve as a cache key."""
|
|
203
204
|
return self._model
|
|
204
205
|
|
|
206
|
+
def same_fluid(self, other: "Fluid") -> bool:
|
|
207
|
+
"""Whether ``other`` is this fluid model, however it was given.
|
|
208
|
+
|
|
209
|
+
The same model key, or the same model as CoolProp reports it for the
|
|
210
|
+
two states (:func:`model_from_state`): the same backend, components
|
|
211
|
+
and interaction parameters, with the same mole fractions to 1e-9 (the
|
|
212
|
+
rounding of converting mass to mole fractions). So R32/R125 50/50 by
|
|
213
|
+
mass, the same mixture by mole and CoolProp's "R410A.mix" are one
|
|
214
|
+
fluid, and so are "R290" and "Propane".
|
|
215
|
+
"""
|
|
216
|
+
if self._model == other._model:
|
|
217
|
+
return True
|
|
218
|
+
try:
|
|
219
|
+
mine, theirs = model_from_state(self._state), model_from_state(other._state)
|
|
220
|
+
except ValueError: # a state that cannot report its fluid (INCOMP): only the model key decides
|
|
221
|
+
return False
|
|
222
|
+
# CoolProp reports a predefined blend ("R410A.mix") on "HelmholtzEOSBackend"
|
|
223
|
+
# and the same mixture given by its components on
|
|
224
|
+
# "HelmholtzEOSMixtureBackend": one family of equations, so the word
|
|
225
|
+
# Mixture is left out of the comparison (likewise for REFPROP)
|
|
226
|
+
backends = (str(mine[0]).replace("Mixture", ""), str(theirs[0]).replace("Mixture", ""))
|
|
227
|
+
if backends[0] != backends[1] or mine[1] != theirs[1]:
|
|
228
|
+
return False
|
|
229
|
+
same_fractions = len(mine[2]) == len(theirs[2]) and all(
|
|
230
|
+
math.isclose(a, b, rel_tol=0.0, abs_tol=1e-9) for a, b in zip(mine[2], theirs[2]))
|
|
231
|
+
# Interaction parameters as (i, j, key, value); a state of one backend
|
|
232
|
+
# reports the same keys, so the values decide
|
|
233
|
+
same_interactions = len(mine[4]) == len(theirs[4]) and all(
|
|
234
|
+
a[:3] == b[:3] and math.isclose(a[3], b[3], rel_tol=1e-12, abs_tol=0.0)
|
|
235
|
+
for a, b in zip(mine[4], theirs[4]))
|
|
236
|
+
return same_fractions and same_interactions
|
|
237
|
+
|
|
205
238
|
@property
|
|
206
239
|
def pseudo_pure_blend(self) -> Optional[str]:
|
|
207
240
|
"""For CoolProp's pseudo-pure model of a blend ("R407C"), the name of the
|
|
@@ -222,6 +255,22 @@ class Fluid:
|
|
|
222
255
|
name = components[0] + ".mix"
|
|
223
256
|
return name if name in _predefined_mixtures() else None
|
|
224
257
|
|
|
258
|
+
@classmethod
|
|
259
|
+
def from_model(cls, model: Tuple, name: str = "") -> "Fluid":
|
|
260
|
+
"""A Fluid of a model key (:attr:`model_key`), as a Cycle keeps it.
|
|
261
|
+
|
|
262
|
+
The model key holds everything a fluid name may lose: the basis of
|
|
263
|
+
the fractions, interaction parameters set on a mixture, the fractions
|
|
264
|
+
of a mixture given as an AbstractState. ``name`` is shown in messages;
|
|
265
|
+
by default the components joined by "&".
|
|
266
|
+
"""
|
|
267
|
+
fluid = cls.__new__(cls)
|
|
268
|
+
fluid._model = tuple(model)
|
|
269
|
+
fluid._state = build_state(fluid._model)
|
|
270
|
+
fluid._reset_caches()
|
|
271
|
+
fluid._name = name or "&".join(fluid._model[1])
|
|
272
|
+
return fluid
|
|
273
|
+
|
|
225
274
|
def with_backend(self, backend: str) -> "Fluid":
|
|
226
275
|
"""The same fluid model on another CoolProp backend."""
|
|
227
276
|
twin = Fluid.__new__(Fluid)
|