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
71bb209a
Commit
71bb209a
authored
5 years ago
by
thopri
Browse files
Options
Download
Email Patches
Plain Diff
added salinity check
parent
129c5043
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
18 deletions
+21
-18
pynemo/profile.py
pynemo/profile.py
+2
-1
unit_tests/gen_tools.py
unit_tests/gen_tools.py
+6
-6
unit_tests/test_gen.py
unit_tests/test_gen.py
+3
-1
unit_tests/unit_test.py
unit_tests/unit_test.py
+10
-10
No files found.
pynemo/profile.py
View file @
71bb209a
...
...
@@ -505,7 +505,8 @@ def process_bdy(setup_filepath=0, mask_gui=False):
if
settings
[
'use_cmems'
]
==
True
:
logger
.
info
(
'using CMEMS variable names......'
)
if
ln_tra
:
var_in
[
't'
].
extend
([
'thetao'
])
# ,'so'])
var_in
[
't'
].
extend
([
'thetao'
])
var_in
[
't'
].
extend
([
'so'
])
if
ln_dyn2d
or
ln_dyn3d
:
var_in
[
'u'
].
extend
([
'uo'
])
...
...
This diff is collapsed.
Click to expand it.
unit_tests/gen_tools.py
View file @
71bb209a
...
...
@@ -557,7 +557,6 @@ def write_parameter(fileout, grid_h,grid_z,params):
dataset
.
createDimension
(
'z'
,
nz
)
dataset
.
createDimension
(
'time'
,
nt
)
# Create Variables
longitude
=
dataset
.
createVariable
(
'longitude'
,
np
.
float32
,
(
'y'
,
'x'
))
latitude
=
dataset
.
createVariable
(
'latitude'
,
np
.
float32
,
(
'y'
,
'x'
))
...
...
@@ -577,11 +576,12 @@ def write_parameter(fileout, grid_h,grid_z,params):
latitude
[:,
:]
=
grid_h
[
'latt'
].
T
depth
[:]
=
grid_z
[
'dept_1d'
]
time_counter
[:]
=
np
.
linspace
(
587340.00
,
588060.00
,
31
)
parameter
=
dataset
.
createVariable
(
str
(
params
[
'name'
]),
np
.
float64
,
(
'time'
,
'z'
,
'y'
,
'x'
))
parameter
.
units
,
parameter
.
long_name
=
str
(
params
[
'units'
]),
str
(
params
[
'longname'
])
value_fill
=
np
.
ones
(
np
.
shape
(
grid_z
[
'e3t'
]))
value_fill
=
value_fill
*
params
[
'const_value'
]
parameter
[:,
:,
:]
=
value_fill
.
T
for
key
in
params
:
parameter
=
dataset
.
createVariable
(
str
(
params
[
key
][
'name'
]),
np
.
float64
,
(
'time'
,
'z'
,
'y'
,
'x'
))
parameter
.
units
,
parameter
.
long_name
=
str
(
params
[
key
][
'units'
]),
str
(
params
[
key
][
'longname'
])
value_fill
=
np
.
ones
(
np
.
shape
(
grid_z
[
'e3t'
]))
value_fill
=
value_fill
*
params
[
key
][
'const_value'
]
parameter
[:,
:,
:]
=
value_fill
.
T
# Close off pointer
dataset
.
close
()
...
...
This diff is collapsed.
Click to expand it.
unit_tests/test_gen.py
View file @
71bb209a
...
...
@@ -105,7 +105,9 @@ def _main():
# write boundary files (constant parameters)
out_fname
=
'unit_tests/test_data/output_boundary_T.nc'
params
=
{
'name'
:
'thetao'
,
'const_value'
:
15.0
,
'longname'
:
'temperature'
,
'units'
:
'degreesC'
}
params
=
{
'param1'
:
{
'name'
:
'thetao'
,
'const_value'
:
15.0
,
'longname'
:
'temperature'
,
'units'
:
'degreesC'
},
'param2'
:
{
'name'
:
'so'
,
'const_value'
:
35.0
,
'longname'
:
'salinity'
,
'units'
:
'PSU'
}
}
boundary
=
gt
.
write_parameter
(
out_fname
,
grid_h1
,
grid_z1
,
params
)
if
boundary
==
0
:
print
(
'Success!'
)
...
...
This diff is collapsed.
Click to expand it.
unit_tests/unit_test.py
View file @
71bb209a
...
...
@@ -33,16 +33,16 @@ def test_temp():
assert
abs
(
temp_
[
temp_
!=
0.0
].
max
()
-
15
)
<=
0.001
assert
abs
(
temp_
[
temp_
!=
0.0
].
min
()
-
15
)
<=
0.001
#
def test_salinty():
#
test_files = glob.glob('unit_tests/test_outputs/unit_test*')
#
for t in test_files:
#
results = Dataset(t) # open results
#
sal = results['so'][:]
#
results.close()
#
sal_ = np.ma.masked_array(sal,sal == -32767.0)
#
assert abs(sal_[sal_!=0.0].mean() - 35) <= 0.001
#
assert abs(sal_[sal_ != 0.0].max() - 35) <= 0.001
#
assert abs(sal_[sal_ != 0.0].min() - 35) <= 0.001
def
test_salinty
():
test_files
=
glob
.
glob
(
'unit_tests/test_outputs/unit_test*'
)
for
t
in
test_files
:
results
=
Dataset
(
t
)
# open results
sal
=
results
[
'so'
][:]
results
.
close
()
sal_
=
np
.
ma
.
masked_array
(
sal
,
sal
==
-
32767.0
)
assert
abs
(
sal_
[
sal_
!=
0.0
].
mean
()
-
35
)
<=
0.001
assert
abs
(
sal_
[
sal_
!=
0.0
].
max
()
-
35
)
<=
0.001
assert
abs
(
sal_
[
sal_
!=
0.0
].
min
()
-
35
)
<=
0.001
# clean up test I/O
files
=
glob
.
glob
(
'unit_tests/test_outputs/*'
)
...
...
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