Skip to content

grid_params tuple indices must be integers or slices, not str #76

@danhamill

Description

@danhamill

I am trying to convert the livenh VIC parameter files to netcdf format.

I have installed tonic to a python 3.9 environment with these packages:

conda create -n tonic python=3.9
conda activate tonic
conda install -c conda-forge pandas numpy scipy xarray jupyter netCDF4 configobj

I am getting the following trace back from grid_params

TUPLE INDICIES MUST BE INTEGERS OR SLICES NOT STR

Which points to Line 1013 of grid_params.py and read as:

if extra_class: # <--- Line 1012
    new[:-1, yi, xi] = veglib_dict[lib_var][:, np.newaxis] # <--- Line 1013

Here is my script:

import pandas as pd
from tonic.models.vic.grid_params import soil, snow, veg, veg_class, Cols, Desc, write_netcdf, grid_params, calc_grid
# Read the soil parameters
soil_dict = soil(r'livenh\vic.nldas.mexico.soil.txt', c=Cols(nlayers=3))


# Read the snow parameters
snow_dict = snow(r'livenh\vic.nldas.mexico.snow.txt.L13',
                 soil_dict, c=Cols(snow_bands=5))


# Read the veg parameter file
veg_dict = veg(r'livenh\vic.nldas.mexico.veg.txt',
               soil_dict,
               vegparam_lai=True,
               veg_classes=11)


# Read the veg library file
veg_lib = veg_class(r'livenh\LDAS_veg_lib')


# Determine the grid shape
target_grid, target_attrs = calc_grid(soil_dict['lats'], soil_dict['lons'])


# Grid all the parameters
grid_dict = grid_params(soil_dict, target_grid, version_in = '4.1.2',
                        veg_dict=veg_dict, veglib_dict=veg_lib, snow_dict=snow_dict,
                        )


# Write a netCDF file with all the parameters
write_netcdf(r'livenh\livenh.params.vic5.nc', target_attrs,
             target_grid=target_grid,
             soil_grid=grid_dict['soil_dict'],
             snow_grid=grid_dict['snow_dict'],
             veglib_dict=veg_lib,
             veg_grid=grid_dict['veg_dict'],
             version_in='4.1.2')

Could I be missing something in veg?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions