コード例 #1
0
def get_relative_x_y(vehicle):
    """get x and y coordinates of the vehicle relative to the avalance centre"""
    dist = distance_to_current_waypoint(vehicle)
    true_bearing = bearing_to_current_waypoint(vehicle) - avalanche_bearing
    x = dist * np.cos(true_bearing) * 6
    y = dist * np.sine(true_bearing) * 6
    return x, y
コード例 #2
0
def sine_plot_compare():
    """Computes the derivative of sin(x) through the numpy function"""
    x = np.arange(15, .01)
    fx = np.sine(x)
    fdx3 = np.gradient(fx)
    cartesian = plt.axes()
    cartesian.plot(x, fx, label="$f(x)$")
    cartesian.plot(x,
                   fdx3,
                   color="Red",
                   label="Derivative of $f(x) with Numpy Function$")
    cartesian.legend()
    cartesian.set(xlabel="x", ylabel="y", title="$\sin(x)$")
    plt.show()
コード例 #3
0
    def tangente(self, angle_min, angle_max, Array):
        #TODO: LaserScan durch Array mit Hinderniskoordinaten austauschen

        data = np.array(Array)
        length = len(data)
        vektor = [0, 0]
        i = 0
        if length < 4:
            # big obstacle
            #TODO: Tangenten berechnen
            angle_avg = (angle_min + angle_max) / 2
            vektor[0] = np.cos(angle_avg - 45 + 90)
            vektor[1] = np.sine(angle_avg - 45 + 90)

        else:
            #TODO: Alle Messwerte aufsummieren & anders umfliegen
            # small obstacle

            while i < length:
                sum = sum + data[i]
                i += 1
            avg = sum / length  # avg distance to obstacle

            #TODO: vektor durch twist erstetzen
            #TODO: vektorteil des twists in abhaengigkeit von winkel
            # +-40° reichen fuer Sicherheitsabstand von 1m bei Groeße der Drohne von 1.5m
            # zu einem Hindernis von Durchmesser ~40cm

            if (angle_min < 180 - 45 & angle_max < 180 - 45):
                vektor = []  # right
            else:
                if (angle_min > 180 - 45 & angle_max > 180 - 45):
                    vektor = []  # left
                else:
                    # object is straight ahead

                    if abs(angle_min - 135) < abs(angle_max - 135):
                        # obstacle is more to the right
                        vektor = []  # right
                    else:
                        # obstacle is more to the left
                        vektor = []  #left
コード例 #4
0
def Price(t):
    """
    Example function defining how price changes as a function of time.
    
    For now just make deterministic but could imagine adding random noise, etc.
    
    For now just use a simple sine curve offset to always be positive (so 
    price is always positive)
    
    
    input:
        t - np array of timesteps
        
        **could eventually make more sophisticated if other vars influence
        price too, and take in other input vectors or params.
        
    return:
        P_t 
    """
    A = 100.
    return .5*A*np.sine(t) + A
