ladybug-tools / ladybug

🐞 Core ladybug library for weather data analysis and visualization
https://www.ladybug.tools/ladybug/docs/
GNU Affero General Public License v3.0
192 stars 54 forks source link

Ladybug-Psychrometric Chart Enthalpy Units #131

Closed dradair closed 5 years ago

dradair commented 5 years ago

Have searched but not been able to find anyone asking about the IP units for enthalpy on the LB_Psychrometric Chart object. In the code the unit conversion appears correct / agrees with ASHRAE ( def kJkg2BTUlb(enthalpy): ). The issue is on the plot of the data the enthalpy units appear to be off by ~7-9 btu/lb when compared to standard charts. See attached image. At 45F and saturation, the enthalpy should be ~17.5btu/lb; not the 10btu/lb plotted. Similar at 70F & saturation, should have an enthalpy of 34 bu/lb; chart shows ~26 btu/lb. I've checked this against multiple psych charts, PsyChart software and Andrew Marsh's tool.

Theories: 1-I am using the Ladybug_CtoF on the temperature, but missing some other conversion. Pressure possibly? Is this needed? 2-I've found other images with same scale as show in image and there's something wrong with the programmed scale? 3-The conversion is (deceptively) not as straightforward as it seems. Thus, the conversion needs reprogrammed.

I am biased to ##3 with all the cross checks completed, but am concerned about the result regardless.

2019-04-15 GH-Ladybug-IP-Enthalpy Issue

chriswmackey commented 5 years ago

@dradair ,

This is likely not the right repository for this issue. If you are hoping to get something fixed in the legacy ladybug, you should be posting to this repository for legacy ladybug.

