Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
thopri
PyNEMO
Commits
12043a0e
Commit
12043a0e
authored
5 years ago
by
thopri
Browse files
Options
Download
Email Patches
Plain Diff
updated grid size on test cases
parent
4bf5c365
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
18 deletions
+23
-18
unit_tests/test_gen.py
unit_tests/test_gen.py
+14
-13
unit_tests/unit_test.py
unit_tests/unit_test.py
+9
-5
No files found.
unit_tests/test_gen.py
View file @
12043a0e
...
...
@@ -15,8 +15,8 @@ def _main():
#Source Coords
dx
=
1000
# units in km
dy
=
1000
# units in Km
jpi
=
1
5
jpj
=
1
5
jpi
=
1
6
jpj
=
1
6
jpk
=
10
max_dep
=
100
min_dep
=
10
...
...
@@ -28,15 +28,15 @@ def _main():
write_coord_H
=
gt
.
write_coord_H
(
h_fname
,
grid_h1
)
write_coord_Z
=
gt
.
write_coord_Z
(
z_fname
,
grid_h1
,
grid_z1
)
if
write_coord_H
+
write_coord_Z
==
0
:
print
(
"
S
uccess!"
)
print
(
"
Parent grid generation s
uccess
ful
!"
)
#Dst Coords
dx
=
100
# units in km
dy
=
100
# units in Km
jpi
=
100
jpj
=
100
zoffx
=
2
0
zoffy
=
2
0
zoffx
=
3
0
zoffy
=
3
0
jpk
=
10
max_dep
=
100
min_dep
=
10
...
...
@@ -52,12 +52,12 @@ def _main():
bathy_fname
=
'unit_tests/test_data/test_dst_bathy.nc'
bathy
=
gt
.
write_bathy
(
bathy_fname
,
grid_h2
,
grid_z2
)
if
write_coord_H
+
write_coord_Z
+
bathy
==
0
:
print
(
"
S
uccess!"
)
print
(
"
Org child grid generation s
uccess
ful
!"
)
# set rotation and origin point
rot
=
45
theta
=
gt
.
radians
(
rot
)
origin
=
(
7
,
7
)
origin
=
(
8
,
8
)
# rotate grid
rot_h_fname
=
'unit_tests/test_data/test_rot_dst_hgr_zps.nc'
...
...
@@ -73,7 +73,7 @@ def _main():
bathy_fname
=
'unit_tests/test_data/test_rot_dst_bathy.nc'
bathy
=
gt
.
write_bathy
(
bathy_fname
,
grid_rot
,
grid_z2
)
if
write_coord_H
+
write_coord_Z
+
bathy
==
0
:
print
(
"Success!"
)
print
(
"
Rotated child grid generation
Success
ful
!"
)
# offset grid
dx
=
100
# units in km
...
...
@@ -97,26 +97,27 @@ def _main():
bathy_fname
=
'unit_tests/test_data/test_offset_dst_bathy.nc'
bathy
=
gt
.
write_bathy
(
bathy_fname
,
grid_h3
,
grid_z3
)
if
write_coord_H
+
write_coord_Z
+
bathy
==
0
:
print
(
"
S
uccess!"
)
print
(
"
Offset child grid gneration s
uccess
ful
!"
)
# 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'
}
}
# 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
:
print
(
'
S
uccess!'
)
print
(
'
Boundary file generation s
uccess
ful
!'
)
#write_mask
mask_fname
=
'unit_tests/test_data/mask.nc'
mask
=
gt
.
write_mask
(
mask_fname
,
grid_h1
,
grid_z1
)
if
mask
==
0
:
print
(
'
S
uccess!'
)
print
(
'
Mask file generation s
uccess
ful
!'
)
return
0
...
...
This diff is collapsed.
Click to expand it.
unit_tests/unit_test.py
View file @
12043a0e
...
...
@@ -10,20 +10,24 @@ import glob
import
os
# 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.
import
unit_tests.test_gen
as
tg
gen_data
=
tg
.
_main
()
# if a non zero is return than the grid and data generation has failed.
if
gen_data
!=
0
:
raise
Exception
(
'DONT PANIC: Input data generation failed'
)
# TODO: run different bdy files or change bdy file for different grid types for testing.
raise
Exception
(
'DONT PANIC: Input grid and boundary data generation failed'
)
# run PyNEMO with test data
# generate list of namelist.bdy files to run
namelist_files
=
glob
.
glob
(
'unit_tests/namelist*'
)
for
n
in
namelist_files
:
# run each of the namelist files
stdout
,
stderr
=
Popen
([
'pynemo'
,
'-s'
,
n
],
stdout
=
PIPE
,
stderr
=
PIPE
,
universal_newlines
=
True
).
communicate
()
if
'Execution Time'
not
in
stdout
:
raise
Exception
(
'DONT PANIC: Test Run Failed'
)
# check to see if PyNEMO ran correctly, no execution time in stdout is indication of this.
if
'Execution Time'
not
in
stdout
:
print
(
stderr
)
raise
Exception
(
'DONT PANIC: Test Run '
+
str
(
n
)
+
' Failed'
)
# TODO: Learn about parameterising the tests so that different parameters can be checked
# with same code. Rather than having similar test functions repeated.
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment