def test_tolerance(rate): labtime.set_rate(rate) for _ in clock(1, tol=0.25): labtime.sleep(1.2) for t in clock(5, 1, tol=0.25): if 0.5 < t < 2.5: labtime.sleep(1.1) assert round(t) == 5.0
Q[630:] = 60.0 Q[800:] = 0.0 # Create linear interpolation of the data versus time Qf = interp1d(t, Q) ############################################################################### # MEASURE DATA ############################################################################### try: df = pd.read_csv('tclab_data.csv') except FileNotFoundError: with tclab.TCLab() as lab: h = tclab.Historian(lab.sources) for i in tclab.clock(t_heat - 1, step=1, tol=0.5): lab.Q1(Q[int(i)]) h.update(i) print(f"Time: {i:.0f} sec") df = pd.DataFrame(h.log, columns=h.columns) df.to_csv('tclab_data.csv') y = df.T1 ############################################################################### # INITIAL CONDITIONS ############################################################################### Tss = 23 # degrees celcius y0 = [Tss]
def test_tstep(rate): labtime.set_rate(rate) print([_ for _ in clock(4, 2)]) assert [round(_) for _ in clock(4, 2)] == [0, 2, 4]
def test_generator(rate): labtime.set_rate(rate) assert [round(_) for _ in clock(3)] == [0, 1, 2, 3]
t_heat = 300 # seconds # Simulation time t = np.linspace(0, t_heat, t_heat * 10) ############################################################################### # MEASURE DATA ############################################################################### try: df = pd.read_csv('data.csv') except FileNotFoundError: with tclab.TCLab() as lab: h = tclab.Historian(lab.sources) for i in tclab.clock(t_heat): lab.Q1(Q_INPUT) h.update(i) print("Time:", i, 'seconds') df = pd.DataFrame(h.log, columns=h.columns) df.to_csv('data.csv') ############################################################################### # VARIABLES ############################################################################### Ta = 21.5 # deg C U = 5 # W/m^2-K A = 0.0012 # m^2 TaK = Ta + 273.15 # deg K ε = 0.9 # no units
t_heat = 300 # seconds # Simulation time t = np.linspace(0, t_heat, t_heat * 10) ############################################################################### # MEASURE DATA ############################################################################### try: df = pd.read_csv('data.csv') except FileNotFoundError: with tclab.TCLab() as lab: h = tclab.Historian(lab.sources) for t in tclab.clock(t_heat): lab.Q1(50) h.update(t) print("Time:", t, 'seconds') df = pd.DataFrame(h.log, columns=h.columns) df.to_csv('data.csv') ############################################################################### # VARIABLES ############################################################################### Ta = 21.5 # deg C U = 5 # W/m^2-K A = 0.0012 # m^2 TaK = Ta + 273.15 # deg K ε = 0.9 # no units