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