Conditions | 47 |
Total Lines | 1067 |
Code Lines | 722 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like data.datasets.pypsaeur.neighbor_reduction() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | """The central module containing all code dealing with importing data from |
||
670 | def neighbor_reduction(): |
||
671 | network_solved = read_network(planning_horizon=2045) |
||
672 | network_prepared = prepared_network(planning_horizon="2045") |
||
673 | |||
674 | # network.links.drop("pipe_retrofit", axis="columns", inplace=True) |
||
675 | |||
676 | wanted_countries = countries_list() |
||
677 | |||
678 | foreign_buses = network_solved.buses[ |
||
679 | (~network_solved.buses.index.str.contains("|".join(wanted_countries))) |
||
680 | | (network_solved.buses.index.str.contains("FR6")) |
||
681 | ] |
||
682 | network_solved.buses = network_solved.buses.drop( |
||
683 | network_solved.buses.loc[foreign_buses.index].index |
||
684 | ) |
||
685 | |||
686 | # Add H2 demand of Fischer-Tropsch process and methanolisation |
||
687 | # to industrial H2 demands |
||
688 | industrial_hydrogen = network_prepared.loads.loc[ |
||
689 | network_prepared.loads.carrier == "H2 for industry" |
||
690 | ] |
||
691 | fischer_tropsch = ( |
||
692 | network_solved.links_t.p0[ |
||
693 | network_solved.links.loc[ |
||
694 | network_solved.links.carrier == "Fischer-Tropsch" |
||
695 | ].index |
||
696 | ] |
||
697 | .mul(network_solved.snapshot_weightings.generators, axis=0) |
||
698 | .sum() |
||
699 | ) |
||
700 | methanolisation = ( |
||
701 | network_solved.links_t.p0[ |
||
702 | network_solved.links.loc[ |
||
703 | network_solved.links.carrier == "methanolisation" |
||
704 | ].index |
||
705 | ] |
||
706 | .mul(network_solved.snapshot_weightings.generators, axis=0) |
||
707 | .sum() |
||
708 | ) |
||
709 | for i, row in industrial_hydrogen.iterrows(): |
||
710 | network_prepared.loads.loc[i, "p_set"] += ( |
||
711 | fischer_tropsch[ |
||
712 | fischer_tropsch.index.str.startswith(row.bus[:5]) |
||
713 | ].sum() |
||
714 | / 8760 |
||
715 | ) |
||
716 | network_prepared.loads.loc[i, "p_set"] += ( |
||
717 | methanolisation[ |
||
718 | methanolisation.index.str.startswith(row.bus[:5]) |
||
719 | ].sum() |
||
720 | / 8760 |
||
721 | ) |
||
722 | # drop foreign lines and links from the 2nd row |
||
723 | |||
724 | network_solved.lines = network_solved.lines.drop( |
||
725 | network_solved.lines[ |
||
726 | ( |
||
727 | network_solved.lines["bus0"].isin(network_solved.buses.index) |
||
728 | == False |
||
729 | ) |
||
730 | & ( |
||
731 | network_solved.lines["bus1"].isin(network_solved.buses.index) |
||
732 | == False |
||
733 | ) |
||
734 | ].index |
||
735 | ) |
||
736 | |||
737 | # select all lines which have at bus1 the bus which is kept |
||
738 | lines_cb_1 = network_solved.lines[ |
||
739 | ( |
||
740 | network_solved.lines["bus0"].isin(network_solved.buses.index) |
||
741 | == False |
||
742 | ) |
||
743 | ] |
||
744 | |||
745 | # create a load at bus1 with the line's hourly loading |
||
746 | for i, k in zip(lines_cb_1.bus1.values, lines_cb_1.index): |
||
747 | |||
748 | # Copy loading of lines into hourly resolution |
||
749 | pset = pd.Series( |
||
750 | index=network_prepared.snapshots, |
||
751 | data=network_solved.lines_t.p1[k].resample("H").ffill(), |
||
752 | ) |
||
753 | pset["2011-12-31 22:00:00"] = pset["2011-12-31 21:00:00"] |
||
754 | pset["2011-12-31 23:00:00"] = pset["2011-12-31 21:00:00"] |
||
755 | |||
756 | # Loads are all imported from the prepared network in the end |
||
757 | network_prepared.add( |
||
758 | "Load", |
||
759 | "slack_fix " + i + " " + k, |
||
760 | bus=i, |
||
761 | p_set=pset, |
||
762 | carrier=lines_cb_1.loc[k, "carrier"], |
||
763 | ) |
||
764 | |||
765 | # select all lines which have at bus0 the bus which is kept |
||
766 | lines_cb_0 = network_solved.lines[ |
||
767 | ( |
||
768 | network_solved.lines["bus1"].isin(network_solved.buses.index) |
||
769 | == False |
||
770 | ) |
||
771 | ] |
||
772 | |||
773 | # create a load at bus0 with the line's hourly loading |
||
774 | for i, k in zip(lines_cb_0.bus0.values, lines_cb_0.index): |
||
775 | # Copy loading of lines into hourly resolution |
||
776 | pset = pd.Series( |
||
777 | index=network_prepared.snapshots, |
||
778 | data=network_solved.lines_t.p0[k].resample("H").ffill(), |
||
779 | ) |
||
780 | pset["2011-12-31 22:00:00"] = pset["2011-12-31 21:00:00"] |
||
781 | pset["2011-12-31 23:00:00"] = pset["2011-12-31 21:00:00"] |
||
782 | |||
783 | network_prepared.add( |
||
784 | "Load", |
||
785 | "slack_fix " + i + " " + k, |
||
786 | bus=i, |
||
787 | p_set=pset, |
||
788 | carrier=lines_cb_0.loc[k, "carrier"], |
||
789 | ) |
||
790 | |||
791 | # do the same for links |
||
792 | network_solved.mremove( |
||
793 | "Link", |
||
794 | network_solved.links[ |
||
795 | (~network_solved.links.bus0.isin(network_solved.buses.index)) |
||
796 | | (~network_solved.links.bus1.isin(network_solved.buses.index)) |
||
797 | ].index, |
||
798 | ) |
||
799 | |||
800 | # select all links which have at bus1 the bus which is kept |
||
801 | links_cb_1 = network_solved.links[ |
||
802 | ( |
||
803 | network_solved.links["bus0"].isin(network_solved.buses.index) |
||
804 | == False |
||
805 | ) |
||
806 | ] |
||
807 | |||
808 | # create a load at bus1 with the link's hourly loading |
||
809 | for i, k in zip(links_cb_1.bus1.values, links_cb_1.index): |
||
810 | pset = pd.Series( |
||
811 | index=network_prepared.snapshots, |
||
812 | data=network_solved.links_t.p1[k].resample("H").ffill(), |
||
813 | ) |
||
814 | pset["2011-12-31 22:00:00"] = pset["2011-12-31 21:00:00"] |
||
815 | pset["2011-12-31 23:00:00"] = pset["2011-12-31 21:00:00"] |
||
816 | |||
817 | network_prepared.add( |
||
818 | "Load", |
||
819 | "slack_fix_links " + i + " " + k, |
||
820 | bus=i, |
||
821 | p_set=pset, |
||
822 | carrier=links_cb_1.loc[k, "carrier"], |
||
823 | ) |
||
824 | |||
825 | # select all links which have at bus0 the bus which is kept |
||
826 | links_cb_0 = network_solved.links[ |
||
827 | ( |
||
828 | network_solved.links["bus1"].isin(network_solved.buses.index) |
||
829 | == False |
||
830 | ) |
||
831 | ] |
||
832 | |||
833 | # create a load at bus0 with the link's hourly loading |
||
834 | for i, k in zip(links_cb_0.bus0.values, links_cb_0.index): |
||
835 | pset = pd.Series( |
||
836 | index=network_prepared.snapshots, |
||
837 | data=network_solved.links_t.p0[k].resample("H").ffill(), |
||
838 | ) |
||
839 | pset["2011-12-31 22:00:00"] = pset["2011-12-31 21:00:00"] |
||
840 | pset["2011-12-31 23:00:00"] = pset["2011-12-31 21:00:00"] |
||
841 | |||
842 | network_prepared.add( |
||
843 | "Load", |
||
844 | "slack_fix_links " + i + " " + k, |
||
845 | bus=i, |
||
846 | p_set=pset, |
||
847 | carrier=links_cb_0.carrier[k], |
||
848 | ) |
||
849 | |||
850 | # drop remaining foreign components |
||
851 | for comp in network_solved.iterate_components(): |
||
852 | if "bus0" in comp.df.columns: |
||
853 | network_solved.mremove( |
||
854 | comp.name, |
||
855 | comp.df[~comp.df.bus0.isin(network_solved.buses.index)].index, |
||
856 | ) |
||
857 | network_solved.mremove( |
||
858 | comp.name, |
||
859 | comp.df[~comp.df.bus1.isin(network_solved.buses.index)].index, |
||
860 | ) |
||
861 | elif "bus" in comp.df.columns: |
||
862 | network_solved.mremove( |
||
863 | comp.name, |
||
864 | comp.df[~comp.df.bus.isin(network_solved.buses.index)].index, |
||
865 | ) |
||
866 | |||
867 | # Combine urban decentral and rural heat |
||
868 | network_prepared, network_solved = combine_decentral_and_rural_heat( |
||
869 | network_solved, network_prepared |
||
870 | ) |
||
871 | |||
872 | # writing components of neighboring countries to etrago tables |
||
873 | |||
874 | # Set country tag for all buses |
||
875 | network_solved.buses.country = network_solved.buses.index.str[:2] |
||
876 | neighbors = network_solved.buses[network_solved.buses.country != "DE"] |
||
877 | |||
878 | neighbors["new_index"] = ( |
||
879 | db.next_etrago_id("bus") + neighbors.reset_index().index |
||
880 | ) |
||
881 | |||
882 | # Use index of AC buses created by electrical_neigbors |
||
883 | foreign_ac_buses = db.select_dataframe( |
||
884 | """ |
||
885 | SELECT * FROM grid.egon_etrago_bus |
||
886 | WHERE carrier = 'AC' AND v_nom = 380 |
||
887 | AND country!= 'DE' AND scn_name ='eGon100RE' |
||
888 | AND bus_id NOT IN (SELECT bus_i FROM osmtgmod_results.bus_data) |
||
889 | """ |
||
890 | ) |
||
891 | buses_with_defined_id = neighbors[ |
||
892 | (neighbors.carrier == "AC") |
||
893 | & (neighbors.country.isin(foreign_ac_buses.country.values)) |
||
894 | ].index |
||
895 | neighbors.loc[buses_with_defined_id, "new_index"] = ( |
||
896 | foreign_ac_buses.set_index("x") |
||
897 | .loc[neighbors.loc[buses_with_defined_id, "x"]] |
||
898 | .bus_id.values |
||
899 | ) |
||
900 | |||
901 | # lines, the foreign crossborder lines |
||
902 | # (without crossborder lines to Germany!) |
||
903 | |||
904 | neighbor_lines = network_solved.lines[ |
||
905 | network_solved.lines.bus0.isin(neighbors.index) |
||
906 | & network_solved.lines.bus1.isin(neighbors.index) |
||
907 | ] |
||
908 | if not network_solved.lines_t["s_max_pu"].empty: |
||
909 | neighbor_lines_t = network_prepared.lines_t["s_max_pu"][ |
||
910 | neighbor_lines.index |
||
911 | ] |
||
912 | |||
913 | neighbor_lines.reset_index(inplace=True) |
||
914 | neighbor_lines.bus0 = ( |
||
915 | neighbors.loc[neighbor_lines.bus0, "new_index"].reset_index().new_index |
||
916 | ) |
||
917 | neighbor_lines.bus1 = ( |
||
918 | neighbors.loc[neighbor_lines.bus1, "new_index"].reset_index().new_index |
||
919 | ) |
||
920 | neighbor_lines.index += db.next_etrago_id("line") |
||
921 | |||
922 | if not network_solved.lines_t["s_max_pu"].empty: |
||
923 | for i in neighbor_lines_t.columns: |
||
924 | new_index = neighbor_lines[neighbor_lines["name"] == i].index |
||
925 | neighbor_lines_t.rename(columns={i: new_index[0]}, inplace=True) |
||
926 | |||
927 | # links |
||
928 | neighbor_links = network_solved.links[ |
||
929 | network_solved.links.bus0.isin(neighbors.index) |
||
930 | & network_solved.links.bus1.isin(neighbors.index) |
||
931 | ] |
||
932 | |||
933 | neighbor_links.reset_index(inplace=True) |
||
934 | neighbor_links.bus0 = ( |
||
935 | neighbors.loc[neighbor_links.bus0, "new_index"].reset_index().new_index |
||
936 | ) |
||
937 | neighbor_links.bus1 = ( |
||
938 | neighbors.loc[neighbor_links.bus1, "new_index"].reset_index().new_index |
||
939 | ) |
||
940 | neighbor_links.index += db.next_etrago_id("link") |
||
941 | |||
942 | # generators |
||
943 | neighbor_gens = network_solved.generators[ |
||
944 | network_solved.generators.bus.isin(neighbors.index) |
||
945 | ] |
||
946 | neighbor_gens_t = network_prepared.generators_t["p_max_pu"][ |
||
947 | neighbor_gens[ |
||
948 | neighbor_gens.index.isin( |
||
949 | network_prepared.generators_t["p_max_pu"].columns |
||
950 | ) |
||
951 | ].index |
||
952 | ] |
||
953 | |||
954 | gen_time = [ |
||
955 | "solar", |
||
956 | "onwind", |
||
957 | "solar rooftop", |
||
958 | "offwind-ac", |
||
959 | "offwind-dc", |
||
960 | "solar-hsat", |
||
961 | "urban central solar thermal", |
||
962 | "rural solar thermal", |
||
963 | "offwind-float", |
||
964 | ] |
||
965 | |||
966 | missing_gent = neighbor_gens[ |
||
967 | neighbor_gens["carrier"].isin(gen_time) |
||
968 | & ~neighbor_gens.index.isin(neighbor_gens_t.columns) |
||
969 | ].index |
||
970 | |||
971 | gen_timeseries = network_prepared.generators_t["p_max_pu"].copy() |
||
972 | for mgt in missing_gent: # mgt: missing generator timeseries |
||
973 | try: |
||
974 | neighbor_gens_t[mgt] = gen_timeseries.loc[:, mgt[0:-5]] |
||
975 | except: |
||
976 | print(f"There are not timeseries for {mgt}") |
||
977 | |||
978 | neighbor_gens.reset_index(inplace=True) |
||
979 | neighbor_gens.bus = ( |
||
980 | neighbors.loc[neighbor_gens.bus, "new_index"].reset_index().new_index |
||
981 | ) |
||
982 | neighbor_gens.index += db.next_etrago_id("generator") |
||
983 | |||
984 | for i in neighbor_gens_t.columns: |
||
985 | new_index = neighbor_gens[neighbor_gens["Generator"] == i].index |
||
986 | neighbor_gens_t.rename(columns={i: new_index[0]}, inplace=True) |
||
987 | |||
988 | # loads |
||
989 | # imported from prenetwork in 1h-resolution |
||
990 | neighbor_loads = network_prepared.loads[ |
||
991 | network_prepared.loads.bus.isin(neighbors.index) |
||
992 | ] |
||
993 | neighbor_loads_t_index = neighbor_loads.index[ |
||
994 | neighbor_loads.index.isin(network_prepared.loads_t.p_set.columns) |
||
995 | ] |
||
996 | neighbor_loads_t = network_prepared.loads_t["p_set"][ |
||
997 | neighbor_loads_t_index |
||
998 | ] |
||
999 | |||
1000 | neighbor_loads.reset_index(inplace=True) |
||
1001 | neighbor_loads.bus = ( |
||
1002 | neighbors.loc[neighbor_loads.bus, "new_index"].reset_index().new_index |
||
1003 | ) |
||
1004 | neighbor_loads.index += db.next_etrago_id("load") |
||
1005 | |||
1006 | for i in neighbor_loads_t.columns: |
||
1007 | new_index = neighbor_loads[neighbor_loads["Load"] == i].index |
||
1008 | neighbor_loads_t.rename(columns={i: new_index[0]}, inplace=True) |
||
1009 | |||
1010 | # stores |
||
1011 | neighbor_stores = network_solved.stores[ |
||
1012 | network_solved.stores.bus.isin(neighbors.index) |
||
1013 | ] |
||
1014 | neighbor_stores_t_index = neighbor_stores.index[ |
||
1015 | neighbor_stores.index.isin(network_solved.stores_t.e_min_pu.columns) |
||
1016 | ] |
||
1017 | neighbor_stores_t = network_prepared.stores_t["e_min_pu"][ |
||
1018 | neighbor_stores_t_index |
||
1019 | ] |
||
1020 | |||
1021 | neighbor_stores.reset_index(inplace=True) |
||
1022 | neighbor_stores.bus = ( |
||
1023 | neighbors.loc[neighbor_stores.bus, "new_index"].reset_index().new_index |
||
1024 | ) |
||
1025 | neighbor_stores.index += db.next_etrago_id("store") |
||
1026 | |||
1027 | for i in neighbor_stores_t.columns: |
||
1028 | new_index = neighbor_stores[neighbor_stores["Store"] == i].index |
||
1029 | neighbor_stores_t.rename(columns={i: new_index[0]}, inplace=True) |
||
1030 | |||
1031 | # storage_units |
||
1032 | neighbor_storage = network_solved.storage_units[ |
||
1033 | network_solved.storage_units.bus.isin(neighbors.index) |
||
1034 | ] |
||
1035 | neighbor_storage_t_index = neighbor_storage.index[ |
||
1036 | neighbor_storage.index.isin( |
||
1037 | network_solved.storage_units_t.inflow.columns |
||
1038 | ) |
||
1039 | ] |
||
1040 | neighbor_storage_t = network_prepared.storage_units_t["inflow"][ |
||
1041 | neighbor_storage_t_index |
||
1042 | ] |
||
1043 | |||
1044 | neighbor_storage.reset_index(inplace=True) |
||
1045 | neighbor_storage.bus = ( |
||
1046 | neighbors.loc[neighbor_storage.bus, "new_index"] |
||
1047 | .reset_index() |
||
1048 | .new_index |
||
1049 | ) |
||
1050 | neighbor_storage.index += db.next_etrago_id("storage") |
||
1051 | |||
1052 | for i in neighbor_storage_t.columns: |
||
1053 | new_index = neighbor_storage[ |
||
1054 | neighbor_storage["StorageUnit"] == i |
||
1055 | ].index |
||
1056 | neighbor_storage_t.rename(columns={i: new_index[0]}, inplace=True) |
||
1057 | |||
1058 | # Connect to local database |
||
1059 | engine = db.engine() |
||
1060 | |||
1061 | neighbors["scn_name"] = "eGon100RE" |
||
1062 | neighbors.index = neighbors["new_index"] |
||
1063 | |||
1064 | # Correct geometry for non AC buses |
||
1065 | carriers = set(neighbors.carrier.to_list()) |
||
1066 | carriers = [e for e in carriers if e not in ("AC")] |
||
1067 | non_AC_neighbors = pd.DataFrame() |
||
1068 | for c in carriers: |
||
1069 | c_neighbors = neighbors[neighbors.carrier == c].set_index( |
||
1070 | "location", drop=False |
||
1071 | ) |
||
1072 | for i in ["x", "y"]: |
||
1073 | c_neighbors = c_neighbors.drop(i, axis=1) |
||
1074 | coordinates = neighbors[neighbors.carrier == "AC"][ |
||
1075 | ["location", "x", "y"] |
||
1076 | ].set_index("location") |
||
1077 | c_neighbors = pd.concat([coordinates, c_neighbors], axis=1).set_index( |
||
1078 | "new_index", drop=False |
||
1079 | ) |
||
1080 | non_AC_neighbors = pd.concat([non_AC_neighbors, c_neighbors]) |
||
1081 | |||
1082 | neighbors = pd.concat( |
||
1083 | [neighbors[neighbors.carrier == "AC"], non_AC_neighbors] |
||
1084 | ) |
||
1085 | |||
1086 | for i in [ |
||
1087 | "new_index", |
||
1088 | "control", |
||
1089 | "generator", |
||
1090 | "location", |
||
1091 | "sub_network", |
||
1092 | "unit", |
||
1093 | "substation_lv", |
||
1094 | "substation_off", |
||
1095 | ]: |
||
1096 | neighbors = neighbors.drop(i, axis=1) |
||
1097 | |||
1098 | # Add geometry column |
||
1099 | neighbors = ( |
||
1100 | gpd.GeoDataFrame( |
||
1101 | neighbors, geometry=gpd.points_from_xy(neighbors.x, neighbors.y) |
||
1102 | ) |
||
1103 | .rename_geometry("geom") |
||
1104 | .set_crs(4326) |
||
1105 | ) |
||
1106 | |||
1107 | # Unify carrier names |
||
1108 | neighbors.carrier = neighbors.carrier.str.replace(" ", "_") |
||
1109 | neighbors.carrier.replace( |
||
1110 | { |
||
1111 | "gas": "CH4", |
||
1112 | "gas_for_industry": "CH4_for_industry", |
||
1113 | "urban_central_heat": "central_heat", |
||
1114 | "EV_battery": "Li_ion", |
||
1115 | "urban_central_water_tanks": "central_heat_store", |
||
1116 | "rural_water_tanks": "rural_heat_store", |
||
1117 | }, |
||
1118 | inplace=True, |
||
1119 | ) |
||
1120 | |||
1121 | neighbors[~neighbors.carrier.isin(["AC"])].to_postgis( |
||
1122 | "egon_etrago_bus", |
||
1123 | engine, |
||
1124 | schema="grid", |
||
1125 | if_exists="append", |
||
1126 | index=True, |
||
1127 | index_label="bus_id", |
||
1128 | ) |
||
1129 | |||
1130 | # prepare and write neighboring crossborder lines to etrago tables |
||
1131 | def lines_to_etrago(neighbor_lines=neighbor_lines, scn="eGon100RE"): |
||
1132 | neighbor_lines["scn_name"] = scn |
||
1133 | neighbor_lines["cables"] = 3 * neighbor_lines["num_parallel"].astype( |
||
1134 | int |
||
1135 | ) |
||
1136 | neighbor_lines["s_nom"] = neighbor_lines["s_nom_min"] |
||
1137 | |||
1138 | for i in [ |
||
1139 | "Line", |
||
1140 | "x_pu_eff", |
||
1141 | "r_pu_eff", |
||
1142 | "sub_network", |
||
1143 | "x_pu", |
||
1144 | "r_pu", |
||
1145 | "g_pu", |
||
1146 | "b_pu", |
||
1147 | "s_nom_opt", |
||
1148 | "i_nom", |
||
1149 | "dc", |
||
1150 | ]: |
||
1151 | neighbor_lines = neighbor_lines.drop(i, axis=1) |
||
1152 | |||
1153 | # Define geometry and add to lines dataframe as 'topo' |
||
1154 | gdf = gpd.GeoDataFrame(index=neighbor_lines.index) |
||
1155 | gdf["geom_bus0"] = neighbors.geom[neighbor_lines.bus0].values |
||
1156 | gdf["geom_bus1"] = neighbors.geom[neighbor_lines.bus1].values |
||
1157 | gdf["geometry"] = gdf.apply( |
||
1158 | lambda x: LineString([x["geom_bus0"], x["geom_bus1"]]), axis=1 |
||
1159 | ) |
||
1160 | |||
1161 | neighbor_lines = ( |
||
1162 | gpd.GeoDataFrame(neighbor_lines, geometry=gdf["geometry"]) |
||
1163 | .rename_geometry("topo") |
||
1164 | .set_crs(4326) |
||
1165 | ) |
||
1166 | |||
1167 | neighbor_lines["lifetime"] = get_sector_parameters("electricity", scn)[ |
||
1168 | "lifetime" |
||
1169 | ]["ac_ehv_overhead_line"] |
||
1170 | |||
1171 | neighbor_lines.to_postgis( |
||
1172 | "egon_etrago_line", |
||
1173 | engine, |
||
1174 | schema="grid", |
||
1175 | if_exists="append", |
||
1176 | index=True, |
||
1177 | index_label="line_id", |
||
1178 | ) |
||
1179 | |||
1180 | lines_to_etrago(neighbor_lines=neighbor_lines, scn="eGon100RE") |
||
1181 | |||
1182 | def links_to_etrago(neighbor_links, scn="eGon100RE", extendable=True): |
||
1183 | """Prepare and write neighboring crossborder links to eTraGo table |
||
1184 | |||
1185 | This function prepare the neighboring crossborder links |
||
1186 | generated the PyPSA-eur-sec (p-e-s) run by: |
||
1187 | * Delete the useless columns |
||
1188 | * If extendable is false only (non default case): |
||
1189 | * Replace p_nom = 0 with the p_nom_op values (arrising |
||
1190 | from the p-e-s optimisation) |
||
1191 | * Setting p_nom_extendable to false |
||
1192 | * Add geomtry to the links: 'geom' and 'topo' columns |
||
1193 | * Change the name of the carriers to have the consistent in |
||
1194 | eGon-data |
||
1195 | |||
1196 | The function insert then the link to the eTraGo table and has |
||
1197 | no return. |
||
1198 | |||
1199 | Parameters |
||
1200 | ---------- |
||
1201 | neighbor_links : pandas.DataFrame |
||
1202 | Dataframe containing the neighboring crossborder links |
||
1203 | scn_name : str |
||
1204 | Name of the scenario |
||
1205 | extendable : bool |
||
1206 | Boolean expressing if the links should be extendable or not |
||
1207 | |||
1208 | Returns |
||
1209 | ------- |
||
1210 | None |
||
1211 | |||
1212 | """ |
||
1213 | neighbor_links["scn_name"] = scn |
||
1214 | |||
1215 | dropped_carriers = [ |
||
1216 | "Link", |
||
1217 | "geometry", |
||
1218 | "tags", |
||
1219 | "under_construction", |
||
1220 | "underground", |
||
1221 | "underwater_fraction", |
||
1222 | "bus2", |
||
1223 | "bus3", |
||
1224 | "bus4", |
||
1225 | "efficiency2", |
||
1226 | "efficiency3", |
||
1227 | "efficiency4", |
||
1228 | "lifetime", |
||
1229 | "pipe_retrofit", |
||
1230 | "committable", |
||
1231 | "start_up_cost", |
||
1232 | "shut_down_cost", |
||
1233 | "min_up_time", |
||
1234 | "min_down_time", |
||
1235 | "up_time_before", |
||
1236 | "down_time_before", |
||
1237 | "ramp_limit_up", |
||
1238 | "ramp_limit_down", |
||
1239 | "ramp_limit_start_up", |
||
1240 | "ramp_limit_shut_down", |
||
1241 | "length_original", |
||
1242 | "reversed", |
||
1243 | "location", |
||
1244 | "project_status", |
||
1245 | "dc", |
||
1246 | "voltage", |
||
1247 | ] |
||
1248 | |||
1249 | if extendable: |
||
1250 | dropped_carriers.append("p_nom_opt") |
||
1251 | neighbor_links = neighbor_links.drop( |
||
1252 | columns=dropped_carriers, |
||
1253 | errors="ignore", |
||
1254 | ) |
||
1255 | |||
1256 | else: |
||
1257 | dropped_carriers.append("p_nom") |
||
1258 | dropped_carriers.append("p_nom_extendable") |
||
1259 | neighbor_links = neighbor_links.drop( |
||
1260 | columns=dropped_carriers, |
||
1261 | errors="ignore", |
||
1262 | ) |
||
1263 | neighbor_links = neighbor_links.rename( |
||
1264 | columns={"p_nom_opt": "p_nom"} |
||
1265 | ) |
||
1266 | neighbor_links["p_nom_extendable"] = False |
||
1267 | |||
1268 | if neighbor_links.empty: |
||
1269 | print("No links selected") |
||
1270 | return |
||
1271 | |||
1272 | # Define geometry and add to lines dataframe as 'topo' |
||
1273 | gdf = gpd.GeoDataFrame( |
||
1274 | index=neighbor_links.index, |
||
1275 | data={ |
||
1276 | "geom_bus0": neighbors.loc[neighbor_links.bus0, "geom"].values, |
||
1277 | "geom_bus1": neighbors.loc[neighbor_links.bus1, "geom"].values, |
||
1278 | }, |
||
1279 | ) |
||
1280 | |||
1281 | gdf["geometry"] = gdf.apply( |
||
1282 | lambda x: LineString([x["geom_bus0"], x["geom_bus1"]]), axis=1 |
||
1283 | ) |
||
1284 | |||
1285 | neighbor_links = ( |
||
1286 | gpd.GeoDataFrame(neighbor_links, geometry=gdf["geometry"]) |
||
1287 | .rename_geometry("topo") |
||
1288 | .set_crs(4326) |
||
1289 | ) |
||
1290 | |||
1291 | # Unify carrier names |
||
1292 | neighbor_links.carrier = neighbor_links.carrier.str.replace(" ", "_") |
||
1293 | |||
1294 | neighbor_links.carrier.replace( |
||
1295 | { |
||
1296 | "H2_Electrolysis": "power_to_H2", |
||
1297 | "H2_Fuel_Cell": "H2_to_power", |
||
1298 | "H2_pipeline_retrofitted": "H2_retrofit", |
||
1299 | "SMR": "CH4_to_H2", |
||
1300 | "Sabatier": "H2_to_CH4", |
||
1301 | "gas_for_industry": "CH4_for_industry", |
||
1302 | "gas_pipeline": "CH4", |
||
1303 | "urban_central_gas_boiler": "central_gas_boiler", |
||
1304 | "urban_central_resistive_heater": "central_resistive_heater", |
||
1305 | "urban_central_water_tanks_charger": "central_heat_store_charger", |
||
1306 | "urban_central_water_tanks_discharger": "central_heat_store_discharger", |
||
1307 | "rural_water_tanks_charger": "rural_heat_store_charger", |
||
1308 | "rural_water_tanks_discharger": "rural_heat_store_discharger", |
||
1309 | "urban_central_gas_CHP": "central_gas_CHP", |
||
1310 | "urban_central_air_heat_pump": "central_heat_pump", |
||
1311 | "rural_ground_heat_pump": "rural_heat_pump", |
||
1312 | }, |
||
1313 | inplace=True, |
||
1314 | ) |
||
1315 | |||
1316 | H2_links = { |
||
1317 | "H2_to_CH4": "H2_to_CH4", |
||
1318 | "H2_to_power": "H2_to_power", |
||
1319 | "power_to_H2": "power_to_H2_system", |
||
1320 | "CH4_to_H2": "CH4_to_H2", |
||
1321 | } |
||
1322 | |||
1323 | for c in H2_links.keys(): |
||
1324 | |||
1325 | neighbor_links.loc[ |
||
1326 | (neighbor_links.carrier == c), |
||
1327 | "lifetime", |
||
1328 | ] = get_sector_parameters("gas", "eGon100RE")["lifetime"][ |
||
1329 | H2_links[c] |
||
1330 | ] |
||
1331 | |||
1332 | neighbor_links.to_postgis( |
||
1333 | "egon_etrago_link", |
||
1334 | engine, |
||
1335 | schema="grid", |
||
1336 | if_exists="append", |
||
1337 | index=True, |
||
1338 | index_label="link_id", |
||
1339 | ) |
||
1340 | |||
1341 | extendable_links_carriers = [ |
||
1342 | "battery charger", |
||
1343 | "battery discharger", |
||
1344 | "home battery charger", |
||
1345 | "home battery discharger", |
||
1346 | "rural water tanks charger", |
||
1347 | "rural water tanks discharger", |
||
1348 | "urban central water tanks charger", |
||
1349 | "urban central water tanks discharger", |
||
1350 | "urban decentral water tanks charger", |
||
1351 | "urban decentral water tanks discharger", |
||
1352 | "H2 Electrolysis", |
||
1353 | "H2 Fuel Cell", |
||
1354 | "SMR", |
||
1355 | "Sabatier", |
||
1356 | ] |
||
1357 | |||
1358 | # delete unwanted carriers for eTraGo |
||
1359 | excluded_carriers = [ |
||
1360 | "gas for industry CC", |
||
1361 | "SMR CC", |
||
1362 | "DAC", |
||
1363 | ] |
||
1364 | neighbor_links = neighbor_links[ |
||
1365 | ~neighbor_links.carrier.isin(excluded_carriers) |
||
1366 | ] |
||
1367 | |||
1368 | # Combine CHP_CC and CHP |
||
1369 | chp_cc = neighbor_links[ |
||
1370 | neighbor_links.carrier == "urban central gas CHP CC" |
||
1371 | ] |
||
1372 | for index, row in chp_cc.iterrows(): |
||
1373 | neighbor_links.loc[ |
||
1374 | neighbor_links.Link == row.Link.replace("CHP CC", "CHP"), |
||
1375 | "p_nom_opt", |
||
1376 | ] += row.p_nom_opt |
||
1377 | neighbor_links.loc[ |
||
1378 | neighbor_links.Link == row.Link.replace("CHP CC", "CHP"), "p_nom" |
||
1379 | ] += row.p_nom |
||
1380 | neighbor_links.drop(index, inplace=True) |
||
1381 | |||
1382 | # Combine heat pumps |
||
1383 | # Like in Germany, there are air heat pumps in central heat grids |
||
1384 | # and ground heat pumps in rural areas |
||
1385 | rural_air = neighbor_links[neighbor_links.carrier == "rural air heat pump"] |
||
1386 | for index, row in rural_air.iterrows(): |
||
1387 | neighbor_links.loc[ |
||
1388 | neighbor_links.Link == row.Link.replace("air", "ground"), |
||
1389 | "p_nom_opt", |
||
1390 | ] += row.p_nom_opt |
||
1391 | neighbor_links.loc[ |
||
1392 | neighbor_links.Link == row.Link.replace("air", "ground"), "p_nom" |
||
1393 | ] += row.p_nom |
||
1394 | neighbor_links.drop(index, inplace=True) |
||
1395 | links_to_etrago( |
||
1396 | neighbor_links[neighbor_links.carrier.isin(extendable_links_carriers)], |
||
1397 | "eGon100RE", |
||
1398 | ) |
||
1399 | links_to_etrago( |
||
1400 | neighbor_links[ |
||
1401 | ~neighbor_links.carrier.isin(extendable_links_carriers) |
||
1402 | ], |
||
1403 | "eGon100RE", |
||
1404 | extendable=False, |
||
1405 | ) |
||
1406 | # Include links time-series |
||
1407 | # For heat_pumps |
||
1408 | hp = neighbor_links[neighbor_links["carrier"].str.contains("heat pump")] |
||
1409 | |||
1410 | neighbor_eff_t = network_prepared.links_t["efficiency"][ |
||
1411 | hp[hp.Link.isin(network_prepared.links_t["efficiency"].columns)].index |
||
1412 | ] |
||
1413 | |||
1414 | missing_hp = hp[~hp["Link"].isin(neighbor_eff_t.columns)].Link |
||
1415 | |||
1416 | eff_timeseries = network_prepared.links_t["efficiency"].copy() |
||
1417 | for met in missing_hp: # met: missing efficiency timeseries |
||
1418 | try: |
||
1419 | neighbor_eff_t[met] = eff_timeseries.loc[:, met[0:-5]] |
||
1420 | except: |
||
1421 | print(f"There are not timeseries for heat_pump {met}") |
||
1422 | |||
1423 | for i in neighbor_eff_t.columns: |
||
1424 | new_index = neighbor_links[neighbor_links["Link"] == i].index |
||
1425 | neighbor_eff_t.rename(columns={i: new_index[0]}, inplace=True) |
||
1426 | |||
1427 | # Include links time-series |
||
1428 | # For ev_chargers |
||
1429 | ev = neighbor_links[neighbor_links["carrier"].str.contains("BEV charger")] |
||
1430 | |||
1431 | ev_p_max_pu = network_prepared.links_t["p_max_pu"][ |
||
1432 | ev[ev.Link.isin(network_prepared.links_t["p_max_pu"].columns)].index |
||
1433 | ] |
||
1434 | |||
1435 | missing_ev = ev[~ev["Link"].isin(ev_p_max_pu.columns)].Link |
||
1436 | |||
1437 | ev_p_max_pu_timeseries = network_prepared.links_t["p_max_pu"].copy() |
||
1438 | for mct in missing_ev: # evt: missing charger timeseries |
||
1439 | try: |
||
1440 | ev_p_max_pu[mct] = ev_p_max_pu_timeseries.loc[:, mct[0:-5]] |
||
1441 | except: |
||
1442 | print(f"There are not timeseries for EV charger {mct}") |
||
1443 | |||
1444 | for i in ev_p_max_pu.columns: |
||
1445 | new_index = neighbor_links[neighbor_links["Link"] == i].index |
||
1446 | ev_p_max_pu.rename(columns={i: new_index[0]}, inplace=True) |
||
1447 | |||
1448 | # prepare neighboring generators for etrago tables |
||
1449 | neighbor_gens["scn_name"] = "eGon100RE" |
||
1450 | neighbor_gens["p_nom"] = neighbor_gens["p_nom_opt"] |
||
1451 | neighbor_gens["p_nom_extendable"] = False |
||
1452 | |||
1453 | # Unify carrier names |
||
1454 | neighbor_gens.carrier = neighbor_gens.carrier.str.replace(" ", "_") |
||
1455 | |||
1456 | neighbor_gens.carrier.replace( |
||
1457 | { |
||
1458 | "onwind": "wind_onshore", |
||
1459 | "ror": "run_of_river", |
||
1460 | "offwind-ac": "wind_offshore", |
||
1461 | "offwind-dc": "wind_offshore", |
||
1462 | "offwind-float": "wind_offshore", |
||
1463 | "urban_central_solar_thermal": "urban_central_solar_thermal_collector", |
||
1464 | "residential_rural_solar_thermal": "residential_rural_solar_thermal_collector", |
||
1465 | "services_rural_solar_thermal": "services_rural_solar_thermal_collector", |
||
1466 | "solar-hsat": "solar", |
||
1467 | }, |
||
1468 | inplace=True, |
||
1469 | ) |
||
1470 | |||
1471 | for i in [ |
||
1472 | "Generator", |
||
1473 | "weight", |
||
1474 | "lifetime", |
||
1475 | "p_set", |
||
1476 | "q_set", |
||
1477 | "p_nom_opt", |
||
1478 | "e_sum_min", |
||
1479 | "e_sum_max", |
||
1480 | ]: |
||
1481 | neighbor_gens = neighbor_gens.drop(i, axis=1) |
||
1482 | |||
1483 | neighbor_gens.to_sql( |
||
1484 | "egon_etrago_generator", |
||
1485 | engine, |
||
1486 | schema="grid", |
||
1487 | if_exists="append", |
||
1488 | index=True, |
||
1489 | index_label="generator_id", |
||
1490 | ) |
||
1491 | |||
1492 | # prepare neighboring loads for etrago tables |
||
1493 | neighbor_loads["scn_name"] = "eGon100RE" |
||
1494 | |||
1495 | # Unify carrier names |
||
1496 | neighbor_loads.carrier = neighbor_loads.carrier.str.replace(" ", "_") |
||
1497 | |||
1498 | neighbor_loads.carrier.replace( |
||
1499 | { |
||
1500 | "electricity": "AC", |
||
1501 | "DC": "AC", |
||
1502 | "industry_electricity": "AC", |
||
1503 | "H2_pipeline_retrofitted": "H2_system_boundary", |
||
1504 | "gas_pipeline": "CH4_system_boundary", |
||
1505 | "gas_for_industry": "CH4_for_industry", |
||
1506 | "urban_central_heat": "central_heat", |
||
1507 | }, |
||
1508 | inplace=True, |
||
1509 | ) |
||
1510 | |||
1511 | neighbor_loads = neighbor_loads.drop( |
||
1512 | columns=["Load"], |
||
1513 | errors="ignore", |
||
1514 | ) |
||
1515 | |||
1516 | neighbor_loads.to_sql( |
||
1517 | "egon_etrago_load", |
||
1518 | engine, |
||
1519 | schema="grid", |
||
1520 | if_exists="append", |
||
1521 | index=True, |
||
1522 | index_label="load_id", |
||
1523 | ) |
||
1524 | |||
1525 | # prepare neighboring stores for etrago tables |
||
1526 | neighbor_stores["scn_name"] = "eGon100RE" |
||
1527 | |||
1528 | # Unify carrier names |
||
1529 | neighbor_stores.carrier = neighbor_stores.carrier.str.replace(" ", "_") |
||
1530 | |||
1531 | neighbor_stores.carrier.replace( |
||
1532 | { |
||
1533 | "Li_ion": "battery", |
||
1534 | "gas": "CH4", |
||
1535 | "urban_central_water_tanks": "central_heat_store", |
||
1536 | "rural_water_tanks": "rural_heat_store", |
||
1537 | "EV_battery": "battery_storage", |
||
1538 | }, |
||
1539 | inplace=True, |
||
1540 | ) |
||
1541 | neighbor_stores.loc[ |
||
1542 | ( |
||
1543 | (neighbor_stores.e_nom_max <= 1e9) |
||
1544 | & (neighbor_stores.carrier == "H2_Store") |
||
1545 | ), |
||
1546 | "carrier", |
||
1547 | ] = "H2_underground" |
||
1548 | neighbor_stores.loc[ |
||
1549 | ( |
||
1550 | (neighbor_stores.e_nom_max > 1e9) |
||
1551 | & (neighbor_stores.carrier == "H2_Store") |
||
1552 | ), |
||
1553 | "carrier", |
||
1554 | ] = "H2_overground" |
||
1555 | |||
1556 | for i in [ |
||
1557 | "Store", |
||
1558 | "p_set", |
||
1559 | "q_set", |
||
1560 | "e_nom_opt", |
||
1561 | "lifetime", |
||
1562 | "e_initial_per_period", |
||
1563 | "e_cyclic_per_period", |
||
1564 | "location", |
||
1565 | ]: |
||
1566 | neighbor_stores = neighbor_stores.drop(i, axis=1, errors="ignore") |
||
1567 | |||
1568 | for c in ["H2_underground", "H2_overground"]: |
||
1569 | neighbor_stores.loc[ |
||
1570 | (neighbor_stores.carrier == c), |
||
1571 | "lifetime", |
||
1572 | ] = get_sector_parameters("gas", "eGon100RE")["lifetime"][c] |
||
1573 | |||
1574 | neighbor_stores.to_sql( |
||
1575 | "egon_etrago_store", |
||
1576 | engine, |
||
1577 | schema="grid", |
||
1578 | if_exists="append", |
||
1579 | index=True, |
||
1580 | index_label="store_id", |
||
1581 | ) |
||
1582 | |||
1583 | # prepare neighboring storage_units for etrago tables |
||
1584 | neighbor_storage["scn_name"] = "eGon100RE" |
||
1585 | |||
1586 | # Unify carrier names |
||
1587 | neighbor_storage.carrier = neighbor_storage.carrier.str.replace(" ", "_") |
||
1588 | |||
1589 | neighbor_storage.carrier.replace( |
||
1590 | {"PHS": "pumped_hydro", "hydro": "reservoir"}, inplace=True |
||
1591 | ) |
||
1592 | |||
1593 | for i in [ |
||
1594 | "StorageUnit", |
||
1595 | "p_nom_opt", |
||
1596 | "state_of_charge_initial_per_period", |
||
1597 | "cyclic_state_of_charge_per_period", |
||
1598 | ]: |
||
1599 | neighbor_storage = neighbor_storage.drop(i, axis=1, errors="ignore") |
||
1600 | |||
1601 | neighbor_storage.to_sql( |
||
1602 | "egon_etrago_storage", |
||
1603 | engine, |
||
1604 | schema="grid", |
||
1605 | if_exists="append", |
||
1606 | index=True, |
||
1607 | index_label="storage_id", |
||
1608 | ) |
||
1609 | |||
1610 | # writing neighboring loads_t p_sets to etrago tables |
||
1611 | |||
1612 | neighbor_loads_t_etrago = pd.DataFrame( |
||
1613 | columns=["scn_name", "temp_id", "p_set"], |
||
1614 | index=neighbor_loads_t.columns, |
||
1615 | ) |
||
1616 | neighbor_loads_t_etrago["scn_name"] = "eGon100RE" |
||
1617 | neighbor_loads_t_etrago["temp_id"] = 1 |
||
1618 | for i in neighbor_loads_t.columns: |
||
1619 | neighbor_loads_t_etrago["p_set"][i] = neighbor_loads_t[ |
||
1620 | i |
||
1621 | ].values.tolist() |
||
1622 | |||
1623 | neighbor_loads_t_etrago.to_sql( |
||
1624 | "egon_etrago_load_timeseries", |
||
1625 | engine, |
||
1626 | schema="grid", |
||
1627 | if_exists="append", |
||
1628 | index=True, |
||
1629 | index_label="load_id", |
||
1630 | ) |
||
1631 | |||
1632 | # writing neighboring link_t efficiency and p_max_pu to etrago tables |
||
1633 | neighbor_link_t_etrago = pd.DataFrame( |
||
1634 | columns=["scn_name", "temp_id", "p_max_pu", "efficiency"], |
||
1635 | index=neighbor_eff_t.columns.to_list() + ev_p_max_pu.columns.to_list(), |
||
1636 | ) |
||
1637 | neighbor_link_t_etrago["scn_name"] = "eGon100RE" |
||
1638 | neighbor_link_t_etrago["temp_id"] = 1 |
||
1639 | for i in neighbor_eff_t.columns: |
||
1640 | neighbor_link_t_etrago["efficiency"][i] = neighbor_eff_t[ |
||
1641 | i |
||
1642 | ].values.tolist() |
||
1643 | for i in ev_p_max_pu.columns: |
||
1644 | neighbor_link_t_etrago["p_max_pu"][i] = ev_p_max_pu[i].values.tolist() |
||
1645 | |||
1646 | neighbor_link_t_etrago.to_sql( |
||
1647 | "egon_etrago_link_timeseries", |
||
1648 | engine, |
||
1649 | schema="grid", |
||
1650 | if_exists="append", |
||
1651 | index=True, |
||
1652 | index_label="link_id", |
||
1653 | ) |
||
1654 | |||
1655 | # writing neighboring generator_t p_max_pu to etrago tables |
||
1656 | neighbor_gens_t_etrago = pd.DataFrame( |
||
1657 | columns=["scn_name", "temp_id", "p_max_pu"], |
||
1658 | index=neighbor_gens_t.columns, |
||
1659 | ) |
||
1660 | neighbor_gens_t_etrago["scn_name"] = "eGon100RE" |
||
1661 | neighbor_gens_t_etrago["temp_id"] = 1 |
||
1662 | for i in neighbor_gens_t.columns: |
||
1663 | neighbor_gens_t_etrago["p_max_pu"][i] = neighbor_gens_t[ |
||
1664 | i |
||
1665 | ].values.tolist() |
||
1666 | |||
1667 | neighbor_gens_t_etrago.to_sql( |
||
1668 | "egon_etrago_generator_timeseries", |
||
1669 | engine, |
||
1670 | schema="grid", |
||
1671 | if_exists="append", |
||
1672 | index=True, |
||
1673 | index_label="generator_id", |
||
1674 | ) |
||
1675 | |||
1676 | # writing neighboring stores_t e_min_pu to etrago tables |
||
1677 | neighbor_stores_t_etrago = pd.DataFrame( |
||
1678 | columns=["scn_name", "temp_id", "e_min_pu"], |
||
1679 | index=neighbor_stores_t.columns, |
||
1680 | ) |
||
1681 | neighbor_stores_t_etrago["scn_name"] = "eGon100RE" |
||
1682 | neighbor_stores_t_etrago["temp_id"] = 1 |
||
1683 | for i in neighbor_stores_t.columns: |
||
1684 | neighbor_stores_t_etrago["e_min_pu"][i] = neighbor_stores_t[ |
||
1685 | i |
||
1686 | ].values.tolist() |
||
1687 | |||
1688 | neighbor_stores_t_etrago.to_sql( |
||
1689 | "egon_etrago_store_timeseries", |
||
1690 | engine, |
||
1691 | schema="grid", |
||
1692 | if_exists="append", |
||
1693 | index=True, |
||
1694 | index_label="store_id", |
||
1695 | ) |
||
1696 | |||
1697 | # writing neighboring storage_units inflow to etrago tables |
||
1698 | neighbor_storage_t_etrago = pd.DataFrame( |
||
1699 | columns=["scn_name", "temp_id", "inflow"], |
||
1700 | index=neighbor_storage_t.columns, |
||
1701 | ) |
||
1702 | neighbor_storage_t_etrago["scn_name"] = "eGon100RE" |
||
1703 | neighbor_storage_t_etrago["temp_id"] = 1 |
||
1704 | for i in neighbor_storage_t.columns: |
||
1705 | neighbor_storage_t_etrago["inflow"][i] = neighbor_storage_t[ |
||
1706 | i |
||
1707 | ].values.tolist() |
||
1708 | |||
1709 | neighbor_storage_t_etrago.to_sql( |
||
1710 | "egon_etrago_storage_timeseries", |
||
1711 | engine, |
||
1712 | schema="grid", |
||
1713 | if_exists="append", |
||
1714 | index=True, |
||
1715 | index_label="storage_id", |
||
1716 | ) |
||
1717 | |||
1718 | # writing neighboring lines_t s_max_pu to etrago tables |
||
1719 | if not network_solved.lines_t["s_max_pu"].empty: |
||
1720 | neighbor_lines_t_etrago = pd.DataFrame( |
||
1721 | columns=["scn_name", "s_max_pu"], index=neighbor_lines_t.columns |
||
1722 | ) |
||
1723 | neighbor_lines_t_etrago["scn_name"] = "eGon100RE" |
||
1724 | |||
1725 | for i in neighbor_lines_t.columns: |
||
1726 | neighbor_lines_t_etrago["s_max_pu"][i] = neighbor_lines_t[ |
||
1727 | i |
||
1728 | ].values.tolist() |
||
1729 | |||
1730 | neighbor_lines_t_etrago.to_sql( |
||
1731 | "egon_etrago_line_timeseries", |
||
1732 | engine, |
||
1733 | schema="grid", |
||
1734 | if_exists="append", |
||
1735 | index=True, |
||
1736 | index_label="line_id", |
||
1737 | ) |
||
2384 |