import panel as pn import plotly.graph_objs as go import plotly.express as px from plotly.subplots import make_subplots from consts import ( INVERTER_ID_MAPPING, CURRENT, IRRADIANCE, VOLTAGE, POWER_DC, POWER_AC, T_AMBIENT, T_MODULE, T_HEATSINK, T_CPU, T_BOARD, ) def create_iv_plot(df, inverter_ids): """# Helper function to create a line plot with secondary y-axis""" print("Selected Inverter Ids: {}".format(inverter_ids)) fig = make_subplots( rows=2, cols=1, shared_xaxes=True, vertical_spacing=0.01, specs=[[{"secondary_y": True}], [{}]], ) for inverter in inverter_ids: inv_id = INVERTER_ID_MAPPING[inverter] print("Creating plot for inv_id: {}".format(inv_id)) inv_data = df[str(inv_id)] print(inv_data.head()) print(inv_data.columns) print(f"df columns {df.columns}") # Graph 1: DC current and G-POA (Twin Y-Axis) fig.add_trace( go.Scatter( x=inv_data.index, y=inv_data[CURRENT], mode="lines", name=f"{CURRENT}-{inv_id}", ), row=1, col=1, secondary_y=False, ) fig.add_trace( go.Scatter( x=inv_data.index, y=inv_data[IRRADIANCE], mode="lines", name=f"{IRRADIANCE}-{inv_id}", ), row=1, col=1, secondary_y=True, ) # Graph 2: Voltage fig.add_trace( go.Scatter( x=inv_data.index, y=inv_data[VOLTAGE], mode="lines", name=f"{VOLTAGE}-{inv_id}", ), row=2, col=1, ) # Update axis labels fig.update_yaxes(title_text="Current (A)", row=1, col=1) fig.update_yaxes(title_text="Irradiance (W/m2)", row=1, col=1, secondary_y=True) fig.update_yaxes(title_text="Voltage (V)", row=2, col=1) fig.update_xaxes(title_text="Datetime", row=2, col=1) # Update layout to add titles and adjust axis labels fig.update_layout(title_text="IV Plots", height=1000, width=1600) return fig def create_iv_plot_with_power_curves(df, inverter_ids): """# Helper function to create a line plot with secondary y-axis""" print("Selected Inverter Ids: {}".format(inverter_ids)) fig = make_subplots( rows=3, cols=1, shared_xaxes=True, vertical_spacing=0.01, specs=[[{"secondary_y": True}], [{}], [{}]], ) for inverter in inverter_ids: inv_id = INVERTER_ID_MAPPING[inverter] print("Creating plot for inv_id: {}".format(inv_id)) inv_data = df[str(inv_id)] # Graph 1: DC current and G-POA (Twin Y-Axis) fig.add_trace( go.Scatter( x=inv_data.index, y=inv_data[CURRENT], mode="lines", name=f"{CURRENT}-{inv_id}", ), row=1, col=1, secondary_y=False, ) fig.add_trace( go.Scatter( x=inv_data.index, y=inv_data[IRRADIANCE], mode="lines", name=f"{IRRADIANCE}-{inv_id}", ), row=1, col=1, secondary_y=True, ) # Graph 2: Voltage fig.add_trace( go.Scatter( x=inv_data.index, y=inv_data[VOLTAGE], mode="lines", name=f"{VOLTAGE}-{inv_id}", ), row=2, col=1, ) # Graph 3: P-dc and P-ac fig.add_trace( go.Scatter( x=inv_data.index, y=inv_data[POWER_DC], mode="lines", name=f"{POWER_DC}-{inv_id}", ), row=3, col=1, ) fig.add_trace( go.Scatter( x=inv_data.index, y=inv_data[POWER_AC], mode="lines", name=f"{POWER_AC}-{inv_id}", ), row=3, col=1, ) # Update axis labels fig.update_yaxes(title_text="Current (A)", row=1, col=1) fig.update_yaxes(title_text="Irradiance (W/m2)", row=1, col=1, secondary_y=True) fig.update_yaxes(title_text="Voltage (V)", row=2, col=1) fig.update_yaxes(title_text="P-dc & P-ac (W)", row=3, col=1) fig.update_xaxes(title_text="Datetime", row=3, col=1) # Update layout to add titles fig.update_layout(title_text="IV Plot with Power Curves", height=1000, width=1600) return fig def create_iv_plot_with_power_and_temperature_curves(df, df2, inverter_ids): # Create the specs for subplots print("Selected Inverter Ids: {}".format(inverter_ids)) fig = make_subplots( rows=4, cols=1, shared_xaxes=True, vertical_spacing=0.01, specs=[[{"secondary_y": True}], [{}], [{}], [{}]], ) for inverter in inverter_ids: inv_id = INVERTER_ID_MAPPING[inverter] print("Creating plot for inv_id: {}".format(inv_id)) inv_data = df[str(inv_id)] temperature_data = df2[df2["Inv"] == inv_id] # Graph 1: DC current and G-POA (Twin Y-Axis) fig.add_trace( go.Scatter( x=inv_data.index, y=inv_data[CURRENT], mode="lines", name=f"{CURRENT}-{inv_id}", ), row=1, col=1, secondary_y=False, ) fig.add_trace( go.Scatter( x=inv_data.index, y=inv_data[IRRADIANCE], mode="lines", name=f"{IRRADIANCE}-{inv_id}", ), row=1, col=1, secondary_y=True, ) # Graph 2: Voltage fig.add_trace( go.Scatter( x=inv_data.index, y=inv_data[VOLTAGE], mode="lines", name=f"{VOLTAGE}-{inv_id}", ), row=2, col=1, ) # Graph 3: P-dc and P-ac fig.add_trace( go.Scatter( x=inv_data.index, y=inv_data[POWER_DC], mode="lines", name=f"{POWER_DC}-{inv_id}", ), row=3, col=1, ) fig.add_trace( go.Scatter( x=inv_data.index, y=inv_data[POWER_AC], mode="lines", name=f"{POWER_AC}-{inv_id}", ), row=3, col=1, ) # Graph 4: T-amb, T-mod, T-heatsink, T-CPU and T-board fig.add_trace( go.Scatter( x=temperature_data.index, y=temperature_data[T_AMBIENT], name=f"{T_AMBIENT}-{inv_id}", ), row=4, col=1, ) fig.add_trace( go.Scatter( x=inv_data.index, y=inv_data[T_MODULE], name=f"{T_MODULE}-{inv_id}" ), row=4, col=1, ) fig.add_trace( go.Scatter( x=temperature_data.index, y=temperature_data[T_HEATSINK], name=f"{T_HEATSINK}-{inv_id}", ), row=4, col=1, ) fig.add_trace( go.Scatter( x=temperature_data.index, y=temperature_data[T_CPU], name=f"{T_CPU}-{inv_id}", ), row=4, col=1, ) fig.add_trace( go.Scatter( x=temperature_data.index, y=temperature_data[T_BOARD], name=f"{T_BOARD}-{inv_id}", ), row=4, col=1, ) # Update axis labels fig.update_yaxes(title_text="Current (A)", row=1, col=1) fig.update_yaxes(title_text="Irradiance (W/m2)", row=1, col=1, secondary_y=True) fig.update_yaxes(title_text="Voltage (V)", row=2, col=1) fig.update_yaxes(title_text="P-dc & P-ac (W)", row=3, col=1) fig.update_xaxes(title_text="Datetime", row=4, col=1) fig.update_yaxes(title_text="Temperature (°C)", row=4, col=1) # Update layout to add titles fig.update_layout( title_text="IV Plots with Power and Temperature", height=1000, width=1600 ) return pn.pane.Plotly(fig) def create_iv_plot_with_temperature_curves(df, df2, inverter_ids): # Create the specs for subplots print("Selected Inverter Ids: {}".format(inverter_ids)) fig = make_subplots( rows=3, cols=1, shared_xaxes=True, vertical_spacing=0.01, specs=[[{"secondary_y": True}], [{}], [{}]], ) for inverter in inverter_ids: inv_id = INVERTER_ID_MAPPING[inverter] print("Creating plot for inv_id: {}".format(inv_id)) inv_data = df[str(inv_id)] temperature_data = df2[df2["Inv"] == inv_id] # Graph 1: DC current and G-POA (Twin Y-Axis) fig.add_trace( go.Scatter( x=inv_data.index, y=inv_data[CURRENT], mode="lines", name=f"{CURRENT}-{inv_id}", ), row=1, col=1, secondary_y=False, ) fig.add_trace( go.Scatter( x=inv_data.index, y=inv_data[IRRADIANCE], mode="lines", name=f"{IRRADIANCE}-{inv_id}", ), row=1, col=1, secondary_y=True, ) # Graph 2: Voltage fig.add_trace( go.Scatter( x=inv_data.index, y=inv_data[VOLTAGE], mode="lines", name=f"{VOLTAGE}-{inv_id}", ), row=2, col=1, ) # Graph 4: T-amb, T-mod, T-heatsink, T-CPU and T-board fig.add_trace( go.Scatter( x=temperature_data.index, y=temperature_data[T_AMBIENT], name=f"{T_AMBIENT}-{inv_id}", ), row=3, col=1, ) fig.add_trace( go.Scatter( x=inv_data.index, y=inv_data[T_MODULE], name=f"{T_MODULE}-{inv_id}" ), row=3, col=1, ) fig.add_trace( go.Scatter( x=temperature_data.index, y=temperature_data[T_HEATSINK], name=f"{T_HEATSINK}-{inv_id}", ), row=3, col=1, ) fig.add_trace( go.Scatter( x=temperature_data.index, y=temperature_data[T_CPU], name=f"{T_CPU}-{inv_id}", ), row=3, col=1, ) fig.add_trace( go.Scatter( x=temperature_data.index, y=temperature_data[T_BOARD], name=f"{T_BOARD}-{inv_id}", ), row=3, col=1, ) # Update axis labels fig.update_yaxes(title_text="Current (A)", row=1, col=1) fig.update_yaxes(title_text="Irradiance (W/m2)", row=1, col=1, secondary_y=True) fig.update_yaxes(title_text="Voltage (V)", row=2, col=1) fig.update_xaxes(title_text="Datetime", row=3, col=1) fig.update_yaxes(title_text="Temperature (°C)", row=3, col=1) # Update layout to add titles fig.update_layout(title_text="IV Plots with Temperature", height=1000, width=1600) return pn.pane.Plotly(fig) def create_heatmap(df, title): fig = px.imshow(df.transpose(), aspect="auto", title=title) fig.update_layout(height=800, width=1600) return pn.pane.Plotly(fig)