Exemplo n.º 1
0
class TestGeotiffWriter(TestDerivedRemoteDataPipeline):

    _test_dir = 'test_tmp_dir'
    _log_filename = 'geotiff_writer.log'
    _handle = 'geotiff'
    _features = ["z", "feature_1", "feature_2"]
    _n_subregions = (2, 2)

    def setUp(self):
        os.mkdir(self._test_dir)
        indices = [(nx, ny) for nx in [10, 11] for ny in [12, 13]]
        write_PLY_targets(self._test_dir, indices=indices)
        self.pipeline = GeotiffWriter()

    def tearDown(self):
        shutil.rmtree(self._test_dir)

    @property
    def input(self):
        _input = {
            'log_config': {
                'filename': self._log_filename
            },
            'setup_local_fs': {
                'input_folder': self._test_dir,
                'output_folder': self._test_dir,
            },
            "parse_point_cloud": {},
            "data_split": {"xSub": self._n_subregions[0],
                           "ySub": self._n_subregions[1]},
            "create_subregion_geotiffs": {
                "output_handle": self._handle,
            }
        }
        return _input

    def test_FullPipeline(self):
        self.pipeline.bands = self._features
        self.pipeline.input = self.input
        self.pipeline.run()

        # log file is present
        self.assertTrue(os.path.join(self._test_dir, self._log_filename))

        # geotiff files are present
        index = 0
        for nx in range(self._n_subregions[0]):
            for ny in range(self._n_subregions[1]):
                for feature in self._features:
                    file_name = '{}_TILE_{:03d}_BAND_{}.tif'.format(self._handle,
                                                                    index,
                                                                    feature)
                    file_path = os.path.join(self._test_dir, file_name)
                    print(file_path)
                    self.assertTrue(os.path.isfile(file_path))
                index += 1
Exemplo n.º 2
0
 def setUp(self):
     os.mkdir(self._test_dir)
     self.pipeline = GeotiffWriter()
     self.pipeline.input_folder = pathlib.Path(self._test_dir)
     self.pipeline.output_folder = pathlib.Path(self._test_dir)
     self.pipeline.LengthDataRecord = self._n_points_per_tile_and_dim**2
     self.pipeline.xResolution = self._grid_spacing
     self.pipeline.yResolution = self._grid_spacing
     self.pipeline.subtilelists = [['tile_{}_{}.ply'.format(nx, ny)]
                                   for (nx, ny) in self._tile_indices]
Exemplo n.º 3
0
class test_DataSplit(unittest.TestCase):

    _indices = [(100, 101), (101, 100), (101, 101), (103, 103)]

    def setUp(self):
        self.pipeline = GeotiffWriter()

    def test_validInput(self):
        _tiles = [
            'tile_{}_{}.ply'.format(nx, ny) for (nx, ny) in self._indices
        ]
        self.pipeline.InputTiles = _tiles
        self.pipeline.data_split(len(self._indices), len(self._indices))
        for tile in _tiles:
            self.assertIn([tile], self.pipeline.subtilelists)

    def test_emptyInputTiles(self):
        self.pipeline.InputTiles = []
        with self.assertRaises(ValueError):
            self.pipeline.data_split(2, 2)

    def test_inputTilesNotSet(self):
        with self.assertRaises(ValueError):
            self.pipeline.data_split(2, 2)
Exemplo n.º 4
0
 def setUp(self):
     os.mkdir(self._test_dir)
     indices = [(nx, ny) for nx in [10, 11] for ny in [12, 13]]
     write_PLY_targets(self._test_dir, indices=indices)
     self.pipeline = GeotiffWriter()
Exemplo n.º 5
0
 def setUp(self):
     self.pipeline = GeotiffWriter()
Exemplo n.º 6
0
 def setUp(self):
     os.mkdir(self._test_dir)
     self.pipeline = GeotiffWriter()
