示例#1
0
def write_new_infocell(path = "infocell_QC2.txt"):
    f = open(path, 'w')
    cell_list = []

    #me
    format = '%15s' * 13
    f.write(format % ('N','XX','YY','DA','CHSLP','IBN','NEXT','AREA', 'RID','ROUT','LON', 'LAT', 'CHLEN') + '\n')
    format = '%15d' * 3 + '%15.1f' + '%15.10f' + '%15d' * 2 + '%15.1f' + '%15d' * 2 + '%15.1f' * 3

#    format = '%15s' * 12
#    f.write(format % ('N','XX','YY','DA','CHSLP','IBN','NEXT','AREA', 'CLAY', 'SAND' ,'RID','ROUT') + '\n')
#    format = '%15d' * 3 + '%15.1f' + '%15.10f' + '%15d' * 2 + '%15.1f'*3 + '%15d' * 2

    for basin in basins:
        for cell in basin.cells:
            put_to_list(cell, cell_list)


    final_cell = Cell()
    final_cell.id = len(cell_list) + 1
    final_cell.next = final_cell
    final_cell.area = 0
    final_cell.drainage_area = 0
    final_cell.set_coords(-1, -1)



    for cell in cell_list:
        if cell.next is not None:
            if cell.next.basin is None:
                print cell.next.coords()
                

        write_cell(cell, f, format, final_cell)

    write_cell(final_cell, f, format, final_cell)


    print 'cell list: ', len(cell_list)

    for basin in basins:
        for the_cell in basin.cells:
            assert the_cell in cell_list

    assert len(set(cell_list)) == len(cell_list)


    f.close()
示例#2
0






###Create data structures
### 2D array of cells and list of basins
#create dummy cell objects
cells = []
for i in range(n_cols):
    cells.append([])
    for j in range(n_rows):
        the_cell = Cell()
        the_cell.set_coords(i, j)
        cells[i].append( the_cell )

basins = []


####

def get_additional_cells(path, start_col = 90, start_row = 143):
    f = open(path)
    i0 = start_col - 1
    j0 = start_row - 1
    i = i0
    j = j0
    for line in f:
        if line.strip() == "":