Skip to content

Commit

Permalink
Switch to using PowersReal and PowersImaginary again
Browse files Browse the repository at this point in the history
  • Loading branch information
Joseph McKinsey committed May 30, 2023
1 parent 53c779a commit 3b9fdf1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
12 changes: 7 additions & 5 deletions LocalFeeder/sender_cosim.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,17 +223,21 @@ def get_current_data(sim: FeederSimulator, Y):
power_real, power_imaginary = get_powers(-PQ_load, -PQ_PV, -PQ_gen, -PQ_cap)
injections = Injection(power_real=power_real, power_imaginary=power_imaginary)

ids = xr.DataArray(sim._AllNodeNames, coords={"ids": sim._AllNodeNames})
ids = xr.DataArray(sim._AllNodeNames, coords={
"ids": sim._AllNodeNames,
})
PQ_injections_all = (
agg_to_ids(PQ_load, ids)
+ agg_to_ids(PQ_PV, ids)
+ agg_to_ids(PQ_gen, ids)
+ agg_to_ids(PQ_cap, ids)
)

PQ_injections_all = PQ_injections_all.assign_coords(equipment_ids=('ids', list(map(lambda x: x.split(".")[0], sim._AllNodeNames))))
calculated_power = (
feeder_voltages * (Y.conjugate() @ feeder_voltages.conjugate()) / 1000
)

PQ_injections_all[sim._source_indexes] = -calculated_power[sim._source_indexes]
return CurrentData(
feeder_voltages=feeder_voltages,
Expand Down Expand Up @@ -383,16 +387,14 @@ def go_cosim(sim: FeederSimulator, config: FeederConfig, input_mapping: Dict[str
).json()
)
pub_powers_real.publish(
MeasurementArray(
PowersReal(
**xarray_to_dict(current_data.PQ_injections_all.real),
units = "kW",
time=current_timestamp,
).json()
)
pub_powers_imag.publish(
MeasurementArray(
PowersImaginary(
**xarray_to_dict(current_data.PQ_injections_all.imag),
units = "kVAR",
time=current_timestamp,
).json()
)
Expand Down
2 changes: 2 additions & 0 deletions LocalFeeder/tests/test_feeder.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ def simulation_middle(sim, Y):
assert len(current_data.injections.power_real.values) == len(
current_data.injections.power_real.ids
)

assert '113' in current_data.PQ_injections_all.equipment_ids.data
df = pd.DataFrame(
{
"p": current_data.PQ_injections_all.real,
Expand Down
5 changes: 4 additions & 1 deletion measuring_federate/measuring_federate.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ def run(self):
while granted_time < h.HELICS_TIME_MAXTIME:
logger.info("start time: " + str(datetime.now()))
json_data = self.sub_measurement.json
measurement = MeasurementArray(**json_data)
if "equipment_ids" in json_data:
measurement = EquipmentNodeArray.parse_obj(json_data)
else:
measurement = MeasurementArray.parse_obj(json_data)

with open(self.measurement_file, "r") as fp:
self.measurement = json.load(fp)
Expand Down
4 changes: 2 additions & 2 deletions wls_federate/state_estimator_federate.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,8 @@ def run(self):
logger.info("start time: " + str(datetime.now()))

voltages = VoltagesMagnitude.parse_obj(self.sub_voltages_magnitude.json)
power_Q = MeasurementArray.parse_obj(self.sub_power_Q.json)
power_P = MeasurementArray.parse_obj(self.sub_power_P.json)
power_P = PowersReal.parse_obj(self.sub_power_P.json)
power_Q = PowersImaginary.parse_obj(self.sub_power_Q.json)
knownP = get_indices(topology, power_P)
knownQ = get_indices(topology, power_Q)
knownV = get_indices(topology, voltages)
Expand Down

0 comments on commit 3b9fdf1

Please sign in to comment.