python radians函数_Python numpy.radians() 使用实例

The following are code examples for showing how to use . They are extracted from open source Python projects. You can vote up the examples you like or vote down the exmaples you don’t like. You can also save this page to your account.

Example 1

def angle_wrap(angle,radians=False):

'''

Wraps the input angle to 360.0 degrees.

if radians is True: input is assumed to be in radians, output is also in

radians

'''

if radians:

wrapped = angle % (2.0*PI)

if wrapped < 0.0:

wrapped = 2.0*PI + wrapped

else:

wrapped = angle % 360.0

if wrapped < 0.0:

wrapped = 360.0 + wrapped

return wrapped

Example 2

def great_circle_dist(p1, p2):

"""Return the distance (in km) between two points in

geographical coordinates.

"""

lon0, lat0 = p1

lon1, lat1 = p2

EARTH_R = 6372.8

lat0 = np.radians(float(lat0))

lon0 = np.radians(float(lon0))

lat1 = np.radians(float(lat1))

lon1 = np.radians(float(lon1))

dlon = lon0 - lon1

y = np.sqrt(

(np.cos(lat1) * np.sin(dlon)) ** 2

+ (np.cos(lat0) * np.sin(lat1)

- np.sin(lat0) * np.cos(lat1) * np.cos(dlon)) ** 2)

x = np.sin(lat0) * np.sin(lat1) + \

np.cos(lat0) * np.cos(lat1) * np.cos(dlon)

c = np.arctan2(y, x)

return EARTH_R * c

Example 3

def get_data(filename,headers,ph_units):

# Importation des données .DAT

dat_file = np.loadtxt("%s"%(filename),skiprows=headers,delimiter=',')

labels = ["freq", "amp", "pha", "amp_err", "pha_err"]

data = {l:dat_file[:,i] for (i,l) in enumerate(labels)}

if ph_units == "mrad":

data["pha"] = data["pha"]/1000 # mrad to rad

data["pha_err"] = data["pha_err"]/1000 # mrad to rad

if ph_units == "deg":

data["pha"] = np.radians(data["pha"]) # deg to rad

data["pha_err"] = np.radians(data["pha_err"]) # deg to rad

data["phase_range"] = abs(max(data["pha"])-min(data["pha"])) # Range of phase measurements (used in NRMS error calculation)

data["Z"] = data["amp"]*(np.cos(data["pha"]) + 1j*np.sin(data["pha"]))

EI = np.sqrt(((data["amp"]*np.cos(data["pha"])*data["pha_err"])**2)+(np.sin(data["pha"])*data["amp_err"])**2)

ER = np.sqrt(((data["amp"]*np.sin(data["pha"])*data["pha_err"])**2)+(np.cos(data["pha"])*data["amp_err"])**2)

data["Z_err"] = ER + 1j*EI

# Normalization of amplitude

data["Z_max"] = max(abs(data["Z"])) # Maximum amplitude

zn, zn_e = data["Z"]/data["Z_max"], data["Z_err"]/data["Z_max"] # Normalization of impedance by max amplitude

data["zn"] = np.array([zn.real, zn.imag]) # 2D array with first column = real values, second column = imag values

data["zn_err"] = np.array([zn_e.real, zn_e.imag]) # 2D array with first column = real values, second column = imag values

return data

Example 4

def get_data(filename,headers,ph_units):

# Importation des données .DAT

dat_file = np.loadtxt("%s"%(filename),skiprows=headers,delimiter=',')

labels = ["freq", "amp", "pha", "amp_err", "pha_err"]

data = {l:dat_file[:,i] for (i,l) in enumerate(labels)}

if ph_units == "mrad":

data["pha"] = data["pha"]/1000 # mrad to rad

data["pha_err"] = data["pha_err"]/1000 # mrad to rad

if ph_units == "deg":

data["pha"] = np.radians(data["pha"]) # deg to rad

data["pha_err"] = np.radians(data["pha_err"]) # deg to rad

