Commit 4b2b52fee940d5e4de4831aa0523cef81d1a10cd
1 parent
5947039a
Add unit test of make_pointings.py script
Showing
2 changed files
with
195 additions
and
64 deletions
examples/make_pointings.py
| 1 | #! /usr/bin/env python | 1 | #! /usr/bin/env python |
| 2 | # ========================================================================== | 2 | # ========================================================================== |
| 3 | -# This script generates pointing patterns for CTA observations. | 3 | +# Generates pointing patterns for CTA observations |
| 4 | # | 4 | # |
| 5 | -# Usage: | ||
| 6 | -# ./make_pointings.py | ||
| 7 | -# | ||
| 8 | -# ========================================================================== | ||
| 9 | -# | ||
| 10 | -# Copyright (C) 2015 Juergen Knoedlseder | 5 | +# Copyright (C) 2015-2016 Juergen Knoedlseder |
| 11 | # | 6 | # |
| 12 | # This program is free software: you can redistribute it and/or modify | 7 | # This program is free software: you can redistribute it and/or modify |
| 13 | # it under the terms of the GNU General Public License as published by | 8 | # it under the terms of the GNU General Public License as published by |
| @@ -33,10 +28,30 @@ import gammalib | @@ -33,10 +28,30 @@ import gammalib | ||
| 33 | # ============================================================ # | 28 | # ============================================================ # |
| 34 | def get_positions(xmin, xmax, ymin, ymax, step): | 29 | def get_positions(xmin, xmax, ymin, ymax, step): |
| 35 | """ | 30 | """ |
| 31 | + Get pointing positions for an interleaved pattern | ||
| 32 | + | ||
| 36 | Get positions for a patch of interleaved pointings on the sky. | 33 | Get positions for a patch of interleaved pointings on the sky. |
| 37 | The function does respect the latitude dependence of the | 34 | The function does respect the latitude dependence of the |
| 38 | pointing distance. The step parameter is for a latitude of | 35 | pointing distance. The step parameter is for a latitude of |
| 39 | zero. | 36 | zero. |
| 37 | + | ||
| 38 | + Parameters | ||
| 39 | + ---------- | ||
| 40 | + xmin : float | ||
| 41 | + Minimum longitude (deg) | ||
| 42 | + xmax : float | ||
| 43 | + Maximum longitude (deg) | ||
| 44 | + ymin : float | ||
| 45 | + Minimum latitude (deg) | ||
| 46 | + ymax : float | ||
| 47 | + Maximum latitude (deg) | ||
| 48 | + step : float | ||
| 49 | + Pointing step size (deg) | ||
| 50 | + | ||
| 51 | + Returns | ||
| 52 | + ------- | ||
| 53 | + positions : list of dict | ||
| 54 | + List of dictionaries with x and y positions | ||
| 40 | """ | 55 | """ |
| 41 | # Initialise positions | 56 | # Initialise positions |
| 42 | positions = [] | 57 | positions = [] |
| @@ -46,7 +61,7 @@ def get_positions(xmin, xmax, ymin, ymax, step): | @@ -46,7 +61,7 @@ def get_positions(xmin, xmax, ymin, ymax, step): | ||
| 46 | ny = int((ymax-ymin)/ystep+1.5) | 61 | ny = int((ymax-ymin)/ystep+1.5) |
| 47 | rescale = (ymax-ymin)/(ystep*(ny-1)) | 62 | rescale = (ymax-ymin)/(ystep*(ny-1)) |
| 48 | ystep *= rescale | 63 | ystep *= rescale |
| 49 | - print("Number of rows ....: %d" % (ny)) | 64 | + print('Number of rows ....: %d' % (ny)) |
| 50 | 65 | ||
| 51 | # Loop over rows | 66 | # Loop over rows |
| 52 | y = ymin | 67 | y = ymin |
| @@ -63,7 +78,6 @@ def get_positions(xmin, xmax, ymin, ymax, step): | @@ -63,7 +78,6 @@ def get_positions(xmin, xmax, ymin, ymax, step): | ||
| 63 | x = xmin | 78 | x = xmin |
| 64 | else: | 79 | else: |
| 65 | x = xmin + 0.5 * xstep | 80 | x = xmin + 0.5 * xstep |
| 66 | - #print(row, y, nx) | ||
| 67 | 81 | ||
| 68 | # Append pointings | 82 | # Append pointings |
| 69 | for pnt in range(nx): | 83 | for pnt in range(nx): |
| @@ -86,7 +100,33 @@ def set_patch(lmin=-30.0, lmax=30.0, bmin=-1.5, bmax=+1.5, | @@ -86,7 +100,33 @@ def set_patch(lmin=-30.0, lmax=30.0, bmin=-1.5, bmax=+1.5, | ||
| 86 | separation=3.0, hours=100.0, | 100 | separation=3.0, hours=100.0, |
| 87 | site=None, lst=True, autodec=0.0): | 101 | site=None, lst=True, autodec=0.0): |
| 88 | """ | 102 | """ |
| 89 | - Setup pointing patch on the sky. | 103 | + Setup pointing patch on the sky |
| 104 | + | ||
| 105 | + Parameters | ||
| 106 | + ---------- | ||
| 107 | + lmin : float, optional | ||
| 108 | + Minimum Galactic Longitude (deg) | ||
| 109 | + lmax : float, optional | ||
| 110 | + Maximum Galactic Longitude (deg) | ||
| 111 | + bmin : float, optional | ||
| 112 | + Minimum Galactic Latitude (deg) | ||
| 113 | + bmax : float, optional | ||
| 114 | + Maximum Galactic Latitude (deg) | ||
| 115 | + separation : float, optional | ||
| 116 | + Pointing separation (deg) | ||
| 117 | + hours : float, optional | ||
| 118 | + Total observation duration (h) | ||
| 119 | + site : str, optional | ||
| 120 | + Array site (one of 'Automatic', 'South', 'North') | ||
| 121 | + lst : bool, optional | ||
| 122 | + Use LSTs | ||
| 123 | + autodec : float, optional | ||
| 124 | + Declination for switching automatically between South and North site | ||
| 125 | + | ||
| 126 | + Returns | ||
| 127 | + ------- | ||
| 128 | + obsdef : list of dict | ||
| 129 | + List of pointing definitions | ||
| 90 | """ | 130 | """ |
| 91 | # Initialise observation definition | 131 | # Initialise observation definition |
| 92 | obsdef = [] | 132 | obsdef = [] |
| @@ -112,30 +152,30 @@ def set_patch(lmin=-30.0, lmax=30.0, bmin=-1.5, bmax=+1.5, | @@ -112,30 +152,30 @@ def set_patch(lmin=-30.0, lmax=30.0, bmin=-1.5, bmax=+1.5, | ||
| 112 | if site != None: | 152 | if site != None: |
| 113 | 153 | ||
| 114 | # Handle automatic site switching | 154 | # Handle automatic site switching |
| 115 | - if site == "Automatic": | 155 | + if site == 'Automatic': |
| 116 | pos = gammalib.GSkyDir() | 156 | pos = gammalib.GSkyDir() |
| 117 | pos.lb_deg(pnt['x'], pnt['y']) | 157 | pos.lb_deg(pnt['x'], pnt['y']) |
| 118 | dec = pos.dec_deg() | 158 | dec = pos.dec_deg() |
| 119 | if (dec >= autodec): | 159 | if (dec >= autodec): |
| 120 | - obs_site = "North" | 160 | + obs_site = 'North' |
| 121 | else: | 161 | else: |
| 122 | - obs_site = "South" | 162 | + obs_site = 'South' |
| 123 | else: | 163 | else: |
| 124 | obs_site = site | 164 | obs_site = site |
| 125 | 165 | ||
| 126 | # Set site IRF | 166 | # Set site IRF |
| 127 | - caldb = "prod2" | ||
| 128 | - if obs_site == "North": | 167 | + caldb = 'prod2' |
| 168 | + if obs_site == 'North': | ||
| 129 | if lst: | 169 | if lst: |
| 130 | - irf = "North_50h" | 170 | + irf = 'North_50h' |
| 131 | else: | 171 | else: |
| 132 | - irf = "North_50h" | 172 | + irf = 'North_50h' |
| 133 | exposure_north += duration | 173 | exposure_north += duration |
| 134 | else: | 174 | else: |
| 135 | if lst: | 175 | if lst: |
| 136 | - irf = "South_50h" | 176 | + irf = 'South_50h' |
| 137 | else: | 177 | else: |
| 138 | - irf = "South_50h" | 178 | + irf = 'South_50h' |
| 139 | exposure_south += duration | 179 | exposure_south += duration |
| 140 | 180 | ||
| 141 | # Set IRF information | 181 | # Set IRF information |
| @@ -146,11 +186,11 @@ def set_patch(lmin=-30.0, lmax=30.0, bmin=-1.5, bmax=+1.5, | @@ -146,11 +186,11 @@ def set_patch(lmin=-30.0, lmax=30.0, bmin=-1.5, bmax=+1.5, | ||
| 146 | obsdef.append(obs) | 186 | obsdef.append(obs) |
| 147 | 187 | ||
| 148 | # Dump statistics | 188 | # Dump statistics |
| 149 | - print("Number of pointings: %d (%.2f sec)" % (n_pnt,duration)) | ||
| 150 | - print("South array .......: %.2f hours (%.2f%%)" % | 189 | + print('Number of pointings: %d (%.2f s)' % (n_pnt,duration)) |
| 190 | + print('South array .......: %.2f hours (%.2f%%)' % | ||
| 151 | (exposure_south/3600.0, | 191 | (exposure_south/3600.0, |
| 152 | 100.0*exposure_south/(exposure_south+exposure_north))) | 192 | 100.0*exposure_south/(exposure_south+exposure_north))) |
| 153 | - print("North array .......: %.2f hours (%.2f%%)" % | 193 | + print('North array .......: %.2f hours (%.2f%%)' % |
| 154 | (exposure_north/3600.0, | 194 | (exposure_north/3600.0, |
| 155 | 100.0*exposure_north/(exposure_south+exposure_north))) | 195 | 100.0*exposure_north/(exposure_south+exposure_north))) |
| 156 | 196 | ||
| @@ -163,7 +203,23 @@ def set_patch(lmin=-30.0, lmax=30.0, bmin=-1.5, bmax=+1.5, | @@ -163,7 +203,23 @@ def set_patch(lmin=-30.0, lmax=30.0, bmin=-1.5, bmax=+1.5, | ||
| 163 | # =========================== # | 203 | # =========================== # |
| 164 | def set_gps(separation=3.0, bmin=-1.3, bmax=1.3, lst=True): | 204 | def set_gps(separation=3.0, bmin=-1.3, bmax=1.3, lst=True): |
| 165 | """ | 205 | """ |
| 166 | - Setup Galactic plane survey. | 206 | + Setup Galactic plane survey |
| 207 | + | ||
| 208 | + Parameters | ||
| 209 | + ---------- | ||
| 210 | + separation : float, optional | ||
| 211 | + Pointing separation (deg) | ||
| 212 | + bmin : float, optional | ||
| 213 | + Minimum Galactic Latitude (deg) | ||
| 214 | + bmax : float, optional | ||
| 215 | + Maximum Galactic Latitude (deg) | ||
| 216 | + lst : bool, optional | ||
| 217 | + Use LSTs | ||
| 218 | + | ||
| 219 | + Returns | ||
| 220 | + ------- | ||
| 221 | + obsdef : list of dict | ||
| 222 | + List of pointing definitions | ||
| 167 | """ | 223 | """ |
| 168 | # Initialise observation definition | 224 | # Initialise observation definition |
| 169 | obsdef = [] | 225 | obsdef = [] |
| @@ -171,27 +227,27 @@ def set_gps(separation=3.0, bmin=-1.3, bmax=1.3, lst=True): | @@ -171,27 +227,27 @@ def set_gps(separation=3.0, bmin=-1.3, bmax=1.3, lst=True): | ||
| 171 | # Add inner region South | 227 | # Add inner region South |
| 172 | obsdef.extend(set_patch(lmin=-60.0, lmax=60.0, bmin=bmin, bmax=bmax, | 228 | obsdef.extend(set_patch(lmin=-60.0, lmax=60.0, bmin=bmin, bmax=bmax, |
| 173 | separation=separation, hours=780, | 229 | separation=separation, hours=780, |
| 174 | - site="South", lst=lst)) | 230 | + site='South', lst=lst)) |
| 175 | 231 | ||
| 176 | # Add Vela & Carina region | 232 | # Add Vela & Carina region |
| 177 | obsdef.extend(set_patch(lmin=240.0, lmax=300.0, bmin=bmin, bmax=bmax, | 233 | obsdef.extend(set_patch(lmin=240.0, lmax=300.0, bmin=bmin, bmax=bmax, |
| 178 | separation=separation, hours=180, | 234 | separation=separation, hours=180, |
| 179 | - site="South", lst=lst)) | 235 | + site='South', lst=lst)) |
| 180 | 236 | ||
| 181 | # Add 210-240 region | 237 | # Add 210-240 region |
| 182 | obsdef.extend(set_patch(lmin=210.0, lmax=240.0, bmin=bmin, bmax=bmax, | 238 | obsdef.extend(set_patch(lmin=210.0, lmax=240.0, bmin=bmin, bmax=bmax, |
| 183 | separation=separation, hours=60, | 239 | separation=separation, hours=60, |
| 184 | - site="South", lst=lst)) | 240 | + site='South', lst=lst)) |
| 185 | 241 | ||
| 186 | # Add Cygnus, Perseus | 242 | # Add Cygnus, Perseus |
| 187 | obsdef.extend(set_patch(lmin=60.0, lmax=150.0, bmin=bmin, bmax=bmax, | 243 | obsdef.extend(set_patch(lmin=60.0, lmax=150.0, bmin=bmin, bmax=bmax, |
| 188 | separation=separation, hours=450, | 244 | separation=separation, hours=450, |
| 189 | - site="North", lst=lst)) | 245 | + site='North', lst=lst)) |
| 190 | 246 | ||
| 191 | # Add Anticentre | 247 | # Add Anticentre |
| 192 | obsdef.extend(set_patch(lmin=150.0, lmax=210.0, bmin=bmin, bmax=bmax, | 248 | obsdef.extend(set_patch(lmin=150.0, lmax=210.0, bmin=bmin, bmax=bmax, |
| 193 | separation=separation, hours=150, | 249 | separation=separation, hours=150, |
| 194 | - site="North", lst=lst)) | 250 | + site='North', lst=lst)) |
| 195 | 251 | ||
| 196 | # Return observation definition | 252 | # Return observation definition |
| 197 | return obsdef | 253 | return obsdef |
| @@ -203,6 +259,18 @@ def set_gps(separation=3.0, bmin=-1.3, bmax=1.3, lst=True): | @@ -203,6 +259,18 @@ def set_gps(separation=3.0, bmin=-1.3, bmax=1.3, lst=True): | ||
| 203 | def set_extgal(separation=3.0, lst=True): | 259 | def set_extgal(separation=3.0, lst=True): |
| 204 | """ | 260 | """ |
| 205 | Setup Extragalactic survey. | 261 | Setup Extragalactic survey. |
| 262 | + | ||
| 263 | + Parameters | ||
| 264 | + ---------- | ||
| 265 | + separation : float, optional | ||
| 266 | + Pointing separation (deg) | ||
| 267 | + lst : bool, optional | ||
| 268 | + Use LSTs | ||
| 269 | + | ||
| 270 | + Returns | ||
| 271 | + ------- | ||
| 272 | + obsdef : list of dict | ||
| 273 | + List of pointing definitions | ||
| 206 | """ | 274 | """ |
| 207 | # Initialise observation definition | 275 | # Initialise observation definition |
| 208 | obsdef = [] | 276 | obsdef = [] |
| @@ -210,7 +278,7 @@ def set_extgal(separation=3.0, lst=True): | @@ -210,7 +278,7 @@ def set_extgal(separation=3.0, lst=True): | ||
| 210 | # Set patch | 278 | # Set patch |
| 211 | obsdef.extend(set_patch(lmin=-90.0, lmax=90.0, bmin=+5.0, bmax=+88.0, | 279 | obsdef.extend(set_patch(lmin=-90.0, lmax=90.0, bmin=+5.0, bmax=+88.0, |
| 212 | separation=separation, hours=1000, | 280 | separation=separation, hours=1000, |
| 213 | - site="Automatic", lst=lst, autodec=10.0)) | 281 | + site='Automatic', lst=lst, autodec=10.0)) |
| 214 | 282 | ||
| 215 | # Return observation definition | 283 | # Return observation definition |
| 216 | return obsdef | 284 | return obsdef |
| @@ -222,6 +290,16 @@ def set_extgal(separation=3.0, lst=True): | @@ -222,6 +290,16 @@ def set_extgal(separation=3.0, lst=True): | ||
| 222 | def set_gc(lst=True): | 290 | def set_gc(lst=True): |
| 223 | """ | 291 | """ |
| 224 | Setup Galactic centre KSP. | 292 | Setup Galactic centre KSP. |
| 293 | + | ||
| 294 | + Parameters | ||
| 295 | + ---------- | ||
| 296 | + lst : bool, optional | ||
| 297 | + Use LSTs | ||
| 298 | + | ||
| 299 | + Returns | ||
| 300 | + ------- | ||
| 301 | + obsdef : list of dict | ||
| 302 | + List of pointing definitions | ||
| 225 | """ | 303 | """ |
| 226 | # Initialise observation definition | 304 | # Initialise observation definition |
| 227 | obsdef = [] | 305 | obsdef = [] |
| @@ -229,12 +307,12 @@ def set_gc(lst=True): | @@ -229,12 +307,12 @@ def set_gc(lst=True): | ||
| 229 | # Central wobble | 307 | # Central wobble |
| 230 | obsdef.extend(set_patch(lmin=-0.5, lmax=0.5, bmin=-0.5, bmax=0.5, | 308 | obsdef.extend(set_patch(lmin=-0.5, lmax=0.5, bmin=-0.5, bmax=0.5, |
| 231 | separation=0.1, hours=525, | 309 | separation=0.1, hours=525, |
| 232 | - site="South", lst=lst)) | 310 | + site='South', lst=lst)) |
| 233 | 311 | ||
| 234 | # Extended region | 312 | # Extended region |
| 235 | obsdef.extend(set_patch(lmin=-10.0, lmax=10.0, bmin=-10.0, bmax=10.0, | 313 | obsdef.extend(set_patch(lmin=-10.0, lmax=10.0, bmin=-10.0, bmax=10.0, |
| 236 | separation=1.5, hours=300, | 314 | separation=1.5, hours=300, |
| 237 | - site="South", lst=lst)) | 315 | + site='South', lst=lst)) |
| 238 | 316 | ||
| 239 | # Return observation definition | 317 | # Return observation definition |
| 240 | return obsdef | 318 | return obsdef |
| @@ -246,6 +324,18 @@ def set_gc(lst=True): | @@ -246,6 +324,18 @@ def set_gc(lst=True): | ||
| 246 | def set_lmc(hours=250.0, lst=True): | 324 | def set_lmc(hours=250.0, lst=True): |
| 247 | """ | 325 | """ |
| 248 | Setup LMC KSP. | 326 | Setup LMC KSP. |
| 327 | + | ||
| 328 | + Parameters | ||
| 329 | + ---------- | ||
| 330 | + hours : float, optional | ||
| 331 | + Total observation duration (h) | ||
| 332 | + lst : bool, optional | ||
| 333 | + Use LSTs | ||
| 334 | + | ||
| 335 | + Returns | ||
| 336 | + ------- | ||
| 337 | + obsdef : list of dict | ||
| 338 | + List of pointing definitions | ||
| 249 | """ | 339 | """ |
| 250 | # Initialise observation definition | 340 | # Initialise observation definition |
| 251 | obsdef = [] | 341 | obsdef = [] |
| @@ -275,11 +365,11 @@ def set_lmc(hours=250.0, lst=True): | @@ -275,11 +365,11 @@ def set_lmc(hours=250.0, lst=True): | ||
| 275 | obs = {'lon': lon, 'lat': lat, 'duration': duration} | 365 | obs = {'lon': lon, 'lat': lat, 'duration': duration} |
| 276 | 366 | ||
| 277 | # Add IRF | 367 | # Add IRF |
| 278 | - caldb = "prod2" | 368 | + caldb = 'prod2' |
| 279 | if lst: | 369 | if lst: |
| 280 | - irf = "South_50h" | 370 | + irf = 'South_50h' |
| 281 | else: | 371 | else: |
| 282 | - irf = "South_50h" | 372 | + irf = 'South_50h' |
| 283 | obs['caldb'] = caldb | 373 | obs['caldb'] = caldb |
| 284 | obs['irf'] = irf | 374 | obs['irf'] = irf |
| 285 | 375 | ||
| @@ -287,7 +377,7 @@ def set_lmc(hours=250.0, lst=True): | @@ -287,7 +377,7 @@ def set_lmc(hours=250.0, lst=True): | ||
| 287 | obsdef.append(obs) | 377 | obsdef.append(obs) |
| 288 | 378 | ||
| 289 | # Dump statistics | 379 | # Dump statistics |
| 290 | - print("Number of pointings: %d (%.2f sec)" % (n_pnt,duration)) | 380 | + print('Number of pointings: %d (%.2f s)' % (n_pnt,duration)) |
| 291 | 381 | ||
| 292 | # Return observation definition | 382 | # Return observation definition |
| 293 | return obsdef | 383 | return obsdef |
| @@ -298,31 +388,38 @@ def set_lmc(hours=250.0, lst=True): | @@ -298,31 +388,38 @@ def set_lmc(hours=250.0, lst=True): | ||
| 298 | # ======================================= # | 388 | # ======================================= # |
| 299 | def write_obsdef(filename, obsdef): | 389 | def write_obsdef(filename, obsdef): |
| 300 | """ | 390 | """ |
| 301 | - Write observation definition file. | 391 | + Write observation definition file |
| 392 | + | ||
| 393 | + Parameters | ||
| 394 | + ---------- | ||
| 395 | + filename : str | ||
| 396 | + Observation definition file name | ||
| 397 | + obsdef : list of dict | ||
| 398 | + List of pointing definitions | ||
| 302 | """ | 399 | """ |
| 303 | # Open file | 400 | # Open file |
| 304 | file = open(filename, 'w') | 401 | file = open(filename, 'w') |
| 305 | 402 | ||
| 306 | # Write header | 403 | # Write header |
| 307 | - file.write("ra,dec,duration,caldb,irf\n") | 404 | + file.write('ra,dec,duration,caldb,irf\n') |
| 308 | 405 | ||
| 309 | # Loop over pointings | 406 | # Loop over pointings |
| 310 | for obs in obsdef: | 407 | for obs in obsdef: |
| 311 | 408 | ||
| 312 | # If we have lon,lat then convert into RA,Dec | 409 | # If we have lon,lat then convert into RA,Dec |
| 313 | - if "lon" in obs and "lat" in obs: | ||
| 314 | - lon = obs["lon"] | ||
| 315 | - lat = obs["lat"] | 410 | + if 'lon' in obs and 'lat' in obs: |
| 411 | + lon = obs['lon'] | ||
| 412 | + lat = obs['lat'] | ||
| 316 | dir = gammalib.GSkyDir() | 413 | dir = gammalib.GSkyDir() |
| 317 | dir.lb_deg(lon,lat) | 414 | dir.lb_deg(lon,lat) |
| 318 | ra = dir.ra_deg() | 415 | ra = dir.ra_deg() |
| 319 | dec = dir.dec_deg() | 416 | dec = dir.dec_deg() |
| 320 | else: | 417 | else: |
| 321 | - ra = obs["ra"] | ||
| 322 | - dec = obs["dec"] | 418 | + ra = obs['ra'] |
| 419 | + dec = obs['dec'] | ||
| 323 | 420 | ||
| 324 | # Write information | 421 | # Write information |
| 325 | - file.write("%8.4f,%8.4f,%.4f,%s,%s\n" % | 422 | + file.write('%8.4f,%8.4f,%.4f,%s,%s\n' % |
| 326 | (ra, dec, obs['duration'], obs['caldb'], obs['irf'])) | 423 | (ra, dec, obs['duration'], obs['caldb'], obs['irf'])) |
| 327 | 424 | ||
| 328 | # Close file | 425 | # Close file |
| @@ -342,7 +439,7 @@ if __name__ == '__main__': | @@ -342,7 +439,7 @@ if __name__ == '__main__': | ||
| 342 | 439 | ||
| 343 | # Test for command line arguments | 440 | # Test for command line arguments |
| 344 | if (len(sys.argv) > 1): | 441 | if (len(sys.argv) > 1): |
| 345 | - if sys.argv[1] == "-h": | 442 | + if sys.argv[1] == '-h': |
| 346 | need_help = True | 443 | need_help = True |
| 347 | else: | 444 | else: |
| 348 | obsname = sys.argv[1] | 445 | obsname = sys.argv[1] |
| @@ -351,37 +448,37 @@ if __name__ == '__main__': | @@ -351,37 +448,37 @@ if __name__ == '__main__': | ||
| 351 | 448 | ||
| 352 | # Print help if needed and exit | 449 | # Print help if needed and exit |
| 353 | if need_help: | 450 | if need_help: |
| 354 | - print("Usage: make_pointing.py [OPTIONS]") | ||
| 355 | - print(" -h Display this usage message") | ||
| 356 | - print(" gps Galactic plane survey (2 row scheme)") | ||
| 357 | - print(" gps3 Galactic plane survey (3 row scheme)") | ||
| 358 | - print(" extgal Extragalactic survey") | ||
| 359 | - print(" gc Galactic centre survey") | ||
| 360 | - print(" lmc LMC survey") | 451 | + print('Usage: make_pointing.py [OPTIONS]') |
| 452 | + print(' -h Display this usage message') | ||
| 453 | + print(' gps Galactic plane survey (2 row scheme)') | ||
| 454 | + print(' gps3 Galactic plane survey (3 row scheme)') | ||
| 455 | + print(' extgal Extragalactic survey') | ||
| 456 | + print(' gc Galactic centre survey') | ||
| 457 | + print(' lmc LMC survey') | ||
| 361 | sys.exit() | 458 | sys.exit() |
| 362 | 459 | ||
| 363 | # Galactic plane survey | 460 | # Galactic plane survey |
| 364 | - if obsname == "gps": | 461 | + if obsname == 'gps': |
| 365 | obsdef = set_gps(lst=True) | 462 | obsdef = set_gps(lst=True) |
| 366 | - write_obsdef("gps.dat", obsdef) | ||
| 367 | - elif obsname == "gps3": | 463 | + write_obsdef('gps.dat', obsdef) |
| 464 | + elif obsname == 'gps3': | ||
| 368 | obsdef = set_gps(separation=1.5, lst=True) | 465 | obsdef = set_gps(separation=1.5, lst=True) |
| 369 | - write_obsdef("gps3.dat", obsdef) | 466 | + write_obsdef('gps3.dat', obsdef) |
| 370 | 467 | ||
| 371 | # Extragalactic survey | 468 | # Extragalactic survey |
| 372 | - elif obsname == "extgal": | 469 | + elif obsname == 'extgal': |
| 373 | obsdef = set_extgal(lst=True) | 470 | obsdef = set_extgal(lst=True) |
| 374 | - write_obsdef("extgal.dat", obsdef) | 471 | + write_obsdef('extgal.dat', obsdef) |
| 375 | 472 | ||
| 376 | # Galactic centre | 473 | # Galactic centre |
| 377 | - elif obsname == "gc": | 474 | + elif obsname == 'gc': |
| 378 | obsdef = set_gc(lst=True) | 475 | obsdef = set_gc(lst=True) |
| 379 | - write_obsdef("gc.dat", obsdef) | 476 | + write_obsdef('gc.dat', obsdef) |
| 380 | 477 | ||
| 381 | # LMC | 478 | # LMC |
| 382 | - elif obsname == "lmc": | 479 | + elif obsname == 'lmc': |
| 383 | obsdef = set_lmc(lst=True) | 480 | obsdef = set_lmc(lst=True) |
| 384 | - write_obsdef("lmc.dat", obsdef) | 481 | + write_obsdef('lmc.dat', obsdef) |
| 385 | 482 | ||
| 386 | # Invalid pattern | 483 | # Invalid pattern |
| 387 | else: | 484 | else: |
test/test_examples.py
| @@ -44,21 +44,33 @@ class Test(gammalib.GPythonTestSuite): | @@ -44,21 +44,33 @@ class Test(gammalib.GPythonTestSuite): | ||
| 44 | return | 44 | return |
| 45 | 45 | ||
| 46 | # Execute Python script | 46 | # Execute Python script |
| 47 | - def _execute_python(self, name): | 47 | + def _execute_python(self, name, args='', log=''): |
| 48 | """ | 48 | """ |
| 49 | Execute Python script | 49 | Execute Python script |
| 50 | 50 | ||
| 51 | Parameters | 51 | Parameters |
| 52 | ---------- | 52 | ---------- |
| 53 | name : str | 53 | name : str |
| 54 | - Python script name with .py extension. | 54 | + Python script name with .py extension |
| 55 | + args : str, optional | ||
| 56 | + String with arguments to be passed to script | ||
| 57 | + log : str, optional | ||
| 58 | + String with name to be used for logging | ||
| 55 | """ | 59 | """ |
| 56 | # Setup command | 60 | # Setup command |
| 57 | cmd = '../examples/' + name + '.py' | 61 | cmd = '../examples/' + name + '.py' |
| 62 | + if len(args) > 0: | ||
| 63 | + cmd += ' ' + args | ||
| 64 | + | ||
| 65 | + # Set logname | ||
| 66 | + if len(log) > 0: | ||
| 67 | + logname = log | ||
| 68 | + else: | ||
| 69 | + logname = name | ||
| 58 | 70 | ||
| 59 | # Execute Python script, make sure we catch any exception | 71 | # Execute Python script, make sure we catch any exception |
| 60 | try: | 72 | try: |
| 61 | - rc = os.system(cmd+' > example_'+name+'.log 2>&1') | 73 | + rc = os.system(cmd+' > example_'+logname+'.log 2>&1') |
| 62 | except: | 74 | except: |
| 63 | pass | 75 | pass |
| 64 | 76 | ||
| @@ -78,6 +90,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -78,6 +90,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 78 | 90 | ||
| 79 | # Append tests | 91 | # Append tests |
| 80 | self.append(self.test_generate_prod3_irfs, 'Test generate_prod3_irfs') | 92 | self.append(self.test_generate_prod3_irfs, 'Test generate_prod3_irfs') |
| 93 | + self.append(self.test_make_pointings, 'Test make_pointings') | ||
| 81 | self.append(self.test_pipeline_binned_disk, 'Test pipeline_binned_disk') | 94 | self.append(self.test_pipeline_binned_disk, 'Test pipeline_binned_disk') |
| 82 | self.append(self.test_pipeline_binned_mem, 'Test pipeline_binned_mem') | 95 | self.append(self.test_pipeline_binned_mem, 'Test pipeline_binned_mem') |
| 83 | self.append(self.test_pipeline_stacked_disk, 'Test pipeline_stacked_disk') | 96 | self.append(self.test_pipeline_stacked_disk, 'Test pipeline_stacked_disk') |
| @@ -88,6 +101,27 @@ class Test(gammalib.GPythonTestSuite): | @@ -88,6 +101,27 @@ class Test(gammalib.GPythonTestSuite): | ||
| 88 | # Return | 101 | # Return |
| 89 | return | 102 | return |
| 90 | 103 | ||
| 104 | + # Test make_pointings | ||
| 105 | + def test_make_pointings(self): | ||
| 106 | + """ | ||
| 107 | + Test make_pointings | ||
| 108 | + """ | ||
| 109 | + # Set script name | ||
| 110 | + script = 'make_pointings' | ||
| 111 | + | ||
| 112 | + # Execute script | ||
| 113 | + self._execute_python(script, args='-h', log='make_pointings_help') | ||
| 114 | + self._execute_python(script, args='gps', log='make_pointings_gps') | ||
| 115 | + self._execute_python(script, args='gps3', log='make_pointings_gps3') | ||
| 116 | + self._execute_python(script, args='extgal', log='make_pointings_extgal') | ||
| 117 | + self._execute_python(script, args='gc', log='make_pointings_gc') | ||
| 118 | + self._execute_python(script, args='lmc', log='make_pointings_lmc') | ||
| 119 | + | ||
| 120 | + #TODO: Do any testing | ||
| 121 | + | ||
| 122 | + # Return | ||
| 123 | + return | ||
| 124 | + | ||
| 91 | # Test generate_prod3_irfs | 125 | # Test generate_prod3_irfs |
| 92 | def test_generate_prod3_irfs(self): | 126 | def test_generate_prod3_irfs(self): |
| 93 | """ | 127 | """ |