def _calculate_phi_loss_constant(self): phi_loss_from, phi_loss_to = tx_calc.calculate_phi_loss_constant( self._branches, self.branches_keys, self.buses_keys, ApproximationType.PTDF_LOSSES) ## hold onto these for line outages self._phi_loss_from = phi_loss_from self._phi_loss_to = phi_loss_to ## sum the across the columns, which are indexed by branch phi_losses_adjust_array = phi_loss_from.sum(axis=1) - phi_loss_to.sum( axis=1) ## protect the array using numpy phi_losses_adjust_array.flags.writeable = False self.phi_losses_adjust_array = phi_losses_adjust_array
def create_dicts_of_ptdf_losses(md,base_point=BasePointType.SOLUTION): branches = dict(md.elements(element_type='branch')) buses = dict(md.elements(element_type='bus')) branch_attrs = md.attributes(element_type='branch') bus_attrs = md.attributes(element_type='bus') reference_bus = md.data['system']['reference_bus'] ptdf_r, ldf, ldf_c = tx_calc.calculate_ptdf_ldf(branches,buses,branch_attrs['names'],bus_attrs['names'],reference_bus,base_point) phi_from, phi_to = tx_calc.calculate_phi_constant(branches,branch_attrs['names'],bus_attrs['names'],ApproximationType.PTDF_LOSSES) phi_loss_from, phi_loss_to = tx_calc.calculate_phi_loss_constant(branches,branch_attrs['names'],bus_attrs['names'],ApproximationType.PTDF_LOSSES) _len_branch = len(branch_attrs['names']) _mapping_branch = {i: branch_attrs['names'][i] for i in list(range(0,_len_branch))} _len_bus = len(bus_attrs['names']) _mapping_bus = {i: bus_attrs['names'][i] for i in list(range(0,_len_bus))} for idx,branch_name in _mapping_branch.items(): branch = md.data['elements']['branch'][branch_name] _row_ptdf_r = {bus_attrs['names'][i]: ptdf_r[idx,i] for i in list(range(0,_len_bus))} branch['ptdf_r'] = _row_ptdf_r _row_ldf = {bus_attrs['names'][i]: ldf[idx,i] for i in list(range(0,_len_bus))} branch['ldf'] = _row_ldf branch['ldf_c'] = ldf_c[idx] for idx, bus_name in _mapping_bus.items(): bus = md.data['elements']['bus'][bus_name] _row_phi_from = {branch_attrs['names'][i]: phi_from[idx,i] for i in list(range(0,_len_branch)) if phi_from[idx, i] != 0.} bus['phi_from'] = _row_phi_from _row_phi_to = {branch_attrs['names'][i]: phi_to[idx,i] for i in list(range(0,_len_branch)) if phi_to[idx, i] != 0.} bus['phi_to'] = _row_phi_to _row_phi_loss_from = {branch_attrs['names'][i]: phi_loss_from[idx,i] for i in list(range(0,_len_branch)) if phi_loss_from[idx, i] != 0.} bus['phi_loss_from'] = _row_phi_loss_from _row_phi_loss_to = {branch_attrs['names'][i]: phi_loss_to[idx,i] for i in list(range(0,_len_branch)) if phi_loss_to[idx, i] != 0.} bus['phi_loss_to'] = _row_phi_loss_to
def _calculate_phi_loss_constant(self): phi_loss_from, phi_loss_to = tx_calc.calculate_phi_loss_constant( self._branches, self.branches_keys, self.buses_keys, ApproximationType.PTDF_LOSSES, mapping_bus_to_idx=self._busname_to_index_map) ## hold onto these for line outages self._phi_loss_from = phi_loss_from self._phi_loss_to = phi_loss_to ## sum the across the columns, which are indexed by branch phi_losses_adjust_array = phi_loss_from - phi_loss_to ## sum across the rows to get the total impact, and convert ## to dense for fast operations later self.phi_losses_adjust_array = phi_losses_adjust_array.sum( axis=1).T.A[0] ## protect the array using numpy self.phi_losses_adjust_array.flags.writeable = False