data["phase_range"] = abs(max(data["pha"])-min(data["pha"])) # Range of phase measurements (used in NRMS error calculation)

data["Z"] = data["amp"]*(np.cos(data["pha"]) + 1j*np.sin(data["pha"]))

EI = np.sqrt(((data["amp"]*np.cos(data["pha"])*data["pha_err"])**2)+(np.sin(data["pha"])*data["amp_err"])**2)

ER = np.sqrt(((data["amp"]*np.sin(data["pha"])*data["pha_err"])**2)+(np.cos(data["pha"])*data["amp_err"])**2)

data["Z_err"] = ER + 1j*EI

# Normalization of amplitude

data["Z_max"] = max(abs(data["Z"])) # Maximum amplitude

zn, zn_e = data["Z"]/data["Z_max"], data["Z_err"]/data["Z_max"] # Normalization of impedance by max amplitude

data["zn"] = np.array([zn.real, zn.imag]) # 2D array with first column = real values, second column = imag values

data["zn_err"] = np.array([zn_e.real, zn_e.imag]) # 2D array with first column = real values, second column = imag values

return data

Example 5

def plotArc(start_angle, stop_angle, radius, width, **kwargs):

""" write a docstring for this function"""

numsegments = 100

theta = np.radians(np.linspace(start_angle+90, stop_angle+90, numsegments))

centerx = 0

centery = 0

x1 = -np.cos(theta) * (radius)

y1 = np.sin(theta) * (radius)

stack1 = np.column_stack([x1, y1])

x2 = -np.cos(theta) * (radius + width)

y2 = np.sin(theta) * (radius + width)

stack2 = np.column_stack([np.flip(x2, axis=0), np.flip(y2,axis=0)])

#add the first values from the first set to close the polygon

np.append(stack2, [[x1[0],y1[0]]], axis=0)

arcArray = np.concatenate((stack1,stack2), axis=0)

return patches.Polygon(arcArray, True, **kwargs), ((x1, y1), (x2, y2))

Example 6

def orthogonalization_matrix(lengths, angles):

"""Return orthogonalization matrix for crystallographic cell coordinates.

Angles are expected in degrees.

The de-orthogonalization matrix is the inverse.

>>> O = orthogonalization_matrix([10, 10, 10], [90, 90, 90])

>>> numpy.allclose(O[:3, :3], numpy.identity(3, float) * 10)

True

>>> O = orthogonalization_matrix([9.8, 12.0, 15.5], [87.2, 80.7, 69.7])

>>> numpy.allclose(numpy.sum(O), 43.063229)

True

"""

a, b, c = lengths

angles = numpy.radians(angles)

sina, sinb, _ = numpy.sin(angles)

cosa, cosb, cosg = numpy.cos(angles)

co = (cosa * cosb - cosg) / (sina * sinb)

return numpy.array([

[ a*sinb*math.sqrt(1.0-co*co), 0.0, 0.0, 0.0],

[-a*sinb*co, b*sina, 0.0, 0.0],

[ a*cosb, b*cosa, c, 0.0],

[ 0.0, 0.0, 0.0, 1.0]])

Example 7

def computeRotMatrix(self,Phi=False):

#######################################

# COMPUTE ROTATION MATRIX SUCH THAT m(t) = A*L(t)*A'*Hp

# Default set such that phi1,phi2 = 0 is UXO pointed towards North

if Phi is False:

phi1 = np.radians(self.phi[0])

phi2 = np.radians(self.phi[1])

phi3 = np.radians(self.phi[2])

else:

phi1 = np.radians(Phi[0]) # Roll (CCW)

phi2 = np.radians(Phi[1]) # Inclination (+ve is nose pointing down)

phi3 = np.radians(Phi[2]) # Declination (degrees CW from North)

# A1 = np.r_[np.c_[np.cos(phi1),-np.sin(phi1),0.],np.c_[np.sin(phi1),np.cos(phi1),0.],np.c_[0.,0.,1.]] # CCW Rotation about z-axis

