Skip to content

Commit

Permalink
Merge pull request #203 from USDA-ARS-NWRC/update_gold
Browse files Browse the repository at this point in the history
Tests - Gold files - Fix scripts and update cleanup logic.
  • Loading branch information
jomey committed Apr 22, 2021
2 parents 0a37f04 + 9f63d9a commit 1c4c0f6
Show file tree
Hide file tree
Showing 37 changed files with 61 additions and 77 deletions.
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ utm==0.4.0
pykrige>=1.5.0
spatialnc>=0.2.12
weather-forecast-retrieval>=0.6.12
topocalc>=0.3.1
topocalc>=0.5
setuptools_scm<4.2
xarray>=0.15,<0.16
xarray>=0.15,<0.16
2 changes: 1 addition & 1 deletion scripts/gold_difference
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def main(args):
gold_files.append(
os.path.join(
repo_path,
'tests',
'tests/basins',
args.basin,
args.gold_dir,
"{}.nc".format(gf)
Expand Down
19 changes: 8 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@
import os

from setuptools import Extension, find_packages, setup
from setuptools.command.build_ext import build_ext as _build_ext

# Test if compiling with cython or using the C source
try:
from Cython.Distutils import build_ext as _build_ext
except ImportError:
USE_CYTHON = False
from setuptools.command.build_ext import build_ext as _build_ext
ext = '.c'
print('Using GCC')
else:
USE_CYTHON = True

print('Using Cython {}'.format(USE_CYTHON))
ext = '.pyx' if USE_CYTHON else '.c'
ext = '.pyx'
print('Using Cython')


def c_name_from_path(location, name):
Expand Down Expand Up @@ -85,10 +84,6 @@ def finalize_options(self):
),
]

cmdclass = {}
if USE_CYTHON:
cmdclass = {'build_ext': build_ext}

with open('requirements.txt') as requirements_file:
requirements = requirements_file.read()

