本文整理汇总了Python中math.modf函数的典型用法代码示例。如果您正苦于以下问题:Python modf函数的具体用法?Python modf怎么用?Python modf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了modf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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))
开发者ID:jtornero,项目名称:jtCustomQtWidgets,代码行数:33,代码来源:coordinateEditor.py
示例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
开发者ID:LANHUIYING,项目名称:tvm,代码行数:28,代码来源:darknet.py
示例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()
开发者ID:aplpy,项目名称:aplpy-experimental,代码行数:34,代码来源:angle.py
示例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
开发者ID:asmodeii,项目名称:tanki,代码行数:25,代码来源:game_data.py
示例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)
开发者ID:hayds,项目名称:netcdf4-python,代码行数:28,代码来源:netcdftime.py
示例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)
开发者ID:eastmanjoe,项目名称:python_bucket,代码行数:31,代码来源:julianCalc.py
示例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])
开发者ID:Syralist,项目名称:myGCwebTools,代码行数:33,代码来源:coordinate.py
示例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)
开发者ID:Pujitha20,项目名称:Medical-images---Screening-System-development,代码行数:31,代码来源:temp.py
示例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
开发者ID:rodluger,项目名称:PyKE,代码行数:26,代码来源:kepfunc.py
示例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)
开发者ID:Rafiot,项目名称:bgpranking-hilbert,代码行数:26,代码来源:tilegenerator.py
示例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)
开发者ID:murdemon,项目名称:gps_pi_cloud,代码行数:7,代码来源:gps_helper.py
示例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))
开发者ID:Klafyvel,项目名称:RayCasting,代码行数:26,代码来源:ray_cast_engine.py
示例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
开发者ID:KeplerGO,项目名称:PyKE,代码行数:33,代码来源:kepfunc.py
示例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)
开发者ID:nesl,项目名称:netcar,代码行数:27,代码来源:NMEA.py
示例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)
开发者ID:eegroopm,项目名称:veusz,代码行数:31,代码来源:axisticks.py
示例16: do_lat_lon
def do_lat_lon(self, words):
if len(words[0]) == 0 or len(words[1]) == 0: # empty strings?
return
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)
开发者ID:yellowpoplar,项目名称:qgismapper,代码行数:29,代码来源:NMEA.py
示例17: arrival
def arrival(self):
'''Calculates the estimated arrival time based on current speed - run as thread.'''
#Loops until routing is turned off
while self.mode == True:
speed = round(self.cache.gps['speed'],2)
#Make sure we do not divide by zero
if speed > 0:
time_current = datetime.datetime.now()
#Determine time required for whole route
time_total = self.total_distance / speed
time_total_min, time_total_hour = math.modf(time_total)
time_total_min = round(time_total_min*60)
#Create a date/time object for ETA
time_total = time_current + datetime.timedelta(hours=time_total_hour, minutes=time_total_min)
self.total_eta = time_total.strftime("%Y-%m-%d %H:%M")
#Determine time required for next point in route
time_point = self.waypoint_calc['distance'] / speed
time_point_min, time_point_hour = math.modf(time_point)
time_point_min = round(time_point_min*60)
#If time is too large to display properly
if time_point_hour > 1000:
self.waypoint_eta['hour'] = '1000'
else:
#Add a 0 if minutes are less then 10
if time_point_min < 10:
time_point_min = '0' + str(time_point_min)
#Remove decimal points
self.waypoint_eta['hour'] = int(str(time_point_hour).replace('.0',''))
self.waypoint_eta['min'] = str(time_point_min).replace('.0','')
time.sleep(4)
#Do not estimate times if speed is 0
else:
self.total_eta = ' --'
self.waypoint_eta['hour'] = '--'
self.waypoint_eta['min'] = '--'
开发者ID:PivotLogix,项目名称:navstat,代码行数:35,代码来源:gps.py
示例18: _format_degree
def _format_degree(degree, latitude=True):
lit = ["NS", "EW"][0 if latitude else 1][0 if degree > 0 else 1]
degree = abs(degree)
mint, stop = math.modf(degree)
sec, mint = math.modf(mint * 60)
return "%d %d' %s'' %s" % (stop, mint,
locale.format('%0.2f', sec * 60), lit)
开发者ID:KarolBedkowski,项目名称:tbviewer,代码行数:7,代码来源:wnd_main.py
示例19: simplest_fraction_in_interval
def simplest_fraction_in_interval(x, y):
"""
Return the fraction with the lowest denominator in the interval [x, y].
"""
# http://stackoverflow.com/questions/4266741/check-if-a-number-is-rational-in-python
if x == y:
# The algorithm will not terminate if x and y are equal.
raise ValueError("Equal arguments.")
elif x < 0 and y < 0:
# Handle negative arguments by solving positive case and negating.
return -simplest_fraction_in_interval(-y, -x)
elif x <= 0 or y <= 0:
# One argument is 0, or arguments are on opposite sides of 0, so
# the simplest fraction in interval is 0 exactly.
return Fraction(0)
else:
# Remainder and Coefficient of continued fractions for x and y.
xr, xc = modf(1 / x)
yr, yc = modf(1 / y)
if xc < yc:
return Fraction(1, int(xc) + 1)
elif yc < xc:
return Fraction(1, int(yc) + 1)
else:
return 1 / (int(xc) + simplest_fraction_in_interval(xr, yr))
开发者ID:chebee7i,项目名称:dit,代码行数:28,代码来源:fraction.py
示例20: test_utime
def test_utime(self):
# Test times arg being invalid.
for junk in ('a', 1234.1234, (1, 2, 3), (1)):
self.assertRaises(TypeError, self.vol.utime, '/path', junk)
# Test times = None
mock_glfs_utimens = Mock(return_value=1)
mock_time = Mock(return_value=12345.6789)
with patch("gluster.gfapi.api.glfs_utimens", mock_glfs_utimens):
with patch("time.time", mock_time):
self.vol.utime('/path', None)
self.assertTrue(mock_glfs_utimens.called)
self.assertTrue(mock_time.called)
# Test times passed as arg
mock_glfs_utimens.reset_mock()
atime = time.time()
mtime = time.time()
with patch("gluster.gfapi.api.glfs_utimens", mock_glfs_utimens):
self.vol.utime('/path', (atime, mtime))
self.assertTrue(mock_glfs_utimens.called)
self.assertEqual(mock_glfs_utimens.call_args[0][1], b'/path')
# verify atime and mtime
self.assertEqual(mock_glfs_utimens.call_args[0][2][0].tv_sec,
int(atime))
self.assertEqual(mock_glfs_utimens.call_args[0][2][0].tv_nsec,
int(math.modf(atime)[0] * 1e9))
self.assertEqual(mock_glfs_utimens.call_args[0][2][1].tv_sec,
int(mtime))
self.assertEqual(mock_glfs_utimens.call_args[0][2][1].tv_nsec,
int(math.modf(mtime)[0] * 1e9))
开发者ID:gluster,项目名称:libgfapi-python,代码行数:31,代码来源:test_gfapi.py
注:本文中的math.modf函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论