# A2 = np.r_[np.c_[1.,0.,0.],np.c_[0.,np.cos(phi2),np.sin(phi2)],np.c_[0.,-np.sin(phi2),np.cos(phi2)]] # CW Rotation about x-axis (rotates towards North)

# A3 = np.r_[np.c_[np.cos(phi3),-np.sin(phi3),0.],np.c_[np.sin(phi3),np.cos(phi3),0.],np.c_[0.,0.,1.]] # CCW Rotation about z-axis (direction of head of object)

A1 = np.r_[np.c_[np.cos(phi1),np.sin(phi1),0.],np.c_[-np.sin(phi1),np.cos(phi1),0.],np.c_[0.,0.,1.]] # CW Rotation about z-axis

A2 = np.r_[np.c_[1.,0.,0.],np.c_[0.,np.cos(phi2),np.sin(phi2)],np.c_[0.,-np.sin(phi2),np.cos(phi2)]] # CW Rotation about x-axis (rotates towards North)

A3 = np.r_[np.c_[np.cos(phi3),np.sin(phi3),0.],np.c_[-np.sin(phi3),np.cos(phi3),0.],np.c_[0.,0.,1.]] # CW Rotation about z-axis (direction of head of object)

return np.dot(A3,np.dot(A2,A1))

Example 8

def orthogonalization_matrix(lengths, angles):

"""Return orthogonalization matrix for crystallographic cell coordinates.

Angles are expected in degrees.

The d

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
详细解释以下Python代码:import numpy as np import adi import matplotlib.pyplot as plt sample_rate = 1e6 # Hz center_freq = 915e6 # Hz num_samps = 100000 # number of samples per call to rx() sdr = adi.Pluto("ip:192.168.2.1") sdr.sample_rate = int(sample_rate) # Config Tx sdr.tx_rf_bandwidth = int(sample_rate) # filter cutoff, just set it to the same as sample rate sdr.tx_lo = int(center_freq) sdr.tx_hardwaregain_chan0 = -50 # Increase to increase tx power, valid range is -90 to 0 dB # Config Rx sdr.rx_lo = int(center_freq) sdr.rx_rf_bandwidth = int(sample_rate) sdr.rx_buffer_size = num_samps sdr.gain_control_mode_chan0 = 'manual' sdr.rx_hardwaregain_chan0 = 0.0 # dB, increase to increase the receive gain, but be careful not to saturate the ADC # Create transmit waveform (QPSK, 16 samples per symbol) num_symbols = 1000 x_int = np.random.randint(0, 4, num_symbols) # 0 to 3 x_degrees = x_int*360/4.0 + 45 # 45, 135, 225, 315 degrees x_radians = x_degrees*np.pi/180.0 # sin() and cos() takes in radians x_symbols = np.cos(x_radians) + 1j*np.sin(x_radians) # this produces our QPSK complex symbols samples = np.repeat(x_symbols, 16) # 16 samples per symbol (rectangular pulses) samples *= 2**14 # The PlutoSDR expects samples to be between -2^14 and +2^14, not -1 and +1 like some SDRs # Start the transmitter sdr.tx_cyclic_buffer = True # Enable cyclic buffers sdr.tx(samples) # start transmitting # Clear buffer just to be safe for i in range (0, 10): raw_data = sdr.rx() # Receive samples rx_samples = sdr.rx() print(rx_samples) # Stop transmitting sdr.tx_destroy_buffer() # Calculate power spectral density (frequency domain version of signal) psd = np.abs(np.fft.fftshift(np.fft.fft(rx_samples)))**2 psd_dB = 10*np.log10(psd) f = np.linspace(sample_rate/-2, sample_rate/2, len(psd)) # Plot time domain plt.figure(0) plt.plot(np.real(rx_samples[::100])) plt.plot(np.imag(rx_samples[::100])) plt.xlabel("Time") # Plot freq domain plt.figure(1) plt.plot(f/1e6, psd_dB) plt.xlabel("Frequency [MHz]") plt.ylabel("PSD") plt.show(),并分析该代码中QPSK信号的功率谱密度图的特点
06-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值