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

Commit 6f6a996

Browse files
Merge pull request #640 from openclimatefix/issue/628-satellite-order
Issue/628 satellite order
2 parents ba6f2b1 + aac1225 commit 6f6a996

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

nowcasting_dataset/data_sources/satellite/satellite_model.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77

88
logger = logging.getLogger(__name__)
99

10+
satellite_expected_dims_order = (
11+
"example",
12+
"time_index",
13+
"channels_index",
14+
"y_geostationary_index",
15+
"x_geostationary_index",
16+
)
17+
1018

1119
class Satellite(DataSourceOutput):
1220
"""Class to store satellite data as a xr.Dataset with some validation"""
@@ -34,6 +42,10 @@ def model_validation(cls, v):
3442
v.check_data_var_dim(v.x_geostationary, ("example", "x_geostationary_index"))
3543
v.check_data_var_dim(v.y_geostationary, ("example", "y_geostationary_index"))
3644

45+
# re-order dims
46+
if v.data.dims != satellite_expected_dims_order:
47+
v.__setitem__("data", v.data.transpose(*satellite_expected_dims_order))
48+
3749
return v
3850

3951

tests/data_sources/satellite/test_satellite_model.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
import pytest
77

88
from nowcasting_dataset.data_sources.fake.batch import satellite_fake
9-
from nowcasting_dataset.data_sources.satellite.satellite_model import Satellite
9+
from nowcasting_dataset.data_sources.satellite.satellite_model import (
10+
Satellite,
11+
satellite_expected_dims_order,
12+
)
1013

1114

1215
def test_satellite_init(): # noqa: D103
@@ -15,6 +18,12 @@ def test_satellite_init(): # noqa: D103
1518
assert satellite.x_geostationary.dims == ("example", "x_geostationary_index")
1619

1720

21+
def test_satellite_dims_order(): # noqa: D103
22+
satellite = satellite_fake()
23+
satellite = Satellite.model_validation(satellite)
24+
assert satellite.data.dims == satellite_expected_dims_order
25+
26+
1827
def test_satellite_validation(): # noqa: D103
1928
sat = satellite_fake()
2029

0 commit comments

Comments
 (0)