coniston/double_y_daily.py

66 lines
3.5 KiB
Python
Raw Permalink Normal View History

2024-07-07 18:53:08 -04:00
import pandas as pd
import plotly.graph_objects as go
from plotly.subplots import make_subplots
2024-07-10 09:40:57 -04:00
# Load the data
2024-07-07 18:53:08 -04:00
data = pd.read_csv('06-25_07-07.csv')
# Convert 'Date/Time (--4:0:0)' column to datetime
data['Date/Time (--4:0:0)'] = pd.to_datetime(data['Date/Time (--4:0:0)'])
2024-07-10 09:40:57 -04:00
# Calculate the time difference between consecutive points in minutes
data['Time Diff (min)'] = data['Date/Time (--4:0:0)'].diff().dt.total_seconds() / 60
# Set flow rate and specific heat capacity
flow_rate_gpm = 10
density_water = 62.4 # lbm/ft^3
flow_rate_lbm_min = flow_rate_gpm * 0.133681 * density_water # Convert GPM to lbm/min
# Calculate Q (BTU)
cp_water = 1 # BTU/lbm°F
data['Delta T (F)'] = data['Sewer Water Out'] - data['Sewer Water In']
data['Q (BTU)'] = flow_rate_lbm_min * cp_water * data['Delta T (F)'] * data['Time Diff (min)']
2024-07-07 18:53:08 -04:00
# Apply a smoothing function (moving average)
window_size = 10
data['Sewer Water In Smooth'] = data['Sewer Water In'].rolling(window=window_size, center=True).mean()
data['Sewer Water Out Smooth'] = data['Sewer Water Out'].rolling(window=window_size, center=True).mean()
data['Return Air Smooth'] = data['Return Air'].rolling(window=window_size, center=True).mean()
data['Supply Air Smooth'] = data['Supply Air'].rolling(window=window_size, center=True).mean()
2024-07-10 09:40:57 -04:00
data['Q Smooth'] = data['Q (BTU)'].rolling(window=window_size, center=True).mean()
2024-07-07 18:53:08 -04:00
# Iterate through each calendar day and create separate plots
for day in pd.Index(data['Date/Time (--4:0:0)'].dt.date).unique():
# Filter data for the current day
day_data = data[data['Date/Time (--4:0:0)'].dt.date == day]
# Create subplot figure with secondary y-axis
fig = make_subplots(rows=1, cols=1, shared_xaxes=True, vertical_spacing=0.1,
subplot_titles=(f'Temperature at Inlets and Outlets of the Heat Exchanger and Transferred Heat - {day}',),
specs=[[{"secondary_y": True}]])
# Add traces for each line with spline smoothing and increased visibility
fig.add_trace(go.Scatter(x=day_data['Date/Time (--4:0:0)'], y=day_data['Sewer Water In Smooth'], mode='lines', name='Sewer Water In',
2024-07-10 09:40:57 -04:00
line=dict(shape='spline', color='blue', width=2, dash='solid')), secondary_y=False)
2024-07-07 18:53:08 -04:00
fig.add_trace(go.Scatter(x=day_data['Date/Time (--4:0:0)'], y=day_data['Sewer Water Out Smooth'], mode='lines', name='Sewer Water Out',
2024-07-10 09:40:57 -04:00
line=dict(shape='spline', color='red', width=2, dash='solid')), secondary_y=False)
2024-07-07 18:53:08 -04:00
fig.add_trace(go.Scatter(x=day_data['Date/Time (--4:0:0)'], y=day_data['Return Air Smooth'], mode='lines', name='Return Air',
2024-07-10 09:40:57 -04:00
line=dict(shape='spline', color='orange', width=2, dash='solid')), secondary_y=False)
2024-07-07 18:53:08 -04:00
fig.add_trace(go.Scatter(x=day_data['Date/Time (--4:0:0)'], y=day_data['Supply Air Smooth'], mode='lines', name='Supply Air',
2024-07-10 09:40:57 -04:00
line=dict(shape='spline', color='green', width=2, dash='solid')), secondary_y=False)
2024-07-07 18:53:08 -04:00
fig.add_trace(go.Scatter(x=day_data['Date/Time (--4:0:0)'], y=day_data['Q Smooth'], mode='lines', name='Transferred Heat (BTU/lb)',
2024-07-10 09:40:57 -04:00
line=dict(shape='spline', color='purple', width=2, dash='solid')), secondary_y=True)
2024-07-07 18:53:08 -04:00
# Update layout
fig.update_layout(
xaxis_title='Date/Time',
yaxis_title='Temperature (F)',
2024-07-10 09:40:57 -04:00
yaxis2_title='Transferred Heat (BTU/lb)',
2024-07-07 18:53:08 -04:00
legend_title_text='Legend',
font=dict(size=14),
width=1400,
height=800
)
# Save the plot (requires kaleido package)
2024-07-10 09:40:57 -04:00
fig.write_image(f'temperature_variations_with_q_{day}.png')