Skip to content
This repository was archived by the owner on Sep 11, 2023. It is now read-only.

Commit d0f70fd

Browse files
Merge pull request #655 from openclimatefix/fake-sun-topo
Fake sun topo
2 parents cab3379 + bf34870 commit d0f70fd

File tree

3 files changed

+46
-27
lines changed

3 files changed

+46
-27
lines changed

nowcasting_dataset/data_sources/fake/batch.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,12 @@ def make_fake_batch(configuration: Configuration, temporally_align_examples: boo
7777
metadata=metadata,
7878
),
7979
sun=sun_fake(
80-
batch_size=batch_size,
81-
seq_length_5=configuration.input_data.sun.seq_length_5_minutes,
80+
configuration=configuration,
8281
metadata=metadata,
8382
),
8483
topographic=topographic_fake(
85-
batch_size=batch_size,
8684
metadata=metadata,
87-
image_size_pixels_height=configuration.input_data.topographic.topographic_image_size_pixels_height, # noqa
88-
image_size_pixels_width=configuration.input_data.topographic.topographic_image_size_pixels_width, # noqa
85+
configuration=configuration,
8986
),
9087
)
9188

@@ -442,17 +439,23 @@ def optical_flow_fake(
442439

443440

444441
def sun_fake(
445-
batch_size,
446-
seq_length_5,
442+
configuration,
447443
metadata: Optional[Metadata] = None,
448444
):
449445
"""Create fake data"""
450446

447+
if configuration.input_data.sun is None:
448+
return None
449+
450+
batch_size = configuration.process.batch_size
451+
451452
if metadata is None:
452453
t0_datetimes_utc = make_t0_datetimes_utc(batch_size)
453454
else:
454455
t0_datetimes_utc = metadata.t0_datetimes_utc
455456

457+
seq_length_5 = configuration.input_data.sun.seq_length_5_minutes
458+
456459
# create dataset with both azimuth and elevation, index with time
457460
# make batch of arrays
458461
xr_arrays = [
@@ -467,13 +470,23 @@ def sun_fake(
467470

468471

469472
def topographic_fake(
470-
batch_size,
471-
image_size_pixels_height,
472-
image_size_pixels_width,
473+
configuration,
473474
metadata: Optional[Metadata] = None,
474475
):
475476
"""Create fake data"""
476477

478+
if configuration.input_data.topographic is None:
479+
return None
480+
481+
batch_size = configuration.process.batch_size
482+
483+
image_size_pixels_height = (
484+
configuration.input_data.topographic.topographic_image_size_pixels_height
485+
)
486+
image_size_pixels_width = (
487+
configuration.input_data.topographic.topographic_image_size_pixels_width
488+
)
489+
477490
if metadata is None:
478491
x_centers_osgb, y_centers_osgb = make_random_x_and_y_osgb_centers(batch_size)
479492
else:

tests/data_sources/fake/test_fake_datasource_output.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ def test_satellite(configuration):
6161
assert s.x_geostationary is not None
6262

6363

64-
def test_sun():
64+
def test_sun(configuration):
6565
"""Test sun fake"""
66-
_ = sun_fake(
67-
batch_size=4,
68-
seq_length_5=13,
69-
)
66+
67+
configuration.process.batch_size = 4
68+
_ = sun_fake(configuration=configuration)
7069

7170

72-
def test_topo():
71+
def test_topo(configuration):
7372
"""Test topo fake"""
74-
_ = topographic_fake(batch_size=4, image_size_pixels_height=64, image_size_pixels_width=64)
73+
configuration.process.batch_size = 4
74+
_ = topographic_fake(configuration=configuration)

tests/data_sources/sun/test_sun_model.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
from nowcasting_dataset.data_sources.sun.sun_model import Sun
1010

1111

12-
def test_sun_init(): # noqa: D103
13-
_ = sun_fake(batch_size=4, seq_length_5=17)
12+
def test_sun_init(configuration): # noqa: D103
13+
configuration.process.batch_size = 4
14+
_ = sun_fake(configuration=configuration)
1415

1516

16-
def test_sun_validation(): # noqa: D103
17-
sun = sun_fake(batch_size=4, seq_length_5=17)
17+
def test_sun_validation(configuration): # noqa: D103
18+
configuration.process.batch_size = 4
19+
sun = sun_fake(configuration=configuration)
1820

1921
Sun.model_validation(sun)
2022

@@ -23,8 +25,9 @@ def test_sun_validation(): # noqa: D103
2325
Sun.model_validation(sun)
2426

2527

26-
def test_sun_validation_elevation(): # noqa: D103
27-
sun = sun_fake(batch_size=4, seq_length_5=17)
28+
def test_sun_validation_elevation(configuration): # noqa: D103
29+
configuration.process.batch_size = 4
30+
sun = sun_fake(configuration=configuration)
2831

2932
Sun.model_validation(sun)
3033

@@ -33,8 +36,9 @@ def test_sun_validation_elevation(): # noqa: D103
3336
Sun.model_validation(sun)
3437

3538

36-
def test_sun_validation_azimuth(): # noqa: D103
37-
sun = sun_fake(batch_size=4, seq_length_5=17)
39+
def test_sun_validation_azimuth(configuration): # noqa: D103
40+
configuration.process.batch_size = 4
41+
sun = sun_fake(configuration=configuration)
3842

3943
Sun.model_validation(sun)
4044

@@ -43,9 +47,11 @@ def test_sun_validation_azimuth(): # noqa: D103
4347
Sun.model_validation(sun)
4448

4549

46-
def test_sun_save(): # noqa: D103
50+
def test_sun_save(configuration): # noqa: D103
51+
52+
configuration.process.batch_size = 4
4753
with tempfile.TemporaryDirectory() as dirpath:
48-
sun = sun_fake(batch_size=4, seq_length_5=17)
54+
sun = sun_fake(configuration=configuration)
4955
sun.save_netcdf(path=dirpath, batch_i=0)
5056

5157
assert os.path.exists(f"{dirpath}/sun/000000.nc")

0 commit comments

Comments
 (0)