MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / test_PowerNorm

Function test_PowerNorm

lib/matplotlib/tests/test_colors.py:530–568  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

528
529
530def test_PowerNorm():
531 # Check an exponent of 1 gives same results as a normal linear
532 # normalization. Also implicitly checks that vmin/vmax are
533 # automatically initialized from first array input.
534 a = np.array([0, 0.5, 1, 1.5], dtype=float)
535 pnorm = mcolors.PowerNorm(1)
536 norm = mcolors.Normalize()
537 assert_array_almost_equal(norm(a), pnorm(a))
538
539 a = np.array([-0.5, 0, 2, 4, 8], dtype=float)
540 expected = [-1/16, 0, 1/16, 1/4, 1]
541 pnorm = mcolors.PowerNorm(2, vmin=0, vmax=8)
542 assert_array_almost_equal(pnorm(a), expected)
543 assert pnorm(a[0]) == expected[0]
544 assert pnorm(a[2]) == expected[2]
545 # Check inverse
546 a_roundtrip = pnorm.inverse(pnorm(a))
547 assert_array_almost_equal(a, a_roundtrip)
548 # PowerNorm inverse adds a mask, so check that is correct too
549 assert_array_equal(a_roundtrip.mask, np.zeros(a.shape, dtype=bool))
550
551 # Clip = True
552 a = np.array([-0.5, 0, 1, 8, 16], dtype=float)
553 expected = [0, 0, 0, 1, 1]
554 # Clip = True when creating the norm
555 pnorm = mcolors.PowerNorm(2, vmin=2, vmax=8, clip=True)
556 assert_array_almost_equal(pnorm(a), expected)
557 assert pnorm(a[0]) == expected[0]
558 assert pnorm(a[-1]) == expected[-1]
559 # Clip = True at call time
560 pnorm = mcolors.PowerNorm(2, vmin=2, vmax=8, clip=False)
561 assert_array_almost_equal(pnorm(a, clip=True), expected)
562 assert pnorm(a[0], clip=True) == expected[0]
563 assert pnorm(a[-1], clip=True) == expected[-1]
564
565 # Check clip=True preserves masked values
566 a = np.ma.array([5, 2], mask=[True, False])
567 out = pnorm(a, clip=True)
568 assert_array_equal(out.mask, [True, False])
569
570
571def test_PowerNorm_translation_invariance():

Callers

nothing calls this directly

Calls 2

inverseMethod · 0.95
normFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…