Exemplo n.º 7
0
class TestCreateSubregionGeotiffs(unittest.TestCase):

    _test_dir = 'test_tmp_dir'
    _tile_indices = [(100, 100), (100, 101), (101, 100), (101, 101)]
    _n_points_per_tile_and_dim = 10
    _grid_spacing = 10

    def setUp(self):
        os.mkdir(self._test_dir)
        self.pipeline = GeotiffWriter()
        self.pipeline.input_folder = pathlib.Path(self._test_dir)
        self.pipeline.output_folder = pathlib.Path(self._test_dir)
        self.pipeline.LengthDataRecord = self._n_points_per_tile_and_dim**2
        self.pipeline.xResolution = self._grid_spacing
        self.pipeline.yResolution = self._grid_spacing
        self.pipeline.subtilelists = [['tile_{}_{}.ply'.format(nx, ny)]
                                      for (nx, ny) in self._tile_indices]

    def tearDown(self):
        shutil.rmtree(self._test_dir)

    def test_validInput(self):
        write_PLY_targets(self._test_dir,
                          indices=self._tile_indices,
                          grid_spacing=self._grid_spacing,
                          nx_values=self._n_points_per_tile_and_dim)
        self.pipeline.bands = ['feature_1']
        self.pipeline.create_subregion_geotiffs('geotiff')
        self.assertEqual(
            len([
                f for f in os.listdir(self._test_dir)
                if f.startswith('geotiff')
            ]), 4)

    def test_validInputOneSubregion(self):
        write_PLY_targets(self._test_dir,
                          indices=self._tile_indices,
                          grid_spacing=self._grid_spacing,
                          nx_values=self._n_points_per_tile_and_dim)
        self.pipeline.subtilelists = [[
            'tile_{}_{}.ply'.format(nx, ny) for (nx, ny) in self._tile_indices
        ]]
        self.pipeline.bands = ['feature_1']
        self.pipeline.create_subregion_geotiffs('geotiff')
        self.assertEqual(
            len([
                f for f in os.listdir(self._test_dir)
                if f.startswith('geotiff')
            ]), 1)

    def test_emptySubTileList(self):
        self.pipeline.subtilelists = []
        self.pipeline.bands = ['feature_1']
        self.pipeline.create_subregion_geotiffs('geotiff')
        self.assertEqual(
            len([
                f for f in os.listdir(self._test_dir)
                if f.startswith('geotiff')
            ]), 0)

    def test_inputFolderNonexistent(self):
        self.pipeline.input_folder = pathlib.Path(
            self._test_dir).joinpath('tmp')
        self.pipeline.bands = ['feature_1']
        with self.assertRaises(FileNotFoundError):
            self.pipeline.create_subregion_geotiffs('geotiff')

    def test_outputFolderNonexistent(self):
        self.pipeline.output_folder = pathlib.Path(
            self._test_dir).joinpath('tmp')
        self.pipeline.bands = ['feature_1']
        with self.assertRaises(FileNotFoundError):
            self.pipeline.create_subregion_geotiffs('geotiff')
Exemplo n.º 8
0
class test_parsePointCloud(unittest.TestCase):

    _test_dir = 'test_tmp_dir'
    _tile_indices = [(0, 0), (0, 1)]
    _n_points_per_tile_and_dim = 10
    _grid_spacing = 10

    def setUp(self):
        os.mkdir(self._test_dir)
        self.pipeline = GeotiffWriter()

    def tearDown(self):
        shutil.rmtree(self._test_dir)

    def test_tileList(self):
        write_PLY_targets(self._test_dir,
                          indices=self._tile_indices,
                          grid_spacing=self._grid_spacing,
                          nx_values=self._n_points_per_tile_and_dim)
        self.pipeline.input_folder = self._test_dir
        self.pipeline.parse_point_cloud()
        expected_tile_list = [
            'tile_{}_{}.ply'.format(nx, ny) for (nx, ny) in self._tile_indices
        ]
        self.assertListEqual(sorted(self.pipeline.InputTiles),
                             sorted(expected_tile_list))

    def test_lengthDataRecord(self):
        write_PLY_targets(self._test_dir,
                          indices=self._tile_indices,
                          grid_spacing=self._grid_spacing,
                          nx_values=self._n_points_per_tile_and_dim)
        self.pipeline.input_folder = self._test_dir
        self.pipeline.parse_point_cloud()
        expected_lenght = self._n_points_per_tile_and_dim**2
        self.assertEqual(self.pipeline.LengthDataRecord, expected_lenght)

    def test_resolution(self):
        write_PLY_targets(self._test_dir,
                          indices=self._tile_indices,
                          grid_spacing=self._grid_spacing,
                          nx_values=self._n_points_per_tile_and_dim)
        self.pipeline.input_folder = self._test_dir
        self.pipeline.parse_point_cloud()
        self.assertEqual(self.pipeline.xResolution, self._grid_spacing)
        self.assertEqual(self.pipeline.yResolution, self._grid_spacing)

    def test_singleBandFiles(self):
        write_PLY_targets(self._test_dir,
                          indices=self._tile_indices,
                          grid_spacing=self._grid_spacing,
                          nx_values=self._n_points_per_tile_and_dim,
                          feature='feature_1')
        self.pipeline.input_folder = self._test_dir
        self.pipeline.parse_point_cloud()
        expected_lenght = self._n_points_per_tile_and_dim**2
        self.assertEqual(self.pipeline.LengthDataRecord, expected_lenght)

    def test_singlePointPLYFile(self):
        write_PLY_targets(self._test_dir,
                          indices=self._tile_indices,
                          grid_spacing=self._grid_spacing,
                          nx_values=1)
        self.pipeline.input_folder = self._test_dir
        with self.assertRaises(ValueError):
            self.pipeline.parse_point_cloud()

    def test_inputFolderNonexistent(self):
        self.pipeline.input_folder = os.path.join(self._test_dir, 'tmp')
        with self.assertRaises(FileNotFoundError):
            self.pipeline.parse_point_cloud()

    def test_emptyDirectory(self):
        self.pipeline.input_folder = self._test_dir
        with self.assertRaises(IOError):
            self.pipeline.parse_point_cloud()