示例#1
0
 def get_stack_data():
     dirname = Path("tests/topography")
     basename = Path("N38E083.SRTMGL1.hgt")
     path = dirname / basename
     if not path.exists():
         try:
             os.makedirs(dirname)
         except OSError:
             pass
         with path.open("wb") as f:
             f.write(store.get(basename))
     return dirname
示例#2
0
    def get_data(tag):
        """Get test data from the store"""
        path = Path(__file__).parent / f"data/{tag}"

        if not path.exists():
            tgz_name = f"{tag}-test.tar"
            tgz_path = path / (tgz_name + ".gz")
            tgz = store.get(tgz_name)
            path.mkdir(parents=True)
            with tgz_path.open("wb") as f:
                f.write(tgz)
            with tarfile.open(tgz_path, "r|*") as tar:
                tar.extractall(path)
            tgz_path.unlink()

        return path
示例#3
0
    def test_custom_topography(self):
        # Fetch a test tile
        dirname, basename = Path("tests/topography"), "N39E090.SRTMGL1.hgt"
        path = dirname / basename
        if not path.exists():
            dirname.mkdir(exist_ok=True)
            with path.open("wb") as f:
                f.write(store.get(basename))

        # Test the topography getter
        topo = Topography(dirname)
        c = ECEF(
            GeodeticRepresentation(latitude=39.5 * u.deg,
                                   longitude=90.5 * u.deg))
        z = topo.elevation(c)
        self.assertEqual(z.size, 1)
        self.assertEqual(z.unit, u.m)
        self.assertFalse(numpy.isnan(z))
示例#4
0
    def test_stack(self):
        # Fetch a test tile
        dirname, basename = "tests/topography", "N38E083.SRTMGL1.hgt"
        path = os.path.join(dirname, basename)
        if not os.path.exists(path):
            try:
                os.makedirs(dirname)
            except OSError:
                pass
            with open(path, "wb") as f:
                f.write(store.get(basename))

        # Check the stack initalisation
        stack = turtle.Stack(dirname)
        self.assertNotEqual(stack._stack, None)
        self.assertEqual(stack.path, dirname)
        self.assertEqual(stack.stack_size, 0)

        # Check the elevation getter for a single entry
        elevation = stack.elevation(38.5, 83.5)
        self.assertFalse(numpy.isnan(elevation))

        # Check the elevation getter for out of map entries
        elevation = stack.elevation(45.5, 3.5)
        self.assertTrue(numpy.isnan(elevation))

        # Check the elevation getter for vectorized entries
        n = 10
        elevation = stack.elevation(n * (38.5, ), n * (83.5, ))
        for i in range(n):
            self.assertFalse(numpy.isnan(elevation[i]))

        # Check the manual deletion
        del stack

        # Check the empty stack initalisation
        stack = turtle.Stack("")
        self.assertNotEqual(stack._stack, None)
        self.assertEqual(stack.path, "")
        self.assertEqual(stack.stack_size, 0)

        # Check the elevation getter for empty entries
        elevation = stack.elevation(45.5, 3.5)
        self.assertTrue(numpy.isnan(elevation))