Coder Social home page Coder Social logo

azogue / psychrochart Goto Github PK

View Code? Open in Web Editor NEW
98.0 13.0 26.0 34.48 MB

A Python 3 library to make psychrometric charts and overlay information on them.

License: MIT License

Python 10.65% Jupyter Notebook 89.25% CSS 0.10%
psychrometrics moisture humidity-control climate-zone matplotlib python3 hvac psychrometric psychrometric-chart

psychrochart's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

psychrochart's Issues

Psychrometric routines with PsychroLib

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...

plotting series of points

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

Incompatibility with Numba

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

Load default style:

chart_default = PsychroChart.create()

customize anything

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"

plot

axes = chart_default.plot()
axes.get_figure()

or store on disk

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.

YES! IP! Small issue though

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

Region around a connector line

Hi,
This is not an issue, but I was unable find the answer it the code.
Is it possible the change the formatting, or even to remove the region around a connector line?
thanks

image

IP Units

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

Change y-axis units

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.

Error for plotting enthalpy lines above 500 kJ/kg

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).

Thank you,
Roy
image
image

How to create a zone with vapour content limit?

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)?

Error under environment with numba installed

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

image

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.

could not see any chart at all, any idea why that could be?

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.

Documentation

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)}}

README Usage example nonfunctional

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 broken SI -

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.

Change the label location for rh

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.

Plotting Large Series of Points

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:

  • if you are plotting series of points, pass them as numpy arrays:
    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.

WIP

Errors while installing in Conda environment

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

PNGs lose axis

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.