Esempio n. 1
0
def read_basins(path = 'data/infocell/amno180x172_basins.nc', cells = None):
    """
    reads data from netcdf files and fills in the basins array
    """

    descr_map = get_basin_descriptions()
    ncfile = Dataset(path)
    id = 1
    for name, values in ncfile.variables.iteritems():
        data = values[:]
        if n_cols == data.shape[1]:#transpose if necessary
            the_values = np.transpose(data)
        else:
            the_values = data
            
        the_basin = Basin(id = id, name = name)
        if descr_map.has_key(name):
            the_basin.description = descr_map[name]

        basins.append(the_basin)

        the_is, the_js = np.where(the_values == 1)
        #add cells to a basin
        for i, j in zip(the_is, the_js):
            the_basin.add_cell(cells[i][j])
 
        id += 1

    ncfile.close()
    return basins
    pass