def test_gamma_corrections (): # test individual component gamma for i in xrange (0, 100): x = 10.0 * (2.0 * random.random() - 1.0) a = colormodels.linear_from_display_component (x) b = colormodels.display_from_linear_component (a) c = colormodels.linear_from_display_component (b) # check err1 = math.fabs (b - x) rel1 = math.fabs (err1 / (b + x)) err2 = math.fabs (c - a) rel2 = math.fabs (err2 / (c + a)) #print 'x = %g, b = %g, err = %g, rel = %g' % (x, b, err1, rel1) #print 'a = %g, c = %g, err = %g, rel = %g' % (a, c, err2, rel2) tolerance = 1.0e-14 if rel1 > tolerance: raise ValueError if rel2 > tolerance: raise ValueError
def test_gamma_corrections(): # test individual component gamma for i in xrange(0, 100): x = 10.0 * (2.0 * random.random() - 1.0) a = colormodels.linear_from_display_component(x) b = colormodels.display_from_linear_component(a) c = colormodels.linear_from_display_component(b) # check err1 = math.fabs(b - x) rel1 = math.fabs(err1 / (b + x)) err2 = math.fabs(c - a) rel2 = math.fabs(err2 / (c + a)) #print 'x = %g, b = %g, err = %g, rel = %g' % (x, b, err1, rel1) #print 'a = %g, c = %g, err = %g, rel = %g' % (a, c, err2, rel2) tolerance = 1.0e-14 if rel1 > tolerance: raise ValueError if rel2 > tolerance: raise ValueError
def check_gamma_correction(self, verbose): ''' Check if the current gamma correction is consistent. ''' for i in range (10): x = 10.0 * (2.0 * random.random() - 1.0) a = colormodels.linear_from_display_component (x) y = colormodels.display_from_linear_component (a) b = colormodels.linear_from_display_component (y) # Check errors. abs_err1 = math.fabs (y - x) rel_err1 = math.fabs (abs_err1 / (y + x)) abs_err2 = math.fabs (b - a) rel_err2 = math.fabs (abs_err2 / (b + a)) msg1 = 'x = %g, y = %g, err = %g, rel = %g' % (x, y, abs_err1, rel_err1) msg2 = 'a = %g, b = %g, err = %g, rel = %g' % (a, b, abs_err2, rel_err2) if verbose: print (msg1) print (msg2) tolerance = 1.0e-14 self.assertLessEqual(rel_err1, tolerance) self.assertLessEqual(rel_err2, tolerance)
def check_gamma_correction(self, verbose): ''' Check if the current gamma correction is consistent. ''' for i in range(10): x = 10.0 * (2.0 * random.random() - 1.0) a = colormodels.linear_from_display_component(x) y = colormodels.display_from_linear_component(a) b = colormodels.linear_from_display_component(y) # Check errors. abs_err1 = math.fabs(y - x) rel_err1 = math.fabs(abs_err1 / (y + x)) abs_err2 = math.fabs(b - a) rel_err2 = math.fabs(abs_err2 / (b + a)) msg1 = 'x = %g, y = %g, err = %g, rel = %g' % (x, y, abs_err1, rel_err1) msg2 = 'a = %g, b = %g, err = %g, rel = %g' % (a, b, abs_err2, rel_err2) if verbose: print(msg1) print(msg2) tolerance = 1.0e-14 self.assertLessEqual(rel_err1, tolerance) self.assertLessEqual(rel_err2, tolerance)