|
12 | 12 | from pytz.exceptions import UnknownTimeZoneError
|
13 | 13 |
|
14 | 14 | import pvlib
|
| 15 | +from pvlib import location |
15 | 16 | from pvlib.location import Location, lookup_altitude
|
16 | 17 | from pvlib.solarposition import declination_spencer71
|
17 | 18 | from pvlib.solarposition import equation_of_time_spencer71
|
@@ -212,7 +213,7 @@ def test_get_clearsky_valueerror(times):
|
212 | 213 | def test_from_tmy_3():
|
213 | 214 | from pvlib.tests.iotools.test_tmy import TMY3_TESTFILE
|
214 | 215 | from pvlib.iotools import read_tmy3
|
215 |
| - data, meta = read_tmy3(TMY3_TESTFILE, map_variables=True) |
| 216 | + data, meta = read_tmy3(TMY3_TESTFILE) |
216 | 217 | loc = Location.from_tmy(meta, data)
|
217 | 218 | assert loc.name is not None
|
218 | 219 | assert loc.altitude != 0
|
@@ -328,21 +329,28 @@ def test_extra_kwargs():
|
328 | 329 | Location(32.2, -111, arbitrary_kwarg='value')
|
329 | 330 |
|
330 | 331 |
|
331 |
| -def test_lookup_altitude(): |
332 |
| - max_alt_error = 125 |
333 |
| - # location name, latitude, longitude, altitude |
334 |
| - test_locations = [ |
335 |
| - ('Tucson, USA', 32.2540, -110.9742, 724), |
336 |
| - ('Lusaka, Zambia', -15.3875, 28.3228, 1253), |
337 |
| - ('Tokio, Japan', 35.6762, 139.6503, 40), |
338 |
| - ('Canberra, Australia', -35.2802, 149.1310, 566), |
339 |
| - ('Bogota, Colombia', 4.7110, -74.0721, 2555), |
340 |
| - ('Dead Sea, West Bank', 31.525849, 35.449214, -415), |
341 |
| - ('New Delhi, India', 28.6139, 77.2090, 214), |
342 |
| - ('Null Island, Atlantic Ocean', 0, 0, 0), |
343 |
| - ] |
344 |
| - |
345 |
| - for name, lat, lon, expected_alt in test_locations: |
346 |
| - alt_found = lookup_altitude(lat, lon) |
347 |
| - assert abs(alt_found - expected_alt) < max_alt_error, \ |
348 |
| - f'Max error exceded for {name} - e: {expected_alt} f: {alt_found}' |
| 332 | +@pytest.mark.parametrize('lat,lon,expected_alt', [ |
| 333 | + pytest.param(32.2540, -110.9742, 724, id='Tucson, USA'), |
| 334 | + pytest.param(-15.3875, 28.3228, 1253, id='Lusaka, Zambia'), |
| 335 | + pytest.param(35.6762, 139.6503, 40, id='Tokyo, Japan'), |
| 336 | + pytest.param(-35.2802, 149.1310, 566, id='Canberra, Australia'), |
| 337 | + pytest.param(4.7110, -74.0721, 2555, id='Bogota, Colombia'), |
| 338 | + pytest.param(31.525849, 35.449214, -415, id='Dead Sea, West Bank'), |
| 339 | + pytest.param(28.6139, 77.2090, 214, id='New Delhi, India'), |
| 340 | + pytest.param(0, 0, 0, id='Null Island, Atlantic Ocean'), |
| 341 | +]) |
| 342 | +def test_lookup_altitude(lat, lon, expected_alt): |
| 343 | + alt_found = lookup_altitude(lat, lon) |
| 344 | + assert alt_found == pytest.approx(expected_alt, abs=125) |
| 345 | + |
| 346 | + |
| 347 | +def test_location_lookup_altitude(mocker): |
| 348 | + mocker.spy(location, 'lookup_altitude') |
| 349 | + tus = Location(32.2, -111, 'US/Arizona', 700, 'Tucson') |
| 350 | + location.lookup_altitude.assert_not_called() |
| 351 | + assert tus.altitude == 700 |
| 352 | + location.lookup_altitude.reset_mock() |
| 353 | + |
| 354 | + tus = Location(32.2, -111, 'US/Arizona') |
| 355 | + location.lookup_altitude.assert_called_once_with(32.2, -111) |
| 356 | + assert tus.altitude == location.lookup_altitude(32.2, -111) |
0 commit comments