Skip to content

Commit d428212

Browse files
authored
Handle -99999 NaN for 6-character width fields in USCRN data (#775)
* handle -99999 for 6-character width fields * add whatsnew * link to pvlib issue
1 parent 47b5aef commit d428212

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed

docs/source/whatsnew/1.0.12.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.. _whatsnew_1012:
2+
3+
.. py:currentmodule:: solarforecastarbiter
4+
5+
6+
1.0.12 (January ??, 2022)
7+
--------------------------
8+
9+
Fixed
10+
~~~~~~~~~~~~
11+
* Fixed USCRN data fetch to handle NaN values of -99999. (:pull:`775`, :issue:`773`)
12+
13+
Contributors
14+
~~~~~~~~~~~~
15+
16+
* Will Holmgren (:ghuser:`wholmgren`)
17+
* Leland Boeman (:ghuser:`lboeman`)

docs/source/whatsnew/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ These are new features and improvements of note in each release.
99
.. toctree::
1010
:maxdepth: 2
1111

12+
1.0.12
1213
1.0.11
1314
1.0.10
1415
1.0.9

solarforecastarbiter/io/reference_observations/crn.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from urllib.error import URLError
33

44

5+
import numpy as np
56
import pandas as pd
67
from pvlib import iotools
78

@@ -72,6 +73,11 @@ def fetch(api, site, start, end):
7273
return pd.DataFrame()
7374
all_period_data = all_period_data.rename(
7475
columns={'temp_air': 'air_temperature'})
76+
77+
# Remove possible nans with value -99999. This can be removed
78+
# if pvlib is updated to account for these values.
79+
# See pvlib issue: https://github.com/pvlib/pvlib-python/issues/1372
80+
all_period_data = all_period_data.replace(-99999, np.nan)
7581
return all_period_data
7682

7783

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import pandas as pd
2+
3+
from solarforecastarbiter.io.reference_observations import crn
4+
from solarforecastarbiter.datamodel import Site
5+
6+
7+
test_site_dict = {
8+
"extra_parameters": '{"network": "NOAA USCRN", "network_api_id": "NY_Millbrook_3_W", "network_api_abbreviation": "NY_Millbrook_3_W", "observation_interval_length": 5}', # noqa: E501
9+
"climate_zones": [
10+
"Reference Region 5"
11+
],
12+
"created_at": "2019-05-24T17:31:44+00:00",
13+
"elevation": 126,
14+
"latitude": 41.78,
15+
"longitude": -73.74,
16+
"modified_at": "2020-09-15T18:22:05+00:00",
17+
"name": "NOAA USCRN Millbrook NY",
18+
"provider": "Reference",
19+
"site_id": "cc9f4180-7e49-11e9-b191-0a580a8003e9",
20+
"timezone": "America/New_York"
21+
}
22+
23+
test_site_object = Site.from_dict(test_site_dict)
24+
25+
26+
def test_fetch_fill_nan_99999(mocker):
27+
mocker.patch(
28+
'solarforecastarbiter.io.reference_observations.crn.iotools.read_crn',
29+
return_value=pd.DataFrame(
30+
data=[-99999],
31+
index=pd.DatetimeIndex(['20220101T0000Z']),
32+
columns=['ghi']
33+
)
34+
)
35+
result = crn.fetch(
36+
None,
37+
test_site_object,
38+
pd.Timestamp('20210101t0000z'),
39+
pd.Timestamp('20210101t0000z'),
40+
)
41+
assert pd.isna(result.iloc[0]['ghi'])

0 commit comments

Comments
 (0)