Skip to content

Commit 1c95743

Browse files
committed
NSRDB parallel API calls :)
1 parent 268e57b commit 1c95743

File tree

3 files changed

+1455
-114
lines changed

3 files changed

+1455
-114
lines changed

pvdeg/store.py

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import zarr
77
import os
88

9-
from pvdeg.weather import pvgis_hourly_empty_weather_ds
10-
119
from pvdeg import METOROLOGICAL_DOWNLOAD_PATH
1210

1311
def get(group):

pvdeg/weather.py

+26-56
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,13 @@ def _weather_distributed_vec(
10341034
return weather_ds, meta_dict, None
10351035

10361036

1037-
def emtpy_weather_ds(gids_size, periodicity, database):
1037+
# THE NSRDB shapes could be moved to their own definition
1038+
# organization style question?
1039+
def emtpy_weather_ds(
1040+
gids_size,
1041+
periodicity,
1042+
database
1043+
)->xr.Dataset:
10381044
"""
10391045
Create an empty weather dataframe for generalized input.
10401046
@@ -1060,8 +1066,7 @@ def emtpy_weather_ds(gids_size, periodicity, database):
10601066

10611067
import dask.array as da
10621068

1063-
# pvgis default shapes
1064-
shapes = {
1069+
pvgis_shapes = {
10651070
"temp_air": ("gid", "time"),
10661071
"relative_humidity": ("gid", "time"),
10671072
"ghi": ("gid", "time"),
@@ -1073,15 +1078,22 @@ def emtpy_weather_ds(gids_size, periodicity, database):
10731078
"pressure": ("gid", "time"),
10741079
}
10751080

1076-
# additional results from NSRDB
1077-
nsrdb_extra_shapes = {
1081+
nsrdb_shapes = {
10781082
'Year': ("gid", "time"),
10791083
'Month': ("gid", "time"),
10801084
'Day': ("gid", "time"),
10811085
'Hour': ("gid", "time"),
10821086
'Minute': ("gid", "time"),
1087+
'temp_air':("gid", "time"),
10831088
'dew_point': ("gid", "time"),
1084-
'albedo': ("gid", "time")
1089+
'dhi': ("gid", "time"),
1090+
'dni': ("gid", "time"),
1091+
'ghi': ("gid", "time"),
1092+
'albedo': ("gid", "time"),
1093+
'pressure': ("gid", "time"),
1094+
'wind_direction': ("gid", "time"),
1095+
'wind_speed' : ("gid", "time"),
1096+
'relative_humidity': ("gid", "time"),
10851097
}
10861098

10871099
attrs = {}
@@ -1091,63 +1103,20 @@ def emtpy_weather_ds(gids_size, periodicity, database):
10911103
dims_size = {'time': TIME_PERIODICITY_MAP[periodicity], 'gid': gids_size}
10921104

10931105
if database == "NSRDB" or database == "PSM3":
1094-
shapes = shapes | nsrdb_extra_shapes
1095-
1096-
weather_ds = xr.Dataset(
1097-
data_vars={
1098-
var: (dim, da.empty([dims_size[d] for d in dim]), attrs.get(var))
1099-
for var, dim in shapes.items()
1100-
},
1101-
coords={'time': pd.date_range("2022-01-01", freq=periodicity, periods=TIME_PERIODICITY_MAP[periodicity]),
1102-
'gid': np.linspace(0, gids_size-1, gids_size, dtype=int)},
1103-
attrs=global_attrs,
1104-
)
1105-
1106-
return weather_ds
1107-
1108-
1109-
1110-
def pvgis_hourly_empty_weather_ds(gids_size):
1111-
"""
1112-
Create an empty weather dataset for pvgis hourly TMY data
1113-
1114-
Parameters
1115-
----------
1116-
gids_size: int
1117-
number of gids, equivalent to number of unique locations
1118-
1119-
Returns
1120-
-------
1121-
weather_ds: xarray.Dataset
1122-
Weather dataset of the same format/shapes given by a `pvdeg.weather.get` geospatial call or `pvdeg.weather.weather_distributed` call or `GeosptialScenario.get_geospatial_data`.
1123-
"""
1124-
import dask.array as da
1125-
1126-
1127-
1128-
shapes = {
1129-
"temp_air": ("gid", "time"),
1130-
"relative_humidity": ("gid", "time"),
1131-
"ghi": ("gid", "time"),
1132-
"dni": ("gid", "time"),
1133-
"dhi": ("gid", "time"),
1134-
"IR(h)": ("gid", "time"),
1135-
"wind_speed": ("gid", "time"),
1136-
"wind_direction": ("gid", "time"),
1137-
"pressure": ("gid", "time"),
1138-
}
1139-
attrs = {}
1140-
global_attrs = {}
1106+
# shapes = shapes | nsrdb_extra_shapes
1107+
shapes = nsrdb_shapes
1108+
elif database == "PVGIS":
1109+
shapes = pvgis_shapes
1110+
else:
1111+
raise ValueError(f"database must be PVGIS, NSRDB, PSM3 not {database}")
11411112

1142-
dims = {'gid', 'time'}
1143-
dims_size = {'time': 8760, 'gid': gids_size}
11441113

11451114
weather_ds = xr.Dataset(
11461115
data_vars={
11471116
var: (dim, da.empty([dims_size[d] for d in dim]), attrs.get(var))
11481117
for var, dim in shapes.items()
11491118
},
1150-
coords={'time': pd.date_range("2022-01-01", freq="h", periods=365 * 24),
1119+
coords={'time': pd.date_range("2022-01-01", freq=periodicity, periods=TIME_PERIODICITY_MAP[periodicity]),
11511120
'gid': np.linspace(0, gids_size-1, gids_size, dtype=int)},
11521121
attrs=global_attrs,
11531122
)
@@ -1162,6 +1131,7 @@ def pvgis_hourly_empty_weather_ds(gids_size):
11621131

11631132
# TODO: implement rate throttling so we do not make too many requests.
11641133
# TODO: multiple API keys to get around NSRDB key rate limit. 2 key, email pairs means twice the speed ;)
1134+
# TODO: this overwrites NSRDB GIDS when database == "PSM3"
11651135
def weather_distributed(
11661136
database: str,
11671137
coords: list[tuple],

0 commit comments

Comments
 (0)