示例#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
示例#2
0
    def _determine_basins(self):
        """
        Determine list of basins
        """
        
        for i in xrange(self.nx):
            for j in xrange(self.ny):
                theCell = self.cells[i][j]

                if theCell.basin is not None:
                    continue
                
                #go to the exit point
                while theCell.next is not None:
                    theCell = theCell.next

                #single cell is not considered as a basin
                # @type theCell Cell
                if len(theCell.previous) == 0 or theCell.number_of_upstream_cells <= 45:
                    continue

                basin = Basin(id = len(self.basins))
                basin.name = 'Basin_{0}'.format(basin.id)
                self.basins.append(basin)

                #assign the basin to all the cells flowing into it
                theCell.set_common_basin(basin)