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