本文整理汇总了Python中math.modf函数的典型用法代码示例。如果您正苦于以下问题:Python modf函数的具体用法?Python modf怎么用?Python modf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了modf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setCoordinate
def setCoordinate(self, coordinate):
self.coordinate = coordinate
degree_fraction, degrees = math.modf(coordinate)
degrees=int(degrees)
decimal_minutes=abs(degree_fraction*60)
minute_fraction, minutes = math.modf(decimal_minutes)
minutes=int(minutes)
decimal_seconds=minute_fraction*60
decString=(u"{0}".format(coordinate))
dmString=(u"{0}\u00b0 {1}'".format(degrees, decimal_minutes))
dmsString=(u"{0}\u00b0 {1}' {2}''".format(degrees, minutes, decimal_seconds))
print '***********************',coordinate,decString,dmString,dmsString
if self.displayMode=='DEC':
print 'DEC'
self.setText(decString)
elif self.displayMode=='DM':
print 'DM'
self.setText(dmString)
elif self.displayMode=='DMS':
print 'DMS'
self.setText(dmsString)
self.setToolTip(u"DEC: {0}\nDM: {1}\nDMS: {2}".format(decString,dmString,dmsString))
示例2: _resize_image
def _resize_image(img, w_in, h_in):
"""Resize the image to the given height and width."""
imc, imh, imw = img.shape
h_in = int(h_in)
w_in = int(w_in)
part = np.zeros((imc, imh, w_in))
resized = np.zeros((imc, h_in, w_in))
w_scale = (imw - 1) / (w_in - 1)
h_scale = (imh - 1) / (h_in - 1)
for k in range(imc):
for j in range(imh):
for c in range(w_in):
if c == w_in - 1 or imw == 1:
part[k][j][c] = img[k][j][imw - 1]
else:
fdx, idx = math.modf(c * w_scale)
part[k][j][c] = (1 - fdx) * img[k][j][int(idx)] + \
fdx * img[k][j][int(idx) + 1]
for k in range(imc):
for j in range(h_in):
fdy, idy = math.modf(j * h_scale)
for c in range(w_in):
resized[k][j][c] = (1 - fdy)*part[k][int(idy)][c]
if (j == h_in - 1) or (imh == 1):
continue
for c in range(w_in):
resized[k][j][c] += fdy * part[k][int(idy) + 1][c]
return resized
示例3: __init__
def __init__(self, degrees='none', sexagesimal='none', latitude=False):
if degrees != 'none':
# Find out if the angle is negative
negative = degrees < 0
# Treat angle as positive
degrees = np.abs(degrees)
# Decompose angle into degrees, minutes, seconds
m, d = math.modf(degrees)
s, m = math.modf(m * 60.)
s = s * 60.
# Express degrees and minutes as integers
d, m = int(round(d)), int(round(m))
# Put back minus sign if negative
if negative:
d, m, s = -d, -m, -s
# Set angle to tuple of degrees/minutes/seconds
self.angle = (d, m, s)
elif sexagesimal != 'none':
self.angle = sexagesimal
# Whether to keep the angle between 0 and 360 or -90 and 90
self.latitude = latitude
self.negative = False
self._simplify()
示例4: backward
def backward(self):
"""
Moves player forward if there is no obstacle ahead.
:return: True if succeeded/ False if hit obstacle.
"""
(vec_x, vec_y) = self.moving['vector']
(debt_x, debt_y) = self.moving['position_debt']
if self.status['speed_bonus']:
speed = self.status['speed'] + 1
else:
speed = self.status['speed']
(fractional_x, integral_x) = math.modf(vec_x*speed+debt_x)
(fractional_y, integral_y) = math.modf(vec_y*speed+debt_y)
old_x = self.tank.rect.x
old_y = self.tank.rect.y
self.tank.rect.x += integral_x
self.tank.rect.y -= integral_y
obstacles_hit = pygame.sprite.spritecollide(self.tank, GAME_DATA.tanks, False)
obstacles_hit += pygame.sprite.spritecollide(self.tank, GAME_DATA.walls, False)
self.moving['position_debt'] = (fractional_x, fractional_y)
if len(obstacles_hit) > 1:
self.tank.rect.x = old_x
self.tank.rect.y = old_y
return False
return True
示例5: _DateFrom360Day
def _DateFrom360Day(JD):
"""
returns a 'datetime-like' object given Julian Day for a calendar where all
months have 30 days.
Julian Day is a fractional day with a resolution of approximately 0.1 seconds.
"""
if JD < 0:
raise ValueError('Julian Day must be positive')
#jd = int(360. * (year + 4716)) + int(30. * (month - 1)) + day
(F, Z) = math.modf(JD)
year = int((Z - 0.5) / 360.) - 4716
dayofyr = Z - (year + 4716) * 360
month = int((dayofyr - 0.5) / 30) + 1
day = dayofyr - (month - 1) * 30 + F
# Convert fractions of a day to time
(dfrac, days) = math.modf(day / 1.0)
(hfrac, hours) = math.modf(dfrac * 24.0)
(mfrac, minutes) = math.modf(hfrac * 60.0)
(sfrac, seconds) = math.modf(mfrac * 60.0)
microseconds = sfrac*1.e6
return datetime(year, month, int(days), int(hours), int(minutes),
int(seconds), int(microseconds), -1, dayofyr)
示例6: decimal_to_base60
def decimal_to_base60(deci, precision=1e-8):
"""Converts decimal number into sexagesimal number parts.
``deci`` is the decimal number to be converted. ``precision`` is how
close the multiple of 60 and 3600, for example minutes and seconds,
are to 60.0 before they are rounded to the higher quantity, for
example hours and minutes.
"""
sign = "+" # simple putting sign back at end gives errors for small
# deg. This is because -00 is 00 and hence ``format``,
# that constructs the delimited string will not add '-'
# sign. So, carry it as a character.
if deci < 0:
deci = abs(deci)
sign = "-"
frac1, num = math.modf(deci)
num = int(num) # hours/degrees is integer valued but type is float
frac2, frac1 = math.modf(frac1 * 60.0)
frac1 = int(frac1) # minutes is integer valued but type is float
frac2 *= 60.0 # number of seconds between 0 and 60
# Keep seconds and minutes in [0 - 60.0000)
if abs(frac2 - 60.0) < precision:
frac2 = 0.0
frac1 += 1
if abs(frac1 - 60.0) < precision:
frac1 = 0.0
num += 1
return (sign, num, frac1, frac2)
示例7: toDegreesMinutesSeconds
def toDegreesMinutesSeconds(self):
self.__NorthString = ""
(decimal, integer) = math.modf(self.__North)
if self.__North < 0:
self.__NorthString += self.__LetterSouth
decimal *= -1
integer *= -1
else:
self.__NorthString += self.__LetterNorth
(mdecimal, minteger) = math.modf(decimal*60.0)
self.__NorthString += str(int(integer))
self.__NorthString += "° "
self.__NorthString += str(int(minteger))
self.__NorthString += "' "
self.__NorthString += str(mdecimal*60.0)
self.__NorthString += "\""
self.__EastString = ""
(decimal, integer) = math.modf(self.__East)
if self.__East < 0:
self.__EastString += self.__LetterWest
decimal *= -1
integer *= -1
else:
self.__EastString += self.__LetterEast
(mdecimal, minteger) = math.modf(decimal*60.0)
self.__EastString += str(int(integer))
self.__EastString += "° "
self.__EastString += str(int(minteger))
self.__EastString += "' "
self.__EastString += str(mdecimal*60.0)
self.__EastString += "\""
return " ".join([self.__NorthString, self.__EastString])
示例8: configcosfire1
def configcosfire1(img,params,x,y,sig):
angle=np.linspace(1,360,360)*(math.pi/180);
rho=[2,4,6,8]
rho1=[0,2,4,6,8]
max1=np.amax(img);
asymparams={'sigma':sig,'0':[0,0],'2':[],'4':[],'6':[],'8':[]}
for r in rho:
for theta in angle:
cnt=theta*180/math.pi
x1=x+(r*math.cos(theta))
y1=y+(r*math.sin(theta))
x_1=math.modf(x1)
y_1=math.modf(y1)
#print(img[x_1,y1])
#print(x1,y1)
if((x_1[0]==float(0)) & (y_1[0]==float(0))):
if((img[x_1[1],y_1[1]]==43)or img[x_1[1],y_1[1]]==45 or img[x_1[1],y_1[1]]==42):
asymparams[str(r)].append(theta-(math.pi/2))
asymparams['rho']=rho1
return(asymparams)
示例9: PRF2DET2
def PRF2DET2(flux,OBJx,OBJy,DATx,DATy,splineInterpolation):
# where in the pixel is the source position?
PRFfit = zeros((size(DATy),size(DATx)))
for i in range(len(flux)):
FRCx,INTx = modf(OBJx[i])
FRCy,INTy = modf(OBJy[i])
if FRCx > 0.5:
FRCx -= 1.0
INTx += 1.0
if FRCy > 0.5:
FRCy -= 1.0
INTy += 1.0
FRCx = -FRCx
FRCy = -FRCy
# constuct model PRF in detector coordinates
for (j,y) in enumerate(DATy):
for (k,x) in enumerate(DATx):
dy = y - INTy + FRCy
dx = x - INTx + FRCx
PRFfit[j,k] = PRFfit[j,k] + splineInterpolation(dy,dx) * flux[i]
return PRFfit
示例10: getcolor
def getcolor(value, size):
color = None
if value == 0:
color = scale[0]
elif value >= size:
color = scale[-1]
else:
if size > 1:
details, low_bound = math.modf(value * len(scale) / float(math.log(size, 2)))
else:
details, low_bound = math.modf(value * len(scale))
low_bound = int(low_bound)
if low_bound >= len(scale) - 1:
color = scale[-1]
else:
min_scale = scale[low_bound]
max_scale = scale[low_bound + 1]
color = []
for c1, c2 in zip(min_scale, max_scale):
if c1 == c2:
color.append(c1)
elif c1 < c2:
color.append(c1 + int(details * (c2 - c1)))
else:
color.append(c1 - int(details * (c1 - c2)))
return tuple(color)
示例11: convertHHMMSSToTotalSeconds
def convertHHMMSSToTotalSeconds(inputTime):
# the original input time is in the format hhmmss.xyz
seconds = math.modf(inputTime / 100.0)
# seconds is now a 2-tuple containing (.ssxyz, hhmm.)
minutes = math.modf(seconds[1] / 100.0)
# minutes is now a 2-tuple containing (.mm, hh)
return (seconds[0] * 100.0) + ((minutes[0] * 100.0) * 60.0) + (minutes[1] * 3600.0)
示例12: on_render
def on_render(self, target):
if self.roof:
target.blit(
self.roof, (0, 0), area=(target.get_width(), target.get_height() / 2))
if self.floor:
target.blit(self.floor, (0, target.get_height() / 2),
area=(get_target.width(), target.get_height() / 2))
self.screen_width, self.screen_height = target.get_width(), target.get_height()
f = self.create_screen_func()
# print(self.screen_width)
for k in range(1, self.screen_width + 1, self.column_width):
x_cam, y_cam = f(k/self.screen_width)
p = self.get_obstacle_in_direction(
(self.player.x, self.player.y), (x_cam, y_cam))
if p:
x, y = p
i, j = int(
modf(x / BLOCK_WIDTH)[1]), int(modf(y / BLOCK_HEIGHT)[1])
height = self.calc_column_height((x, y))
if not self.fish_eye:
x_base, y_base = self.player.camera_vector()
c = ((x_cam - self.player.x) * x_base + (y_cam - self.player.y) * y_base) / (norm(x_base, y_base) * norm((x_cam - self.player.x), (y_cam - self.player.y)))
height /= c
pygame.draw.rect(target, self.world[j][i][1],
(k, (self.screen_height - height) / 2, self.column_width, height))
示例13: PRF2DET
def PRF2DET(flux,OBJx,OBJy,DATx,DATy,wx,wy,a,splineInterpolation):
# trigonometry
cosa = cos(radians(a))
sina = sin(radians(a))
# where in the pixel is the source position?
PRFfit = zeros((size(DATy),size(DATx)))
for i in range(len(flux)):
FRCx,INTx = modf(OBJx[i])
FRCy,INTy = modf(OBJy[i])
if FRCx > 0.5:
FRCx -= 1.0
INTx += 1.0
if FRCy > 0.5:
FRCy -= 1.0
INTy += 1.0
FRCx = -FRCx
FRCy = -FRCy
# constuct model PRF in detector coordinates
for (j,y) in enumerate(DATy):
for (k,x) in enumerate(DATx):
xx = x - INTx + FRCx
yy = y - INTy + FRCy
dx = xx * cosa - yy * sina
dy = xx * sina + yy * cosa
PRFfit[j,k] += PRFfit[j,k] + splineInterpolation(dy*wy,dx*wx) * flux[i]
return PRFfit
示例14: do_lat_lon
def do_lat_lon(self, words):
if words[0][-1] == 'N':
words[0] = words[0][:-1]
words[1] = 'N'
if words[0][-1] == 'S':
words[0] = words[0][:-1]
words[1] = 'S'
if words[2][-1] == 'E':
words[2] = words[2][:-1]
words[3] = 'E'
if words[2][-1] == 'W':
words[2] = words[2][:-1]
words[3] = 'W'
if len(words[0]):
lat = string.atof(words[0])
frac, intpart = math.modf(lat / 100.0)
lat = intpart + frac * 100.0 / 60.0
if words[1] == 'S':
lat = -lat
(self.lat, self.LATLON) = self.update(self.lat, lat, self.LATLON)
if len(words[2]):
lon = string.atof(words[2])
frac, intpart = math.modf(lon / 100.0)
lon = intpart + frac * 100.0 / 60.0
if words[3] == 'W':
lon = -lon
(self.lon, self.LATLON) = self.update(self.lon, lon, self.LATLON)
示例15: _calcNoTicks
def _calcNoTicks( self, interval, logdelta ):
"""Return the number of ticks with spacing interval*10^logdelta.
Returns a tuple (noticks, minval, maxval).
"""
# store these for modification (if we extend bounds)
minval = self.minval
maxval = self.maxval
# calculate tick spacing and maximum extension factor
delta = interval * (10**logdelta)
maxextend = (maxval - minval) * AxisTicks.max_extend_factor
# should we try to extend to nearest interval*10^logdelta?
if self.extendmin:
# extend minval if possible
if math.fabs( math.modf( minval / delta )[0] ) > 1e-8:
d = minval - ( math.floor( minval / delta ) * delta )
if d <= maxextend:
minval -= d
if self.extendmax:
# extend maxval if possible
if math.fabs( math.modf( maxval / delta)[0] ) > 1e-8:
d = ( (math.floor(maxval / delta)+1.) * delta) - maxval
if d <= maxextend:
maxval += d
numticks = self._tickNums(minval, maxval, delta)
return (numticks, minval, maxval)