Answer To: Version and change log Due Date : Friday 29th October 5pm AEST 1 Introduction Automatic detection of...
Dinesh answered on Oct 24 2021
document/assign1prelim-ytipxaae.zip
calc_log_prob_ratio.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
ENGG1811 21T3 Assignment 1
Template file for calc_log_prob_ratio()
@author:
"""
def calc_log_prob_ratio(measurement, conc_range, conc_var):
__MACOSX/._calc_log_prob_ratio.py
calc_signal_log_prob_ratio.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
ENGG1811 21T3 Assignment 1
Template file for calc_signal_log_prob_ratio()
@author:
"""
def calc_signal_log_prob_ratio(conc_signal,conc_range,conc_var):
import calc_log_prob_ratio as clpr
__MACOSX/._calc_signal_log_prob_ratio.py
classify_fault.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
ENGG1811 21T3 Assignment 1
Template file for classify_fault()
@author:
"""
def classify_fault(conc_signal,conc_range,conc_var,conc_cusum_limit,
flow_signal,flow_range,flow_control_window):
import calc_signal_log_prob_ratio as cslpr
import cusum as cs
import detect_fault_in_conc as detect
__MACOSX/._classify_fault.py
conc_signal_0.txt
6.87
5.86
5.76
4.67
6.0
5.84
5.73
6.16
6.21
5.47
5.56
5.76
6.34
6.28
5.35
5.44
6.37
6.79
5.98
5.66
6.55
5.85
6.36
6.97
6.52
6.24
6.57
5.88
6.11
5.91
6.1
5.96
6.11
6.01
6.24
6.23
6.35
6.9
5.43
6.85
6.08
5.58
6.11
6.25
6.73
5.67
6.31
6.26
5.36
5.61
6.5
6.55
6.74
6.47
6.4
6.26
6.8
5.78
6.13
6.39
5.41
6.86
5.8
6.16
7.28
5.79
5.94
6.98
5.66
5.98
6.46
6.43
6.5
6.39
6.87
6.71
6.5
5.86
5.84
5.25
6.54
5.29
6.64
7.12
5.67
5.86
5.96
6.62
5.77
6.13
5.94
6.07
6.85
5.72
6.24
6.34
6.63
5.57
6.76
6.42
conc_signal_1.txt
6.87
5.86
5.76
4.67
6.0
5.84
5.73
6.16
6.21
5.47
5.56
5.76
6.34
6.28
5.35
5.44
6.37
6.79
5.98
5.66
6.55
5.85
6.36
6.77
6.32
6.04
6.37
5.68
5.91
5.71
5.9
5.76
5.91
5.81
6.04
6.03
6.15
6.7
5.23
6.65
5.88
5.38
5.91
6.05
6.53
5.47
6.11
6.06
5.16
5.41
6.3
6.35
6.54
6.27
6.2
6.06
6.6
5.58
5.93
6.19
5.21
6.66
5.6
5.96
7.08
5.59
5.74
6.78
5.46
5.78
6.26
6.23
6.3
6.19
6.67
6.51
6.3
5.66
5.64
5.05
6.34
5.09
6.44
6.92
5.47
5.66
5.76
6.42
5.57
5.93
5.74
5.87
6.65
5.52
6.04
6.14
6.43
5.37
6.56
6.22
conc_signal_2.txt
6.87
5.86
5.76
4.67
6.0
5.84
5.73
6.16
6.21
5.47
5.56
5.76
6.34
6.28
5.35
5.44
6.37
6.79
5.98
5.66
6.55
5.85
6.36
6.97
6.52
6.24
6.57
5.88
6.11
5.91
6.1
5.96
6.11
6.01
6.24
6.23
6.35
6.9
5.43
6.85
6.08
5.58
6.11
6.25
6.73
5.67
6.31
6.26
5.36
5.61
6.5
6.55
6.74
6.47
6.4
6.26
6.8
5.78
6.13
6.39
5.41
6.86
5.8
6.16
7.28
5.79
5.94
6.98
5.66
5.98
6.46
6.43
6.5
6.39
6.87
6.71
6.5
5.86
5.84
5.25
6.54
5.29
6.64
7.12
5.67
5.86
5.96
6.62
5.77
6.13
5.94
6.07
6.85
5.72
6.24
6.34
6.63
5.57
6.76
6.42
conc_signal_cusum_0.txt
0.3479999999999988
0.29199999999999915
0.1959999999999994
0
0.0
0
0
0.06399999999999983
0.14799999999999952
0
0
0
0.13599999999999945
0.24799999999999917
0
0
0.14799999999999952
0.4639999999999984
0.45599999999999863
0.3199999999999992
0.5399999999999983
0.4799999999999983
0.6239999999999979
1.0119999999999965
1.2199999999999955
1.3159999999999952
1.5439999999999945
1.4959999999999947
1.5399999999999947
1.503999999999995
1.5439999999999947
1.5279999999999947
1.5719999999999947
1.5759999999999947
1.6719999999999944
1.7639999999999942
1.9039999999999937
2.2639999999999927
2.0359999999999934
2.375999999999992
2.407999999999992
2.2399999999999927
2.2839999999999927
2.3839999999999923
2.6759999999999913
2.5439999999999916
2.667999999999991
2.7719999999999905
2.5159999999999916
2.3599999999999923
2.5599999999999916
2.779999999999991
3.07599999999999
3.263999999999989
3.423999999999989
3.5279999999999885
3.8479999999999874
3.759999999999988
3.8119999999999874
3.9679999999999866
3.7319999999999878
4.075999999999986
3.9959999999999867
4.059999999999986
4.571999999999985
4.487999999999985
4.463999999999985
4.855999999999984
4.719999999999985
4.711999999999985
4.895999999999984
5.067999999999984
5.267999999999983
5.423999999999983
5.771999999999982
6.0559999999999805
6.25599999999998
6.19999999999998
6.13599999999998
5.835999999999981
6.05199999999998
5.767999999999981
6.0239999999999805
6.471999999999979
6.339999999999979
6.283999999999979
6.267999999999979
6.515999999999979
6.423999999999979
6.475999999999979
6.451999999999979
6.479999999999978
6.819999999999977
6.707999999999977
6.803999999999977
6.939999999999976
7.191999999999975
7.0199999999999765
7.323999999999975
7.491999999999974
conc_signal_cusum_1.txt
0.3479999999999988
0.29199999999999915
0.1959999999999994
0
0.0
0
0
0.06399999999999983
0.14799999999999952
0
0
0
0.13599999999999945
0.24799999999999917
0
0
0.14799999999999952
0.4639999999999984
0.45599999999999863
0.3199999999999992
0.5399999999999983
0.4799999999999983
0.6239999999999979
0.9319999999999966
1.0599999999999963
1.0759999999999963
1.2239999999999958
1.095999999999996
1.0599999999999963
0.9439999999999966
0.9039999999999969
0.8079999999999972
0.7719999999999974
0.6959999999999975
0.7119999999999975
0.7239999999999975
0.7839999999999975
1.0639999999999965
0.7559999999999978
1.015999999999997
0.9679999999999971
0.719999999999998
0.6839999999999982
0.7039999999999981
0.9159999999999975
0.7039999999999982
0.7479999999999981
0.7719999999999979
0.43599999999999917
0.20000000000000007
0.31999999999999956
0.4599999999999989
0.6759999999999982
0.7839999999999976
0.8639999999999974
0.8879999999999972
1.1279999999999961
0.9599999999999967
0.9319999999999967
1.0079999999999967
0.6919999999999977
0.9559999999999969
0.7959999999999973
0.7799999999999974
1.2119999999999957
1.0479999999999963
0.9439999999999967
1.2559999999999958
1.0399999999999965
0.9519999999999968
1.0559999999999965
1.1479999999999964
1.2679999999999958
1.3439999999999956
1.6119999999999948
1.815999999999994
1.9359999999999935
1.799999999999994
1.6559999999999944
1.2759999999999956
1.411999999999995
1.0479999999999963
1.2239999999999958
1.5919999999999943
1.379999999999995
1.2439999999999956
1.147999999999996
1.3159999999999954
1.1439999999999961
1.115999999999996
1.0119999999999965
0.9599999999999966
1.2199999999999958
1.0279999999999963
1.0439999999999963
1.0999999999999959
1.2719999999999951
1.019999999999996
1.243999999999995
1.3319999999999947
conc_signal_cusum_2.txt
0.3479999999999988
0.29199999999999915
0.1959999999999994
0
0.0
0
0
0.06399999999999983
0.14799999999999952
0
0
0
0.13599999999999945
0.24799999999999917
0
0
0.14799999999999952
0.4639999999999984
0.45599999999999863
0.3199999999999992
0.5399999999999983
0.4799999999999983
0.6239999999999979
1.0119999999999965
1.2199999999999955
1.3159999999999952
1.5439999999999945
1.4959999999999947
1.5399999999999947
1.503999999999995
1.5439999999999947
1.5279999999999947
1.5719999999999947
1.5759999999999947
1.6719999999999944
1.7639999999999942
1.9039999999999937
2.2639999999999927
2.0359999999999934
2.375999999999992
2.407999999999992
2.2399999999999927
2.2839999999999927
2.3839999999999923
2.6759999999999913
2.5439999999999916
2.667999999999991
2.7719999999999905
2.5159999999999916
2.3599999999999923
2.5599999999999916
2.779999999999991
3.07599999999999
3.263999999999989
3.423999999999989
3.5279999999999885
3.8479999999999874
3.759999999999988
3.8119999999999874
3.9679999999999866
3.7319999999999878
4.075999999999986
3.9959999999999867
4.059999999999986
4.571999999999985
4.487999999999985
4.463999999999985
4.855999999999984
4.719999999999985
4.711999999999985
4.895999999999984
5.067999999999984
5.267999999999983
5.423999999999983
5.771999999999982
6.0559999999999805
6.25599999999998
6.19999999999998
6.13599999999998
5.835999999999981
6.05199999999998
5.767999999999981
6.0239999999999805
6.471999999999979
6.339999999999979
6.283999999999979
6.267999999999979
6.515999999999979
6.423999999999979
6.475999999999979
6.451999999999979
6.479999999999978
6.819999999999977
6.707999999999977
6.803999999999977
6.939999999999976
7.191999999999975
7.0199999999999765
7.323999999999975
7.491999999999974
cusum.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
ENGG1811 21T3 Assignment 1
Template file for cusum()
@author:
"""
def cusum(conc_lpr):
__MACOSX/._cusum.py
detect_fault_in_conc.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
ENGG1811 21T3 Assignment 1
Template file for detect_fault_in_conc
@author:
"""
def detect_fault_in_conc(conc_cusum,conc_cusum_limit):
__MACOSX/._detect_fault_in_conc.py
detect_fault_main.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
ENGG1811 21T3 Assignment 1
Template file for detect_fault_main
@author:
"""
def detect_fault_main(conc_signal,conc_range,conc_var,conc_cusum_limit,
flow_signal,flow_range,flow_control_window):
import classify_fault as classify
__MACOSX/._detect_fault_main.py
flow_signal_0.txt
22.94
23.07
22.97
22.9
23.05
22.65
22.78
22.78
22.94
22.91
22.96
23.07
23.14
23.08
22.89
23.12
22.97
23.32
23.14
23.0
22.98
22.8
23.02
22.77
23.07
22.63
22.77
23.28
23.3
23.26
22.64
22.7
22.71
22.66
23.05
22.9
23.0
22.9
22.84
23.41
23.12
22.8
23.24
22.87
22.95
23.28
22.84
22.95
22.94
23.35
23.4
23.04
23.38
22.73
22.96
23.26
22.95
23.07
23.04
23.14
23.05
22.7
22.92
22.85
23.12
22.65
22.83
23.24
23.07
23.49
22.99
22.46
23.2
23.04
22.93
22.73
22.96
23.12
23.07
23.02
23.12
23.03
22.79
23.06
23.1
23.39
23.01
22.79
23.23
23.15
22.89
22.76
23.31
22.66
22.87
23.06
22.79
22.96
23.1
22.92
flow_signal_1.txt
22.94
23.07
22.97
22.9
23.05
22.65
22.78
22.78
22.94
22.91
22.96
23.07
23.14
23.08
22.89
23.12
22.97
23.32
23.14
23.0
22.98
22.8
23.02
22.77
23.07
22.63
22.77
23.28
23.3
23.26
22.64
22.7
22.71
22.66
23.05
22.9
23.0
22.9
22.84
23.41
23.12
22.8
23.24
22.87
22.95
23.28
22.84
22.95
22.94
23.35
23.4
23.04
23.38
22.73
22.96
23.26
22.95
23.07
23.04
23.14
23.05
22.7
22.92
22.85
23.12
22.65
22.83
23.24
23.07
23.49
22.99
22.46
23.2
23.04
22.93
22.73
22.96
23.12
23.07
23.02
23.12
23.03
22.79
23.06
23.1
23.39
23.01
22.79
23.23
23.15
22.89
22.76
23.31
22.66
22.87
23.06
22.79
22.96
23.1
22.92
flow_signal_2.txt
22.94
23.07
22.97
22.9
23.05
22.65
22.78
22.78
22.94
22.91
22.96
23.07
23.14
23.08
22.89
23.12
22.97
23.32
23.14
23.0
22.98
22.8
23.02
22.83
23.57
22.47
22.82
24.11
24.15
24.04
22.49
22.65
22.67
22.55
23.51
23.16
23.4
23.15
23.0
24.42
23.7
22.9
24.01
23.07
23.26
24.11
23.01
23.27
23.25
24.26
24.39
23.51
24.35
22.72
23.3
24.04
23.28
23.57
23.51
23.74
23.53
22.66
23.21
23.03
23.69
22.53
22.99
23.99
23.58
24.62
23.38
22.04
23.9
23.5
23.22
22.73
23.31
23.7
23.57
23.44
23.7
23.48
22.88
23.54
23.65
24.37
23.42
22.87
23.98
23.77
23.12
22.79
24.17
22.55
23.08
23.54
22.88
23.31
23.65
23.2
test_calc_prob_ratio.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
ENGG1811 Asssignment 1 (21T3)
You can use this file to test your calc_log_prob_ratio().
This file containing three test cases which you can choose by
adjusting the variable test_index in Line 18.
You can use this file to come out with additional tests.
"""
# %% import
import calc_log_prob_ratio as clpr
# %% Tests
test_index = 0 # Can be 0, 1 or 2
if test_index == 0:
measurement = 6
conc_range = [3, 7]
conc_var = 2
expected_answer = 2.0
elif test_index == 1:
measurement = 6.2
conc_range = [6.1, 6.8]
conc_var = 0.3
expected_answer = -0.58333
elif test_index == 2:
measurement = 6.9
conc_range = [6.0, 7.1]
conc_var = 0.4
expected_answer = 0.9625
# %% Run the function and check the answers
your_answer = clpr.calc_log_prob_ratio(measurement, conc_range, conc_var)
print('Your function returns',your_answer)
print('The expected answer is',expected_answer)
TOL = 1e-5
comparison_output = abs(your_answer-expected_answer) <= TOL
if comparison_output:
print('Your answer is correct')
else:
print('Your answer is NOT correct')
test_calc_signal_log_prob_ratio.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
ENGG1811 Asssignment 1 (21T3)
You can use this file to test your calc_signal_log_prob_ratio().
This file containing three test cases which you can choose by
adjusting the variable test_index in Line 18.
You can use this file to come out with additional tests.
"""
# %% import
import calc_signal_log_prob_ratio as cslpr
# %% Tests
test_index = 0 # Can be 0, 1 or 2
if test_index == 0:
conc_signal = [6, 5, 4, 7]
conc_range = [3, 7]
conc_var = 2
expected_answer = [2.0, 0.0, -2.0, 4.0]
elif test_index == 1:
conc_signal = [15.62, 8.8, 11.69, 18.0, 16.14]
conc_range = [6.1, 6.8]
conc_var = 0.5
expected_answer = [12.838, 3.29, 7.336, 16.17, 13.566]
elif test_index == 2:
conc_signal = [5.55, 6.63, 0.39, 9.38, 2.51, 4.42, 7.11]
conc_range = [6.1, 6.8]
conc_var = 2.5
expected_answer = [-0.252, 0.0504, -1.6968, 0.8204, -1.1032, -0.5684, 0.1848]
# %% Run the function and check the answers
your_answer = cslpr.calc_signal_log_prob_ratio(conc_signal, conc_range, conc_var)
print('Your function returns',your_answer)
print('The expected answer is',expected_answer)
TOL = 1e-5
try:
if len(your_answer) == len(expected_answer):
comparison_output = [True if abs(y-e) <= TOL else False for
y,e in zip(your_answer,expected_answer)]
if all(comparison_output):
print('Your answer is correct')
else:
print('Your answer is NOT correct')
else:
print('The number of list entries in your answer is different from expected.')
except:
print('Your answer is NOT correct.')
print('Probably because your answer is not a list but can be other problems.')
__MACOSX/._test_calc_signal_log_prob_ratio.py
test_classify_fault.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
ENGG1811 Asssignment 1 (21T3)
You can use this file to test your classify_fault().
This file containing three test cases which you can choose by
adjusting the variable test_index in Line 18.
You can use this file to come out with additional tests.
"""
# %% import
import classify_fault as classify
# %% Tests
test_index = 0 # Can be 0, 1 or 2
if test_index == 0:
conc_signal = [6.87, 7.06, 6.96, 5.87, 7.2, 7.04, 6.93, 7.36, 7.41, 6.67]
conc_range = [6.1, 6.8]
conc_var = 0.5
conc_cusum_limit = 3.1
flow_signal = [22.94, 23.07, 22.97, 22.9, 23.05, 22.65, 22.78, 22.78, 22.94, 22.91]
flow_range = [22.5, 23.5]
flow_control_window = 3
expected_answer = 'conc fault only'
elif test_index == 1:
conc_signal = [6.24, 5.66, 6.12, 5.15, 6.38, 6.43, 7.2, 7.14, 6.8, 8.64]
conc_range = [6.1, 6.9]
conc_var = 0.5
conc_cusum_limit = 2.5
flow_signal = [22.94, 23.07, 23.97, 23.9, 24.05, 23.65, 23.78, 23.78, 23.94, 23.91]
flow_range = [22.5, 23.5]
flow_control_window = 5
expected_answer = 'flow and conc faults'
elif test_index == 2:
conc_signal = [6.78, 6.04, 6.09, 5.96, 5.0, 6.07, 5.25, 6.11, 5.72, 6.54, 5.91, 6.01]
conc_range = [5.3, 6.8]
conc_var = 0.5
conc_cusum_limit = 3.7
flow_signal = [23.27, 23.14, 22.69, 23.0, 23.12, 22.86, 23.05, 23.02, 23.0, 22.97, 23.09, 23.24]
flow_range = [22.5, 23.5]
flow_control_window = 3
expected_answer = 'no faults'
# %% Run the function and check the answers
your_answer = classify.classify_fault(conc_signal,conc_range,conc_var,conc_cusum_limit,
flow_signal,flow_range,flow_control_window)
print('Your function returns:',your_answer)
print('The expected answer is:',expected_answer)
comparison_output = your_answer == expected_answer
if comparison_output:
print('Your answer is correct')
else:
print('Your answer is NOT correct')
test_cusum.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
ENGG1811 Asssignment 1 (21T3)
You can use this file to test your cusum().
This file containing three test cases which you can choose by
adjusting the variable test_index in Line 18.
You can use this file to come out with additional tests.
"""
# %% import
import cusum as cs
# %% Tests
test_index = 0 # Can be 0, 1 or 2
if test_index == 0:
conc_lpr = [1, 3, 2, 4]
expected_answer = [1, 4, 6, 10]
elif test_index == 1:
conc_lpr = [2, -1, 3, -8, -1, -2, 3, 4]
expected_answer = [2, 1, 4, 0, 0, 0, 3, 7]
elif test_index == 2:
conc_lpr = [-1.6, -1.3, 2.5, -3.1, -1.7, 4.2, 3.6, -1.2, -0.4, 0.7]
expected_answer = [0, 0, 2.5, 0, 0, 4.2, 7.8, 6.6, 6.2, 6.9]
# %% Run the function and check the answers
your_answer = cs.cusum(conc_lpr)
print('Your function returns',your_answer)
print('The expected answer is',expected_answer)
TOL = 1e-5
try:
if len(your_answer) == len(expected_answer):
comparison_output = [True if abs(y-e) <= TOL else False for
y,e in zip(your_answer,expected_answer)]
if all(comparison_output):
print('Your answer is correct')
else:
print('Your answer is NOT correct')
else:
print('The number of list entries in your answer is different from expected.')
except:
print('Your answer is NOT correct.')
print('Probably because your answer is not a list but can be other problems.')
__MACOSX/._test_cusum.py
test_detect_fault_in_conc.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
ENGG1811 Asssignment 1 (21T3)
You can use this file to test your detect_fault_in_conc().
This file containing four test cases which you can choose by
adjusting the variable test_index in Line 18.
You can use this file to come out with additional tests.
"""
# %% import
import detect_fault_in_conc as detect
import math
# %% Tests
test_index = 2 # Can be 0, 1, 2 or 3
if test_index == 0:
conc_cusum = [0.59, 1.44, 2.16, 1.34, 2.39, 3.22, 3.89, 5.17, 6.51, 6.82]
conc_cusum_limit = 3.1
time_fault_detected_expected = 5
total_fault_time_expected = 5
elif test_index == 1:
conc_cusum = [0.59, 1.44, 2.16, 1.34, 2.39, 3.22, 3.89, 5.17, 6.51, 6.82]
conc_cusum_limit = 1.9
time_fault_detected_expected = 2
total_fault_time_expected = 7
elif test_index == 2:
conc_cusum = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.12, 2.14, 2.62, 6.05]
conc_cusum_limit = 2.5
time_fault_detected_expected = 8
total_fault_time_expected = 2
elif test_index == 3:
conc_cusum = [2.19, 2.16, 2.28, 2.01, 0.0, 0.06, 0.0, 0.18, 0.0, 1.47]
conc_cusum_limit = 3.7
time_fault_detected_expected = math.inf
total_fault_time_expected = 0
# %% Plotting
#
# You can use the following line of code to plot what the cusim signal
# looks like respect to the threshold used for fault detection
#
# Comment the code out for plotting
#
# import matplotlib.pyplot as plt
# plt.plot(conc_cusum)
# plt.axhline(conc_cusum_limit,linestyle='--',color='r')
# plt.title('cusum for test case '+ str(test_index))
# plt.show()
# %% Run the function and check the answers
time_fault_detected_your, total_fault_time_your = \
detect.detect_fault_in_conc(conc_cusum, conc_cusum_limit)
print('For the computation of the time at which fault is detected:')
print('\tYour function returns:',time_fault_detected_your)
print('\tThe expected answer is:',time_fault_detected_expected)
comparison_time_fault_detected = time_fault_detected_your == time_fault_detected_expected
if comparison_time_fault_detected:
print('\tYour answer for the first output is correct')
else:
print('\tour answer for the first output is NOT correct')
print('\n') # Print a blank line
print('For the computation of the total fault time:')
print('\tYour function returns:',total_fault_time_your)
print('\tThe expected answer is:',total_fault_time_expected)
comparison_total_fault_time_expected = total_fault_time_your == total_fault_time_expected
if comparison_total_fault_time_expected:
print('\tYour answer for the second output is correct')
else:
print('\tYour answer for the second output is NOT correct')
__MACOSX/._test_detect_fault_in_conc.py
test_detect_fault_main_0.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
ENGG1811 Asssignment 1 (21T3)
You can use this file to test your detect_fault_main().
This file contains only one test case which is the same as the sample
test code in the project specifications.
You can use this file to come out with additional tests.
"""
# %% Test data and parameters
# The conc signal
conc_signal = [6.55, 6.40, 6.76, 6.45, 6.87, 6.92, 6.45, 7.36, 7.41, 6.67]
# Parameters used to detect whether there is a fault in the conc_signal
conc_range = [6.1, 6.9]
conc_var = 0.5
conc_cusum_limit = 1.55
# The flow_signal
flow_signal = [22.94, 23.07, 23.97, 23.9, 24.05, 23.65, 23.78, 23.78, 23.94, 23.91]
# The parameters used to detect whether there is a fault in the flow_signal
flow_range = [22.5, 23.5]
flow_control_window = 3
# %% Call the fault detection function
import detect_fault_main as df
fault_type_your = df.detect_fault_main(conc_signal,conc_range,conc_var,
conc_cusum_limit,flow_signal,flow_range,flow_control_window)
# The fault type
fault_type_expected = 'flow and conc faults'
print('Your function returns:',fault_type_your)
print('The expected answer is:',fault_type_expected)
comparison_output = fault_type_your == fault_type_expected
if comparison_output:
print('Your answer is correct')
else:
print('Your answer is NOT correct')
__MACOSX/._test_detect_fault_main_0.py
test_detect_fault_main_1.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
ENGG1811 Asssignment 1 (21T3)
You can use this file to test your detect_fault_main().
All the cases in this file have valid parameters and the function should
determine the fault type.
This file containing three test cases which you can choose by
adjusting the variable test_index in Line 20.
You can use this file to come out with additional tests.
"""
# %% import
import detect_fault_main as df
# %% Tests
test_index = 2 # Choose 0, 1 or 2
# Both conc_signal and flow_signal have 100 entries each.
# They will be loaded from files rather than listed here.
#
# load conc_signal and flow_signal from files
with open('conc_signal_'+str(test_index)+'.txt','r') as f:
conc_signal = f.readlines()
conc_signal = [float(d) for d in conc_signal]
with open('flow_signal_'+str(test_index)+'.txt','r') as f:
flow_signal = f.readlines()
flow_signal = [float(d) for d in flow_signal]
# The algorithm parameters - the same all tests
conc_range = [5.9, 6.1]
conc_var = 0.5
conc_cusum_limit = 3.1
flow_range = [22.5, 23.5]
flow_control_window = 10
# The expected answer
if test_index == 0:
expected_answer = 'conc fault only'
elif test_index == 1:
expected_answer = 'no faults'
elif test_index == 2:
expected_answer = 'flow and conc faults'
# %% Run the function and check the answers
your_answer = df.detect_fault_main(conc_signal,conc_range,conc_var,conc_cusum_limit,
flow_signal,flow_range,flow_control_window)
print('Your function returns:',your_answer)
print('The expected answer is:',expected_answer)
comparison_output = your_answer == expected_answer
if comparison_output:
print('Your answer is correct')
else:
print('Your answer is NOT correct')
# %% Code for plotting
"""
Since the signals are long, you can use the code below to visualise them.
The signals that you can plot are:
conc_signal
conc_signal_cusum
flow_signal
A point of interest is that if you look at the conc_singal when there is a
fault and there isn't, you don't see much difference. The fault in the
conc_signal is in fact very small and is not perceptible by eyes. However,
if you look at their corresponding conc_signal_cusum, you will see that
the cusum drifts upwards steadily later on. This is an indication of fault.
We have included this example to demonstrate how powerful it can be if you
can combine computing and maths to achieve a task which is beyond our
visual perception.
If you would like to see plot of the above signals, comment out the
appropriate lines in the code below.
"""
# import matplotlib.pyplot as plt
# # conc_signal
# plt.figure(0)
# plt.plot(conc_signal)
# plt.title('conc signal for test case'+str(test_index))
# # conc_signal_cusum (Need to load the pre-computed data from file)
# plt.figure(1)
# with open('conc_signal_cusum_'+str(test_index)+'.txt','r') as f:
# conc_signal_cusum = f.readlines()
# conc_signal_cusum = [float(d) for d in conc_signal_cusum]
# plt.plot(conc_signal_cusum)
# plt.axhline(conc_cusum_limit,linestyle='--',color='r')
# plt.title('conc cusum for test case'+str(test_index))
# # flow_signal
# plt.figure(2)
# plt.plot(flow_signal)
# plt.title('flow signal for test case'+str(test_index))
__MACOSX/._test_detect_fault_main_1.py
test_detect_fault_main_2.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
ENGG1811 Asssignment 1 (21T3)
You can use this file to test your detect_fault_main().
All the cases in this file are expected to return the output 'invalid parameters'
This file containing three test cases which you can choose by
adjusting the variable test_index in Line 19.
You can use this file to come out with additional tests.
"""
# %% import
import detect_fault_main as df
# %% Tests
test_index = 0 # Can be 0, 1 or 2
if test_index == 0:
conc_signal = [6.87, 7.06, 6.96, 5.87, 7.2, 7.04, 6.93, 7.36, 7.41, 6.67]
conc_range = [6.8, 6.1] # invalid
conc_var = 0.5
conc_cusum_limit = 3.1
flow_signal = [22.94, 23.07, 22.97, 22.9, 23.05, 22.65, 22.78, 22.78, 22.94, 22.91]
flow_range = [22.5, 23.5]
flow_control_window = 3
expected_answer = 'invalid parameters'
elif test_index == 1:
conc_signal = [6.24, 5.66, 6.12, 5.15, 6.38, 6.43, 7.2, 7.14, 6.8, 8.64]
conc_range = [6.1, 6.9]
conc_var = 0.5
conc_cusum_limit = 2.5
flow_signal = [22.94, 23.07, 23.97, 23.9, 24.05, 23.65, 23.78, 23.78, 23.94, 23.91]
flow_range = [22.5, 23.5]
flow_control_window = 5.2 # invalid
expected_answer = 'invalid parameters'
elif test_index == 2:
conc_signal = [6.78, 6.04, 6.09, 5.96, 5.0, 6.07, 5.25, 6.11, 5.72, 6.54, 5.91, 6.01]
conc_range = [5.3, 6.8]
conc_var = 0.5
conc_cusum_limit = 2.6
flow_signal = [23.27, 23.14, 22.69, 23.0, 23.12, 22.86, 23.05, 23.02, 23.0, 22.97, 23.09, 23.24]
flow_range = [22.5, 23.5, 24.5] # invalid
flow_control_window = 3
expected_answer = 'invalid parameters'
# %% Run the function and check the answers
your_answer = df.detect_fault_main(conc_signal,conc_range,conc_var,conc_cusum_limit,
flow_signal,flow_range,flow_control_window)
print('Your function returns:',your_answer)
print('The expected answer is:',expected_answer)
comparison_output = your_answer == expected_answer
if comparison_output:
print('Your answer is correct')
else:
print('Your answer is NOT correct')
__MACOSX/._test_detect_fault_main_2.py
document/version-and-change-log-python-assignment-yeaewdip-1qlkhvwu.docx
Version and change log
Due Date : Friday 29th October 5pm AEST
1 Introduction
Automatic detection of faults can be found in many engineering systems. There are systems to automatically diagnose faults in engines, chemical plants,...