Psychrometrics - Calculate Dry bulb from Web bulb and Relative Humidity

Hi All -

I have a case where I have relative humidity and wet bulb and would like to calculate dry bulb temp. Is this flexibility available with the “LB Humidity Metrics” component? It looks like dry bulb is required as an input.

image

Anyone aware of a flexible gh component that would do this? Looks like the code is available, but not written into the “LB Humidity Metrics” component.

https://www.ladybug.tools/ladybug/docs/ladybug.psychrometrics.html#ladybug.psychrometrics.enthalpy_from_db_hr

At it’s simplest you can do this. There’s definitely a better way if you want to to work with data collections, but I’m guessing this will be good enough

from ladybug.psychrometrics import db_temp_and_hr_from_wb_rh

_pressure_ = 101325

DBT, HR = db_temp_and_hr_from_wb_rh(WB,RH,_pressure_)

3 Likes

Really nice, @charlie.brooker ! You’re becoming the community’s unofficial master of custom SDK components.

FYI, for making a component that works well for data collections, I recommend using the compute_function_aligned method, which can be accessed on any data collection class. Here’s a sample:

from ladybug.psychrometrics import db_temp_and_hr_from_wb_rh
from ladybug.datacollection import HourlyContinuousCollection
from ladybug.datatype.temperature import DryBulbTemperature

_pressure_ = 101325

dbt = HourlyContinuousCollection.compute_function_aligned(
        db_temp_and_hr_from_wb_rh, [wb, rh, _pressure_],
        DryBulbTemperature(), 'C')

That method will automatically work with both data collection inputs or single numerical inputs.

2 Likes

Thanks @charlie.brooker and @chris!

To learn how to create a custom LBT component myself, I tried to recreate these custom components. I dropped GhPython onto canvas and copy and pasted the code Chris provided into the component.

When I run “test” (upper right button in editor), I get an error that wet bulb, “wb” is not defined. Besides using “GhPython Script” component, did you do any other prep to to get the component to run?

I see your component transformed to show the new inputs and outputs, does this happen automatically once component runs or did you enable this somehow?

Hey @victorbrac, if you right click on x, y, a on the component you can change the names of the inputs/outputs to what you want them to be, eg wb, and match them up with the variables you use in your python script.

@chris, thanks! I’m finding helping on the forum is at least maintaining my bit of python knowledge and teaching me more about all the methods you and the team have put together :slight_smile:

2 Likes

Hi @chris -

I replicated your component and while the output shows as a data collection (dbt) in panel, it is not accepted by hourly plot and the values are not correct. Is this a user error or component issue?

Reference Snip - I boxed the output from the custom component

my gh script replicating what you did
calc_dbt.gh (23.1 KB)

Sidenote,

How do you guys nicely format the code when you post on discourse? It doesn’t look like a snip since I was able to select the text and paste into a gh component.

Example - Nicely Formatted

Example - Copy and Pasted From Component
from ladybug.psychrometrics import db_temp_and_hr_from_wb_rh
from ladybug.datacollection import HourlyContinuousCollection
from ladybug.datatype.temperature import DryBulbTemperature

pressure = 101325

dbt = HourlyContinuousCollection.compute_function_aligned(
db_temp_and_hr_from_wb_rh, [wb, rh, pressure],
DryBulbTemperature(), ‘C’)

Interesting, the output of that psychrometric method is the only method that returns a tuple, and that’s what’s being shown in GH where deconstructing the data collection is giving a list of (x, y) instead of just x.

I think this bit of code needs to be tweaked slightly. Although as it’s the only method that returns a tuple I do wonder if this is a bug, @chris will be able to confirm (it might make perfect sense in terms of psychrometrics, I don’t often use them).

Not at my laptop atm but I think this might do it (although I’m definitely doubting it!)

dbt = HourlyContinuousCollection.compute_function_aligned(
        db_temp_and_hr_from_wb_rh[0], [wb, rh, _pressure_],
        DryBulbTemperature(), 'C')

Ahh, I should have looked more closely at that db_temp_and_hr_from_wb_rh function before I posted my sample as the docs clearly say that it returns two values the dry bulb temperature and the humidity ratio. Or I could have just read the name of of the function correctly since both metrics appear there :man_facepalming: .

In any event, the fastest way to get the component working correctly is to just overwrite the values of the data collection like so:

from ladybug.psychrometrics import db_temp_and_hr_from_wb_rh
from ladybug.datacollection import HourlyContinuousCollection
from ladybug.datatype.temperature import DryBulbTemperature

pressure = 101325 if _p_ is None else _p_

dbt = HourlyContinuousCollection.compute_function_aligned(
        db_temp_and_hr_from_wb_rh, [wb, rh, pressure],
        DryBulbTemperature(), 'C')
dbt.values = [val[0] for val in dbt.values]


calc_dbt.gh (27.5 KB)

Now that I see it all, I can also sense that the psychrometric functions have a bit of an error in really hot conditions around 40C and I imagine that these AHRAE Handbook formulas weren’t really built to handle the major extremes.

Still, everything under 30C seems to have an error that’s less than 1C.

1 Like