Beispiel #1
0
    def parameters_extraction(cfg, maindb):
        """Main entrance for terrain related spatial parameters extraction."""
        f = cfg.logs.extract_terrain
        landuse_shp = cfg.landuse_shp
        # 1. Calculate initial channel width by accumulated area and add width to reach.shp.
        status_output(
            "Calculate initial channel width and added to reach.shp...", 10, f)
        acc_file = cfg.spatials.d8acc
        channel_width_file = cfg.spatials.chwidth
        channel_shp_file = cfg.vecs.reach
        streamlink_file = cfg.spatials.stream_link
        chwidth_data = TerrainUtilClass.calculate_channel_width(
            acc_file, channel_width_file)
        TerrainUtilClass.add_channel_width_to_shp(channel_shp_file,
                                                  streamlink_file,
                                                  chwidth_data,
                                                  cfg.default_reach_depth)
        # 2. Initialize depression storage capacity
        status_output("Generating depression storage capacity...", 20, f)
        slope_file = cfg.spatials.slope
        soil_texture_file = cfg.spatials.soil_texture
        landuse_file = cfg.spatials.landuse
        depression_file = cfg.spatials.depression
        TerrainUtilClass.depression_capacity(maindb, landuse_file,
                                             soil_texture_file, slope_file,
                                             depression_file, landuse_shp,
                                             cfg.imper_perc_in_urban)
        # 2. Calculate inputs for IUH
        status_output("Prepare parameters for IUH...", 30, f)
        radius_file = cfg.spatials.radius
        TerrainUtilClass.hydrological_radius(acc_file, radius_file, "T2")
        manning_file = cfg.spatials.manning
        velocity_file = cfg.spatials.velocity
        TerrainUtilClass.flow_velocity(slope_file, radius_file, manning_file,
                                       velocity_file)
        flow_dir_file = cfg.spatials.d8flow
        t0_s_file = cfg.spatials.t0_s
        flow_model_code = "ArcGIS"
        TerrainUtilClass.flow_time_to_stream(streamlink_file, velocity_file,
                                             flow_dir_file, t0_s_file,
                                             flow_model_code)
        delta_s_file = cfg.spatials.delta_s
        TerrainUtilClass.std_of_flow_time_to_stream(streamlink_file,
                                                    flow_dir_file, slope_file,
                                                    radius_file, velocity_file,
                                                    delta_s_file,
                                                    flow_model_code)
        # IUH calculation and import to MongoDB are implemented in db_build_mongodb.py
        # 3. Calculate position (i.e. latitude) related parameters
        status_output("Calculate latitude dependent parameters...", 40, f)
        lat_file = cfg.spatials.cell_lat
        min_dayl_file = cfg.spatials.dayl_min
        dormhr_file = cfg.spatials.dorm_hr
        TerrainUtilClass.calculate_latitude_dependent_parameters(
            lat_file, min_dayl_file, dormhr_file, cfg.dorm_hr)

        status_output("Terrain related spatial parameters extracted done!",
                      100, f)
Beispiel #2
0
    def parameters_extraction(cfg, maindb):
        """Main entrance for terrain related spatial parameters extraction."""
        f = cfg.logs.extract_terrain
        # 1. Calculate initial channel width by accumulated area and add width to reach.shp.
        status_output('Calculate initial channel width and added to reach.shp...', 10, f)
        acc_file = cfg.spatials.d8acc
        channel_width_file = cfg.spatials.chwidth
        channel_depth_file = cfg.spatials.chdepth
        channel_shp_file = cfg.vecs.reach
        streamlink_file = cfg.spatials.stream_link
        TerrainUtilClass.calculate_channel_width_depth(acc_file,
                                                       channel_width_file,
                                                       channel_depth_file)
        TerrainUtilClass.add_channel_width_depth_to_shp(channel_shp_file, streamlink_file,
                                                        channel_width_file,
                                                        channel_depth_file)
        # 2. Initialize depression storage capacity
        status_output('Generating depression storage capacity...', 20, f)
        slope_file = cfg.spatials.slope
        soil_texture_file = cfg.spatials.soil_texture
        landuse_file = cfg.spatials.landuse
        depression_file = cfg.spatials.depression
        TerrainUtilClass.depression_capacity(maindb, landuse_file, soil_texture_file,
                                             slope_file, depression_file, cfg.imper_perc_in_urban)
        # 2. Calculate inputs for IUH
        status_output('Prepare parameters for IUH...', 30, f)
        radius_file = cfg.spatials.radius
        TerrainUtilClass.hydrological_radius(acc_file, radius_file, 'T2')
        manning_file = cfg.spatials.manning
        velocity_file = cfg.spatials.velocity
        TerrainUtilClass.flow_velocity(slope_file, radius_file, manning_file, velocity_file)
        flow_dir_file = cfg.spatials.d8flow
        t0_s_file = cfg.spatials.t0_s
        flow_model_code = 'ArcGIS'
        TerrainUtilClass.flow_time_to_stream(streamlink_file, velocity_file, flow_dir_file,
                                             t0_s_file, flow_model_code)
        delta_s_file = cfg.spatials.delta_s
        TerrainUtilClass.std_of_flow_time_to_stream(streamlink_file, flow_dir_file, slope_file,
                                                    radius_file, velocity_file, delta_s_file,
                                                    flow_model_code)
        # IUH calculation and import to MongoDB are implemented in db_build_mongodb.py
        # 3. Calculate position (i.e. latitude) related parameters
        status_output('Calculate latitude dependent parameters...', 40, f)
        lat_file = cfg.spatials.cell_lat
        min_dayl_file = cfg.spatials.dayl_min
        dormhr_file = cfg.spatials.dorm_hr
        TerrainUtilClass.calculate_latitude_dependent_parameters(lat_file, min_dayl_file,
                                                                 dormhr_file, cfg.dorm_hr)

        status_output('Terrain related spatial parameters extracted done!', 100, f)
