8000 defer ForecastModel network operations until necessary (#332) · adarga-Polytech/pvlib-python@e8bdd90 · GitHub
[go: up one dir, main page]

Skip to content

Commit e8bdd90

Browse files
authored
defer ForecastModel network operations until necessary (pvlib#332)
* dont connect to unidata unless its necessary * add note to whatsnew
1 parent 1d5650b commit e8bdd90

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

docs/sphinx/source/whatsnew/v0.4.5.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ Enhancements
2626

2727
* Added irradiance.dni method that determines DNI from GHI and DHI and corrects
2828
unreasonable DNI values during sunrise/sunset transitions
29+
* ForecastModel will now only connect to the Unidata server when necessary,
30+
rather than when the object is created. This supports offline work
31+
and speeds up analysis of previously downloaded data.
2932

3033

3134
Contributors

pvlib/forecast.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,16 @@ def __init__(self, model_type, model_name, set_type):
118118
self.model_type = model_type
119119
self.model_name = model_name
120120
self.set_type = set_type
121+
self.connected = False
122+
123+
def connect_to_catalog(self):
121124
self.catalog = TDSCatalog(self.catalog_url)
122-
self.fm_models = TDSCatalog(self.catalog.catalog_refs[model_type].href)
125+
self.fm_models = TDSCatalog(
126+
self.catalog.catalog_refs[self.model_type].href)
123127
self.fm_models_list = sorted(list(self.fm_models.catalog_refs.keys()))
124128

125129
try:
126-
model_url = self.fm_models.catalog_refs[model_name].href
130+
model_url = self.fm_models.catalog_refs[self.model_name].href
127131
except ParseError:
128132
raise ParseError(self.model_name + ' model may be unavailable.')
129133

@@ -137,6 +141,7 @@ def __init__(self, model_type, model_name, set_type):
137141

138142
self.datasets_list = list(self.model.datasets.keys())
139143
self.set_dataset()
144+
self.connected = True
140145

141146
def __repr__(self):
142147
return '{}, {}'.format(self.model_name, self.set_type)
@@ -224,6 +229,10 @@ def get_data(self, latitude, longitude, start, end,
224229
forecast_data : DataFrame
225230
column names are the weather model's variable names.
226231
"""
232+
233+
if not self.connected:
234+
self.connect_to_catalog()
235+
227236
if vert_level is not None:
228237
self.vert_level = vert_level
229238

0 commit comments

Comments
 (0)
0