PyPSA / pypsa-usa

PyPSA-USA: An Open-Source Energy System Optimization Model for the United States
https://pypsa-usa.readthedocs.io
MIT License
35 stars 15 forks source link

`Bus` cannot be matched by `bus_region_mapper` because of different column type (int and str) #216

Closed casinocullen closed 3 months ago

casinocullen commented 3 months ago

Checklist

The Issue

In add_electricity.py, the code gen[f"{fuel_region_type}"] = gen.bus.map(bus_region_mapper) has an issue because the column type doesn't match (the bus column in gen is integer while in bus_region_mapper is string)

Steps To Reproduce

No response

Expected Behavior

No response

Error Message

No response

Anything else?

No response

casinocullen commented 3 months ago

Bigger issue found: update_marginal_costs doesn't work on Texas.. Solving the bug now.

casinocullen commented 3 months ago

I found the reason that update_marginal_costs doesn't work for Texas. The fuel_region_type in ng_fuel_prices.csv doesn't have any balancing area columns for ERCOT, therefore the dataframe gen would be empty, and cause the problem for the following codes:

        # fuel_costs.set_index(fuel_region_type, inplace=True)
        for fuel_region in gen[fuel_region_type].unique():
            gens_in_region = gen[gen[fuel_region_type] == fuel_region].index.to_list()
            dfs.append(
                pd.DataFrame({gen_: fuel_costs[fuel_region] for gen_ in gens_in_region})
            )
        df = pd.concat(dfs, axis=1)

Now, I added

        if len(gen) == 0:
            continue

before running the above code to avoid the issue.