Exemple #1
0
    def setUp(self):
        self.gssha_project_directory = path.join(self.writeDirectory,
                                                 'gssha_project')
        self.gssha_project_file = 'grid_standard_basic.prj'

        self.elevation_path = path.join(self.writeDirectory,
                                        'gmted_elevation.tif')

        self.shapefile_path = path.join(self.writeDirectory,
                                        'phillipines_5070115700.shp')

        self.compare_path = path.join(self.readDirectory, 'phillipines',
                                      'compare_data')

        # copy gssha project
        try:
            copytree(
                path.join(self.readDirectory, 'phillipines', 'gssha_project'),
                self.gssha_project_directory)
        except OSError:
            pass

        # copy elevation grid
        try:
            copy(
                path.join(self.readDirectory, 'phillipines',
                          'gmted_elevation.tif'), self.elevation_path)
        except OSError:
            pass

        # copy shapefile
        shapefile_basename = path.join(self.readDirectory, 'phillipines',
                                       'phillipines_5070115700.*')

        for shapefile_part in glob(shapefile_basename):
            try:
                copy(
                    shapefile_part,
                    path.join(self.writeDirectory,
                              path.basename(shapefile_part)))
            except OSError:
                pass

        # Create Test DB
        sqlalchemy_url, sql_engine = dbt.init_sqlite_memory()

        # Create DB Sessions
        self.db_session = dbt.create_session(sqlalchemy_url, sql_engine)

        # Instantiate GSSHAPY object for reading to database
        self.project_manager = ProjectFile(name='grid_standard_ele')

        # read project file
        self.project_manager.readInput(directory=self.gssha_project_directory,
                                       projectFileName=self.gssha_project_file,
                                       session=self.db_session)
        self.ele_file = ElevationGridFile(project_file=self.project_manager,
                                          session=self.db_session)
        chdir(self.gssha_project_directory)
Exemple #2
0
    def setUp(self):
        # Find db directory path
        here = os.path.abspath(os.path.dirname(__file__))

        # Create Test DB
        sqlalchemy_url, sql_engine = dbt.init_sqlite_memory()

        # Create DB Sessions
        self.readSession = dbt.create_session(sqlalchemy_url, sql_engine)
        self.querySession = dbt.create_session(sqlalchemy_url, sql_engine)

        # Define directory of test files to read
        self.directory = os.path.join(here, 'standard')
Exemple #3
0
    def test_add_land_cover_map_table(self):
        """
        Tests adding land cover to map table
        """
        land_use_to_roughness_table = path.join(path.dirname(path.realpath(__file__)),
                                                '..', 'gsshapy',
                                                'grid', 'land_cover',
                                                'land_cover_glcf_modis.txt'
                                                )
        chdir(self.gssha_project_directory)

        # Create Test DB
        sqlalchemy_url, sql_engine = dbt.init_sqlite_memory()

        # Create DB Sessions
        db_session = dbt.create_session(sqlalchemy_url, sql_engine)

        # Instantiate GSSHAPY object for reading to database
        project_manager = ProjectFile()

        # Call read method
        project_manager.readInput(directory=self.gssha_project_directory,
                                  projectFileName=self.gssha_project_file,
                                  session=db_session)

        project_manager.mapTableFile.addRoughnessMapFromLandUse("roughness",
                                                                db_session,
                                                                self.land_use_grid,
                                                                land_use_to_roughness_table,
                                                                #land_use_grid_id='glcf',
                                                                )
        # WRITE OUT UPDATED GSSHA PROJECT FILE
        project_manager.writeInput(session=db_session,
                                   directory=self.gssha_project_directory,
                                   name=path.splitext(self.gssha_project_file)[0])

        db_session.close()

        # compare prj
        original_prj_file = path.join(self.readDirectory, 'land_cover', 'grid_standard.prj')
        new_prj_file = path.join(self.gssha_project_directory, 'grid_standard.prj')
        self._compare_files(original_prj_file, new_prj_file)
        # compare cmt
        original_cmt_file = path.join(self.readDirectory, 'land_cover', 'grid_standard.cmt')
        new_cmt_file = path.join(self.gssha_project_directory, 'grid_standard.cmt')
        self._compare_files(original_cmt_file, new_cmt_file)
        # compare idx
        original_idx_file = path.join(self.readDirectory, 'land_cover', 'roughness.idx')
        new_idx_file = path.join(self.gssha_project_directory, 'roughness.idx')
        self._compare_files(original_idx_file, new_idx_file, raster=True)
