Commit fc2cefaca481780132aba424983d01f98c66b861
1 parent
a7875a37
Adapt to usual coding standards.
Showing
1 changed file
with
27 additions
and
8 deletions
test/test_GSky.py
| ... | ... | @@ -21,19 +21,31 @@ from gammalib import * |
| 21 | 21 | from math import * |
| 22 | 22 | import os |
| 23 | 23 | |
| 24 | + | |
| 25 | +# =========== # | |
| 26 | +# Text parser # | |
| 27 | +# =========== # | |
| 24 | 28 | def loadtxt(filename): |
| 25 | - """Parse text file with columns of floats. | |
| 29 | + """ | |
| 30 | + Parse text file with columns of floats. | |
| 26 | 31 | |
| 27 | 32 | We have files with multiple spaces as delimiter, |
| 28 | - which I think csv.reader can't handle.""" | |
| 33 | + which I think csv.reader can't handle. | |
| 34 | + """ | |
| 35 | + # Initialise result array | |
| 29 | 36 | data = [] |
| 37 | + | |
| 38 | + # Loop over all rows in file | |
| 30 | 39 | for row in [_.split() for _ in file(filename)]: |
| 31 | 40 | row_data = [] |
| 32 | 41 | for item in row: |
| 33 | 42 | row_data.append(float(item)) |
| 34 | 43 | data.append(row_data) |
| 44 | + | |
| 45 | + # Return result | |
| 35 | 46 | return data |
| 36 | 47 | |
| 48 | + | |
| 37 | 49 | # ================================== # |
| 38 | 50 | # Test class for GammaLib sky module # |
| 39 | 51 | # ================================== # |
| ... | ... | @@ -222,6 +234,7 @@ class Test(GPythonTestSuite): |
| 222 | 234 | # Return |
| 223 | 235 | return |
| 224 | 236 | |
| 237 | + # FK5 J2000 to Galactic coordinate tranformations | |
| 225 | 238 | def test_fk5_to_galactic(self): |
| 226 | 239 | """ |
| 227 | 240 | Test precision of FK5 J2000 to Galactic coordinate tranformations |
| ... | ... | @@ -231,14 +244,17 @@ class Test(GPythonTestSuite): |
| 231 | 244 | Test txt files taken from: |
| 232 | 245 | See https://github.com/astropy/coordinates-benchmark |
| 233 | 246 | """ |
| 234 | - fk5_filename = "data/initial_coords.txt" | |
| 235 | - galactic_filename = "data/fk5_to_galactic.txt" | |
| 236 | - fk5_coordinates = loadtxt(fk5_filename) | |
| 247 | + # Set parameters | |
| 248 | + fk5_filename = "data/initial_coords.txt" | |
| 249 | + galactic_filename = "data/fk5_to_galactic.txt" | |
| 250 | + fk5_coordinates = loadtxt(fk5_filename) | |
| 237 | 251 | galactic_coordinates = loadtxt(galactic_filename) |
| 238 | - coordinates = zip(fk5_coordinates, galactic_coordinates) | |
| 239 | - max_dist = 0 | |
| 252 | + coordinates = zip(fk5_coordinates, galactic_coordinates) | |
| 253 | + max_dist = 0 | |
| 240 | 254 | |
| 255 | + # Loop over coordinates | |
| 241 | 256 | for (ra, dec), (glon, glat) in coordinates: |
| 257 | + | |
| 242 | 258 | # Create point A in FK5 J2000 coordinates |
| 243 | 259 | input_point = GSkyDir() |
| 244 | 260 | input_point.radec_deg(ra, dec) |
| ... | ... | @@ -256,7 +272,9 @@ class Test(GPythonTestSuite): |
| 256 | 272 | this_dist = actual_point.dist_deg(reference_point) |
| 257 | 273 | max_dist = max(max_dist, this_dist) |
| 258 | 274 | |
| 259 | - max_dist *= 1e3 * 3600 # convert max_dist from deg to milli-arcsec | |
| 275 | + # Convert max_dist from deg to milli-arcsec | |
| 276 | + max_dist *= 1e3 * 3600 | |
| 277 | + | |
| 260 | 278 | # Results match within 10 milli-arcsec on my machine, |
| 261 | 279 | # I put 20 arcsec here to avoid test failures on machines with |
| 262 | 280 | # slightly different numerical results |
| ... | ... | @@ -264,4 +282,5 @@ class Test(GPythonTestSuite): |
| 264 | 282 | err = '' |
| 265 | 283 | self.test_assert(max_dist < 20, msg, err) |
| 266 | 284 | |
| 285 | + # Return | |
| 267 | 286 | return | ... | ... |