Example #1
0
 def load_nidata(self):
     nidata = loadmat(os.path.join(self.raw_dir, "nidata.mat"), squeeze_me=True)
     self.time_ni = nidata["t"]
     self.sr_ni = (1.0/(self.time_ni[1] - self.time_ni[0]))
     if "carriage_pos" in nidata:
         self.lin_enc = True
         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, 8)
         self.tow_speed_ref = self.tow_speed_ni
     else:
         self.lin_enc = False
         self.tow_speed_ref = self.tow_speed_nom
     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
Example #2
0
 def EveryNCallback_py(taskHandle, everyNsamplesEventType, nSamples, 
                       callbackData_ptr):
     """Function called every N samples"""
     callbackdata = daqmx.get_callbackdata_from_id(callbackData_ptr)
     data, npoints = daqmx.ReadAnalogF64(taskHandle, self.nsamps, 
             10.0, daqmx.Val_GroupByChannel, self.nsamps, 
             len(self.analogchans))
     callbackdata.extend(data.tolist())
     self.data["torque_trans"] = np.append(self.data["torque_trans"], 
                                           data[:,0], axis=0)
     self.data["torque_arm"] = np.append(self.data["torque_arm"], 
                                         data[:,1], axis=0)
     self.data["drag_left"] = np.append(self.data["drag_left"], 
                                         data[:,2], axis=0)
     self.data["drag_right"] = np.append(self.data["drag_right"], 
                                         data[:,3], axis=0)
     self.data["time"] = np.arange(len(self.data["torque_trans"]), 
                                dtype=float)/self.sr                                                
     carpos, cpoints = daqmx.ReadCounterF64(self.carpostask,
                                            self.nsamps, 10.0,
                                            self.nsamps)
     self.data["carriage_pos"] = np.append(self.data["carriage_pos"],
                                           carpos)  
     turbang, cpoints = daqmx.ReadCounterF64(self.turbangtask,
                                             self.nsamps, 10.0,
                                             self.nsamps)
     self.data["turbine_angle"] = np.append(self.data["turbine_angle"],
                                            turbang)
     self.data["turbine_rpm"] \
         = ts.smooth(fdiff.second_order_diff(self.data["turbine_angle"], 
                                   self.data["time"])/6.0, 8)
     return 0 # The function should return an integer
Example #3
0
def process_tare_torque(nrun, plot=False):
    """Process 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 calc_perf(theta_0=360,
              plot=False,
              verbose=True,
              inertial=False,
              export_csv=True):
    t, torque, drag = foampy.load_all_torque_drag()
    _t, theta, omega = foampy.load_theta_omega(t_interp=t)
    reached_theta_0 = True
    if theta.max() < theta_0:
        theta_0 = 1
        reached_theta_0 = False
    # Compute tip speed ratio
    tsr = omega * R / U_infty
    # Compute mean TSR
    meantsr = np.mean(tsr[theta >= theta_0])
    if inertial:
        inertia = 3  # guess from SolidWorks model
        inertial_torque = inertia * fdiff.second_order_diff(omega, t)
        torque -= inertial_torque
    # Compute power coefficient
    power = torque * omega
    cp = power / (0.5 * rho * area * U_infty**3)
    meancp = np.mean(cp[theta >= theta_0])
    # Compute drag coefficient
    cd = drag / (0.5 * rho * area * U_infty**2)
    meancd = np.mean(cd[theta >= theta_0])
    if export_csv:
        df = pd.DataFrame()
        df["theta_deg"] = theta
        df["tsr"] = tsr
        df["cp"] = cp
        df["cd"] = cd
        df.to_csv("processed/perf.csv", index=False)
    if verbose:
        print("Performance from {:.1f}--{:.1f} degrees:".format(
            theta_0, theta.max()))
        print("Mean TSR = {:.3f}".format(meantsr))
        print("Mean C_P = {:.3f}".format(meancp))
        print("Mean C_D = {:.3f}".format(meancd))
    if plot:
        plt.close('all')
        plt.plot(theta[5:], cp[5:])
        plt.title(r"$\lambda = %1.1f$" % meantsr)
        plt.xlabel(r"$\theta$ (degrees)")
        plt.ylabel(r"$C_P$")
        #plt.ylim((0, 1.0))
        plt.tight_layout()
        plt.show()
    if reached_theta_0:
        return {"C_P": meancp, "C_D": meancd, "TSR": meantsr}
    else:
        return {"C_P": "nan", "C_D": "nan", "TSR": "nan"}
 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
Example #6
0
def process_strut_torque(nrun, zero_torque=0.0, plot=False, covers=False,
                         verbose=False):
    """Process 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
Example #7
0
def calc_perf(theta_0=360, plot=False, verbose=True, inertial=False):
    t, torque, drag = foampy.load_all_torque_drag()
    _t, theta, omega = foampy.load_theta_omega(t_interp=t)
    reached_theta_0 = True
    if theta.max() < theta_0:
        theta_0 = 1
        reached_theta_0 = False
    # Compute tip speed ratio
    tsr = omega*R/U_infty
    # Compute mean TSR
    meantsr = np.mean(tsr[theta >= theta_0])
    if inertial:
        inertia = 3 # guess from SolidWorks model
        inertial_torque = inertia*fdiff.second_order_diff(omega, t)
        torque -= inertial_torque
    # Compute power coefficient
    power = torque*omega
    cp = power/(0.5*rho*area*U_infty**3)
    meancp = np.mean(cp[theta >= theta_0])
    # Compute drag coefficient
    cd = drag/(0.5*rho*area*U_infty**2)
    meancd = np.mean(cd[theta >= theta_0])
    if verbose:
        print("Performance from {:.1f}--{:.1f} degrees:".format(theta_0, 
                                                                theta.max()))
        print("Mean TSR = {:.3f}".format(meantsr))
        print("Mean C_P = {:.3f}".format(meancp))
        print("Mean C_D = {:.3f}".format(meancd))
    if plot:
        plt.close('all')
        plt.plot(theta[5:], cp[5:])
        plt.title(r"$\lambda = %1.1f$" %meantsr)
        plt.xlabel(r"$\theta$ (degrees)")
        plt.ylabel(r"$C_P$")
        #plt.ylim((0, 1.0))
        plt.tight_layout()
        plt.show()
    if reached_theta_0:
        return {"C_P" : meancp, 
                "C_D" : meancd, 
                "TSR" : meantsr}
    else:
        return {"C_P" : "nan", 
                "C_D" : "nan", 
                "TSR" : "nan"}
Example #8
0
 def EveryNCallback_py(taskHandle, everyNsamplesEventType, nSamples,
                       callbackData_ptr):
     """Function called every N samples"""
     callbackdata = daqmx.get_callbackdata_from_id(callbackData_ptr)
     data, npoints = daqmx.ReadAnalogF64(taskHandle, self.nsamps, 10.0,
                                         daqmx.Val_GroupByChannel,
                                         self.nsamps,
                                         len(self.analogchans))
     callbackdata.extend(data.tolist())
     self.data["torque_trans"] = np.append(self.data["torque_trans"],
                                           data[:, 0],
                                           axis=0)
     self.data["torque_arm"] = np.append(self.data["torque_arm"],
                                         data[:, 1],
                                         axis=0)
     self.data["drag_left"] = np.append(self.data["drag_left"],
                                        data[:, 2],
                                        axis=0)
     self.data["drag_right"] = np.append(self.data["drag_right"],
                                         data[:, 3],
                                         axis=0)
     self.data["t"] = np.arange(len(self.data["torque_trans"]),
                                dtype=float) / self.sr
     carpos, cpoints = daqmx.ReadCounterF64(self.carpostask,
                                            self.nsamps, 10.0,
                                            self.nsamps)
     self.data["carriage_pos"] = np.append(self.data["carriage_pos"],
                                           carpos)
     turbang, cpoints = daqmx.ReadCounterF64(self.turbangtask,
                                             self.nsamps, 10.0,
                                             self.nsamps)
     self.data["turbine_angle"] = np.append(self.data["turbine_angle"],
                                            turbang)
     self.data["turbine_rpm"] \
         = ts.smooth(fdiff.second_order_diff(self.data["turbine_angle"],
                                   self.data["t"])/6.0, 50)
     return 0  # The function should return an integer