API 参考 - 后处理模块 (Post-processing)¶
后处理模块 (Post-processing)
后处理模块 (Post-processing) 提供了在仿真运行后自动执行的分析和报告功能。 请在下方的标签页中选择您感兴趣的特定模块。
This module provides functions for plotting simulation results.
baseline_analysis(results_df, output_dir, **kwargs)
¶
Generates baseline analysis plots and reports.
Creates three outputs: 1. A time-series plot with overall view and detailed zoom around turning point 2. A bar chart showing final values of all variables, sorted 3. An optional Markdown report with AI analysis (if 'ai' flag is True)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results_df
|
DataFrame
|
The combined DataFrame of simulation results. |
required |
output_dir
|
str
|
The directory to save the plots and report. |
required |
**kwargs
|
Additional parameters from config, including 'ai' flag, 'detailed_var', 'glossary_path', and AI model settings. |
{}
|
Note
Removes duplicate rows before processing. Creates bilingual plots (English and Chinese). If AI analysis enabled, requires API_KEY, BASE_URL, and AI_MODELS/AI_MODEL environment variables. Generates both initial LLM analysis and academic summary.
Source code in tricys/postprocess/baseline_analysis.py
879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 | |
generate_academic_report(output_dir, ai_model, **kwargs)
¶
Generates a professional academic analysis summary by sending the existing report and a glossary of terms to an LLM.
Source code in tricys/postprocess/baseline_analysis.py
737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 | |
load_glossary(glossary_path)
¶
Loads glossary data from the specified CSV path into global dictionaries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
glossary_path
|
str
|
Path to the glossary CSV file. |
required |
Note
Expected columns: "模型参数 (Model Parameter)", "英文术语 (English Term)", "中文翻译 (Chinese Translation)". Clears existing glossaries on error. Updates global _english_glossary_map and _chinese_glossary_map.
Source code in tricys/postprocess/baseline_analysis.py
set_plot_language(lang='en')
¶
Sets the preferred language for plot labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lang
|
str
|
'en' for English (default), 'cn' for Chinese. |
'en'
|
Note
For Chinese, sets font to SimHei and adjusts unicode_minus. For English, restores matplotlib defaults. Changes apply globally to all subsequent plots.
Source code in tricys/postprocess/baseline_analysis.py
analyze_rise_dip(results_df, output_dir, **kwargs)
¶
Analyzes parameter sweep results to identify curves that fail to exhibit 'dip and rise' feature.
A curve exhibits the 'dip and rise' feature if: 1. It has a clear minimum point (not at boundaries) 2. Values at both start and end are higher than the minimum (with tolerance)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results_df
|
DataFrame
|
The combined DataFrame of simulation results, including time and multiple parameter combinations. |
required |
output_dir
|
str
|
The directory to save the analysis report. |
required |
**kwargs
|
Additional parameters from config, e.g., 'output_filename'. |
{}
|
Note
Uses 0.1% smoothing window to handle noisy data. Column names expected in format 'variable¶m1=v1¶m2=v2'. Logs ERROR for each curve without the feature. Always generates rise_report.json with analysis results for all curves, including 'rises' boolean flag.
Source code in tricys/postprocess/rise_analysis.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
check_thresholds(results_df, output_dir, rules, **kwargs)
¶
Analyzes simulation results to check if specified columns fall within threshold ranges.
Supports both single tasks (column name as 'var') and parameter sweep tasks (column name as 'var¶m=value').
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results_df
|
DataFrame
|
Merged simulation results DataFrame. |
required |
output_dir
|
str
|
Directory for saving alert reports. |
required |
rules
|
List[Dict[str, Any]]
|
List of rules, where each rule defines columns and their min/max thresholds. Format: [{"columns": ["var1", "var2"], "min": value, "max": value}, ...] |
required |
**kwargs
|
Additional parameters from configuration, such as 'output_filename'. |
{}
|
Note
Logs ERROR for each threshold violation with peak/dip values. Generates alarm_report.json with parsed parameter information and 'has_alarm' flags. For columns matching 'base_col_name¶m=value', extracts parameters into separate fields in the report. Reports total alarm count in logs.
Source code in tricys/postprocess/static_alarm.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |