Commit d35c2587 authored by thopri's avatar thopri
Browse files

fixed rotated grid test case

parent 12043a0e
......@@ -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
......
......@@ -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'
......
......@@ -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
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment