Commit 25555aba authored by thopri's avatar thopri
Browse files

added config file to remove hard coded paths

parent 8f6d0b5b
...@@ -98,12 +98,13 @@ The PyNEMO module can be tested using the bench marking namelist bdy file in the ...@@ -98,12 +98,13 @@ The PyNEMO module can be tested using the bench marking namelist bdy file in the
Unit Tests Unit Tests
------------------- -------------------
To test operation of the PyNEMO module, running the PyTest script in the unit tests folder will perform a range tests on different child grids, To test operation of the PyNEMO module, running the PyTest script in the unit tests folder will perform a range of tests on different child grids,
checking the interpolation of the source data on to the child grid. To do this the following command is required:: e.g. checking the interpolation of the source data on to the child grid. To do this the following command is required::
$ pytest -q unit_tests/unit_test.py $ pytest -q pynemo/unit_test.py
The command should be run from the main PyNEMO directory to enable modules to be imported correctly. Currently **(26/03/2020)** there are 7 tests that cover checking the interpolation results of different child grids. The input data is generated as part of the
test and is removed afterwards. The number of tests will be increased in the future to cover more PyNEMO functionality.
Who do I talk to? Who do I talk to?
----------------- -----------------
...@@ -114,5 +115,6 @@ Who do I talk to? ...@@ -114,5 +115,6 @@ Who do I talk to?
* Other community or team contact * Other community or team contact
thopri
For more information regarding the use and development of PyNEMO see: [PyNEMO Wiki](https://github.com/jdha/PyNEMO/wiki) For more information regarding the use and development of PyNEMO see: [PyNEMO Wiki](https://github.com/jdha/PyNEMO/wiki)
...@@ -8,6 +8,7 @@ from netCDF4 import Dataset ...@@ -8,6 +8,7 @@ from netCDF4 import Dataset
import numpy as np import numpy as np
import glob import glob
import os import os
from pynemo.unit_tests import UT_config as config
# generate test data by import test gen script and executing main function # generate test data by import test gen script and executing main function
# TODO: Maybe simplify this, as this import imports other scripts and is abit clunky. # TODO: Maybe simplify this, as this import imports other scripts and is abit clunky.
...@@ -19,7 +20,7 @@ if gen_data != 0: ...@@ -19,7 +20,7 @@ if gen_data != 0:
# run PyNEMO with test data # run PyNEMO with test data
# generate list of namelist.bdy files to run # generate list of namelist.bdy files to run
namelist_files = glob.glob('pynemo/unit_tests/namelist*') namelist_files = glob.glob(config.unit_dir+'namelist*')
for n in namelist_files: for n in namelist_files:
# run each of the namelist files # run each of the namelist files
stdout, stderr = Popen(['pynemo', '-s', n], stdout=PIPE, stderr=PIPE, stdout, stderr = Popen(['pynemo', '-s', n], stdout=PIPE, stderr=PIPE,
...@@ -34,7 +35,7 @@ for n in namelist_files: ...@@ -34,7 +35,7 @@ for n in namelist_files:
# perform tests # perform tests
def test_temp(): def test_temp():
test_files = glob.glob('pynemo/unit_tests/test_outputs/*bdyT*') test_files = glob.glob(config.output_dir+'*bdyT*')
if len(test_files) == 0: if len(test_files) == 0:
raise Exception('DONT PANIC: no temperature test files found') raise Exception('DONT PANIC: no temperature test files found')
for t in test_files: for t in test_files:
...@@ -47,7 +48,7 @@ def test_temp(): ...@@ -47,7 +48,7 @@ def test_temp():
assert abs(temp_[temp_ != 0.0].min() - 15) <= 0.001 assert abs(temp_[temp_ != 0.0].min() - 15) <= 0.001
def test_salinty(): def test_salinty():
test_files = glob.glob('pynemo/unit_tests/test_outputs/*bdyT*') test_files = glob.glob(config.output_dir+'*bdyT*')
if len(test_files) == 0: if len(test_files) == 0:
raise Exception('DONT PANIC: no salinity test files found') raise Exception('DONT PANIC: no salinity test files found')
for t in test_files: for t in test_files:
...@@ -63,7 +64,7 @@ def test_salinty(): ...@@ -63,7 +64,7 @@ def test_salinty():
# U and V and SSH tests are required. e.g. ln_dyn2d is set to true. # U and V and SSH tests are required. e.g. ln_dyn2d is set to true.
def test_ssh(): def test_ssh():
test_files = glob.glob('pynemo/unit_tests/test_outputs/*bdyT*') test_files = glob.glob(config.output_dir+'*bdyT*')
if len(test_files) == 0: if len(test_files) == 0:
raise Exception('DONT PANIC: no SSH test files found') raise Exception('DONT PANIC: no SSH test files found')
for t in test_files: for t in test_files:
...@@ -76,7 +77,7 @@ def test_ssh(): ...@@ -76,7 +77,7 @@ def test_ssh():
assert abs(ssh_[ssh_ != 0.0].min() - 1.0) <= 0.001 assert abs(ssh_[ssh_ != 0.0].min() - 1.0) <= 0.001
def test_U(): def test_U():
test_files = glob.glob('pynemo/unit_tests/test_outputs/*bdyU*') test_files = glob.glob(config.output_dir+'*bdyU*')
if len(test_files) == 0: if len(test_files) == 0:
raise Exception('DONT PANIC: no U current test files found') raise Exception('DONT PANIC: no U current test files found')
for t in test_files: for t in test_files:
...@@ -89,7 +90,7 @@ def test_U(): ...@@ -89,7 +90,7 @@ def test_U():
assert abs(U_[U_ != 0.0].min() - 0.5) <= 0.001 assert abs(U_[U_ != 0.0].min() - 0.5) <= 0.001
def test_V(): def test_V():
test_files = glob.glob('pynemo/unit_tests/test_outputs/*bdyV*') test_files = glob.glob(config.output_dir+'*bdyV*')
if len(test_files) == 0: if len(test_files) == 0:
raise Exception('DONT PANIC: no V current test files found') raise Exception('DONT PANIC: no V current test files found')
for t in test_files: for t in test_files:
...@@ -103,16 +104,16 @@ def test_V(): ...@@ -103,16 +104,16 @@ def test_V():
# clean up test I/O # clean up test I/O
def test_rm_out(): def test_rm_out():
files = glob.glob('pynemo/unit_tests/test_outputs/*') files = glob.glob(config.output_dir+'*')
for f in files: for f in files:
os.remove(f) os.remove(f)
files = glob.glob('pynemo/unit_tests/test_outputs/*') files = glob.glob(config.output_dir+'*')
assert len(files) == 0 assert len(files) == 0
def test_rm_in(): def test_rm_in():
files = glob.glob('pynemo/unit_tests/test_inputs/*') files = glob.glob(config.output_dir+'*')
for f in files: for f in files:
os.remove(f) os.remove(f)
files = glob.glob('pynemo/unit_tests/test_inputs/*') files = glob.glob(config.output_dir+'*')
assert len(files) == 0 assert len(files) == 0
# -*- coding: utf-8 -*-
"""
Config file for Unit test functions, file paths for I/O etc are defined here.
"""
# test input directory
input_dir = 'pynemo/unit_tests/test_inputs/'
# test output directory
output_dir = 'pynemo/unit_tests/test_outputs/'
# unit test directory
unit_dir = 'pynemo/unit_tests/'
...@@ -260,152 +260,152 @@ def write_coord_Z(fileout, grid_h,grid_z): ...@@ -260,152 +260,152 @@ def write_coord_Z(fileout, grid_h,grid_z):
return 0 return 0
def write_domcfg(fileout, ln_zco, ln_zps, ln_sco, ln_isfcav, jperio, bat, # def write_domcfg(fileout, ln_zco, ln_zps, ln_sco, ln_isfcav, jperio, bat,
lont, latt, lonu, latu, lonv, latv, lonf, latf, # lont, latt, lonu, latu, lonv, latv, lonf, latf,
e1t, e2t, e1u, e2u, e1v, e2v, e1f, e2f, ff_f, ff_t, # e1t, e2t, e1u, e2u, e1v, e2v, e1f, e2f, ff_f, ff_t,
dept_1d, e3t_1d, e3w_1d, e3t, e3u, e3v, e3f, e3w, e3uw, e3vw, # dept_1d, e3t_1d, e3w_1d, e3t, e3u, e3v, e3f, e3w, e3uw, e3vw,
ktop, kbot): # ktop, kbot):
''' # '''
Writes out a NEMO formatted domcfg file. # Writes out a NEMO formatted domcfg file.
#
Args: # Args:
fileout (string): filename # fileout (string): filename
ln_zco (logical): vertical coordinate flag [z-level] # ln_zco (logical): vertical coordinate flag [z-level]
ln_zps (logical): vertical coordinate flag [z-partial-step] # ln_zps (logical): vertical coordinate flag [z-partial-step]
ln_sco (logical): vertical coordinate flag [sigma] # ln_sco (logical): vertical coordinate flag [sigma]
ln_isfcav (logical): ice cavity flag # ln_isfcav (logical): ice cavity flag
jperio (int): domain type # jperio (int): domain type
bat (np.ndarray): bathymetry array at t-points (2D) # bat (np.ndarray): bathymetry array at t-points (2D)
lon[t/u/v/f](np.ndarray): longitude array at [t/u/v/f]-points (2D) # lon[t/u/v/f](np.ndarray): longitude array at [t/u/v/f]-points (2D)
lat[t/u/v/f](np.ndarray): latitude array at [t/u/v/f]-points (2D) # lat[t/u/v/f](np.ndarray): latitude array at [t/u/v/f]-points (2D)
e1[t/u/v/f] (np.ndarray): zonal scale factors at [t/u/v/f]-points # e1[t/u/v/f] (np.ndarray): zonal scale factors at [t/u/v/f]-points
e2[t/u/v/f] (np.ndarray): meridional scale factors at [t/u/v/f]-points # e2[t/u/v/f] (np.ndarray): meridional scale factors at [t/u/v/f]-points
ff_[f/t] (np.ndarray): coriolis parameter at [t/f]-points # ff_[f/t] (np.ndarray): coriolis parameter at [t/f]-points
dept_1d (np.ndarray): 1D depth levels at t-points # dept_1d (np.ndarray): 1D depth levels at t-points
e3[t/w]_1d (np.ndarray): 1D vertical scale factors at [t/w]-points # e3[t/w]_1d (np.ndarray): 1D vertical scale factors at [t/w]-points
e3[t/u/v/f] (np.ndarray): vertcal scale factors at [t/u/v/f]-points # e3[t/u/v/f] (np.ndarray): vertcal scale factors at [t/u/v/f]-points
e3[w/uw/vw] (np.ndarray): vertcal scale factors at [w/uw/vw]-points # e3[w/uw/vw] (np.ndarray): vertcal scale factors at [w/uw/vw]-points
ktop (np.ndarray): upper most wet point # ktop (np.ndarray): upper most wet point
kbot (np.ndarray): lower most wet point # kbot (np.ndarray): lower most wet point
#
Returns: # Returns:
''' # '''
#
# Open pointer to netcdf file # # Open pointer to netcdf file
dataset = Dataset(fileout, 'w', format='NETCDF4_CLASSIC') # dataset = Dataset(fileout, 'w', format='NETCDF4_CLASSIC')
#
# Get input size and create appropriate dimensions # # Get input size and create appropriate dimensions
# TODO: add some sort of error handling # # TODO: add some sort of error handling
nx, ny, nz = np.shape(e3t) # nx, ny, nz = np.shape(e3t)
dataset.createDimension('x', nx) # dataset.createDimension('x', nx)
dataset.createDimension('y', ny) # dataset.createDimension('y', ny)
dataset.createDimension('z', nz) # dataset.createDimension('z', nz)
#
# create Variables # # create Variables
nav_lon = dataset.createVariable('nav_lon', np.float32, ('y', 'x')) # nav_lon = dataset.createVariable('nav_lon', np.float32, ('y', 'x'))
nav_lat = dataset.createVariable('nav_lat', np.float32, ('y', 'x')) # nav_lat = dataset.createVariable('nav_lat', np.float32, ('y', 'x'))
nav_lev = dataset.createVariable('nav_lev', np.float32, 'z') # nav_lev = dataset.createVariable('nav_lev', np.float32, 'z')
#
giglo = dataset.createVariable('jpiglo', "i4") # giglo = dataset.createVariable('jpiglo', "i4")
gjglo = dataset.createVariable('jpjglo', "i4") # gjglo = dataset.createVariable('jpjglo', "i4")
gkglo = dataset.createVariable('jpkglo', "i4") # gkglo = dataset.createVariable('jpkglo', "i4")
#
gperio = dataset.createVariable('jperio', "i4") # gperio = dataset.createVariable('jperio', "i4")
#
gzco = dataset.createVariable('ln_zco', "i4") # gzco = dataset.createVariable('ln_zco', "i4")
gzps = dataset.createVariable('ln_zps', "i4") # gzps = dataset.createVariable('ln_zps', "i4")
gsco = dataset.createVariable('ln_sco', "i4") # gsco = dataset.createVariable('ln_sco', "i4")
gcav = dataset.createVariable('ln_isfcav', "i4") # gcav = dataset.createVariable('ln_isfcav', "i4")
#
ge3t1d = dataset.createVariable('e3t_1d', np.float64, 'z') # ge3t1d = dataset.createVariable('e3t_1d', np.float64, 'z')
ge3w1d = dataset.createVariable('e3w_1d', np.float64, 'z') # ge3w1d = dataset.createVariable('e3w_1d', np.float64, 'z')
gitop = dataset.createVariable('top_level', "i4", ('y', 'x')) # gitop = dataset.createVariable('top_level', "i4", ('y', 'x'))
gibot = dataset.createVariable('bottom_level', "i4", ('y', 'x')) # gibot = dataset.createVariable('bottom_level', "i4", ('y', 'x'))
gbat = dataset.createVariable('Bathymetry', np.float64, ('y', 'x')) # gbat = dataset.createVariable('Bathymetry', np.float64, ('y', 'x'))
glamt = dataset.createVariable('glamt', np.float64, ('y', 'x')) # glamt = dataset.createVariable('glamt', np.float64, ('y', 'x'))
glamu = dataset.createVariable('glamu', np.float64, ('y', 'x')) # glamu = dataset.createVariable('glamu', np.float64, ('y', 'x'))
glamv = dataset.createVariable('glamv', np.float64, ('y', 'x')) # glamv = dataset.createVariable('glamv', np.float64, ('y', 'x'))
glamf = dataset.createVariable('glamf', np.float64, ('y', 'x')) # glamf = dataset.createVariable('glamf', np.float64, ('y', 'x'))
gphit = dataset.createVariable('gphit', np.float64, ('y', 'x')) # gphit = dataset.createVariable('gphit', np.float64, ('y', 'x'))
gphiu = dataset.createVariable('gphiu', np.float64, ('y', 'x')) # gphiu = dataset.createVariable('gphiu', np.float64, ('y', 'x'))
gphiv = dataset.createVariable('gphiv', np.float64, ('y', 'x')) # gphiv = dataset.createVariable('gphiv', np.float64, ('y', 'x'))
gphif = dataset.createVariable('gphif', np.float64, ('y', 'x')) # gphif = dataset.createVariable('gphif', np.float64, ('y', 'x'))
ge1t = dataset.createVariable('e1t', np.float64, ('y', 'x')) # ge1t = dataset.createVariable('e1t', np.float64, ('y', 'x'))
ge1u = dataset.createVariable('e1u', np.float64, ('y', 'x')) # ge1u = dataset.createVariable('e1u', np.float64, ('y', 'x'))
ge1v = dataset.createVariable('e1v', np.float64, ('y', 'x')) # ge1v = dataset.createVariable('e1v', np.float64, ('y', 'x'))
ge1f = dataset.createVariable('e1f', np.float64, ('y', 'x')) # ge1f = dataset.createVariable('e1f', np.float64, ('y', 'x'))
ge2t = dataset.createVariable('e2t', np.float64, ('y', 'x')) # ge2t = dataset.createVariable('e2t', np.float64, ('y', 'x'))
ge2u = dataset.createVariable('e2u', np.float64, ('y', 'x')) # ge2u = dataset.createVariable('e2u', np.float64, ('y', 'x'))
ge2v = dataset.createVariable('e2v', np.float64, ('y', 'x')) # ge2v = dataset.createVariable('e2v', np.float64, ('y', 'x'))
ge2f = dataset.createVariable('e2f', np.float64, ('y', 'x')) # ge2f = dataset.createVariable('e2f', np.float64, ('y', 'x'))
gfff = dataset.createVariable('ff_f', np.float64, ('y', 'x')) # gfff = dataset.createVariable('ff_f', np.float64, ('y', 'x'))
gfft = dataset.createVariable('ff_t', np.float64, ('y', 'x')) # gfft = dataset.createVariable('ff_t', np.float64, ('y', 'x'))
ge3t = dataset.createVariable('e3t_0', np.float64, ('z', 'y', 'x')) # ge3t = dataset.createVariable('e3t_0', np.float64, ('z', 'y', 'x'))
ge3w = dataset.createVariable('e3w_0', np.float64, ('z', 'y', 'x')) # ge3w = dataset.createVariable('e3w_0', np.float64, ('z', 'y', 'x'))
ge3u = dataset.createVariable('e3u_0', np.float64, ('z', 'y', 'x')) # ge3u = dataset.createVariable('e3u_0', np.float64, ('z', 'y', 'x'))
ge3v = dataset.createVariable('e3v_0', np.float64, ('z', 'y', 'x')) # ge3v = dataset.createVariable('e3v_0', np.float64, ('z', 'y', 'x'))
ge3f = dataset.createVariable('e3f_0', np.float64, ('z', 'y', 'x')) # ge3f = dataset.createVariable('e3f_0', np.float64, ('z', 'y', 'x'))
ge3uw = dataset.createVariable('e3uw_0', np.float64, ('z', 'y', 'x')) # ge3uw = dataset.createVariable('e3uw_0', np.float64, ('z', 'y', 'x'))
ge3vw = dataset.createVariable('e3vw_0', np.float64, ('z', 'y', 'x')) # ge3vw = dataset.createVariable('e3vw_0', np.float64, ('z', 'y', 'x'))
#
nav_lon.units, nav_lon.long_name = 'km', 'X' # nav_lon.units, nav_lon.long_name = 'km', 'X'
nav_lat.units, nav_lat.long_name = 'km', 'Y' # nav_lat.units, nav_lat.long_name = 'km', 'Y'
#
# Populate file with input data # # Populate file with input data
giglo[:] = nx # giglo[:] = nx
gjglo[:] = ny # gjglo[:] = ny
gkglo[:] = nz # gkglo[:] = nz
#
gzco[:] = ln_zco # gzco[:] = ln_zco
gzps[:] = ln_zps # gzps[:] = ln_zps
gsco[:] = ln_sco # gsco[:] = ln_sco
gcav[:] = ln_isfcav # gcav[:] = ln_isfcav
#
gperio[:] = jperio # gperio[:] = jperio
#
# TODO: do we need to transpose? # # TODO: do we need to transpose?
nav_lon[:, :] = lont.T # nav_lon[:, :] = lont.T
nav_lat[:, :] = latt.T # nav_lat[:, :] = latt.T
nav_lev[:] = dept_1d # nav_lev[:] = dept_1d
#
ge3t1d[:] = e3t_1d # ge3t1d[:] = e3t_1d
ge3w1d[:] = e3w_1d # ge3w1d[:] = e3w_1d
#
gitop[:, :] = ktop.T # gitop[:, :] = ktop.T
gibot[:, :] = kbot.T # gibot[:, :] = kbot.T
#
gbat[:, :] = bat.T # gbat[:, :] = bat.T
#
glamt[:, :] = lont.T # glamt[:, :] = lont.T
glamu[:, :] = lonu.T # glamu[:, :] = lonu.T
glamv[:, :] = lonv.T # glamv[:, :] = lonv.T
glamf[:, :] = lonf.T # glamf[:, :] = lonf.T
gphit[:, :] = latt.T # gphit[:, :] = latt.T
gphiu[:, :] = latu.T # gphiu[:, :] = latu.T
gphiv[:, :] = latv.T # gphiv[:, :] = latv.T
gphif[:, :] = latf.T # gphif[:, :] = latf.T
#
ge1t[:, :] = e1t.T # ge1t[:, :] = e1t.T
ge1u[:, :] = e1u.T # ge1u[:, :] = e1u.T
ge1v[:, :] = e1v.T # ge1v[:, :] = e1v.T
ge1f[:, :] = e1f.T # ge1f[:, :] = e1f.T
ge2t[:, :] = e2t.T # ge2t[:, :] = e2t.T
ge2u[:, :] = e2u.T # ge2u[:, :] = e2u.T
ge2v[:, :] = e2v.T # ge2v[:, :] = e2v.T
ge2f[:, :] = e2f.T # ge2f[:, :] = e2f.T
gfff[:, :] = ff_f.T # gfff[:, :] = ff_f.T
gfft[:, :] = ff_t.T # gfft[:, :] = ff_t.T
#
ge3t[:, :, :] = e3t.T # ge3t[:, :, :] = e3t.T
ge3w[:, :, :] = e3w.T # ge3w[:, :, :] = e3w.T
ge3u[:, :, :] = e3u.T # ge3u[:, :, :] = e3u.T
ge3v[:, :, :] = e3v.T # ge3v[:, :, :] = e3v.T
ge3f[:, :, :] = e3f.T # ge3f[:, :, :] = e3f.T
ge3uw[:, :, :] = e3uw.T # ge3uw[:, :, :] = e3uw.T
ge3vw[:, :, :] = e3vw.T # ge3vw[:, :, :] = e3vw.T
#
# Close off pointer # # Close off pointer
dataset.close() # dataset.close()
def rotate_around_point(lat_in,lon_in, radians , origin=(0, 0)): def rotate_around_point(lat_in,lon_in, radians , origin=(0, 0)):
"""Rotate a point around a given point. """Rotate a point around a given point.
......
...@@ -7,11 +7,14 @@ The source coordinate grid is also plotted (green). ...@@ -7,11 +7,14 @@ The source coordinate grid is also plotted (green).
""" """
from pynemo.unit_tests import gen_tools as gt from pynemo.unit_tests import gen_tools as gt
from pynemo.unit_tests import UT_config as config
# TODO: remove hard coded file names and directories. # TODO: remove hard coded file names and directories.
# TODO: organise the variables better, (maybe in a single dict?) # TODO: organise the variables better, (maybe in a single dict?)
def _main(): def _main():
#define directory for test input data for PyNEMO
#Source Coords #Source Coords
dx = 1000 # units in km dx = 1000 # units in km
dy = 1000 # units in Km dy = 1000 # units in Km
...@@ -21,8 +24,8 @@ def _main(): ...@@ -21,8 +24,8 @@ def _main():
max_dep = 100 max_dep = 100
min_dep = 10 min_dep = 10
z_end_dim = 1 z_end_dim = 1
h_fname = 'pynemo/unit_tests/test_inputs/test_src_hgr_zps.nc' h_fname = config.input_dir+'test_src_hgr_zps.nc'
z_fname = 'pynemo/unit_tests/test_inputs/test_src_zgr_zps.nc' z_fname = config.input_dir+'test_src_zgr_zps.nc'
grid_h1 = gt.set_hgrid(dx,dy,jpi,jpj) grid_h1 = gt.set_hgrid(dx,dy,jpi,jpj)
grid_z1 = gt.set_zgrid(grid_h1,jpk,max_dep,min_dep,z_end_dim) grid_z1 = gt.set_zgrid(grid_h1,jpk,max_dep,min_dep,z_end_dim)
write_coord_H = gt.write_coord_H(h_fname,grid_h1) write_coord_H = gt.write_coord_H(h_fname,grid_h1)
...@@ -42,14 +45,14 @@ def _main(): ...@@ -42,14 +45,14 @@ def _main():
min_dep = 10 min_dep = 10
z_end_dim = 1 z_end_dim = 1
sf = 10 sf = 10
h_fname = 'pynemo/unit_tests/test_inputs/test_dst_hgr_zps.nc' h_fname = config.input_dir+'test_dst_hgr_zps.nc'
z_fname = 'pynemo/unit_tests/test_inputs/test_dst_zgr_zps.nc' z_fname = config.input_dir+'test_dst_zgr_zps.nc'
grid_h2 = gt.set_hgrid(dx,dy,jpi,jpj,zoffx,zoffy,sf) grid_h2 = gt.set_hgrid(dx,dy,jpi,jpj,zoffx,zoffy,sf)
grid_z2 = gt.set_zgrid(grid_h2,jpk,max_dep,min_dep,z_end_dim) grid_z2 = gt.set_zgrid(grid_h2,jpk,max_dep,min_dep,z_end_dim)
write_coord_H = gt.write_coord_H(h_fname,grid_h2) write_coord_H = gt.write_coord_H(h_fname,grid_h2)
write_coord_Z = gt.write_coord_Z(z_fname,grid_h2,grid_z2) write_coord_Z = gt.write_coord_Z(z_fname,grid_h2,grid_z2)
# write bathy files (constant bathy) # write bathy files (constant bathy)
bathy_fname = 'pynemo/unit_tests/test_inputs/test_dst_bathy.nc' bathy_fname = config.input_dir+'test_dst_bathy.nc'
bathy = gt.write_bathy(bathy_fname,grid_h2,grid_z2) bathy = gt.write_bathy(bathy_fname,grid_h2,grid_z2)
if write_coord_H + write_coord_Z + bathy == 0: if write_coord_H + write_coord_Z + bathy == 0:
print("Org child grid generation successful!") print("Org child grid generation successful!")
...@@ -60,8 +63,8 @@ def _main(): ...@@ -60,8 +63,8 @@ def _main():
origin = (8,8) origin = (8,8)
# rotate grid # rotate grid
rot_h_fname = 'pynemo/unit_tests/test_inputs/test_rot_dst_hgr_zps.nc' rot_h_fname = config.input_dir+'test_rot_dst_hgr_zps.nc'
rot_z_fname = 'pynemo/unit_tests/test_inputs/test_rot_dst_zgr_zps.nc' rot_z_fname = config.input_dir+'test_rot_dst_zgr_zps.nc'
grid_rot = grid_h2.copy() grid_rot = grid_h2.copy()
grid_rot['latt'], grid_rot['lont'] = gt.rotate_around_point(grid_h2['latt'],grid_h2['lont'],theta,origin) grid_rot['latt'], grid_rot['lont'] = gt.rotate_around_point(grid_h2['latt'],grid_h2['lont'],theta,origin)
grid_rot['latu'], grid_rot['lonu'] = gt.rotate_around_point(grid_h2['latu'], grid_h2['lonu'], theta, origin) grid_rot['latu'], grid_rot['lonu'] = gt.rotate_around_point(grid_h2['latu'], grid_h2['lonu'], theta, origin)
...@@ -70,7 +73,7 @@ def _main(): ...@@ -70,7 +73,7 @@ def _main():
write_coord_H = gt.write_coord_H(rot_h_fname,grid_rot) write_coord_H = gt.write_coord_H(rot_h_fname,grid_rot)
write_coord_Z = gt.write_coord_Z(rot_z_fname,grid_rot,grid_z2) write_coord_Z = gt.write_coord_Z(rot_z_fname,grid_rot,grid_z2)
# write bathy files (constant bathy) # write bathy files (constant bathy)
bathy_fname = 'pynemo/unit_tests/test_inputs/test_rot_dst_bathy.nc' bathy_fname = config.input_dir+'test_rot_dst_bathy.nc'
bathy = gt.write_bathy(bathy_fname,grid_rot,grid_z2) bathy = gt.write_bathy(bathy_fname,grid_rot,grid_z2)
if write_coord_H + write_coord_Z + bathy == 0: if write_coord_H + write_coord_Z + bathy == 0:
print("Rotated child grid generation Successful!") print("Rotated child grid generation Successful!")
...@@ -87,14 +90,14 @@ def _main(): ...@@ -87,14 +90,14 @@ def _main():
min_dep = 10 min_dep = 10
z_end_dim = 1 z_end_dim = 1
sf = 10 sf = 10
h_fname = 'pynemo/unit_tests/test_inputs/test_offset_dst_hgr_zps.nc' h_fname = config.input_dir+'test_offset_dst_hgr_zps.nc'
z_fname = 'pynemo/unit_tests/test_inputs/test_offset_dst_zgr_zps.nc' z_fname = config.input_dir+'test_offset_dst_zgr_zps.nc'
grid_h3 = gt.set_hgrid(dx,dy,jpi,jpj,zoffx,zoffy,sf) grid_h3 = gt.set_hgrid(dx,dy,jpi,jpj,zoffx,zoffy,sf)
grid_z3 = gt.set_zgrid(grid_h2,jpk,max_dep,min_dep,z_end_dim) grid_z3 = gt.set_zgrid(grid_h2,jpk,max_dep,min_dep,z_end_dim)
write_coord_H = gt.write_coord_H(h_fname,grid_h3) write_coord_H = gt.write_coord_H(h_fname,grid_h3)
write_coord_Z = gt.write_coord_Z(z_fname,grid_h3,grid_z3) write_coord_Z = gt.write_coord_Z(z_fname,grid_h3,grid_z3)
# write bathy files (constant bathy) # write bathy files (constant bathy)
bathy_fname = 'pynemo/unit_tests/test_inputs/test_offset_dst_bathy.nc' bathy_fname = config.input_dir+'test_offset_dst_bathy.nc'
bathy = gt.write_bathy(bathy_fname,grid_h3,grid_z3) bathy = gt.write_bathy(bathy_fname,grid_h3,grid_z3)
if write_coord_H + write_coord_Z + bathy == 0: if write_coord_H + write_coord_Z + bathy == 0:
print("Offset child grid gneration successful!") print("Offset child grid gneration successful!")
...@@ -104,7 +107,7 @@ def _main(): ...@@ -104,7 +107,7 @@ def _main():
# grid_h3['lont'],grid_h1['latt'],grid_h1['lont']) # grid_h3['lont'],grid_h1['latt'],grid_h1['lont'])
# write boundary files (constant parameters) # write boundary files (constant parameters)
out_fname = 'pynemo/unit_tests/test_inputs/output_boundary' #drop file extension out_fname = config.input_dir+'output_boundary' #drop file extension
params_t = {'param1': {'name':'thetao','const_value':15.0,'longname':'temperature','units':'degreesC'}, params_t = {'param1': {'name':'thetao','const_value':15.0,'longname':'temperature','units':'degreesC'},
'param2': {'name':'so','const_value':35.0,'longname':'salinity','units':'PSU'}, 'param2': {'name':'so','const_value':35.0,'longname':'salinity','units':'PSU'},
'param3': {'name': 'zos', 'const_value': 1.0, 'longname': 'sea surface height', 'units': 'metres'} 'param3': {'name': 'zos', 'const_value': 1.0, 'longname': 'sea surface height', 'units': 'metres'}
...@@ -121,7 +124,7 @@ def _main(): ...@@ -121,7 +124,7 @@ def _main():
print('Boundary file generation successful!') print('Boundary file generation successful!')
#write_mask #write_mask
mask_fname = 'pynemo/unit_tests/test_inputs/mask.nc' mask_fname = config.input_dir+'mask.nc'
mask = gt.write_mask(mask_fname,grid_h1,grid_z1) mask = gt.write_mask(mask_fname,grid_h1,grid_z1)
if mask == 0: if mask == 0:
print('Mask file generation successful!') print('Mask file generation successful!')
......
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