예제 #1
0
def conv_segpoints(seg, output):

    segments, mset = (seg.split('@') if '@' in seg else (seg, ''))
    # convert the map with segments in a map with intakes and restitution
    new_vec = VectorTopo(output)
    #TODO:  check if the vector already exists
    new_vec.layer = 1
    new_vec.open('w', tab_cols=COLS_points)
    reg = Region()

    seg = VectorTopo(segments, mapset=mset)
    seg.layer = 1
    seg.open('r')

    for pla in seg:
        #import ipdb; ipdb.set_trace()
        new_vec.write(pla[-1],
                      (2, pla.attrs['plant_id'], 'restitution',
                       pla.attrs['stream_id'], pla.attrs['elev_down'],
                       pla.attrs['discharge'], pla.attrs['pot_power']))
        #import ipdb; ipdb.set_trace()
        new_vec.write(pla[0], (1, pla.attrs['plant_id'], 'intake',
                               pla.attrs['stream_id'], pla.attrs['elev_up'],
                               pla.attrs['discharge'], pla.attrs['pot_power']))

    new_vec.table.conn.commit()
    new_vec.comment = (' '.join(sys.argv))
    new_vec.write_header()
    #pdb.set_trace()
    new_vec.close()

    return new_vec
예제 #2
0
def write_points(plants, output, efficiency, min_power):
    # create vetor segment
    new_vec = VectorTopo(output)
    #TODO:  check if the vector already exists
    new_vec.layer = 1
    new_vec.open('w', tab_cols=COLS_points)
    reg = Region()

    # import ipdb; ipdb.set_trace()
    for pla in plants:
        power = pla.potential_power(efficiency=efficiency)
        if power > min_power:
            new_vec.write(pla.line[-1],
                          (pla.restitution.id, pla.id, 'restitution',
                           pla.id_stream, float(pla.restitution.elevation),
                           float(pla.restitution.discharge), power))
            for ink in pla.intakes:
                new_vec.write(
                    pla.line[0],
                    (ink.id, pla.id, 'intake', pla.id_stream,
                     float(ink.elevation), float(ink.discharge), power))

    new_vec.table.conn.commit()
    new_vec.comment = (' '.join(sys.argv))
    new_vec.write_header()
    #pdb.set_trace()
    new_vec.close()
예제 #3
0
def write_plants(plants, output, efficiency, min_power):
    # create vetor segment
    new_vec = VectorTopo(output)
    #TODO:  check if the vector already exists
    new_vec.layer = 1
    new_vec.open('w', tab_cols=COLS)
    reg = Region()
    for pla in plants:
        power = pla.potential_power(efficiency=efficiency)
        if power > min_power:
            for cat, ink in enumerate(pla.intakes):
                if version == 70:
                    new_vec.write(
                        pla.line,
                        (pla.id, pla.id_stream, power,
                         float(pla.restitution.discharge), float(
                             ink.elevation), float(pla.restitution.elevation)))
                else:
                    new_vec.write(pla.line,
                                  cat=cat,
                                  attrs=(pla.id, pla.id_stream, power,
                                         float(pla.restitution.discharge),
                                         float(ink.elevation),
                                         float(pla.restitution.elevation)))

    new_vec.table.conn.commit()
    new_vec.comment = (' '.join(sys.argv))
    #pdb.set_trace()
    new_vec.close()
예제 #4
0
def get_electro_length(opts):
    # open vector plant
    pname = opts["struct"]
    pname, vmapset = pname.split("@") if "@" in pname else (pname, "")
    with VectorTopo(pname,
                    mapset=vmapset,
                    layer=int(opts["struct_layer"]),
                    mode="r") as vect:
        kcol = opts["struct_column_kind"]
        ktype = opts["struct_kind_turbine"]
        # check if electro_length it is alredy in the table
        if "electro_length" not in vect.table.columns:
            vect.table.columns.add("electro_length", "double precision")
        # open vector map with the existing electroline
        ename = opts["electro"]
        ename, emapset = ename.split("@") if "@" in ename else (ename, "")
        ltemp = []
        with VectorTopo(ename,
                        mapset=emapset,
                        layer=int(opts["electro_layer"]),
                        mode="r") as electro:
            pid = os.getpid()
            elines = opts["elines"] if opts["elines"] else (
                "tmprgreen_%i_elines" % pid)
            for cat, line in enumerate(vect):
                if line.attrs[kcol] == ktype:
                    # the turbine is the last point of the penstock
                    turbine = line[-1]
                    # find the closest electro line
                    eline = electro.find["by_point"].geo(turbine, maxdist=1e6)
                    dist = eline.distance(turbine)
                    line.attrs["electro_length"] = dist.dist
                    if line.attrs["side"] == "option1":
                        ltemp.append([
                            geo.Line([turbine, dist.point]),
                            (line.attrs["plant_id"], line.attrs["side"]),
                        ])
                else:
                    line.attrs["electro_length"] = 0.0
            vect.table.conn.commit()
        new = VectorTopo(elines)  # new vec with elines
        new.layer = 1
        cols = [
            (u"cat", "INTEGER PRIMARY KEY"),
            (u"plant_id", "VARCHAR(10)"),
            (u"side", "VARCHAR(10)"),
        ]
        new.open("w", tab_cols=cols)
        reg = Region()
        for cat, line in enumerate(ltemp):
            if version == 70:
                new.write(line[0], line[1])
            else:
                new.write(line[0], cat=cat, attrs=line[1])
        new.table.conn.commit()
        new.comment = " ".join(sys.argv)
        new.close()
예제 #5
0
def get_electro_length(opts):
    # open vector plant
    pname = opts['struct']
    pname, vmapset = pname.split('@') if '@' in pname else (pname, '')
    with VectorTopo(pname,
                    mapset=vmapset,
                    layer=int(opts['struct_layer']),
                    mode='r') as vect:
        kcol = opts['struct_column_kind']
        ktype = opts['struct_kind_turbine']
        # check if electro_length it is alredy in the table
        if 'electro_length' not in vect.table.columns:
            vect.table.columns.add('electro_length', 'double precision')
        # open vector map with the existing electroline
        ename = opts['electro']
        ename, emapset = ename.split('@') if '@' in ename else (ename, '')
        ltemp = []
        with VectorTopo(ename,
                        mapset=emapset,
                        layer=int(opts['electro_layer']),
                        mode='r') as electro:
            pid = os.getpid()
            elines = (opts['elines'] if opts['elines'] else
                      ('tmprgreen_%i_elines' % pid))
            for cat, line in enumerate(vect):
                if line.attrs[kcol] == ktype:
                    # the turbine is the last point of the penstock
                    turbine = line[-1]
                    # find the closest electro line
                    eline = electro.find['by_point'].geo(turbine, maxdist=1e6)
                    dist = eline.distance(turbine)
                    line.attrs['electro_length'] = dist.dist
                    if line.attrs['side'] == 'option1':
                        ltemp.append([
                            geo.Line([turbine, dist.point]),
                            (line.attrs['plant_id'], line.attrs['side'])
                        ])
                else:
                    line.attrs['electro_length'] = 0.
            vect.table.conn.commit()
        new = VectorTopo(elines)  # new vec with elines
        new.layer = 1
        cols = [
            (u'cat', 'INTEGER PRIMARY KEY'),
            (u'plant_id', 'VARCHAR(10)'),
            (u'side', 'VARCHAR(10)'),
        ]
        new.open('w', tab_cols=cols)
        reg = Region()
        for cat, line in enumerate(ltemp):
            if version == 70:
                new.write(line[0], line[1])
            else:
                new.write(line[0], cat=cat, attrs=line[1])
        new.table.conn.commit()
        new.comment = (' '.join(sys.argv))
        new.close()
예제 #6
0
def conv_segpoints(seg, output):

    segments, mset = seg.split("@") if "@" in seg else (seg, "")
    # convert the map with segments in a map with intakes and restitution
    new_vec = VectorTopo(output)
    # TODO:  check if the vector already exists
    new_vec.layer = 1
    new_vec.open("w", tab_cols=COLS_points)
    reg = Region()

    seg = VectorTopo(segments, mapset=mset)
    seg.layer = 1
    seg.open("r")

    for pla in seg:
        # import ipdb; ipdb.set_trace()
        new_vec.write(
            pla[-1],
            (
                2,
                pla.attrs["plant_id"],
                "restitution",
                pla.attrs["stream_id"],
                pla.attrs["elev_down"],
                pla.attrs["discharge"],
                pla.attrs["pot_power"],
            ),
        )
        # import ipdb; ipdb.set_trace()
        new_vec.write(
            pla[0],
            (
                1,
                pla.attrs["plant_id"],
                "intake",
                pla.attrs["stream_id"],
                pla.attrs["elev_up"],
                pla.attrs["discharge"],
                pla.attrs["pot_power"],
            ),
        )

    new_vec.table.conn.commit()
    new_vec.comment = " ".join(sys.argv)
    new_vec.write_header()
    # pdb.set_trace()
    new_vec.close()

    return new_vec