Skip to content

tf cos phi power factor#3064

Open
Fabsit wants to merge 16 commits into
e2nIEE:developfrom
Fabsit:feature/2026-01-07-TF-cos-phi-power-factor
Open

tf cos phi power factor#3064
Fabsit wants to merge 16 commits into
e2nIEE:developfrom
Fabsit:feature/2026-01-07-TF-cos-phi-power-factor

Conversation

@Fabsit

@Fabsit Fabsit commented Jul 8, 2026

Copy link
Copy Markdown
Contributor
New helper for the toolbox: ``sync_q_from_cos_phi''

Recompute q_mvar = abs(p_mw) * tan(arccos(abs(cos_phi))) * sign(cos_phi).

Use to sync q_mvar from p_mw via cos phi for e.g. time series or OPF studies.

@Fabsit

Fabsit commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

Provide functionality to write "cos phi" columns to load and sgen and then sync them to p.
I will fix mypy asap (sorry, first PR from github)
also: not completely sure if this functionality should go into pp or somewhere else

@codecov

codecov Bot commented Jul 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.47619% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.69%. Comparing base (1576fe6) to head (73d4daa).

Files with missing lines Patch % Lines
pandapower/toolbox/power_factor.py 90.47% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3064      +/-   ##
===========================================
+ Coverage    71.67%   71.69%   +0.01%     
===========================================
  Files          355      355              
  Lines        39348    39381      +33     
===========================================
+ Hits         28204    28235      +31     
- Misses       11144    11146       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread pandapower/test/toolbox/test_power_factor.py Outdated
Comment thread pandapower/test/toolbox/test_power_factor.py Outdated
@KS-HTK KS-HTK changed the title Feature/2026 01 07 tf cos phi power factor tf cos phi power factor Jul 9, 2026
assert via allclose, replace .values with to_numpy, added changelog entry
@Fabsit

Fabsit commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

Thank you for the review!
I pushed the requested changes: assert via allclose, replace .values by to_numpy(), and I added a changelog entry.

KS-HTK
KS-HTK previously approved these changes Jul 10, 2026
KS-HTK
KS-HTK previously approved these changes Jul 10, 2026
Comment thread pandapower/toolbox/power_factor.py Outdated
return _pq_from_cosphi_bulk(s, cosphi, qmode, pmode, len_=len_)


def create_cos_phi_from_network(net: pandapowerNet, element_type: str) -> None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rename this function, create_cos_phi(net: pandapowerNet, element_type: Literal["sgen", "gen", "load"])

@Fabsit Fabsit Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create_cos_phi_from_network_state?
Note that gen (PV generator) makes no sense

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I would remove the "from_network*" since the first parameter is the network and nothing else. So it is kinda clear, that it is from / for the network.

PV gen we thought about, but this needs to be handled differently, I guess.

Comment thread pandapower/toolbox/power_factor.py Outdated
table["cos_phi"] = cos_phi


def create_cos_phi_constant(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This I would rename to set_cos_phi(net: pandapowerNet, element_type: Literal["load", "sgen", "gen"], cos_phi: float = 0.95, mode: Literal["underexcited", "overexcited"] = "underexcited")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set_constant_cos_phi? again, gen makes no sense

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is not really constant, it is just a cos_phi value. Again nowhere in pp it is called like that. Also setting this value, does not enforce that it is constant (no logic is available in pp for doing that), in essence it could just be ignored by other parts of the code base.

Comment thread pandapower/toolbox/power_factor.py Outdated
table["cos_phi"] = sign * abs(cos_phi)


def sync_q_from_cos_phi(net: pandapowerNet, element_type: str, indices: Any) -> None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this I would change to update_via_cos_phi(net: pandapowerNet, element_type: str, indices: Iterable[Int] | Int, direction: Literal["q_from_p", "p_from_q"] = "q_from_p")

Please implement both directions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sync p from q makes no sense.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is the part I do not know, maybe in some kind of optimization it could be interesting. But If you think it is unnecessary, just omit it.

@sonarqubecloud

Copy link
Copy Markdown

table["cos_phi"] = cos_phi


def set_constant_cos_phi(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A constant does not need to be set, either it is constant, then it should be declared as such (see pep8 on constants), or it is not constant and should not be named as such.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants