1515import socket
1616from getpass import getuser
1717from collections import OrderedDict
18+ from warnings import warn
1819from tonic .io import read_netcdf
20+ from tonic .pycompat import pyrange , pyzip
21+
1922
2023# -------------------------------------------------------------------- #
2124description = 'Converter for VIC ASCII style parameters to gridded netCDF'
@@ -123,12 +126,11 @@ def __init__(self, nlayers=3, snow_bands=5):
123126 ('lib_albedo' , np .arange (16 , 28 )),
124127 ('lib_veg_rough' , np .arange (28 , 40 )),
125128 ('lib_displacement' , np .arange (40 , 52 )),
126- ('lib_wind_h' , np .array (52 )),
127- ('lib_RGL' , np .array (53 )),
128- ('lib_rad_atten' , np .array (54 )),
129- ('lib_wind_atten' , np .array (55 )),
130- ('lib_trunk_ratio' , np .array (56 )),
131- ('lib_snow_albedo' , np .array (57 ))])
129+ ('lib_wind_h' , np .array ([52 ])),
130+ ('lib_RGL' , np .array ([53 ])),
131+ ('lib_rad_atten' , np .array ([54 ])),
132+ ('lib_wind_atten' , np .array ([55 ])),
133+ ('lib_trunk_ratio' , np .array ([56 ]))])
132134# -------------------------------------------------------------------- #
133135
134136
@@ -507,14 +509,14 @@ def calc_grid(lats, lons, decimals=4):
507509
508510 # check that counts and steps make sense
509511 if lon_step != lat_step :
510- print ( 'WARNING: lon_step ({0}) and lat_step ({1}) do not '
511- 'match' .format (lon_step , lat_step ))
512+ warn ( ' lon_step ({0}) and lat_step ({1}) do not '
513+ 'match' .format (lon_step , lat_step ))
512514 if lat_count / len (ulats ) < 0.95 :
513- print ( 'WARNING: lat_count of mode is less than 95% ({0}%) of'
514- ' len(lats)' .format (lat_count / len (ulats )))
515+ warn ( ' lat_count of mode is less than 95% ({0}%) of'
516+ ' len(lats)' .format (lat_count / len (ulats )))
515517 if lon_count / len (ulons ) < 0.95 :
516- print ( 'WARNING: lon_count of mode is less than 95% ({0}%) of'
517- ' len(lons)' .format (lon_count / len (ulons )))
518+ warn ( ' lon_count of mode is less than 95% ({0}%) of'
519+ ' len(lons)' .format (lon_count / len (ulons )))
518520
519521 if lats .min () < - 55 and lats .max () > 70 :
520522 # assume global grid
@@ -644,7 +646,7 @@ def grid_params(soil_dict, target_grid, snow_dict, veg_dict, veglib_dict,
644646 steps = mydict [var ].shape [1 ]
645647 out_dict [var ] = np .ma .zeros ((steps , ysize , xsize ),
646648 dtype = dtype )
647- for i in xrange (steps ):
649+ for i in pyrange (steps ):
648650 out_dict [var ][i , yi , xi ] = mydict [var ][:, i ]
649651 out_dict [var ][:, ymask , xmask ] = fill_val
650652
@@ -653,10 +655,10 @@ def grid_params(soil_dict, target_grid, snow_dict, veg_dict, veglib_dict,
653655 k = mydict [var ].shape [2 ]
654656 out_dict [var ] = np .ma .zeros ((j , k , ysize , xsize ),
655657 dtype = dtype )
656- for jj in xrange (j ):
657- for kk in xrange (k ):
658+ for jj in pyrange (j ):
659+ for kk in pyrange (k ):
658660 out_dict [var ][jj , kk , yi , xi ] = mydict [var ][:, jj , kk ]
659- for y , x in zip (ymask , xmask ):
661+ for y , x in pyzip (ymask , xmask ):
660662 out_dict [var ][:, :, y , x ] = fill_val
661663
662664 out_dict [var ] = np .ma .masked_values (out_dict [var ], fill_val )
@@ -710,7 +712,7 @@ def grid_params(soil_dict, target_grid, snow_dict, veg_dict, veglib_dict,
710712 new = np .zeros (shape ) + FILLVALUE_F
711713 new [:- 1 , :, yi , xi ] = veglib_dict [lib_var ][:, :, np .newaxis ]
712714 new [- 1 , :, yi , xi ] = 0
713- for y , x in zip (ymask , xmask ):
715+ for y , x in pyzip (ymask , xmask ):
714716 new [:, :, y , x ] = fill_val
715717 out_dicts ['veg_dict' ][var ] = np .ma .masked_values (new , FILLVALUE_F )
716718
@@ -1021,7 +1023,6 @@ def veg(veg_file, soil_dict, max_roots=3, veg_classes=11,
10211023
10221024 row = 0
10231025 cell = 0
1024-
10251026 while row < len (lines ):
10261027 line = lines [row ].strip ('\n ' ).split (' ' )
10271028 gridcel [cell ], nveg [cell ] = np .array (line ).astype (int )
@@ -1078,7 +1079,7 @@ def veg(veg_file, soil_dict, max_roots=3, veg_classes=11,
10781079
10791080
10801081# -------------------------------------------------------------------- #
1081- def veg_class (veg_file , maxcols = 58 , skiprows = 3 , c = Cols ()):
1082+ def veg_class (veg_file , maxcols = 57 , skiprows = 3 , c = Cols ()):
10821083 """
10831084 Load the entire vegetation library file into a dictionary of numpy arrays.
10841085 Also reorders data to match gridcell order of soil file.
@@ -1087,7 +1088,6 @@ def veg_class(veg_file, maxcols=58, skiprows=3, c=Cols()):
10871088 print ('reading {0}' .format (veg_file ))
10881089
10891090 usecols = np .arange (maxcols )
1090- print (usecols , maxcols , skiprows )
10911091
10921092 data = np .loadtxt (veg_file , usecols = usecols , skiprows = skiprows )
10931093
0 commit comments