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

module 'tonic.models.vic.grid_params' has no attribute 'cols' or 'format' #77

Open
danhamill opened this issue May 14, 2022 · 1 comment

Comments

@danhamill
Copy link

I am trying to convert a netcdf file representing the livenh dataset back to ascii to ensure the conversion from #76 worked.

My Script is:

from tonic.models.vic.ncparam2ascii import subset

param_file =   r'livenh\livenh.params.vic5.nc'
veg_export  =  r"livenh\output\veg.txt"
snow_export =  r"livenh\output\snow.txt"
soil_export =  r"livenh\output\soil.txt"


subset(param_file, soil_file = soil_export,
       snow_file = snow_export, veg_file = veg_export,
       )

It appeared to complete the veg file export, but failed on the snow export.

Exception has occurred: AttributeError
module 'tonic.models.vic.grid_params' has no attribute 'cols'
  File "C:\workspace\git_clones\tonic\tonic\models\vic\ncparam2ascii.py", line 328, in snow
    c = grid_params.cols(snow_bands=snow_bands)
  File "C:\workspace\git_clones\tonic\tonic\models\vic\ncparam2ascii.py", line 59, in subset
    snow(data, xinds, yinds, snow_file)
  File "C:\workspace\git_clones\tonic\tests\levenh_to_ascii.py", line 9, in <module>
    subset(param_file, soil_file = soil_export,

def snow(data, xinds, yinds, snow_file):
"""Write VIC formatted snowband parameter file"""
try:
snow_bands = data['AreaFract'].shape[0]
except:
snow_bands = 5
c = grid_params.cols(snow_bands=snow_bands)
f = grid_params.format(snow_bands=snow_bands)
arrayshape = (len(xinds), 1 + np.max([np.max(c.snow_param[var])
for var in c.snow_param]))
snow_params = np.zeros(arrayshape)
dtypes = [0] * arrayshape[1]
for var in c.snow_param:
if data[var].ndim == 2:
snow_params[:, c.snow_param[var]] = np.atleast_2d(
data[var][yinds, xinds]).transpose()
elif data[var].ndim == 3:
snow_params[:, c.snow_param[var]] = np.atleast_2d(
data[var][:, yinds, xinds]).transpose()
for col in c.snow_param[var]:
dtypes[col] = f.snow_param[var]
np.savetxt(snow_file, snow_params, fmt=dtypes)
print('finished writing snow parameter file: {0}'.format(snow_file))
return

grid_params appears to have the attribute Cols as apposed to cols.

After inspecting the output veg file, I see this in the output:

450000 2
6 0.828125 0.1 0.1 1.0 0.65 1.0 0.25 
1.68 1.52 1.68 2.9 4.9 5.0 5.0 4.6 3.44 3.04 2.16 2.0 
7 0.171875 0.1 0.1 1.0 0.65 1.0 0.25 
2.0 2.25 2.95 3.85 3.75 3.5 3.55 3.2 3.3 2.85 2.6 2.2 

And this is from the Livenh input file I started with:

450000 2
6 0.828125 0.10 0.10 1.00 0.65 1.00 0.25 
0.175 0.238 0.275 0.275 0.425 0.825 1.175 1.300 0.837 0.350 0.200 0.175 
7 0.171875 0.10 0.10 1.00 0.65 1.00 0.25 
0.487 0.500 0.213 0.213 0.400 0.875 1.525 1.562 0.775 0.363 0.225 0.350 

I believe the mistaken lines represent monthly LAI numbers. Why are they different?

@danhamill
Copy link
Author

Similarly, grid_params has the attribute Format as apposed to format

Exception has occurred: AttributeError
module 'tonic.models.vic.grid_params' has no attribute 'format'
  File "C:\workspace\git_clones\tonic\tonic\models\vic\ncparam2ascii.py", line 329, in snow
    f = grid_params.format(snow_bands=snow_bands)
  File "C:\workspace\git_clones\tonic\tonic\models\vic\ncparam2ascii.py", line 59, in subset
    snow(data, xinds, yinds, snow_file)
  File "C:\workspace\git_clones\tonic\tests\levenh_to_ascii.py", line 9, in <module>
    subset(param_file, soil_file = soil_export,

def snow(data, xinds, yinds, snow_file):
"""Write VIC formatted snowband parameter file"""
try:
snow_bands = data['AreaFract'].shape[0]
except:
snow_bands = 5
c = grid_params.cols(snow_bands=snow_bands)
f = grid_params.format(snow_bands=snow_bands)
arrayshape = (len(xinds), 1 + np.max([np.max(c.snow_param[var])
for var in c.snow_param]))
snow_params = np.zeros(arrayshape)
dtypes = [0] * arrayshape[1]
for var in c.snow_param:
if data[var].ndim == 2:
snow_params[:, c.snow_param[var]] = np.atleast_2d(
data[var][yinds, xinds]).transpose()
elif data[var].ndim == 3:
snow_params[:, c.snow_param[var]] = np.atleast_2d(
data[var][:, yinds, xinds]).transpose()
for col in c.snow_param[var]:
dtypes[col] = f.snow_param[var]
np.savetxt(snow_file, snow_params, fmt=dtypes)
print('finished writing snow parameter file: {0}'.format(snow_file))
return

@danhamill danhamill changed the title module 'tonic.models.vic.grid_params' has no attribute 'cols' module 'tonic.models.vic.grid_params' has no attribute 'cols' or 'format' May 14, 2022
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

1 participant