Exemplo n.º 1
0
    def test_remapping(self):
        """Test that threshold values can be rescaled
        """

        cpt = CPT(test_filename)        

        cpt.normalise()
        
        assert allclose(cpt.segments[0].lower_bound, 0)
        assert allclose(cpt.segments[0].upper_bound, 1./3)
        
        assert allclose(cpt.segments[1].lower_bound, 1./3)
        assert allclose(cpt.segments[1].upper_bound, 2./3)        
        
        assert allclose(cpt.segments[2].lower_bound, 2./3)
        assert allclose(cpt.segments[2].upper_bound, 1.0)                
        
        # Test that colours and flags are unchanged
        assert allclose(cpt.segments[0].rgb_min, [0,0,0])
        assert allclose(cpt.segments[0].rgb_dif, [85,85,85])
        
        assert allclose(cpt.segments[1].rgb_min, [85,85,85])        
        assert allclose(cpt.segments[1].rgb_dif, [170-85,170-85,170-85])        
        
        assert allclose(cpt.segments[2].rgb_min, [170,170,170])
        assert allclose(cpt.segments[2].rgb_dif, [85,85,85])        
        
        assert cpt.segments[0].color_segment_boundary == 'L'
        assert cpt.segments[1].color_segment_boundary == ''
        assert cpt.segments[2].color_segment_boundary == 'U'                


        cpt.rescale(-10, 20)
        assert allclose(cpt.segments[0].lower_bound, -10)
        assert allclose(cpt.segments[0].upper_bound, 0)
        
        assert allclose(cpt.segments[1].lower_bound, 0)
        assert allclose(cpt.segments[1].upper_bound, 10)        
        
        assert allclose(cpt.segments[2].lower_bound, 10)
        assert allclose(cpt.segments[2].upper_bound, 20)                        
        

        # Test that colours and flags are unchanged
        assert allclose(cpt.segments[0].rgb_min, [0,0,0])
        assert allclose(cpt.segments[0].rgb_dif, [85,85,85])
        
        assert allclose(cpt.segments[1].rgb_min, [85,85,85])        
        assert allclose(cpt.segments[1].rgb_dif, [170-85,170-85,170-85])        
        
        assert allclose(cpt.segments[2].rgb_min, [170,170,170])
        assert allclose(cpt.segments[2].rgb_dif, [85,85,85])        
        
        assert cpt.segments[0].color_segment_boundary == 'L'
        assert cpt.segments[1].color_segment_boundary == ''
        assert cpt.segments[2].color_segment_boundary == 'U'