Skip to content

Commit 34fa0bb

Browse files
authored
Add direct irradiance to VARIABLE_MAP in get_era5 iotools function (#2819)
* Add dni to VARIABLE_MAP in get_era5 iotools function * Add dni to example variable in doc * Convert dni from J to W * Change dni to bhi * Update v0.16.0.rst * Update test_era5.py * Fix linter
1 parent 83bc4e7 commit 34fa0bb

3 files changed

Lines changed: 18 additions & 5 deletions

File tree

docs/sphinx/source/whatsnew/v0.16.0.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ Bug fixes
2525

2626
Enhancements
2727
~~~~~~~~~~~~
28-
28+
* Map beam horizontal irradiance to ``bhi`` when
29+
:py:func:`~pvlib.iotools.get_era5` is called with ``map_variables=True``.
30+
(:pull:`2819`)
2931

3032
Documentation
3133
~~~~~~~~~~~~~

pvlib/iotools/era5.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
't2m': 'temp_air',
1212
'sp': 'pressure',
1313
'ssrd': 'ghi',
14+
'fdir': 'bhi',
1415
'tp': 'precipitation',
1516
'strd': 'longwave_down',
1617

@@ -19,6 +20,7 @@
1920
'2m_temperature': 'temp_air',
2021
'surface_pressure': 'pressure',
2122
'surface_solar_radiation_downwards': 'ghi',
23+
'total_sky_direct_solar_radiation_at_surface': 'bhi',
2224
'total_precipitation': 'precipitation',
2325
'surface_thermal_radiation_downwards': 'longwave_down',
2426
}
@@ -52,6 +54,7 @@ def _m_to_cm(m):
5254
'skt': _k_to_c,
5355
'sp': _same,
5456
'ssrd': _j_to_w,
57+
'fdir': _j_to_w,
5558
'strd': _j_to_w,
5659
'tp': _m_to_cm,
5760
}
@@ -80,7 +83,7 @@ def get_era5(latitude, longitude, start, end, variables, api_key,
8083
Last day of the requested period. Assumed to be UTC if not localized.
8184
variables : list of str
8285
List of variable names to retrieve, for example
83-
``['ghi', 'temp_air']``. Both pvlib and ERA5 names can be used.
86+
``['ghi', 'bhi', 'temp_air']``. Both pvlib and ERA5 names can be used.
8487
See [1]_ for additional options.
8588
api_key : str
8689
ECMWF CDS API key.

tests/iotools/test_era5.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ def params():
1717
return {
1818
'latitude': 40.01, 'longitude': -80.01,
1919
'start': '2020-06-01', 'end': '2020-06-01',
20-
'variables': ['ghi', 'temp_air'],
20+
# Test a mix of pvlib and ERA5 variable names
21+
'variables': [
22+
'ghi', 'temp_air', 'total_sky_direct_solar_radiation_at_surface'],
2123
'api_key': api_key,
2224
}
2325

@@ -33,7 +35,11 @@ def expected():
3335
ghi = [153., 18.4, 0., 0., 0., 0., 0., 0., 0., 0., 0., 60., 229.5,
3436
427.8, 620.1, 785.5, 910.1, 984.2, 1005.9, 962.4, 844.1, 685.2,
3537
526.9, 331.4]
36-
df = pd.DataFrame({'temp_air': temp_air, 'ghi': ghi}, index=index)
38+
bhi = [102.6, 8.3, 0., 0., 0., 0., 0., 0., 0., 0., 0., 34.9, 167.8, 345.6,
39+
524.3, 679.5, 796.1, 866.1, 893.4, 841.7, 724., 539.6, 415.1,
40+
239.6]
41+
df = pd.DataFrame({'temp_air': temp_air, 'ghi': ghi, 'bhi': bhi},
42+
index=index)
3743
return df
3844

3945

@@ -66,9 +72,11 @@ def test_get_era5_timezone(params, expected):
6672
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
6773
def test_get_era5_map_variables(params, expected):
6874
df, meta = pvlib.iotools.get_era5(**params, map_variables=False)
69-
expected = expected.rename(columns={'temp_air': 't2m', 'ghi': 'ssrd'})
75+
expected = expected.rename(columns={
76+
'temp_air': 't2m', 'ghi': 'ssrd', "bhi": "fdir"})
7077
df['t2m'] -= 273.15 # apply unit conversions manually
7178
df['ssrd'] /= 3600
79+
df['fdir'] /= 3600
7280
pd.testing.assert_frame_equal(df, expected, check_freq=False, atol=0.1)
7381
assert meta['longitude'] == -80.0
7482
assert meta['latitude'] == 40.0

0 commit comments

Comments
 (0)