Beispiel #3
0
    def parameters_extraction(cfg):
        """Soil spatial parameters extraction."""
        f = cfg.logs.extract_soil
        # 1. Calculate soil physical and chemical parameters
        soiltype_file = cfg.spatials.soil_type
        status_output("Calculating initial soil physical and chemical parameters...", 30, f)
        SoilUtilClass.lookup_soil_parameters(cfg.dirs.geodata2db, soiltype_file, cfg.soil_property)

        # other soil related spatial parameters
        # 3. Initial soil moisture
        status_output("Calculating initial soil moisture...", 40, f)
        acc_file = cfg.spatials.d8acc
        slope_file = cfg.spatials.slope
        out_filename = cfg.spatials.init_somo
        SoilUtilClass.initial_soil_moisture(acc_file, slope_file, out_filename)

        status_output("Soil related spatial parameters extracted done!", 100, f)
Beispiel #4
0
    def parameters_extraction(cfg):
        """Soil spatial parameters extraction."""
        f = cfg.logs.extract_soil
        # 1. Calculate soil physical and chemical parameters
        soiltype_file = cfg.spatials.soil_type
        status_output(
            "Calculating initial soil physical and chemical parameters...", 30,
            f)
        SoilUtilClass.lookup_soil_parameters(cfg.dirs.geodata2db,
                                             soiltype_file, cfg.soil_property)

        # other soil related spatial parameters
        # 3. Initial soil moisture
        status_output("Calculating initial soil moisture...", 40, f)
        acc_file = cfg.spatials.d8acc
        slope_file = cfg.spatials.slope
        out_filename = cfg.spatials.init_somo
        SoilUtilClass.initial_soil_moisture(acc_file, slope_file, out_filename)

        status_output("Soil related spatial parameters extracted done!", 100,
                      f)
    def workflow(cfg):
        """Building MongoDB workflow"""
        f = cfg.logs.build_mongo
        # build a connection to mongodb database
        client = ConnectMongoDB(cfg.hostname, cfg.port)
        conn = client.get_conn()
        maindb = conn[cfg.spatial_db]
        climatedb = conn[cfg.climate_db]
        scenariodb = None
        if cfg.use_scernario:
            scenariodb = conn[cfg.bmp_scenario_db]

        # import model parameters information to MongoDB
        status_output('Import model parameters', 10, f)
        ImportParam2Mongo.workflow(cfg, maindb)
        n_subbasins = MongoQuery.get_init_parameter_value(
            maindb, SubbsnStatsName.subbsn_num)
        print('Number of subbasins: %d' % n_subbasins)

        # Extract spatial parameters for reaches, landuse, soil, etc.
        status_output(
            'Extract spatial parameters for reaches, landuse, soil, etc...',
            20, f)
        extract_spatial_parameters(cfg, maindb)

        # import stream parameters
        status_output('Generating reach table with initialized parameters...',
                      40, f)
        ImportReaches2Mongo.generate_reach_table(cfg, maindb)

        # import raster data to MongoDB
        status_output('Importing raster to MongoDB....', 50, f)
        ImportMongodbClass.spatial_rasters(cfg, 0)
        ImportMongodbClass.spatial_rasters(cfg, n_subbasins)

        # Import IUH
        status_output(
            'Generating and importing IUH (Instantaneous Unit Hydrograph)....',
            60, f)
        ImportMongodbClass.iuh(cfg, 0)
        ImportMongodbClass.iuh(cfg, n_subbasins)

        # Import grid layering data
        status_output('Generating and importing grid layering....', 70, f)
        ImportMongodbClass.grid_layering(cfg, 0)
        ImportMongodbClass.grid_layering(cfg, n_subbasins)

        # Import hydro-climate data
        status_output('Import climate data....', 80, f)
        ImportMongodbClass.climate_data(cfg, maindb, climatedb)

        # Import weight and related data, this should after ImportMongodbClass.climate_data()
        status_output(
            'Generating weight data for interpolation of meteorology data '
            'and weight dependent parameters....', 85, f)
        ImportWeightData.workflow(cfg, conn, 0)
        ImportWeightData.workflow(cfg, conn, n_subbasins)

        # Measurement Data, such as discharge, sediment yield.
        status_output(
            'Import observed data, such as discharge, sediment yield....', 90,
            f)
        ImportObservedData.workflow(cfg, maindb, climatedb)

        # Import BMP scenario database to MongoDB
        status_output('Importing bmp scenario....', 95, f)
        ImportScenario2Mongo.scenario_from_texts(cfg, maindb, scenariodb)

        status_output('Build DB: %s finished!' % cfg.spatial_db, 100, f)

        # close connection to MongoDB
        client.close()
