本文整理汇总了Python中numpy.fix函数的典型用法代码示例。如果您正苦于以下问题:Python fix函数的具体用法?Python fix怎么用?Python fix使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fix函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: detect_face_12net
def detect_face_12net(cls_prob,roi,out_side,scale,width,height,threshold):
in_side = 2*out_side+11
stride = 0
if out_side != 1:
stride = float(in_side-12)/(out_side-1)
(x,y) = np.where(cls_prob>=threshold)
boundingbox = np.array([x,y]).T
bb1 = np.fix((stride * (boundingbox) + 0 ) * scale)
bb2 = np.fix((stride * (boundingbox) + 11) * scale)
boundingbox = np.concatenate((bb1,bb2),axis = 1)
dx1 = roi[0][x,y]
dx2 = roi[1][x,y]
dx3 = roi[2][x,y]
dx4 = roi[3][x,y]
score = np.array([cls_prob[x,y]]).T
offset = np.array([dx1,dx2,dx3,dx4]).T
boundingbox = boundingbox + offset*12.0*scale
rectangles = np.concatenate((boundingbox,score),axis=1)
rectangles = rect2square(rectangles)
pick = []
for i in range(len(rectangles)):
x1 = int(max(0 ,rectangles[i][0]))
y1 = int(max(0 ,rectangles[i][1]))
x2 = int(min(width ,rectangles[i][2]))
y2 = int(min(height,rectangles[i][3]))
sc = rectangles[i][4]
if x2>x1 and y2>y1:
pick.append([x1,y1,x2,y2,sc])
return NMS(pick,0.5,'iou')
示例2: symmetrized_dot_cloud
def symmetrized_dot_cloud(waveform, angle=60, top=50, lag=1):
"""
same as symmetrized dots but returns a 2d point cloud instead of a boolean image. note the
return value is a tuple (x, y) of int ndarrays, which is equivalent to (cols, rows).
"""
# normalize the waveform to 0-top
waveform = normalize(waveform, top)
# roll the waveform by lag to get the angles we'll use
roll_waveform = np.roll(waveform, lag)
# now compute the angles
first_angle = np.concatenate(
[base_angle + roll_waveform for base_angle in np.arange(0, 360, angle)])
second_angle = np.concatenate(
[base_angle - roll_waveform for base_angle in np.arange(0, 360, angle)])
all_angles = np.deg2rad(np.concatenate([first_angle, second_angle]))
# tile the original waveform until it matches the length of the angles
num_repeats = int(all_angles.size / waveform.size)
waveform = np.tile(waveform, num_repeats)
# now make the point cloud
x_cols = waveform * np.cos(all_angles) + top
y_rows = waveform * np.sin(all_angles) + top
return (np.fix(x_cols).astype(np.int), np.fix(y_rows).astype(np.int))
示例3: dec2Dec2
def dec2Dec2(Dec):
'''
change degree to dec2
dec2 is the degree: np.array([ XXdegree, XXminute, XXsecond])
if dec2 is negative, it should be like np.array([-XXdegree, -XXminute, -XXsecond])
examples:
for single degree
input: np.array([degree])
dec2Dec2(np.array([45.51]))
output =
array([[ 45., 30., 36.]])
it is the dec2 representing 45 degree 30 minute 36 second
for array degrees
input: np.array([degree1, degree2, degree3....])
dec2Dec2(np.array([-256.32, -135.5, 10.3234, 256.3333333333]))
output =
array([[-256. , -19. , -12. ],
[-135. , -30. , 0. ],
[ 10. , 19. , 24.24 ],
[ 256. , 19. , 59.99999988]])
they are 4 dec2s
'''
Dec = np.float64(Dec)
degree = np.fix(Dec)
#print 'degree=',degree
_point = (Dec-degree)*60.0
minute = np.fix(_point)
#print 'minute=',minute
arc = (_point-minute)*60.0
#print 'arc=',arc
return np.array([degree,minute,arc]).T
示例4: generate_bounding_box
def generate_bounding_box(imap, reg, scale, threshold):
"""Use heatmap to generate bounding boxes"""
# pylint: disable=too-many-locals
stride = 2
cellsize = 12
imap = np.transpose(imap)
d_x1 = np.transpose(reg[:, :, 0])
d_y1 = np.transpose(reg[:, :, 1])
d_x2 = np.transpose(reg[:, :, 2])
d_y2 = np.transpose(reg[:, :, 3])
dim_y, dim_x = np.where(imap >= threshold)
if dim_y.shape[0] == 1:
d_x1 = np.flipud(d_x1)
d_y1 = np.flipud(d_y1)
d_x2 = np.flipud(d_x2)
d_y2 = np.flipud(d_y2)
score = imap[(dim_y, dim_x)]
reg = np.transpose(np.vstack([d_x1[(dim_y, dim_x)], d_y1[(dim_y, dim_x)],
d_x2[(dim_y, dim_x)], d_y2[(dim_y, dim_x)]]))
if reg.size == 0:
reg = np.empty((0, 3))
bbox = np.transpose(np.vstack([dim_y, dim_x]))
q_1 = np.fix((stride * bbox + 1) / scale)
q_2 = np.fix((stride * bbox + cellsize - 1 + 1) / scale)
boundingbox = np.hstack([q_1, q_2, np.expand_dims(score, 1), reg])
return boundingbox, reg
示例5: epoch_plot
def epoch_plot(t, y, period, name='none'):
phase = (t/period)*1.0 - np.fix(t/period)
sortidxs = np.argsort(phase)
sorted_phase = phase[sortidxs]
sorted_y = y[sortidxs]
sorted_dates = t[sortidxs]
pp = np.concatenate([sorted_phase, sorted_phase+1.0], 1)
yy = np.concatenate([sorted_y, sorted_y], 1)
epochs = np.fix(sorted_dates/period)
epoch_list = set(epochs)
mi = min(y)-0.15
ma2 = heapq.nlargest(2, y)[1]
plt.clf()
x = 0
for i in epoch_list:
period_date_idxs = np.asarray(np.where(epochs == i))
period_mags = sorted_y[period_date_idxs]
period_dates = sorted_dates[period_date_idxs]
period_phases = sorted_phase[period_date_idxs]
pp = np.concatenate([period_phases, period_phases + 1.0], 1)
yy = np.concatenate([period_mags, period_mags], 1)
plt.scatter(pp, yy, color=cm.jet(1.*x/len(epoch_list)), alpha=0.7, edgecolors='none')
x +=1
print ma2, mi
plt.ylim(ma2, mi)
#plt.gca().invert_yaxis()
plt.text(-0.4, mi+0.1, "period = {} days".format(period), fontsize=14)
plt.xlabel("phase")
plt.ylabel("V-band magnitude")
if name !='none':
#plt.title("{}".format(name))
plt.savefig("../output/{}_epoch.png".format(name))
plt.show()
示例6: LST
def LST(y, m, d, ut1, EL):
'''
calculate the Local sidereal time
input: year,month,day(do not have to be integer),ut1,Longitude of the site (all input can be array)
output: Local sidereal time in degree
examples:
LST(2012,10,29,19+53./60 -8 ,116.4) # the Local sidereal time in Beijing(+8) at 2012-10-29 19:53:00
output =
332.86374268340001 # (degree)
'''
def J0(year, month, day):
'''temp function of LST'''
j0 = 367.0*year - np.fix(7.0*(year + np.fix((month + 9)/12.0))/4.0)+ np.fix(275.0*month/9) + day + 1721013.5
return j0
y = np.float64(y)
m = np.float64(m)
d = np.float64(d)
ut1 = np.float64(ut1)
EL = np.float64(EL)
dd = np.fix(d)
time = (d-dd)*24.0
ut = (ut1 + time)%24
j0 = J0(y, m, dd)
j = (j0 - 2451545.0)/36525.0
g0 = 100.4606184 + (36000.77004*j) + (0.000387933*j**2)- 2.583e-8*j**3
g0 = g0%360
gst = g0 + (360.98564724*ut/24.0)
lst = gst + EL
lst = lst - 360.0*np.fix(lst/360.0)
return lst
示例7: idftreal
def idftreal(A, N, M):
'''
Calculates multiple 1D inverse DFT from complex to real
Input:
A - input complex vectors in column form (samples from zero to Nyquist)
N - number of output samples (= number of implied complex input samples)
M - number of input vectors
Based on idftreal.m by R.G. Pratt
'''
a = np.zeros((N, M))
n = np.arange(N).reshape((N,1))
# Set maximum non-Nyquist frequency index (works for even or odd N)
imax = np.int(np.fix((N+1)//2)-1)
k1 = np.arange(np.fix(N//2)+1) # Freq indices from zero to Nyquist
k2 = np.arange(1, imax+1) # Freq indices except zero and Nyquist
nk1 = n * k1.T
nk2 = n * k2.T
w = np.exp(-2j*np.pi / N)
W = w**nk1
W2 = w**nk2
W[:,1:imax+1] += W2 # Add two matrices properly shifted
a = np.dot(W, A[:np.fix(N//2)+1,:M]).real # (leads to doubling for non-Nyquist)
return a
示例8: cos_pattern
def cos_pattern(AO_resolution, freq):
# Experiment spec: sinewave on angles of stepper motor:
# 60 degree amplitude (max), 15 Hz (max)
# from Karin and Holger 12-apr-2011 15:00:00
step = 360.0/5000 #...step(/microstep) angle (degree)
amp = 60 /2 #...sine wave amplitude (peak to peak degree)
# freq = 1 #...sine wave frequency (Hz)
Y = numpy.arange(0,amp,step)
X = (1/(2*numpy.pi*freq))*numpy.arcsin(Y/amp)
# AO_resolution = 2.5e-6 # (us) resolution: 400k Hz maximum, the period of which is 2.5 us
# AO_resolution = 5e-6 # (us) resolution: 200k Hz maximum, the period of which is 5 us
# AO_resolution = 1e-4 # (us) resolution: 10k Hz maximum, the period of which is 100 us
Xs = numpy.fix(X / AO_resolution )
SM_sig = numpy.zeros(numpy.fix(Xs[numpy.size(Xs)-1])+1)
for i in range(numpy.size(Xs)): SM_sig[Xs[i]]=1
rev_SM_sig = numpy.zeros(numpy.fix(Xs[numpy.size(Xs)-1])+1)
for i in range(numpy.size(SM_sig)): rev_SM_sig[i]=SM_sig[numpy.size(SM_sig)-1-i]
# duration = 2 * X[numpy.size(X)-1] # (second) duration of the signal train
wavelet = 5 * numpy.append( rev_SM_sig , SM_sig)
wavelet = numpy.append(wavelet, wavelet)
wavelet = numpy.append(wavelet, numpy.array([0]))
return wavelet
示例9: nlfer
def nlfer(signal, pitch, parameters):
#---------------------------------------------------------------
# Set parameters.
#---------------------------------------------------------------
N_f0_min = np.around((parameters['f0_min']*2/float(signal.new_fs))*pitch.nfft)
N_f0_max = np.around((parameters['f0_max']/float(signal.new_fs))*pitch.nfft)
window = hanning(pitch.frame_size+2)[1:-1]
data = np.zeros((signal.size)) #Needs other array, otherwise stride and
data[:] = signal.filtered #windowing will modify signal.filtered
#---------------------------------------------------------------
# Main routine.
#---------------------------------------------------------------
samples = np.arange(int(np.fix(float(pitch.frame_size)/2)),
signal.size-int(np.fix(float(pitch.frame_size)/2)),
pitch.frame_jump)
data_matrix = np.empty((len(samples), pitch.frame_size))
data_matrix[:, :] = stride_matrix(data, len(samples),
pitch.frame_size, pitch.frame_jump)
data_matrix *= window
specData = np.fft.rfft(data_matrix, pitch.nfft)
frame_energy = np.abs(specData[:, N_f0_min-1:N_f0_max]).sum(axis=1)
pitch.set_energy(frame_energy, parameters['nlfer_thresh1'])
pitch.set_frames_pos(samples)
示例10: get_cofe_target
def get_cofe_target(ut,lat,lon,target):
#function to use ephem to find az and el of specified target for COFE
#parameters: UT, LAt Lon Target
cofe=ephem.Observer()
cofe.elevation=0.0
year=2013
month=10
day=04
az=[]
el=[]
for u,la,lo in zip(ut,lat,lon):
if (u >24):
u=u-24
day=05
hour=int(np.fix(u))
minute=(u-hour)*60
iminute=int(np.fix(minute))
second=int(np.fix((minute-iminute)*60))
datestring=str(year)+'/'+str(month)+'/'+str(day)+' '+str(hour)+':'+str(iminute)+':'+str(second)
datestring
cofe.date=datestring
cofe.lon=str(rtd*lo)
cofe.lat=str(rtd*la)
pos=ephem.__getattribute__(target)(cofe)
az.append(pos.az)
el.append(pos.alt)
return np.array(az),np.array(el)
示例11: plot_imfs
def plot_imfs(self, time, tstart=None, tend=None, tunit='s', savefig_name=''):
time = time - time[0]
dt = time[1] - time[0]
if tstart != None:
tstart = int(np.fix(tstart / dt))
if tend != None:
tend = int(np.fix(tend / dt))
num_subplot = self.num_imf + 1
fig = plt.figure()
ax = fig.add_subplot(num_subplot, 1, 1)
ax.plot(time[tstart:tend], self.input_signal[tstart:tend])
ax.set_ylabel('Data')
ax.get_yaxis().set_label_coords(-0.1,0.5)
for i in range(self.num_imf - 1):
ax = fig.add_subplot(num_subplot, 1, i + 2)
ax.plot(time[tstart:tend], self.imfs[:,i][tstart:tend])
ax.set_ylabel(r'$C_{' + str(i + 1) + '}$')
ax.get_yaxis().set_label_coords(-0.1,0.5)
ax = fig.add_subplot(num_subplot, 1, num_subplot)
ax.plot(time[tstart:tend], self.imfs[:,-1][tstart:tend])
ax.get_yaxis().set_label_coords(-0.1,0.5)
ax.set_ylabel('Trend')
ax.set_xlabel('Time (' + tunit + ')')
if savefig_name == '':
plt.show()
else:
plt.savefig(savefig_name, format='eps', dpi=1000)
示例12: generateBoundingBox
def generateBoundingBox(imap, reg, scale, t):
# use heatmap to generate bounding boxes
stride = 2
cellsize = 12
imap = np.transpose(imap)
dx1 = np.transpose(reg[:, :, 0])
dy1 = np.transpose(reg[:, :, 1])
dx2 = np.transpose(reg[:, :, 2])
dy2 = np.transpose(reg[:, :, 3])
y, x = np.where(imap >= t)
if y.shape[0] == 1:
dx1 = np.flipud(dx1)
dy1 = np.flipud(dy1)
dx2 = np.flipud(dx2)
dy2 = np.flipud(dy2)
score = imap[(y, x)]
reg = np.transpose(np.vstack([dx1[(y, x)], dy1[(y, x)], dx2[(y, x)], dy2[(y, x)]]))
if reg.size == 0:
reg = np.empty((0, 3))
bb = np.transpose(np.vstack([y, x]))
q1 = np.fix((stride * bb + 1) / scale)
q2 = np.fix((stride * bb + cellsize - 1 + 1) / scale)
boundingbox = np.hstack([q1, q2, np.expand_dims(score, 1), reg])
return boundingbox, reg
示例13: intermediate_profile
def intermediate_profile(x, xhinge, delta):
"""Generate an intermediate profile of some quantity.
Ferron et. al. 1998
Returns the 'top down' and 'bottom up' profiles as well as the average
of the two.
"""
xf = np.flipud(x)
xtd = np.zeros_like(x)
xbu = np.zeros_like(x)
ntd = np.fix(x[0]/delta - xhinge/delta)
nbu = np.fix(xf[0]/delta - xhinge/delta)
xtd[0] = xhinge + ntd*delta
xbu[0] = xhinge + nbu*delta
for i in xrange(len(x) - 1):
ntd = np.fix(x[i+1]/delta - xtd[i]/delta)
nbu = np.fix(xf[i+1]/delta - xbu[i]/delta)
xtd[i+1] = xtd[i] + ntd*delta
xbu[i+1] = xbu[i] + nbu*delta
xbu = np.flipud(xbu)
xav = (xtd + xbu)/2.
return xtd, xbu, xav
示例14: _simulate_image
def _simulate_image(self):
"""
Generates the fake output.
"""
with self._acquisition_init_lock:
pos = self.align.position.value
logging.debug("Simulating image shift by %s", pos)
ac, bc = pos.get("a"), pos.get("b")
ang = math.radians(135)
# AB->XY
xc = -(ac * math.sin(ang) + bc * math.cos(ang))
yc = -(ac * math.cos(ang) - bc * math.sin(ang))
pixelSize = self.fake_img.metadata[model.MD_PIXEL_SIZE]
self.fake_img.metadata[model.MD_ACQ_DATE] = time.time()
x_pxs = xc / pixelSize[0]
y_pxs = yc / pixelSize[1]
# Image shifted based on LensAligner position
z = 1j # imaginary unit
self.deltar = x_pxs
self.deltac = y_pxs
nr, nc = self.fake_img.shape
array_nr = numpy.arange(-numpy.fix(nr / 2), numpy.ceil(nr / 2))
array_nc = numpy.arange(-numpy.fix(nc / 2), numpy.ceil(nc / 2))
Nr = fft.ifftshift(array_nr)
Nc = fft.ifftshift(array_nc)
[Nc, Nr] = numpy.meshgrid(Nc, Nr)
sim_img = fft.ifft2(fft.fft2(self.fake_img) * numpy.power(math.e,
z * 2 * math.pi * (self.deltar * Nr / nr + self.deltac * Nc / nc)))
output = model.DataArray(abs(sim_img), self.fake_img.metadata)
return output
示例15: interval2semitone
def interval2semitone(interval, accidentals):
# Need it to be int
import numpy as np
interval = int(interval)
# semitone equivalents for intervals
# interval 1,2,3,4,5,6,7
semitonetranslation = [0,2,4,5,7,9,11]
semitone = 0
success = True
if (interval > 0) and (interval < 50):
# semitone value is the number of semitones equivalent to the interval
# added to the number of accidentals (sharps are positive, flats are
# negative) and the number of octaves above the reference note to
# account for extensions
des_index = int(np.mod(interval,8) + np.fix(interval/8))-1
semitone = int(semitonetranslation[des_index] + accidentals + 12*np.fix(interval/8))
else:
success = False
print 'Error in interval2semitone: out of range interval'
return semitone, success