coniston/daily_plots.py

66 lines
2.9 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
# Load the data (assuming you've already loaded and processed it as shown)
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)'])
# Set the datetime column as the index
data.set_index('Date/Time (--4:0:0)', inplace=True)
# 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()
# Ensure index is a datetime index for ease of filtering
data.index = pd.to_datetime(data.index)
# Loop through each calendar day and create separate plots
for day in pd.Index(data.index.date).unique():
# Filter data for the current day
day_data = data[data.index.date == day]
# Create the plot for the current day
fig = go.Figure()
fig.add_trace(go.Scatter(x=day_data.index, 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')))
2024-07-07 18:53:08 -04:00
fig.add_trace(go.Scatter(x=day_data.index, 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')))
2024-07-07 18:53:08 -04:00
fig.add_trace(go.Scatter(x=day_data.index, 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')))
2024-07-07 18:53:08 -04:00
fig.add_trace(go.Scatter(x=day_data.index, 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')))
2024-07-07 18:53:08 -04:00
fig.update_layout(
title=dict(
text=f'Temperature at Inlets and Outlets of the Heat Exchanger - {day}',
font=dict(size=20, family='Arial', color='black', weight='bold')
),
xaxis_title=dict(
text='Date/Time',
font=dict(size=18, family='Arial', color='black', weight='bold')
),
yaxis_title=dict(
text='Temperature (F)',
font=dict(size=18, family='Arial', color='black', weight='bold'),
),
legend=dict(
title=dict(font=dict(size=15, family='Arial', color='black', weight='bold')),
font=dict(size=14, family='Arial', color='black', weight='bold')
),
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_without_Q_{day}.png')
2024-07-07 18:53:08 -04:00