Conditions | 2 |
Total Lines | 61 |
Code Lines | 51 |
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:
1 | # -*- coding: utf-8 -*- |
||
134 | def test_py_msise_flat(): |
||
135 | # high ap values |
||
136 | aph = [100.] * 7 |
||
137 | # set up empty arrays for the aps and flags |
||
138 | aphs = np.empty((17,), dtype=object) |
||
139 | flags = np.empty((17,), dtype=object) |
||
140 | # standard flags |
||
141 | for i in range(17): |
||
142 | flags[i] = [0] + [1] * 23 |
||
143 | # set the standard values 17 times |
||
144 | times = [dt.datetime(2009, 6, 21, 8, 3, 20)] * 17 |
||
145 | alts = [400] * 17 # alt |
||
146 | lats = [60] * 17 # g_lat |
||
147 | lons = [-70] * 17 # g_long |
||
148 | f107a = [150] * 17 # f107A |
||
149 | f107 = [150] * 17 # f107 |
||
150 | ap = [4] * 17 # ap |
||
151 | lsts = [16] * 17 |
||
152 | # update for individual tests |
||
153 | times[1] = dt.datetime(2009, 3, 22, 8, 3, 20) |
||
154 | times[2] = dt.datetime(2009, 6, 21, 20, 50, 0) |
||
155 | alts[2] = 1000 # alt |
||
156 | alts[3] = 100 # alt |
||
157 | alts[10] = 0 # alt |
||
158 | alts[11] = 10 # alt |
||
159 | alts[12] = 30 # alt |
||
160 | alts[13] = 50 # alt |
||
161 | alts[14] = 70 # alt |
||
162 | alts[16] = 100 # alt |
||
163 | lats[4] = 0 # g_lat |
||
164 | lons[5] = 0 # g_long |
||
165 | f107a[7] = 70 # f107A |
||
166 | f107[8] = 180 # f107 |
||
167 | ap[9] = 40 # ap |
||
168 | lsts[6] = 4 |
||
169 | # include ap array for the last two tests |
||
170 | flags[15][9] = -1 |
||
171 | flags[16][9] = -1 |
||
172 | aphs[15] = aph |
||
173 | aphs[16] = aph |
||
174 | # MSIS test outputs from the documentation |
||
175 | test_file = os.path.join( |
||
176 | os.path.realpath(os.path.dirname(__file__)), |
||
177 | "msis_testoutput.txt") |
||
178 | test_output = np.genfromtxt(test_file) |
||
179 | output = msise.msise_flat(times, alts, lats, lons, |
||
180 | f107a, f107, ap, lst=lsts, ap_a=aphs, flags=flags) |
||
181 | # Compare results |
||
182 | np.testing.assert_allclose(output, test_output, rtol=1e-6) |
||
183 | # single call only, default ap and flags |
||
184 | output0 = msise.msise_flat(times[0], alts[0], lats[0], lons[0], |
||
185 | f107a[0], f107[0], ap[0], lst=lsts[0]) |
||
186 | np.testing.assert_allclose(output0, test_output[0], rtol=1e-6) |
||
187 | # special flags and ap setting in a single call |
||
188 | aps0 = np.empty((1,), dtype=object) |
||
189 | flags0 = np.empty((1,), dtype=object) |
||
190 | aps0[0] = aphs[16] |
||
191 | flags0[0] = flags[16] |
||
192 | output0 = msise.msise_flat(times[16], alts[16], lats[16], lons[16], |
||
193 | f107a[16], f107[16], ap[16], lst=lsts[16], ap_a=aps0, flags=flags0) |
||
194 | np.testing.assert_allclose(output0[0], test_output[16], rtol=1e-6) |
||
195 | |||
228 |