If you are posting about how we can better calculate enthalpy in the new version of ladybug that is currently being developed, issues about the psychrometric chart should go under the ladybug_comfort repository)[https://github.com/ladybug-tools/ladybug-comfort], though if it is specifically about the calculation of enthalpy and humidity metrics it could go here at this repository since the core functions that calculate humidity metrics from other humidity metrics live here. I am aware that there are a few things we can likely do to improve the accuracy of the enthaply calculation but they are not on the scale that you are suggesting here.

I am not able to understand what you mean. Looking at Andrew Marsh's chart, the location of enthalpy values on the chart it looks like it is in agreement with the image you post: image Enthalpy is ~10btu/lb at 45F and saturation.

dradair commented 5 years ago

@chriswmackey Sorry for confusion if I'm on the wrong repository; new to this. Based on the options you provided, and the core issue, it seems like if should live here rather than the comfort tool or new LadyBug. It will impact those other developments as well, but this appears to be a central issue. Am happy to move if this is not the right place; let me know.

The core issue is that the IP Psych Chart enthalpy doesnt align with ASHRAE-IP. I have also reached out to Andrew Marsh on this same issue. Per ASHRAE Fundamentals Chapter 1, Tdb=75F at saturation (rh=100% ' HR=0.0188), the enthalpy is 38.6 bth/lb. Both diagrams above indicate it would be closer to 30 btu/lb. Using the conversions on an epw and vba library from: https://github.com/psychrometrics/psychrolib align with ASHRAE's numbers & plots.

IP-Psych Chart-PsyChart.pdf

Am i missing a conversion step in LadyBug or...?

chriswmackey commented 5 years ago

@dradair ,

Thank you for the useful reference. The formulas in that python library are very well documented and I want to take a closer look at them. I see that the assumptions for some of the constants in the library are slightly different than ours.

For example, here is their code to calculate enthalpy from humidity ratio and dry bulb: https://github.com/psychrometrics/psychrolib/blob/master/src/python/psychrolib.py#L1100 And here is our code: https://github.com/ladybug-tools/ladybug/blob/master/ladybug/psychrometrics.py#L72

The two are very similar but there are slight differences in the constants used and I think this might lead to the discrepancy we see here.

I also noticed something odd, which is that, for enthalpy on our ladybug chart, we assume that air at the freezing point of water (0C or 32F) with a humidity ratio of 0 has an enthalpy of 0. This does not seem to be the case for the ASHRAE-endorsed way for calculating enthalpy and so I wonder what ASHRAE is using as their baseline at which there is 0 enthalpy. I'll also read up on the HoF to see if it mentions this there but, if you have any info with regards to this, that would be very helpful.

chriswmackey commented 5 years ago

Also, I will add that this actually is the best repo to have posed this question to. The other ones I listed might deal directly with the psychrometric chart but this issue is more about the underlying calculation method for enthalpy than it is about the visualization of the psych chart.

chriswmackey commented 5 years ago

Ok. I think I have found out what is going on. The two formulas for calculating enthaply actually agree with one another very well (even though the constants are ever-so-slightly different). The real reason for the discrepancy is that, apparently, there are very different definitions for a psychrometric enthalpy of 0 depending on whether you are in SI or IP

I realized that this formula in the psychrometrics python library could not have produced the enthalpy values in the chart that you linked to: MoistAirEnthalpy = (1.006 * TDryBulb + BoundedHumRatio * (2501. + 1.86 * TDryBulb)) * 1000 https://github.com/psychrometrics/psychrolib/blob/master/src/python/psychrolib.py#L1100 You can see very clearly that a TDryBulb of 0C and a BoundedHumRatio of 0 would yield an enthalpy of 0, which is not the case in your chart.

However, if you look at the IP equivalent formula it is: MoistAirEnthalpy = 0.240 * TDryBulb + BoundedHumRatio * (1061 + 0.444 * TDryBulb) https://github.com/psychrometrics/psychrolib/blob/master/src/python/psychrolib.py#L1098 ... meaning that you have an enthalpy of 0 when the temperature is 0F (not 32F) and a humidity ratio of 0.

So it seems this 0-point is arbitrarily defined and some people working in IP decided to set it at 0F while others decided to set it at 0C. I guess, if we really wanted to be impartial and in-sync with how thermodynamics defines enthalpy, it should be 0K but I realize this is somewhat impractical for psychrometrics. Given that the definition of 0 enthalpy is arbitrary, though, both the Ladybug and the ASHRAE charts can be seen as correct. So I am a bit disinclined to change the ladybug code unless the fact that we are out of sync with ASHRAE is creating some difficulties for your case and that of other users. Is there a particular workflow that is affected by the fact that the 0-enthalpy line is at 0Cfor you instead of 0F?

dradair commented 5 years ago

@chriswmackey Thank you for digging into this. I can confirm that the ASHRAE-IP uses 0F and 0 humidity ratio as the start point for their enthalpy scale. Sorry I could jump in to confirm this earlier.

The bigger question of does it impact workflows? Depends. In terms of enthalpy deltas, for load calculations, those are probably fine (unconfirmed). In terms of absolutes, it matters far more. If one goes to draw a line on the plot to look at hours above/below a certain level the analysis would be wrong. Example: 90.1 has limits for economizers tired to the enthlapy btu/h. The off-set caused by different starting point puts this line in the wrong place. This could really hurt. Graphically, for a presentation, a line could be overlaid or the scale numbers overwritten, but that doesnt fix the calc, just makes it 'pretty'. Now, do most people know a psych chart well enough to call one out in a presentation? no, probably not. But if the chart is used and it is compared to ASHRAE/Trane/any other standard IP Psych chart, it will appear incorrect. The other odd/funny part is that using the conversion factor from HoF Ch 39 of 2.3626 yields the LadyBug Chart - and not the Published ASHRAE-IP Chart. Which is...odd...

dradair commented 5 years ago

note- i dont necessarily like pointing out an issue/potential issue and not being able to help with some type of solution. I do not feel confident enough in my programming abilities to fork and guarantee any type of fix. Attempt? maybe. but 'for sure'...no. Rookie here in python world.

chriswmackey commented 5 years ago

@dradair ,

I can confirm for you that having the enthalpy start from 32F it will not affect calculations of enthalpy deltas since the SI and IP forms of the equations are the same. The fact that our coefficients are slightly different than ASHRAE's could cause some very minor differences but these are not significant.

You have a good case for making a change with the fact that 90.1 giving limits of "absolute" enthalpy starting form 0F (even though we have already determined that all psychrometric calculations of enthalpy are not absolute unless they start from absolute zero). How about this proposed compromise:

For now, we leave the Ladybug legacy chart as it is and, if you really need a chart with the enthalpy lines as they appear in ASHRAE, you can just edit these lines of the psych chart component here: https://github.com/mostaphaRoudsari/ladybug/blob/master/src/Ladybug_Psychrometric%20Chart.py#L717-L736 Basically, you would just replace the calcTempFromEnthalpy call with the formula that I posted in the previous post taken from the ASHRAE psychrometric library. You might also what to change the range of enthalpies generated (Maybe starting from 10 BTU/lb instead of 0)

When I develop the psych chart for Ladybug[+], which should be relatively soon, I will build in options within the API to set the zero_value of enthalpy to be whatever temperature you want (0C, 0F, or even 0K). With this, it will be easy to either set it to 0F by default when viewing data in IP or just expose the enthalpy 0 value as an input on the components.

Let me know if this sounds good.

dradair commented 5 years ago

@chriswmackey ; sorry for delay. This has become a topic of discussion within our mechanical technical leadership with this finding. One found a/the resource explaining it in "Understanding Psychrometrics" by Gatley. Have pasted the extracted section dealing with this SI-IP conversion and warnings associated with the conversion.

I'll play with coding & offset to see what makes the most sense for workflow. Glad to hear about Ladybug [+] development. Enthalpy SI IP.pdf

chriswmackey commented 5 years ago

@dradair ,

Sorry for an even longer delay. I just wanted to let you know that I have built the option into the ladybug core library to specify the reference temperature for enthalpy calculations: https://github.com/chriswmackey/ladybug/blob/development/ladybug/psychrometrics.py#L72-L82

This will allow us to produce the IP type of enthalpy that you have noted here.

chriswmackey commented 5 years ago

Also, @dradair , that psychrometric python library was extremely helpful. In the past, we were using psychrometric formulas from a bunch of different sources but I can now say that all of the psychrometric functions in the new ladybug core are using the most accurate versions of the ASHRAE 2017 Handbook formulas.

dradair commented 5 years ago

So, rookie question.... how are these changes deployed or rolled out? Uninstall / reinstall ladybug does not appear have the enthalpy fix and the switch for reference temperature included? or do I need to track down 'psychrometrics.py' on my machine to correct (where....?)? how is this main ladybug/ladybug repo different than the one mostaphaRoudsari/ladybug where these fixes live? Within Grasshopper, If i open PsychChart and replace/amend lines 134-142, i get the correct plot units (though other consequences are unknown yet....): def BTUlb2kJkg(enthalpy): newEnthalpy = [] for num in enthalpy: newEnthalpy.append((num-7.686)/0.429922614) return newEnthalpy

def kJkg2BTUlb(enthalpy): newEnthalpy = [] for num in enthalpy: newEnthalpy.append((num*0.429922614)+7.686) return newEnthalpy

If correct, should this be added to the main/master file?

chriswmackey commented 5 years ago

@dradair , I understand the confusion. This repo where you have posted this issue is for the new revision of ladybug that is currently WIP and does not yet have a psychrometric chart (just some simple psychrometric functions that will be used to make a chart in the coming months). If you want to suggest a change to the legacy ladybug, which houses the majority of components that people are still using, this is the repo you want to post on: https://github.com/mostaphaRoudsari/ladybug

I suggest that you record your proposed changes over there on that repo or, better yet, send a PR with them and we can merge them directly into the latest version of the legacy plugin. Seeing your changes in a PR will also allow me to see if there are any other issues the change will cause. Here is a video playlist that walks you through the basics of packaging your changes into a PR for that repo: https://www.youtube.com/watch?v=n_m5PDqv5pU&list=PLkjfDmSc5Orxq-f_fbmu_HV4tE2ZPIdaC

chriswmackey commented 5 years ago

Also, given that the groundwork has been laid here on the new ladybug repo to produce the proposed IP enthalpy units, I am going to close out this issue. We can continue further discussion on the legacy ladybug repo.