forked from NOAA-GFDL/FRE-NCtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
attempt to add a test for frenctools
- Loading branch information
1 parent
dcbfc10
commit 38b1209
Showing
4 changed files
with
81 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env bats | ||
|
||
#*********************************************************************** | ||
# GNU Lesser General Public License | ||
# | ||
# This file is part of the GFDL FRE NetCDF tools package (FRE-NCTools). | ||
# | ||
# FRE-NCTools is free software: you can redistribute it and/or modify it under | ||
# the terms of the GNU Lesser General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or (at | ||
# your option) any later version. | ||
# | ||
# FRE-NCTools is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
# for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser General Public | ||
# License along with FRE-NCTools. If not, see | ||
# <http://www.gnu.org/licenses/>. | ||
#*********************************************************************** | ||
|
||
load test_utils | ||
|
||
@test "Test timavg" { | ||
python $top_srcdir/t/test_time_avg.py | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import xarray as xr | ||
import numpy as np | ||
import os | ||
|
||
def init_fake_data(a, count=0., factor=1.): | ||
with np.nditer(a, op_flags=['readwrite']) as it: | ||
for x in it: | ||
count = count + 1 | ||
x[...] = count * factor | ||
|
||
class TestTimeAvg(): | ||
def create_input(self): | ||
print("Creating input files to test with") | ||
nx = 96 | ||
ny = 96 | ||
nt = 12 | ||
|
||
a = np.zeros([nt, ny, nx]) | ||
for k in range(0,nt): | ||
for j in range(0,ny): | ||
for i in range(0,nx): | ||
a[k, j, i] = (i+1.)*1000 + (j+1.)*10 + (k+1.)/100. | ||
self.a = a | ||
|
||
Time_attrs = {"units": "days since 2000-01-01", "axis": "T", "calendar_type": "JULIAN", "calendar": "julian"} | ||
ds1 = xr.Dataset( | ||
data_vars={ | ||
## This is backwards #FORTRAN4LYFE | ||
"a": (("Time", "y", "x"), a), | ||
"Time": (("Time", np.arange(nt)*1.0+1, Time_attrs)) | ||
}, | ||
coords={ | ||
"x": np.arange(nx)*1.0, | ||
"y": np.arange(ny)*1.0, | ||
}, | ||
) | ||
ds1.to_netcdf("20120101.ice_shelf.nc", unlimited_dims="Time") | ||
|
||
|
||
def check_output(self): | ||
out_file = xr.open_dataset("wut.nc") | ||
if not (out_file.a.values == np.average(self.a, axis=0)).all(): | ||
raise Exception("Test failed") | ||
|
||
|
||
test_class = TestTimeAvg() | ||
test_class.create_input() | ||
os.system(os.path.dirname(os.path.realpath(__file__))+"/../postprocessing/timavg/timavg.csh -m -o wut.nc 20120101.ice_shelf.nc") | ||
test_class.check_output() |