def process_strut_torque(nrun, zero_torque=0.0, plot=False, covers=False,
                         verbose=False):
    """Processes a single strut torque run."""
    testplan = pd.read_csv("Config/Test plan/Strut-torque.csv",
                           index_col="run")
    ref_speed = testplan.ref_speed.iloc[nrun]
    tsr_nom = testplan.tsr.iloc[nrun]
    revs = testplan.revs.iloc[nrun]
    rpm_nom = tsr_nom*ref_speed/R/(2*np.pi)*60
    dur = revs/rpm_nom*60
    if covers:
        if verbose:
            print("Processing strut torque with covers run", nrun)
        nidata = loadhdf("Data/Raw/Strut-torque-covers/" + str(nrun) + \
                         "/nidata.h5")
    else:
        if verbose:
            print("Processing strut torque run", nrun)
        nidata = loadhdf("Data/Raw/Strut-torque/" + str(nrun) + "/nidata.h5")
    # Compute RPM
    time_ni  = nidata["time"]
    angle = nidata["turbine_angle"]
    rpm_ni = fdiff.second_order_diff(angle, time_ni)/6.0
    rpm_ni = ts.smooth(rpm_ni, 8)
    t1, t2 = 9, dur
    meanrpm, _ = ts.calcstats(rpm_ni, t1, t2, 2000)
    torque = nidata["torque_trans"]
    torque += calc_tare_torque(rpm_ni)
    meantorque, _ = ts.calcstats(torque, t1, t2, 2000)
    tsr_ref = meanrpm/60.0*2*np.pi*R/ref_speed
    if verbose:
        print("Reference TSR =", np.round(tsr_ref, decimals=4))
        print("Strut torque =", meantorque, "Nm at", meanrpm, "RPM")
    if plot:
        plt.figure()
        plt.plot(time_ni, torque)
        plt.xlabel("Time (s)")
        plt.ylabel("Torque (Nm)")
        plt.tight_layout()
        plt.show()
    meantorque -= zero_torque
    ct = meantorque/(0.5*rho*A*R*ref_speed**2)
    cp = ct*tsr_ref
    summary = pd.Series()
    summary["run"] = nrun
    summary["tsr_ref"] = tsr_ref
    summary["cp"] = cp
    summary["mean_torque"] = meantorque
    summary["mean_rpm"] = meanrpm
    return summary
示例#2
0
文件: tests.py 项目: whmrtm/daqmx
def test_task_autologging(filetype=".csv", duration=3):
    import time
    import matplotlib.pyplot as plt
    from pxl import timeseries

    print("Testing autologging to", filetype)
    task = daqmx.tasks.Task()
    c = daqmx.channels.AnalogInputVoltageChannel()
    c.physical_channel = "Dev1/ai0"
    c.name = "analog input 0"
    task.add_channel(c)
    c2 = daqmx.channels.AnalogInputVoltageChannel()
    c2.physical_channel = "Dev1/ai1"
    c2.name = "analog input 1"
    task.add_channel(c2)
    task.setup_autologging("test" + filetype, newfile=True)
    task.start()
    time.sleep(duration)
    task.stop()
    task.clear()
    if filetype == ".csv":
        data = pd.read_csv("test" + filetype)
    else:
        data = timeseries.loadhdf("test" + filetype)
    plt.plot(data["time"], data["analog input 0"])
    plt.plot(data["time"], data["analog input 1"])
    print("Deleting test CSV")
    os.remove("test.csv")
示例#3
0
文件: tests.py 项目: whmrtm/daqmx
def test_task_autologging(filetype=".csv", duration=3):
    import time
    import matplotlib.pyplot as plt
    from pxl import timeseries
    print("Testing autologging to", filetype)
    task = daqmx.tasks.Task()
    c = daqmx.channels.AnalogInputVoltageChannel()
    c.physical_channel = "Dev1/ai0"
    c.name = "analog input 0"
    task.add_channel(c)
    c2 = daqmx.channels.AnalogInputVoltageChannel()
    c2.physical_channel = "Dev1/ai1"
    c2.name = "analog input 1"
    task.add_channel(c2)
    task.setup_autologging("test" + filetype, newfile=True)
    task.start()
    time.sleep(duration)
    task.stop()
    task.clear()
    if filetype == ".csv":
        data = pd.read_csv("test" + filetype)
    else:
        data = timeseries.loadhdf("test" + filetype)
    plt.plot(data["time"], data["analog input 0"])
    plt.plot(data["time"], data["analog input 1"])
    print("Deleting test CSV")
    os.remove("test.csv")
def process_tare_torque(nrun, plot=False):
    """Processes a single tare torque run."""
    print("Processing tare torque run", nrun)
    times = {0 : (35, 86),
             1 : (12, 52),
             2 : (11, 32),
             3 : (7, 30)}
    nidata = loadhdf("Data/Raw/Tare-torque/" + str(nrun) + "/nidata.h5")
    # Compute RPM
    time_ni  = nidata["time"]
    angle = nidata["turbine_angle"]
    rpm_ni = fdiff.second_order_diff(angle, time_ni)/6.0
    rpm_ni = ts.smooth(rpm_ni, 8)
    try:
        t1, t2 = times[nrun]
    except KeyError:
        t1, t2 = times[3]
    meanrpm, _ = ts.calcstats(rpm_ni, t1, t2, 2000)
    torque = nidata["torque_trans"]
    meantorque, _ = ts.calcstats(torque, t1, t2, 2000)
    print("Tare torque =", meantorque, "Nm at", meanrpm, "RPM")
    if plot:
        plt.figure()
        plt.plot(time_ni, torque)
        plt.xlabel("Time (s)")
        plt.ylabel("Torque (Nm)")
        plt.tight_layout()
        plt.show()
    return meanrpm, -meantorque
def process_tare_drag(nrun, plot=False):
    """Processes a single tare drag run."""
    print("Processing tare drag run", nrun)
    times = {0.2: (15, 120),
             0.3: (10, 77),
             0.4: (10, 56),
             0.5: (8, 47),
             0.6: (10, 40),
             0.7: (8, 33),
             0.8: (5, 31),
             0.9: (8, 27),
             1.0: (6, 24),
             1.1: (9, 22),
             1.2: (8, 21),
             1.3: (7, 19),
             1.4: (6, 18)}
    rdpath = os.path.join(raw_data_dir, "Tare-drag", str(nrun))
    with open(os.path.join(rdpath, "metadata.json")) as f:
        metadata = json.load(f)
    speed = float(metadata["Tow speed (m/s)"])
    nidata = loadhdf(os.path.join(rdpath, "nidata.h5"))
    time_ni  = nidata["time"]
    drag = nidata["drag_left"] + nidata["drag_right"]
    drag = drag - np.mean(drag[:2000])
    t1, t2 = times[speed]
    meandrag, x = ts.calcstats(drag, t1, t2, 2000)
    print("Tare drag =", meandrag, "N at", speed, "m/s")
    if plot:
        plt.figure()
        plt.plot(time_ni, drag, 'k')
        plt.show()
    return speed, meandrag
 def load_acsdata(self):
     fpath = os.path.join(self.raw_dir, "acsdata.h5")
     acsdata = loadhdf(fpath)
     self.tow_speed_acs = acsdata["carriage_vel"]
     self.rpm_acs = acsdata["turbine_rpm"]
     self.rpm_acs = ts.sigmafilter(self.rpm_acs, 3, 3)
     self.omega_acs = self.rpm_acs*2*np.pi/60.0
     self.time_acs = acsdata["time"]
     if len(self.time_acs) != len(self.omega_acs):
         newlen = np.min((len(self.time_acs), len(self.omega_acs)))
         self.time_acs = self.time_acs[:newlen]
         self.omega_acs = self.omega_acs[:newlen]
     self.omega_acs_interp = np.interp(self.time_ni, self.time_acs, self.omega_acs)
     self.rpm_acs_interp = self.omega_acs_interp*60.0/(2*np.pi)
 def load_nidata(self):
     nidata = loadhdf(os.path.join(self.raw_dir, "nidata.h5"))
     self.time_ni = nidata["time"]
     self.sr_ni = (1.0/(self.time_ni[1] - self.time_ni[0]))
     self.carriage_pos = nidata["carriage_pos"]
     self.tow_speed_ni = fdiff.second_order_diff(self.carriage_pos, self.time_ni)
     self.tow_speed_ni = ts.smooth(self.tow_speed_ni, 100)
     self.tow_speed_ref = self.tow_speed_ni.copy()
     self.tow_speed_ref[np.abs(self.tow_speed_ref) < 0.01] = np.nan
     self.torque = nidata["torque_trans"]
     self.torque_arm = nidata["torque_arm"]
     self.drag = nidata["drag_left"] + nidata["drag_right"]
     # Remove offsets from drag, not torque
     t0 = 2
     self.drag = self.drag - np.mean(self.drag[0:self.sr_ni*t0])
     # Compute RPM and omega
     self.angle = nidata["turbine_angle"]
     self.rpm_ni = fdiff.second_order_diff(self.angle, self.time_ni)/6.0
     self.rpm_ni = ts.smooth(self.rpm_ni, 8)
     self.omega_ni = self.rpm_ni*2*np.pi/60.0
     self.omega = self.omega_ni
     self.tow_speed = self.tow_speed_ref