ocf-data-sampler 0.0.35__tar.gz → 0.0.37__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 (75) hide show
  1. {ocf_data_sampler-0.0.35/ocf_data_sampler.egg-info → ocf_data_sampler-0.0.37}/PKG-INFO +3 -2
  2. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/README.md +2 -1
  3. ocf_data_sampler-0.0.37/ocf_data_sampler/numpy_batch/collate.py +79 -0
  4. ocf_data_sampler-0.0.37/ocf_data_sampler/numpy_batch/site.py +29 -0
  5. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37/ocf_data_sampler.egg-info}/PKG-INFO +3 -2
  6. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler.egg-info/SOURCES.txt +2 -0
  7. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/pyproject.toml +1 -1
  8. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/tests/conftest.py +16 -0
  9. ocf_data_sampler-0.0.37/tests/numpy_batch/test_collate.py +26 -0
  10. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/tests/torch_datasets/test_pvnet_uk_regional.py +0 -13
  11. ocf_data_sampler-0.0.35/ocf_data_sampler/numpy_batch/site.py +0 -29
  12. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/LICENSE +0 -0
  13. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/MANIFEST.in +0 -0
  14. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler/__init__.py +0 -0
  15. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler/config/__init__.py +0 -0
  16. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler/config/load.py +0 -0
  17. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler/config/model.py +0 -0
  18. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler/config/save.py +0 -0
  19. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler/constants.py +0 -0
  20. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler/data/uk_gsp_locations.csv +0 -0
  21. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler/load/__init__.py +0 -0
  22. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler/load/gsp.py +0 -0
  23. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler/load/load_dataset.py +0 -0
  24. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler/load/nwp/__init__.py +0 -0
  25. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler/load/nwp/nwp.py +0 -0
  26. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler/load/nwp/providers/__init__.py +0 -0
  27. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler/load/nwp/providers/ecmwf.py +0 -0
  28. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler/load/nwp/providers/ukv.py +0 -0
  29. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler/load/nwp/providers/utils.py +0 -0
  30. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler/load/satellite.py +0 -0
  31. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler/load/site.py +0 -0
  32. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler/load/utils.py +0 -0
  33. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler/numpy_batch/__init__.py +0 -0
  34. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler/numpy_batch/gsp.py +0 -0
  35. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler/numpy_batch/nwp.py +0 -0
  36. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler/numpy_batch/satellite.py +0 -0
  37. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler/numpy_batch/sun_position.py +0 -0
  38. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler/select/__init__.py +0 -0
  39. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler/select/dropout.py +0 -0
  40. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler/select/fill_time_periods.py +0 -0
  41. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler/select/find_contiguous_time_periods.py +0 -0
  42. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler/select/geospatial.py +0 -0
  43. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler/select/location.py +0 -0
  44. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler/select/select_spatial_slice.py +0 -0
  45. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler/select/select_time_slice.py +0 -0
  46. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler/select/spatial_slice_for_dataset.py +0 -0
  47. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler/select/time_slice_for_dataset.py +0 -0
  48. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler/torch_datasets/__init__.py +0 -0
  49. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler/torch_datasets/process_and_combine.py +0 -0
  50. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler/torch_datasets/pvnet_uk_regional.py +0 -0
  51. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler/torch_datasets/site.py +0 -0
  52. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler/torch_datasets/valid_time_periods.py +0 -0
  53. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler/utils.py +0 -0
  54. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler.egg-info/dependency_links.txt +0 -0
  55. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler.egg-info/requires.txt +0 -0
  56. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/ocf_data_sampler.egg-info/top_level.txt +0 -0
  57. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/scripts/refactor_site.py +0 -0
  58. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/setup.cfg +0 -0
  59. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/tests/__init__.py +0 -0
  60. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/tests/config/test_config.py +0 -0
  61. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/tests/load/test_load_gsp.py +0 -0
  62. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/tests/load/test_load_nwp.py +0 -0
  63. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/tests/load/test_load_satellite.py +0 -0
  64. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/tests/load/test_load_sites.py +0 -0
  65. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/tests/numpy_batch/test_gsp.py +0 -0
  66. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/tests/numpy_batch/test_nwp.py +0 -0
  67. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/tests/numpy_batch/test_satellite.py +0 -0
  68. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/tests/numpy_batch/test_sun_position.py +0 -0
  69. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/tests/select/test_dropout.py +0 -0
  70. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/tests/select/test_fill_time_periods.py +0 -0
  71. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/tests/select/test_find_contiguous_time_periods.py +0 -0
  72. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/tests/select/test_location.py +0 -0
  73. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/tests/select/test_select_spatial_slice.py +0 -0
  74. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/tests/select/test_select_time_slice.py +0 -0
  75. {ocf_data_sampler-0.0.35 → ocf_data_sampler-0.0.37}/tests/torch_datasets/test_site.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ocf_data_sampler
