Conditions | 47 |
Total Lines | 1070 |
Code Lines | 725 |
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", len(neighbors.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", len(neighbor_lines.index)) |
||
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", len(neighbor_links.index)) |
||
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( |
||
984 | "generator", len(neighbor_gens.index)) |
||
985 | |||
986 | for i in neighbor_gens_t.columns: |
||
987 | new_index = neighbor_gens[neighbor_gens["Generator"] == i].index |
||
988 | neighbor_gens_t.rename(columns={i: new_index[0]}, inplace=True) |
||
989 | |||
990 | # loads |
||
991 | # imported from prenetwork in 1h-resolution |
||
992 | neighbor_loads = network_prepared.loads[ |
||
993 | network_prepared.loads.bus.isin(neighbors.index) |
||
994 | ] |
||
995 | neighbor_loads_t_index = neighbor_loads.index[ |
||
996 | neighbor_loads.index.isin(network_prepared.loads_t.p_set.columns) |
||
997 | ] |
||
998 | neighbor_loads_t = network_prepared.loads_t["p_set"][ |
||
999 | neighbor_loads_t_index |
||
1000 | ] |
||
1001 | |||
1002 | neighbor_loads.reset_index(inplace=True) |
||
1003 | neighbor_loads.bus = ( |
||
1004 | neighbors.loc[neighbor_loads.bus, "new_index"].reset_index().new_index |
||
1005 | ) |
||
1006 | neighbor_loads.index = db.next_etrago_id("load", len(neighbor_loads.index)) |
||
1007 | |||
1008 | for i in neighbor_loads_t.columns: |
||
1009 | new_index = neighbor_loads[neighbor_loads["Load"] == i].index |
||
1010 | neighbor_loads_t.rename(columns={i: new_index[0]}, inplace=True) |
||
1011 | |||
1012 | # stores |
||
1013 | neighbor_stores = network_solved.stores[ |
||
1014 | network_solved.stores.bus.isin(neighbors.index) |
||
1015 | ] |
||
1016 | neighbor_stores_t_index = neighbor_stores.index[ |
||
1017 | neighbor_stores.index.isin(network_solved.stores_t.e_min_pu.columns) |
||
1018 | ] |
||
1019 | neighbor_stores_t = network_prepared.stores_t["e_min_pu"][ |
||
1020 | neighbor_stores_t_index |
||
1021 | ] |
||
1022 | |||
1023 | neighbor_stores.reset_index(inplace=True) |
||
1024 | neighbor_stores.bus = ( |
||
1025 | neighbors.loc[neighbor_stores.bus, "new_index"].reset_index().new_index |
||
1026 | ) |
||
1027 | neighbor_stores.index = db.next_etrago_id( |
||
1028 | "store", len(neighbor_stores.index)) |
||
1029 | |||
1030 | for i in neighbor_stores_t.columns: |
||
1031 | new_index = neighbor_stores[neighbor_stores["Store"] == i].index |
||
1032 | neighbor_stores_t.rename(columns={i: new_index[0]}, inplace=True) |
||
1033 | |||
1034 | # storage_units |
||
1035 | neighbor_storage = network_solved.storage_units[ |
||
1036 | network_solved.storage_units.bus.isin(neighbors.index) |
||
1037 | ] |
||
1038 | neighbor_storage_t_index = neighbor_storage.index[ |
||
1039 | neighbor_storage.index.isin( |
||
1040 | network_solved.storage_units_t.inflow.columns |
||
1041 | ) |
||
1042 | ] |
||
1043 | neighbor_storage_t = network_prepared.storage_units_t["inflow"][ |
||
1044 | neighbor_storage_t_index |
||
1045 | ] |
||
1046 | |||
1047 | neighbor_storage.reset_index(inplace=True) |
||
1048 | neighbor_storage.bus = ( |
||
1049 | neighbors.loc[neighbor_storage.bus, "new_index"] |
||
1050 | .reset_index() |
||
1051 | .new_index |
||
1052 | ) |
||
1053 | neighbor_storage.index = db.next_etrago_id( |
||
1054 | "storage", len(neighbor_storage.index)) |
||
1055 | |||
1056 | for i in neighbor_storage_t.columns: |
||
1057 | new_index = neighbor_storage[ |
||
1058 | neighbor_storage["StorageUnit"] == i |
||
1059 | ].index |
||
1060 | neighbor_storage_t.rename(columns={i: new_index[0]}, inplace=True) |
||
1061 | |||
1062 | # Connect to local database |
||
1063 | engine = db.engine() |
||
1064 | |||
1065 | neighbors["scn_name"] = "eGon100RE" |
||
1066 | neighbors.index = neighbors["new_index"] |
||
1067 | |||
1068 | # Correct geometry for non AC buses |
||
1069 | carriers = set(neighbors.carrier.to_list()) |
||
1070 | carriers = [e for e in carriers if e not in ("AC")] |
||
1071 | non_AC_neighbors = pd.DataFrame() |
||
1072 | for c in carriers: |
||
1073 | c_neighbors = neighbors[neighbors.carrier == c].set_index( |
||
1074 | "location", drop=False |
||
1075 | ) |
||
1076 | for i in ["x", "y"]: |
||
1077 | c_neighbors = c_neighbors.drop(i, axis=1) |
||
1078 | coordinates = neighbors[neighbors.carrier == "AC"][ |
||
1079 | ["location", "x", "y"] |
||
1080 | ].set_index("location") |
||
1081 | c_neighbors = pd.concat([coordinates, c_neighbors], axis=1).set_index( |
||
1082 | "new_index", drop=False |
||
1083 | ) |
||
1084 | non_AC_neighbors = pd.concat([non_AC_neighbors, c_neighbors]) |
||
1085 | |||
1086 | neighbors = pd.concat( |
||
1087 | [neighbors[neighbors.carrier == "AC"], non_AC_neighbors] |
||
1088 | ) |
||
1089 | |||
1090 | for i in [ |
||
1091 | "new_index", |
||
1092 | "control", |
||
1093 | "generator", |
||
1094 | "location", |
||
1095 | "sub_network", |
||
1096 | "unit", |
||
1097 | "substation_lv", |
||
1098 | "substation_off", |
||
1099 | ]: |
||
1100 | neighbors = neighbors.drop(i, axis=1) |
||
1101 | |||
1102 | # Add geometry column |
||
1103 | neighbors = ( |
||
1104 | gpd.GeoDataFrame( |
||
1105 | neighbors, geometry=gpd.points_from_xy(neighbors.x, neighbors.y) |
||
1106 | ) |
||
1107 | .rename_geometry("geom") |
||
1108 | .set_crs(4326) |
||
1109 | ) |
||
1110 | |||
1111 | # Unify carrier names |
||
1112 | neighbors.carrier = neighbors.carrier.str.replace(" ", "_") |
||
1113 | neighbors.carrier.replace( |
||
1114 | { |
||
1115 | "gas": "CH4", |
||
1116 | "gas_for_industry": "CH4_for_industry", |
||
1117 | "urban_central_heat": "central_heat", |
||
1118 | "EV_battery": "Li_ion", |
||
1119 | "urban_central_water_tanks": "central_heat_store", |
||
1120 | "rural_water_tanks": "rural_heat_store", |
||
1121 | }, |
||
1122 | inplace=True, |
||
1123 | ) |
||
1124 | |||
1125 | neighbors[~neighbors.carrier.isin(["AC"])].to_postgis( |
||
1126 | "egon_etrago_bus", |
||
1127 | engine, |
||
1128 | schema="grid", |
||
1129 | if_exists="append", |
||
1130 | index=True, |
||
1131 | index_label="bus_id", |
||
1132 | ) |
||
1133 | |||
1134 | # prepare and write neighboring crossborder lines to etrago tables |
||
1135 | def lines_to_etrago(neighbor_lines=neighbor_lines, scn="eGon100RE"): |
||
1136 | neighbor_lines["scn_name"] = scn |
||
1137 | neighbor_lines["cables"] = 3 * neighbor_lines["num_parallel"].astype( |
||
1138 | int |
||
1139 | ) |
||
1140 | neighbor_lines["s_nom"] = neighbor_lines["s_nom_min"] |
||
1141 | |||
1142 | for i in [ |
||
1143 | "Line", |
||
1144 | "x_pu_eff", |
||
1145 | "r_pu_eff", |
||
1146 | "sub_network", |
||
1147 | "x_pu", |
||
1148 | "r_pu", |
||
1149 | "g_pu", |
||
1150 | "b_pu", |
||
1151 | "s_nom_opt", |
||
1152 | "i_nom", |
||
1153 | "dc", |
||
1154 | ]: |
||
1155 | neighbor_lines = neighbor_lines.drop(i, axis=1) |
||
1156 | |||
1157 | # Define geometry and add to lines dataframe as 'topo' |
||
1158 | gdf = gpd.GeoDataFrame(index=neighbor_lines.index) |
||
1159 | gdf["geom_bus0"] = neighbors.geom[neighbor_lines.bus0].values |
||
1160 | gdf["geom_bus1"] = neighbors.geom[neighbor_lines.bus1].values |
||
1161 | gdf["geometry"] = gdf.apply( |
||
1162 | lambda x: LineString([x["geom_bus0"], x["geom_bus1"]]), axis=1 |
||
1163 | ) |
||
1164 | |||
1165 | neighbor_lines = ( |
||
1166 | gpd.GeoDataFrame(neighbor_lines, geometry=gdf["geometry"]) |
||
1167 | .rename_geometry("topo") |
||
1168 | .set_crs(4326) |
||
1169 | ) |
||
1170 | |||
1171 | neighbor_lines["lifetime"] = get_sector_parameters("electricity", scn)[ |
||
1172 | "lifetime" |
||
1173 | ]["ac_ehv_overhead_line"] |
||
1174 | |||
1175 | neighbor_lines.to_postgis( |
||
1176 | "egon_etrago_line", |
||
1177 | engine, |
||
1178 | schema="grid", |
||
1179 | if_exists="append", |
||
1180 | index=True, |
||
1181 | index_label="line_id", |
||
1182 | ) |
||
1183 | |||
1184 | lines_to_etrago(neighbor_lines=neighbor_lines, scn="eGon100RE") |
||
1185 | |||
1186 | def links_to_etrago(neighbor_links, scn="eGon100RE", extendable=True): |
||
1187 | """Prepare and write neighboring crossborder links to eTraGo table |
||
1188 | |||
1189 | This function prepare the neighboring crossborder links |
||
1190 | generated the PyPSA-eur-sec (p-e-s) run by: |
||
1191 | * Delete the useless columns |
||
1192 | * If extendable is false only (non default case): |
||
1193 | * Replace p_nom = 0 with the p_nom_op values (arrising |
||
1194 | from the p-e-s optimisation) |
||
1195 | * Setting p_nom_extendable to false |
||
1196 | * Add geomtry to the links: 'geom' and 'topo' columns |
||
1197 | * Change the name of the carriers to have the consistent in |
||
1198 | eGon-data |
||
1199 | |||
1200 | The function insert then the link to the eTraGo table and has |
||
1201 | no return. |
||
1202 | |||
1203 | Parameters |
||
1204 | ---------- |
||
1205 | neighbor_links : pandas.DataFrame |
||
1206 | Dataframe containing the neighboring crossborder links |
||
1207 | scn_name : str |
||
1208 | Name of the scenario |
||
1209 | extendable : bool |
||
1210 | Boolean expressing if the links should be extendable or not |
||
1211 | |||
1212 | Returns |
||
1213 | ------- |
||
1214 | None |
||
1215 | |||
1216 | """ |
||
1217 | neighbor_links["scn_name"] = scn |
||
1218 | |||
1219 | dropped_carriers = [ |
||
1220 | "Link", |
||
1221 | "geometry", |
||
1222 | "tags", |
||
1223 | "under_construction", |
||
1224 | "underground", |
||
1225 | "underwater_fraction", |
||
1226 | "bus2", |
||
1227 | "bus3", |
||
1228 | "bus4", |
||
1229 | "efficiency2", |
||
1230 | "efficiency3", |
||
1231 | "efficiency4", |
||
1232 | "lifetime", |
||
1233 | "pipe_retrofit", |
||
1234 | "committable", |
||
1235 | "start_up_cost", |
||
1236 | "shut_down_cost", |
||
1237 | "min_up_time", |
||
1238 | "min_down_time", |
||
1239 | "up_time_before", |
||
1240 | "down_time_before", |
||
1241 | "ramp_limit_up", |
||
1242 | "ramp_limit_down", |
||
1243 | "ramp_limit_start_up", |
||
1244 | "ramp_limit_shut_down", |
||
1245 | "length_original", |
||
1246 | "reversed", |
||
1247 | "location", |
||
1248 | "project_status", |
||
1249 | "dc", |
||
1250 | "voltage", |
||
1251 | ] |
||
1252 | |||
1253 | if extendable: |
||
1254 | dropped_carriers.append("p_nom_opt") |
||
1255 | neighbor_links = neighbor_links.drop( |
||
1256 | columns=dropped_carriers, |
||
1257 | errors="ignore", |
||
1258 | ) |
||
1259 | |||
1260 | else: |
||
1261 | dropped_carriers.append("p_nom") |
||
1262 | dropped_carriers.append("p_nom_extendable") |
||
1263 | neighbor_links = neighbor_links.drop( |
||
1264 | columns=dropped_carriers, |
||
1265 | errors="ignore", |
||
1266 | ) |
||
1267 | neighbor_links = neighbor_links.rename( |
||
1268 | columns={"p_nom_opt": "p_nom"} |
||
1269 | ) |
||
1270 | neighbor_links["p_nom_extendable"] = False |
||
1271 | |||
1272 | if neighbor_links.empty: |
||
1273 | print("No links selected") |
||
1274 | return |
||
1275 | |||
1276 | # Define geometry and add to lines dataframe as 'topo' |
||
1277 | gdf = gpd.GeoDataFrame( |
||
1278 | index=neighbor_links.index, |
||
1279 | data={ |
||
1280 | "geom_bus0": neighbors.loc[neighbor_links.bus0, "geom"].values, |
||
1281 | "geom_bus1": neighbors.loc[neighbor_links.bus1, "geom"].values, |
||
1282 | }, |
||
1283 | ) |
||
1284 | |||
1285 | gdf["geometry"] = gdf.apply( |
||
1286 | lambda x: LineString([x["geom_bus0"], x["geom_bus1"]]), axis=1 |
||
1287 | ) |
||
1288 | |||
1289 | neighbor_links = ( |
||
1290 | gpd.GeoDataFrame(neighbor_links, geometry=gdf["geometry"]) |
||
1291 | .rename_geometry("topo") |
||
1292 | .set_crs(4326) |
||
1293 | ) |
||
1294 | |||
1295 | # Unify carrier names |
||
1296 | neighbor_links.carrier = neighbor_links.carrier.str.replace(" ", "_") |
||
1297 | |||
1298 | neighbor_links.carrier.replace( |
||
1299 | { |
||
1300 | "H2_Electrolysis": "power_to_H2", |
||
1301 | "H2_Fuel_Cell": "H2_to_power", |
||
1302 | "H2_pipeline_retrofitted": "H2_retrofit", |
||
1303 | "SMR": "CH4_to_H2", |
||
1304 | "Sabatier": "H2_to_CH4", |
||
1305 | "gas_for_industry": "CH4_for_industry", |
||
1306 | "gas_pipeline": "CH4", |
||
1307 | "urban_central_gas_boiler": "central_gas_boiler", |
||
1308 | "urban_central_resistive_heater": "central_resistive_heater", |
||
1309 | "urban_central_water_tanks_charger": "central_heat_store_charger", |
||
1310 | "urban_central_water_tanks_discharger": "central_heat_store_discharger", |
||
1311 | "rural_water_tanks_charger": "rural_heat_store_charger", |
||
1312 | "rural_water_tanks_discharger": "rural_heat_store_discharger", |
||
1313 | "urban_central_gas_CHP": "central_gas_CHP", |
||
1314 | "urban_central_air_heat_pump": "central_heat_pump", |
||
1315 | "rural_ground_heat_pump": "rural_heat_pump", |
||
1316 | }, |
||
1317 | inplace=True, |
||
1318 | ) |
||
1319 | |||
1320 | H2_links = { |
||
1321 | "H2_to_CH4": "H2_to_CH4", |
||
1322 | "H2_to_power": "H2_to_power", |
||
1323 | "power_to_H2": "power_to_H2_system", |
||
1324 | "CH4_to_H2": "CH4_to_H2", |
||
1325 | } |
||
1326 | |||
1327 | for c in H2_links.keys(): |
||
1328 | |||
1329 | neighbor_links.loc[ |
||
1330 | (neighbor_links.carrier == c), |
||
1331 | "lifetime", |
||
1332 | ] = get_sector_parameters("gas", "eGon100RE")["lifetime"][ |
||
1333 | H2_links[c] |
||
1334 | ] |
||
1335 | |||
1336 | neighbor_links.to_postgis( |
||
1337 | "egon_etrago_link", |
||
1338 | engine, |
||
1339 | schema="grid", |
||
1340 | if_exists="append", |
||
1341 | index=True, |
||
1342 | index_label="link_id", |
||
1343 | ) |
||
1344 | |||
1345 | extendable_links_carriers = [ |
||
1346 | "battery charger", |
||
1347 | "battery discharger", |
||
1348 | "home battery charger", |
||
1349 | "home battery discharger", |
||
1350 | "rural water tanks charger", |
||
1351 | "rural water tanks discharger", |
||
1352 | "urban central water tanks charger", |
||
1353 | "urban central water tanks discharger", |
||
1354 | "urban decentral water tanks charger", |
||
1355 | "urban decentral water tanks discharger", |
||
1356 | "H2 Electrolysis", |
||
1357 | "H2 Fuel Cell", |
||
1358 | "SMR", |
||
1359 | "Sabatier", |
||
1360 | ] |
||
1361 | |||
1362 | # delete unwanted carriers for eTraGo |
||
1363 | excluded_carriers = [ |
||
1364 | "gas for industry CC", |
||
1365 | "SMR CC", |
||
1366 | "DAC", |
||
1367 | ] |
||
1368 | neighbor_links = neighbor_links[ |
||
1369 | ~neighbor_links.carrier.isin(excluded_carriers) |
||
1370 | ] |
||
1371 | |||
1372 | # Combine CHP_CC and CHP |
||
1373 | chp_cc = neighbor_links[ |
||
1374 | neighbor_links.carrier == "urban central gas CHP CC" |
||
1375 | ] |
||
1376 | for index, row in chp_cc.iterrows(): |
||
1377 | neighbor_links.loc[ |
||
1378 | neighbor_links.Link == row.Link.replace("CHP CC", "CHP"), |
||
1379 | "p_nom_opt", |
||
1380 | ] += row.p_nom_opt |
||
1381 | neighbor_links.loc[ |
||
1382 | neighbor_links.Link == row.Link.replace("CHP CC", "CHP"), "p_nom" |
||
1383 | ] += row.p_nom |
||
1384 | neighbor_links.drop(index, inplace=True) |
||
1385 | |||
1386 | # Combine heat pumps |
||
1387 | # Like in Germany, there are air heat pumps in central heat grids |
||
1388 | # and ground heat pumps in rural areas |
||
1389 | rural_air = neighbor_links[neighbor_links.carrier == "rural air heat pump"] |
||
1390 | for index, row in rural_air.iterrows(): |
||
1391 | neighbor_links.loc[ |
||
1392 | neighbor_links.Link == row.Link.replace("air", "ground"), |
||
1393 | "p_nom_opt", |
||
1394 | ] += row.p_nom_opt |
||
1395 | neighbor_links.loc[ |
||
1396 | neighbor_links.Link == row.Link.replace("air", "ground"), "p_nom" |
||
1397 | ] += row.p_nom |
||
1398 | neighbor_links.drop(index, inplace=True) |
||
1399 | links_to_etrago( |
||
1400 | neighbor_links[neighbor_links.carrier.isin(extendable_links_carriers)], |
||
1401 | "eGon100RE", |
||
1402 | ) |
||
1403 | links_to_etrago( |
||
1404 | neighbor_links[ |
||
1405 | ~neighbor_links.carrier.isin(extendable_links_carriers) |
||
1406 | ], |
||
1407 | "eGon100RE", |
||
1408 | extendable=False, |
||
1409 | ) |
||
1410 | # Include links time-series |
||
1411 | # For heat_pumps |
||
1412 | hp = neighbor_links[neighbor_links["carrier"].str.contains("heat pump")] |
||
1413 | |||
1414 | neighbor_eff_t = network_prepared.links_t["efficiency"][ |
||
1415 | hp[hp.Link.isin(network_prepared.links_t["efficiency"].columns)].index |
||
1416 | ] |
||
1417 | |||
1418 | missing_hp = hp[~hp["Link"].isin(neighbor_eff_t.columns)].Link |
||
1419 | |||
1420 | eff_timeseries = network_prepared.links_t["efficiency"].copy() |
||
1421 | for met in missing_hp: # met: missing efficiency timeseries |
||
1422 | try: |
||
1423 | neighbor_eff_t[met] = eff_timeseries.loc[:, met[0:-5]] |
||
1424 | except: |
||
1425 | print(f"There are not timeseries for heat_pump {met}") |
||
1426 | |||
1427 | for i in neighbor_eff_t.columns: |
||
1428 | new_index = neighbor_links[neighbor_links["Link"] == i].index |
||
1429 | neighbor_eff_t.rename(columns={i: new_index[0]}, inplace=True) |
||
1430 | |||
1431 | # Include links time-series |
||
1432 | # For ev_chargers |
||
1433 | ev = neighbor_links[neighbor_links["carrier"].str.contains("BEV charger")] |
||
1434 | |||
1435 | ev_p_max_pu = network_prepared.links_t["p_max_pu"][ |
||
1436 | ev[ev.Link.isin(network_prepared.links_t["p_max_pu"].columns)].index |
||
1437 | ] |
||
1438 | |||
1439 | missing_ev = ev[~ev["Link"].isin(ev_p_max_pu.columns)].Link |
||
1440 | |||
1441 | ev_p_max_pu_timeseries = network_prepared.links_t["p_max_pu"].copy() |
||
1442 | for mct in missing_ev: # evt: missing charger timeseries |
||
1443 | try: |
||
1444 | ev_p_max_pu[mct] = ev_p_max_pu_timeseries.loc[:, mct[0:-5]] |
||
1445 | except: |
||
1446 | print(f"There are not timeseries for EV charger {mct}") |
||
1447 | |||
1448 | for i in ev_p_max_pu.columns: |
||
1449 | new_index = neighbor_links[neighbor_links["Link"] == i].index |
||
1450 | ev_p_max_pu.rename(columns={i: new_index[0]}, inplace=True) |
||
1451 | |||
1452 | # prepare neighboring generators for etrago tables |
||
1453 | neighbor_gens["scn_name"] = "eGon100RE" |
||
1454 | neighbor_gens["p_nom"] = neighbor_gens["p_nom_opt"] |
||
1455 | neighbor_gens["p_nom_extendable"] = False |
||
1456 | |||
1457 | # Unify carrier names |
||
1458 | neighbor_gens.carrier = neighbor_gens.carrier.str.replace(" ", "_") |
||
1459 | |||
1460 | neighbor_gens.carrier.replace( |
||
1461 | { |
||
1462 | "onwind": "wind_onshore", |
||
1463 | "ror": "run_of_river", |
||
1464 | "offwind-ac": "wind_offshore", |
||
1465 | "offwind-dc": "wind_offshore", |
||
1466 | "offwind-float": "wind_offshore", |
||
1467 | "urban_central_solar_thermal": "urban_central_solar_thermal_collector", |
||
1468 | "residential_rural_solar_thermal": "residential_rural_solar_thermal_collector", |
||
1469 | "services_rural_solar_thermal": "services_rural_solar_thermal_collector", |
||
1470 | "solar-hsat": "solar", |
||
1471 | }, |
||
1472 | inplace=True, |
||
1473 | ) |
||
1474 | |||
1475 | for i in [ |
||
1476 | "Generator", |
||
1477 | "weight", |
||
1478 | "lifetime", |
||
1479 | "p_set", |
||
1480 | "q_set", |
||
1481 | "p_nom_opt", |
||
1482 | "e_sum_min", |
||
1483 | "e_sum_max", |
||
1484 | ]: |
||
1485 | neighbor_gens = neighbor_gens.drop(i, axis=1) |
||
1486 | |||
1487 | neighbor_gens.to_sql( |
||
1488 | "egon_etrago_generator", |
||
1489 | engine, |
||
1490 | schema="grid", |
||
1491 | if_exists="append", |
||
1492 | index=True, |
||
1493 | index_label="generator_id", |
||
1494 | ) |
||
1495 | |||
1496 | # prepare neighboring loads for etrago tables |
||
1497 | neighbor_loads["scn_name"] = "eGon100RE" |
||
1498 | |||
1499 | # Unify carrier names |
||
1500 | neighbor_loads.carrier = neighbor_loads.carrier.str.replace(" ", "_") |
||
1501 | |||
1502 | neighbor_loads.carrier.replace( |
||
1503 | { |
||
1504 | "electricity": "AC", |
||
1505 | "DC": "AC", |
||
1506 | "industry_electricity": "AC", |
||
1507 | "H2_pipeline_retrofitted": "H2_system_boundary", |
||
1508 | "gas_pipeline": "CH4_system_boundary", |
||
1509 | "gas_for_industry": "CH4_for_industry", |
||
1510 | "urban_central_heat": "central_heat", |
||
1511 | }, |
||
1512 | inplace=True, |
||
1513 | ) |
||
1514 | |||
1515 | neighbor_loads = neighbor_loads.drop( |
||
1516 | columns=["Load"], |
||
1517 | errors="ignore", |
||
1518 | ) |
||
1519 | |||
1520 | neighbor_loads.to_sql( |
||
1521 | "egon_etrago_load", |
||
1522 | engine, |
||
1523 | schema="grid", |
||
1524 | if_exists="append", |
||
1525 | index=True, |
||
1526 | index_label="load_id", |
||
1527 | ) |
||
1528 | |||
1529 | # prepare neighboring stores for etrago tables |
||
1530 | neighbor_stores["scn_name"] = "eGon100RE" |
||
1531 | |||
1532 | # Unify carrier names |
||
1533 | neighbor_stores.carrier = neighbor_stores.carrier.str.replace(" ", "_") |
||
1534 | |||
1535 | neighbor_stores.carrier.replace( |
||
1536 | { |
||
1537 | "Li_ion": "battery", |
||
1538 | "gas": "CH4", |
||
1539 | "urban_central_water_tanks": "central_heat_store", |
||
1540 | "rural_water_tanks": "rural_heat_store", |
||
1541 | "EV_battery": "battery_storage", |
||
1542 | }, |
||
1543 | inplace=True, |
||
1544 | ) |
||
1545 | neighbor_stores.loc[ |
||
1546 | ( |
||
1547 | (neighbor_stores.e_nom_max <= 1e9) |
||
1548 | & (neighbor_stores.carrier == "H2_Store") |
||
1549 | ), |
||
1550 | "carrier", |
||
1551 | ] = "H2_underground" |
||
1552 | neighbor_stores.loc[ |
||
1553 | ( |
||
1554 | (neighbor_stores.e_nom_max > 1e9) |
||
1555 | & (neighbor_stores.carrier == "H2_Store") |
||
1556 | ), |
||
1557 | "carrier", |
||
1558 | ] = "H2_overground" |
||
1559 | |||
1560 | for i in [ |
||
1561 | "Store", |
||
1562 | "p_set", |
||
1563 | "q_set", |
||
1564 | "e_nom_opt", |
||
1565 | "lifetime", |
||
1566 | "e_initial_per_period", |
||
1567 | "e_cyclic_per_period", |
||
1568 | "location", |
||
1569 | ]: |
||
1570 | neighbor_stores = neighbor_stores.drop(i, axis=1, errors="ignore") |
||
1571 | |||
1572 | for c in ["H2_underground", "H2_overground"]: |
||
1573 | neighbor_stores.loc[ |
||
1574 | (neighbor_stores.carrier == c), |
||
1575 | "lifetime", |
||
1576 | ] = get_sector_parameters("gas", "eGon100RE")["lifetime"][c] |
||
1577 | |||
1578 | neighbor_stores.to_sql( |
||
1579 | "egon_etrago_store", |
||
1580 | engine, |
||
1581 | schema="grid", |
||
1582 | if_exists="append", |
||
1583 | index=True, |
||
1584 | index_label="store_id", |
||
1585 | ) |
||
1586 | |||
1587 | # prepare neighboring storage_units for etrago tables |
||
1588 | neighbor_storage["scn_name"] = "eGon100RE" |
||
1589 | |||
1590 | # Unify carrier names |
||
1591 | neighbor_storage.carrier = neighbor_storage.carrier.str.replace(" ", "_") |
||
1592 | |||
1593 | neighbor_storage.carrier.replace( |
||
1594 | {"PHS": "pumped_hydro", "hydro": "reservoir"}, inplace=True |
||
1595 | ) |
||
1596 | |||
1597 | for i in [ |
||
1598 | "StorageUnit", |
||
1599 | "p_nom_opt", |
||
1600 | "state_of_charge_initial_per_period", |
||
1601 | "cyclic_state_of_charge_per_period", |
||
1602 | ]: |
||
1603 | neighbor_storage = neighbor_storage.drop(i, axis=1, errors="ignore") |
||
1604 | |||
1605 | neighbor_storage.to_sql( |
||
1606 | "egon_etrago_storage", |
||
1607 | engine, |
||
1608 | schema="grid", |
||
1609 | if_exists="append", |
||
1610 | index=True, |
||
1611 | index_label="storage_id", |
||
1612 | ) |
||
1613 | |||
1614 | # writing neighboring loads_t p_sets to etrago tables |
||
1615 | |||
1616 | neighbor_loads_t_etrago = pd.DataFrame( |
||
1617 | columns=["scn_name", "temp_id", "p_set"], |
||
1618 | index=neighbor_loads_t.columns, |
||
1619 | ) |
||
1620 | neighbor_loads_t_etrago["scn_name"] = "eGon100RE" |
||
1621 | neighbor_loads_t_etrago["temp_id"] = 1 |
||
1622 | for i in neighbor_loads_t.columns: |
||
1623 | neighbor_loads_t_etrago["p_set"][i] = neighbor_loads_t[ |
||
1624 | i |
||
1625 | ].values.tolist() |
||
1626 | |||
1627 | neighbor_loads_t_etrago.to_sql( |
||
1628 | "egon_etrago_load_timeseries", |
||
1629 | engine, |
||
1630 | schema="grid", |
||
1631 | if_exists="append", |
||
1632 | index=True, |
||
1633 | index_label="load_id", |
||
1634 | ) |
||
1635 | |||
1636 | # writing neighboring link_t efficiency and p_max_pu to etrago tables |
||
1637 | neighbor_link_t_etrago = pd.DataFrame( |
||
1638 | columns=["scn_name", "temp_id", "p_max_pu", "efficiency"], |
||
1639 | index=neighbor_eff_t.columns.to_list() + ev_p_max_pu.columns.to_list(), |
||
1640 | ) |
||
1641 | neighbor_link_t_etrago["scn_name"] = "eGon100RE" |
||
1642 | neighbor_link_t_etrago["temp_id"] = 1 |
||
1643 | for i in neighbor_eff_t.columns: |
||
1644 | neighbor_link_t_etrago["efficiency"][i] = neighbor_eff_t[ |
||
1645 | i |
||
1646 | ].values.tolist() |
||
1647 | for i in ev_p_max_pu.columns: |
||
1648 | neighbor_link_t_etrago["p_max_pu"][i] = ev_p_max_pu[i].values.tolist() |
||
1649 | |||
1650 | neighbor_link_t_etrago.to_sql( |
||
1651 | "egon_etrago_link_timeseries", |
||
1652 | engine, |
||
1653 | schema="grid", |
||
1654 | if_exists="append", |
||
1655 | index=True, |
||
1656 | index_label="link_id", |
||
1657 | ) |
||
1658 | |||
1659 | # writing neighboring generator_t p_max_pu to etrago tables |
||
1660 | neighbor_gens_t_etrago = pd.DataFrame( |
||
1661 | columns=["scn_name", "temp_id", "p_max_pu"], |
||
1662 | index=neighbor_gens_t.columns, |
||
1663 | ) |
||
1664 | neighbor_gens_t_etrago["scn_name"] = "eGon100RE" |
||
1665 | neighbor_gens_t_etrago["temp_id"] = 1 |
||
1666 | for i in neighbor_gens_t.columns: |
||
1667 | neighbor_gens_t_etrago["p_max_pu"][i] = neighbor_gens_t[ |
||
1668 | i |
||
1669 | ].values.tolist() |
||
1670 | |||
1671 | neighbor_gens_t_etrago.to_sql( |
||
1672 | "egon_etrago_generator_timeseries", |
||
1673 | engine, |
||
1674 | schema="grid", |
||
1675 | if_exists="append", |
||
1676 | index=True, |
||
1677 | index_label="generator_id", |
||
1678 | ) |
||
1679 | |||
1680 | # writing neighboring stores_t e_min_pu to etrago tables |
||
1681 | neighbor_stores_t_etrago = pd.DataFrame( |
||
1682 | columns=["scn_name", "temp_id", "e_min_pu"], |
||
1683 | index=neighbor_stores_t.columns, |
||
1684 | ) |
||
1685 | neighbor_stores_t_etrago["scn_name"] = "eGon100RE" |
||
1686 | neighbor_stores_t_etrago["temp_id"] = 1 |
||
1687 | for i in neighbor_stores_t.columns: |
||
1688 | neighbor_stores_t_etrago["e_min_pu"][i] = neighbor_stores_t[ |
||
1689 | i |
||
1690 | ].values.tolist() |
||
1691 | |||
1692 | neighbor_stores_t_etrago.to_sql( |
||
1693 | "egon_etrago_store_timeseries", |
||
1694 | engine, |
||
1695 | schema="grid", |
||
1696 | if_exists="append", |
||
1697 | index=True, |
||
1698 | index_label="store_id", |
||
1699 | ) |
||
1700 | |||
1701 | # writing neighboring storage_units inflow to etrago tables |
||
1702 | neighbor_storage_t_etrago = pd.DataFrame( |
||
1703 | columns=["scn_name", "temp_id", "inflow"], |
||
1704 | index=neighbor_storage_t.columns, |
||
1705 | ) |
||
1706 | neighbor_storage_t_etrago["scn_name"] = "eGon100RE" |
||
1707 | neighbor_storage_t_etrago["temp_id"] = 1 |
||
1708 | for i in neighbor_storage_t.columns: |
||
1709 | neighbor_storage_t_etrago["inflow"][i] = neighbor_storage_t[ |
||
1710 | i |
||
1711 | ].values.tolist() |
||
1712 | |||
1713 | neighbor_storage_t_etrago.to_sql( |
||
1714 | "egon_etrago_storage_timeseries", |
||
1715 | engine, |
||
1716 | schema="grid", |
||
1717 | if_exists="append", |
||
1718 | index=True, |
||
1719 | index_label="storage_id", |
||
1720 | ) |
||
1721 | |||
1722 | # writing neighboring lines_t s_max_pu to etrago tables |
||
1723 | if not network_solved.lines_t["s_max_pu"].empty: |
||
1724 | neighbor_lines_t_etrago = pd.DataFrame( |
||
1725 | columns=["scn_name", "s_max_pu"], index=neighbor_lines_t.columns |
||
1726 | ) |
||
1727 | neighbor_lines_t_etrago["scn_name"] = "eGon100RE" |
||
1728 | |||
1729 | for i in neighbor_lines_t.columns: |
||
1730 | neighbor_lines_t_etrago["s_max_pu"][i] = neighbor_lines_t[ |
||
1731 | i |
||
1732 | ].values.tolist() |
||
1733 | |||
1734 | neighbor_lines_t_etrago.to_sql( |
||
1735 | "egon_etrago_line_timeseries", |
||
1736 | engine, |
||
1737 | schema="grid", |
||
1738 | if_exists="append", |
||
1739 | index=True, |
||
1740 | index_label="line_id", |
||
1741 | ) |
||
2388 |