From 0d6fa73241c11066f06440ad58d989bec2a3e738 Mon Sep 17 00:00:00 2001 From: Sierd Date: Mon, 3 Jul 2017 21:18:27 +0200 Subject: [PATCH 1/4] added grid direction wrt north --- aeolis/constants.py | 3 ++- aeolis/wind.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/aeolis/constants.py b/aeolis/constants.py index 481c0d0c..9743212b 100644 --- a/aeolis/constants.py +++ b/aeolis/constants.py @@ -155,7 +155,8 @@ 'max_error' : 1e-6, # [-] Maximum error at which to quit iterative solution in implicit numerical schemes 'max_iter' : 1000, # [-] Maximum number of iterations at which to quit iterative solution in implicit numerical schemes 'refdate' : '1970-01-01 00:00', # [-] Reference datetime in netCDF output - 'callback' : None, # Reference to callback function (e.g. example/callback.py':callback) + 'callback' : None, # Reference to callback function (e.g. example/callback.py':callback) + 'grid_dir' : 0, # direction of the grid with respect to geograpic north } diff --git a/aeolis/wind.py b/aeolis/wind.py index 73440844..4c9ae5e4 100644 --- a/aeolis/wind.py +++ b/aeolis/wind.py @@ -76,7 +76,7 @@ def interpolate(s, p, t): uw_t = p['wind_file'][:,0] uw_s = p['wind_file'][:,1] - uw_d = p['wind_file'][:,2] / 180. * np.pi + uw_d = p['wind_file'][:,2] / 180. * np.pi - 90 + p['grid_dir'] s['uw'][:,:] = interp_circular(t, uw_t, uw_s) s['udir'][:,:] = np.arctan2(np.interp(t, uw_t, np.sin(uw_d)), From 6ea065adada14b0aa34b5efdf4a665e474456445 Mon Sep 17 00:00:00 2001 From: Sierd Date: Tue, 4 Jul 2017 13:08:51 +0200 Subject: [PATCH 2/4] Implement option for cartesian and nautical axis definition for wind direction. --- aeolis/constants.py | 2 +- aeolis/inout.py | 4 ++++ aeolis/wind.py | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/aeolis/constants.py b/aeolis/constants.py index 9743212b..d167972d 100644 --- a/aeolis/constants.py +++ b/aeolis/constants.py @@ -156,7 +156,7 @@ 'max_iter' : 1000, # [-] Maximum number of iterations at which to quit iterative solution in implicit numerical schemes 'refdate' : '1970-01-01 00:00', # [-] Reference datetime in netCDF output 'callback' : None, # Reference to callback function (e.g. example/callback.py':callback) - 'grid_dir' : 0, # direction of the grid with respect to geograpic north + 'wind_dir' : 'cartesian', # direction of the grid with respect to geograpic north } diff --git a/aeolis/inout.py b/aeolis/inout.py index 3fe79653..02a177dc 100644 --- a/aeolis/inout.py +++ b/aeolis/inout.py @@ -93,6 +93,10 @@ def read_configfile(configfile, parse_files=True, load_defaults=True): else: raise IOError('File not found [%s]' % configfile) + # rotate nautical wind direction to cartesian grid + if p['wind_dir'] == 'nautical' and parse_files==True: + p['wind_file'][:,2] = 270-p['wind_file'][:,2] + # normalize grain size distribution if 'grain_dist' in p: p['grain_dist'] = normalize(p['grain_dist']) diff --git a/aeolis/wind.py b/aeolis/wind.py index 4c9ae5e4..73440844 100644 --- a/aeolis/wind.py +++ b/aeolis/wind.py @@ -76,7 +76,7 @@ def interpolate(s, p, t): uw_t = p['wind_file'][:,0] uw_s = p['wind_file'][:,1] - uw_d = p['wind_file'][:,2] / 180. * np.pi - 90 + p['grid_dir'] + uw_d = p['wind_file'][:,2] / 180. * np.pi s['uw'][:,:] = interp_circular(t, uw_t, uw_s) s['udir'][:,:] = np.arctan2(np.interp(t, uw_t, np.sin(uw_d)), From c74b9aca48fa2b004dd5405df433e7a510eca88c Mon Sep 17 00:00:00 2001 From: Bas Hoonhout Date: Tue, 4 Jul 2017 13:12:07 +0200 Subject: [PATCH 3/4] Changed parameter name to "wind_convention" --- aeolis/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aeolis/constants.py b/aeolis/constants.py index d167972d..768aff0f 100644 --- a/aeolis/constants.py +++ b/aeolis/constants.py @@ -156,7 +156,7 @@ 'max_iter' : 1000, # [-] Maximum number of iterations at which to quit iterative solution in implicit numerical schemes 'refdate' : '1970-01-01 00:00', # [-] Reference datetime in netCDF output 'callback' : None, # Reference to callback function (e.g. example/callback.py':callback) - 'wind_dir' : 'cartesian', # direction of the grid with respect to geograpic north + 'wind_convention' : 'cartesian', # Convention used for the wind direction in the input files } From 362087b06422047bde688e71ef8499cacc3d3821 Mon Sep 17 00:00:00 2001 From: Bas Hoonhout Date: Tue, 4 Jul 2017 13:24:42 +0200 Subject: [PATCH 4/4] Moved convention transformation --- aeolis/inout.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/aeolis/inout.py b/aeolis/inout.py index 02a177dc..ec2f68af 100644 --- a/aeolis/inout.py +++ b/aeolis/inout.py @@ -92,10 +92,6 @@ def read_configfile(configfile, parse_files=True, load_defaults=True): p[key.strip()] = parse_value(val, parse_files=parse_files) else: raise IOError('File not found [%s]' % configfile) - - # rotate nautical wind direction to cartesian grid - if p['wind_dir'] == 'nautical' and parse_files==True: - p['wind_file'][:,2] = 270-p['wind_file'][:,2] # normalize grain size distribution if 'grain_dist' in p: @@ -198,6 +194,14 @@ def check_configuration(p): if p['wind_file'].ndim != 2 or p['wind_file'].shape[1] < 3: raise ValueError('Invalid wind definition file') + # rotate nautical wind direction to cartesian grid + if p['wind_convention'] == 'cartesian': + pass + elif p['wind_convention'] == 'nautical': + p['wind_file'][:,2] = 270.0 - p['wind_file'][:,2] + else: + raise ValueError('Unknown convention: %s' % p['wind_convention']) + if isarray(p['tide_file']): if p['tide_file'].ndim != 2 or p['tide_file'].shape[1] < 2: raise ValueError('Invalid tide definition file')