Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linopy fix #1

Closed
coroa opened this issue Nov 8, 2022 · 2 comments · Fixed by #2
Closed

linopy fix #1

coroa opened this issue Nov 8, 2022 · 2 comments · Fixed by #2

Comments

@coroa
Copy link

coroa commented Nov 8, 2022

You are right, linopy is still too alpha for directly comparing it with the other implementations, but anyway, just had a short look and what is going wrong is PyPSA/linopy#57 .

ie. variable / scalar is not dispatching to the correct method and changing variable labels instead of coefficients in a linear expression.

    intertemp_soc_lhs = (
        soc_mwh
        - soc_mwh.shift(datetime=1)
        - charge_mw * (charge_eff * tau)
        + discharge_mw * (tau / discharge_eff)
    ).isel(datetime=slice(1, None))

will work correctly; ie you either do variable * scalar or scalar * variable.

To understand why the shift is necessary, that is a pandas/xarray feature that they align data on their index (the first column, like the labels) automatically.

Just consider the very simple example below:

In [1]: import pandas as pd

In [2]: s = pd.Series([1, 2, 3])

In [3]: s
Out[3]:
0    1
1    2
2    3
dtype: int64

In [4]: s.loc[1:]
Out[4]:
1    2
2    3
dtype: int64

In [5]: s.shift(1)
Out[5]:
0    NaN
1    1.0
2    2.0
dtype: float64

In [6]: s - s.loc[1:]
Out[6]:
0    NaN
1    0.0
2    0.0
dtype: float64

In [7]: s - s.shift(1)
Out[7]:
0    NaN
1    1.0
2    1.0
dtype: float64
@prakaa
Copy link
Owner

prakaa commented Nov 10, 2022

Thanks @coroa. Will hopefully have time to correct in the next couple of weeks.

@prakaa prakaa mentioned this issue Dec 6, 2022
@prakaa prakaa closed this as completed in #2 Dec 6, 2022
@prakaa
Copy link
Owner

prakaa commented Dec 6, 2022

Thanks very much @coroa, working now. I will update the README

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 a pull request may close this issue.

2 participants