Friday, August 7, 2026

Nice_Code

                                                                                       


The Python Code:

import matplotlib.pyplot as plt
from matplotlib.widgets import Slider
import numpy as np


def wet_bulb_stull(T, RH):
term1 = T * np.arctan(0.151977 * (RH + 8.313659) ** 0.5)
term2 = np.arctan(T + RH)
term3 = np.arctan(RH - 1.676331)
term4 = 0.00391838 * (RH**1.5) * np.arctan(0.023101 * RH)
return term1 + term2 - term3 + term4 - 4.686035


# Grid setup for background contours
T_vals = np.linspace(20, 45, 200)
RH_vals = np.linspace(10, 100, 200)
T_grid, RH_grid = np.meshgrid(T_vals, RH_vals)
Tw_grid = wet_bulb_stull(T_grid, RH_grid)

fig, ax = plt.subplots(figsize=(10, 7))
plt.subplots_adjust(bottom=0.25)

levels = [0, 24, 28, 31, 50]
colors = ['#a8e6cf', '#dcedc1', '#ffd3b6', '#ffaaa5']
cs = ax.contourf(
RH_grid, T_grid, Tw_grid, levels=levels, colors=colors, alpha=0.85, extend='max'
)

cbar = fig.colorbar(cs, ax=ax)
cbar.set_label('Wet-Bulb Temperature (°C)')

# Initial point representing the single unique point
init_T = 24.0
init_RH = 89.0
point = ax.scatter(
[init_RH], [init_T], color='blue', s=120, zorder=5, label='Unique Point'
)

ax.set_xlabel('Relative Humidity (%)', fontsize=12)
ax.set_ylabel('Dry-Bulb Temperature (°C)', fontsize=12)
ax.set_title(
'Interactive Heat Stress Visualizer', fontsize=14, fontweight='bold'
)
ax.legend(loc='upper left')
ax.grid(True, linestyle='--', alpha=0.5)

# Setup Slider axes for Temperature and Humidity simultaneously on the same display
ax_temp = plt.axes([0.25, 0.1, 0.65, 0.03])
ax_rh = plt.axes([0.25, 0.05, 0.65, 0.03])

s_temp = Slider(ax_temp, 'Temp (°C)', 20.0, 45.0, valinit=init_T, valstep=0.5)
s_rh = Slider(ax_rh, 'Humidity (%)', 10.0, 100.0, valinit=init_RH, valstep=1.0)


# Unified update function moving the unique point from either slider change
def update(val):
t = s_temp.val
rh = s_rh.val
point.set_offsets([[rh, t]])
tw = wet_bulb_stull(t, rh)
ax.set_title(
f'Interactive Heat Stress Visualizer (Wet-Bulb: {tw:.1f}°C)',
fontsize=14,
fontweight='bold',
)
fig.canvas.draw_idle()


s_temp.on_changed(update)
s_rh.on_changed(update)

plt.show()

I am running this in PyCharm. The code is the work of Gemini AI!!

                                                                *     *     *

I copied the code to Notepad, saved it with a .py extension and now it opens like any other

shortcut on my dektop: with a double-click!

                                                   


                           

No comments: