Skip to content

Grid params with a single veg type: Indexing error #71

@jhamman

Description

@jhamman

Email from Shervan:

I am trying to move to VIC image and I would like to transfer all my files which I prepared for the classical version (version 5) to NetCDF format. I am using tonic toolkit.

I have encounter couple of issues which I managed to solve but there is an issue which persists.

The issue is in grid_params function when the code try to add bare soil parameter in case it is not specify in the veg library.

My code together with the error messages is as follow; I have tried many combination but the issue still persists (such as removing the bare soil None changing it or adding or removing version_in and…). I tied to find the issue in the code it is around line 1010 to 1020 with new[:-1,yi,xi] = … The example is from stehekin basin. I just simplify the vegetation param to include only one vegetation type.

I would appreciate if you can give me some insight into why this problem remains as it remains. I hope the issue is not very stupid…

BTW, I see that apparently there is no version_in 5. I am working with version 5 and basically I want to have the classical files to be in a netcdf. I am not sure if this make lot of difference in this case.

from tonic.models.vic.grid_params import soil, snow, veg, veg_class, Cols, Desc, calc_grid, grid_params

n_veg_classes = 11
root_zones = 3

# Read the soil parameters
soil_dict = soil('D:/VIC_modeling/stehekin/params/vic/soil_param.txt', c=Cols(nlayers=3))

#%%
# Read the snow parameters
snow_dict = snow('D:/VIC_modeling/stehekin/params/vic/snowbands.txt',
                 soil_dict, c=Cols(snow_bands=5))

#%%
# Read the veg parameter file
veg_dict = veg('D:/VIC_modeling/stehekin/params/vic/veg_param_1.txt',
               soil_dict,
               vegparam_lai=True,
               lai_src = 'FROM_VEGPARAM',
               veg_classes=n_veg_classes)

#%%
# Read the veg library file
veg_lib = veg_class('D:/VIC_modeling/stehekin/params/vic/veglib.txt')
#%%
# 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.2',
                        veg_dict=veg_dict, veglib_dict=veg_lib, snow_dict=snow_dict,
                        vegparam_lai=True, lai_src = 'FROM_VEGPARAM',
                        lib_bare_idx=None)​

yields


  File "C:\Users\SHERVAN\Anaconda3\lib\site-packages\tonic-0.0.0.dev_67cc1a1-py3.6.egg\tonic\models\vic\grid_params.py"

    new[:-1, yi, xi] = veglib_dict[lib_var][:, np.newaxis]

 TypeError: tuple indices must be integers or slices, not str

snowbands.txt
soil_param.txt
veg_param_1.txt
veglib.txt

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