|
8 | 8 |
|
9 | 9 | from nose.tools import assert_equals, assert_almost_equals |
10 | 10 | from pandas.util.testing import assert_series_equal, assert_frame_equal |
| 11 | +from numpy.testing import assert_allclose |
11 | 12 |
|
12 | 13 | from pvlib import tmy |
13 | 14 | from pvlib import pvsystem |
|
17 | 18 | from pvlib import solarposition |
18 | 19 | from pvlib.location import Location |
19 | 20 |
|
| 21 | +from . import needs_numpy_1_10 |
| 22 | + |
20 | 23 | latitude = 32.2 |
21 | 24 | longitude = -111 |
22 | 25 | tus = Location(latitude, longitude, 'US/Arizona', 700, 'Tucson') |
@@ -524,3 +527,108 @@ def test_LocalizedPVSystem___repr__(): |
524 | 527 | assert localized_system.__repr__()==('LocalizedPVSystem with tilt:0 and'+ |
525 | 528 | ' azimuth: 180 with Module: blah and Inverter: blarg at Latitude: 32 ' + |
526 | 529 | 'and Longitude: -111') |
| 530 | + |
| 531 | + |
| 532 | +def test_pvwatts_dc_scalars(): |
| 533 | + expected = 88.65 |
| 534 | + out = pvsystem.pvwatts_dc(900, 30, 100, -0.003) |
| 535 | + assert_allclose(expected, out) |
| 536 | + |
| 537 | + |
| 538 | +@needs_numpy_1_10 |
| 539 | +def test_pvwatts_dc_arrays(): |
| 540 | + irrad_trans = np.array([np.nan, 900, 900]) |
| 541 | + temp_cell = np.array([30, np.nan, 30]) |
| 542 | + irrad_trans, temp_cell = np.meshgrid(irrad_trans, temp_cell) |
| 543 | + expected = np.array([[ nan, 88.65, 88.65], |
| 544 | + [ nan, nan, nan], |
| 545 | + [ nan, 88.65, 88.65]]) |
| 546 | + out = pvsystem.pvwatts_dc(irrad_trans, temp_cell, 100, -0.003) |
| 547 | + assert_allclose(expected, out, equal_nan=True) |
| 548 | + |
| 549 | + |
| 550 | +def test_pvwatts_dc_series(): |
| 551 | + irrad_trans = pd.Series([np.nan, 900, 900]) |
| 552 | + temp_cell = pd.Series([30, np.nan, 30]) |
| 553 | + expected = pd.Series(np.array([ nan, nan, 88.65])) |
| 554 | + out = pvsystem.pvwatts_dc(irrad_trans, temp_cell, 100, -0.003) |
| 555 | + assert_series_equal(expected, out) |
| 556 | + |
| 557 | + |
| 558 | +def test_pvwatts_ac_scalars(): |
| 559 | + expected = 85.58556604752516 |
| 560 | + out = pvsystem.pvwatts_ac(90, 100, 0.95) |
| 561 | + assert_allclose(expected, out) |
| 562 | + |
| 563 | + |
| 564 | +@needs_numpy_1_10 |
| 565 | +def test_pvwatts_ac_arrays(): |
| 566 | + pdc = np.array([[np.nan], [50], [100]]) |
| 567 | + pdc0 = 100 |
| 568 | + expected = np.array([[ nan], |
| 569 | + [ 47.60843624], |
| 570 | + [ 95. ]]) |
| 571 | + out = pvsystem.pvwatts_ac(pdc, pdc0, 0.95) |
| 572 | + assert_allclose(expected, out, equal_nan=True) |
| 573 | + |
| 574 | + |
| 575 | +def test_pvwatts_ac_series(): |
| 576 | + pdc = pd.Series([np.nan, 50, 100]) |
| 577 | + pdc0 = 100 |
| 578 | + expected = pd.Series(np.array([ nan, 47.608436, 95. ])) |
| 579 | + out = pvsystem.pvwatts_ac(pdc, pdc0, 0.95) |
| 580 | + assert_series_equal(expected, out) |
| 581 | + |
| 582 | + |
| 583 | +def test_pvwatts_losses_default(): |
| 584 | + expected = 14.075660688264469 |
| 585 | + out = pvsystem.pvwatts_losses() |
| 586 | + assert_allclose(expected, out) |
| 587 | + |
| 588 | + |
| 589 | +@needs_numpy_1_10 |
| 590 | +def test_pvwatts_losses_arrays(): |
| 591 | + expected = np.array([nan, 14.934904]) |
| 592 | + age = np.array([nan, 1]) |
| 593 | + out = pvsystem.pvwatts_losses(age=age) |
| 594 | + assert_allclose(expected, out) |
| 595 | + |
| 596 | + |
| 597 | +def test_pvwatts_losses_series(): |
| 598 | + expected = pd.Series([nan, 14.934904]) |
| 599 | + age = pd.Series([nan, 1]) |
| 600 | + out = pvsystem.pvwatts_losses(age=age) |
| 601 | + assert_series_equal(expected, out) |
| 602 | + |
| 603 | + |
| 604 | +def make_pvwatts_system(): |
| 605 | + module_parameters = {'pdc0': 100, 'gamma_pdc': -0.003} |
| 606 | + inverter_parameters = {'eta_inv_nom': 0.95} |
| 607 | + system = pvsystem.PVSystem(module_parameters=module_parameters, |
| 608 | + inverter_parameters=inverter_parameters) |
| 609 | + return system |
| 610 | + |
| 611 | + |
| 612 | +def test_PVSystem_pvwatts_dc(): |
| 613 | + system = make_pvwatts_system() |
| 614 | + irrad_trans = pd.Series([np.nan, 900, 900]) |
| 615 | + temp_cell = pd.Series([30, np.nan, 30]) |
| 616 | + expected = pd.Series(np.array([ nan, nan, 88.65])) |
| 617 | + out = system.pvwatts_dc(irrad_trans, temp_cell) |
| 618 | + assert_series_equal(expected, out) |
| 619 | + |
| 620 | + |
| 621 | +def test_PVSystem_pvwatts_losses(): |
| 622 | + system = make_pvwatts_system() |
| 623 | + expected = pd.Series([nan, 14.934904]) |
| 624 | + age = pd.Series([nan, 1]) |
| 625 | + out = system.pvwatts_losses(age=age) |
| 626 | + assert_series_equal(expected, out) |
| 627 | + |
| 628 | + |
| 629 | +def test_PVSystem_pvwatts_ac(): |
| 630 | + system = make_pvwatts_system() |
| 631 | + pdc = pd.Series([np.nan, 50, 100]) |
| 632 | + expected = pd.Series(np.array([ nan, 47.608436, 95. ])) |
| 633 | + out = system.pvwatts_ac(pdc) |
| 634 | + assert_series_equal(expected, out) |
0 commit comments