Skip to content

Commit

Permalink
Remove double-negatives in SiteInfo
Browse files Browse the repository at this point in the history
Everything works the same, but now users will need to specify `wind=False` or `solar=False` in the initialization of `SiteInfo`, rather than modifying the data dictionary with `no_wind` or `no_solar`.
  • Loading branch information
camirmas committed Aug 22, 2023
1 parent d7a57d9 commit a0821c6
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 28 deletions.
6 changes: 3 additions & 3 deletions examples/CSP_PV_Battery_Analysis/simulation_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ def init_hybrid_plant(techs_in_sim: list, is_test: bool = False, ud_techs: dict
"lon": -116.7830,
"elev": 561,
"tz": 1,
"no_wind": True
}
}
solar_file = example_root + "02_weather_data/daggett_ca_34.865371_-116.783023_psmv3_60_tmy.csv"
prices_file = example_root + "03_cost_load_price_data/constant_norm_prices.csv"
desired_schedule_file = example_root + "03_cost_load_price_data/desired_schedule_normalized.csv"
Expand All @@ -98,7 +97,8 @@ def init_hybrid_plant(techs_in_sim: list, is_test: bool = False, ud_techs: dict
site = SiteInfo(site_data,
solar_resource_file=solar_file,
grid_resource_file=prices_file,
desired_schedule=desired_schedule
desired_schedule=desired_schedule,
wind=False
)

# Load in system costs
Expand Down
4 changes: 2 additions & 2 deletions examples/offshore-hybrid/wind-h2.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,14 @@ def setup_hopp(plant_config, turbine_config, wind_resource, orbit_project, flori
hopp_site_input_data["lat"] = plant_config["project_location"]["lat"]
hopp_site_input_data["lon"] = plant_config["project_location"]["lon"]
hopp_site_input_data["year"] = plant_config["wind_resource_year"]
hopp_site_input_data["no_solar"] = not plant_config["project_parameters"]["solar"]
solar = plant_config["project_parameters"]["solar"]

# set desired schedule based on electrolyzer capacity
desired_schedule = [plant_config["electrolyzer"]["rating"]]*8760
desired_schedule = []

# generate HOPP SiteInfo class instance
hopp_site = SiteInfo(hopp_site_input_data, hub_height=turbine_config["hub_height"], desired_schedule=desired_schedule)
hopp_site = SiteInfo(hopp_site_input_data, hub_height=turbine_config["hub_height"], desired_schedule=desired_schedule, solar=solar)

# replace wind data with previously downloaded and adjusted wind data
hopp_site.wind_resource = wind_resource
Expand Down
6 changes: 4 additions & 2 deletions hopp/eco/hopp_mgmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def setup_hopp(
hopp_site_input_data["lat"] = plant_config["project_location"]["lat"]
hopp_site_input_data["lon"] = plant_config["project_location"]["lon"]
hopp_site_input_data["year"] = plant_config["wind_resource_year"]
hopp_site_input_data["no_wind"] = not plant_config["project_parameters"]["wind"]
hopp_site_input_data["no_solar"] = not plant_config["project_parameters"]["solar"]
wind = plant_config["project_parameters"]["wind"]
solar = plant_config["project_parameters"]["solar"]

# set desired schedule based on electrolyzer capacity
desired_schedule = [plant_config["electrolyzer"]["rating"]] * 8760
Expand All @@ -33,6 +33,8 @@ def setup_hopp(
hopp_site_input_data,
hub_height=turbine_config["hub_height"],
desired_schedule=desired_schedule,
wind=wind,
solar=solar
)

# replace wind data with previously downloaded and adjusted wind data
Expand Down
18 changes: 7 additions & 11 deletions hopp/simulation/technologies/sites/site_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class SiteInfo(BaseClass):
hub_height: hopp_float_type = hopp_float_type(97.)
capacity_hours: NDArray = field(default=[], converter=converter(bool))
desired_schedule: NDArrayFloat = field(default=[], converter=converter())
solar: bool = True
wind: bool = True

# Set in post init hook
n_timesteps: int = field(init=False, default=None)
Expand Down Expand Up @@ -119,17 +121,11 @@ def __attrs_post_init__(self):
if 'tz' in data:
self.tz = data['tz']

if 'no_solar' not in data:
data['no_solar'] = False

if not data['no_solar']:
if self.solar:
self.solar_resource = SolarResource(data['lat'], data['lon'], data['year'], filepath=self.solar_resource_file)
self.n_timesteps = len(self.solar_resource.data['gh']) // 8760 * 8760

if 'no_wind' not in data:
data['no_wind'] = False

if not data['no_wind']:
if self.wind:
# TODO: allow hub height to be used as an optimization variable
self.wind_resource = WindResource(data['lat'], data['lon'], data['year'], wind_turbine_hub_ht=self.hub_height,
filepath=self.wind_resource_file)
Expand All @@ -151,11 +147,11 @@ def __attrs_post_init__(self):
self.follow_desired_schedule = len(self.desired_schedule) == self.n_timesteps
if len(self.desired_schedule) > 0 and len(self.desired_schedule) != self.n_timesteps:
raise ValueError('The provided desired schedule does not match length of the simulation horizon.')

# FIXME: this a hack
if 'no_wind' in data and data["no_wind"]:

if not self.wind:
logger.info("Set up SiteInfo with solar resource files: {}".format(self.solar_resource.filename))
elif 'no_solar' in data and data["no_solar"]:
elif not self.solar:
logger.info("Set up SiteInfo with wind resource files: {}".format(self.wind_resource.filename))
else:
logger.info(
Expand Down
5 changes: 2 additions & 3 deletions hopp/to_organize/hopp_tools_steel.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,10 @@ def set_site_info(hopp_dict, site_df, sample_site):
lon = float(lon)
sample_site['lat'] = lat
sample_site['lon'] = lon
sample_site['no_solar'] = False
# if solar_size_mw>0:
# sample_site['no_solar'] = False
# sample_site['solar'] = True
# else:
# sample_site['no_solar'] = True
# sample_site['solar'] = False

hopp_dict.add('Configuration', {'sample_site': sample_site})

Expand Down
6 changes: 3 additions & 3 deletions hopp/tools/dispatch/csp_pv_battery_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ def init_hybrid_plant():
"elev": 641,
"year": 2012,
"tz": -8,
"no_wind": True
}
}

root = "C:/Users/WHamilt2/Documents/Projects/HOPP/CSP_PV_battery_dispatch_plots/"
solar_file = root + "34.865371_-116.783023_psmv3_60_tmy.csv"
Expand All @@ -84,7 +83,8 @@ def init_hybrid_plant():
site = SiteInfo(site_data,
solar_resource_file=solar_file,
grid_resource_file=prices_file,
desired_schedule=desired_schedule
desired_schedule=desired_schedule,
wind=False
)

technologies = {'tower': {
Expand Down
1 change: 0 additions & 1 deletion hopp/tools/hopp_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def set_site_info(site_df, sample_site):
lon = float(lon)
sample_site['lat'] = lat
sample_site['lon'] = lon
sample_site['no_solar'] = False

return site_df, sample_site

Expand Down
2 changes: 1 addition & 1 deletion tests/hopp/hopp_tools_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def set_site_info(xl, turbine_model, site_location, sample_site):
lon = float(lon)
sample_site['lat'] = lat
sample_site['lon'] = lon
sample_site['no_solar'] = True
sample_site['solar'] = False

return site_df, sample_site

Expand Down
4 changes: 2 additions & 2 deletions tests/hopp/test_site_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ def test_site_init_improper_schedule():
def test_site_init_no_wind():
"""Should initialize without pulling wind data."""
data = copy.deepcopy(flatirons_site)
data["no_wind"] = True

site = SiteInfo(
data,
solar_resource_file=solar_resource_file,
wind_resource_file=wind_resource_file,
grid_resource_file=grid_resource_file,
wind=False
)

assert site.wind_resource is None
Expand All @@ -123,13 +123,13 @@ def test_site_init_no_wind():
def test_site_init_no_solar():
"""Should initialize without pulling wind data."""
data = copy.deepcopy(flatirons_site)
data["no_solar"] = True

site = SiteInfo(
data,
solar_resource_file=solar_resource_file,
wind_resource_file=wind_resource_file,
grid_resource_file=grid_resource_file,
solar=False
)

assert site.solar_resource is None
Expand Down

0 comments on commit a0821c6

Please sign in to comment.