def Lab_to_LCHab(cobj, *args, **kwargs):
"""
Convert from CIE Lab to LCH(ab).
"""
lch_l = cobj.lab_l
lch_c = math.sqrt(math.pow(float(cobj.lab_a), 2) + math.pow(float(cobj.lab_b), 2))
lch_h = math.atan2(float(cobj.lab_b), float(cobj.lab_a))
if lch_h > 0:
lch_h = (lch_h / math.pi) * 180
else:
lch_h = 360 - (math.fabs(lch_h) / math.pi) * 180
return LCHabColor(
lch_l, lch_c, lch_h, observer=cobj.observer, illuminant=cobj.illuminant)
# noinspection PyPep8Naming,PyUnusedLocal
python类fabs()的实例源码
def Luv_to_LCHuv(cobj, *args, **kwargs):
"""
Convert from CIE Luv to LCH(uv).
"""
lch_l = cobj.luv_l
lch_c = math.sqrt(math.pow(cobj.luv_u, 2.0) + math.pow(cobj.luv_v, 2.0))
lch_h = math.atan2(float(cobj.luv_v), float(cobj.luv_u))
if lch_h > 0:
lch_h = (lch_h / math.pi) * 180
else:
lch_h = 360 - (math.fabs(lch_h) / math.pi) * 180
return LCHuvColor(
lch_l, lch_c, lch_h, observer=cobj.observer, illuminant=cobj.illuminant)
# noinspection PyPep8Naming,PyUnusedLocal
def centeroidPinHoleMode(height, focal, altitude, theta, yCoordinate):
# height : jumlah baris (piksel)
# focal -> |A'O| : focal length (piksel)
# altitude -> |O'O| : tinggi kamera (m)
# theta : sudut kemiringan kamera (derajat)
# yCoordinate : indeks piksel Y object
height = float(height)
focal = float(focal)
theta = float(theta)
yCoordinate = float(yCoordinate)
delta = math.degrees(math.atan(math.fabs(yCoordinate - (height / 2)) / focal))
if yCoordinate >= height / 2:
lCentroid = altitude * math.tan(math.radians(theta + delta))
else:
lCentroid = altitude * math.tan(math.radians(theta - delta))
lCentroid = round(lCentroid, 4)
delta = round(delta, 4)
# print "delta: {0} | lCentroid: {1}".format(delta, lCentroid)
return lCentroid
def area(self):
"""Returns the cross sectional area of the bridge openings.
Return:
Dict - containing the area of the opening(s). keys = 'total', then
'1', '2', 'n' for all openings found.
"""
return 0
# areas = []
# opening_data = self.additional_row_collections['Opening']
# x_vals = self.row_collection.getRowDataAsList(rdt.CHAINAGE)
# y_vals = self.row_collection.getRowDataAsList(rdt.ELEVATION)
#
# start_vals = opening_data.getRowDataAsList(rdt.OPEN_START)
# end_vals = opening_data.getRowDataAsList(rdt.OPEN_END)
# soffit_vals = opening_data.getRowDataAsList(rdt.SOFFIT_LEVEL)
# springing_vals = opening_data.getRowDataAsList(rdt.SPRINGING_LEVEL)
# openings = zip(start_vals, end_vals, soffit_vals, springing_vals)
#
# for i, x in enumerate(x_vals):
#
# if math.fabs(x - )
#
#
# i=0
def _improvePolicy(self):
''' Policy improvement step. '''
policy_stable = True
for s in xrange(self.numStates):
old_action = self.pi[s]
tempV = [0.0] * len(self.actionSet)
# I first get all value-function estimates
for i in xrange(len(self.actionSet)):
nextS, nextR = self.environment.getNextStateAndReward(
s, self.actionSet[i])
tempV[i] = nextR + self.gamma * self.V[nextS]
# Now I take the argmax
self.pi[s] = np.argmax(tempV)
# I break ties always choosing to terminate:
if math.fabs(tempV[self.pi[s]] - tempV[(len(self.actionSet) - 1)]) < 0.001:
self.pi[s] = (len(self.actionSet) - 1)
if old_action != self.pi[s]:
policy_stable = False
return policy_stable
def hessian_dfp(self, c, delta_w, delta_g, epsilon):
n = delta_w.size
d = delta_g.dot(delta_w)
if fabs(d) < epsilon:
return np.identity(n)
a = np.zeros((n, n))
a = delta_w.dot(delta_w)
a /= d
b = np.zeros((n, n))
w2 = c.dot(delta_g)
b = w2.dot(w2)
d = delta_g.dot(w2)
if fabs(d) < epsilon:
return np.identity(n)
b /= d
return c+a-b
def tolerant_equals(a, b, atol=10e-7, rtol=10e-7):
return math.fabs(a - b) <= (atol + rtol * math.fabs(b))
def _update_cto(self):
# JP: One big WTF
if self._first_est:
self._srtt = self._qd
self._rttvar = self._qd / 2
self._cto = self._srtt + max([self._qd, LEDBAT.K * self._rttvar])
else:
self._rttvar = (1 - LEDBAT.BETA) * self._rttvar + LEDBAT.BETA * math.fabs(self._srtt - self._qd)
self._srtt = (1 - LEDBAT.ALPHA) * self._srtt + LEDBAT.ALPHA * self._qd
self._cto = self._srtt + max([self._g, LEDBAT.K * self._rttvar])
def _construct_mask_values(self, ids):
mask_vals = {}
print("Creating Mask Values...")
size = len(self._annotations)
for idx, annotation in enumerate(self._annotations):
print(str(idx) + "/" + str(size))
series, z, y, x, d = annotation #Order as given in the tutorial for LUNA-16
r = d/2.0
try:
img, o, s = p.load(open(os.path.join(self._target_directory, series + ".pick"), "rb"))
except:
continue
if series not in mask_vals:
mask_vals[series] = {}
voxelCenter = dp.world_to_voxel_coord(np.array([x, y, z]), o, s)
x, y, z = voxelCenter
y = int(y)
z = int(z)
sliceRange = range(max(0, int(x - r/s[0])), int(x + r/s[0] + 1)) #1 so that we don't loose any information
for sliceIdx in sliceRange:
center = (z, y)
radius = math.sqrt(max(0, r*r - ((s[0] * math.fabs(x - sliceIdx))**2)))
if sliceIdx not in mask_vals[series]:
mask_vals[series][sliceIdx] = []
mask_vals[series][sliceIdx].append((center, max(radius/s[1], radius/s[2])))
print("Mask values created!")
return mask_vals
def decimal_to_hms(decimal_value):
'''
This converts from decimal degrees to HH:MM:SS, returned as a
tuple. Negative values of degrees are wrapped to 360.0.
'''
# wrap to 360.0
if decimal_value < 0:
dec_wrapped = 360.0 + decimal_value
else:
dec_wrapped = decimal_value
# convert to decimal hours first
dec_hours = dec_wrapped/15.0
if dec_hours < 0:
negative = True
dec_val = fabs(dec_hours)
else:
negative = False
dec_val = dec_hours
hours = trunc(dec_val)
minutes_hrs = dec_val - hours
minutes_mm = minutes_hrs * 60.0
minutes_out = trunc(minutes_mm)
seconds = (minutes_mm - minutes_out)*60.0
if negative:
hours = -hours
return hours, minutes_out, seconds
else:
return hours, minutes_out, seconds
def hms_to_decimal(hours, minutes, seconds, returndeg=True):
'''
Converts from HH:MM:SS to a decimal value.
if returndeg is True: returns decimal degrees
if returndeg is False: returns decimal hours
'''
if hours > 24:
return None
else:
dec_hours = fabs(hours) + fabs(minutes)/60.0 + fabs(seconds)/3600.0
if returndeg:
dec_deg = dec_hours*15.0
if dec_deg < 0:
dec_deg = dec_deg + 360.0
dec_deg = dec_deg % 360.0
return dec_deg
else:
return dec_hours
def adjust(xa, ya, x, y, xb, yb):
global image
if(image.getpixel((x,y)) == 0):
d=math.fabs(xa-xb) + math.fabs(ya-yb)
v=(image.getpixel((xa,ya)) + image.getpixel((xb,yb)))/2.0 \
+ (random.random()-0.5) * d * roughness
c=int(math.fabs(v) % 256)
image.putpixel((x,y), c)
def abs(self):
return self.__class__(math.fabs(self.__point[0]),
math.fabs(self.__point[1]),
math.fabs(self.__point[2]))
def approx_equals(self, other, max_error=1e-15):
return (math.fabs(self.lat().radians -
other.lat().radians) < max_error and
math.fabs(self.lng().radians -
other.lng().radians) < max_error)
def approx_equals(self, other, max_error=1e-14):
return ((self.axis().angle(other.axis()) <= max_error and
math.fabs(self.height() - other.height()) <= max_error) or
(self.is_empty() and other.height() <= max_error) or
(other.is_empty() and self.height() <= max_error) or
(self.is_full() and other.height() >= 2 - max_error) or
(other.is_full() and self.height() >= 2 - max_error))
def is_valid(self):
return (math.fabs(self.lat().lo()) <= math.pi / 2.0 and
math.fabs(self.lat().hi()) <= math.pi / 2.0 and
self.lng().is_valid() and
self.lat().is_empty() == self.lng().is_empty())
def area(self):
"""Area in steradians."""
if self.is_empty():
return 0.0
return self.lng().get_length() * math.fabs(
math.sin(self.lat_hi().radians) -
math.sin(self.lat_lo().radians)
)
def is_unit_length(p):
return math.fabs(p.norm() * p.norm() - 1) <= 1e-15
def approx_equals(self, other, max_error=1e-15):
if self.is_empty():
return other.get_length() <= max_error
if other.is_empty():
return self.get_length() <= max_error
return (math.fabs(other.lo() - self.lo()) +
math.fabs(other.hi() - self.hi()) <= max_error)
def from_point_pair(cls, a, b):
assert math.fabs(a) <= math.pi
assert math.fabs(b) <= math.pi
if a == -math.pi:
a = math.pi
if b == -math.pi:
b = math.pi
if cls.positive_distance(a, b) <= math.pi:
return cls(a, b, args_checked=True)
else:
return cls(b, a, args_checked=True)