ocf-data-sampler 0.0.51__py3-none-any.whl → 0.0.53__py3-none-any.whl

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.

@@ -5,6 +5,7 @@ import numpy as np
5
5
  NWP_PROVIDERS = [
6
6
  "ukv",
7
7
  "ecmwf",
8
+ "gfs"
8
9
  ]
9
10
 
10
11
 
@@ -127,13 +128,60 @@ ECMWF_MEAN = {
127
128
  ECMWF_STD = _to_data_array(ECMWF_STD)
128
129
  ECMWF_MEAN = _to_data_array(ECMWF_MEAN)
129
130
 
131
+ # ------ GFS
132
+ GFS_STD = {
133
+ "dlwrf": 96.305916,
134
+ "dswrf": 246.18533,
135
+ "hcc": 42.525383,
136
+ "lcc": 44.3732,
137
+ "mcc": 43.150745,
138
+ "prate": 0.00010159573,
139
+ "r": 25.440672,
140
+ "sde": 0.43345627,
141
+ "t": 22.825893,
142
+ "tcc": 41.030598,
143
+ "u10": 5.470838,
144
+ "u100": 6.8899174,
145
+ "v10": 4.7401133,
146
+ "v100": 6.076132,
147
+ "vis": 8294.022,
148
+ "u": 10.614556,
149
+ "v": 7.176398,
150
+ }
151
+
152
+ GFS_MEAN = {
153
+ "dlwrf": 298.342,
154
+ "dswrf": 168.12321,
155
+ "hcc": 35.272,
156
+ "lcc": 43.578342,
157
+ "mcc": 33.738823,
158
+ "prate": 2.8190969e-05,
159
+ "r": 18.359747,
160
+ "sde": 0.36937004,
161
+ "t": 278.5223,
162
+ "tcc": 66.841606,
163
+ "u10": -0.0022310058,
164
+ "u100": 0.0823025,
165
+ "v10": 0.06219831,
166
+ "v100": 0.0797807,
167
+ "vis": 19628.32,
168
+ "u": 11.645444,
169
+ "v": 0.12330122,
170
+ }
171
+
172
+ GFS_STD = _to_data_array(GFS_STD)
173
+ GFS_MEAN = _to_data_array(GFS_MEAN)
174
+
175
+
130
176
  NWP_STDS = NWPStatDict(
131
177
  ukv=UKV_STD,
132
178
  ecmwf=ECMWF_STD,
179
+ gfs=GFS_STD
133
180
  )
134
181
  NWP_MEANS = NWPStatDict(
135
182
  ukv=UKV_MEAN,
136
183
  ecmwf=ECMWF_MEAN,
184
+ gfs=GFS_MEAN
137
185
  )
138
186
 
139
187
  # ------ Satellite
@@ -40,4 +40,4 @@ def get_xr_data_array_from_xr_dataset(ds: xr.Dataset) -> xr.DataArray:
40
40
 
41
41
  datavars = list(ds.var())
42
42
  assert len(datavars) == 1, "Cannot open as xr.DataArray: dataset contains multiple variables"
43
- return ds[datavars[0]]
43
+ return ds[datavars[0]]
@@ -1,6 +1,6 @@
1
1
  """Torch dataset for sites"""
2
2
  import logging
3
-
3
+ import numpy as np
4
4
  import pandas as pd
5
5
  import xarray as xr
6
6
  from typing import Tuple
@@ -421,3 +421,27 @@ def convert_to_numpy_and_combine(
421
421
  combined_sample = fill_nans_in_arrays(combined_sample)
422
422
 
423
423
  return combined_sample
424
+
425
+
426
+ def coarsen_data(xr_data: xr.Dataset, coarsen_to_deg: float=0.1):
427
+ """
428
+ Coarsen the data to a specified resolution in degrees.
429
+
430
+ Args:
431
+ xr_data: xarray dataset to coarsen
432
+ coarsen_to_deg: resolution to coarsen to in degrees
433
+ """
434
+
435
+ if "latitude" in xr_data.coords and "longitude" in xr_data.coords:
436
+ step = np.abs(xr_data.latitude.values[1]-xr_data.latitude.values[0])
437
+ step = np.round(step,4)
438
+ coarsen_factor = int(coarsen_to_deg/step)
439
+ if coarsen_factor > 1:
440
+ xr_data = xr_data.coarsen(
441
+ latitude=coarsen_factor,
442
+ longitude=coarsen_factor,
443
+ boundary="pad",
444
+ coord_func="min"
445
+ ).mean()
446
+
447
+ return xr_data
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: ocf_data_sampler
3
- Version: 0.0.51
3
+ Version: 0.0.53
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-11-orange.svg?style=flat-square)](#contributors-)
59
+ [![All Contributors](https://img.shields.io/badge/all_contributors-12-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)
@@ -136,6 +136,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
136
136
  <td align="center" valign="top" width="14.28%"><a href="https://timothyajaniportfolio-b6v3zq29k-timthegreat.vercel.app/"><img src="https://avatars.githubusercontent.com/u/60073728?v=4?s=100" width="100px;" alt="Ajani Timothy"/><br /><sub><b>Ajani Timothy</b></sub></a><br /><a href="https://github.com/openclimatefix/ocf-data-sampler/commits?author=Tim1119" title="Code">💻</a></td>
137
137
  <td align="center" valign="top" width="14.28%"><a href="https://rupeshmangalam.vercel.app/"><img src="https://avatars.githubusercontent.com/u/91172425?v=4?s=100" width="100px;" alt="Rupesh Mangalam"/><br /><sub><b>Rupesh Mangalam</b></sub></a><br /><a href="https://github.com/openclimatefix/ocf-data-sampler/commits?author=RupeshMangalam21" title="Code">💻</a></td>
138
138
  <td align="center" valign="top" width="14.28%"><a href="http://siddharth7113.github.io"><img src="https://avatars.githubusercontent.com/u/114160268?v=4?s=100" width="100px;" alt="Siddharth"/><br /><sub><b>Siddharth</b></sub></a><br /><a href="https://github.com/openclimatefix/ocf-data-sampler/commits?author=siddharth7113" title="Code">💻</a></td>
139
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/Sachin-G13"><img src="https://avatars.githubusercontent.com/u/190184500?v=4?s=100" width="100px;" alt="Sachin-G13"/><br /><sub><b>Sachin-G13</b></sub></a><br /><a href="https://github.com/openclimatefix/ocf-data-sampler/commits?author=Sachin-G13" title="Code">💻</a></td>
139
140
  </tr>
140
141
  </tbody>
141
142
  </table>
@@ -1,5 +1,5 @@
1
1
  ocf_data_sampler/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
2
- ocf_data_sampler/constants.py,sha256=G2VfkE_-veq_0hNBQQOQCtCsfC37O5-QG9mJWEmln5s,4153
2
+ ocf_data_sampler/constants.py,sha256=S4-pkGdKj9HxQcMpI0iL90Ob_37Dloejn3c-niqdar0,5063
3
3
  ocf_data_sampler/utils.py,sha256=rKA0BHAyAG4f90zEcgxp25EEYrXS-aOVNzttZ6Mzv2k,250
4
4
  ocf_data_sampler/config/__init__.py,sha256=YXnAkgHViHB26hSsjiv32b6EbpG-A1kKTkARJf0_RkY,212
5
5
  ocf_data_sampler/config/load.py,sha256=4f7vPHAIAmd-55tPxoIzn7F_TI_ue4NxkDcLPoVWl0g,943
@@ -11,7 +11,7 @@ ocf_data_sampler/load/gsp.py,sha256=Gcr1JVUOPKhFRDCSHtfPDjxx0BtyyEhXrZvGEKLPJ5I,
11
11
  ocf_data_sampler/load/load_dataset.py,sha256=Ua3RaUg4PIYJkD9BKqTfN8IWUbezbhThJGgEkd9PcaE,1587
12
12
  ocf_data_sampler/load/satellite.py,sha256=3KlA1fx4SwxdzM-jC1WRaONXO0D6m0WxORnEnwUnZrA,2967
13
13
  ocf_data_sampler/load/site.py,sha256=P83uz01WBDzoZajdOH0m8FQt4-buKDlUk19N548KqhA,1086
14
- ocf_data_sampler/load/utils.py,sha256=EQGvVWlGMoSOdbDYuMfVAa0v6wmAOPmHIAemdrTB5v4,1406
14
+ ocf_data_sampler/load/utils.py,sha256=sAEkPMS9LXVCrc5pANQo97zaoEItVg9hoNj2ZWfx_Ug,1405
15
15
  ocf_data_sampler/load/nwp/__init__.py,sha256=SmcrnbygO5xtCKmGR4wtHrj-HI7nOAvnAtfuvRufBGQ,25
16
16
  ocf_data_sampler/load/nwp/nwp.py,sha256=O4QnajEZem8BvBgTcYYDBhRhgqPYuJkolHmpMRmrXEA,610
17
17
  ocf_data_sampler/load/nwp/providers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -38,7 +38,7 @@ ocf_data_sampler/select/spatial_slice_for_dataset.py,sha256=3tRrMBXr7s4CnClbVSIq
38
38
  ocf_data_sampler/select/time_slice_for_dataset.py,sha256=P7cAARfDzjttGDvpKt2zuA4WkLoTmSXy_lBpI8RiA6k,4249
39
39
  ocf_data_sampler/torch_datasets/datasets/__init__.py,sha256=nJUa2KzVa84ZoM0PT2AbDz26ennmAYc7M7WJVfypPMs,85
40
40
  ocf_data_sampler/torch_datasets/datasets/pvnet_uk_regional.py,sha256=xxeX4Js9LQpydehi3BS7k9psqkYGzgJuM17uTYux40M,8742
41
- ocf_data_sampler/torch_datasets/datasets/site.py,sha256=v7plMF_WJPkfwnJAUFf_8gXAy8SXE5Og_fgZMEm4c20,15257
41
+ ocf_data_sampler/torch_datasets/datasets/site.py,sha256=5T8nkTMUHHFidZRuFOunYeKAqNuyZ8V7sikBoBOBwwA,16033
42
42
  ocf_data_sampler/torch_datasets/utils/merge_and_fill_utils.py,sha256=hIbekql64eXsNDFIoEc--GWxwdVWrh2qKegdOi70Bow,874
43
43
  ocf_data_sampler/torch_datasets/utils/valid_time_periods.py,sha256=Qo65qUHtle_bW5tLTYr7empHTRv-lpjvfx_6GNJj3Xg,4371
44
44
  scripts/refactor_site.py,sha256=asZ27hQ4IyXgCCUaFJqcz1ObBNcV2W3ywqHBpSXA_fc,1728
@@ -65,9 +65,9 @@ tests/select/test_select_time_slice.py,sha256=nYrdlmZlGEygJKiE26bADiluNPN1qt5kD4
65
65
  tests/torch_datasets/conftest.py,sha256=eRCzHE7cxS4AoskExkCGFDBeqItktAYNAdkfpMoFCeE,629
66
66
  tests/torch_datasets/test_merge_and_fill_utils.py,sha256=ueA0A7gZaWEgNdsU8p3CnKuvSnlleTUjEhSw2HUUROM,1229
67
67
  tests/torch_datasets/test_pvnet_uk_regional.py,sha256=FCiFueeFqrsXe7gWguSjBz5ZeUrvyhGbGw81gaVvkHM,5087
68
- tests/torch_datasets/test_site.py,sha256=0gT_7k086BBnxqbvOayiUeI-vzJsYXlx3KvACC0c6lk,6114
69
- ocf_data_sampler-0.0.51.dist-info/LICENSE,sha256=F-Q3UFCR-BECSocV55BFDpn4YKxve9PKrm-lTt6o_Tg,1073
70
- ocf_data_sampler-0.0.51.dist-info/METADATA,sha256=fBrPrERCKjQRN6HWgInZA5aibFPQLTTC_c2Xs4u921w,11788
71
- ocf_data_sampler-0.0.51.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
72
- ocf_data_sampler-0.0.51.dist-info/top_level.txt,sha256=Faob6N6cFdPc5eUpCTYcXgCaNhi4XLLteUL5W5ayYmg,31
73
- ocf_data_sampler-0.0.51.dist-info/RECORD,,
68
+ tests/torch_datasets/test_site.py,sha256=J1ZDE5V5MRlq7EuZ1zUu-aFRGTDJIiO-ZZzkOXvDdWA,6757
69
+ ocf_data_sampler-0.0.53.dist-info/LICENSE,sha256=F-Q3UFCR-BECSocV55BFDpn4YKxve9PKrm-lTt6o_Tg,1073
70
+ ocf_data_sampler-0.0.53.dist-info/METADATA,sha256=KlR1y8ot0K5afAbA_0FzdY6SLVm378QYzQpiAhShI8Y,12143
71
+ ocf_data_sampler-0.0.53.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
72
+ ocf_data_sampler-0.0.53.dist-info/top_level.txt,sha256=Faob6N6cFdPc5eUpCTYcXgCaNhi4XLLteUL5W5ayYmg,31
73
+ ocf_data_sampler-0.0.53.dist-info/RECORD,,
@@ -1,7 +1,8 @@
1
1
  import pandas as pd
2
2
  import numpy as np
3
- from ocf_data_sampler.torch_datasets.datasets.site import SitesDataset, convert_from_dataset_to_dict_datasets
3
+ from ocf_data_sampler.torch_datasets.datasets.site import SitesDataset, convert_from_dataset_to_dict_datasets, coarsen_data
4
4
  from xarray import Dataset, DataArray
5
+ import xarray as xr
5
6
 
6
7
  from torch.utils.data import DataLoader
7
8
 
@@ -43,7 +44,6 @@ def test_site(site_config_filename):
43
44
 
44
45
  expected_data_vars = {"nwp-ukv", "satellite", "site"}
45
46
 
46
- import xarray as xr
47
47
 
48
48
  sample.to_netcdf("sample.nc")
49
49
  sample = xr.open_dataset("sample.nc")
@@ -198,3 +198,18 @@ def test_process_and_combine_site_sample_dict(site_config_filename):
198
198
  assert nwp_result.shape == (4, 1, 2, 2), f"Unexpected shape for nwp-ukv : {nwp_result.shape}"
199
199
  site_result = result["site"]
200
200
  assert site_result.shape == (197,), f"Unexpected shape for site: {site_result.shape}"
201
+
202
+
203
+ def test_potentially_coarsen(ds_nwp_ecmwf):
204
+ """Test potentially_coarsen function with ECMWF_UK data."""
205
+ nwp_data = ds_nwp_ecmwf
206
+ assert nwp_data.ECMWF_UK.shape[3:] == (15, 12) # Check initial shape (lon, lat)
207
+
208
+ data = coarsen_data(xr_data=nwp_data, coarsen_to_deg=2)
209
+ assert data.ECMWF_UK.shape[3:] == (8, 6) # Coarsen to every 2 degrees
210
+
211
+ data = coarsen_data(xr_data=nwp_data, coarsen_to_deg=3)
212
+ assert data.ECMWF_UK.shape[3:] == (5, 4) # Coarsen to every 3 degrees
213
+
214
+ data = coarsen_data(xr_data=nwp_data, coarsen_to_deg=1)
215
+ assert data.ECMWF_UK.shape[3:] == (15, 12) # No coarsening (same shape)