本文整理汇总了Python中math.ceil函数的典型用法代码示例。如果您正苦于以下问题:Python ceil函数的具体用法?Python ceil怎么用?Python ceil使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ceil函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: is_converged
def is_converged(hartree_parameters, structure, return_values=False):
filename = s_name(structure) + ".conv_res"
to_return = {}
try:
f = open(filename, mode='r')
conv_res = ast.literal_eval(f.read())
f.close()
converged = True if True in conv_res['control'].values() else False
except (IOError, OSError, ValueError):
if return_values:
print('Inputfile ', filename, ' not found, the convergence calculation did not finish properly' \
' or was not parsed ...')
converged = False
return converged
if return_values and converged:
if hartree_parameters:
try:
conv_res['values']['ecut'] = 4 * math.ceil(conv_res['values']['ecut'] * eV_to_Ha / 4)
except (KeyError, ArithmeticError, FloatingPointError, SyntaxError):
pass
try:
conv_res['values']['ecuteps'] = 4 * math.ceil(conv_res['values']['ecuteps'] * eV_to_Ha / 4)
except (KeyError, ArithmeticError, FloatingPointError, SyntaxError):
pass
for k in conv_res['values'].keys():
if conv_res['values'][k] != 0 and conv_res['values'][k] != np.inf:
to_return.update({k: conv_res['values'][k]})
return to_return
else:
return converged
示例2: sharkeventkinshnavaw
def sharkeventkinshnavaw(self, a_ship, a_screen):
randnum = random.randint(1, 10)
if randnum < 10:
self.mess = "What were you thinking? The king shark sees all in the seas, nothing escapes it's sight"
self.mess += "What would you order your crew to do? The shark is still attacking."
messobj = StrObj.render(self.mess[0:33], 1, (0, 0, 0))
a_screen.blit(messobj, (self.xpos, 5))
messobj = StrObj.render(self.mess[33:68], 1, (0, 0, 0))
a_screen.blit(messobj, (self.xpos, 25))
messobj = StrObj.render(self.mess[69:87], 1, (0, 0, 0))
a_screen.blit(messobj, (self.xpos, 45))
messobj = StrObj.render(self.mess[87:113], 1, (0, 0, 0))
a_screen.blit(messobj, (self.xpos, 65))
messobj = StrObj.render(self.mess[113:143], 1, (0, 0, 0))
a_screen.blit(messobj, (self.xpos, 85))
messobj = StrObj.render(self.mess[144:], 1, (0, 0, 0))
a_screen.blit(messobj, (self.xpos, 105))
randnum = random.randint(0, 9)
a_ship.ShipHp -= int(math.ceil(randnum * .55))
a_ship.CrewHp -= int(math.ceil(randnum * .45))
self.MenuOp.initshkinafternavawf(170)
self.MenuOp.drawmen(a_screen, 0)
else:
self.mess = "Impossible! The king shark did not see us! The fates must be asleep."
messobj = StrObj.render(self.mess[0:35], 1, (0, 0, 0))
a_screen.blit(messobj, (self.xpos, 5))
messobj = StrObj.render(self.mess[35:], 1, (0, 0, 0))
a_screen.blit(messobj, (self.xpos, 25))
示例3: _download
def _download(url):
"""
Do a wget: Download the file specified in url to the cwd.
Return the filename.
"""
filename = os.path.split(url)[1]
req = requests.get(url, stream=True, headers={'User-Agent': 'PyBOMBS'})
filesize = float(req.headers['content-length'])
filesize_dl = 0
with open(filename, "wb") as f:
for buff in req.iter_content(chunk_size=8192):
if buff:
f.write(buff)
filesize_dl += len(buff)
# TODO wrap this into an output processor or at least
# standardize the progress bars we use
status = r"%05d kB / %05d kB (%03d%%)" % (
int(math.ceil(filesize_dl/1000.)),
int(math.ceil(filesize/1000.)),
int(math.ceil(filesize_dl*100.)/filesize)
)
status += chr(8)*(len(status)+1)
sys.stdout.write(status)
sys.stdout.write("\n")
return filename
示例4: SetValue
def SetValue(self, value):
""" Sets the FloatSpin value. """
if not self._textctrl or not self.InRange(value):
return
if self._snapticks and self._increment != 0.0:
finite, snap_value = self.IsFinite(value)
if not finite: # FIXME What To Do About A Failure?
if (snap_value - floor(snap_value) < ceil(snap_value) - snap_value):
value = self._defaultvalue + floor(snap_value)*self._increment
else:
value = self._defaultvalue + ceil(snap_value)*self._increment
strs = ("%100." + str(self._digits) + self._textformat[1])%value
strs = strs.strip()
strs = self.ReplaceDoubleZero(strs)
if value != self._value or strs != self._textctrl.GetValue():
self._textctrl.SetValue(strs)
self._textctrl.DiscardEdits()
self._value = value
示例5: __init__
def __init__(self, n, n_iter=3, train_size=.5, test_size=None,
random_state=None, n_bootstraps=None):
self.n = n
if n_bootstraps is not None: # pragma: no cover
warnings.warn("n_bootstraps was renamed to n_iter and will "
"be removed in 0.16.", DeprecationWarning)
n_iter = n_bootstraps
self.n_iter = n_iter
if (isinstance(train_size, numbers.Real) and train_size >= 0.0
and train_size <= 1.0):
self.train_size = int(ceil(train_size * n))
elif isinstance(train_size, numbers.Integral):
self.train_size = train_size
else:
raise ValueError("Invalid value for train_size: %r" %
train_size)
if self.train_size > n:
raise ValueError("train_size=%d should not be larger than n=%d" %
(self.train_size, n))
if isinstance(test_size, numbers.Real) and 0.0 <= test_size <= 1.0:
self.test_size = int(ceil(test_size * n))
elif isinstance(test_size, numbers.Integral):
self.test_size = test_size
elif test_size is None:
self.test_size = self.n - self.train_size
else:
raise ValueError("Invalid value for test_size: %r" % test_size)
if self.test_size > n:
raise ValueError("test_size=%d should not be larger than n=%d" %
(self.test_size, n))
self.random_state = random_state
示例6: NNI
def NNI(dir):
All = os.listdir(dir)
NumL = [int(I[0:-4]) for I in All]
n = len(All)
if n < 32:
Ext = [int(math.ceil(x*32./n)) for x in NumL]
for i in range(n):
os.rename(os.path.join(dir, All[i]), os.path.join(dir,'__' + str(Ext[i]) + '.png'))
for i in range(n):
os.rename(os.path.join(dir, '__' + str(Ext[i]) + '.png'), os.path.join(dir, str(Ext[i]) + '.png'))
Dif = list(set(range(1,33)).difference(set(Ext)))
Dif.sort()
Ext.sort()
for i in Dif:
item = [x>i for x in Ext].index(True)
obj = Ext[item]
os.system('cp '+os.path.join(dir,str(obj)+'.png')+' '+os.path.join(dir,str(i)+'.png'))
elif n > 32:
Ext = [int(math.ceil(x*n/32.)) for x in range(1,33)]
m = len(Ext)
Dif = list(set(NumL).difference(set(Ext)))
Dif.sort()
Ext.sort()
for i in Dif:
os.remove(os.path.join(dir, str(i) + '.png'))
for i in range(m):
os.rename(os.path.join(dir, str(Ext[i]) + '.png'),os.path.join(dir, '__'+str(i+1) + '.png'))
for i in range(m):
os.rename(os.path.join(dir, '__'+str(i+1) + '.png'),os.path.join(dir, str(i+1) + '.png'))
示例7: setAppearance
def setAppearance(self):
"""
A setter for the appearance of the tower.
"""
self.towerDiv = avg.DivNode(size=util.towerDivSize, pos=(self.pos.x - util.towerDivSize[0]//2, self.pos.y-util.towerDivSize[1]//2))
#sets the explosion radius
self.towerCircle = avg.CircleNode(fillopacity=0.3, strokewidth=0, fillcolor=self.team.color, r=self.towerDiv.size.x//2, pos=(self.towerDiv.size.x//2,self.towerDiv.size.y//2), parent=self.towerDiv)
#sets the fancy snow balls
for i in xrange(5):
radius = self.towerDiv.size[0]//10
xPos = random.randint(0 + math.floor(radius), math.ceil(self.towerDiv.size.x - radius))
yPos = random.randint(0 + math.floor(radius), math.ceil(self.towerDiv.size.y - radius))
snowball = avg.CircleNode(fillopacity=0.5, strokewidth=0, filltexhref=os.path.join(getMediaDir(__file__, "resources"), "snowflakes.png"), r=radius, pos=(xPos,yPos), parent=self.towerDiv)
self.snowballAnim(xPos,yPos,snowball)
self.tower = avg.RectNode(fillopacity=1, strokewidth=0, size=util.towerSize, pos=(self.pos.x - util.towerSize[0] // 2, self.pos.y - util.towerSize[1] // 2))
if self.team.name == "Team2":
self.tower.filltexhref = os.path.join(getMediaDir(__file__, "resources"), "iceball.png")
else:
self.tower.filltexhref = os.path.join(getMediaDir(__file__, "resources"), "iceball.png")
示例8: testFloor
def testFloor(self):
self.assertRaises(TypeError, math.floor)
# These types will be int in py3k.
self.assertEquals(float, type(math.floor(1)))
self.assertEquals(float, type(math.floor(1L)))
self.assertEquals(float, type(math.floor(1.0)))
self.ftest('floor(0.5)', math.floor(0.5), 0)
self.ftest('floor(1.0)', math.floor(1.0), 1)
self.ftest('floor(1.5)', math.floor(1.5), 1)
self.ftest('floor(-0.5)', math.floor(-0.5), -1)
self.ftest('floor(-1.0)', math.floor(-1.0), -1)
self.ftest('floor(-1.5)', math.floor(-1.5), -2)
# pow() relies on floor() to check for integers
# This fails on some platforms - so check it here
self.ftest('floor(1.23e167)', math.floor(1.23e167), 1.23e167)
self.ftest('floor(-1.23e167)', math.floor(-1.23e167), -1.23e167)
self.assertEquals(math.ceil(INF), INF)
self.assertEquals(math.ceil(NINF), NINF)
self.assert_(math.isnan(math.floor(NAN)))
class TestFloor(object):
def __float__(self):
return 42.3
class TestNoFloor(object):
pass
self.ftest('floor(TestFloor())', math.floor(TestFloor()), 42)
self.assertRaises(TypeError, math.floor, TestNoFloor())
t = TestNoFloor()
t.__floor__ = lambda *args: args
self.assertRaises(TypeError, math.floor, t)
self.assertRaises(TypeError, math.floor, t, 0)
示例9: readEgg
def readEgg(self,filename):
""" reads the egg file and stores the info"""
egg = EggData()
egg.read(filename)
for char in getAllEggGroup(egg):
name = str(char.getName())
image = Image()
image.name = name
self.images[name] = image
pos = char.getComponentVec3(0)
for p in getAllType(char,EggPolygon):
if p.getNumVertices() > 2:
v = p.getVertex(2)
vpos = v.getPos3()-pos
image.x = pos.getX()
image.y = pos.getZ()
image.w = vpos.getX()
image.h = vpos.getZ()
for l in getAllType(char,EggPoint):
extend = l.getVertex(0).getPos3()-pos
image.extend = math.ceil(extend.getX()),math.ceil(extend.getZ())
示例10: gaussian_smear
def gaussian_smear(self, r):
"""
Applies an isotropic Gaussian smear of width (standard deviation) r to the potential field. This is necessary to
avoid finding paths through narrow minima or nodes that may exist in the field (although any potential or
charge distribution generated from GGA should be relatively smooth anyway). The smearing obeys periodic
boundary conditions at the edges of the cell.
:param r - Smearing width in cartesian coordinates, in the same units as the structure lattice vectors
"""
# Since scaling factor in fractional coords is not isotropic, have to have different radii in 3 directions
a_lat = self.__s.lattice.a
b_lat = self.__s.lattice.b
c_lat = self.__s.lattice.c
# Conversion factors for discretization of v
v_dim = self.__v.shape
r_frac = (r / a_lat, r / b_lat, r / c_lat)
r_disc = (int(math.ceil(r_frac[0] * v_dim[0])), int(math.ceil(r_frac[1] * v_dim[1])),
int(math.ceil(r_frac[2] * v_dim[2])))
# Apply smearing
# Gaussian filter
gauss_dist = np.zeros((r_disc[0] * 4 + 1, r_disc[1] * 4 + 1, r_disc[2] * 4 + 1))
for g_a in np.arange(-2.0 * r_disc[0], 2.0 * r_disc[0] + 1, 1.0):
for g_b in np.arange(-2.0 * r_disc[1], 2.0 * r_disc[1] + 1, 1.0):
for g_c in np.arange(-2.0 * r_disc[2], 2.0 * r_disc[2] + 1, 1.0):
g = np.array([g_a / v_dim[0], g_b / v_dim[1], g_c / v_dim[2]]).T
gauss_dist[int(g_a + r_disc[0])][int(g_b + r_disc[1])][int(g_c + r_disc[2])] = la.norm(np.dot(self.__s.lattice.matrix, g))/r
gauss = scipy.stats.norm.pdf(gauss_dist)
gauss = gauss/np.sum(gauss, dtype=float)
padded_v = np.pad(self.__v, ((r_disc[0], r_disc[0]), (r_disc[1], r_disc[1]), (r_disc[2], r_disc[2])), mode='wrap')
smeared_v = scipy.signal.convolve(padded_v, gauss, mode='valid')
self.__v = smeared_v
示例11: __setAccountsAttrs
def __setAccountsAttrs(self, isPremiumAccount, premiumExpiryTime = 0):
disableTTHeader = ''
disableTTBody = ''
isNavigationEnabled = True
if self.prbDispatcher:
isNavigationEnabled = not self.prbDispatcher.getFunctionalState().isNavigationDisabled()
if isPremiumAccount:
if not premiumExpiryTime > 0:
raise AssertionError
deltaInSeconds = float(time_utils.getTimeDeltaFromNow(time_utils.makeLocalServerTime(premiumExpiryTime)))
if deltaInSeconds > time_utils.ONE_DAY:
timeLeft = math.ceil(deltaInSeconds / time_utils.ONE_DAY)
timeMetric = i18n.makeString('#menu:header/account/premium/days')
else:
timeLeft = math.ceil(deltaInSeconds / time_utils.ONE_HOUR)
timeMetric = i18n.makeString('#menu:header/account/premium/hours')
buyPremiumLabel = i18n.makeString('#menu:headerButtons/doLabel/premium')
premiumBtnLbl = makeHtmlString('html_templates:lobby/header', 'premium-account-label', {'timeMetric': timeMetric,
'timeLeft': timeLeft})
canUpdatePremium = deltaInSeconds < time_utils.ONE_YEAR
else:
canUpdatePremium = True
premiumBtnLbl = makeHtmlString('html_templates:lobby/header', 'base-account-label')
buyPremiumLabel = i18n.makeString('#menu:common/premiumBuy')
if not canUpdatePremium:
disableTTHeader = i18n.makeString(TOOLTIPS.LOBBY_HEADER_BUYPREMIUMACCOUNT_DISABLED_HEADER)
disableTTBody = i18n.makeString(TOOLTIPS.LOBBY_HEADER_BUYPREMIUMACCOUNT_DISABLED_BODY, number=time_utils.ONE_YEAR / time_utils.ONE_DAY)
self.as_doDisableHeaderButtonS(self.BUTTONS.PREM, canUpdatePremium and isNavigationEnabled)
hasPersonalDiscount = len(g_itemsCache.items.shop.personalPremiumPacketsDiscounts) > 0
tooltip = canUpdatePremium or {'header': disableTTHeader,
'body': disableTTBody}
else:
tooltip = TOOLTIPS.HEADER_PREMIUM_EXTEND if isPremiumAccount else TOOLTIPS.HEADER_PREMIUM_BUY
self.as_setPremiumParamsS(isPremiumAccount, premiumBtnLbl, buyPremiumLabel, canUpdatePremium, disableTTHeader, disableTTBody, hasPersonalDiscount, tooltip, TOOLTIP_TYPES.COMPLEX)
示例12: _max_min
def _max_min(self):
"""
Calculate minimum and maximum for the axis adding some padding.
There are always a maximum of ten units for the length of the axis.
"""
value = length = self._max - self._min
sign = value/value
zoom = less_than_one(value) or 1
value = value * zoom
ab = abs(value)
value = math.ceil(ab * 1.1) * sign
# calculate tick
l = math.log10(abs(value))
exp = int(l)
mant = l - exp
unit = math.ceil(math.ceil(10**mant) * 10**(exp-1))
# recalculate max
value = math.ceil(value / unit) * unit
unit = unit / zoom
if value / unit > 9:
# no more that 10 ticks
unit *= 2
self.unit = unit
scale = value / length
mini = math.floor(self._min * scale) / zoom
maxi = math.ceil(self._max * scale) / zoom
return mini, maxi
示例13: getCtInfo
def getCtInfo(id):
infos = {'description':'','ip':[],'hostname':'','ram':0}
infos['vmStatus'] = VE_STOPPED
#infos['ips'] = getCtIp(id)
f = open(VPS_CONF_DIR+'/'+id+'.conf')
for line in f:
line = re.sub('#.*','',line).strip()
if line != '':
m = re.search('([A-Z_]*)="(.*)"', line)
key = m.group(1)
value = m.group(2).replace('\\"','"')
if key == 'HOSTNAME':
infos['hostname'] = value
elif key == 'DESCRIPTION':
infos['description'] = unescape(value)
elif key == 'PRIVVMPAGES':
privvmpages = int(ceil(int(value.split(':')[0])/256.0))
elif key == 'LOCKEDPAGES':
infos['ram'] = int(ceil(int(value.split(':')[0])/256.0))
elif key == 'IP_ADDRESS':
infos['ip'] = re.sub('\s+',' ',value).strip().split(' ')
infos['swap'] = privvmpages - infos['ram']
return infos
示例14: generate_shifts_2d
def generate_shifts_2d(width, height, n_samples, with_hot=False):
x_shifts = gpu_rng.gen_uniform((n_samples,), np.float32) * (width - 0.01)
x_shifts = x_shifts.astype(np.uint32)
y_shifts = gpu_rng.gen_uniform((n_samples,), np.float32) * (height - 0.01)
y_shifts = y_shifts.astype(np.uint32)
if with_hot:
shifts_hot = gp.empty((width * height, n_samples), np.float32)
threads_per_block = 32
n_blocks = int(math.ceil(n_samples / threads_per_block))
gpu_shift_to_hot_2d(x_shifts, y_shifts, shifts_hot,
np.uint32(shifts_hot.strides[0]/4),
np.uint32(shifts_hot.strides[1]/4),
np.uint32(width), np.uint32(height), np.uint32(n_samples),
block=(threads_per_block, 1, 1), grid=(n_blocks, 1))
return x_shifts, y_shifts, shifts_hot
else:
shifts = gp.empty((2, n_samples), np.float32)
threads_per_block = 32
n_blocks = int(math.ceil(n_samples / threads_per_block))
gpu_vstack(y_shifts, x_shifts, shifts,
np.uint32(shifts.strides[0]/4), np.uint32(shifts.strides[1]/4),
np.uint32(n_samples),
block=(threads_per_block, 1, 1), grid=(n_blocks, 1))
return x_shifts, y_shifts, shifts
示例15: format
def format(self, value, form, length=32):
""" Format a number based on a format character and length
"""
# get current gdb radix setting
radix = int(re.search("\d+", gdb.execute("show output-radix", True, True)).group(0))
# override it if asked to
if form == 'x' or form == 'a':
radix = 16
elif form == 'o':
radix = 8
elif form == 'b' or form == 't':
radix = 2
# format the output
if radix == 16:
# For addresses, probably best in hex too
l = int(math.ceil(length/4.0))
return "0x"+"{:X}".format(value).zfill(l)
if radix == 8:
l = int(math.ceil(length/3.0))
return "0"+"{:o}".format(value).zfill(l)
if radix == 2:
return "0b"+"{:b}".format(value).zfill(length)
# Default: Just return in decimal
return str(value)