3
- Version: 0.0.35
3
+ Version: 0.0.37
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
@@ -56,7 +56,7 @@ Requires-Dist: mkdocs-material>=8.0; extra == "docs"
56
56
  # ocf-data-sampler
57
57
 
58
58
  <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
59
- [![All Contributors](https://img.shields.io/badge/all_contributors-6-orange.svg?style=flat-square)](#contributors-)
59
+ [![All Contributors](https://img.shields.io/badge/all_contributors-7-orange.svg?style=flat-square)](#contributors-)
60
60
  <!-- ALL-CONTRIBUTORS-BADGE:END -->
61
61
 
62
62
  [![tags badge](https://img.shields.io/github/v/tag/openclimatefix/ocf-data-sampler?include_prereleases&sort=semver&color=FFAC5F)](https://github.com/openclimatefix/ocf-data-sampler/tags)
@@ -129,6 +129,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
129
129
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/peterdudfield"><img src="https://avatars.githubusercontent.com/u/34686298?v=4?s=100" width="100px;" alt="Peter Dudfield"/><br /><sub><b>Peter Dudfield</b></sub></a><br /><a href="https://github.com/openclimatefix/ocf-data-sampler/commits?author=peterdudfield" title="Code">💻</a></td>
130
130
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/VikramsDataScience"><img src="https://avatars.githubusercontent.com/u/45002417?v=4?s=100" width="100px;" alt="Vikram Pande"/><br /><sub><b>Vikram Pande</b></sub></a><br /><a href="https://github.com/openclimatefix/ocf-data-sampler/commits?author=VikramsDataScience" title="Code">💻</a></td>
131
131
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/SophiaLi20"><img src="https://avatars.githubusercontent.com/u/163532536?v=4?s=100" width="100px;" alt="Unnati Bhardwaj"/><br /><sub><b>Unnati Bhardwaj</b></sub></a><br /><a href="https://github.com/openclimatefix/ocf-data-sampler/commits?author=SophiaLi20" title="Documentation">📖</a></td>
132
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/alirashidAR"><img src="https://avatars.githubusercontent.com/u/110668489?v=4?s=100" width="100px;" alt="Ali Rashid"/><br /><sub><b>Ali Rashid</b></sub></a><br /><a href="https://github.com/openclimatefix/ocf-data-sampler/commits?author=alirashidAR" title="Code">💻</a></td>
132
133
  </tr>
133
134
  </tbody>
134
135
  </table>
@@ -1,7 +1,7 @@
1
1
  # ocf-data-sampler
2
2
 
3
3
  <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
4
- [![All Contributors](https://img.shields.io/badge/all_contributors-6-orange.svg?style=flat-square)](#contributors-)
4
+ [![All Contributors](https://img.shields.io/badge/all_contributors-7-orange.svg?style=flat-square)](#contributors-)
5
5
  <!-- ALL-CONTRIBUTORS-BADGE:END -->
6
6
 
7
7
  [![tags badge](https://img.shields.io/github/v/tag/openclimatefix/ocf-data-sampler?include_prereleases&sort=semver&color=FFAC5F)](https://github.com/openclimatefix/ocf-data-sampler/tags)
@@ -74,6 +74,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
74
74
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/peterdudfield"><img src="https://avatars.githubusercontent.com/u/34686298?v=4?s=100" width="100px;" alt="Peter Dudfield"/><br /><sub><b>Peter Dudfield</b></sub></a><br /><a href="https://github.com/openclimatefix/ocf-data-sampler/commits?author=peterdudfield" title="Code">💻</a></td>
75
75
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/VikramsDataScience"><img src="https://avatars.githubusercontent.com/u/45002417?v=4?s=100" width="100px;" alt="Vikram Pande"/><br /><sub><b>Vikram Pande</b></sub></a><br /><a href="https://github.com/openclimatefix/ocf-data-sampler/commits?author=VikramsDataScience" title="Code">💻</a></td>
76
76
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/SophiaLi20"><img src="https://avatars.githubusercontent.com/u/163532536?v=4?s=100" width="100px;" alt="Unnati Bhardwaj"/><br /><sub><b>Unnati Bhardwaj</b></sub></a><br /><a href="https://github.com/openclimatefix/ocf-data-sampler/commits?author=SophiaLi20" title="Documentation">📖</a></td>
77
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/alirashidAR"><img src="https://avatars.githubusercontent.com/u/110668489?v=4?s=100" width="100px;" alt="Ali Rashid"/><br /><sub><b>Ali Rashid</b></sub></a><br /><a href="https://github.com/openclimatefix/ocf-data-sampler/commits?author=alirashidAR" title="Code">💻</a></td>
77
78
  </tr>
78
79
  </tbody>
79
80
  </table>
@@ -0,0 +1,79 @@
1
+ from ocf_data_sampler.numpy_batch import NWPBatchKey
2
+
3
+ import numpy as np
4
+ import logging
5
+ from typing import Union
6
+
7
+ logger = logging.getLogger(__name__)
8
+
9
+
10
+ def stack_np_examples_into_batch(dict_list):
11
+ """
12
+ Stacks Numpy examples into a batch
13
+
14
+ See also: `unstack_np_batch_into_examples()` for opposite
15
+
16
+ Args:
17
+ dict_list: A list of dict-like Numpy examples to stack
18
+
19
+ Returns:
20
+ The stacked NumpyBatch object
21
+ """
22
+ batch = {}
23
+
24
+ batch_keys = list(dict_list[0].keys())
25
+
26
+ for batch_key in batch_keys:
27
+ # NWP is nested so treat separately
28
+ if batch_key == "nwp":
29
+ nwp_batch: dict[str, NWPBatchKey] = {}
30
+
31
+ # Unpack source keys
32
+ nwp_sources = list(dict_list[0]["nwp"].keys())
33
+
34
+ for nwp_source in nwp_sources:
35
+ # Keys can be different for different NWPs
36
+ nwp_batch_keys = list(dict_list[0]["nwp"][nwp_source].keys())
37
+
38
+ nwp_source_batch = {}
39
+ for nwp_batch_key in nwp_batch_keys:
40
+ nwp_source_batch[nwp_batch_key] = stack_data_list(
41
+ [d["nwp"][nwp_source][nwp_batch_key] for d in dict_list],
42
+ nwp_batch_key,
43
+ )
44
+
45
+ nwp_batch[nwp_source] = nwp_source_batch
46
+
47
+ batch["nwp"] = nwp_batch
48
+
49
+ else:
50
+ batch[batch_key] = stack_data_list(
51
+ [d[batch_key] for d in dict_list],
52
+ batch_key,
53
+ )
54
+
55
+ return batch
56
+
57
+
58
+ def _key_is_constant(batch_key):
59
+ is_constant = batch_key.endswith("t0_idx") or batch_key == NWPBatchKey.channel_names
60
+ return is_constant
61
+
62
+
63
+ def stack_data_list(
64
+ data_list: list,
65
+ batch_key: Union[str, NWPBatchKey],
66
+ ):
67
+ """How to combine data entries for each key
68
+ """
69
+ if _key_is_constant(batch_key):
70
+ # These are always the same for all examples.
71
+ return data_list[0]
72
+ try:
73
+ return np.stack(data_list)
74
+ except Exception as e:
75
+ logger.debug(f"Could not stack the following shapes together, ({batch_key})")
76
+ shapes = [example.shape for example in data_list]
77
+ logger.debug(shapes)
78
+ logger.error(e)
79
+ raise e
@@ -0,0 +1,29 @@
1
+ """Convert site to Numpy Batch"""
2
+
3
+ import xarray as xr
4
+
5
+
6
+ class SiteBatchKey:
7
+
8
+ generation = "site"
9
+ capacity_kwp = "site_capacity_kwp"
10
+ time_utc = "site_time_utc"
11
+ t0_idx = "site_t0_idx"
12
+ solar_azimuth = "site_solar_azimuth"
13
+ solar_elevation = "site_solar_elevation"
14
+ id = "site_id"
15
+
16
+
17
+ def convert_site_to_numpy_batch(da: xr.DataArray, t0_idx: int | None = None) -> dict:
18
+ """Convert from Xarray to NumpyBatch"""
19
+
20
+ example = {
21
+ SiteBatchKey.generation: da.values,
22
+ SiteBatchKey.capacity_kwp: da.isel(time_utc=0)["capacity_kwp"].values,
23
+ SiteBatchKey.time_utc: da["time_utc"].values.astype(float),
24
+ }
25
+
26
+ if t0_idx is not None:
27
+ example[SiteBatchKey.t0_idx] = t0_idx
28
+
29
+ return example
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ocf_data_sampler
3
- Version: 0.0.35
3
+ Version: 0.0.37
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
@@ -56,7 +56,7 @@ Requires-Dist: mkdocs-material>=8.0; extra == "docs"
56
56
  # ocf-data-sampler
57
57
 
58
58
  <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
59
- [![All Contributors](https://img.shields.io/badge/all_contributors-6-orange.svg?style=flat-square)](#contributors-)
59
+ [![All Contributors](https://img.shields.io/badge/all_contributors-7-orange.svg?style=flat-square)](#contributors-)
60
60
  <!-- ALL-CONTRIBUTORS-BADGE:END -->
61
61
 
62
62
  [![tags badge](https://img.shields.io/github/v/tag/openclimatefix/ocf-data-sampler?include_prereleases&sort=semver&color=FFAC5F)](https://github.com/openclimatefix/ocf-data-sampler/tags)
@@ -129,6 +129,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
129
129
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/peterdudfield"><img src="https://avatars.githubusercontent.com/u/34686298?v=4?s=100" width="100px;" alt="Peter Dudfield"/><br /><sub><b>Peter Dudfield</b></sub></a><br /><a href="https://github.com/openclimatefix/ocf-data-sampler/commits?author=peterdudfield" title="Code">💻</a></td>
130
130
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/VikramsDataScience"><img src="https://avatars.githubusercontent.com/u/45002417?v=4?s=100" width="100px;" alt="Vikram Pande"/><br /><sub><b>Vikram Pande</b></sub></a><br /><a href="https://github.com/openclimatefix/ocf-data-sampler/commits?author=VikramsDataScience" title="Code">💻</a></td>
131
131
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/SophiaLi20"><img src="https://avatars.githubusercontent.com/u/163532536?v=4?s=100" width="100px;" alt="Unnati Bhardwaj"/><br /><sub><b>Unnati Bhardwaj</b></sub></a><br /><a href="https://github.com/openclimatefix/ocf-data-sampler/commits?author=SophiaLi20" title="Documentation">📖</a></td>
132
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/alirashidAR"><img src="https://avatars.githubusercontent.com/u/110668489?v=4?s=100" width="100px;" alt="Ali Rashid"/><br /><sub><b>Ali Rashid</b></sub></a><br /><a href="https://github.com/openclimatefix/ocf-data-sampler/commits?author=alirashidAR" title="Code">💻</a></td>
132
133
  </tr>
133
134
  </tbody>
134
135
  </table>
@@ -28,6 +28,7 @@ ocf_data_sampler/load/nwp/providers/ecmwf.py
28
28
  ocf_data_sampler/load/nwp/providers/ukv.py
29
29
  ocf_data_sampler/load/nwp/providers/utils.py
30
30
  ocf_data_sampler/numpy_batch/__init__.py
31
+ ocf_data_sampler/numpy_batch/collate.py
31
32
  ocf_data_sampler/numpy_batch/gsp.py
32
33
  ocf_data_sampler/numpy_batch/nwp.py
33
34
  ocf_data_sampler/numpy_batch/satellite.py
@@ -56,6 +57,7 @@ tests/load/test_load_gsp.py
56
57
  tests/load/test_load_nwp.py
57
58
  tests/load/test_load_satellite.py
58
59
  tests/load/test_load_sites.py
60
+ tests/numpy_batch/test_collate.py
59
61
  tests/numpy_batch/test_gsp.py
60
62
  tests/numpy_batch/test_nwp.py
61
63
  tests/numpy_batch/test_satellite.py
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "ocf_data_sampler"
7
- version = "0.0.35"
7
+ version = "0.0.37"
8
8
  license = { file = "LICENSE" }
9
9
  readme = "README.md"
10
10
  description = "Sample from weather data for renewable energy prediction"
@@ -7,6 +7,7 @@ import xarray as xr
7
7
  import tempfile
8
8
 
9
9
  from ocf_data_sampler.config.model import Site
10
+ from ocf_data_sampler.config import load_yaml_configuration, save_yaml_configuration
10
11
 
11
12
  _top_test_directory = os.path.dirname(os.path.realpath(__file__))
12
13
 
@@ -269,3 +270,18 @@ def uk_gsp_zarr_path(ds_uk_gsp):
269
270
  ds_uk_gsp.to_zarr(filename)
270
271
  yield filename
271
272
 
273
+
274
+ @pytest.fixture()
275
+ def pvnet_config_filename(
276
+ tmp_path, config_filename, nwp_ukv_zarr_path, uk_gsp_zarr_path, sat_zarr_path
277
+ ):
278
+
279
+ # adjust config to point to the zarr file
280
+ config = load_yaml_configuration(config_filename)
281
+ config.input_data.nwp["ukv"].zarr_path = nwp_ukv_zarr_path
282
+ config.input_data.satellite.zarr_path = sat_zarr_path
283
+ config.input_data.gsp.zarr_path = uk_gsp_zarr_path
284
+
285
+ filename = f"{tmp_path}/configuration.yaml"
286
+ save_yaml_configuration(config, filename)
287
+ return filename
@@ -0,0 +1,26 @@
1
+ from ocf_data_sampler.numpy_batch import GSPBatchKey, SatelliteBatchKey
2
+ from ocf_data_sampler.numpy_batch.collate import stack_np_examples_into_batch
3
+ from ocf_data_sampler.torch_datasets import PVNetUKRegionalDataset
4
+
5
+
6
+ def test_pvnet(pvnet_config_filename):
7
+
8
+ # Create dataset object
9
+ dataset = PVNetUKRegionalDataset(pvnet_config_filename)
10
+
11
+ assert len(dataset.locations) == 317
12
+ assert len(dataset.valid_t0_times) == 39
13
+ assert len(dataset) == 317 * 39
14
+
15
+ # Generate 2 samples
16
+ sample1 = dataset[0]
17
+ sample2 = dataset[1]
18
+
19
+ batch = stack_np_examples_into_batch([sample1, sample2])
20
+
21
+ assert isinstance(batch, dict)
22
+ assert "nwp" in batch
23
+ assert isinstance(batch["nwp"], dict)
24
+ assert "ukv" in batch["nwp"]
25
+ assert GSPBatchKey.gsp in batch
26
+ assert SatelliteBatchKey.satellite_actual in batch
@@ -6,19 +6,6 @@ from ocf_data_sampler.config import load_yaml_configuration, save_yaml_configura
6
6
  from ocf_data_sampler.numpy_batch import NWPBatchKey, GSPBatchKey, SatelliteBatchKey
7
7
 
8
8
 
9
- @pytest.fixture()
10
- def pvnet_config_filename(tmp_path, config_filename, nwp_ukv_zarr_path, uk_gsp_zarr_path, sat_zarr_path):
11
-
12
- # adjust config to point to the zarr file
13
- config = load_yaml_configuration(config_filename)
14
- config.input_data.nwp['ukv'].zarr_path = nwp_ukv_zarr_path
15
- config.input_data.satellite.zarr_path = sat_zarr_path
16
- config.input_data.gsp.zarr_path = uk_gsp_zarr_path
17
-
18
- filename = f"{tmp_path}/configuration.yaml"
19
- save_yaml_configuration(config, filename)
20
- return filename
21
-
22
9
 
23
10
  def test_pvnet(pvnet_config_filename):
24
11
 
@@ -1,29 +0,0 @@
1
- """Convert site to Numpy Batch"""
2
-
3
- import xarray as xr
4
-
5
-
6
- class SiteBatchKey:
7
-
8
- generation = "site"
9
- site_capacity_kwp = "site_capacity_kwp"
10
- site_time_utc = "site_time_utc"
11
- site_t0_idx = "site_t0_idx"
12
- site_solar_azimuth = "site_solar_azimuth"
13
- site_solar_elevation = "site_solar_elevation"
14
- site_id = "site_id"
15
-
16
-
17
- def convert_site_to_numpy_batch(da: xr.DataArray, t0_idx: int | None = None) -> dict:
18
- """Convert from Xarray to NumpyBatch"""
19
-
20
- example = {
21
- SiteBatchKey.generation: da.values,
22
- SiteBatchKey.site_capacity_kwp: da.isel(time_utc=0)["capacity_kwp"].values,
23
- SiteBatchKey.site_time_utc: da["time_utc"].values.astype(float),
24
- }
25
-
26
- if t0_idx is not None:
27
- example[SiteBatchKey.site_t0_idx] = t0_idx
28
-
29
- return example