Exemple #1
0
    def test_write_geojson(self):
        """
        Check if geoJSON is properly created from contours
        """
        contour = pydiva2d.Diva2DContours(self.xlist, self.ylist)
        contour.to_geojson(filename=self.geojsonfile)

        self.assertTrue(os.path.exists(self.geojsonfile))

        with open(self.geojsonfile) as f:
            lines = f.readlines()
            line0 = lines[0].rstrip()

        self.assertEqual(line0, "var contours = {")
        self.assertEqual(len(lines), 41)

        contour.to_geojson(filename=self.geojsonfile, varname="divacont")
        self.assertTrue(os.path.exists(self.geojsonfile))

        with open(self.geojsonfile) as f:
            lines = f.readlines()
            line0 = lines[0].rstrip()

        self.assertEqual(line0, "var divacont = {")
        self.assertEqual(len(lines), 41)
Exemple #2
0
 def test_write_nonexisting_geojson(self):
     """
     Check if geoJSON is properly created from contours
     """
     contour = pydiva2d.Diva2DContours(self.xlist, self.ylist)
     self.assertRaises(FileNotFoundError,
                       lambda: contour.to_geojson(filename=self.nogeojsonfile))
Exemple #3
0
 def test_init_list(self):
     """
     Instantiate Contour object with a list of lists
     """
     contour = pydiva2d.Diva2DContours(self.xlist, self.ylist)
     np.testing.assert_array_equal(contour.x, self.xlist)
     np.testing.assert_array_equal(contour.y, self.ylist)
     self.assertEqual(contour.get_contours_number, 2)
Exemple #4
0
 def test_init(self):
     """
     Instantiate Contour object with pre-set values
     """
     contour = pydiva2d.Diva2DContours(self.xx, self.yy)
     np.testing.assert_array_equal(contour.x, self.xx)
     np.testing.assert_array_equal(contour.y, self.yy)
     self.assertEqual(contour.get_contours_number, 2)
Exemple #5
0
 def test_read_file(self):
     """
     Instantiate Contour object reading an existing file
     """
     contour = pydiva2d.Diva2DContours().read_from(self.coastfile)
     self.assertEqual(contour.get_contours_number, 28)
     self.assertEqual(len(contour.x), 28)
     self.assertEqual(len(contour.y), 28)
     self.assertEqual(len(contour.x[0]), 576)
     self.assertEqual(len(contour.y[1]), 16)
     self.assertEqual(len(contour.x[-1]), 6)
Exemple #6
0
    def test_write_file(self):
        """
        Write a contour to a file
        """
        contour = pydiva2d.Diva2DContours(self.xx, self.yy)
        contour.write_to(self.outputfile)

        self.assertTrue(os.path.exists(self.outputfile))
        with open(self.outputfile) as f:
            lines = f.readlines()
            lastline = lines[-1].rstrip()
            self.assertEqual(int(lines[0].rstrip()), 2)
            self.assertEqual(int(lines[1].rstrip()), 4)
            self.assertEqual(float(lastline.split()[0]), 7.4)
            self.assertEqual(len(lines), 11)
Exemple #7
0
    def setUpClass(cls):

        cls.divadir = "/home/ctroupin/Software/DIVA/DIVA-diva-4.7.1/"
        cls.contourfile = "./datawrite/coast.cont"
        cls.datafile = "./datawrite/data.dat"
        cls.paramfile = "./datawrite/param.par"

        # Create contour
        cls.xc = [[-10, 10, 10, -10]]
        cls.yc = [[-10, -10, 10, 10]]
        contour = pydiva2d.Diva2DContours(cls.xc, cls.yc)
        contour.write_to(cls.contourfile)

        # Create parameter file
        parameters = pydiva2d.Diva2DParameters(3., 0, 11, 0, -10., -10., 0.1, 0.1,
                                               201, 201, -99, 1.0, 1.)
        parameters.write_to(cls.paramfile)

        # Create datafile
        data = pydiva2d.Diva2DData(x=[0], y=[0], field=[1.], weight=[1.])
        data.write_to(cls.datafile)
Exemple #8
0
 def test_read_nonexisting_file(self):
     """
     Try instantiate Contour object reading an non-existing file
     """
     self.assertRaises(FileNotFoundError,
                       lambda: pydiva2d.Diva2DContours().read_from(self.nocoastfile))