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

Pandas FutureWarning in westeros_historical_new_capacity.ipynb #899

Open
Tyler-lc opened this issue Dec 12, 2024 · 2 comments · May be fixed by #900
Open

Pandas FutureWarning in westeros_historical_new_capacity.ipynb #899

Tyler-lc opened this issue Dec 12, 2024 · 2 comments · May be fixed by #900

Comments

@Tyler-lc
Copy link

Tyler-lc commented Dec 12, 2024

What is this about?

Deprecated method in Pandas
In the tutorial hystorical_new_capacity we use the command df["value"] = float(df[df["year"] == 700]["value"]) modify the demand.
The problem is that this will throw a warning because it will be deprecated in future version of Pandas:

:1: FutureWarning: Calling float on a single element Series is deprecated and will raise a TypeError in the future. Use float(ser.iloc[0]) instead

I suggest to replace the above line with either a lengthy:

filter_df = df["year"] == 700
value = df[filter_df]["value"].values[0]
df["value"] = value

or a more compact:
df["value"] = df.loc[df["year"] == 700, "value"].iloc[0]

since the values in the column are already numpy.float64 it should not be a problem. If for some reason we really need to make sure that it is a float we could always use
df["value"] = df["year"].apply(float)

Grid Efficiency value
In this exercise we need to retrieve the grid_efficiency value so that we can calculate how much coal_ppl capacity we need. The following is used:


# We know that there are losses that occur when electricity is transmitted via the
# `grid`.
grid_eff = float(
    scenario.par(
        "output",
        filters={
            "year_vtg": scenario.firstmodelyear,
            "year_act": scenario.firstmodelyear,
            "technology": "grid",
        },
    )["value"]
)
print(f"Grid efficiency is {grid_eff}.")
demand_of_firstmodelyear /= grid_eff

This will give 1 as a result because the output of the grid is 1.
I think we are looking for the input which is 1.111111_ in which case the correct code would be:


grid_eff = float(
    scenario.par(
        "input",
        filters={
            "year_vtg": scenario.firstmodelyear,
            "year_act": scenario.firstmodelyear,
            "technology": "grid",
        },
    )["value"]
)

@glatterf42
Copy link
Member

I'm not sure I agree on the grid_efficiency part of this issue. In my tutorial notebook, when I execute this cell,

grid_eff = float(
    scenario.par(
        "output",
        filters={
            "year_vtg": scenario.firstmodelyear,
            "year_act": scenario.firstmodelyear,
            "technology": "grid",
        },
    )["value"].iloc[0]
)
print(f"Grid efficiency is {grid_eff}.")
demand_of_firstmodelyear /= grid_eff

I see this output:

Grid efficiency is 0.9.

Which is exactly what we said in the westeros_baseline tutorial. We are using this value to increase the demand_of_firstmodelyear to reflect that we need higher input by 1/grid_efficiency so that the demanded output is achieved.

@Tyler-lc
Copy link
Author

When I run:

grid_eff = float(
    scenario.par(
        "output",
        filters={
            "year_vtg": scenario.firstmodelyear,
            "year_act": scenario.firstmodelyear,
            "technology": "grid",
        },
    )["value"].iloc[0]
)
print(f"Grid efficiency is {grid_eff}.")
demand_of_firstmodelyear /= grid_eff

I get that the grid_efficiency is 1.0.

When looking at the westeros_baseline from the official repo we have that:


grid_efficiency = 0.9
year_df = scenario.vintage_and_active_years((country, "grid"), in_horizon=False)
vintage_years, act_years = year_df["year_vtg"], year_df["year_act"]

base.update(
    year_vtg=vintage_years,
    year_act=act_years,
    technology="grid",
    commodity="electricity",
    level="final",
    value=1.0,
)
grid_out = make_df("output", **base, node_dest=country, time_dest="year")
scenario.add_par("output", grid_out)

base.update(commodity="electricity", level="secondary", value=1.0 / grid_efficiency)
grid_in = make_df("input", **base, node_origin=country, time_origin="year")
scenario.add_par("input", grid_in)

We are setting the value = 1.0/grid_efficiency on the input parameter. As you can see here the output is set to 1.0.
I don't know why we get different numbers though. That is interesting 😄

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