Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jhamman opened this issue Jul 27, 2018 · 2 comments
Open

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

jhamman opened this issue Jul 27, 2018 · 2 comments

Comments

@jhamman
Copy link
Member

jhamman commented Jul 27, 2018

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

@solomonsg
Copy link

solomonsg commented May 3, 2019

Hi Jhamman,
did you manage to solve this? I am facing the same issue using the same code and for Stehekin.
I am also trying to convert other files for very large basins and I got an error as:

grid_params: line 1515, in veg
root_depth[cell, vind, :] = temp[2:tmp:2]
ValueError: could not broadcast input array from shape (2) into shape (3)

the same code as above is used. Please let me know :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants