Skip to content

Commit

Permalink
multiple fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ktehranchi committed Sep 27, 2024
1 parent da3bcd8 commit eb2b428
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
9 changes: 4 additions & 5 deletions src/r2x/exporter/sienna.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,26 +523,25 @@ def apply_operation_table_data(
component["heat_rate_a1"] = function_data["proportional_term"]
if "quadratic_term" in function_data.keys():
component["heat_rate_a2"] = function_data["quadratic_term"]
if "x_coords" in function_data.keys():
if "points" in function_data.keys():
component = _variable_type_parsing(component, operation_cost)
return component


def _variable_type_parsing(component: dict, cost_dict: dict[str, Any]) -> dict[str, Any]:
variable_curve = cost_dict["variable"]
function_data = variable_curve["value_curve"]["function_data"]
x_y_coords = dict(zip(function_data["x_coords"], function_data["y_coords"]))
x_y_coords = variable_curve["value_curve"]["function_data"]["points"]
match cost_dict["variable_type"]:
case "CostCurve":
for i, (x_coord, y_coord) in enumerate(x_y_coords.items()):
for i, (x_coord, y_coord) in enumerate(x_y_coords):
output_point_col = f"output_point_{i}"
component[output_point_col] = x_coord

cost_point_col = f"cost_point_{i}"
component[cost_point_col] = y_coord

case "FuelCurve":
for i, (x_coord, y_coord) in enumerate(x_y_coords.items()):
for i, (x_coord, y_coord) in enumerate(x_y_coords):
output_point_col = f"output_point_{i}"
component[output_point_col] = x_coord

Expand Down
7 changes: 5 additions & 2 deletions src/r2x/models/costs.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ def variable_type(self) -> str | None:
@property
def value_curve_type(self) -> str | None:
"""Create attribute that holds the class name."""
if not attrgetter("variable.value_curve")(self):
try:
if not attrgetter("variable.value_curve")(self):
return None
return type(attrgetter("variable.value_curve")(self)).__name__
except AttributeError:
return None
return type(attrgetter("variable.value_curve")(self)).__name__


class RenewableGenerationCost(OperationalCost):
Expand Down
2 changes: 1 addition & 1 deletion src/r2x/parser/parser_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def construct_pwl_from_quadtratic(fn, mapped_records, num_tranches=6):

# Use evenly spaced X values for the tranches
# Future iteration should accept custom X values for Bid Cost Markup
x_vals, y_vals = optimize_pwl(a, b, c, x_min, x_max, n_tranches=6)
x_vals, y_vals = optimize_pwl(a, b, c, x_min, x_max, num_tranches)

pwl_fn = PiecewiseLinearData(points=[XYCoords(x, y) for x, y in zip(x_vals, y_vals)])

Expand Down
2 changes: 1 addition & 1 deletion src/r2x/parser/plexos.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ def _construct_interfaces(self, default_model=TransmissionInterface):

interface_property_map = {
v: k
for k, v in self.config.defaults["plexos_property_map"].items()
for k, v in self.config.defaults["plexos_input_property_map"].items()
if k in default_model.model_fields
}

Expand Down

0 comments on commit eb2b428

Please sign in to comment.