def extract_subbasin_updown(self): """Extract the up-down relationship of subbasins.""" subbsn_info = ImportReaches2Mongo.read_reach_downstream_info( self.reach) for k, v in viewitems(subbsn_info): self.subbsin_tree.setdefault(k, v['downstream']) self.subbsin_num = len(self.subbsin_tree) # type: int
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()
def extract_subbasin_updown(self): """Extract the up-down relationship of subbasins.""" self.subbsin_tree = ImportReaches2Mongo.read_reach_downstream_info(self.reach) self.subbsin_num = len(self.subbsin_tree)
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()
def extract_subbasin_updown(self): """Extract the up-down relationship of subbasins.""" self.subbsin_tree = ImportReaches2Mongo.read_reach_downstream_info( self.reach) self.subbsin_num = len(self.subbsin_tree)