Skip to content

Commit

Permalink
update with pv station distance returned from pvwatts
Browse files Browse the repository at this point in the history
  • Loading branch information
adfarth committed Sep 22, 2023
1 parent 0a70cbc commit 54841cc
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/core/production_factor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions src/core/reopt_inputs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/core/scenario.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/core/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"))
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/test_with_xpress.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 54841cc

Please sign in to comment.