-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* start adding template for bsrn sites * fix ref site csv * add to api * add bsrn to ref obs page * update docs * mock out bsrn test * flake8
- Loading branch information
1 parent
8cdadb1
commit 69d7a5d
Showing
7 changed files
with
187 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import logging | ||
|
||
|
||
from solarforecastarbiter.io.reference_observations import ( | ||
common, default_forecasts) | ||
|
||
|
||
logger = logging.getLogger('reference_data') | ||
bsrn_variables = ('ghi', 'dni', 'dhi', 'air_temperature', 'relative_humidity') | ||
|
||
|
||
def initialize_site_observations(api, site): | ||
"""Creates an observation at the site for each variable in bsrn_variables. | ||
Parameters | ||
---------- | ||
site : datamodel.Site | ||
The site object for which to create Observations. | ||
""" | ||
for variable in bsrn_variables: | ||
common.create_observation(api, site, variable) | ||
|
||
|
||
def initialize_site_forecasts(api, site): | ||
""" | ||
Create forecasts for each variable in bsrn_variables at the site | ||
Parameters | ||
---------- | ||
api : solarforecastarbiter.io.api.APISession | ||
An active Reference user session. | ||
site : datamodel.Site | ||
The site object for which to create Forecasts. | ||
""" | ||
common.create_forecasts(api, site, bsrn_variables, | ||
default_forecasts.TEMPLATE_FORECASTS) | ||
|
||
|
||
def fetch(api, site, start, end): | ||
"""Retrieve observation data for a BSRN site between start and end. | ||
Parameters | ||
---------- | ||
api : io.APISession | ||
Unused but conforms to common.update_site_observations call | ||
site : datamodel.Site | ||
Site object with the appropriate metadata. | ||
start : datetime | ||
The beginning of the period to request data for. | ||
end : datetime | ||
The end of the period to request data for. | ||
Returns | ||
------- | ||
data : pandas.DataFrame | ||
All of the requested data concatenated into a single DataFrame. | ||
""" | ||
raise NotImplementedError('Fetching BSRN data not yet implemented') | ||
|
||
|
||
def update_observation_data(api, sites, observations, start, end): | ||
"""Post new observation data to all BSRN observations from | ||
start to end. | ||
Parameters | ||
---------- | ||
api : solarforecastarbiter.io.api.APISession | ||
An active Reference user session. | ||
sites: list | ||
List of all reference sites as Objects | ||
observations: list of solarforecastarbiter.datamodel.Observation | ||
List of all reference observations. | ||
start : datetime | ||
The beginning of the period to request data for. | ||
end : datetime | ||
The end of the period to request data for. | ||
""" | ||
bsrn_sites = common.filter_by_networks(sites, ['WRMC BSRN']) | ||
for site in bsrn_sites: | ||
common.update_site_observations( | ||
api, fetch, site, observations, start, end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
solarforecastarbiter/io/reference_observations/tests/test_ref_bsrn.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import pytest | ||
import re | ||
import pandas as pd | ||
|
||
from solarforecastarbiter.datamodel import Site | ||
from solarforecastarbiter.io import api | ||
from solarforecastarbiter.io.reference_observations import bsrn | ||
|
||
|
||
@pytest.fixture | ||
def session(requests_mock): | ||
return api.APISession('') | ||
|
||
|
||
@pytest.fixture | ||
def site(): | ||
return Site( | ||
name='WRMC BSRN NASA Langley Research Center', | ||
latitude=37.1048, | ||
longitude=-76.3872, | ||
elevation=3.0, | ||
timezone='Etc/GMT+5', | ||
site_id='', | ||
provider='', | ||
extra_parameters='{"network_api_id": "LRC", "attribution": "Driemel, A., Augustine, J., Behrens, K., Colle, S., Cox, C., Cuevas-Agull\\u00f3, E., Denn, F. M., Duprat, T., Fukuda, M., Grobe, H., Haeffelin, M., Hodges, G., Hyett, N., Ijima, O., Kallis, A., Knap, W., Kustov, V., Long, C. N., Longenecker, D., Lupi, A., Maturilli, M., Mimouni, M., Ntsangwane, L., Ogihara, H., Olano, X., Olefs, M., Omori, M., Passamani, L., Pereira, E. B., Schmith\\u00fcsen, H., Schumacher, S., Sieger, R., Tamlyn, J., Vogt, R., Vuilleumier, L., Xia, X., Ohmura, A., and K\\u00f6nig-Langlo, G.: Baseline Surface Radiation Network (BSRN): structure and data description (1992\\u20132017), Earth Syst. Sci. Data, 10, 1491-1501, doi:10.5194/essd-10-1491-2018, 2018.", "network": "WRMC BSRN", "network_api_abbreviation": "", "observation_interval_length": 1}', # noqa: E501 | ||
) | ||
|
||
|
||
@pytest.fixture() | ||
def mock_list_sites(mocker, many_sites): | ||
mocker.patch('solarforecastarbiter.io.api.APISession.list_sites', | ||
return_value=many_sites) | ||
|
||
|
||
def test_initialize_site_observations( | ||
requests_mock, mocker, session, site, single_observation, | ||
single_observation_text, mock_list_sites): | ||
matcher = re.compile(f'{session.base_url}/observations/.*') | ||
requests_mock.register_uri('POST', matcher, | ||
text=single_observation.observation_id) | ||
requests_mock.register_uri('GET', matcher, content=single_observation_text) | ||
status = mocker.patch( | ||
'solarforecastarbiter.io.api.APISession.create_observation') | ||
bsrn.initialize_site_observations(session, site) | ||
assert status.called | ||
|
||
|
||
def test_initialize_site_obs(mock_api, mocker, site): | ||
mocked = mocker.patch( | ||
'solarforecastarbiter.io.reference_observations.common.' | ||
'create_observation') | ||
|
||
bsrn.initialize_site_observations(mock_api, site) | ||
mocked.assert_called() | ||
|
||
|
||
def test_fetch(mocker, session, site): | ||
start = pd.Timestamp('2020-01-01T0000Z') | ||
end = pd.Timestamp('2020-01-02T0000Z') | ||
with pytest.raises(NotImplementedError): | ||
bsrn.fetch(session, site, start, end) | ||
|
||
|
||
def test_initialize_site_forecasts(mocker, session, site): | ||
mocked = mocker.patch( | ||
'solarforecastarbiter.io.reference_observations.common.' | ||
'create_forecasts') | ||
bsrn.initialize_site_forecasts(session, site) | ||
mocked.assert_called() | ||
|
||
|
||
def test_update_observation_data(mocker, session, site): | ||
obs_update = mocker.patch( | ||
'solarforecastarbiter.io.reference_observations.common.' | ||
'update_site_observations') | ||
start = pd.Timestamp('20200101T0000Z') | ||
end = pd.Timestamp('20200102T0000Z') | ||
bsrn.update_observation_data(session, [site], [], start, end) | ||
obs_update.assert_called() | ||
assert obs_update.call_count == 1 |