| Conditions | 24 |
| Total Lines | 554 |
| Code Lines | 358 |
| 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.sanity_checks.sanitycheck_emobility_mit() 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 | """ |
||
| 589 | def sanitycheck_emobility_mit(): |
||
| 590 | """Execute sanity checks for eMobility: motorized individual travel |
||
| 591 | |||
| 592 | Checks data integrity for eGon2035, eGon2035_lowflex and eGon100RE scenario |
||
| 593 | using assertions: |
||
| 594 | 1. Allocated EV numbers and EVs allocated to grid districts |
||
| 595 | 2. Trip data (original inout data from simBEV) |
||
| 596 | 3. Model data in eTraGo PF tables (grid.egon_etrago_*) |
||
| 597 | |||
| 598 | Parameters |
||
| 599 | ---------- |
||
| 600 | None |
||
| 601 | |||
| 602 | Returns |
||
| 603 | ------- |
||
| 604 | None |
||
| 605 | """ |
||
| 606 | |||
| 607 | def check_ev_allocation(): |
||
| 608 | # Get target number for scenario |
||
| 609 | ev_count_target = scenario_variation_parameters["ev_count"] |
||
| 610 | print(f" Target count: {str(ev_count_target)}") |
||
| 611 | |||
| 612 | # Get allocated numbers |
||
| 613 | ev_counts_dict = {} |
||
| 614 | with db.session_scope() as session: |
||
| 615 | for table, level in zip( |
||
| 616 | [ |
||
| 617 | EgonEvCountMvGridDistrict, |
||
| 618 | EgonEvCountMunicipality, |
||
| 619 | EgonEvCountRegistrationDistrict, |
||
| 620 | ], |
||
| 621 | ["Grid District", "Municipality", "Registration District"], |
||
| 622 | ): |
||
| 623 | query = session.query( |
||
| 624 | func.sum( |
||
| 625 | table.bev_mini |
||
| 626 | + table.bev_medium |
||
| 627 | + table.bev_luxury |
||
| 628 | + table.phev_mini |
||
| 629 | + table.phev_medium |
||
| 630 | + table.phev_luxury |
||
| 631 | ).label("ev_count") |
||
| 632 | ).filter( |
||
| 633 | table.scenario == scenario_name, |
||
| 634 | table.scenario_variation == scenario_var_name, |
||
| 635 | ) |
||
| 636 | |||
| 637 | ev_counts = pd.read_sql( |
||
| 638 | query.statement, query.session.bind, index_col=None |
||
| 639 | ) |
||
| 640 | ev_counts_dict[level] = ev_counts.iloc[0].ev_count |
||
| 641 | print( |
||
| 642 | f" Count table: Total count for level {level} " |
||
| 643 | f"(table: {table.__table__}): " |
||
| 644 | f"{str(ev_counts_dict[level])}" |
||
| 645 | ) |
||
| 646 | |||
| 647 | # Compare with scenario target (only if not in testmode) |
||
| 648 | if TESTMODE_OFF: |
||
| 649 | for level, count in ev_counts_dict.items(): |
||
| 650 | np.testing.assert_allclose( |
||
| 651 | count, |
||
| 652 | ev_count_target, |
||
| 653 | rtol=0.0001, |
||
| 654 | err_msg=f"EV numbers in {level} seems to be flawed.", |
||
| 655 | ) |
||
| 656 | else: |
||
| 657 | print(" Testmode is on, skipping sanity check...") |
||
| 658 | |||
| 659 | # Get allocated EVs in grid districts |
||
| 660 | with db.session_scope() as session: |
||
| 661 | query = session.query( |
||
| 662 | func.count(EgonEvMvGridDistrict.egon_ev_pool_ev_id).label( |
||
| 663 | "ev_count" |
||
| 664 | ), |
||
| 665 | ).filter( |
||
| 666 | EgonEvMvGridDistrict.scenario == scenario_name, |
||
| 667 | EgonEvMvGridDistrict.scenario_variation == scenario_var_name, |
||
| 668 | ) |
||
| 669 | ev_count_alloc = ( |
||
| 670 | pd.read_sql(query.statement, query.session.bind, index_col=None) |
||
| 671 | .iloc[0] |
||
| 672 | .ev_count |
||
| 673 | ) |
||
| 674 | print( |
||
| 675 | f" EVs allocated to Grid Districts " |
||
| 676 | f"(table: {EgonEvMvGridDistrict.__table__}) total count: " |
||
| 677 | f"{str(ev_count_alloc)}" |
||
| 678 | ) |
||
| 679 | |||
| 680 | # Compare with scenario target (only if not in testmode) |
||
| 681 | if TESTMODE_OFF: |
||
| 682 | np.testing.assert_allclose( |
||
| 683 | ev_count_alloc, |
||
| 684 | ev_count_target, |
||
| 685 | rtol=0.0001, |
||
| 686 | err_msg=( |
||
| 687 | "EV numbers allocated to Grid Districts seems to be flawed." |
||
| 688 | ), |
||
| 689 | ) |
||
| 690 | else: |
||
| 691 | print(" Testmode is on, skipping sanity check...") |
||
| 692 | |||
| 693 | return ev_count_alloc |
||
| 694 | |||
| 695 | def check_trip_data(): |
||
| 696 | # Check if trips start at timestep 0 and have a max. of 35040 steps |
||
| 697 | # (8760h in 15min steps) |
||
| 698 | print(" Checking timeranges...") |
||
| 699 | with db.session_scope() as session: |
||
| 700 | query = session.query( |
||
| 701 | func.count(EgonEvTrip.event_id).label("cnt") |
||
| 702 | ).filter( |
||
| 703 | or_( |
||
| 704 | and_( |
||
| 705 | EgonEvTrip.park_start > 0, |
||
| 706 | EgonEvTrip.simbev_event_id == 0, |
||
| 707 | ), |
||
| 708 | EgonEvTrip.park_end |
||
| 709 | > (60 / int(meta_run_config.stepsize)) * 8760, |
||
| 710 | ), |
||
| 711 | EgonEvTrip.scenario == scenario_name, |
||
| 712 | ) |
||
| 713 | invalid_trips = pd.read_sql( |
||
| 714 | query.statement, query.session.bind, index_col=None |
||
| 715 | ) |
||
| 716 | np.testing.assert_equal( |
||
| 717 | invalid_trips.iloc[0].cnt, |
||
| 718 | 0, |
||
| 719 | err_msg=( |
||
| 720 | f"{str(invalid_trips.iloc[0].cnt)} trips in table " |
||
| 721 | f"{EgonEvTrip.__table__} have invalid timesteps." |
||
| 722 | ), |
||
| 723 | ) |
||
| 724 | |||
| 725 | # Check if charging demand can be covered by available charging energy |
||
| 726 | # while parking |
||
| 727 | print(" Compare charging demand with available power...") |
||
| 728 | with db.session_scope() as session: |
||
| 729 | query = session.query( |
||
| 730 | func.count(EgonEvTrip.event_id).label("cnt") |
||
| 731 | ).filter( |
||
| 732 | func.round( |
||
| 733 | cast( |
||
| 734 | (EgonEvTrip.park_end - EgonEvTrip.park_start + 1) |
||
| 735 | * EgonEvTrip.charging_capacity_nominal |
||
| 736 | * (int(meta_run_config.stepsize) / 60), |
||
| 737 | Numeric, |
||
| 738 | ), |
||
| 739 | 3, |
||
| 740 | ) |
||
| 741 | < cast(EgonEvTrip.charging_demand, Numeric), |
||
| 742 | EgonEvTrip.scenario == scenario_name, |
||
| 743 | ) |
||
| 744 | invalid_trips = pd.read_sql( |
||
| 745 | query.statement, query.session.bind, index_col=None |
||
| 746 | ) |
||
| 747 | np.testing.assert_equal( |
||
| 748 | invalid_trips.iloc[0].cnt, |
||
| 749 | 0, |
||
| 750 | err_msg=( |
||
| 751 | f"In {str(invalid_trips.iloc[0].cnt)} trips (table: " |
||
| 752 | f"{EgonEvTrip.__table__}) the charging demand cannot be " |
||
| 753 | f"covered by available charging power." |
||
| 754 | ), |
||
| 755 | ) |
||
| 756 | |||
| 757 | def check_model_data(): |
||
| 758 | # Check if model components were fully created |
||
| 759 | print(" Check if all model components were created...") |
||
| 760 | # Get MVGDs which got EV allocated |
||
| 761 | with db.session_scope() as session: |
||
| 762 | query = ( |
||
| 763 | session.query( |
||
| 764 | EgonEvMvGridDistrict.bus_id, |
||
| 765 | ) |
||
| 766 | .filter( |
||
| 767 | EgonEvMvGridDistrict.scenario == scenario_name, |
||
| 768 | EgonEvMvGridDistrict.scenario_variation |
||
| 769 | == scenario_var_name, |
||
| 770 | ) |
||
| 771 | .group_by(EgonEvMvGridDistrict.bus_id) |
||
| 772 | ) |
||
| 773 | mvgds_with_ev = ( |
||
| 774 | pd.read_sql(query.statement, query.session.bind, index_col=None) |
||
| 775 | .bus_id.sort_values() |
||
| 776 | .to_list() |
||
| 777 | ) |
||
| 778 | |||
| 779 | # Load model components |
||
| 780 | with db.session_scope() as session: |
||
| 781 | query = ( |
||
| 782 | session.query( |
||
| 783 | EgonPfHvLink.bus0.label("mvgd_bus_id"), |
||
| 784 | EgonPfHvLoad.bus.label("emob_bus_id"), |
||
| 785 | EgonPfHvLoad.load_id.label("load_id"), |
||
| 786 | EgonPfHvStore.store_id.label("store_id"), |
||
| 787 | ) |
||
| 788 | .select_from(EgonPfHvLoad, EgonPfHvStore) |
||
| 789 | .join( |
||
| 790 | EgonPfHvLoadTimeseries, |
||
| 791 | EgonPfHvLoadTimeseries.load_id == EgonPfHvLoad.load_id, |
||
| 792 | ) |
||
| 793 | .join( |
||
| 794 | EgonPfHvStoreTimeseries, |
||
| 795 | EgonPfHvStoreTimeseries.store_id == EgonPfHvStore.store_id, |
||
| 796 | ) |
||
| 797 | .filter( |
||
| 798 | EgonPfHvLoad.carrier == "land transport EV", |
||
| 799 | EgonPfHvLoad.scn_name == scenario_name, |
||
| 800 | EgonPfHvLoadTimeseries.scn_name == scenario_name, |
||
| 801 | EgonPfHvStore.carrier == "battery storage", |
||
| 802 | EgonPfHvStore.scn_name == scenario_name, |
||
| 803 | EgonPfHvStoreTimeseries.scn_name == scenario_name, |
||
| 804 | EgonPfHvLink.scn_name == scenario_name, |
||
| 805 | EgonPfHvLink.bus1 == EgonPfHvLoad.bus, |
||
| 806 | EgonPfHvLink.bus1 == EgonPfHvStore.bus, |
||
| 807 | ) |
||
| 808 | ) |
||
| 809 | model_components = pd.read_sql( |
||
| 810 | query.statement, query.session.bind, index_col=None |
||
| 811 | ) |
||
| 812 | |||
| 813 | # Check number of buses with model components connected |
||
| 814 | mvgd_buses_with_ev = model_components.loc[ |
||
| 815 | model_components.mvgd_bus_id.isin(mvgds_with_ev) |
||
| 816 | ] |
||
| 817 | np.testing.assert_equal( |
||
| 818 | len(mvgds_with_ev), |
||
| 819 | len(mvgd_buses_with_ev), |
||
| 820 | err_msg=( |
||
| 821 | f"Number of Grid Districts with connected model components " |
||
| 822 | f"({str(len(mvgd_buses_with_ev))} in tables egon_etrago_*) " |
||
| 823 | f"differ from number of Grid Districts that got EVs " |
||
| 824 | f"allocated ({len(mvgds_with_ev)} in table " |
||
| 825 | f"{EgonEvMvGridDistrict.__table__})." |
||
| 826 | ), |
||
| 827 | ) |
||
| 828 | |||
| 829 | # Check if all required components exist (if no id is NaN) |
||
| 830 | np.testing.assert_equal( |
||
| 831 | model_components.drop_duplicates().isna().any().any(), |
||
| 832 | False, |
||
| 833 | err_msg=( |
||
| 834 | f"Some components are missing (see True values): " |
||
| 835 | f"{model_components.drop_duplicates().isna().any()}" |
||
| 836 | ), |
||
| 837 | ) |
||
| 838 | |||
| 839 | # Get all model timeseries |
||
| 840 | print(" Loading model timeseries...") |
||
| 841 | # Get all model timeseries |
||
| 842 | model_ts_dict = { |
||
| 843 | "Load": { |
||
| 844 | "carrier": "land transport EV", |
||
| 845 | "table": EgonPfHvLoad, |
||
| 846 | "table_ts": EgonPfHvLoadTimeseries, |
||
| 847 | "column_id": "load_id", |
||
| 848 | "columns_ts": ["p_set"], |
||
| 849 | "ts": None, |
||
| 850 | }, |
||
| 851 | "Link": { |
||
| 852 | "carrier": "BEV charger", |
||
| 853 | "table": EgonPfHvLink, |
||
| 854 | "table_ts": EgonPfHvLinkTimeseries, |
||
| 855 | "column_id": "link_id", |
||
| 856 | "columns_ts": ["p_max_pu"], |
||
| 857 | "ts": None, |
||
| 858 | }, |
||
| 859 | "Store": { |
||
| 860 | "carrier": "battery storage", |
||
| 861 | "table": EgonPfHvStore, |
||
| 862 | "table_ts": EgonPfHvStoreTimeseries, |
||
| 863 | "column_id": "store_id", |
||
| 864 | "columns_ts": ["e_min_pu", "e_max_pu"], |
||
| 865 | "ts": None, |
||
| 866 | }, |
||
| 867 | } |
||
| 868 | |||
| 869 | with db.session_scope() as session: |
||
| 870 | for node, attrs in model_ts_dict.items(): |
||
| 871 | print(f" Loading {node} timeseries...") |
||
| 872 | subquery = ( |
||
| 873 | session.query(getattr(attrs["table"], attrs["column_id"])) |
||
| 874 | .filter(attrs["table"].carrier == attrs["carrier"]) |
||
| 875 | .filter(attrs["table"].scn_name == scenario_name) |
||
| 876 | .subquery() |
||
| 877 | ) |
||
| 878 | |||
| 879 | cols = [ |
||
| 880 | getattr(attrs["table_ts"], c) for c in attrs["columns_ts"] |
||
| 881 | ] |
||
| 882 | query = session.query( |
||
| 883 | getattr(attrs["table_ts"], attrs["column_id"]), *cols |
||
| 884 | ).filter( |
||
| 885 | getattr(attrs["table_ts"], attrs["column_id"]).in_( |
||
| 886 | subquery |
||
| 887 | ), |
||
| 888 | attrs["table_ts"].scn_name == scenario_name, |
||
| 889 | ) |
||
| 890 | attrs["ts"] = pd.read_sql( |
||
| 891 | query.statement, |
||
| 892 | query.session.bind, |
||
| 893 | index_col=attrs["column_id"], |
||
| 894 | ) |
||
| 895 | |||
| 896 | # Check if all timeseries have 8760 steps |
||
| 897 | print(" Checking timeranges...") |
||
| 898 | for node, attrs in model_ts_dict.items(): |
||
| 899 | for col in attrs["columns_ts"]: |
||
| 900 | ts = attrs["ts"] |
||
| 901 | invalid_ts = ts.loc[ts[col].apply(lambda _: len(_)) != 8760][ |
||
| 902 | col |
||
| 903 | ].apply(len) |
||
| 904 | np.testing.assert_equal( |
||
| 905 | len(invalid_ts), |
||
| 906 | 0, |
||
| 907 | err_msg=( |
||
| 908 | f"{str(len(invalid_ts))} rows in timeseries do not " |
||
| 909 | f"have 8760 timesteps. Table: " |
||
| 910 | f"{attrs['table_ts'].__table__}, Column: {col}, IDs: " |
||
| 911 | f"{str(list(invalid_ts.index))}" |
||
| 912 | ), |
||
| 913 | ) |
||
| 914 | |||
| 915 | # Compare total energy demand in model with some approximate values |
||
| 916 | # (per EV: 14,000 km/a, 0.17 kWh/km) |
||
| 917 | print(" Checking energy demand in model...") |
||
| 918 | total_energy_model = ( |
||
| 919 | model_ts_dict["Load"]["ts"].p_set.apply(lambda _: sum(_)).sum() |
||
| 920 | / 1e6 |
||
| 921 | ) |
||
| 922 | print(f" Total energy amount in model: {total_energy_model} TWh") |
||
| 923 | total_energy_scenario_approx = ev_count_alloc * 14000 * 0.17 / 1e9 |
||
| 924 | print( |
||
| 925 | f" Total approximated energy amount in scenario: " |
||
| 926 | f"{total_energy_scenario_approx} TWh" |
||
| 927 | ) |
||
| 928 | np.testing.assert_allclose( |
||
| 929 | total_energy_model, |
||
| 930 | total_energy_scenario_approx, |
||
| 931 | rtol=0.1, |
||
| 932 | err_msg=( |
||
| 933 | "The total energy amount in the model deviates heavily " |
||
| 934 | "from the approximated value for current scenario." |
||
| 935 | ), |
||
| 936 | ) |
||
| 937 | |||
| 938 | # Compare total storage capacity |
||
| 939 | print(" Checking storage capacity...") |
||
| 940 | # Load storage capacities from model |
||
| 941 | with db.session_scope() as session: |
||
| 942 | query = session.query( |
||
| 943 | func.sum(EgonPfHvStore.e_nom).label("e_nom") |
||
| 944 | ).filter( |
||
| 945 | EgonPfHvStore.scn_name == scenario_name, |
||
| 946 | EgonPfHvStore.carrier == "battery storage", |
||
| 947 | ) |
||
| 948 | storage_capacity_model = ( |
||
| 949 | pd.read_sql( |
||
| 950 | query.statement, query.session.bind, index_col=None |
||
| 951 | ).e_nom.sum() |
||
| 952 | / 1e3 |
||
| 953 | ) |
||
| 954 | print( |
||
| 955 | f" Total storage capacity ({EgonPfHvStore.__table__}): " |
||
| 956 | f"{round(storage_capacity_model, 1)} GWh" |
||
| 957 | ) |
||
| 958 | |||
| 959 | # Load occurences of each EV |
||
| 960 | with db.session_scope() as session: |
||
| 961 | query = ( |
||
| 962 | session.query( |
||
| 963 | EgonEvMvGridDistrict.bus_id, |
||
| 964 | EgonEvPool.type, |
||
| 965 | func.count(EgonEvMvGridDistrict.egon_ev_pool_ev_id).label( |
||
| 966 | "count" |
||
| 967 | ), |
||
| 968 | ) |
||
| 969 | .join( |
||
| 970 | EgonEvPool, |
||
| 971 | EgonEvPool.ev_id |
||
| 972 | == EgonEvMvGridDistrict.egon_ev_pool_ev_id, |
||
| 973 | ) |
||
| 974 | .filter( |
||
| 975 | EgonEvMvGridDistrict.scenario == scenario_name, |
||
| 976 | EgonEvMvGridDistrict.scenario_variation |
||
| 977 | == scenario_var_name, |
||
| 978 | EgonEvPool.scenario == scenario_name, |
||
| 979 | ) |
||
| 980 | .group_by(EgonEvMvGridDistrict.bus_id, EgonEvPool.type) |
||
| 981 | ) |
||
| 982 | count_per_ev_all = pd.read_sql( |
||
| 983 | query.statement, query.session.bind, index_col="bus_id" |
||
| 984 | ) |
||
| 985 | count_per_ev_all["bat_cap"] = count_per_ev_all.type.map( |
||
| 986 | meta_tech_data.battery_capacity |
||
| 987 | ) |
||
| 988 | count_per_ev_all["bat_cap_total_MWh"] = ( |
||
| 989 | count_per_ev_all["count"] * count_per_ev_all.bat_cap / 1e3 |
||
| 990 | ) |
||
| 991 | storage_capacity_simbev = count_per_ev_all.bat_cap_total_MWh.div( |
||
| 992 | 1e3 |
||
| 993 | ).sum() |
||
| 994 | print( |
||
| 995 | f" Total storage capacity (simBEV): " |
||
| 996 | f"{round(storage_capacity_simbev, 1)} GWh" |
||
| 997 | ) |
||
| 998 | |||
| 999 | np.testing.assert_allclose( |
||
| 1000 | storage_capacity_model, |
||
| 1001 | storage_capacity_simbev, |
||
| 1002 | rtol=0.01, |
||
| 1003 | err_msg=( |
||
| 1004 | "The total storage capacity in the model deviates heavily " |
||
| 1005 | "from the input data provided by simBEV for current scenario." |
||
| 1006 | ), |
||
| 1007 | ) |
||
| 1008 | |||
| 1009 | # Check SoC storage constraint: e_min_pu < e_max_pu for all timesteps |
||
| 1010 | print(" Validating SoC constraints...") |
||
| 1011 | stores_with_invalid_soc = [] |
||
| 1012 | for idx, row in model_ts_dict["Store"]["ts"].iterrows(): |
||
| 1013 | ts = row[["e_min_pu", "e_max_pu"]] |
||
| 1014 | x = np.array(ts.e_min_pu) > np.array(ts.e_max_pu) |
||
| 1015 | if x.any(): |
||
| 1016 | stores_with_invalid_soc.append(idx) |
||
| 1017 | |||
| 1018 | np.testing.assert_equal( |
||
| 1019 | len(stores_with_invalid_soc), |
||
| 1020 | 0, |
||
| 1021 | err_msg=( |
||
| 1022 | f"The store constraint e_min_pu < e_max_pu does not apply " |
||
| 1023 | f"for some storages in {EgonPfHvStoreTimeseries.__table__}. " |
||
| 1024 | f"Invalid store_ids: {stores_with_invalid_soc}" |
||
| 1025 | ), |
||
| 1026 | ) |
||
| 1027 | |||
| 1028 | def check_model_data_lowflex_eGon2035(): |
||
| 1029 | # TODO: Add eGon100RE_lowflex |
||
| 1030 | print("") |
||
| 1031 | print("SCENARIO: eGon2035_lowflex") |
||
| 1032 | |||
| 1033 | # Compare driving load and charging load |
||
| 1034 | print(" Loading eGon2035 model timeseries: driving load...") |
||
| 1035 | with db.session_scope() as session: |
||
| 1036 | query = ( |
||
| 1037 | session.query( |
||
| 1038 | EgonPfHvLoad.load_id, |
||
| 1039 | EgonPfHvLoadTimeseries.p_set, |
||
| 1040 | ) |
||
| 1041 | .join( |
||
| 1042 | EgonPfHvLoadTimeseries, |
||
| 1043 | EgonPfHvLoadTimeseries.load_id == EgonPfHvLoad.load_id, |
||
| 1044 | ) |
||
| 1045 | .filter( |
||
| 1046 | EgonPfHvLoad.carrier == "land transport EV", |
||
| 1047 | EgonPfHvLoad.scn_name == "eGon2035", |
||
| 1048 | EgonPfHvLoadTimeseries.scn_name == "eGon2035", |
||
| 1049 | ) |
||
| 1050 | ) |
||
| 1051 | model_driving_load = pd.read_sql( |
||
| 1052 | query.statement, query.session.bind, index_col=None |
||
| 1053 | ) |
||
| 1054 | driving_load = np.array(model_driving_load.p_set.to_list()).sum(axis=0) |
||
| 1055 | |||
| 1056 | print( |
||
| 1057 | " Loading eGon2035_lowflex model timeseries: dumb charging " |
||
| 1058 | "load..." |
||
| 1059 | ) |
||
| 1060 | with db.session_scope() as session: |
||
| 1061 | query = ( |
||
| 1062 | session.query( |
||
| 1063 | EgonPfHvLoad.load_id, |
||
| 1064 | EgonPfHvLoadTimeseries.p_set, |
||
| 1065 | ) |
||
| 1066 | .join( |
||
| 1067 | EgonPfHvLoadTimeseries, |
||
| 1068 | EgonPfHvLoadTimeseries.load_id == EgonPfHvLoad.load_id, |
||
| 1069 | ) |
||
| 1070 | .filter( |
||
| 1071 | EgonPfHvLoad.carrier == "land transport EV", |
||
| 1072 | EgonPfHvLoad.scn_name == "eGon2035_lowflex", |
||
| 1073 | EgonPfHvLoadTimeseries.scn_name == "eGon2035_lowflex", |
||
| 1074 | ) |
||
| 1075 | ) |
||
| 1076 | model_charging_load_lowflex = pd.read_sql( |
||
| 1077 | query.statement, query.session.bind, index_col=None |
||
| 1078 | ) |
||
| 1079 | charging_load = np.array( |
||
| 1080 | model_charging_load_lowflex.p_set.to_list() |
||
| 1081 | ).sum(axis=0) |
||
| 1082 | |||
| 1083 | # Ratio of driving and charging load should be 0.9 due to charging |
||
| 1084 | # efficiency |
||
| 1085 | print(" Compare cumulative loads...") |
||
| 1086 | print(f" Driving load (eGon2035): {driving_load.sum() / 1e6} TWh") |
||
| 1087 | print( |
||
| 1088 | f" Dumb charging load (eGon2035_lowflex): " |
||
| 1089 | f"{charging_load.sum() / 1e6} TWh" |
||
| 1090 | ) |
||
| 1091 | driving_load_theoretical = ( |
||
| 1092 | float(meta_run_config.eta_cp) * charging_load.sum() |
||
| 1093 | ) |
||
| 1094 | np.testing.assert_allclose( |
||
| 1095 | driving_load.sum(), |
||
| 1096 | driving_load_theoretical, |
||
| 1097 | rtol=0.01, |
||
| 1098 | err_msg=( |
||
| 1099 | f"The driving load (eGon2035) deviates by more than 1% " |
||
| 1100 | f"from the theoretical driving load calculated from charging " |
||
| 1101 | f"load (eGon2035_lowflex) with an efficiency of " |
||
| 1102 | f"{float(meta_run_config.eta_cp)}." |
||
| 1103 | ), |
||
| 1104 | ) |
||
| 1105 | |||
| 1106 | print("=====================================================") |
||
| 1107 | print("=== SANITY CHECKS FOR MOTORIZED INDIVIDUAL TRAVEL ===") |
||
| 1108 | print("=====================================================") |
||
| 1109 | |||
| 1110 | for scenario_name in ["eGon2035", "eGon100RE"]: |
||
| 1111 | scenario_var_name = DATASET_CFG["scenario"]["variation"][scenario_name] |
||
| 1112 | |||
| 1113 | print("") |
||
| 1114 | print(f"SCENARIO: {scenario_name}, VARIATION: {scenario_var_name}") |
||
| 1115 | |||
| 1116 | # Load scenario params for scenario and scenario variation |
||
| 1117 | scenario_variation_parameters = get_sector_parameters( |
||
| 1118 | "mobility", scenario=scenario_name |
||
| 1119 | )["motorized_individual_travel"][scenario_var_name] |
||
| 1120 | |||
| 1121 | # Load simBEV run config and tech data |
||
| 1122 | meta_run_config = read_simbev_metadata_file( |
||
| 1123 | scenario_name, "config" |
||
| 1124 | ).loc["basic"] |
||
| 1125 | meta_tech_data = read_simbev_metadata_file(scenario_name, "tech_data") |
||
| 1126 | |||
| 1127 | print("") |
||
| 1128 | print("Checking EV counts...") |
||
| 1129 | ev_count_alloc = check_ev_allocation() |
||
| 1130 | |||
| 1131 | print("") |
||
| 1132 | print("Checking trip data...") |
||
| 1133 | check_trip_data() |
||
| 1134 | |||
| 1135 | print("") |
||
| 1136 | print("Checking model data...") |
||
| 1137 | check_model_data() |
||
| 1138 | |||
| 1139 | print("") |
||
| 1140 | check_model_data_lowflex_eGon2035() |
||
| 1141 | |||
| 1142 | print("=====================================================") |
||
| 1143 |