ocf-data-sampler 0.1.8__tar.gz → 0.1.9__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.
Files changed (88) hide show
  1. {ocf_data_sampler-0.1.8/ocf_data_sampler.egg-info → ocf_data_sampler-0.1.9}/PKG-INFO +1 -1
  2. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/sample/base.py +23 -0
  3. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9/ocf_data_sampler.egg-info}/PKG-INFO +1 -1
  4. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/pyproject.toml +1 -1
  5. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/scripts/refactor_site.py +1 -1
  6. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/tests/test_sample/test_base.py +18 -1
  7. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/LICENSE +0 -0
  8. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/MANIFEST.in +0 -0
  9. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/README.md +0 -0
  10. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/__init__.py +0 -0
  11. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/config/__init__.py +0 -0
  12. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/config/load.py +0 -0
  13. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/config/model.py +0 -0
  14. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/config/save.py +0 -0
  15. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/constants.py +0 -0
  16. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/data/uk_gsp_locations.csv +0 -0
  17. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/load/__init__.py +0 -0
  18. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/load/gsp.py +0 -0
  19. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/load/load_dataset.py +0 -0
  20. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/load/nwp/__init__.py +0 -0
  21. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/load/nwp/nwp.py +0 -0
  22. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/load/nwp/providers/__init__.py +0 -0
  23. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/load/nwp/providers/ecmwf.py +0 -0
  24. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/load/nwp/providers/ukv.py +0 -0
  25. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/load/nwp/providers/utils.py +0 -0
  26. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/load/satellite.py +0 -0
  27. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/load/site.py +0 -0
  28. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/load/utils.py +0 -0
  29. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/numpy_sample/__init__.py +0 -0
  30. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/numpy_sample/collate.py +0 -0
  31. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/numpy_sample/datetime_features.py +0 -0
  32. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/numpy_sample/gsp.py +0 -0
  33. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/numpy_sample/nwp.py +0 -0
  34. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/numpy_sample/satellite.py +0 -0
  35. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/numpy_sample/site.py +0 -0
  36. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/numpy_sample/sun_position.py +0 -0
  37. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/sample/__init__.py +0 -0
  38. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/sample/site.py +0 -0
  39. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/sample/uk_regional.py +0 -0
  40. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/select/__init__.py +0 -0
  41. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/select/dropout.py +0 -0
  42. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/select/fill_time_periods.py +0 -0
  43. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/select/find_contiguous_time_periods.py +0 -0
  44. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/select/geospatial.py +0 -0
  45. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/select/location.py +0 -0
  46. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/select/select_spatial_slice.py +0 -0
  47. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/select/select_time_slice.py +0 -0
  48. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/select/spatial_slice_for_dataset.py +0 -0
  49. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/select/time_slice_for_dataset.py +0 -0
  50. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/torch_datasets/datasets/__init__.py +0 -0
  51. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/torch_datasets/datasets/pvnet_uk.py +0 -0
  52. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/torch_datasets/datasets/site.py +0 -0
  53. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/torch_datasets/utils/merge_and_fill_utils.py +0 -0
  54. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/torch_datasets/utils/valid_time_periods.py +0 -0
  55. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/torch_datasets/utils/validate_channels.py +0 -0
  56. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler/utils.py +0 -0
  57. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler.egg-info/SOURCES.txt +0 -0
  58. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler.egg-info/dependency_links.txt +0 -0
  59. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler.egg-info/requires.txt +0 -0
  60. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/ocf_data_sampler.egg-info/top_level.txt +0 -0
  61. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/setup.cfg +0 -0
  62. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/tests/__init__.py +0 -0
  63. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/tests/config/test_config.py +0 -0
  64. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/tests/config/test_load.py +0 -0
  65. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/tests/config/test_save.py +0 -0
  66. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/tests/conftest.py +0 -0
  67. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/tests/load/test_load_gsp.py +0 -0
  68. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/tests/load/test_load_nwp.py +0 -0
  69. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/tests/load/test_load_satellite.py +0 -0
  70. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/tests/load/test_load_sites.py +0 -0
  71. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/tests/numpy_sample/test_collate.py +0 -0
  72. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/tests/numpy_sample/test_datetime_features.py +0 -0
  73. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/tests/numpy_sample/test_gsp.py +0 -0
  74. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/tests/numpy_sample/test_nwp.py +0 -0
  75. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/tests/numpy_sample/test_satellite.py +0 -0
  76. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/tests/numpy_sample/test_sun_position.py +0 -0
  77. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/tests/select/test_dropout.py +0 -0
  78. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/tests/select/test_fill_time_periods.py +0 -0
  79. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/tests/select/test_find_contiguous_time_periods.py +0 -0
  80. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/tests/select/test_location.py +0 -0
  81. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/tests/select/test_select_spatial_slice.py +0 -0
  82. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/tests/select/test_select_time_slice.py +0 -0
  83. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/tests/test_sample/test_site_sample.py +0 -0
  84. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/tests/test_sample/test_uk_regional_sample.py +0 -0
  85. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/tests/torch_datasets/test_merge_and_fill_utils.py +0 -0
  86. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/tests/torch_datasets/test_pvnet_uk.py +0 -0
  87. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/tests/torch_datasets/test_site.py +0 -0
  88. {ocf_data_sampler-0.1.8 → ocf_data_sampler-0.1.9}/tests/torch_datasets/test_validate_channels_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: ocf_data_sampler