Beispiel #6
0
 def parameters_extraction(cfg, maindb):
     """Landuse spatial parameters extraction."""
     f = cfg.logs.extract_lu
     # 1. Generate landuse lookup tables
     status_output("Generating landuse lookup tables from MongoDB...", 10, f)
     LanduseUtilClass.export_landuse_lookup_files_from_mongodb(cfg, maindb)
     # 2. Reclassify landuse parameters by lookup tables
     status_output("Generating landuse attributes...", 20, f)
     lookup_lu_config_file = cfg.logs.reclasslu_cfg
     LanduseUtilClass.reclassify_landuse_parameters(cfg.seims_bin, lookup_lu_config_file,
                                                    cfg.dirs.geodata2db,
                                                    cfg.spatials.landuse, cfg.dirs.lookup,
                                                    ModelParamDataUtils.landuse_fields,
                                                    cfg.default_landuse)
     # 3. Generate crop parameters
     status_output("Generating crop/landcover_init_param attributes...", 30, f)
     crop_lookup_file = cfg.paramcfgs.crop_file
     LanduseUtilClass.reclassify_landcover_parameters(cfg.spatials.landuse,
                                                      cfg.spatials.crop,
                                                      cfg.landcover_init_param,
                                                      crop_lookup_file,
                                                      ModelParamDataUtils.crop_fields,
                                                      cfg.dirs.geodata2db)
     # 4. Generate Curve Number according to landuse
     status_output("Calculating CN numbers...", 40, f)
     hg_file = cfg.spatials.hydro_group
     cn2_filename = cfg.spatials.cn2
     LanduseUtilClass.generate_cn2(maindb, cfg.spatials.landuse, hg_file, cn2_filename)
     # 5. Generate runoff coefficient
     status_output("Calculating potential runoff coefficient...", 50, f)
     slope_file = cfg.spatials.slope
     soil_texture_raster = cfg.spatials.soil_texture
     runoff_coef_file = cfg.spatials.runoff_coef
     LanduseUtilClass.generate_runoff_coefficent(maindb, cfg.spatials.landuse, slope_file,
                                                 soil_texture_raster,
                                                 runoff_coef_file, cfg.imper_perc_in_urban)
     status_output("Landuse/Landcover related spatial parameters extracted done!", 100, f)
