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