3
- Version: 0.1.8
3
+ Version: 0.1.9
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
@@ -73,3 +73,26 @@ def batch_to_tensor(batch: NumpyBatch) -> TensorBatch:
73
73
  elif np.issubdtype(v.dtype, np.number):
74
74
  batch[k] = torch.as_tensor(v)
75
75
  return batch
76
+
77
+
78
+ def copy_batch_to_device(batch: dict, device: torch.device) -> dict:
79
+ """
80
+ Moves tensor leaves in a nested dict to a new device.
81
+
82
+ Args:
83
+ batch: Nested dict with tensors to move.
84
+ device: Device to move tensors to.
85
+
86
+ Returns:
87
+ A dict with tensors moved to the new device.
88
+ """
89
+ batch_copy = {}
90
+
91
+ for k, v in batch.items():
92
+ if isinstance(v, dict):
93
+ batch_copy[k] = copy_batch_to_device(v, device)
94
+ elif isinstance(v, torch.Tensor):
95
+ batch_copy[k] = v.to(device)
96
+ else:
97
+ batch_copy[k] = v
98
+ return batch_copy
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: ocf_data_sampler
3
- Version: 0.1.8
3
+ Version: 0.1.9
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.1.8"
7
+ version = "0.1.9"
8
8
  license = { file = "LICENSE" }
9
9
  readme = "README.md"
10
10
  description = "Sample from weather data for renewable energy prediction"
@@ -1,5 +1,5 @@
1
1
  """ Helper functions for refactoring legacy site data """
2
-
2
+ import xarray as xr
3
3
 
4
4
  def legacy_format(data_ds, metadata_df):
5
5
  """This formats old legacy data to the new format.
@@ -9,7 +9,8 @@ import numpy as np
9
9
  from pathlib import Path
10
10
  from ocf_data_sampler.sample.base import (
11
11
  SampleBase,
12
- batch_to_tensor
12
+ batch_to_tensor,
13
+ copy_batch_to_device
13
14
  )
14
15
 
15
16
  class TestSample(SampleBase):
@@ -145,3 +146,19 @@ def test_batch_to_tensor_multidimensional():
145
146
  assert tensor_batch['matrix'].shape == (2, 2)
146
147
  assert tensor_batch['tensor'].shape == (2, 2, 2)
147
148
  assert torch.equal(tensor_batch['matrix'], torch.tensor([[1, 2], [3, 4]]))
149
+
150
+
151
+ def test_copy_batch_to_device():
152
+ """ Test moving tensors to a different device """
153
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
154
+ batch = {
155
+ 'tensor_data': torch.tensor([1, 2, 3]),
156
+ 'nested': {
157
+ 'matrix': torch.tensor([[1, 2], [3, 4]])
158
+ },
159
+ 'non_tensor': 'unchanged'
160
+ }
161
+ moved_batch = copy_batch_to_device(batch, device)
162
+ assert moved_batch['tensor_data'].device == device
163
+ assert moved_batch['nested']['matrix'].device == device
164
+ assert moved_batch['non_tensor'] == 'unchanged' # Non-tensors should remain unchanged