ocf-data-sampler 0.0.22__tar.gz → 0.0.24__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of ocf-data-sampler might be problematic. Click here for more details.

Files changed (64) hide show
  1. {ocf_data_sampler-0.0.22/ocf_data_sampler.egg-info → ocf_data_sampler-0.0.24}/PKG-INFO +1 -1
  2. ocf_data_sampler-0.0.24/ocf_data_sampler/numpy_batch/__init__.py +7 -0
  3. ocf_data_sampler-0.0.24/ocf_data_sampler/numpy_batch/gsp.py +33 -0
  4. ocf_data_sampler-0.0.24/ocf_data_sampler/numpy_batch/nwp.py +43 -0
  5. ocf_data_sampler-0.0.24/ocf_data_sampler/numpy_batch/satellite.py +30 -0
  6. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/ocf_data_sampler/torch_datasets/pvnet_uk_regional.py +4 -4
  7. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24/ocf_data_sampler.egg-info}/PKG-INFO +1 -1
  8. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/pyproject.toml +1 -1
  9. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/tests/numpy_batch/test_gsp.py +1 -2
  10. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/tests/numpy_batch/test_nwp.py +2 -4
  11. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/tests/numpy_batch/test_satellite.py +1 -3
  12. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/tests/numpy_batch/test_sun_position.py +7 -7
  13. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/tests/select/test_select_time_slice.py +13 -13
  14. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/tests/torch_datasets/test_pvnet_uk_regional.py +4 -6
  15. ocf_data_sampler-0.0.22/ocf_data_sampler/numpy_batch/__init__.py +0 -7
  16. ocf_data_sampler-0.0.22/ocf_data_sampler/numpy_batch/gsp.py +0 -33
  17. ocf_data_sampler-0.0.22/ocf_data_sampler/numpy_batch/nwp.py +0 -43
  18. ocf_data_sampler-0.0.22/ocf_data_sampler/numpy_batch/satellite.py +0 -30
  19. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/LICENSE +0 -0
  20. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/MANIFEST.in +0 -0
  21. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/README.md +0 -0
  22. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/ocf_data_sampler/__init__.py +0 -0
  23. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/ocf_data_sampler/config/__init__.py +0 -0
  24. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/ocf_data_sampler/config/load.py +0 -0
  25. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/ocf_data_sampler/config/model.py +0 -0
  26. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/ocf_data_sampler/config/save.py +0 -0
  27. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/ocf_data_sampler/constants.py +0 -0
  28. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/ocf_data_sampler/data/uk_gsp_locations.csv +0 -0
  29. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/ocf_data_sampler/load/__init__.py +0 -0
  30. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/ocf_data_sampler/load/gsp.py +0 -0
  31. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/ocf_data_sampler/load/nwp/__init__.py +0 -0
  32. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/ocf_data_sampler/load/nwp/nwp.py +0 -0
  33. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/ocf_data_sampler/load/nwp/providers/__init__.py +0 -0
  34. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/ocf_data_sampler/load/nwp/providers/ecmwf.py +0 -0
  35. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/ocf_data_sampler/load/nwp/providers/ukv.py +0 -0
  36. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/ocf_data_sampler/load/nwp/providers/utils.py +0 -0
  37. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/ocf_data_sampler/load/satellite.py +0 -0
  38. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/ocf_data_sampler/load/utils.py +0 -0
  39. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/ocf_data_sampler/numpy_batch/sun_position.py +0 -0
  40. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/ocf_data_sampler/select/__init__.py +0 -0
  41. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/ocf_data_sampler/select/dropout.py +0 -0
  42. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/ocf_data_sampler/select/fill_time_periods.py +0 -0
  43. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/ocf_data_sampler/select/find_contiguous_time_periods.py +0 -0
  44. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/ocf_data_sampler/select/geospatial.py +0 -0
  45. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/ocf_data_sampler/select/location.py +0 -0
  46. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/ocf_data_sampler/select/select_spatial_slice.py +0 -0
  47. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/ocf_data_sampler/select/select_time_slice.py +0 -0
  48. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/ocf_data_sampler/torch_datasets/__init__.py +0 -0
  49. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/ocf_data_sampler.egg-info/SOURCES.txt +0 -0
  50. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/ocf_data_sampler.egg-info/dependency_links.txt +0 -0
  51. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/ocf_data_sampler.egg-info/requires.txt +0 -0
  52. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/ocf_data_sampler.egg-info/top_level.txt +0 -0
  53. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/setup.cfg +0 -0
  54. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/tests/__init__.py +0 -0
  55. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/tests/config/test_config.py +0 -0
  56. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/tests/conftest.py +0 -0
  57. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/tests/load/test_load_gsp.py +0 -0
  58. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/tests/load/test_load_nwp.py +0 -0
  59. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/tests/load/test_load_satellite.py +0 -0
  60. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/tests/select/test_dropout.py +0 -0
  61. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/tests/select/test_fill_time_periods.py +0 -0
  62. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/tests/select/test_find_contiguous_time_periods.py +0 -0
  63. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/tests/select/test_location.py +0 -0
  64. {ocf_data_sampler-0.0.22 → ocf_data_sampler-0.0.24}/tests/select/test_select_spatial_slice.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ocf_data_sampler
