-
Notifications
You must be signed in to change notification settings - Fork 34
changed to better match the config file, also changed some indexing p… #33
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change was required because my original code was assuming the xs/ys were 2d. If we used |
||
| 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'], | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure why this was changed but we should make sure the example configuration file works with both Binary and ASCII output. |
||
| 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') | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should just specify these values in the configuration file.