예제 #1
0
    def test_make_discrete_cpt(self):
        """
        Test the make_discrete_cpt() function that makes discrete CPT files.
        """

        # need a temporary working directory
        tmp_dir = tempfile.mkdtemp(prefix='test_utilities_')

        # simple test
        filename = os.path.join(tmp_dir, 'test.cpt')
        colourmap = util.get_colourmap('hazmap')
        seq = [0.0, 1.0, 2.0, 4.0, 8.0]
        if sys.platform == 'win32':
            expected = [
                ['0.00', '32', '255', '0', '1.00', '32', '255', '0'],
                ['1.00', '96', '255', '0', '2.00', '96', '255', '0'],
                ['2.00', '191', '255', '0', '4.00', '191', '255', '0'],
                ['4.00', '255', '128', '0', '8.00', '255', '128', '0'],
                ['B', '0', '255', '0'],
                ['F', '255', '0', '0'],
                ['N', '255', '255', '255']
            ]
        else:
            expected = [
                ['0', '32', '255', '0', '1', '32', '255', '0'],
                ['1', '96', '255', '0', '2', '96', '255', '0'],
                ['2', '191', '255', '0', '4', '191', '255', '0'],
                ['4', '255', '127', '0', '8', '255', '127', '0'],
                ['B', '0', '255', '0'],
                ['F', '255', '0', '0'],
                ['N', '255', '255', '255']
            ]

        util.make_discrete_cpt(filename, colourmap, seq)

        # check resultant file
        fd = open(filename, 'r')
        lines = fd.readlines()
        fd.close()

        split_pattern = re.compile('[ |\t]+')
        generated = []
        for l in lines:
            l = l.strip()
            if l[0] == '#':
                continue

            generated.append(split_pattern.split(l))

        # delete the temporary directory
        shutil.rmtree(tmp_dir)

        msg = 'expected=\n%s\ngenerated=\n%s' % (str(expected), str(generated))
        self.failUnless(expected == generated, msg)
예제 #2
0
    def test_get_colourmap(self):
        """Test the get_colourmap() function."""

        # unrecognised colourmap name
        self.failUnlessRaises(RuntimeError, util.get_colourmap, 'xyzzy')

        # GMT builtin colormap names, case insensitive
        expected = 'cool'
        got = util.get_colourmap('cool')
        self.failUnlessEqual(got, expected)
        expected = 'cool'
        got = util.get_colourmap('COOL')
        self.failUnlessEqual(got, expected)

        # local name, case insensitive
        expected = 'hazmap.cpt'
        got = util.get_colourmap('hazmap')
        self.failUnlessEqual(os.path.basename(got), expected)
        expected = 'hazmap.cpt'
        got = util.get_colourmap('HazMap')
        self.failUnlessEqual(os.path.basename(got), expected)
예제 #3
0
    def test_get_colourmap(self):
        """Test the get_colourmap() function."""

        # unrecognised colourmap name
        self.failUnlessRaises(RuntimeError, util.get_colourmap, 'xyzzy')

        # GMT builtin colormap names, case insensitive
        expected = 'cool'
        got = util.get_colourmap('cool')
        self.failUnlessEqual(got, expected)
        expected = 'cool'
        got = util.get_colourmap('COOL')
        self.failUnlessEqual(got, expected)

        # local name, case insensitive
        expected = 'hazmap.cpt'
        got = util.get_colourmap('hazmap')
        self.failUnlessEqual(os.path.basename(got), expected)
        expected = 'hazmap.cpt'
        got = util.get_colourmap('HazMap')
        self.failUnlessEqual(os.path.basename(got), expected)
예제 #4
0
    def test_make_discrete_cpt(self):
        """
        Test the make_discrete_cpt() function that makes discrete CPT files.
        """

        # need a temporary working directory
        tmp_dir = tempfile.mkdtemp(prefix='test_utilities_')

        # simple test
        filename = os.path.join(tmp_dir, 'test.cpt')
        colourmap = util.get_colourmap('hazmap')
        seq = [0.0, 1.0, 2.0, 4.0, 8.0]
        if sys.platform == 'win32':
            expected = [['0.00', '32', '255', '0', '1.00', '32', '255', '0'],
                        ['1.00', '96', '255', '0', '2.00', '96', '255', '0'],
                        ['2.00', '191', '255', '0', '4.00', '191', '255', '0'],
                        ['4.00', '255', '128', '0', '8.00', '255', '128', '0'],
                        ['B', '0', '255', '0'], ['F', '255', '0', '0'],
                        ['N', '255', '255', '255']]
        else:
            expected = [['0', '32', '255', '0', '1', '32', '255', '0'],
                        ['1', '96', '255', '0', '2', '96', '255', '0'],
                        ['2', '191', '255', '0', '4', '191', '255', '0'],
                        ['4', '255', '127', '0', '8', '255', '127', '0'],
                        ['B', '0', '255', '0'], ['F', '255', '0', '0'],
                        ['N', '255', '255', '255']]

        util.make_discrete_cpt(filename, colourmap, seq)

        # check resultant file
        fd = open(filename, 'r')
        lines = fd.readlines()
        fd.close()

        split_pattern = re.compile('[ |\t]+')
        generated = []
        for l in lines:
            l = l.strip()
            if l[0] == '#':
                continue

            generated.append(split_pattern.split(l))

        # delete the temporary directory
        shutil.rmtree(tmp_dir)

        msg = 'expected=\n%s\ngenerated=\n%s' % (str(expected), str(generated))
        self.failUnless(expected == generated, msg)