3
- Version: 0.0.22
3
+ Version: 0.0.24
4
4
  Summary: Sample from weather data for renewable energy prediction
5
5
  Author: James Fulton, Peter Dudfield, and the Open Climate Fix team
6
6
  Author-email: info@openclimatefix.org
@@ -0,0 +1,7 @@
1
+ """Conversion from Xarray to NumpyBatch"""
2
+
3
+ from .gsp import convert_gsp_to_numpy_batch, GSPBatchKey
4
+ from .nwp import convert_nwp_to_numpy_batch, NWPBatchKey
5
+ from .satellite import convert_satellite_to_numpy_batch, SatelliteBatchKey
6
+ from .sun_position import make_sun_position_numpy_batch
7
+
@@ -0,0 +1,33 @@
1
+ """Convert GSP to Numpy Batch"""
2
+
3
+ import xarray as xr
4
+
5
+
6
+ class GSPBatchKey:
7
+
8
+ gsp = 'gsp'
9
+ nominal_capacity_mwp = 'gsp_nominal_capacity_mwp'
10
+ effective_capacity_mwp = 'gsp_effective_capacity_mwp'
11
+ time_utc = 'gsp_time_utc'
12
+ t0_idx = 'gsp_t0_idx'
13
+ solar_azimuth = 'gsp_solar_azimuth'
14
+ solar_elevation = 'gsp_solar_elevation'
15
+ gsp_id = 'gsp_id'
16
+ x_osgb = 'gsp_x_osgb'
17
+ y_osgb = 'gsp_y_osgb'
18
+
19
+
20
+ def convert_gsp_to_numpy_batch(da: xr.DataArray, t0_idx: int | None = None) -> dict:
21
+ """Convert from Xarray to NumpyBatch"""
22
+
23
+ example = {
24
+ GSPBatchKey.gsp: da.values,
25
+ GSPBatchKey.nominal_capacity_mwp: da.isel(time_utc=0)["nominal_capacity_mwp"].values,
26
+ GSPBatchKey.effective_capacity_mwp: da.isel(time_utc=0)["effective_capacity_mwp"].values,
27
+ GSPBatchKey.time_utc: da["time_utc"].values.astype(float),
28
+ }
29
+
30
+ if t0_idx is not None:
31
+ example[GSPBatchKey.t0_idx] = t0_idx
32
+
33
+ return example
@@ -0,0 +1,43 @@
1
+ """Convert NWP to NumpyBatch"""
2
+
3
+ import pandas as pd
4
+ import xarray as xr
5
+
6
+
7
+ class NWPBatchKey:
8
+
9
+ nwp = 'nwp'
10
+ channel_names = 'nwp_channel_names'
11
+ init_time_utc = 'nwp_init_time_utc'
12
+ step = 'nwp_step'
13
+ target_time_utc = 'nwp_target_time_utc'
14
+ t0_idx = 'nwp_t0_idx'
15
+ y_osgb = 'nwp_y_osgb'
16
+ x_osgb = 'nwp_x_osgb'
17
+
18
+
19
+ def convert_nwp_to_numpy_batch(da: xr.DataArray, t0_idx: int | None = None) -> dict:
20
+ """Convert from Xarray to NWP NumpyBatch"""
21
+
22
+ example = {
23
+ NWPBatchKey.nwp: da.values,
24
+ NWPBatchKey.channel_names: da.channel.values,
25
+ NWPBatchKey.init_time_utc: da.init_time_utc.values.astype(float),
26
+ NWPBatchKey.step: (da.step.values / pd.Timedelta("1h")).astype(int),
27
+ }
28
+
29
+ if "target_time_utc" in da.coords:
30
+ example[NWPBatchKey.target_time_utc] = da.target_time_utc.values.astype(float)
31
+
32
+ # TODO: Do we need this at all? Especially since it is only present in UKV data
33
+ for batch_key, dataset_key in (
34
+ (NWPBatchKey.y_osgb, "y_osgb"),
35
+ (NWPBatchKey.x_osgb, "x_osgb"),
36
+ ):
37
+ if dataset_key in da.coords:
38
+ example[batch_key] = da[dataset_key].values
39
+
40
+ if t0_idx is not None:
41
+ example[NWPBatchKey.t0_idx] = t0_idx
42
+
43
+ return example
@@ -0,0 +1,30 @@
1
+ """Convert Satellite to NumpyBatch"""
2
+ import xarray as xr
3
+
4
+
5
+ class SatelliteBatchKey:
6
+
7
+ satellite_actual = 'satellite_actual'
8
+ time_utc = 'satellite_time_utc'
9
+ x_geostationary = 'satellite_x_geostationary'
10
+ y_geostationary = 'satellite_y_geostationary'
11
+ t0_idx = 'satellite_t0_idx'
12
+
13
+
14
+ def convert_satellite_to_numpy_batch(da: xr.DataArray, t0_idx: int | None = None) -> dict:
15
+ """Convert from Xarray to NumpyBatch"""
16
+ example = {
17
+ SatelliteBatchKey.satellite_actual: da.values,
18
+ SatelliteBatchKey.time_utc: da.time_utc.values.astype(float),
19
+ }
20
+
21
+ for batch_key, dataset_key in (
22
+ (SatelliteBatchKey.x_geostationary, "x_geostationary"),
23
+ (SatelliteBatchKey.y_geostationary, "y_geostationary"),
24
+ ):
25
+ example[batch_key] = da[dataset_key].values
26
+
27
+ if t0_idx is not None:
28
+ example[SatelliteBatchKey.t0_idx] = t0_idx
29
+
30
+ return example
@@ -24,12 +24,12 @@ from ocf_data_sampler.numpy_batch import (
24
24
  convert_nwp_to_numpy_batch,
25
25
  convert_satellite_to_numpy_batch,
26
26
  make_sun_position_numpy_batch,
27
+ NWPBatchKey,
28
+ GSPBatchKey,
27
29
  )
