def main(opts, flgs): TMPVECT = [] DEBUG = True if flgs['d'] else False atexit.register(cleanup, vector=TMPVECT, debug=DEBUG) # check input maps plant = [ opts['plant_column_discharge'], opts['plant_column_elevup'], opts['plant_column_elevdown'], opts['plant_column_point_id'], opts['plant_column_plant_id'], opts['plant_column_power'], opts['plant_column_stream_id'] ] ovwr = overwrite() try: plnt = check_required_columns(opts['plant'], int(opts['plant_layer']), plant, 'plant') except ParameterError as exc: exception2error(exc) return if not opts['output_point']: output_point = 'tmp_output_point' TMPVECT.append(output_point) else: output_point = opts['output_point'] plnt = conv_segpoints(opts['plant'], output_point) el, mset = (opts['elevation'].split('@') if '@' in opts['elevation'] else (opts['elevation'], '')) elev = RasterRow(name=el, mapset=mset) elev.open('r') plnt.open('r') plants, skipped = read_plants(plnt, elev=elev, restitution='restitution', intake='intake', ckind_label='kind_label', cdischarge='discharge', celevation='elevation', cid_point='cat', cid_plant='plant_id') plnt.close() # contour options resolution = float(opts['resolution']) if opts['resolution'] else None write_structures(plants, opts['output_struct'], elev, ndigits=int(opts['ndigits']), resolution=resolution, contour=opts['contour'], overwrite=ovwr) elev.close()
def main(options, flags): TMPRAST = [] DEBUG = True if flags['d'] else False atexit.register(cleanup, raster=TMPRAST, debug=DEBUG) elevation = options['elevation'] plant = options['plant'] output_struct = options['output_struct'] input_struct = options['input_struct'] output_plant = options['output_plant'] percentage_losses = float(options['percentage_losses']) roughness_penstock = float(options['roughness_penstock']) ks_derivation = float(options['ks_derivation']) turbine_folder = (options['turbine_folder'] if options['turbine_folder'] else os.path.join(os.path.abspath('.'), 'turbines')) turbine_list = (options['turbine_list'] if options['turbine_list'] else os.path.join(os.path.abspath('.'), 'turbines', 'list.txt')) efficiency_shaft = float(options['efficiency_shaft']) efficiency_alt = float(options['efficiency_alt']) efficiency_transf = float(options['efficiency_transf']) #import ipdb; ipdb.set_trace() #c = flags['c'] msgr = get_msgr() #import ipdb; ipdb.set_trace() TMPRAST.extend(['new_river', 'buff_area']) if not gcore.overwrite(): for m in TMPRAST: if gcore.find_file(m)['name']: msgr.fatal(_("Temporary raster map %s exists") % (m)) # FIXME:check if it works for vectors if options['output_point']: conv_segpoints(plant, options['output_point']) # FIXME: gross_head coherent with plants # set the opions to execute the r.green.hydro.structure struct_opts = dict(elevation=elevation, plant=plant, output_struct=output_struct, ndigits=options['ndigits'], contour=options['contour'], overwrite=gcore.overwrite()) if options['resolution']: struct_opts['resolution'] = options['resolution'] ## -------------------------------------------------------------------------- if output_struct: gcore.run_command('r.green.hydro.structure', **struct_opts) gcore.run_command('v.build', map=output_struct) else: output_struct = input_struct # FIXME: check the structure of the input file ## -------------------------------------------------------------------------- gcore.run_command('g.copy', vector=(plant, output_plant)) with VectorTopo(output_struct, mode='rw') as struct: list_intakeid = compute_losses(struct, options, percentage_losses, roughness_penstock, ks_derivation) compute_power(struct, list_intakeid, turbine_list, turbine_folder, efficiency_shaft, efficiency_alt, efficiency_transf) with VectorTopo(output_plant, mode='rw') as out, \ VectorTopo(output_struct, mode='r') as struct: cols = [('tot_losses', 'DOUBLE'), ('net_head', 'DOUBLE'), ('e_global', 'DOUBLE'), ('power', 'DOUBLE')] add_columns(out, cols) scols = 'tot_losses', 'net_head', 'e_global', 'power' wherecond = 'plant_id={!r} AND kind LIKE {!r} AND max_power LIKE {!r}' for seg in out: where = wherecond.format(str(seg.attrs['plant_id']), 'penstock', 'yes') sqlcode = struct.table.filters.select( ','.join(scols)).where(where).get_sql() svalues = struct.table.execute(sqlcode).fetchone() if svalues: for col, value in zip(scols, svalues): if value: seg.attrs[col] = value out.table.conn.commit() power2energy(output_plant, 'power', float(options['n']))
def main(opts, flgs): TMPVECT = [] DEBUG = True if flgs["d"] else False atexit.register(cleanup, vector=TMPVECT, debug=DEBUG) # check input maps plant = [ opts["plant_column_discharge"], opts["plant_column_elevup"], opts["plant_column_elevdown"], opts["plant_column_point_id"], opts["plant_column_plant_id"], opts["plant_column_power"], opts["plant_column_stream_id"], ] ovwr = overwrite() try: plnt = check_required_columns( opts["plant"], int(opts["plant_layer"]), plant, "plant" ) except ParameterError as exc: exception2error(exc) return if not opts["output_point"]: output_point = "tmp_output_point" TMPVECT.append(output_point) else: output_point = opts["output_point"] plnt = conv_segpoints(opts["plant"], output_point) el, mset = ( opts["elevation"].split("@") if "@" in opts["elevation"] else (opts["elevation"], "") ) elev = RasterRow(name=el, mapset=mset) elev.open("r") plnt.open("r") plants, skipped = read_plants( plnt, elev=elev, restitution="restitution", intake="intake", ckind_label="kind_label", cdischarge="discharge", celevation="elevation", cid_point="cat", cid_plant="plant_id", ) plnt.close() # contour options resolution = float(opts["resolution"]) if opts["resolution"] else None write_structures( plants, opts["output_struct"], elev, ndigits=int(opts["ndigits"]), resolution=resolution, contour=opts["contour"], overwrite=ovwr, ) elev.close()
def main(options, flags): TMPRAST = [] DEBUG = True if flags["d"] else False atexit.register(cleanup, raster=TMPRAST, debug=DEBUG) elevation = options["elevation"] plant = options["plant"] output_struct = options["output_struct"] input_struct = options["input_struct"] output_plant = options["output_plant"] percentage_losses = float(options["percentage_losses"]) roughness_penstock = float(options["roughness_penstock"]) ks_derivation = float(options["ks_derivation"]) turbine_folder = (options["turbine_folder"] if options["turbine_folder"] else os.path.join(os.path.abspath("."), "turbines")) turbine_list = (options["turbine_list"] if options["turbine_list"] else os.path.join(os.path.abspath("."), "turbines", "list.txt")) efficiency_shaft = float(options["efficiency_shaft"]) efficiency_alt = float(options["efficiency_alt"]) efficiency_transf = float(options["efficiency_transf"]) # import ipdb; ipdb.set_trace() # c = flags['c'] msgr = get_msgr() # import ipdb; ipdb.set_trace() TMPRAST.extend(["new_river", "buff_area"]) if not gcore.overwrite(): for m in TMPRAST: if gcore.find_file(m)["name"]: msgr.fatal(_("Temporary raster map %s exists") % (m)) # FIXME:check if it works for vectors if options["output_point"]: conv_segpoints(plant, options["output_point"]) # FIXME: gross_head coherent with plants # set the opions to execute the r.green.hydro.structure struct_opts = dict( elevation=elevation, plant=plant, output_struct=output_struct, ndigits=options["ndigits"], contour=options["contour"], overwrite=gcore.overwrite(), ) if options["resolution"]: struct_opts["resolution"] = options["resolution"] ## -------------------------------------------------------------------------- if output_struct: gcore.run_command("r.green.hydro.structure", **struct_opts) gcore.run_command("v.build", map=output_struct) else: output_struct = input_struct # FIXME: check the structure of the input file ## -------------------------------------------------------------------------- gcore.run_command("g.copy", vector=(plant, output_plant)) with VectorTopo(output_struct, mode="rw") as struct: list_intakeid = compute_losses(struct, options, percentage_losses, roughness_penstock, ks_derivation) compute_power( struct, list_intakeid, turbine_list, turbine_folder, efficiency_shaft, efficiency_alt, efficiency_transf, ) with VectorTopo(output_plant, mode="rw") as out, VectorTopo(output_struct, mode="r") as struct: cols = [ ("tot_losses", "DOUBLE"), ("net_head", "DOUBLE"), ("e_global", "DOUBLE"), ("power", "DOUBLE"), ] add_columns(out, cols) scols = "tot_losses", "net_head", "e_global", "power" wherecond = "plant_id={!r} AND kind LIKE {!r} AND max_power LIKE {!r}" for seg in out: where = wherecond.format(str(seg.attrs["plant_id"]), "penstock", "yes") sqlcode = (struct.table.filters.select( ",".join(scols)).where(where).get_sql()) svalues = struct.table.execute(sqlcode).fetchone() if svalues: for col, value in zip(scols, svalues): if value: seg.attrs[col] = value out.table.conn.commit() power2energy(output_plant, "power", float(options["n"]))