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