Skip to content

Commit

Permalink
Use better try/except
Browse files Browse the repository at this point in the history
  • Loading branch information
Joseph McKinsey committed Aug 13, 2024
1 parent 1c54841 commit f1b7926
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions LocalFeeder/FeederSimulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def forcast_pv(self, steps: int) -> list:
average irradiance is computed over all PV systems for each time step. This average irradiance
is used to compute the individual PV system power output
"""
cmd = f'Set stepsize={self._simulation_time_step} Number=1'
cmd = f"Set stepsize={self._simulation_time_step} Number=1"
dss.Text.Command(cmd)
forecast = []
for k in range(steps):
Expand All @@ -182,7 +182,7 @@ def forcast_pv(self, steps: int) -> list:
flag = dss.PVsystems.First()
avg_irradiance = dss.PVsystems.IrradianceNow()
while flag:
avg_irradiance = (avg_irradiance + dss.PVsystems.IrradianceNow())/2
avg_irradiance = (avg_irradiance + dss.PVsystems.IrradianceNow()) / 2
flag = dss.PVsystems.Next()

# now compute the power output from the evaluated average irradiance
Expand Down Expand Up @@ -319,17 +319,17 @@ def get_bus_coords(self) -> Dict[str, Tuple[float, float]] | None:
if not os.path.exists(bus_path):
self.bus_coords = None
return self.bus_coords
try:
with open(bus_path, "r") as f:
bus_coord_csv = csv.reader(f, delimiter=" ")
bus_coords = {}
for row in bus_coord_csv:
with open(bus_path, "r") as f:
bus_coord_csv = csv.reader(f, delimiter=" ")
bus_coords = {}
for row in bus_coord_csv:
try:
identifier, x, y = row
bus_coords[identifier] = (float(x), float(y))
return bus_coords
except Exception as e:
logging.warning(f"Unable to parse bus coords: {e}")
return None
except ValueError as e:
logging.warning(f"Unable to parse row in bus coords: {row}, {e}")
return None
return bus_coords

def load_feeder(self):
"""Load feeder once downloaded. Relies on legacy mode."""
Expand Down

0 comments on commit f1b7926

Please sign in to comment.