From 435918af0bccb7366c61d401025bbf4989f0f348 Mon Sep 17 00:00:00 2001 From: adfarth Date: Fri, 22 Sep 2023 12:00:55 -0700 Subject: [PATCH] update with pv station distance returned from pvwatts --- src/core/production_factor.jl | 4 ++-- src/core/reopt_inputs.jl | 8 ++++---- src/core/scenario.jl | 4 ++-- src/core/utils.jl | 4 +++- test/test_with_xpress.jl | 2 +- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/core/production_factor.jl b/src/core/production_factor.jl index 4fd4ce81a..22396e0e7 100644 --- a/src/core/production_factor.jl +++ b/src/core/production_factor.jl @@ -7,12 +7,12 @@ function get_production_factor(pv::PV, latitude::Real, longitude::Real; timefram return pv.production_factor_series end - watts, ambient_temp_celcius = call_pvwatts_api(latitude, longitude; tilt=pv.tilt, azimuth=pv.azimuth, module_type=pv.module_type, + watts, ambient_temp_celcius, pv_station_distance_km = call_pvwatts_api(latitude, longitude; tilt=pv.tilt, azimuth=pv.azimuth, module_type=pv.module_type, array_type=pv.array_type, losses=round(pv.losses*100, digits=3), dc_ac_ratio=pv.dc_ac_ratio, gcr=pv.gcr, inv_eff=pv.inv_eff*100, timeframe=timeframe, radius=pv.radius, time_steps_per_hour=time_steps_per_hour) - return watts + return watts, pv_station_distance_km end diff --git a/src/core/reopt_inputs.jl b/src/core/reopt_inputs.jl index 55e50ce4a..b7243d2ac 100644 --- a/src/core/reopt_inputs.jl +++ b/src/core/reopt_inputs.jl @@ -151,7 +151,7 @@ function REoptInputs(s::AbstractScenario) time_steps = 1:length(s.electric_load.loads_kw) hours_per_time_step = 1 / s.settings.time_steps_per_hour - techs, pv_to_location, maxsize_pv_locations, pvlocations, + techs, pv_to_location, maxsize_pv_locations, pvlocations, production_factor, max_sizes, min_sizes, existing_sizes, cap_cost_slope, om_cost_per_kw, n_segs_by_tech, seg_min_size, seg_max_size, seg_yint, techs_by_exportbin, export_bins_by_tech, boiler_efficiency, tech_renewable_energy_fraction, tech_emissions_factors_CO2, tech_emissions_factors_NOx, tech_emissions_factors_SO2, @@ -349,7 +349,7 @@ function setup_tech_inputs(s::AbstractScenario) setup_operating_reserve_fraction(s, techs_operating_reserve_req_fraction) end - return techs, pv_to_location, maxsize_pv_locations, pvlocations, + return techs, pv_to_location, maxsize_pv_locations, pvlocations, production_factor, max_sizes, min_sizes, existing_sizes, cap_cost_slope, om_cost_per_kw, n_segs_by_tech, seg_min_size, seg_max_size, seg_yint, techs_by_exportbin, export_bins_by_tech, boiler_efficiency, tech_renewable_energy_fraction, tech_emissions_factors_CO2, tech_emissions_factors_NOx, tech_emissions_factors_SO2, @@ -435,7 +435,7 @@ end function setup_pv_inputs(s::AbstractScenario, max_sizes, min_sizes, existing_sizes, cap_cost_slope, om_cost_per_kw, production_factor, - pvlocations, pv_to_location, maxsize_pv_locations, + pvlocations, pv_to_location, maxsize_pv_locations, segmented_techs, n_segs_by_tech, seg_min_size, seg_max_size, seg_yint, techs_by_exportbin, techs) @@ -444,7 +444,7 @@ function setup_pv_inputs(s::AbstractScenario, max_sizes, min_sizes, roof_max_kw, land_max_kw = 1.0e5, 1.0e5 for pv in s.pvs - production_factor[pv.name, :] = get_production_factor(pv, s.site.latitude, s.site.longitude; + production_factor[pv.name, :], pv_station_distance_km = get_production_factor(pv, s.site.latitude, s.site.longitude; time_steps_per_hour=s.settings.time_steps_per_hour) for location in pvlocations if pv.location == String(location) # Must convert symbol to string diff --git a/src/core/scenario.jl b/src/core/scenario.jl index 7b6db2f5d..9213be1ba 100644 --- a/src/core/scenario.jl +++ b/src/core/scenario.jl @@ -432,12 +432,12 @@ function Scenario(d::Dict; flex_hvac_from_json=false) # By assigning pv.production_factor_series here, it will skip the PVWatts call in get_production_factor(PV) call from reopt_input.jl if !isempty(pvs) for pv in pvs - pv.production_factor_series, ambient_temp_celcius = call_pvwatts_api(site.latitude, site.longitude; tilt=pv.tilt, azimuth=pv.azimuth, module_type=pv.module_type, + pv.production_factor_series, ambient_temp_celcius, pv_station_distance_km = call_pvwatts_api(site.latitude, site.longitude; tilt=pv.tilt, azimuth=pv.azimuth, module_type=pv.module_type, array_type=pv.array_type, losses=round(pv.losses*100, digits=3), dc_ac_ratio=pv.dc_ac_ratio, gcr=pv.gcr, inv_eff=pv.inv_eff*100, timeframe="hourly", radius=pv.radius, time_steps_per_hour=settings.time_steps_per_hour) end else - pv_prodfactor, ambient_temp_celcius = call_pvwatts_api(site.latitude, site.longitude; time_steps_per_hour=settings.time_steps_per_hour) + pv_prodfactor, ambient_temp_celcius, pv_station_distance_km = call_pvwatts_api(site.latitude, site.longitude; time_steps_per_hour=settings.time_steps_per_hour) end ambient_temp_degF = ambient_temp_celcius * 1.8 .+ 32.0 else diff --git a/src/core/utils.jl b/src/core/utils.jl index dfae17daf..e86c06f92 100644 --- a/src/core/utils.jl +++ b/src/core/utils.jl @@ -363,6 +363,7 @@ end This calls the PVWatts API and returns both: - PV production factor - Ambient outdoor air dry bulb temperature profile [Celcius] + - pv_station_distance_km """ function call_pvwatts_api(latitude::Real, longitude::Real; tilt=latitude, azimuth=180, module_type=0, array_type=1, losses=14, dc_ac_ratio=1.2, gcr=0.4, inv_eff=96, timeframe="hourly", radius=0, time_steps_per_hour=1) @@ -394,6 +395,7 @@ function call_pvwatts_api(latitude::Real, longitude::Real; tilt=latitude, azimut # Get both possible data of interest watts = collect(get(response["outputs"], "ac", []) / 1000) # scale to 1 kW system (* 1 kW / 1000 W) tamb_celcius = collect(get(response["outputs"], "tamb", [])) # Celcius + pv_station_distance_km = response["station_info"]["distance"] / 1000 # Distance between the input location and the climate station. (meters) # Validate outputs if length(watts) != 8760 throw(@error("PVWatts did not return a valid prodfactor. Got $watts")) @@ -407,7 +409,7 @@ function call_pvwatts_api(latitude::Real, longitude::Real; tilt=latitude, azimut watts = repeat(watts, inner=time_steps_per_hour) tamb_celcius = repeat(tamb_celcius, inner=time_steps_per_hour) end - return watts, tamb_celcius + return watts, tamb_celcius, pv_station_distance_km catch e throw(@error("Error occurred when calling PVWatts: $e")) end diff --git a/test/test_with_xpress.jl b/test/test_with_xpress.jl index 08d237c44..059f0e14f 100644 --- a/test/test_with_xpress.jl +++ b/test/test_with_xpress.jl @@ -228,7 +228,7 @@ end =# # Austin, TX -> existing_chiller and existing_boiler added with FlexibleHVAC - pf, tamb, dist, resourcename = REopt.call_pvwatts_api(30.2672, -97.7431); + pf, tamb, dist = REopt.call_pvwatts_api(30.2672, -97.7431); R = 0.00025 # K/kW C = 1e5 # kJ/K # the starting scenario has flat fuel and electricty costs