22from numpy .testing import assert_allclose
33
44from mapflpy .scripts import run_forward_tracing , run_backward_tracing , run_fwdbwd_tracing , inter_domain_tracing
5- from tests .utils import compute_fieldline_length , compute_weighted_fieldline_difference
5+ from tests .utils import compute_fieldline_length , compute_weighted_fieldline_difference , _BUFFER_SIZE , _TEST_TOLERANCES , _DOMAIN_RANGES
66from mapflpy .utils import trim_fieldline_nan_buffer , combine_fwd_bwd_traces
77
88
99@pytest .mark .filterwarnings ("ignore::DeprecationWarning" )
10- def test_tracing_against_reference_traces (tracermp_instance , mesh_fields_aspaths , launch_points , default_params , reference_traces ):
11- mesh_id , (br , bt , bp ) = mesh_fields_aspaths
12- lps_id , lps = launch_points
10+ def test_tracing_against_reference_traces (tracermp_instance ,
11+ mesh_resolution ,
12+ mas_type ,
13+ tracing_direction ,
14+ mesh_fields_aspaths ,
15+ launch_points ,
16+ reference_traces ):
17+ br , bt , bp = mesh_fields_aspaths
18+ lps = launch_points
1319 tracermp_instance .br = br
1420 tracermp_instance .bt = bt
1521 tracermp_instance .bp = bp
1622
17- match lps_id :
23+ match tracing_direction :
1824 case 'fwd' :
1925 tracermp_instance .set_tracing_direction ('f' )
20- traces = tracermp_instance .trace (lps , buffer_size = default_params [ 'lps' ][ 'BUFFER' ] )
26+ traces = tracermp_instance .trace (lps , buffer_size = _BUFFER_SIZE )
2127 case 'bwd' :
2228 tracermp_instance .set_tracing_direction ('b' )
23- traces = tracermp_instance .trace (lps , buffer_size = default_params [ 'lps' ][ 'BUFFER' ] )
29+ traces = tracermp_instance .trace (lps , buffer_size = _BUFFER_SIZE )
2430 case 'both' :
2531 tracermp_instance .set_tracing_direction ('f' )
26- fwd_traces = tracermp_instance .trace (lps , buffer_size = default_params [ 'lps' ][ 'BUFFER' ] )
32+ fwd_traces = tracermp_instance .trace (lps , buffer_size = _BUFFER_SIZE )
2733 tracermp_instance .set_tracing_direction ('b' )
28- bwd_traces = tracermp_instance .trace (lps , buffer_size = default_params [ 'lps' ][ 'BUFFER' ] )
34+ bwd_traces = tracermp_instance .trace (lps , buffer_size = _BUFFER_SIZE )
2935 traces = combine_fwd_bwd_traces (fwd_traces , bwd_traces )
3036 case _:
31- raise ValueError (f'Unknown launch points id: { lps_id } ' )
37+ raise ValueError (f'Unknown launch points id: { tracing_direction } ' )
3238
3339 traces_trimmed = trim_fieldline_nan_buffer (traces )
3440 for i , arr in enumerate (traces_trimmed ):
35- wdist = compute_weighted_fieldline_difference (arr , reference_traces [f'{ mesh_id } _{ lps_id } _{ i } ' ])
36- assert_allclose (wdist , 0 , atol = default_params ['_testing' ]['tolerances' ]['atol_exact' ])
41+ wdist = compute_weighted_fieldline_difference (arr , reference_traces [f'{ mesh_resolution } _{ mas_type } _{ tracing_direction } _{ i } ' ])
42+ assert_allclose (wdist , 0 , atol = _TEST_TOLERANCES ['atol_exact' ])
43+
44+
45+ @pytest .mark .filterwarnings ("ignore::DeprecationWarning" )
46+ def test_old_mas_traces_against_new_mas_traces (tracermp_instance ,
47+ mesh_resolution ,
48+ tracing_direction ,
49+ old_and_new_mas ,
50+ launch_points ,
51+ reference_traces ):
52+ mas_old , mas_new = old_and_new_mas
53+ tracermp_instance .load_fields (* mas_old )
54+
55+ match tracing_direction :
56+ case 'fwd' :
57+ tracermp_instance .set_tracing_direction ('f' )
58+ traces = tracermp_instance .trace (launch_points , buffer_size = _BUFFER_SIZE )
59+ case 'bwd' :
60+ tracermp_instance .set_tracing_direction ('b' )
61+ traces = tracermp_instance .trace (launch_points , buffer_size = _BUFFER_SIZE )
62+ case 'both' :
63+ tracermp_instance .set_tracing_direction ('f' )
64+ fwd_traces = tracermp_instance .trace (launch_points , buffer_size = _BUFFER_SIZE )
65+ tracermp_instance .set_tracing_direction ('b' )
66+ bwd_traces = tracermp_instance .trace (launch_points , buffer_size = _BUFFER_SIZE )
67+ traces = combine_fwd_bwd_traces (fwd_traces , bwd_traces )
68+ case _:
69+ raise ValueError (f'Unknown launch points id: { tracing_direction } ' )
70+
71+ traces_trimmed = trim_fieldline_nan_buffer (traces )
72+ for i , arr in enumerate (traces_trimmed ):
73+ wdist = compute_weighted_fieldline_difference (arr , reference_traces [f'{ mesh_resolution } _new_mas_{ tracing_direction } _{ i } ' ])
74+ assert_allclose (wdist , 0 , atol = _TEST_TOLERANCES ['atol_fuzzy' ])
75+
76+
77+ @pytest .mark .filterwarnings ("ignore::DeprecationWarning" )
78+ def test_new_mas_traces_against_old_mas_traces (tracermp_instance ,
79+ mesh_resolution ,
80+ tracing_direction ,
81+ old_and_new_mas ,
82+ launch_points ,
83+ reference_traces ):
84+ mas_old , mas_new = old_and_new_mas
85+ tracermp_instance .load_fields (* mas_new )
86+
87+ match tracing_direction :
88+ case 'fwd' :
89+ tracermp_instance .set_tracing_direction ('f' )
90+ traces = tracermp_instance .trace (launch_points , buffer_size = _BUFFER_SIZE )
91+ case 'bwd' :
92+ tracermp_instance .set_tracing_direction ('b' )
93+ traces = tracermp_instance .trace (launch_points , buffer_size = _BUFFER_SIZE )
94+ case 'both' :
95+ tracermp_instance .set_tracing_direction ('f' )
96+ fwd_traces = tracermp_instance .trace (launch_points , buffer_size = _BUFFER_SIZE )
97+ tracermp_instance .set_tracing_direction ('b' )
98+ bwd_traces = tracermp_instance .trace (launch_points , buffer_size = _BUFFER_SIZE )
99+ traces = combine_fwd_bwd_traces (fwd_traces , bwd_traces )
100+ case _:
101+ raise ValueError (f'Unknown launch points id: { tracing_direction } ' )
102+
103+ traces_trimmed = trim_fieldline_nan_buffer (traces )
104+ for i , arr in enumerate (traces_trimmed ):
105+ wdist = compute_weighted_fieldline_difference (arr , reference_traces [f'{ mesh_resolution } _old_mas_{ tracing_direction } _{ i } ' ])
106+ assert_allclose (wdist , 0 , atol = _TEST_TOLERANCES ['atol_fuzzy' ])
37107
38108
39109@pytest .mark .filterwarnings ("ignore::DeprecationWarning" )
40- def test_tracing_scripts_against_reference_traces (mesh_fields_aspaths , launch_points , default_params , reference_traces ):
41- mesh_id , (br , bt , bp ) = mesh_fields_aspaths
42- lps_id , lps = launch_points
110+ def test_tracing_scripts_against_reference_traces (mesh_resolution ,
111+ mas_type ,
112+ tracing_direction ,
113+ mesh_fields_aspaths ,
114+ launch_points ,
115+ reference_traces ):
116+ br , bt , bp = mesh_fields_aspaths
117+ lps = launch_points
43118
44- match lps_id :
119+ match tracing_direction :
45120 case 'fwd' :
46- traces = run_forward_tracing (br , bt , bp , lps , buffer_size = default_params [ 'lps' ][ 'BUFFER' ] )
121+ traces = run_forward_tracing (br , bt , bp , lps , buffer_size = _BUFFER_SIZE )
47122 case 'bwd' :
48- traces = run_backward_tracing (br , bt , bp , lps , buffer_size = default_params [ 'lps' ][ 'BUFFER' ] )
123+ traces = run_backward_tracing (br , bt , bp , lps , buffer_size = _BUFFER_SIZE )
49124 case 'both' :
50- traces = run_fwdbwd_tracing (br , bt , bp , lps , buffer_size = default_params [ 'lps' ][ 'BUFFER' ] )
125+ traces = run_fwdbwd_tracing (br , bt , bp , lps , buffer_size = _BUFFER_SIZE )
51126 case _:
52- raise ValueError (f'Unknown launch points id: { lps_id } ' )
127+ raise ValueError (f'Unknown launch points id: { tracing_direction } ' )
53128
54129 traces_trimmed = trim_fieldline_nan_buffer (traces )
55130 for i , arr in enumerate (traces_trimmed ):
56- wdist = compute_weighted_fieldline_difference (arr , reference_traces [f'{ mesh_id } _{ lps_id } _{ i } ' ])
57- assert_allclose (wdist , 0 , atol = default_params ['_testing' ]['tolerances' ]['atol_exact' ])
131+ wdist = compute_weighted_fieldline_difference (arr , reference_traces [f'{ mesh_resolution } _{ mas_type } _{ tracing_direction } _{ i } ' ])
132+ assert_allclose (wdist , 0 , atol = _TEST_TOLERANCES ['atol_exact' ])
133+
58134
59135@pytest .mark .filterwarnings ("ignore::DeprecationWarning" )
60- def test_interdomain_tracing_against_reference_traces (interdomain_files , launch_points , default_params , reference_traces ):
136+ def test_interdomain_tracing_against_reference_traces (mesh_resolution ,
137+ mas_type ,
138+ tracing_direction ,
139+ interdomain_files ,
140+ launch_points ,
141+ reference_traces ):
61142 """
62143 This test compares an interdomain trace where the domain has been split at r_interface to the reference traces
63144 where there was no split-domain. These traces can differ more because exactly where the interface lies along
64145 a reference field line segment can vary, which is effectively like seeding a part (or parts) of the trace
65146 with a slightly different start location. This means the traces *will not* be the same length and we must
66147 use the fuzzy tolerances because the errors are related to the mesh and discretization of B (not the tracer itself).
67148 """
68- mesh_id , ( br_cor , bt_cor , bp_cor , br_hel , bt_hel , bp_hel ) = interdomain_files
69- lps_id , lps = launch_points
70- buffer = default_params [ 'lps' ][ 'BUFFER' ]
149+ br_cor , bt_cor , bp_cor , br_hel , bt_hel , bp_hel = interdomain_files
150+ lps = launch_points
151+ buffer = _BUFFER_SIZE
71152
72- assert default_params [ "_testing" ][ "domain_ranges" ][ 'cor' ]['r1' ] == default_params [ "_testing" ][ "domain_ranges" ] ['hel' ]['r0' ], \
153+ assert _DOMAIN_RANGES [ 'cor' ]['r1' ] == _DOMAIN_RANGES ['hel' ]['r0' ], \
73154 "Inconsistent domain interface radii."
74- r_interface = default_params [ "_testing" ][ "domain_ranges" ] ['cor' ]['r1' ]
155+ r_interface = _DOMAIN_RANGES ['cor' ]['r1' ]
75156
76- if lps_id != 'both' :
157+ if tracing_direction != 'both' :
77158 pytest .skip ("Interdomain tracing only implemented for both directions." )
78159 else :
79160 traces , * _ = inter_domain_tracing (br_cor ,
@@ -86,10 +167,11 @@ def test_interdomain_tracing_against_reference_traces(interdomain_files, launch_
86167 r_interface = r_interface ,
87168 buffer_size = buffer )
88169 for i , arr in enumerate (traces ):
170+ reference_trace = reference_traces [f'{ mesh_resolution } _{ mas_type } _{ tracing_direction } _{ i } ' ]
89171 # compare the distance of the first and last points (footprints)
90- wdist = compute_weighted_fieldline_difference (arr [:, [0 , - 1 ]], reference_traces [ f' { mesh_id } _ { lps_id } _ { i } ' ] [:, [0 , - 1 ]])
91- assert_allclose (wdist , 0 , atol = default_params [ "_testing" ][ "tolerances" ] ['atol_fuzzy' ])
172+ wdist = compute_weighted_fieldline_difference (arr [:, [0 , - 1 ]], reference_trace [:, [0 , - 1 ]])
173+ assert_allclose (wdist , 0 , atol = _TEST_TOLERANCES ['atol_fuzzy' ])
92174 # compare the lengths of the traces
93175 len_test = compute_fieldline_length (arr )
94- len_ref = compute_fieldline_length (reference_traces [ f' { mesh_id } _ { lps_id } _ { i } ' ] )
95- assert_allclose (len_test , len_ref , rtol = default_params [ "_testing" ][ "tolerances" ] ['rtol_fuzzy' ])
176+ len_ref = compute_fieldline_length (reference_trace )
177+ assert_allclose (len_test , len_ref , rtol = _TEST_TOLERANCES ['rtol_fuzzy' ])
0 commit comments