diff --git a/tonic/models/vic/netcdf2vic.py b/tonic/models/vic/netcdf2vic.py old mode 100644 new mode 100755 index d7ec1b4..37341ae --- a/tonic/models/vic/netcdf2vic.py +++ b/tonic/models/vic/netcdf2vic.py @@ -17,18 +17,20 @@ def _run(args): config = read_config(args.config) - files = config['options']['files'] - var_keys = config['options']['var_keys'] - output = config['options']['output'] - binary_mult = config['options']['binary_mult'] - binary_type = config['options']['binary_type'], - paths = config['options']['paths'] - out_prefix = config['options']['out_prefix'] - verbose = config['options']['verbose'] - - mask = read_netcdf(paths['mask_path'], nc_vars=['mask'])['mask'] + files = [config['Basics']['files']] + var_keys = [config['Basics']['var_keys']] + output = config['Paths']['ASCIIoutPath'] + #binary_mult = config['Basics']['binary_mult'] + #binary_type = config['Basics']['binary_type'], + paths = config['Paths'] + out_prefix = config['Basics']['out_prefix'] + verbose = config['Basics']['verbose'] + mask = read_netcdf(paths['mask_path'], variables=['mask'])[0]['mask'] yi, xi = np.nonzero(mask) - print('found {0} points in mask file.'.format(len(yi))) + print(mask) + print('found {0} points in mask fqile.'.format(len(xi))) + #x = read_netcdf(os.path.join(paths['in_path'], 'pr_1979.nc')) + #print(x) xlist = [] ylist = [] @@ -37,25 +39,27 @@ def _run(args): for i, fname in enumerate(files): d = read_netcdf(os.path.join(paths['in_path'], fname), - verbose=verbose) - + verbose=verbose)[0] + print(i) if i == 0: # find point locations - xs = d['xc'] - ys = d['yc'] + xs = d['lon'] + ys = d['lat'] posinds = np.nonzero(xs > 180) xs[posinds] -= 360 print('adjusted xs lon minimum') + for y, x in pyzip(yi, xi): active_flag = False for key in var_keys: if (d[key][:, y, x].all() is np.ma.masked) \ or (mask[y, x] == 0): active_flag = True - if not active_flag: - point = (ys[y, x], xs[y, x]) + if not active_flag: + point = (ys[y], xs[x]) + print(point) xlist.append(x) ylist.append(y) pointlist.append(point) @@ -70,11 +74,11 @@ def _run(args): for j, key in enumerate(var_keys): data[:, j] = d[key][:, y, x] - if output['Binary']: - write_binary(data * binary_mult, point, binary_type, - out_prefix, paths['BinaryoutPath'], append) - if output['ASCII']: - write_ascii(data, point, out_prefix, paths['ASCIIoutPath'], + #if output['Binary']: + # write_binary(data * binary_mult, point, binary_type, + # out_prefix, paths['BinaryoutPath'], append) + #if output['ASCII']: + write_ascii(data, point, out_prefix, paths['ASCIIoutPath'], append) return # -------------------------------------------------------------------- # @@ -86,7 +90,7 @@ def write_ascii(array, point, out_prefix, path, append, verbose=False): """ Write an array to standard VIC ASCII output. """ - fname = out_prefix + ('%1.3f' % point[0]) + '_' + ('%1.3f' % point[1]) + fname = out_prefix + ('%1.5f' % point[0]) + '_' + ('%1.5f' % point[1]) out_file = os.path.join(path, fname) if append: f = open(out_file, 'a')