Beispiel #7
0
    def workflow(cfg):
        """Building MongoDB workflow"""
        f = cfg.logs.build_mongo
        # build a connection to mongodb database
        client = ConnectMongoDB(cfg.hostname, cfg.port)
        conn = client.get_conn()
        maindb = conn[cfg.spatial_db]
        climatedb = conn[cfg.climate_db]
        scenariodb = None
        if cfg.use_scernario:
            scenariodb = conn[cfg.bmp_scenario_db]

        # import model parameters information to MongoDB
        status_output('Import model parameters', 10, f)
        ImportParam2Mongo.workflow(cfg, maindb)
        n_subbasins = MongoQuery.get_init_parameter_value(maindb, SubbsnStatsName.subbsn_num)
        print('Number of subbasins: %d' % n_subbasins)

        # Extract spatial parameters for reaches, landuse, soil, etc.
        status_output('Extract spatial parameters for reaches, landuse, soil, etc...', 20, f)
        extract_spatial_parameters(cfg, maindb)

        # import stream parameters
        status_output('Generating reach table with initialized parameters...', 40, f)
        ImportReaches2Mongo.generate_reach_table(cfg, maindb)

        # import raster data to MongoDB
        status_output('Importing raster to MongoDB....', 50, f)
        ImportMongodbClass.spatial_rasters(cfg, 0)
        ImportMongodbClass.spatial_rasters(cfg, n_subbasins)

        # Import IUH
        status_output('Generating and importing IUH (Instantaneous Unit Hydrograph)....', 60, f)
        ImportMongodbClass.iuh(cfg, 0)
        ImportMongodbClass.iuh(cfg, n_subbasins)

        # Import grid layering data
        status_output('Generating and importing grid layering....', 70, f)
        ImportMongodbClass.grid_layering(cfg, 0)
        ImportMongodbClass.grid_layering(cfg, n_subbasins)

        # Import hydro-climate data
        status_output('Import climate data....', 80, f)
        ImportMongodbClass.climate_data(cfg, maindb, climatedb)

        # Import weight and related data, this should after ImportMongodbClass.climate_data()
        status_output('Generating weight data for interpolation of meteorology data '
                      'and weight dependent parameters....', 85, f)
        ImportWeightData.workflow(cfg, conn, 0)
        ImportWeightData.workflow(cfg, conn, n_subbasins)

        # Measurement Data, such as discharge, sediment yield.
        status_output('Import observed data, such as discharge, sediment yield....', 90, f)
        ImportObservedData.workflow(cfg, maindb, climatedb)

        # Import BMP scenario database to MongoDB
        status_output('Importing bmp scenario....', 95, f)
        ImportScenario2Mongo.scenario_from_texts(cfg, maindb, scenariodb)

        status_output('Build DB: %s finished!' % cfg.spatial_db, 100, f)

        # close connection to MongoDB
        client.close()
Beispiel #8
0
 def parameters_extraction(cfg, maindb):
     """Landuse spatial parameters extraction."""
     f = cfg.logs.extract_lu
     # 1. Generate landuse lookup tables
     status_output("Generating landuse lookup tables from MongoDB...", 10,
                   f)
     LanduseUtilClass.export_landuse_lookup_files_from_mongodb(cfg, maindb)
     # 2. Reclassify landuse parameters by lookup tables
     status_output("Generating landuse attributes...", 20, f)
     lookup_lu_config_file = cfg.logs.reclasslu_cfg
     LanduseUtilClass.reclassify_landuse_parameters(
         cfg.seims_bin, lookup_lu_config_file, cfg.dirs.geodata2db,
         cfg.spatials.landuse, cfg.dirs.lookup,
         ModelParamDataUtils.landuse_fields, cfg.default_landuse)
     # 3. Generate crop parameters
     status_output("Generating crop/landcover_init_param attributes...", 30,
                   f)
     crop_lookup_file = cfg.paramcfgs.crop_file
     LanduseUtilClass.reclassify_landcover_parameters(
         cfg.spatials.landuse, cfg.spatials.crop, cfg.landcover_init_param,
         crop_lookup_file, ModelParamDataUtils.crop_fields,
         cfg.dirs.geodata2db)
     # 4. Generate Curve Number according to landuse
     status_output("Calculating CN numbers...", 40, f)
     hg_file = cfg.spatials.hydro_group
     cn2_filename = cfg.spatials.cn2
     LanduseUtilClass.generate_cn2(maindb, cfg.spatials.landuse, hg_file,
                                   cn2_filename)
     # 5. Generate runoff coefficient
     status_output("Calculating potential runoff coefficient...", 50, f)
     slope_file = cfg.spatials.slope
     soil_texture_raster = cfg.spatials.soil_texture
     runoff_coef_file = cfg.spatials.runoff_coef
     LanduseUtilClass.generate_runoff_coefficent(
         maindb, cfg.spatials.landuse, slope_file, soil_texture_raster,
         runoff_coef_file, cfg.imper_perc_in_urban)
     status_output(
         "Landuse/Landcover related spatial parameters extracted done!",
         100, f)