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
1d094960
Commit
1d094960
authored
5 years ago
by
thopri
Browse files
Options
Download
Email Patches
Plain Diff
updated to build constant boundary file
parent
d76b4538
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
1 deletion
+50
-1
unit_tests/gen_tools.py
unit_tests/gen_tools.py
+45
-1
unit_tests/test_gen.py
unit_tests/test_gen.py
+5
-0
No files found.
unit_tests/gen_tools.py
View file @
1d094960
...
...
@@ -449,4 +449,48 @@ def plot_grids(lat_in,lon_in,new_lat,new_lon,off_lat,off_lon,src_lat,src_lon):
# tweak margins of subplots as tight layout doesn't work
plt
.
subplots_adjust
(
left
=
0.01
,
right
=
1
,
top
=
0.9
,
bottom
=
0.05
,
wspace
=
0.01
)
plt
.
show
()
\ No newline at end of file
plt
.
show
()
def
write_parameter
(
fileout
,
grid_h
,
grid_z
,
params
):
'''
Writes out a
Args:
Returns:
'''
#TODO: implement multiple parameters using dicts.
# Open pointer to netcdf file
dataset
=
Dataset
(
fileout
,
'w'
,
format
=
'NETCDF4_CLASSIC'
)
# Get input size and create appropriate dimensions
# TODO: add some sort of error handling
nx
,
ny
,
nz
=
np
.
shape
(
grid_z
[
'e3t'
])
dataset
.
createDimension
(
'x'
,
nx
)
dataset
.
createDimension
(
'y'
,
ny
)
dataset
.
createDimension
(
'z'
,
nz
)
# 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'
)
longitude
.
units
,
longitude
.
long_name
=
'km'
,
'X'
latitude
.
units
,
latitude
.
long_name
=
'km'
,
'Y'
depth
.
units
,
depth
.
long_name
=
'm'
,
'Z'
# Populate file with input data
longitude
[:,
:]
=
grid_h
[
'lont'
].
T
latitude
[:,
:]
=
grid_h
[
'latt'
].
T
depth
[:]
=
grid_z
[
'dept_1d'
]
parameter
=
dataset
.
createVariable
(
str
(
params
[
'name'
]),
np
.
float64
,
(
'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
# Close off pointer
dataset
.
close
()
return
0
\ No newline at end of file
This diff is collapsed.
Click to expand it.
unit_tests/test_gen.py
View file @
1d094960
...
...
@@ -101,6 +101,11 @@ def _main():
# close data files
#ds.close()
#src.close()
out_fname
=
'unit_tests/test_data/output_boundary.nc'
params
=
{
'name'
:
'thetao'
,
'const_value'
:
15.0
,
'longname'
:
'temperature'
,
'units'
:
'degreesC'
}
boundary
=
gt
.
write_parameter
(
out_fname
,
grid_h1
,
grid_z1
,
params
)
if
boundary
==
0
:
print
(
'Success!'
)
if
__name__
==
'__main__'
:
_main
()
\ No newline at end of file
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