Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dirtviz prototype #5

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feature: add c_impedance plot
lfbsdev committed Apr 11, 2022
commit 3e1d2a2d2ee7508186e55719fb55ccc018730a1b
26 changes: 12 additions & 14 deletions data_processing/app.py
Original file line number Diff line number Diff line change
@@ -3,25 +3,23 @@

from dash import Dash, dcc, html
import plotly.express as px
from c_impedance import c_impedance_plot
import pandas as pd

app = Dash(__name__)

app.layout = html.Div(children=[

html.Main(children=[
html.Div(children=[
html.H1(children=['DirtViz']),
html.H3(children=['A soil-battery data dashboard made with Dash'])
]),
html.Div(className="flex", children=[
html.Div(id="graph1",className="flexItem"),
html.Div(id="graph2",className="flexItem"),
html.Div(id="graph3",className="flexItem"),
html.Div(id="graph4",className="flexItem"),
html.Div(id="graph5",className="flexItem"),
])
app.layout = html.Main(children=[
html.Div(children=[
html.H1(children=['DirtViz']),
html.H3(children=['A soil-battery data dashboard made with Dash'])
]),
html.Div(className="flex", children=[
html.Div(className="flexItem", children= [dcc.Graph(figure=c_impedance_plot())]),
html.Div(id="graph2",className="flexItem"),
html.Div(id="graph3",className="flexItem"),
html.Div(id="graph4",className="flexItem"),
html.Div(id="graph5",className="flexItem"),
])
])

if __name__ == '__main__':
107 changes: 38 additions & 69 deletions data_processing/c_impedance.py
Original file line number Diff line number Diff line change
@@ -1,74 +1,43 @@
#!/usr/bin/env python3
import matplotlib as mpl
mpl.use('Agg')
font= {'family': 'Arial',
'size': 7}
mpl.rc('font', **font)
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
import matplotlib.dates as md
import numpy as np
from pytz import timezone
import pandas as pd
from glob import glob
import arrow
import os
from pandas.plotting import register_matplotlib_converters
register_matplotlib_converters()

import plotly.graph_objects as go
from plotly.subplots import make_subplots
import pandas as pd

avgdata = [];
avgdata.append({'mcurrent':2.2,'mvoltage':1.38,'mpower':0.003})
avgdata.append({'mcurrent':3.2,'mvoltage':1.92,'mpower':0.006})
avgdata.append({'mcurrent':12.3,'mvoltage':15.7,'mpower':0.19})
avgdata.append({'mcurrent':14.8,'mvoltage':26.7,'mpower':0.4})
avgdata.append({'mcurrent':16.3,'mvoltage':39.3,'mpower':0.64})
avgdata.append({'mcurrent':17.1,'mvoltage':48,'mpower':0.82})
avgdata.append({'mcurrent':17.7,'mvoltage':58.7,'mpower':0.84})
avgdata.append({'mcurrent':18,'mvoltage':70,'mpower':1.06})
avgdata.append({'mcurrent':19,'mvoltage':86,'mpower':1.33})
avgdata.append({'mcurrent':20,'mvoltage':120,'mpower':2.4})
avgdata.append({'mcurrent':20,'mvoltage':176,'mpower':3.52})
avgdata = {
'mcurrent':[2.2, 3.2, 12.3, 14.8, 16.3, 17.1, 17.7, 18, 19, 20, 20],
'mvoltage':[1.38, 1.92, 15.7, 26.7, 39.3, 48, 58.7, 70, 86, 120, 176],
'mpower':[0.003, 0.006, 0.19, 0.4, 0.64, 0.82, 0.84, 1.06, 1.33, 2.4, 3.52],
'impedance':[68, 100, 1e3, 2e3, 3.3e3, 4.7e3, 6.8e3, 9.1e3, 15e3, 39e3, 82e3]
}
avgdata = pd.DataFrame(avgdata)
print(avgdata)

plt.close()

fig, (ax1, ax3) = plt.subplots(2,figsize=(4,2), sharex=True)

volt_color= 'tab:blue'
volt_style = 'solid'
amp_color = 'tab:red'
amp_style='dashed'
ax1.set_ylabel('Cell Voltage (mV)')
ax1.plot(avgdata.index, avgdata['mvoltage'], color=volt_color, ls=volt_style)
ax1.tick_params(axis='y', labelcolor=volt_color)
ax1.set_ylim(0, 200)

ax2 = ax1.twinx()
ax2.set_ylabel('Harvesting Current (μA)')
ax2.plot(avgdata.index, avgdata['mcurrent'], color=amp_color, ls=amp_style)
ax2.tick_params(axis='y', labelcolor=amp_color)
ax2.set_ylim(0,25)

ax1.tick_params(axis='x', which='both', length=0)
ax2.tick_params(axis='x', which='both', length=0)

ax1.grid(True)
ax1.legend(['voltage'], loc='lower right')
ax2.legend(['current'], loc='upper left')

ax3.set_ylabel("Power (uW)")
ax3.set_xlabel("Impedance ($\Omega$)")
ax3.grid(True)
ax3.set_ylim(0, 4)
ax3.plot(avgdata.index, avgdata['mpower'])
plt.xticks(np.arange(11), ['68', '100', '1k', '2k','3.3k','4.7k','6.8k','9.1k','15k','39k','82k'])

plt.tight_layout(pad=0.4, w_pad=0.5, h_pad=0.5)
plt.subplots_adjust(hspace=0.15)
plt.savefig('c_impedance.pdf')
plt.close()



def c_impedance_plot():
fig = make_subplots(rows=2, cols=1, shared_xaxes=True, vertical_spacing=0.1,
specs=[[{"secondary_y": True}], [{"secondary_y":False}]]
)

fig.add_trace(
go.Scatter(x=avgdata['impedance'], y=avgdata['mvoltage'], mode='lines', name='voltage'),
row=1, col=1,
secondary_y=False
)
fig.add_trace(
go.Scatter(x=avgdata['impedance'], y=avgdata['mcurrent'], mode='lines', name='current'),
row=1, col=1,
secondary_y=True
)
fig.add_trace(
go.Scatter(x=avgdata['impedance'], y=avgdata['mpower'], mode='lines', showlegend=False),
row=2, col=1
)

fig.update_xaxes(title={'text':"Impedance (Ω)"}, row=2, col=1)
fig.update_yaxes(title={'text':"Cell Voltage (mV)", 'standoff':5}, row=1,col=1, secondary_y=False)
fig.update_yaxes(title={'text':"Harvesting Current (μA)"}, row=1,col=1, secondary_y=True)
fig.update_yaxes(title={'text':"Power (uW)", 'standoff':20}, row=2, col=1)
fig.update_layout(height=500, width=700, title="Impedance Subplots",template='plotly_dark',
paper_bgcolor="#121212", plot_bgcolor="#121212"
)

return fig