28
30
 
29
31
 
30
32
  from ocf_data_sampler.config import Configuration, load_yaml_configuration
31
- from ocf_data_sampler.numpy_batch.nwp import NWPBatchKey
32
- from ocf_data_sampler.numpy_batch.gsp import GSPBatchKey
33
33
 
34
34
  from ocf_data_sampler.select.location import Location
35
35
  from ocf_data_sampler.select.geospatial import osgb_to_lon_lat
@@ -426,8 +426,8 @@ def process_and_combine_datasets(
426
426
  # TODO: Do we need all of these?
427
427
  numpy_modalities.append({
428
428
  GSPBatchKey.gsp_id: location.id,
429
- GSPBatchKey.gsp_x_osgb: location.x,
430
- GSPBatchKey.gsp_y_osgb: location.y,
429
+ GSPBatchKey.x_osgb: location.x,
430
+ GSPBatchKey.y_osgb: location.y,
431
431
  })
432
432
 
433
433
  # Combine all the modalities and fill NaNs
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ocf_data_sampler
3
- Version: 0.0.22
3
+ Version: 0.0.24
4
4
  Summary: Sample from weather data for renewable energy prediction
5
5
  Author: James Fulton, Peter Dudfield, and the Open Climate Fix team
6
6
  Author-email: info@openclimatefix.org
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "ocf_data_sampler"
7
- version = "0.0.22"
7
+ version = "0.0.24"
8
8
  license = { file = "LICENSE" }
9
9
  readme = "README.md"
10
10
  description = "Sample from weather data for renewable energy prediction"
@@ -1,7 +1,6 @@
1
1
  from ocf_data_sampler.load.gsp import open_gsp
2
2
 
3
- from ocf_data_sampler.numpy_batch import convert_gsp_to_numpy_batch
4
- from ocf_data_sampler.numpy_batch.gsp import GSPBatchKey
3
+ from ocf_data_sampler.numpy_batch import convert_gsp_to_numpy_batch, GSPBatchKey
5
4
 
6
5
  def test_convert_gsp_to_numpy_batch(uk_gsp_zarr_path):
7
6
 
@@ -4,9 +4,7 @@ import xarray as xr
4
4
 
5
5
  import pytest
6
6
 
7
- from ocf_data_sampler.numpy_batch import convert_nwp_to_numpy_batch
8
-
9
- from ocf_data_sampler.numpy_batch.nwp import NWPBatchKey
7
+ from ocf_data_sampler.numpy_batch import convert_nwp_to_numpy_batch, NWPBatchKey
10
8
 
11
9
  @pytest.fixture(scope="module")
12
10
  def da_nwp_like():
@@ -16,7 +14,7 @@ def da_nwp_like():
16
14
 
17
15
  x = np.arange(-100, 100, 10)
18
16
  y = np.arange(-100, 100, 10)
19
- steps = pd.timedelta_range("0H", "8H", freq="1H")
17
+ steps = pd.timedelta_range("0h", "8h", freq="1h")
20
18
  target_times = t0 + steps
21
19
 
22
20
  channels = ["t", "dswrf"]
@@ -5,9 +5,7 @@ import xarray as xr
5
5
 
6
6
  import pytest
7
7
 
8
- from ocf_data_sampler.numpy_batch import convert_satellite_to_numpy_batch
9
-
10
- from ocf_data_sampler.numpy_batch.satellite import SatelliteBatchKey
8
+ from ocf_data_sampler.numpy_batch import convert_satellite_to_numpy_batch, SatelliteBatchKey
11
9
 
12
10
 
13
11
  @pytest.fixture(scope="module")
@@ -6,7 +6,7 @@ from ocf_data_sampler.numpy_batch.sun_position import (
6
6
  calculate_azimuth_and_elevation, make_sun_position_numpy_batch
7
7
  )
8
8
 
9
- from ocf_data_sampler.numpy_batch.gsp import GSPBatchKey
9
+ from ocf_data_sampler.numpy_batch import GSPBatchKey
10
10
 
11
11
 
12
12
  @pytest.mark.parametrize("lat", [0, 5, 10, 23.5])
@@ -71,11 +71,11 @@ def test_make_sun_position_numpy_batch():
71
71
 
72
72
  batch = make_sun_position_numpy_batch(datetimes, lon, lat, key_prefix="gsp")
73
73
 
74
- assert GSPBatchKey.gsp_solar_elevation in batch
75
- assert GSPBatchKey.gsp_solar_azimuth in batch
74
+ assert GSPBatchKey.solar_elevation in batch
75
+ assert GSPBatchKey.solar_azimuth in batch
76
76
 
77
77
  # The solar coords are normalised in the function
78
- assert (batch[GSPBatchKey.gsp_solar_elevation]>=0).all()
79
- assert (batch[GSPBatchKey.gsp_solar_elevation]<=1).all()
80
- assert (batch[GSPBatchKey.gsp_solar_azimuth]>=0).all()
81
- assert (batch[GSPBatchKey.gsp_solar_azimuth]<=1).all()
78
+ assert (batch[GSPBatchKey.solar_elevation]>=0).all()
79
+ assert (batch[GSPBatchKey.solar_elevation]<=1).all()
80
+ assert (batch[GSPBatchKey.solar_azimuth]>=0).all()
81
+ assert (batch[GSPBatchKey.solar_azimuth]<=1).all()
@@ -6,7 +6,7 @@ import xarray as xr
6
6
  import pytest
7
7
 
8
8
 
9
- NWP_FREQ = pd.Timedelta("3H")
9
+ NWP_FREQ = pd.Timedelta("3h")
10
10
 
11
11
  @pytest.fixture(scope="module")
12
12
  def da_sat_like():
@@ -33,7 +33,7 @@ def da_nwp_like():
33
33
  x = np.arange(-100, 100)
34
34
  y = np.arange(-100, 100)
35
35
  datetimes = pd.date_range("2024-01-02 00:00", "2024-01-03 00:00", freq=NWP_FREQ)
36
- steps = pd.timedelta_range("0H", "16H", freq="1H")
36
+ steps = pd.timedelta_range("0h", "16h", freq="1h")
37
37
  channels = ["t", "dswrf"]
38
38
 
39
39
  da_nwp = xr.DataArray(
@@ -138,9 +138,9 @@ def test_select_time_slice_nwp_basic(da_nwp_like, t0_str):
138
138
 
139
139
  # Slice parameters
140
140
  t0 = pd.Timestamp(f"2024-01-02 {t0_str}")
141
- forecast_duration = pd.Timedelta("6H")
142
- history_duration = pd.Timedelta("3H")
143
- freq = pd.Timedelta("1H")
141
+ forecast_duration = pd.Timedelta("6h")
142
+ history_duration = pd.Timedelta("3h")
143
+ freq = pd.Timedelta("1h")
144
144
 
145
145
  # Make the selection
146
146
  da_slice = select_time_slice_nwp(
@@ -172,10 +172,10 @@ def test_select_time_slice_nwp_with_dropout(da_nwp_like, dropout_hours):
172
172
  """Test the functionality of select_time_slice_nwp with dropout"""
173
173
 
174
174
  t0 = pd.Timestamp("2024-01-02 12:00")
175
- forecast_duration = pd.Timedelta("6H")
176
- history_duration = pd.Timedelta("3H")
177
- freq = pd.Timedelta("1H")
178
- dropout_timedelta = pd.Timedelta(f"-{dropout_hours}H")
175
+ forecast_duration = pd.Timedelta("6h")
176
+ history_duration = pd.Timedelta("3h")
177
+ freq = pd.Timedelta("1h")
178
+ dropout_timedelta = pd.Timedelta(f"-{dropout_hours}h")
179
179
 
180
180
  da_slice = select_time_slice_nwp(
181
181
  da_nwp_like,
@@ -207,10 +207,10 @@ def test_select_time_slice_nwp_with_dropout_and_accum(da_nwp_like, t0_str):
207
207
 
208
208
  # Slice parameters
209
209
  t0 = pd.Timestamp(f"2024-01-02 {t0_str}")
210
- forecast_duration = pd.Timedelta("6H")
211
- history_duration = pd.Timedelta("3H")
212
- freq = pd.Timedelta("1H")
213
- dropout_timedelta = pd.Timedelta("-2H")
210
+ forecast_duration = pd.Timedelta("6h")
211
+ history_duration = pd.Timedelta("3h")
212
+ freq = pd.Timedelta("1h")
213
+ dropout_timedelta = pd.Timedelta("-2h")
214
214
 
215
215
  t0_delayed = (t0 + dropout_timedelta).floor(NWP_FREQ)
216
216
 
@@ -3,9 +3,7 @@ import tempfile
3
3
 
4
4
  from ocf_data_sampler.torch_datasets.pvnet_uk_regional import PVNetUKRegionalDataset
5
5
  from ocf_data_sampler.config import load_yaml_configuration, save_yaml_configuration
6
- from ocf_data_sampler.numpy_batch.nwp import NWPBatchKey
7
- from ocf_data_sampler.numpy_batch.gsp import GSPBatchKey
8
- from ocf_data_sampler.numpy_batch.satellite import SatelliteBatchKey
6
+ from ocf_data_sampler.numpy_batch import NWPBatchKey, GSPBatchKey, SatelliteBatchKey
9
7
 
10
8
 
11
9
  @pytest.fixture()
@@ -39,7 +37,7 @@ def test_pvnet(pvnet_config_filename):
39
37
 
40
38
  for key in [
41
39
  NWPBatchKey.nwp, SatelliteBatchKey.satellite_actual, GSPBatchKey.gsp,
42
- GSPBatchKey.gsp_solar_azimuth, GSPBatchKey.gsp_solar_elevation,
40
+ GSPBatchKey.solar_azimuth, GSPBatchKey.solar_elevation,
43
41
  ]:
44
42
  assert key in sample
45
43
 
@@ -54,8 +52,8 @@ def test_pvnet(pvnet_config_filename):
54
52
  # 3 hours of 30 minute data (inclusive)
55
53
  assert sample[GSPBatchKey.gsp].shape == (7,)
56
54
  # Solar angles have same shape as GSP data
57
- assert sample[GSPBatchKey.gsp_solar_azimuth].shape == (7,)
58
- assert sample[GSPBatchKey.gsp_solar_elevation].shape == (7,)
55
+ assert sample[GSPBatchKey.solar_azimuth].shape == (7,)
56
+ assert sample[GSPBatchKey.solar_elevation].shape == (7,)
59
57
 
60
58
  def test_pvnet_no_gsp(pvnet_config_filename):
61
59
 
@@ -1,7 +0,0 @@
1
- """Conversion from Xarray to NumpyBatch"""
2
-
3
- from .gsp import convert_gsp_to_numpy_batch
4
- from .nwp import convert_nwp_to_numpy_batch
5
- from .satellite import convert_satellite_to_numpy_batch
6
- from .sun_position import make_sun_position_numpy_batch
7
-
@@ -1,33 +0,0 @@
1
- """Convert GSP to Numpy Batch"""
2
-
3
- import xarray as xr
4
-
5
-
6
- class GSPBatchKey:
7
-
8
- gsp = 'gsp'
9
- gsp_nominal_capacity_mwp = 'gsp_nominal_capacity_mwp'
10
- gsp_effective_capacity_mwp = 'gsp_effective_capacity_mwp'
11
- gsp_time_utc = 'gsp_time_utc'
12
- gsp_t0_idx = 'gsp_t0_idx'
13
- gsp_solar_azimuth = 'gsp_solar_azimuth'
14
- gsp_solar_elevation = 'gsp_solar_elevation'
15
- gsp_id = 'gsp_id'
16
- gsp_x_osgb = 'gsp_x_osgb'
17
- gsp_y_osgb = 'gsp_y_osgb'
18
-
19
-
20
- def convert_gsp_to_numpy_batch(da: xr.DataArray, t0_idx: int | None = None) -> dict:
21
- """Convert from Xarray to NumpyBatch"""
22
-
23
- example = {
24
- GSPBatchKey.gsp: da.values,
25
- GSPBatchKey.gsp_nominal_capacity_mwp: da.isel(time_utc=0)["nominal_capacity_mwp"].values,
26
- GSPBatchKey.gsp_effective_capacity_mwp: da.isel(time_utc=0)["effective_capacity_mwp"].values,
27
- GSPBatchKey.gsp_time_utc: da["time_utc"].values.astype(float),
28
- }
29
-
30
- if t0_idx is not None:
31
- example[GSPBatchKey.gsp_t0_idx] = t0_idx
32
-
33
- return example
@@ -1,43 +0,0 @@
1
- """Convert NWP to NumpyBatch"""
2
-
3
- import pandas as pd
4
- import xarray as xr
5
-
6
-
7
- class NWPBatchKey:
8
-
9
- nwp = 'nwp'
10
- nwp_channel_names = 'nwp_channel_names'
11
- nwp_init_time_utc = 'nwp_init_time_utc'
12
- nwp_step = 'nwp_step'
13
- nwp_target_time_utc = 'nwp_target_time_utc'
14
- nwp_t0_idx = 'nwp_t0_idx'
15
- nwp_y_osgb = 'nwp_y_osgb'
16
- nwp_x_osgb = 'nwp_x_osgb'
17
-
18
-
19
- def convert_nwp_to_numpy_batch(da: xr.DataArray, t0_idx: int | None = None) -> dict:
20
- """Convert from Xarray to NWP NumpyBatch"""
21
-
22
- example = {
23
- NWPBatchKey.nwp: da.values,
24
- NWPBatchKey.nwp_channel_names: da.channel.values,
25
- NWPBatchKey.nwp_init_time_utc: da.init_time_utc.values.astype(float),
26
- NWPBatchKey.nwp_step: (da.step.values / pd.Timedelta("1h")).astype(int),
27
- }
28
-
29
- if "target_time_utc" in da.coords:
30
- example[NWPBatchKey.nwp_target_time_utc] = da.target_time_utc.values.astype(float)
31
-
32
- # TODO: Do we need this at all? Especially since it is only present in UKV data
33
- for batch_key, dataset_key in (
34
- (NWPBatchKey.nwp_y_osgb, "y_osgb"),
35
- (NWPBatchKey.nwp_x_osgb, "x_osgb"),
36
- ):
37
- if dataset_key in da.coords:
38
- example[batch_key] = da[dataset_key].values
39
-
40
- if t0_idx is not None:
41
- example[NWPBatchKey.nwp_t0_idx] = t0_idx
42
-
43
- return example
@@ -1,30 +0,0 @@
1
- """Convert Satellite to NumpyBatch"""
2
- import xarray as xr
3
-
4
-
5
- class SatelliteBatchKey:
6
-
7
- satellite_actual = 'satellite_actual'
8
- satellite_time_utc = 'satellite_time_utc'
9
- satellite_x_geostationary = 'satellite_x_geostationary'
10
- satellite_y_geostationary = 'satellite_y_geostationary'
11
- satellite_t0_idx = 'satellite_t0_idx'
12
-
13
-
14
- def convert_satellite_to_numpy_batch(da: xr.DataArray, t0_idx: int | None = None) -> dict:
15
- """Convert from Xarray to NumpyBatch"""
16
- example = {
17
- SatelliteBatchKey.satellite_actual: da.values,
18
- SatelliteBatchKey.satellite_time_utc: da.time_utc.values.astype(float),
19
- }
20
-
21
- for batch_key, dataset_key in (
22
- (SatelliteBatchKey.satellite_x_geostationary, "x_geostationary"),
23
- (SatelliteBatchKey.satellite_y_geostationary, "y_geostationary"),
24
- ):
25
- example[batch_key] = da[dataset_key].values
26
-
27
- if t0_idx is not None:
28
- example[SatelliteBatchKey.satellite_t0_idx] = t0_idx
29
-
30
- return example