Expand Down Expand Up @@ -130,7 +125,9 @@ def finalize_options(self):
],
test_suite='smrf.tests',
# tests_require=test_requirements,
cmdclass=cmdclass,
cmdclass={
'build_ext': build_ext
},
ext_modules=ext_modules,
scripts=[
'scripts/update_configs',
Expand Down
Binary file modified smrf/tests/basins/Lakes/gold_hrrr/air_temp.nc
Binary file not shown.
13 changes: 7 additions & 6 deletions smrf/tests/basins/Lakes/gold_hrrr/make_gold_hrrr
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ then
echo "Updating Lakes HRRR gold files"
echo "Removing old gold files"
rm tests/Lakes/gold_hrrr/*.nc

echo "Running SMRF"
run_smrf tests/Lakes/gold_hrrr/gold_config.ini
run_smrf tests/basins/Lakes/gold_hrrr/gold_config.ini

echo "Cleaning up"
rm tests/Lakes/gold_hrrr/log.txt
rm tests/Lakes/gold_hrrr/config.ini
if [ $? == 0 ]; then
echo "Cleaning up"
rm tests/basins/Lakes/gold_hrrr/log.txt
rm tests/basins/Lakes/gold_hrrr/config.ini
fi
else
echo "Lakes HRRR gold files not updated"
fi

Binary file modified smrf/tests/basins/Lakes/gold_hrrr/net_solar.nc
Binary file not shown.
Binary file modified smrf/tests/basins/Lakes/gold_hrrr/percent_snow.nc
Binary file not shown.
Binary file modified smrf/tests/basins/Lakes/gold_hrrr/precip.nc
Binary file not shown.
Binary file modified smrf/tests/basins/Lakes/gold_hrrr/precip_temp.nc
Binary file not shown.
Binary file modified smrf/tests/basins/Lakes/gold_hrrr/snow_density.nc
Binary file not shown.
Binary file modified smrf/tests/basins/Lakes/gold_hrrr/thermal.nc
Binary file not shown.
Binary file modified smrf/tests/basins/Lakes/gold_hrrr/vapor_pressure.nc
Binary file not shown.
Binary file modified smrf/tests/basins/Lakes/gold_hrrr/wind_direction.nc
Binary file not shown.
Binary file modified smrf/tests/basins/Lakes/gold_hrrr/wind_speed.nc
Binary file not shown.
Binary file modified smrf/tests/basins/RME/gold/air_temp.nc
Binary file not shown.
10 changes: 6 additions & 4 deletions smrf/tests/basins/RME/gold/make_gold_stations
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ then
echo "Running SMRF"
run_smrf tests/basins/RME/gold/gold_config.ini

echo "Cleaning up"
rm tests/basins/RME/gold/log.txt
rm tests/basins/RME/gold/config.ini
rm -rf tests/basins/RME/gold/input_backup
if [ $? == 0 ]; then
echo "Cleaning up"
rm tests/basins/RME/gold/log.txt
rm tests/basins/RME/gold/config.ini
rm -rf tests/basins/RME/gold/input_backup
fi
else
echo "RME station gold files not updated"
fi
Expand Down
Binary file modified smrf/tests/basins/RME/gold/net_solar.nc
Binary file not shown.
Binary file modified smrf/tests/basins/RME/gold/percent_snow.nc
Binary file not shown.
Binary file modified smrf/tests/basins/RME/gold/precip.nc
Binary file not shown.
Binary file modified smrf/tests/basins/RME/gold/precip_temp.nc
Binary file not shown.
Binary file modified smrf/tests/basins/RME/gold/snow_density.nc
Binary file not shown.
Binary file modified smrf/tests/basins/RME/gold/thermal.nc
Binary file not shown.
Binary file modified smrf/tests/basins/RME/gold/vapor_pressure.nc
Binary file not shown.
Binary file modified smrf/tests/basins/RME/gold/wind_direction.nc
Binary file not shown.
Binary file modified smrf/tests/basins/RME/gold/wind_speed.nc
Binary file not shown.
Binary file modified smrf/tests/basins/RME/gold_hrrr/air_temp.nc
Binary file not shown.
11 changes: 6 additions & 5 deletions smrf/tests/basins/RME/gold_hrrr/make_gold_hrrr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# file will put the outputs in the correct place
#
# Run as:
# $ ./tests/basins/RME/gold/make_gold_hrrr
# $ ./tests/basins/RME/gold_hrrr/make_gold_hrrr

read -r -p "Recreating gold standard, are you sure? [y/N] " response
if [[ "$response" = "yes" || "$response" = "y" ]]
Expand All @@ -17,10 +17,11 @@ then
echo "Running SMRF"
run_smrf tests/basins/RME/gold_hrrr/gold_config.ini

echo "Cleaning up"
rm tests/basins/RME/gold_hrrr/log.txt
rm tests/basins/RME/gold_hrrr/config.ini
if [ $? == 0 ]; then
echo "Cleaning up"
rm tests/basins/RME/gold_hrrr/log.txt
rm tests/basins/RME/gold_hrrr/config.ini
fi
else
echo "RME HRRR gold files not updated"
fi

Binary file modified smrf/tests/basins/RME/gold_hrrr/net_solar.nc
Binary file not shown.
Binary file modified smrf/tests/basins/RME/gold_hrrr/percent_snow.nc
Binary file not shown.
Binary file modified smrf/tests/basins/RME/gold_hrrr/precip.nc
Binary file not shown.
Binary file modified smrf/tests/basins/RME/gold_hrrr/precip_temp.nc
Binary file not shown.
Binary file modified smrf/tests/basins/RME/gold_hrrr/snow_density.nc
Binary file not shown.
Binary file modified smrf/tests/basins/RME/gold_hrrr/thermal.nc
Binary file not shown.
Binary file modified smrf/tests/basins/RME/gold_hrrr/vapor_pressure.nc
Binary file not shown.
Binary file modified smrf/tests/basins/RME/gold_hrrr/wind_direction.nc
Binary file not shown.
Binary file modified smrf/tests/basins/RME/gold_hrrr/wind_speed.nc
Binary file not shown.
79 changes: 31 additions & 48 deletions smrf/tests/envphys/solar/test_toporad.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,13 @@ def test_elevrad(self):
self.solar_irradiance,
cosz=0.45)

self.assertAlmostEqual(965.8828575567114, np.mean(rad.beam), places=4)
self.assertAlmostEqual(943.7263794826135, np.min(rad.beam), places=4)
self.assertAlmostEqual(989.6429308508227, np.max(rad.beam), places=4)
np.testing.assert_allclose(965, np.mean(rad.beam), atol=1)
np.testing.assert_allclose(943, np.min(rad.beam), atol=1)
np.testing.assert_allclose(989, np.max(rad.beam), atol=1)

self.assertAlmostEqual(
93.84315440085071, np.mean(rad.diffuse), places=4)
self.assertAlmostEqual(
87.84988698685561, np.min(rad.diffuse), places=4)
self.assertAlmostEqual(
99.39603484739534, np.max(rad.diffuse), places=4)
np.testing.assert_allclose(93, np.mean(rad.diffuse), atol=1)
np.testing.assert_allclose(87, np.min(rad.diffuse), atol=1)
np.testing.assert_allclose(99, np.max(rad.diffuse), atol=1)

def test_elevrad_options(self):

Expand All @@ -84,16 +81,13 @@ def test_elevrad_options(self):
scattering_factor=0.35,
surface_albedo=0.3)

self.assertAlmostEqual(866.5210770956645, np.mean(rad.beam), places=4)
self.assertAlmostEqual(839.8354626316999, np.min(rad.beam), places=4)
self.assertAlmostEqual(895.3273572653653, np.max(rad.beam), places=4)
np.testing.assert_allclose(866, np.mean(rad.beam), atol=1)
np.testing.assert_allclose(839, np.min(rad.beam), atol=1)
np.testing.assert_allclose(895, np.max(rad.beam), atol=1)

self.assertAlmostEqual(
76.05068555235343, np.mean(rad.diffuse), places=4)
self.assertAlmostEqual(
71.93616622814766, np.min(rad.diffuse), places=4)
self.assertAlmostEqual(
79.77791625995671, np.max(rad.diffuse), places=4)
np.testing.assert_allclose(76, np.mean(rad.diffuse), atol=1)
np.testing.assert_allclose(71, np.min(rad.diffuse), atol=1)
np.testing.assert_allclose(79, np.max(rad.diffuse), atol=1)

def test_toporad(self):

Expand All @@ -106,16 +100,13 @@ def test_toporad(self):
self.cosz,
surface_albedo=0.5)

self.assertAlmostEqual(706.0067021452699, np.mean(trad_beam), places=4)
self.assertAlmostEqual(85.17264068026927, np.min(trad_beam), places=4)
self.assertAlmostEqual(1164.002943767303, np.max(trad_beam), places=4)
np.testing.assert_allclose(706, np.mean(trad_beam), atol=1)
np.testing.assert_allclose(85, np.min(trad_beam), atol=1)
np.testing.assert_allclose(1162, np.max(trad_beam), atol=1)

self.assertAlmostEqual(
112.40390734361924, np.mean(trad_diffuse), places=4)
self.assertAlmostEqual(
84.87509154016982, np.min(trad_diffuse), places=4)
self.assertAlmostEqual(
148.2553072510663, np.max(trad_diffuse), places=4)
np.testing.assert_allclose(112, np.mean(trad_diffuse), atol=1)
np.testing.assert_allclose(85, np.min(trad_diffuse), atol=1)
np.testing.assert_allclose(148, np.max(trad_diffuse), atol=1)

def test_stoporad_visible(self):

Expand All @@ -135,17 +126,13 @@ def test_stoporad_visible(self):
omega=self.omega,
scattering_factor=self.scattering_factor)

self.assertAlmostEqual(
350.1547099434225, np.mean(srad_beam), places=4)
self.assertAlmostEqual(49.930680972072594, np.min(srad_beam), places=4)
self.assertAlmostEqual(570.8947805048191, np.max(srad_beam), places=4)
np.testing.assert_allclose(350, np.mean(srad_beam), atol=1)
np.testing.assert_allclose(49, np.min(srad_beam), atol=1)
np.testing.assert_allclose(569, np.max(srad_beam), atol=1)

self.assertAlmostEqual(
65.79420200041265, np.mean(srad_diffuse), places=4)
self.assertAlmostEqual(
49.930680972072594, np.min(srad_diffuse), places=4)
self.assertAlmostEqual(
102.02449905038313, np.max(srad_diffuse), places=4)
np.testing.assert_allclose(66, np.mean(srad_diffuse), atol=1)
np.testing.assert_allclose(49, np.min(srad_diffuse), atol=1)
np.testing.assert_allclose(102, np.max(srad_diffuse), atol=1)

def test_stoporad_ir(self):

Expand All @@ -165,14 +152,10 @@ def test_stoporad_ir(self):
omega=self.omega,
scattering_factor=self.scattering_factor)

self.assertAlmostEqual(
365.23243248652074, np.mean(srad_beam), places=4)
self.assertAlmostEqual(41.8954631805951, np.min(srad_beam), places=4)
self.assertAlmostEqual(602.1472248320969, np.max(srad_beam), places=4)

self.assertAlmostEqual(
56.30765350042961, np.mean(srad_diffuse), places=4)
self.assertAlmostEqual(
41.8954631805951, np.min(srad_diffuse), places=4)
self.assertAlmostEqual(
71.27409494983297, np.max(srad_diffuse), places=4)
np.testing.assert_allclose(365, np.mean(srad_beam), atol=1)
np.testing.assert_allclose(41, np.min(srad_beam), atol=1)
np.testing.assert_allclose(602, np.max(srad_beam), atol=1)

np.testing.assert_allclose(56, np.mean(srad_diffuse), atol=1)
np.testing.assert_allclose(41, np.min(srad_diffuse), atol=1)
np.testing.assert_allclose(71, np.max(srad_diffuse), atol=1)

0 comments on commit 1c4c0f6

Please sign in to comment.