コード例 #5
0
def measure(feedback=False, xvec=np.zeros(1), yvec=np.zeros(1), 
            angle=0.0, repeat=False):
    '''
    Takes an appraoch curve measurement. Aborts with 'q' (or stop)
    in non-feedback, 'u' and 'd' will move stage up and down
    
    Kwargs:
    feedback -- whether or not to use feedback
    xvec -- fast scan vector (numpy array)for 1D and 2D scans, false for 0D
    yvec -- slow scan vector (numpy array)for 2D scans, false for 1D and 0D
    angle -- measurement ange (in radians)
    repeat -- whether to continuously repeat measurement until 'q' is pressed
    '''
    #Check that xvec is specified if yvec is
    if len(yvec) > 1 and not len(xvec) > 1:
        logging.error('Cannot have slow but not fast scan vector')
        raise ValueError(len(xvec),len(yvec))
    reload(approachimagingparams)
    #check dimensions of scan
    scanx=False;scany=False
    if len(yvec) > 1:
        scany = True
    if len(xvec) > 1:
        scanx = True
    #set up qt meaurement flow
    qt.flow.connect('measurement-end', tc.kill_all_tasks)
    qt.mstart()
    #Reset instrument (or initialize if not already)
    if qt.instruments.get_instruments_by_type('NI_DAQ'):
        daq = qt.instruments.get_instruments_by_type('NI_DAQ')[0]
        daq.reset()
    else:
        daq = qt.instruments.create('daq', 'NI_DAQ', id = 'Dev1')
        
    #Store current position of scanner
    start_position = np.zeros(3)    
    for i, chan in enumerate(DCCHANS):
        start_position[i] = daq.get_parameters['ao%i' % chan]['value']
        if np.isnan(start_position[i]):
            daq.set('ao%i' % chan, 0.0)
            start_position[i] = 0.0 
    #if we're not already at the right xy position, lift z and move there:
    if (abs(start_position[0] - xvec(0)) > 0.001 or 
            abs(start_position[1] - yvec(0)) > 0.001):
        mg.ramp(daq, 'ao %i' % DCCHANS[2], start_position[2] + Z_LIFT)     
        mg.ramp(daq, 'ao%i' % DCCHANS[0], xvec[0])
        mg.ramp(daq, 'ao%i' % DCCHANS[1], yvec[0])
        mg.ramp(daq, 'ao %i' % DCCHANS[2], start_position[2])
        
    #Prepare approach data structure to store absolutely all raw data:
    approach_data = qt.Data(name='approach_curves')
    approach_data.add_coordinate('sample')
    approach_data.add_coordinate('x [mV]')
    approach_data.add_coordinate('y [mV]')
    approach_data.add_value('z [mV]')
    approach_data.add_value('MIM-C [V]')
    approach_data.add_value('MIM-R [V]')
    approach_data.mimcplot = qt.Plot2D(approach_data, name='MIM-C [V]', 
                                       coorddim = 0, valdim = 3)
    appraoch_data.mimrplot = qt.Plot2D(approach_data, name='MIM-R [V]',
                                       coorddim = 0, valdim = 4)
    approach_data.create_file()
    approach_data.copy_file('appraochimaging.py')
    approach_data.copy_file('approachimagingparams.py')
    #Prepare spatial data structures for "normal" scan data:
    if scanx:
        spatial_data_right = qt.Data(name = 'spatial_data_right')
        spatial_data_left = qt.Data(name = 'spatial_data_left')
        spatial_data = [spatial_data_right, spatial_data_left]
        for data_obj in spatial_data:
            data_obj.add_coordinate('x [mV]')
            data_obj.add_coordinate('y [mV]')
            data_obj.add_value('z [mV]')
            data_obj.add_value('MIM-C [V]')
            data_obj.add_value('MIM-R [V]')
            data_obj.topoplot2d = qt.Plot2D(
                    spatial_data, name = 'topography linecuts')
            data_obj.mimcplot2d = qt.Plot2D(
                    spatial_data, name = 'MIM-C linecuts', valdim = 3)
            data_obj.mimrplot2d = qt.Plot2D(
                    spatial_data, name = 'MIM-R linecuts', valdim = 4)
            if scany:
                data_obj.topoplot3d = qt.Plot3D(spatial_data, 
                                                name = 'topography')
                data_obj.mimcplot3d = qt.Plot3D(spatial_data, 
                                                name = 'MIM-C', valdim = 3)
                data_obj.mimrplot3d = qt.Plot3D(spatial_data, name = 'MIM-R', 
                                                valdim = 4)
            data_obj.create_file()
    
    # Scan out and back
    xvec = np.append(xvec,xvec[::-1]) 
    fastvec = np.zeros((len(xvec),2))
    slowvec = np.zeros((len(yvec),2))
    for i, x in enumerate(xvec):
        fastvec[i] = np.array(
                [np.cos(angle) * xvec[i], np.sine(angle) * xvec[i]])
    for i, y in enumerate(yvec):
        slowvec[i] = np.array(
                [-np.sine(angle) * yvec[i], np.cos(angle) * yvec[i]])

    #Set up tasks:
    zactask = tc.AcOutTask(3, SAMPLES, SAMPLERATE, sync = True)    
    zacdata = GenSineWave(samples,amplitude,phase)
    zactask.set_signal(zacdata) 
    xytask = tc.DcOutTask(DCCHAN[0:2])
    ztask = tc.DcOutTask([DCCHAN[2]])
    maintask = mimCalbackTask(MIMCHANS, SAMPLES, SAMPLERATE, zstart, feedback)
    
    maintask.userin = False
    while maintask.userin != 'q':
        if msvcrt.kbhit():
            maintask.userin = msvcrt.getch()
        try:
            qt.msleep(.5)
        except:
            logging.warning('Live plotting glitch (No big deal)')

    print('%i approaches completed' % maintask.callcounter)
    #stop tasks before error    
    qt.mend()
    qt.msleep(.1)
    #close all 3 data objects    
    approach_data.close_file()
    for data_obj in spatial_data:
        data_obj.close_file()     
コード例 #6
0
import numpy as np

arr = np.arange(0, 11)
print(arr)
print(arr + arr)
print(arr * arr)
print(arr - arr)
print(arr + 100)
print(arr * 10)
# print(arr/ arr) # nan for 0/0
# print(1 / arr)  # inf for 1/0

print(np.sqrt(arr))
print(np.exp(arr))
print(np.sine(arr))
コード例 #7
0
    def horizontal_tempurature_gradient(self):
        """ Calculate the horizontal tempurature gradient. 
            $\lambda \frac{\partial z_s}{\partial x}
        """

        return self.lmbda * np.sine(deg2rad(self.pz_spx))
コード例 #8
0
 def _sine(self, time):
     return sine(np.array(time));
def sine(x):
    return np.sine(x)
コード例 #10
0
 def _sine(self, input_vector, weight_vector, bias):
     z = weight_vector.dot(input_vector) + bias
     return np.sine(z)