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')
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)
def setUp(self): # Find db directory path here = os.path.abspath(os.path.dirname(__file__)) dbName = '%s.db' % uuid.uuid4() self.db_path = os.path.join(here, 'db', 'standard.db') # Create Test DB sqlalchemy_url = dbt.init_sqlite_db(self.db_path) # Define workspace self.readDirectory = os.path.join(here, 'standard') self.writeDirectory = os.path.join(here, 'out') self.original = 'standard' self.name = 'standard' self.dir_list = ('run_2014_to_2017', 'run_2014_to_2017_2', 'run_2015_to_2017', 'run_2015_to_2017_1', 'run_2016_to_2017') for subdir in self.dir_list: try: os.mkdir(os.path.join(self.readDirectory, subdir)) except OSError: pass # Create DB Sessions readSession = dbt.create_session(sqlalchemy_url) # Instantiate GSSHAPY ProjectFile object prjR = ProjectFile() # Invoke read project method prjR.readProject(directory=self.readDirectory, projectFileName='standard.prj', session=readSession) readSession.close() # create write session self.writeSession = dbt.create_session(sqlalchemy_url)
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)
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)
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)
******************************************************************************** * Name: Tutorial Script * Description: This script summarizes the steps followed in the GsshaPy tutorial * Author: Nathan Swain * Created On: July 30, 2014 * Copyright: (c) Brigham Young University 2013 * License: BSD 2-Clause ******************************************************************************** """ # Create a GsshaPy PostGIS database from gsshapy.lib import db_tools as dbt sqlalchemy_url = dbt.sqlalchemy_url = dbt.init_postgresql_db(username='******', host='localhost', database='gsshapy_tutorial', port='5432', password='******') # Create SQLAlchemy session object for db interaction session = dbt.create_session(sqlalchemy_url) # Read Files to a Database --------------------------------------------------------------------------------------------# # Instantiate ProjectFile file object from gsshapy.orm import ProjectFile projectFile = ProjectFile() # Read file into database readDirectory = '/path_to/tutorial-data' filename = 'parkcity.prj' projectFile.read(directory=readDirectory, filename=filename, session=session) # Inspect supporting objects projectCards = projectFile.projectCards
* Copyright: (c) Brigham Young University 2013 * License: BSD 2-Clause ******************************************************************************** """ # Create a GsshaPy PostGIS database from gsshapy.lib import db_tools as dbt sqlalchemy_url = dbt.sqlalchemy_url = dbt.init_postgresql_db( username='******', host='localhost', database='gsshapy_tutorial', port='5432', password='******') # Create SQLAlchemy session object for db interaction session = dbt.create_session(sqlalchemy_url) # Read Files to a Database --------------------------------------------------------------------------------------------# # Instantiate ProjectFile file object from gsshapy.orm import ProjectFile projectFile = ProjectFile() # Read file into database readDirectory = '/path_to/tutorial-data' filename = 'parkcity.prj' projectFile.read(directory=readDirectory, filename=filename, session=session) # Inspect supporting objects projectCards = projectFile.projectCards