How to use the tonic.pycompat.iteritems function in tonic

To help you get started, we’ve selected a few tonic examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github UW-Hydro / tonic / tonic / models / vic / ncparam2ascii.py View on Github external
bad_cells.append(i)
                j = i
                while True:
                    j -= 1
                    if (FILL_VALUE not in soil_params[j, :]) and \
                            not np.isnan(np.sum(soil_params[j, :])):
                        soil_params[i, 5:] = soil_params[j, 5:]
                        replacements.append(j)
                        break
        print('Fixed {0} bad cells'.format(len(bad_cells)))
        print('Example: {0}-->{1}'.format(bad_cells[0], replacements[0]))
    # ---------------------------------------------------------------- #

    # ---------------------------------------------------------------- #
    # Print summary of variables
    for var, cols in iteritems(c.soil_param):
        print('{0: <12}--> min: {1:<09.3f}, max: {2:<09.3f}, mean:'
              ' {3:<09.3f}'.format(var,
                                   soil_params[:, cols].min(),
                                   soil_params[:, cols].max(),
                                   soil_params[:, cols].mean()))
    # ---------------------------------------------------------------- #

    # ---------------------------------------------------------------- #
    # Finish up
    assert soil_params[-1, 3] == data['lats'][y, x]
    assert soil_params[-1, 4] == data['lons'][y, x]
    # ---------------------------------------------------------------- #

    # ---------------------------------------------------------------- #
    # Write the file
    print('writing soil parameter file: {0}'.format(soil_file))
github UW-Hydro / tonic / tonic / models / vic / ncparam2ascii.py View on Github external
*** --------------------------------------------------------------------- ***\n
    """

    print(message)

    # ---------------------------------------------------------------- #
    c = grid_params.cols(nlayers=3)
    f = grid_params.format(nlayers=3)

    c.soil_param['Nveg'] = np.array([0])
    f.soil_param['Nveg'] = '%1i'

    numcells = data['mask'].size

    arrayshape = (numcells, 1 + np.max([np.max(cols) for v, cols in
                                        iteritems(c.soil_param)]))
    soil_params = np.empty(arrayshape)
    dtypes = ['%1i'] * arrayshape[1]
    # ---------------------------------------------------------------- #

    # ---------------------------------------------------------------- #
    # find nearest real grid cell for all grid cells where frozen soil mask is
    # active
    # This is needed because the RASM mask is often different than existing
    # datasets
    print('Finding/filling nearest neighbors for all variables based on '
          'fs_active mask')

    # real mask (from input dataset)
    ry, rx = np.nonzero(data['fs_active'])

    # fill mask (we will fill all of these grid cells with their nearest real
github UW-Hydro / tonic / tonic / models / vic / ncparam2ascii.py View on Github external
if len(fy) > 0:
        combined = np.dstack(([data['yc'][ry, rx], data['xc'][ry, rx]]))[0]
        points = list(np.vstack((data['yc'][fy, fx],
                                 data['xc'][fy, fx])).transpose())
        mytree = cKDTree(combined)
        dist, inds = mytree.query(points, k=1)

        data['avg_T'] = np.array(data['avg_T'])
        data['avg_T'][fy, fx] = data['avg_T'][ry[inds], rx[inds]]
    # ---------------------------------------------------------------- #

    # ---------------------------------------------------------------- #
    # For rasm, all cols are shifted one to right to make room for nveg in
    # col 0
    i = -1
    for var, cols in iteritems(c.soil_param):
        for col in cols:
            dtypes[col] = f.soil_param[var]

    for (y, x), maskval in np.ndenumerate(data['mask']):
        # advance the row count
        i += 1

        # put real data
        for var in c.soil_param:
            cols = c.soil_param[var]
            if data[var].ndim == 2:
                soil_params[i, cols] = data[var][y, x]
            elif data[var].ndim == 3:
                for j, col in enumerate(cols):
                    soil_params[i, col] = data[var][j, y, x]