def spatial_corr(self, cross_len = 2.0, nos = 80): """Spatial Correlatoin, cross length (corss_len) is assigned as two lambdas by default. nos means number of sections.""" self.spatial_correlation = [] spatial_max = 0 step = float(cross_len) / nos for each in range(nos + 1): temp = 0 for k, each_AoA in enumerate(self.AoA_all): each_step = each*step*sine(each_AoA/180.0*PI)*2*PI phase = cosine(each_step) + 1j*sine(each_step) temp = temp + self.power_from_BS_to_UE_V[k]*phase self.spatial_correlation.append(abs(temp)) self.spatial_correlation = [each / self.spatial_correlation[0] for each in self.spatial_correlation] step_tenth_lambda = 0.1 step_half_lambda = 0.5 step_full_lambda = 1.0 self.power_from_BS_to_UE_tenth_lambda = [] self.power_from_BS_to_UE_half_lambda = [] self.power_from_BS_to_UE_full_lambda = [] for k, each_AoA in enumerate(self.AoA_all): step = step_tenth_lambda*sine(each_AoA/180.0*PI)*2*PI phase = cosine(step) + 1j*sine(step) self.power_from_BS_to_UE_tenth_lambda.append(self.power_from_BS_to_UE_V[k]*phase) step = step_half_lambda*sine(each_AoA/180.0*PI)*2*PI phase = cosine(step) + 1j*sine(step) self.power_from_BS_to_UE_half_lambda.append(self.power_from_BS_to_UE_V[k]*phase) step = step_full_lambda*sine(each_AoA/180.0*PI)*2*PI phase = cosine(step) + 1j*sine(step) self.power_from_BS_to_UE_full_lambda.append(self.power_from_BS_to_UE_V[k]*phase)
def print_math(): """ Prints some calculated values. """ x = math.cosine(Pi) print(x) y = math.sine(Pi) print("The sine of PI is", y)
def make_planet(ox,oy,r,texture): if ox + rad > 0 and ox - rad < xSize: for y in range(oy - r + 1, oy + r): ncol = int((y - oy + r)/(r/len(texture))/2) r2 = sqrt(r**2 - (y - oy)**2) c = 2*3.141*r2 n = len(texture[ncol]) n/=2 for i in range(int(n)): icol = i while icol >= 2*n: icol = int(i - 2*n) if r2 == 0: r2 = 0.000001 x = r2*cosine(i*c/(2*n)/r2) - r2*cosine(i*c/(2*n)/r2 + c/(2*n)/r2) x1 = r2 - r2*cosine(i*c/(2*n)/r2) pygame.draw.line(screen, texture[ncol][icol], (ox - r2 + x1, y), (ox - r2 + x1 + x, y))
def spatial_corr(self, cross_len=2.0, nos=80): """Spatial Correlatoin, cross length (corss_len) is assigned as two lambdas by default. nos means number of sections.""" self.spatial_correlation = [] spatial_max = 0 step = float(cross_len) / nos for each in range(nos + 1): temp = 0 for k, each_AoA in enumerate(self.AoA_all): each_step = each * step * sine(each_AoA / 180.0 * PI) * 2 * PI phase = cosine(each_step) + 1j * sine(each_step) temp = temp + self.power_from_BS_to_UE_V[k] * phase self.spatial_correlation.append(abs(temp)) self.spatial_correlation = [ each / self.spatial_correlation[0] for each in self.spatial_correlation ] step_tenth_lambda = 0.1 step_half_lambda = 0.5 step_full_lambda = 1.0 self.power_from_BS_to_UE_tenth_lambda = [] self.power_from_BS_to_UE_half_lambda = [] self.power_from_BS_to_UE_full_lambda = [] for k, each_AoA in enumerate(self.AoA_all): step = step_tenth_lambda * sine(each_AoA / 180.0 * PI) * 2 * PI phase = cosine(step) + 1j * sine(step) self.power_from_BS_to_UE_tenth_lambda.append( self.power_from_BS_to_UE_V[k] * phase) step = step_half_lambda * sine(each_AoA / 180.0 * PI) * 2 * PI phase = cosine(step) + 1j * sine(step) self.power_from_BS_to_UE_half_lambda.append( self.power_from_BS_to_UE_V[k] * phase) step = step_full_lambda * sine(each_AoA / 180.0 * PI) * 2 * PI phase = cosine(step) + 1j * sine(step) self.power_from_BS_to_UE_full_lambda.append( self.power_from_BS_to_UE_V[k] * phase)
def ani(self, cross_len = 2.0, nos = 80): """cross length (corss_len) is assigned as two lambdas by default. nos means number of sections.""" self.ani_x = {} self.ani_y = {} spatial_max = 0 delta = float(cross_len) / nos for n in range(nos + 1): step = n*delta data = [] for k, each_AoA in enumerate(self.AoA_all): step2 = step*sine(each_AoA/180.0*PI)*2*PI phase = cosine(step2) + 1j*sine(step2) data.append(self.power_from_BS_to_UE_V[k]*phase) self.ani_x[n] = np.array([each.real for each in data]) self.ani_y[n] = np.array([each.imag for each in data])
def set_effect(selection, value_args, fade=0, curve='linear', verbose=False, cuelist_mode=False): # [selection, parameter, formula, amplitude, absolute/relative, vertical shift, horizontal shift, spread, buddy] formula = { 'sine': lambda x, amp, absrel, ver, hor, freq: amp * math.sin(freq * x), 'cosine': lambda x: math.cosine(x), 'ramp': lambda x: x % 1 } def effect(): return timer = time.perf_counter() while True: deltaTime = time.perf_counter() - timer if CLIENT_CONNECTION_STATUS: dClient.write(new_values) return
def _do_wave_processing(self): while self.keep_peripheral_threads_alive: if self.hub_node.current_mode == ModeChange.WAVE: self.wave_update_change_mutex.acquire() try: self.wave_position = self.wave_position + self.wave_position_increment while self.wave_position >= _2PI: self.wave_position = self.wave_position - _2PI id_intensity_pairs = [] for p_id, p_location in self.hub_node.participant_locations: intensity = cosine(p_location - self.wave_position) if intensity < WAVE_NEGLIGIBLE_THRESHOLD: intensity = 0.0 id_intensity_pairs.append((p_id, intensity)) self.hub_node.send_wave_update(id_intensity_pairs) finally: self.wave_update_change_mutex.release() sleep(WAVE_UPDATE_WAIT_TIME_S)
def __init__(self): Power_array = [0, -2.2, -1.7, -5.2, -9.1, -12.5] Power_array = [10**(each/10.0) for each in Power_array] N_path = len(Power_array) ## number of clusters AoA_array = [65.7, 45.6, 143.2, 32.5, -91.1, -19.2] AoD_array = [82, 80.5, 79.6, 98.6, 102.1, 107.1] AS_AoD = 5.0 AS_AoA = 35.0 self.Frequency = 7.51e6 ## in Hz self.V_MA = 100000.0 / 60 / 60 ## 100km/hr, mobile speed in m/s self.V_direction = 120.0 XPR = 9 ## in dB subpath10_1 = [-75.4274, -53.1816, -40.1824, -30.9538, -23.7899, -17.9492, -13.0045, -8.7224, -4.9447, -1.4649] subpath10_2 = [-1*each for each in subpath10_1[::-1]] subpath20 = subpath10_1 + subpath10_2 subpath20_AoA = list(subpath20) subpath20_AoD = [each / AS_AoA * AS_AoD for each in subpath20] ## normalizaing subpath, so can be extened later for either AoA or AoD self.AoD_all = [] for each_AoD in AoD_array: for each_subpath in subpath20_AoD: self.AoD_all.append(each_AoD + each_subpath) self.AoA_all = [] for each_AoA in AoA_array: for each_subpath in subpath20_AoA: self.AoA_all.append(each_AoA + each_subpath) ## BS antenna model V_power_BS = [ 0.5 for each in range(120)] H_power_BS = [ pow(cosine(each/180.0*PI), 2) for each in self.AoD_all] self.V_power_BS = V_power_BS self.H_power_BS = H_power_BS ## XPR XPR = 10**(XPR/10.0) co_pol = XPR / (XPR + 1.0) cr_pol = 1 / (XPR + 1.0) ## BS power after XPR power_from_BS_V = [ V_power_BS[i]*co_pol + H_power_BS[i]*cr_pol for i in range(120) ] power_from_BS_H = [ H_power_BS[i]*co_pol + V_power_BS[i]*cr_pol for i in range(120) ] self.power_from_BS_V = power_from_BS_V self.power_from_BS_H = power_from_BS_H ## calculate the V and H power on each subpath from BS to the UE power_array_all = [] for each in Power_array: for each_subpath in range(20): power_array_all.append(each/20.0) self.power_from_BS_to_UE_V = [] self.power_from_BS_to_UE_H = [] for each in range(120): self.power_from_BS_to_UE_V.append( power_from_BS_V[each]*power_array_all[each] ) self.power_from_BS_to_UE_H.append( power_from_BS_H[each]*power_array_all[each] ) self.cross_pol = 10*log10(sum(self.power_from_BS_to_UE_V) / sum(self.power_from_BS_to_UE_H))
#The script is supposed to print out the cosine of 90 import math print(math.cosine(1))
import random # fully for i in range(5): value = random.randint(1, 6) print(value) from math import pi #just one print(pi) from math import sqrt, cos #various import math print(math.cos == cos) from math import sqrt as square_root #import as a diferent name print(square_root(100)) from math import sqrt as square_root, cos as cosine, tan as tangent print(square_root(49)) print(cosine(0)) print(tangent(45)) print(dir(math)) import math as m print(math.sqrt(25))
# + # Import anything, and use it with the dot accessor. import math a = math.cos(4 * math.pi) # You can also selectively import things. from math import pi b = 3 * pi # And even rename them if you don't like their name. from math import cos as cosine c = cosine(b) # - # How to know what is available? # # 1. Read the [documentation](https://docs.python.org/3/library/math.html) # 2. Interactively query the module print(dir(math)) # Typing the dot and the TAB will kick off tab-completion. # math. # In the IPython framework you can also use a question mark to view the documentation of modules and functions.
from math import cos as cosine, pi as piGreco print(2 * cosine(30)) print(piGreco)
def cal(X, Y): C = cosine(X) S = sine(Y) print('The Cosine is:', C, ', and the Sine is:', S) return C, S
def cos(deg): return cosine(radians(deg))
if d >= 11: rad = int(pythag(ySize,xSize)*degrees(atan(r/(d - 8)))/150) else: rad = int(pythag(ySize,xSize)*degrees(atan(r/(d*d*d*3/1331)))/150) #Stars for star in stars: origx = star[0] origy = star[1] star[0] += 90 star[1] -= ySize/2 col = [star[2],star[2],star[2]] odist = sqrt(pow(star[1]*fov/xSize,2) + pow(star[0] - 90 - angle,2)) if odist < 2*rad*fov/xSize: #col = [255,0,0] arg = atan2(star[1]*fov/xSize, star[0] - 90 - angle) dist = pow(odist,2)/(4*rad*fov/xSize) + rad*fov/xSize star[0] = angle + 90 + dist*cosine(arg) star[1] = dist*sine(arg)*xSize/fov #if star[0] - 90 > angle: star[0] = angle + 90 + pow(star[0] - 90 - angle,2)/(4*rad*fov/xSize) + rad*fov/xSize #elif star[0] - 90 < angle: star[0] = angle + 90 - pow(star[0] - 90 - angle,2)/(4*rad*fov/xSize) - rad*fov/xSize #print(angle, rad*fov/xSize, arg, odist, dist, origx, origy, star[0], star[1]) for n in range(-1,2): screen.set_at((int(xSize/2 + (star[0] + offset + 360*n)/fov*xSize), int(star[1] + ySize/2) + 1), col) screen.set_at((int(xSize/2 + (star[0] + offset + 360*n)/fov*xSize), int(star[1] + ySize/2) - 1), col) screen.set_at((int(xSize/2 + (star[0] + offset + 360*n)/fov*xSize), int(star[1] + ySize/2)), col) screen.set_at((int(xSize/2 + (star[0] + offset + 360*n)/fov*xSize + 1), int(star[1] + ySize/2)), col) screen.set_at((int(xSize/2 + (star[0] + offset + 360*n)/fov*xSize - 1), int(star[1] + ySize/2)), col) star[0] = origx star[1] = origy for c in collect:
def cos(deg): return cosine(radians(deg)) def pythag(a,b):
# import modules and use .var to call functions and variables # you can import specific methods or variables with from __ import __ # how can you tell what is in the module? # is there a module reference? import random from math import pi, sqrt, cos as cosine for i in range(1, 11): print(random.randint(1, 20)) print pi print sqrt(36) print cosine(pi) def print_nums(x): for i in range(x): print(i) return print_nums(10)
def cos(degrees): return(cosine(radians(degrees)))