If you provide the same override_component_attrs
dict that you used to create the network when loading the pypsa.Network
from file, the non-standard attributes are loaded as well. (They are always saved, just not loaded as of pypsa=0.23.0
).
Instead of duplicating code you can either either carry the dict
over between along with your network:
import pickle
import pypsa
override_component_attrs = pypsa.descriptors.Dict(
{k: v.copy() for k, v in pypsa.components.component_attrs.items()}
)
override_component_attrs["Link"].loc["bus2"] = [
"string", np.nan, np.nan,
"Name of optional 3rd bus to which link is attached.",
"Input (optional)",
]
override_component_attrs["Link"].loc["efficiency2"] = [
"static or series", "per unit", np.nan,
"Efficiency of power transfer from bus0 to bus2 (static or time-dependent)",
]
# more overwrites
# ...
# Save dict, e.g. as pickle
with open("override_component_attrs.pkl", "wb") as f:
pickle.dump(override_component_attrs, f)
# When loading your Network, use the file for overwriting components
with open("override_component_attrs.pkl", "rb") as f:
oca = pickle.load(f)
network = pypsa.Network(<path of network to load>, override_component_attrs=oca)
Or you create a common function which you call from your different scripts which creates a Network
with the components overwritten and then call pypsa.Network.import_from_<netcdf|csv_folder>(...)
.