Skip to content

Commit

Permalink
still use same padding for tests so easy to work with small samples
Browse files Browse the repository at this point in the history
  • Loading branch information
grantbuster committed Nov 21, 2024
1 parent 3146313 commit 8124053
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 9 deletions.
8 changes: 6 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ def pytest_configure(config): # pylint: disable=unused-argument # noqa: ARG001
CONFIG_DIR, 'spatiotemporal', 'gen_3x_4x_2f.json'
)
pytest.S_FP_GEN = os.path.join(CONFIG_DIR, 'spatial', 'gen_2x_2f.json')
pytest.ST_FP_DISC = os.path.join(CONFIG_DIR, 'spatiotemporal', 'disc.json')
pytest.S_FP_DISC = os.path.join(CONFIG_DIR, 'spatial', 'disc.json')

# Note that disc should not use "same" zeros padding but easier to use this
# for testing on small sample sizes.
pytest.ST_FP_DISC = os.path.join(TEST_DATA_DIR, 'config_disc_st_test.json')
pytest.S_FP_DISC = os.path.join(TEST_DATA_DIR, 'config_disc_s_test.json')

pytest.FPS_GCM = [
os.path.join(TEST_DATA_DIR, 'ua_test.nc'),
os.path.join(TEST_DATA_DIR, 'va_test.nc'),
Expand Down
24 changes: 24 additions & 0 deletions tests/data/config_disc_s_test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"hidden_layers": [
{"class": "Conv2D", "filters": 32, "kernel_size": 3, "padding": "same", "strides": 1},
{"alpha": 0.2, "class": "LeakyReLU"},
{"class": "Conv2D", "filters": 32, "kernel_size": 3, "padding": "same", "strides": 2},
{"alpha": 0.2, "class": "LeakyReLU"},
{"class": "Conv2D", "filters": 64, "kernel_size": 3, "padding": "same", "strides": 1},
{"alpha": 0.2, "class": "LeakyReLU"},
{"class": "Conv2D", "filters": 64, "kernel_size": 3, "padding": "same", "strides": 2},
{"alpha": 0.2, "class": "LeakyReLU"},
{"class": "Conv2D", "filters": 128, "kernel_size": 3, "padding": "same", "strides": 1},
{"alpha": 0.2, "class": "LeakyReLU"},
{"class": "Conv2D", "filters": 128, "kernel_size": 3, "padding": "same", "strides": 2},
{"alpha": 0.2, "class": "LeakyReLU"},
{"class": "Conv2D", "filters": 256, "kernel_size": 3, "padding": "same", "strides": 1},
{"alpha": 0.2, "class": "LeakyReLU"},
{"class": "Conv2D", "filters": 256, "kernel_size": 3, "padding": "same", "strides": 2},
{"alpha": 0.2, "class": "LeakyReLU"},
{"class": "Flatten"},
{"class": "Dense", "units": 1024},
{"alpha": 0.2, "class": "LeakyReLU"},
{"class": "Dense", "units": 1}
]
}
26 changes: 26 additions & 0 deletions tests/data/config_disc_st_test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"hidden_layers": [
{"class": "Conv3D", "filters": 32, "kernel_size": 3, "padding": "same", "strides": 1},
{"alpha": 0.2, "class": "LeakyReLU"},
{"class": "Conv3D", "filters": 32, "kernel_size": 3, "padding": "same", "strides": 2},
{"alpha": 0.2, "class": "LeakyReLU"},
{"class": "Conv3D", "filters": 64, "kernel_size": 3, "padding": "same", "strides": 1},
{"alpha": 0.2, "class": "LeakyReLU"},
{"class": "Conv3D", "filters": 64, "kernel_size": 3, "padding": "same", "strides": 2},
{"alpha": 0.2, "class": "LeakyReLU"},
{"class": "Conv3D", "filters": 128, "kernel_size": 3, "padding": "same", "strides": 1},
{"alpha": 0.2, "class": "LeakyReLU"},
{"class": "Conv3D", "filters": 128, "kernel_size": 3, "padding": "same", "strides": 2},
{"alpha": 0.2, "class": "LeakyReLU"},
{"class": "Conv3D", "filters": 256, "kernel_size": 3, "padding": "same", "strides": 1},
{"alpha": 0.2, "class": "LeakyReLU"},
{"class": "Conv3D", "filters": 256, "kernel_size": 3, "padding": "same", "strides": 2},
{"alpha": 0.2, "class": "LeakyReLU"},
{"class": "Flatten"},
{"class": "Dense", "units": 2048},
{"alpha": 0.2, "class": "LeakyReLU"},
{"class": "Dense", "units": 1024},
{"alpha": 0.2, "class": "LeakyReLU"},
{"class": "Dense", "units": 1}
]
}
5 changes: 1 addition & 4 deletions tests/training/test_train_exo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import numpy as np
import pytest

from sup3r import CONFIG_DIR
from sup3r.models import Sup3rGan
from sup3r.preprocessing import (
BatchHandler,
Expand Down Expand Up @@ -65,11 +64,9 @@ def test_wind_hi_res_topo(
if mode == 'eager':
assert batcher.loaded

fp_disc = os.path.join(CONFIG_DIR, 'spatial/disc.json')

Sup3rGan.seed()
model = Sup3rGan(
gen_config_with_topo(CustomLayer), fp_disc, learning_rate=1e-4
gen_config_with_topo(CustomLayer), pytest.S_FP_DISC, learning_rate=1e-4
)

start = time.time()
Expand Down
6 changes: 3 additions & 3 deletions tests/training/test_train_solar.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_solar_cc_model(hr_steps):
)

fp_gen = os.path.join(CONFIG_DIR, 'sup3rcc/gen_solar_1x_8x_1f.json')
fp_disc = os.path.join(CONFIG_DIR, 'spatiotemporal/disc.json')
fp_disc = pytest.ST_FP_DISC

Sup3rGan.seed()
model = SolarCC(
Expand Down Expand Up @@ -127,7 +127,7 @@ def test_solar_cc_model_spatial():
)

fp_gen = os.path.join(CONFIG_DIR, 'sup3rcc/gen_solar_5x_1x_1f.json')
fp_disc = os.path.join(CONFIG_DIR, 'spatial/disc.json')
fp_disc = pytest.S_FP_DISC

Sup3rGan.seed()
model = Sup3rGan(fp_gen, fp_disc, learning_rate=1e-4)
Expand Down Expand Up @@ -179,7 +179,7 @@ def test_solar_custom_loss():
)

fp_gen = os.path.join(CONFIG_DIR, 'sup3rcc/gen_solar_1x_8x_1f.json')
fp_disc = os.path.join(CONFIG_DIR, 'spatiotemporal/disc.json')
fp_disc = pytest.ST_FP_DISC

Sup3rGan.seed()
model = SolarCC(
Expand Down

0 comments on commit 8124053

Please sign in to comment.