Skip to content

Commit

Permalink
autopep8
Browse files Browse the repository at this point in the history
  • Loading branch information
samgdotson committed Dec 23, 2024
1 parent de99762 commit f211f42
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 79 deletions.
38 changes: 22 additions & 16 deletions osier/models/logic_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

class LogicDispatchModel(OsierModel):

def __init__(self,
technology_list,
def __init__(self,
technology_list,
net_demand,
allow_blackout=False,
curtailment=True,
verbosity=50,
*args, **kwargs):
super().__init__(technology_list=technology_list,
super().__init__(technology_list=technology_list,
net_demand=net_demand,
*args, **kwargs)
self.technology_list = technology_list
Expand All @@ -28,7 +28,7 @@ def __init__(self,
self.covered_demand = None
self.objective = None
self.results = None
self.verbosity=verbosity
self.verbosity = verbosity
self.allow_blackout = allow_blackout
self.curtailment = curtailment

Expand All @@ -40,19 +40,24 @@ def _reset_all(self):
def _format_results(self):
data = {}
for t in self.technology_list:
data[f"{t.technology_name}"] = unyt_array(t.power_history).to_ndarray()
data[f"{t.technology_name}"] = unyt_array(
t.power_history).to_ndarray()
if t.technology_type == 'storage':
data[f"{t.technology_name}_level"] = unyt_array(t.storage_history).to_ndarray()
data[f"{t.technology_name}_charge"] = unyt_array(t.charge_history).to_ndarray()
data["Curtailment"] = np.array([v if v <=0 else 0 for v in self.covered_demand])
data["Shortfall"] = np.array([v if v > 0 else 0 for v in self.covered_demand])
data[f"{t.technology_name}_level"] = unyt_array(
t.storage_history).to_ndarray()
data[f"{t.technology_name}_charge"] = unyt_array(
t.charge_history).to_ndarray()
data["Curtailment"] = np.array(
[v if v <= 0 else 0 for v in self.covered_demand])
data["Shortfall"] = np.array(
[v if v > 0 else 0 for v in self.covered_demand])
self.results = pd.DataFrame(data)
return

def _calculate_objective(self):
self.objective = sum(np.array(t.power_history).sum()
*t.variable_cost.to_value()
for t in self.technology_list)
* t.variable_cost.to_value()
for t in self.technology_list)
return

def solve(self):
Expand All @@ -69,16 +74,17 @@ def solve(self):
v -= power_out

self.covered_demand[i] = v
if not self.allow_blackout and (v>0):
if not self.allow_blackout and (v > 0):
if self.verbosity <= 20:
print('solve failed -- unmet demand')
raise ValueError

if not self.curtailment and (v<0):
if not self.curtailment and (v < 0):
if self.verbosity <= 20:
print('solve failed -- too much overproduction (no curtailment allowed)')
print(
'solve failed -- too much overproduction (no curtailment allowed)')
raise ValueError

self._format_results()
self._calculate_objective()
except ValueError:
Expand All @@ -87,4 +93,4 @@ def solve(self):
f"Infeasible or no solution. Objective set to {LARGE_NUMBER}")
self.objective = LARGE_NUMBER

return
return
16 changes: 8 additions & 8 deletions osier/models/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ def __init__(self,
self.power_units = net_demand.units
elif isinstance(net_demand, (np.ndarray, list)):
self.power_units = power_units
self.net_demand = np.array(self.net_demand)*self.power_units
self.net_demand = np.array(self.net_demand) * self.power_units
elif isinstance(net_demand, pd.core.series.Series):
self.power_units = power_units
self.net_demand = np.array(self.net_demand)*self.power_units
self.net_demand = np.array(self.net_demand) * self.power_units
else:
self.power_units = power_units

self.technology_list = synchronize_units(
technology_list,
unit_power=self.power_units,
unit_time=self.time_delta.units)
unit_time=self.time_delta.units)

@property
def time_delta(self):
Expand All @@ -64,17 +64,17 @@ def time_delta(self, value):
value = float(freq_list[0])
except ValueError:
warnings.warn((f"Could not convert value "
f"{freq_list[0]} to float. "
"Setting to 1.0."),
UserWarning)
f"{freq_list[0]} to float. "
"Setting to 1.0."),
UserWarning)
value = 1.0
self._time_delta = _validate_quantity(
f"{value} {_freq_opts[freq_key]}", dimension='time')
except KeyError:
warnings.warn(
(f"Could not infer time delta with freq {freq_key} "
"from pandas dataframe. Setting delta to 1 hour."),
"from pandas dataframe. Setting delta to 1 hour."),
UserWarning)
self._time_delta = 1 * hr
else:
self._time_delta = 1 * hr
self._time_delta = 1 * hr
20 changes: 9 additions & 11 deletions osier/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ def synchronize_units(tech_list: Iterable[Technology],
return synced_list



def get_tech_names(technology_list):
"""
Returns the a list of :class:`osier.Technology` name strings.
Expand All @@ -74,7 +73,7 @@ def get_tech_names(technology_list):

def get_dispatchable_techs(technology_list):
"""
Returns a list of :class:`osier.Technology` objects
Returns a list of :class:`osier.Technology` objects
where :attr:`dispatchable` is `True`.
Parameters
Expand All @@ -95,7 +94,7 @@ def get_dispatchable_techs(technology_list):

def get_nondispatchable_techs(technology_list):
"""
Returns a list of :class:`osier.Technology` objects
Returns a list of :class:`osier.Technology` objects
where :attr:`dispatchable` is `False`.
Parameters
Expand All @@ -116,7 +115,7 @@ def get_nondispatchable_techs(technology_list):

def get_storage_techs(technology_list):
"""
Returns a list of :class:`osier.Technology` objects
Returns a list of :class:`osier.Technology` objects
that have the attribute :attr:`storage_level`.
Parameters
Expand All @@ -130,14 +129,15 @@ def get_storage_techs(technology_list):
The list of storage technologies.
"""

storage_techs = [t for t in technology_list
if hasattr(t, 'storage_level')]
storage_techs = [t for t in technology_list
if hasattr(t, 'storage_level')]

return storage_techs


def get_nonstorage_techs(technology_list):
"""
Returns a list of :class:`osier.Technology` objects
Returns a list of :class:`osier.Technology` objects
that do not have the attribute :attr:`storage_level`.
Parameters
Expand All @@ -151,8 +151,8 @@ def get_nonstorage_techs(technology_list):
The list of non-storage technologies.
"""

nonstorage_techs = [t for t in technology_list
if not hasattr(t, 'storage_level')]
nonstorage_techs = [t for t in technology_list
if not hasattr(t, 'storage_level')]

return nonstorage_techs

Expand Down Expand Up @@ -203,5 +203,3 @@ def technology_dataframe(technology_list, cast_to_string=True):
technology_dataframe = pd.concat(frames, axis=0)

return technology_dataframe


Loading

0 comments on commit f211f42

Please sign in to comment.