Assign colours to different temp ranges and plot sunrise and sunset on the hourly chart?

I’d like to be able to do a bit more with the standard dry bulb hourly chart. Is it possible to assign different colours to a range of temperatures for example? Is it possible to plot sunrise and sunset hours on the hourly chart?
I’m not sure if this can be approached with the ladybug components available, so I would appreciate any advice on how to approach this.
Thanks

Hi @Alapeace,

Try using this to categorise different temperature ranges to specific colours

To plot sunset and sunrise I don’t believe there’s a simple solution. I would get lists of all sunset, sunrise and days of year, then use remap domain to convert those numbers to the required x-y values and construct points from those, then interpolate a curve between the points and overlay that on the chart by moving the curve up slightly in the z axis

Hope that helps!

1 Like

Hi @charlie.brooker, thank you for getting back to me. :slight_smile:
Plotting the sunrise and sunset hours was definitely not a straightforward task.
Not an ideal solution but I ended up plotting the hours using the Monthly Chart and then rescaling it to match the Hourly Plot. For the hours I averaged each month to get a smooth curve because I only managed to extract the hours not minutes. It’s not accurate but at least they give the plot the context I was looking for. I can extend the edges in rhino later.

1 Like

Hey @Alapeace,

I wanted to give it a go myself now I’m back at my work laptop, here’s my attempt. I put together a python component to get the daily sunset and sunrise times using some LBT code that isn’t directly used in one of the components.

Sunset_Sunrise_Overlay.gh (54.2 KB)

I also had a go at categorising the data, but not particularly happy with the colour scheme and categories :slight_smile:

1 Like

And tweaking my screenshot settings to increase the sunset/sunrise line thickness

2 Likes

@chris, @mostapha while putting together a custom python component for this I noticed that sp.calculate_sunrise_sunset doesn’t pick up the daylight saving analysis period. I got around it by using the same approach as in the calculate_sun_from_date_time method, thought it was worth flagging.

from ladybug.sunpath import Sunpath
from ladybug.dt import DateTime
from datetime import date, timedelta

sp = Sunpath.from_location(_location, north_, dl_saving_)

start_date = date(2023, 1, 1)
end_date = date(2023, 12, 31)

delta = end_date - start_date

sunrise_times = []
sunset_times = []

for i in range(delta.days + 1):
    day = start_date + timedelta(days=i)
    month, day = day.month, day.day
    is_daylight_saving = sp.is_daylight_saving_hour(DateTime(month, day))
    rise_set = sp.calculate_sunrise_sunset(month, day, depression=0.5334, is_solar_time=False) # An angle in degrees indicating the additional period before/after the edge of the sun has passed the horizon where the sun is still considered up. For details see: https://github.com/ladybug-tools/ladybug/blob/d5b4741a9bb0f0eabc1a826f53d723b43276ed62/ladybug/sunpath.py
    
    sunrise = rise_set.get('sunrise') if not is_daylight_saving else rise_set.get('sunrise').add_hour(1)
    sunrise_times.append(sunrise.time)
    
    sunset = rise_set.get('sunset') if not is_daylight_saving else rise_set.get('sunset').add_hour(1)
    sunset_times.append(sunset.time)

sunset_day_fraction = []
sunrise_day_fraction = []

seconds_per_day = 24*60*60

for time in sunrise_times:
    dt = timedelta(hours = time.hour, minutes = time.minute)
    sunrise_day_fraction.append(dt.total_seconds()/seconds_per_day)

for time in sunset_times:
    dt = timedelta(hours = time.hour, minutes = time.minute)
    sunset_day_fraction.append(dt.total_seconds()/seconds_per_day)
3 Likes

Good job @charlie.brooker !I was thinking on creating a component myself, but this is better :slight_smile:
There is a component for this in LB legacy.
In HB_Radiance the imageless glare component sets grey color for all not daylight hours. It can be worth to have a look at it.
Thanks for sharing.
-A.

1 Like

Thanks for pointing this out, @charlie.brooker . You are right that this method was not accounting for the Sunpath’s daylight_saving_period and this is a bug since everything else on the sunpath accounts for it. I just pushed a fix and it should be available with the LB Versioner shortly:

And thanks again for making this component and the sample. This is a really good case for showcasing what can be done on the SDK layer with the GHPython component.

3 Likes