Skip to content

Commit

Permalink
fix flicker heatmap indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
dguittet committed Aug 22, 2023
1 parent 881662f commit c70a2c8
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 40 deletions.
7 changes: 5 additions & 2 deletions hybrid/layout/pv_layout_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ def get_flicker_loss_multiplier(flicker_data: Tuple[float, np.ndarray, np.ndarra
(x_min, y_max),
(x_max, y_max),
(x_max, y_min)))
gridcell_width = x_coords[1] - x_coords[0]
gridcell_height = y_coords[1] - y_coords[0]

flicker_power = total_power
num_turbines = len(turbine_coords_x)
Expand All @@ -274,6 +276,7 @@ def get_flicker_loss_multiplier(flicker_data: Tuple[float, np.ndarray, np.ndarra
active_segments = map(active_area_translated.intersection, [row[2] for row in primary_strands])
for i, s in enumerate(active_segments):
if not s.is_empty:
# figure out the orientation of the modules, whether the module_distance is laid out by width or by height
length_per_module = primary_strands[0][1] / primary_strands[0][0]
module_distance = module_dimensions[np.argmin([abs(d - length_per_module) for d in module_dimensions])]

Expand All @@ -293,8 +296,8 @@ def get_flicker_loss_multiplier(flicker_data: Tuple[float, np.ndarray, np.ndarra
mods_dy_from_t = mods_y - t_y

# map from dist(module, turbine t) to dist(heatmap grid coordinate, turbine in flicker model)
x_coords_ind = ((mods_dx_from_t - x_min) / module_dimensions[0]).round().astype(int)
y_coords_ind = ((mods_dy_from_t - y_min) / module_dimensions[1]).round().astype(int)
x_coords_ind = ((mods_dx_from_t - x_min) / gridcell_width).round().astype(int)
y_coords_ind = ((mods_dy_from_t - y_min) / gridcell_height).round().astype(int)
flicker_val = heatmap[y_coords_ind, x_coords_ind]
flicker_power -= sum(flicker_val)

Expand Down
56 changes: 28 additions & 28 deletions tests/analysis/test_custom_financial.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ def test_detailed_pv(site):

def test_hybrid_simple_pv_with_wind(site):
# Run wind + simple PV (pvwattsv8) hybrid plant with custom financial model
annual_energy_expected_pv = 98821626
annual_energy_expected_wind = 33637984
annual_energy_expected_hybrid = 132459610
npv_expected_pv = -39911660
npv_expected_wind = -11786833
npv_expected_hybrid = -51698493
annual_energy_expected_pv = 98653103
annual_energy_expected_wind = 33584937
annual_energy_expected_hybrid = 132238041
npv_expected_pv = -39925445
npv_expected_wind = -11791174
npv_expected_hybrid = -51716620

interconnect_kw = 150e6
pv_kw = 50000
Expand Down Expand Up @@ -194,12 +194,12 @@ def test_hybrid_simple_pv_with_wind(site):

def test_hybrid_detailed_pv_with_wind(site):
# Test wind + detailed PV (pvsamv1) hybrid plant with custom financial model
annual_energy_expected_pv = 21500708
annual_energy_expected_wind = 33637984
annual_energy_expected_hybrid = 55138692
npv_expected_pv = -7840663
npv_expected_wind = -11786833
npv_expected_hybrid = -19627496
annual_energy_expected_pv = 21452080
annual_energy_expected_wind = 33433774
annual_energy_expected_hybrid = 54885854
npv_expected_pv = -7844643
npv_expected_wind = -11803547
npv_expected_hybrid = -19648190

interconnect_kw = 150e6
wind_kw = 10000
Expand Down Expand Up @@ -276,14 +276,14 @@ def test_hybrid_detailed_pv_with_wind(site):

def test_hybrid_simple_pv_with_wind_storage_dispatch(site):
# Test wind + simple PV (pvwattsv8) + storage with dispatch hybrid plant with custom financial model
annual_energy_expected_pv = 9882421
annual_energy_expected_wind = 33637983
annual_energy_expected_battery = -31287
annual_energy_expected_hybrid = 43489117
npv_expected_pv = -1898253
npv_expected_wind = -4664335
npv_expected_battery = -8163435
npv_expected_hybrid = -14726773
annual_energy_expected_pv = 9857584
annual_energy_expected_wind = 33074859
annual_energy_expected_battery = -31253
annual_energy_expected_hybrid = 42901190
npv_expected_pv = -1905544
npv_expected_wind = -4829660
npv_expected_battery = -8164187
npv_expected_hybrid = -14899381

interconnect_kw = 15000
pv_kw = 5000
Expand Down Expand Up @@ -346,14 +346,14 @@ def test_hybrid_simple_pv_with_wind_storage_dispatch(site):

def test_hybrid_detailed_pv_with_wind_storage_dispatch(site):
# Test wind + detailed PV (pvsamv1) + storage with dispatch hybrid plant with custom financial model
annual_energy_expected_pv = 20413333
annual_energy_expected_wind = 33637984
annual_energy_expected_battery = -30147
annual_energy_expected_hybrid = 54020819
npv_expected_pv = -3607348
npv_expected_wind = -4664335
npv_expected_battery = -8163128
npv_expected_hybrid = -16435636
annual_energy_expected_pv = 20365655
annual_energy_expected_wind = 33462743
annual_energy_expected_battery = -29994
annual_energy_expected_hybrid = 53798060
npv_expected_pv = -3621345
npv_expected_wind = -4715783
npv_expected_battery = -8163817
npv_expected_hybrid = -16501035

interconnect_kw = 15000
wind_kw = 10000
Expand Down
4 changes: 2 additions & 2 deletions tests/hybrid/test_hybrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,9 +891,9 @@ def reinstate_orig_values():

npvs = hybrid_plant.net_present_values
assert npvs.pv == approx(-565098, rel=5e-2)
assert npvs.wind == approx(-1992106, rel=5e-2)
assert npvs.wind == approx(-2232003, rel=5e-2)
assert npvs.battery == approx(-4773045, rel=5e-2)
assert npvs.hybrid == approx(-5849767, rel=5e-2)
assert npvs.hybrid == approx(-6143329, rel=5e-2)

taxes = hybrid_plant.federal_taxes
assert taxes.pv[1] == approx(86826, rel=5e-2)
Expand Down
16 changes: 8 additions & 8 deletions tests/hybrid/test_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ def test_wind_layout(site):
wind_model = WindPlant(site, technology['wind'])
xcoords, ycoords = wind_model._layout.turb_pos_x, wind_model._layout.turb_pos_y

expected_xcoords = [0.7510, 1004.83, 1470.38, 903.06, 658.182]
expected_ycoords = [888.865, 1084.148, 929.881, 266.4096, 647.169]
expected_xcoords = [1498, 867, 525, 3, 658]
expected_ycoords = [951, 265, 74, 288, 647]

for i in range(len(xcoords)):
assert xcoords[i] == pytest.approx(expected_xcoords[i], 1e-3)
assert ycoords[i] == pytest.approx(expected_ycoords[i], 1e-3)
assert xcoords[i] == pytest.approx(expected_xcoords[i], abs=1)
assert ycoords[i] == pytest.approx(expected_ycoords[i], abs=1)

# wind_model.plot()
# plt.show()
Expand Down Expand Up @@ -179,13 +179,13 @@ def test_hybrid_layout_wind_only(site):

print(xcoords, ycoords)

expected_xcoords = [0.751, 1004.834, 1470.385, 903.063, 658.181]
expected_ycoords = [888.865, 1084.148, 929.881, 266.409, 647.169]
expected_xcoords = [1498, 867, 525, 3, 658]
expected_ycoords = [951, 265, 74, 288, 647]

# turbines move from `test_wind_layout` due to the solar exclusion
for i in range(len(xcoords)):
assert xcoords[i] == pytest.approx(expected_xcoords[i], 1e-3)
assert ycoords[i] == pytest.approx(expected_ycoords[i], 1e-3)
assert xcoords[i] == pytest.approx(expected_xcoords[i], abs=1)
assert ycoords[i] == pytest.approx(expected_ycoords[i], abs=1)


def test_hybrid_layout_solar_only(site):
Expand Down

0 comments on commit c70a2c8

Please sign in to comment.