Пример #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)
Пример #2
0
    def test_generate_basic_project(self):
        """
        Tests generating a basic GSSHA project
        """

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

        # ADD MASK
        mask_name = '{0}.msk'.format(project_name)
        msk_file = WatershedMaskFile(project_file=project_manager,
                                     session=self.db_session)

        msk_file.generateFromWatershedShapefile(
            self.shapefile_path,
            cell_size=1000,
            out_raster_path=mask_name,
        )

        # ADD ELEVATION FILE
        ele_file = ElevationGridFile(project_file=project_manager,
                                     session=self.db_session)
        ele_file.generateFromRaster(self.elevation_path, self.shapefile_path)

        # ADD OUTLET POINT
        project_manager.setOutlet(col=0, row=6, outslope=0.002)

        # ADD ADDITIONAL REQUIRED FILES
        # see http://www.gsshawiki.com/Project_File:Required_Inputs
        project_manager.setCard('TOT_TIME', '180')
        project_manager.setCard('TIMESTEP', '10')
        project_manager.setCard('HYD_FREQ', '15')
        # see http://www.gsshawiki.com/Project_File:Output_Files_%E2%80%93_Required
        project_manager.setCard('SUMMARY',
                                '{0}.sum'.format(project_name),
                                add_quotes=True)
        project_manager.setCard('OUTLET_HYDRO',
                                '{0}.otl'.format(project_name),
                                add_quotes=True)
        # see http://www.gsshawiki.com/Project_File:Overland_Flow_%E2%80%93_Required
        project_manager.setCard('MANNING_N', '0.013')
        # see http://www.gsshawiki.com/Project_File:Rainfall_Input_and_Options_%E2%80%93_Required
        project_manager.setCard('PRECIP_UNIF', '')
        project_manager.setCard('RAIN_INTENSITY', '2.4')
        project_manager.setCard('RAIN_DURATION', '30')
        project_manager.setCard('START_DATE', '2017 02 28')
        project_manager.setCard('START_TIME', '14 33')

        # write data
        project_manager.writeInput(session=self.db_session,
                                   directory=self.gssha_project_directory,
                                   name=project_name)
        # compare
        self._compare_basic_model(project_name)
Пример #3
0
    def setUp(self):
        self.tearDown()
        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,
                                        'philippines_5070115700.shp')

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

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

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

        # copy shapefile
        shapefile_basename = path.join(self.readDirectory, 'philippines',
                                       'philippines_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
        self.project_manager, db_sessionmaker = \
            dbt.get_project_session('grid_standard_ele',
                                    self.gssha_project_directory)

        self.db_session = db_sessionmaker()

        # 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)
Пример #4
0
    def setUp(self):
        self.tearDown()
        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,
                                        'philippines_5070115700.shp')

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

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

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

        # copy shapefile
        shapefile_basename = path.join(self.readDirectory,
                                       'philippines',
                                       'philippines_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
        self.project_manager, db_sessionmaker = \
            dbt.get_project_session('grid_standard_ele',
                                    self.gssha_project_directory)

        self.db_session = db_sessionmaker()

        # 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)
Пример #5
0
    def test_generate_basic_project_land_cover(self):
        """
        Tests generating a basic GSSHA project with land cover
        """

        project_name = "grid_standard_basic_land_cover"
        # Instantiate GSSHAPY object for reading to database
        project_manager, db_sessionmaker = \
            dbt.get_project_session(project_name,
                                    self.gssha_project_directory,
                                    map_type=1)
        # Create DB Sessions
        db_session = db_sessionmaker()
        db_session.add(project_manager)
        db_session.commit()

        # ADD MASK
        mask_name = '{0}.msk'.format(project_name)
        msk_file = WatershedMaskFile(project_file=project_manager,
                                     session=db_session)

        msk_file.generateFromWatershedShapefile(self.shapefile_path,
                                                cell_size=1000,
                                                out_raster_path=mask_name,
                                                )

        # ADD ELEVATION FILE
        ele_file = ElevationGridFile(project_file=project_manager,
                                     session=db_session)
        ele_file.generateFromRaster(self.elevation_path,
                                    self.shapefile_path)

        # ADD ROUGHNESS FROM LAND COVER
        # see http://www.gsshawiki.com/Project_File:Overland_Flow_%E2%80%93_Required
        mapTableFile = MapTableFile(project_file=project_manager)
        mapTableFile.addRoughnessMapFromLandUse("roughness",
                                                db_session,
                                                self.land_use_grid,
                                                land_use_grid_id='glcf',
                                                )

        # ADD ADDITIONAL REQUIRED FILES
        # see http://www.gsshawiki.com/Project_File:Required_Inputs
        project_manager.setCard('TOT_TIME', '180')
        project_manager.setCard('TIMESTEP', '10')
        project_manager.setCard('HYD_FREQ', '15')
        # see http://www.gsshawiki.com/Project_File:Output_Files_%E2%80%93_Required
        project_manager.setCard('SUMMARY', '{0}.sum'.format(project_name), add_quotes=True)
        project_manager.setCard('OUTLET_HYDRO', '{0}.otl'.format(project_name), add_quotes=True)
        # see http://www.gsshawiki.com/Project_File:Rainfall_Input_and_Options_%E2%80%93_Required
        project_manager.setCard('PRECIP_UNIF', '')
        project_manager.setCard('RAIN_INTENSITY', '2.4')
        project_manager.setCard('RAIN_DURATION', '30')
        project_manager.setCard('START_DATE', '2017 02 28')
        project_manager.setCard('START_TIME', '14 33')

        # write data
        project_manager.writeInput(session=db_session,
                                   directory=self.gssha_project_directory,
                                   name=project_name)
        db_session.close()
        # compare main project files
        self._compare_basic_model_idx_maps(project_name)
Пример #6
0
    def test_generate_basic_project(self):
        """
        Tests generating a basic GSSHA project
        """

        project_name = "grid_standard_basic"
        # Instantiate GSSHAPY object for reading to database
        # Create Test DB
        project_manager, db_sessionmaker = \
            dbt.get_project_session(project_name,
                                    self.gssha_project_directory,
                                    map_type=1)
        # Create DB Sessions
        db_session = db_sessionmaker()
        db_session.add(project_manager)
        db_session.commit()

        # ADD MASK
        mask_name = '{0}.msk'.format(project_name)
        msk_file = WatershedMaskFile(project_file=project_manager,
                                     session=db_session)

        msk_file.generateFromWatershedShapefile(self.shapefile_path,
                                                cell_size=1000,
                                                out_raster_path=mask_name,
                                                )

        # ADD ELEVATION FILE
        ele_file = ElevationGridFile(project_file=project_manager,
                                     session=db_session)
        ele_file.generateFromRaster(self.elevation_path,
                                    self.shapefile_path)

        # ADD OUTLET POINT
        project_manager.setOutlet(col=0, row=6,
                                  outslope=0.002)

        # ADD ADDITIONAL REQUIRED FILES
        # see http://www.gsshawiki.com/Project_File:Required_Inputs
        project_manager.setCard('TOT_TIME', '180')
        project_manager.setCard('TIMESTEP', '10')
        project_manager.setCard('HYD_FREQ', '15')
        # see http://www.gsshawiki.com/Project_File:Output_Files_%E2%80%93_Required
        project_manager.setCard('SUMMARY', '{0}.sum'.format(project_name), add_quotes=True)
        project_manager.setCard('OUTLET_HYDRO', '{0}.otl'.format(project_name), add_quotes=True)
        # see http://www.gsshawiki.com/Project_File:Overland_Flow_%E2%80%93_Required
        project_manager.setCard('MANNING_N', '0.013')
        # see http://www.gsshawiki.com/Project_File:Rainfall_Input_and_Options_%E2%80%93_Required
        project_manager.setCard('PRECIP_UNIF', '')
        project_manager.setCard('RAIN_INTENSITY', '2.4')
        project_manager.setCard('RAIN_DURATION', '30')
        project_manager.setCard('START_DATE', '2017 02 28')
        project_manager.setCard('START_TIME', '14 33')

        # write data
        project_manager.writeInput(session=db_session,
                                   directory=self.gssha_project_directory,
                                   name=project_name)

        db_session.close()
        # compare
        self._compare_basic_model(project_name)
Пример #7
0
class TestElevation(TestGridTemplate):
    def setUp(self):
        self.tearDown()
        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,
                                        'philippines_5070115700.shp')

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

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

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

        # copy shapefile
        shapefile_basename = path.join(self.readDirectory, 'philippines',
                                       'philippines_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
        self.project_manager, db_sessionmaker = \
            dbt.get_project_session('grid_standard_ele',
                                    self.gssha_project_directory)

        self.db_session = db_sessionmaker()

        # 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)

    def test_generate_elevation_grid(self):
        """
        Tests generating an elevation grid from raster
        """
        self.ele_file.generateFromRaster(self.elevation_path,
                                         self.shapefile_path)

        # WRITE OUT UPDATED GSSHA PROJECT FILE
        self.project_manager.writeInput(session=self.db_session,
                                        directory=self.gssha_project_directory,
                                        name='grid_standard_ele')
        # compare ele
        new_mask_grid = path.join(self.gssha_project_directory,
                                  'grid_standard_ele.ele')
        compare_msk_file = path.join(self.compare_path,
                                     'grid_standard_ele.ele')
        self._compare_files(compare_msk_file, new_mask_grid, raster=True)
        # compare project files
        generated_prj_file = path.join(self.gssha_project_directory,
                                       'grid_standard_ele.prj')
        compare_prj_file = path.join(self.compare_path,
                                     'grid_standard_ele.prj')
        self._compare_files(generated_prj_file, compare_prj_file)
Пример #8
0
    def test_generate_basic_project_land_cover(self):
        """
        Tests generating a basic GSSHA project with land cover
        """

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

        # ADD MASK
        mask_name = '{0}.msk'.format(project_name)
        msk_file = WatershedMaskFile(project_file=project_manager,
                                     session=self.db_session)

        msk_file.generateFromWatershedShapefile(
            self.shapefile_path,
            cell_size=1000,
            out_raster_path=mask_name,
        )

        # ADD ELEVATION FILE
        ele_file = ElevationGridFile(project_file=project_manager,
                                     session=self.db_session)
        ele_file.generateFromRaster(self.elevation_path, self.shapefile_path)

        # ADD ROUGHNESS FROM LAND COVER
        # see http://www.gsshawiki.com/Project_File:Overland_Flow_%E2%80%93_Required
        mapTableFile = MapTableFile(project_file=project_manager)
        mapTableFile.addRoughnessMapFromLandUse(
            "roughness",
            self.db_session,
            self.land_use_grid,
            land_use_grid_id='glcf',
        )

        # ADD ADDITIONAL REQUIRED FILES
        # see http://www.gsshawiki.com/Project_File:Required_Inputs
        project_manager.setCard('TOT_TIME', '180')
        project_manager.setCard('TIMESTEP', '10')
        project_manager.setCard('HYD_FREQ', '15')
        # see http://www.gsshawiki.com/Project_File:Output_Files_%E2%80%93_Required
        project_manager.setCard('SUMMARY',
                                '{0}.sum'.format(project_name),
                                add_quotes=True)
        project_manager.setCard('OUTLET_HYDRO',
                                '{0}.otl'.format(project_name),
                                add_quotes=True)
        # see http://www.gsshawiki.com/Project_File:Rainfall_Input_and_Options_%E2%80%93_Required
        project_manager.setCard('PRECIP_UNIF', '')
        project_manager.setCard('RAIN_INTENSITY', '2.4')
        project_manager.setCard('RAIN_DURATION', '30')
        project_manager.setCard('START_DATE', '2017 02 28')
        project_manager.setCard('START_TIME', '14 33')

        # write data
        project_manager.writeInput(session=self.db_session,
                                   directory=self.gssha_project_directory,
                                   name=project_name)
        # compare main project files
        self._compare_basic_model_idx_maps(project_name)
Пример #9
0
class TestElevation(TestGridTemplate):
    def setUp(self):
        self.tearDown()
        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,
                                        'philippines_5070115700.shp')

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

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

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

        # copy shapefile
        shapefile_basename = path.join(self.readDirectory,
                                       'philippines',
                                       'philippines_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
        self.project_manager, db_sessionmaker = \
            dbt.get_project_session('grid_standard_ele',
                                    self.gssha_project_directory)

        self.db_session = db_sessionmaker()

        # 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)

    def test_generate_elevation_grid(self):
        """
        Tests generating an elevation grid from raster
        """
        self.ele_file.generateFromRaster(self.elevation_path,
                                         self.shapefile_path)

        # WRITE OUT UPDATED GSSHA PROJECT FILE
        self.project_manager.writeInput(session=self.db_session,
                                        directory=self.gssha_project_directory,
                                        name='grid_standard_ele')
        # compare ele
        new_mask_grid = path.join(self.gssha_project_directory, 'grid_standard_ele.ele')
        compare_msk_file = path.join(self.compare_path, 'grid_standard_ele.ele')
        self._compare_files(compare_msk_file, new_mask_grid, raster=True)
        # compare project files
        generated_prj_file = path.join(self.gssha_project_directory, 'grid_standard_ele.prj')
        compare_prj_file = path.join(self.compare_path, 'grid_standard_ele.prj')
        self._compare_files(generated_prj_file, compare_prj_file)