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'                
Exemplo n.º 2
0
    def test_cpt_interpolation(self):
        
        cpt = CPT(test_filename)

        assert allclose(cpt.get_color(0), 0)
        assert allclose(cpt.get_color(3), 85) 
        assert allclose(cpt.get_color(6), 170)
        assert allclose(cpt.get_color(9), 255)
                 
        assert allclose(cpt.get_color(1), 28.3333333333) 
        assert allclose(cpt.get_color(1.5), 42.49999999)
        assert allclose(cpt.get_color(4.5), 85+42.49999999)        
Exemplo n.º 3
0
    def test_create_legend(self):
        """Test that this can run and that file is generated
        """
        
        cpt = CPT(test_filename)        
        legend_filename = cpt.create_legend_for_colour_coding(-10, 20, 
                                                               'Test legend')


        assert os.path.exists(legend_filename)
        
        # Cleanup
        os.remove(legend_filename)