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