@@ -545,6 +545,9 @@ def test_LogNorm_inverse():
545545
546546
547547def test_PowerNorm ():
548+ # Check an exponent of 1 gives same results as a normal linear
549+ # normalization. Also implicitly checks that vmin/vmax are
550+ # automatically initialized from first array input.
548551 a = np .array ([0 , 0.5 , 1 , 1.5 ], dtype = float )
549552 pnorm = mcolors .PowerNorm (1 )
550553 norm = mcolors .Normalize ()
@@ -561,19 +564,22 @@ def test_PowerNorm():
561564 # Clip = True
562565 a = np .array ([- 0.5 , 0 , 1 , 8 , 16 ], dtype = float )
563566 expected = [0 , 0 , 0 , 1 , 1 ]
567+ # Clip = True when creating the norm
564568 pnorm = mcolors .PowerNorm (2 , vmin = 2 , vmax = 8 , clip = True )
565569 assert_array_almost_equal (pnorm (a ), expected )
566570 assert pnorm (a [0 ]) == expected [0 ]
567571 assert pnorm (a [- 1 ]) == expected [- 1 ]
568-
569572 # Clip = True at call time
570- a = np .array ([- 0.5 , 0 , 1 , 8 , 16 ], dtype = float )
571- expected = [0 , 0 , 0 , 1 , 1 ]
572573 pnorm = mcolors .PowerNorm (2 , vmin = 2 , vmax = 8 , clip = False )
573574 assert_array_almost_equal (pnorm (a , clip = True ), expected )
574575 assert pnorm (a [0 ], clip = True ) == expected [0 ]
575576 assert pnorm (a [- 1 ], clip = True ) == expected [- 1 ]
576577
578+ # Check clip=True preserves masked values
579+ a = np .ma .array ([5 , 2 ], mask = [True , False ])
580+ out = pnorm (a , clip = True )
581+ assert_array_equal (out .mask , [True , False ])
582+
577583
578584def test_PowerNorm_translation_invariance ():
579585 a = np .array ([0 , 1 / 2 , 1 ], dtype = float )
0 commit comments