Exemple #4
0
    def setUp(self):
        # Find db directory path
        here = os.path.abspath(os.path.dirname(__file__))

        # Create Test DB
        sqlalchemy_url, sql_engine = dbt.init_sqlite_memory()

        # Create DB Sessions
        session_maker = dbt.get_sessionmaker(sqlalchemy_url, sql_engine)
        self.readSession = session_maker()
        self.querySession = session_maker()

        # Define directory of test files to read
        self.directory = os.path.join(here, 'standard')
    def setUp(self):
        self.compare_path = path.join(self.readDirectory, 'phillipines',
                                      'compare_data')

        self.gssha_project_directory = self.writeDirectory

        self.shapefile_path = path.join(self.writeDirectory,
                                        'phillipines_5070115700.shp')

        self.elevation_path = path.join(self.writeDirectory,
                                        'gmted_elevation.tif')
        self.land_use_grid = path.join(self.writeDirectory,
                                       'LC_hd_global_2012.tif')

        # copy shapefile
        shapefile_basename = path.join(self.readDirectory, 'phillipines',
                                       'phillipines_5070115700.*')

        for shapefile_part in glob(shapefile_basename):
            try:
                copy(
                    shapefile_part,
                    path.join(self.writeDirectory,
                              path.basename(shapefile_part)))
            except OSError:
                pass

        # copy elevation grid
        try:
            copy(
                path.join(self.readDirectory, 'phillipines',
                          'gmted_elevation.tif'), self.elevation_path)
        except OSError:
            pass

        # copy land cover data
        try:
            copy(
                path.join(self.readDirectory, 'land_cover',
                          'LC_hd_global_2012.tif'), self.land_use_grid)
        except OSError:
            pass

        # Create Test DB
        sqlalchemy_url, sql_engine = dbt.init_sqlite_memory()

        # Create DB Sessions
        self.db_session = dbt.create_session(sqlalchemy_url, sql_engine)
Exemple #6
0
    def test_add_land_cover_map_table_twice(self):
        """
        Tests adding land cover to map table run twice
        """
        # Create Test DB
        sqlalchemy_url, sql_engine = dbt.init_sqlite_memory()
        session_maker = dbt.get_sessionmaker(sqlalchemy_url, sql_engine)
        # run twice to ensure uniqueness
        for i in range(2):
            # Create DB Sessions
            db_session = session_maker()

            # Instantiate GSSHAPY object for reading to database
            project_manager = ProjectFile()

            # Call read method
            project_manager.readInput(directory=self.gssha_project_directory,
                                      projectFileName=self.gssha_project_file,
                                      session=db_session)

            project_manager.mapTableFile.addRoughnessMapFromLandUse("roughness",
                                                                    db_session,
                                                                    self.land_use_grid,
                                                                    land_use_grid_id='glcf',
                                                                    )
            # WRITE OUT UPDATED GSSHA PROJECT FILE
            project_manager.writeInput(session=db_session,
                                       directory=self.gssha_project_directory,
                                       name=path.splitext(self.gssha_project_file)[0])

            db_session.close()

        # compare prj
        original_prj_file = path.join(self.readDirectory, 'land_cover', 'grid_standard.prj')
        new_prj_file = path.join(self.gssha_project_directory, 'grid_standard.prj')
        self._compare_files(original_prj_file, new_prj_file)
        # compare cmt
        original_cmt_file = path.join(self.readDirectory, 'land_cover', 'grid_standard.cmt')
        new_cmt_file = path.join(self.gssha_project_directory, 'grid_standard.cmt')
        self._compare_files(original_cmt_file, new_cmt_file)
        # compare idx
        original_idx_file = path.join(self.readDirectory, 'land_cover', 'roughness.idx')
        new_idx_file = path.join(self.gssha_project_directory, 'roughness.idx')
        self._compare_files(original_idx_file, new_idx_file, raster=True)
Exemple #7
0
    def setUp(self):
        self.gssha_project_directory = self.writeDirectory

        self.shapefile_path = path.join(self.writeDirectory,
                                        'phillipines_5070115700.shp')

        self.compare_path = path.join(self.readDirectory, 'phillipines',
                                      'compare_data')
        # copy shapefile
        shapefile_basename = path.join(self.readDirectory, 'phillipines',
                                       'phillipines_5070115700.*')

        for shapefile_part in glob(shapefile_basename):
            try:
                copy(
                    shapefile_part,
                    path.join(self.writeDirectory,
                              path.basename(shapefile_part)))
            except OSError:
                pass

        # Create Test DB
        sqlalchemy_url, sql_engine = dbt.init_sqlite_memory()

        # Create DB Sessions
        self.db_session = dbt.create_session(sqlalchemy_url, sql_engine)

        # Instantiate GSSHAPY object for reading to database
        self.project_manager = ProjectFile(name="grid_standard_msk",
                                           map_type=1)
        self.db_session.add(self.project_manager)
        self.db_session.commit()

        self.msk_file = WatershedMaskFile(project_file=self.project_manager,
                                          session=self.db_session)
        chdir(self.gssha_project_directory)