azogue / psychrochart Goto Github PK
View Code? Open in Web Editor NEWA Python 3 library to make psychrometric charts and overlay information on them.
License: MIT License
A Python 3 library to make psychrometric charts and overlay information on them.
License: MIT License
Hi @azogue, well done for developing psychrochart!
A while ago we developed PsychroLib (https://github.com/psychrometrics/psychrolib) -- a library of psychrometric functions to calculate thermodynamic properties of air for Python, C, Fortran, JavaScript and VBA/Excel. I have noticed that you are maintaining several psychrometric functions yourself and, just in case you did not know, you may find the project useful to rely on PsychroLib rather than maintaining your own...
Hi trying to build a jupyter notebook and getting things mostly working but not understanding plotting a series of points.
python3
chart = PsychroChart("ashrae")
t1 = numpy.array([65.24384, 65.24384])
h1 = numpy.array([50.7857, 51.1154])
points = { 'n': (t1, h1) }
chart.plot_points_dbt_rh(points)
Generates an error:
~/.conda/envs/pschrometricenv/lib/python3.8/site-packages/matplotlib/axes/_base.py in _xy_from_xy(self, x, y)
267 y = _check_1d(y)
268 if x.shape[0] != y.shape[0]:
--> 269 raise ValueError("x and y must have same first dimension, but "
270 "have shapes {} and {}".format(x.shape, y.shape))
271 if x.ndim > 2 or y.ndim > 2:
ValueError: x and y must have same first dimension, but have shapes (1, 2) and (2,)
Now I also got a different error with this method but I am not sure if I'm passing in a numpy array. But I think it is. y['temperature'] and y['humidity'] are python lists.
t = numpy.asarray(y['temperature'])
h = numpy.asarray(y['humidity'])
chart = PsychroChart("ashrae")
points = { 'n': (t, h) }
chart.plot_points_dbt_rh(points)
Then the error is:
~/.conda/envs/pschrometricenv/lib/python3.8/site-packages/psychrolib.py in GetSatVapPres(TDryBulb)
1033 - 2.4780681E-09 * math.pow(T, 3) + 6.5459673 * math.log(T)
1034 else:
-> 1035 if (TDryBulb < -100 or TDryBulb > 200):
1036 raise ValueError("Dry bulb temperature must be in range [-100, 200]°C")
1037
TypeError: '<' not supported between instances of 'numpy.str_' and 'int'
Thanks for any insight. Again, I'm probably doing something silly.
Cary
Hi.
The following problem arises
numba.core.errors.NumbaNotImplementedError: none cannot be represented as a NumPy dtype
when I try to run
from psychrochart import PsychroChart
chart_default = PsychroChart.create()
chart_default.config.limits.range_temp_c = (15.0, 35.0)
chart_default.config.limits.range_humidity_g_kg = (5, 25)
chart_default.config.saturation.linewidth = 1
chart_default.config.constant_wet_temp.color = "darkblue"
axes = chart_default.plot()
axes.get_figure()
chart_default.save("my-custom-chart.svg")
I've already upgraded Numba & psychrochart to the latest versions.
Regards.-
PS: I'm not quite sure if this is a psychrochart problem or a problem of my setup.
I'm super pumped to see that this has been ported over with IP usage. As a mechanical engineer without much debugging experience, I'm running this code and getting the following issue. Am I doing something wrong?
Thanks for the work getting this to work with IP units.
%matplotlib inline
%config InlineBackend.figure_format = 'retina'
import matplotlib.pyplot as plt
from psychrochart import PsychroChart, load_config
chart_ashrae_style = PsychroChart(use_unit_system_si=False)
ax = chart_ashrae_style.plot()
ax.get_figure()
WARNING:root:[IP units mode] ENABLED
ERROR:root:ENTHALPHY CONVERGENCE ERROR: No convergence error after 100 iterations! Last value: 101.8643583901623, ∆: 0.125. Objective: 75, iter_value: 75.18484966677528
ValueError Traceback (most recent call last)
in
5 from psychrochart import PsychroChart, load_config
6
----> 7 chart_ashrae_style = PsychroChart(use_unit_system_si=False)
8 ax = chart_ashrae_style.plot()
9 ax.get_figure()
~\AppData\Roaming\Python\Python37\site-packages\psychrochart\chart.py in init(self, styles, zones_file, use_unit_system_si)
86 self._handlers_annotations: List = []
87
---> 88 self._make_chart_data(styles, zones_file)
89
90 def repr(self) -> str:
~\AppData\Roaming\Python\Python37\site-packages\psychrochart\chart.py in _make_chart_data(self, styles, zones_file)
213 label_loc=self.chart_params.get("constant_v_labels_loc", 1.0),
214 family_label=self.chart_params["constant_v_label"],
--> 215 saturation_curve=self.saturation.curves[0],
216 )
217
~\AppData\Roaming\Python\Python37\site-packages\psychrochart\chartdata.py in make_constant_specific_volume_lines(w_humidity_ratio_min, pressure, vol_values, v_label_values, style, label_loc, family_label, saturation_curve)
310 vol_values,
311 lambda *x: t_sat_interpolator(x[0]),
--> 312 lambda x: GetMoistAirVolume(
313 x, GetHumRatioFromVapPres(GetSatVapPres(x), pressure), pressure,
314 ),
~\AppData\Roaming\Python\Python37\site-packages\psychrochart\util.py in solve_curves_with_iteration(family_name, objective_values, func_init, func_eval)
178 func_eval=func_eval,
179 initial_increment=initial_increment,
--> 180 precision=precision,
181 )
182 except AssertionError as exc: # pragma: no cover
~\AppData\Roaming\Python\Python37\site-packages\psychrochart\util.py in _iter_solver(initial_value, objective_value, func_eval, initial_increment, num_iters_max, precision)
121 num_iter = 0
122 value_calc = initial_value.copy()
--> 123 error = objective_value - func_eval(initial_value)
124 while abs(error) > precision and num_iter < num_iters_max:
125 iteration_value = func_eval(value_calc)
~\AppData\Roaming\Python\Python37\site-packages\psychrochart\chartdata.py in (x)
311 lambda *x: t_sat_interpolator(x[0]),
312 lambda x: GetMoistAirVolume(
--> 313 x, GetHumRatioFromVapPres(GetSatVapPres(x), pressure), pressure,
314 ),
315 )
~\AppData\Roaming\Python\Python37\site-packages\psychrolib.py in GetSatVapPres(TDryBulb)
1022 if isIP():
1023 if (TDryBulb < -148 or TDryBulb > 392):
-> 1024 raise ValueError("Dry bulb temperature must be in range [-148, 392]°F")
1025
1026 T = GetTRankineFromTFahrenheit(TDryBulb)
ValueError: Dry bulb temperature must be in range [-148, 392]°F
Is there a way to create additional axes for Enthalpy as shown in the attached CIBSE chart?
CIBSE PsychrometricChart Atmospheric.pdf
I know IP is new (thanks for adding!), and I hope this is helpful. I've found that I have to pretend my IP units are SI units. For example:
chart.config.limits.range_temp_c = (0, 115) #actually F not C
chart.config.limits.range_humidity_g_kg = (0, 300) #actually grain/lb
Is it possible to change the y-axis from humidity ratio to vapor pressure? I have tried converting, but it is not a 1:1 ratio or linear relationship between the variables so it does not come out right. I'm assuming I would need to change something in the chart.py, chartdata.py, and json files, but am getting mixed up on how to go about that.
More Defaults Needed
Hello, I am using this for project that is not HVAC related. The operating points are hotter and higher humidity than any HVAC system. Upwards of 90C with RH of 90%.
When plotting for an enthalpy exceeding 500 kJ/kg, I receive this error:
ERROR:root:ENTHALPHY CONVERGENCE ERROR: No convergence error after 100 iterations! Last value: 61.13422132911032, ∆: 0.001. Objective: 500, iter_value: 499.98766076525493
This happens regardless of the Max number of iterations or precision values. The change I make in the script do not appear to have an effect (I did turn some other features on/off to verify I was modifying the correct file.
If I change the max Enthalpy value to 500 or below, I do not receive this error and the constant enthalpy lines below 500 do plot just fine.
Is there something in the code limiting this (I can't seem to find anything though) or is the psychrolib limiting the max enthalpy somehow (again I can't seem to find something limiting this).
Hello,
I would like to have only thin connexions between points in the diagram, without the pink zone around the line segments. I didn't find the option to remove them. Is it possible ?
Thanks
Hi,
Thanks a lot for this package. It's helpful and good-looking, especially with the predefined styles.
My question: How can I create a zone that covers the entire graph up to a certain water vapour content (g/kg)?
I tried to install psychrochart for test. However, it seems not compatible with the base environment of anaconda.
The anaconda version used is Anaconda3-2024.02-1-Windows-x86_64
Python version is 3.11.7
When the follow code was tested
from psychrochart import PsychroChart
import matplotlib.pyplot as plt
PsychroChart.create().plot(ax=plt.gca())
plt.show()
Error raised as
I created a new clean environment of python 3.10. The test code was successfully executed.
Therefore, I think it is the problem of numba installed in the base environment of anaconda.
Could this problem be fixed for environment with nubma installed or there is some tricks?
Thank you.
Hello,
Looks like a very nice package.
Unfortunately, I was unable to get any picture.
I tried mainly in Jupyter, but also in Spyder.
In Jupyter, I tried the "Usage example of psychrochart" notebook.
I also tried snippets from README.md in various combinations without any success.
I also checked that for example chart_default contained data, and I saw the many curves calculated.
Clearly only the rendering is not working for me.
Would you have an idea why that could be?
Thanks,
Michel
PS: I checked that matplotlib is working on some simple examples.
Does any documentation exist for inputs and flags? For example, I've had to hunt through the code to figure out what "xy" means. I was feeding it (dry bulb, wet bulb), but data was coming out strange. Commenting here, so others know: this apparently is (dry bulb, relative humidity).
points = {'OAT': {'label': 'OAT',
'style': {'color': [0.855, 0.004, 0.278, 0.8],
'marker': 'o', 'markersize': 1},
'xy': (dft.Fdb, dft.OSArh)}}
How to export Psychrochart figure as png/svg
Hi! This is just an issue with the documentation in the main README: The example provided under "Usage" isn't currently functional. Specifically, it includes
chart_default.limits.range_temp_c = (15.0, 35.0)
chart_default.limits.range_humidity_g_kg = (5, 25)
but it appears that the current version of psychrochart doesn't provide a "limits" attribute for a chart object, directly. As far as I can tell, it should read:
chart_default.config.limits.range_temp_c = (15.0, 35.0)
chart_default.config.limits.range_humidity_g_kg = (5, 25)
Thank you for your time and attention!
versions above 2.5 cause the following errors when trying to plot charts in SI in JupyterLab downgrading to 2.5 resolve issue:
C:\ProgramData\Anaconda3\lib\site-packages\psychrochart\chartdata.py:356: RuntimeWarning: divide by zero encountered in GetRelHumFromTWetBulb
GetSatVapPres(db_t) * GetRelHumFromTWetBulb(db_t, wb_t, p_atm),
Great package really appreciate the time - note downgrading package solves the issue for me which is fine.
I am trying to change the label location by changing the "constant_rh_labels_loc" from 0.85 to 0.1 in chart.py. But there is no change in the plot. Is there a way to change the label location? Thanks.
It appears the current zone_dbt_rh draws lines based on constant temperatures.
Is there an easy way to show a PMV thermal comfort zone?
https://en.wikipedia.org/wiki/Thermal_comfort
Or at least be able to specify dbt/rh for each vertex of a zone?
Hi there,
would it be possible to alter the plot style to print points on Molier style chart rather than Psychro chart?
https://www.engineeringtoolbox.com/psychrometric-chart-mollier-d_27.html
Hi Azogue
I am currently trying to use your psychrometric chart to plot hourly weather data for an annual period. The specified method for adding points to the chart is to enter DBT and RH co-ordinates individually, however I can't do this for 8760 entries.
I noticed you wrote the following in your code:
points={'points_series_name': (temp_array, humid_array)}
I tried to replicate this as per the image attached however I ran into errors within the equations file. Unfortunately editing the code in there goes beyond my current coding capabilities.
I was wondering if you had managed to plot something like this on the chart or if you know how to resolve my issue?
Thanks very much for your help.
Order of operations:
conda create --name=hvac python=3.11
conda activate hvac
pip install psychrochart
(Using cached psychrochart-0.9.1-py3-none-any.whl (44 kB))
python
from psychrochart import PsychroChart
Error:
/Users/brendan/miniforge3/envs/hvac/lib/python3.11/site-packages/pydantic/_internal/_config.py:269: UserWarning: Valid config keys have changed in V2:
* 'allow_mutation' has been removed
* 'underscore_attrs_are_private' has been removed
warnings.warn(message, UserWarning)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/brendan/miniforge3/envs/hvac/lib/python3.11/site-packages/psychrochart/__init__.py", line 2, in <module>
from psychrochart.chart import PsychroChart
File "/Users/brendan/miniforge3/envs/hvac/lib/python3.11/site-packages/psychrochart/chart.py", line 23, in <module>
from psychrochart.chartzones import make_over_saturated_zone
File "/Users/brendan/miniforge3/envs/hvac/lib/python3.11/site-packages/psychrochart/chartzones.py", line 24, in <module>
from psychrochart.models.config import ChartZone
File "/Users/brendan/miniforge3/envs/hvac/lib/python3.11/site-packages/psychrochart/models/config.py", line 80, in <module>
class ChartZone(BaseConfig):
File "/Users/brendan/miniforge3/envs/hvac/lib/python3.11/site-packages/psychrochart/models/config.py", line 89, in ChartZone
@root_validator
^^^^^^^^^^^^^^
File "/Users/brendan/miniforge3/envs/hvac/lib/python3.11/site-packages/pydantic/deprecated/class_validators.py", line 222, in root_validator
return root_validator()(*__args) # type: ignore
^^^^^^^^^^^^^^^^
File "/Users/brendan/miniforge3/envs/hvac/lib/python3.11/site-packages/pydantic/deprecated/class_validators.py", line 228, in root_validator
raise PydanticUserError(
pydantic.errors.PydanticUserError: If you use `@root_validator` with pre=False (the default) you MUST specify `skip_on_failure=True`. Note that `@root_validator` is deprecated and should be replaced with `@model_validator`.
For further information visit https://errors.pydantic.dev/2.1.1/u/root-validator-pre-skip
chart.save("test1-chart.svg") has axis, some white space outside of chart.
chart.save("test1-chart.png") has no axis, png ends at boundaries of chart.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.