From d35c25872e7bc4cfc2250792961515e2f1f255ff Mon Sep 17 00:00:00 2001
From: thopri <thopri@noc.ac.uk>
Date: Tue, 24 Mar 2020 07:30:02 +0000
Subject: [PATCH] fixed rotated grid test case

---
 pynemo/nemo_bdy_extr_tm3.py            |  2 ++
 unit_tests/gen_tools.py                |  8 +++-----
 unit_tests/namelist_unit_test_orth.bdy |  2 +-
 unit_tests/test_gen.py                 | 25 ++++++++++++++++---------
 4 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/pynemo/nemo_bdy_extr_tm3.py b/pynemo/nemo_bdy_extr_tm3.py
index 4d7c745..632e035 100644
--- a/pynemo/nemo_bdy_extr_tm3.py
+++ b/pynemo/nemo_bdy_extr_tm3.py
@@ -275,6 +275,8 @@ class Extract:
         dist_merid = diff_lon_rv * np.cos(dst_lat_rep * np.pi / 180)
         dist_zonal = sc_lat_rv[ind_rv] - dst_lat_rep
 
+        # TODO: would a greater circle distance function be better here?
+
         dist_tot = np.power((np.power(dist_merid, 2) +
                              np.power(dist_zonal, 2)), 0.5)
         dist_tot = dist_tot.reshape(ind.shape, order='F').T
diff --git a/unit_tests/gen_tools.py b/unit_tests/gen_tools.py
index 6dddbf9..cd55564 100644
--- a/unit_tests/gen_tools.py
+++ b/unit_tests/gen_tools.py
@@ -534,7 +534,7 @@ def write_mask(fileout,grid_h,grid_z):
 
     return 0
 
-def write_parameter(fileout, grid_h,grid_z,params):
+def write_parameter(fileout, grid_h,grid_z,params,grid):
     '''
     Writes out a
 
@@ -543,10 +543,8 @@ def write_parameter(fileout, grid_h,grid_z,params):
     Returns:
     '''
 
-    #TODO: implement multiple parameters using params dict.
-
     # Open pointer to netcdf file
-    dataset = Dataset(fileout, 'w', format='NETCDF4_CLASSIC')
+    dataset = Dataset(fileout+'_'+grid.upper()+'.nc', 'w', format='NETCDF4_CLASSIC')
 
     # Get input size and create appropriate dimensions
     # TODO: add some sort of error handling
@@ -560,7 +558,7 @@ def write_parameter(fileout, grid_h,grid_z,params):
     # Create Variables
     longitude = dataset.createVariable('longitude', np.float32, ('y', 'x'))
     latitude = dataset.createVariable('latitude', np.float32, ('y', 'x'))
-    depth = dataset.createVariable('depth', np.float32, 'z')
+    depth = dataset.createVariable('depth'+grid, np.float32, 'z')
     time_counter = dataset.createVariable('time', np.float32, ('time'))
     longitude.units, longitude.long_name = 'km', 'X'
     latitude.units, latitude.long_name = 'km', 'Y'
diff --git a/unit_tests/namelist_unit_test_orth.bdy b/unit_tests/namelist_unit_test_orth.bdy
index b1df9ab..35e9d9d 100644
--- a/unit_tests/namelist_unit_test_orth.bdy
+++ b/unit_tests/namelist_unit_test_orth.bdy
@@ -61,7 +61,7 @@
     ln_mask_file   = .false.              !  =T : read mask from file
     cn_mask_file   = 'mask.nc'            !  name of mask file 
                                           !  (if ln_mask_file=.TRUE.)
-    ln_dyn2d       = .false.              !  boundary conditions for 
+    ln_dyn2d       = .false.              !  boundary conditions for
                                           !  barotropic fields
     ln_dyn3d       = .false.              !  boundary conditions for 
                                           !  baroclinic velocities
diff --git a/unit_tests/test_gen.py b/unit_tests/test_gen.py
index d11b692..0d6f982 100644
--- a/unit_tests/test_gen.py
+++ b/unit_tests/test_gen.py
@@ -80,8 +80,8 @@ def _main():
     dy = 100 # units in Km
     jpi = 100
     jpj = 100
-    zoffx = 25
-    zoffy = 25
+    zoffx = 35
+    zoffy = 35
     jpk = 10
     max_dep = 100
     min_dep = 10
@@ -100,17 +100,24 @@ def _main():
         print("Offset child grid gneration successful!")
 
     # plot orginal, rotatated and source lat and lon
-    gt.plot_grids(grid_h2['latt'],grid_h2['lont'],grid_rot['latt'],grid_rot['lont'],grid_h3['latt'], \
-               grid_h3['lont'],grid_h1['latt'],grid_h1['lont'])
+    #gt.plot_grids(grid_h2['latt'],grid_h2['lont'],grid_rot['latt'],grid_rot['lont'],grid_h3['latt'], \
+    #           grid_h3['lont'],grid_h1['latt'],grid_h1['lont'])
 
     # write boundary files (constant parameters)
-    out_fname = 'unit_tests/test_data/output_boundary_T.nc'
-    params = {'param1': {'name':'thetao','const_value':15.0,'longname':'temperature','units':'degreesC'},
-              'param2': {'name':'so','const_value':35.0,'longname':'salinity','units':'PSU'}
+    out_fname = 'unit_tests/test_data/output_boundary' #drop file extension
+    params_t = {'param1': {'name':'thetao','const_value':15.0,'longname':'temperature','units':'degreesC'},
+              'param2': {'name':'so','const_value':35.0,'longname':'salinity','units':'PSU'},
+              'param3': {'name': 'zos', 'const_value': 1.0, 'longname': 'sea surface height', 'units': 'metres'}
+              }
+    params_u = {'param1': {'name':'uo','const_value':0.5,'longname':'Zonal current','units':'ms-1'}
+              }
+    params_v = {'param1': {'name':'vo','const_value':0.5,'longname':'Meridional current','units':'ms-1'}
               }
     # TODO: This needs to be adapted for parameters that are not on the T grid.
-    boundary = gt.write_parameter(out_fname,grid_h1,grid_z1,params)
-    if boundary == 0:
+    boundary_T = gt.write_parameter(out_fname,grid_h1,grid_z1,params_t,'t')
+    boundary_U = gt.write_parameter(out_fname, grid_h1, grid_z1, params_u, 'u')
+    boundary_V = gt.write_parameter(out_fname, grid_h1, grid_z1, params_v, 'v')
+    if boundary_T + boundary_U + boundary_V == 0:
         print('Boundary file generation successful!')
 
     #write_mask
-- 
GitLab