Commit 733bc09f4d2c1195d26839111fa3ec35b216a4c5
1 parent
2299f91b
Resolve some code quality issues with csviscube
Showing
1 changed file
with
11 additions
and
14 deletions
cscripts/csviscube.py
| @@ -19,8 +19,6 @@ | @@ -19,8 +19,6 @@ | ||
| 19 | # | 19 | # |
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | import sys | 21 | import sys |
| 22 | -import glob | ||
| 23 | -import os | ||
| 24 | import math | 22 | import math |
| 25 | import gammalib | 23 | import gammalib |
| 26 | import ctools | 24 | import ctools |
| @@ -99,7 +97,7 @@ class csviscube(ctools.cscript): | @@ -99,7 +97,7 @@ class csviscube(ctools.cscript): | ||
| 99 | 97 | ||
| 100 | Returns | 98 | Returns |
| 101 | ------- | 99 | ------- |
| 102 | - map : `~gammalib.GSkyMap` | 100 | + zmap : `~gammalib.GSkyMap` |
| 103 | Allsky map comprising the zenith angle for an hour angle of 0. | 101 | Allsky map comprising the zenith angle for an hour angle of 0. |
| 104 | 102 | ||
| 105 | The zenith angle of a position (ra,dec) depends on the declination and | 103 | The zenith angle of a position (ra,dec) depends on the declination and |
| @@ -117,7 +115,7 @@ class csviscube(ctools.cscript): | @@ -117,7 +115,7 @@ class csviscube(ctools.cscript): | ||
| 117 | the local meridian. | 115 | the local meridian. |
| 118 | """ | 116 | """ |
| 119 | # Initialise zenith angle map | 117 | # Initialise zenith angle map |
| 120 | - map = gammalib.GSkyMap('CAR','CEL',0.0,0.0,-dx,dy,nx,ny) | 118 | + zmap = gammalib.GSkyMap('CAR','CEL',0.0,0.0,-dx,dy,nx,ny) |
| 121 | 119 | ||
| 122 | # Set hour angle and declination vectors | 120 | # Set hour angle and declination vectors |
| 123 | hours = [(float(i)+0.5)*dx for i in range(nx)] | 121 | hours = [(float(i)+0.5)*dx for i in range(nx)] |
| @@ -140,15 +138,15 @@ class csviscube(ctools.cscript): | @@ -140,15 +138,15 @@ class csviscube(ctools.cscript): | ||
| 140 | cos_h = math.cos(h*gammalib.deg2rad) | 138 | cos_h = math.cos(h*gammalib.deg2rad) |
| 141 | zenith = math.acos(sin_lat*sin_dec + | 139 | zenith = math.acos(sin_lat*sin_dec + |
| 142 | cos_lat*cos_dec*cos_h)*gammalib.rad2deg | 140 | cos_lat*cos_dec*cos_h)*gammalib.rad2deg |
| 143 | - map[index] = zenith | 141 | + zmap[index] = zenith |
| 144 | index += 1 | 142 | index += 1 |
| 145 | 143 | ||
| 146 | # Log zenith angle map | 144 | # Log zenith angle map |
| 147 | self._log_header2(gammalib.EXPLICIT, 'Zenith angle map') | 145 | self._log_header2(gammalib.EXPLICIT, 'Zenith angle map') |
| 148 | - self._log_string(gammalib.EXPLICIT, str(map)) | 146 | + self._log_string(gammalib.EXPLICIT, str(zmap)) |
| 149 | 147 | ||
| 150 | # Return zenith angle map | 148 | # Return zenith angle map |
| 151 | - return map | 149 | + return zmap |
| 152 | 150 | ||
| 153 | def _sun_radec(self, time): | 151 | def _sun_radec(self, time): |
| 154 | """ | 152 | """ |
| @@ -228,8 +226,7 @@ class csviscube(ctools.cscript): | @@ -228,8 +226,7 @@ class csviscube(ctools.cscript): | ||
| 228 | 226 | ||
| 229 | # Compute Right Ascension and Declination of Sun in degrees and | 227 | # Compute Right Ascension and Declination of Sun in degrees and |
| 230 | # convert the Declination into radians | 228 | # convert the Declination into radians |
| 231 | - sunra, sundec = self._sun_radec(time) | ||
| 232 | - sundec *= gammalib.deg2rad | 229 | + sundec = self._sun_radec(time)[1] * gammalib.deg2rad |
| 233 | 230 | ||
| 234 | # Compute some sines and cosines | 231 | # Compute some sines and cosines |
| 235 | cos_sunzenith = math.cos(sunzenith) | 232 | cos_sunzenith = math.cos(sunzenith) |
| @@ -264,7 +261,7 @@ class csviscube(ctools.cscript): | @@ -264,7 +261,7 @@ class csviscube(ctools.cscript): | ||
| 264 | self._log_header2(gammalib.NORMAL, 'Hour angle weights') | 261 | self._log_header2(gammalib.NORMAL, 'Hour angle weights') |
| 265 | 262 | ||
| 266 | # Get array geographic longitude | 263 | # Get array geographic longitude |
| 267 | - geolon = self['geolon'].real() | 264 | + #geolon = self['geolon'].real() |
| 268 | 265 | ||
| 269 | # Get time interval | 266 | # Get time interval |
| 270 | tmin = gammalib.GTime(self['tmin'].real(), 's') | 267 | tmin = gammalib.GTime(self['tmin'].real(), 's') |
| @@ -415,7 +412,7 @@ class csviscube(ctools.cscript): | @@ -415,7 +412,7 @@ class csviscube(ctools.cscript): | ||
| 415 | self._log_value(gammalib.NORMAL, 'Maximum zenith angle', str(zmax)+' deg') | 412 | self._log_value(gammalib.NORMAL, 'Maximum zenith angle', str(zmax)+' deg') |
| 416 | 413 | ||
| 417 | # Compute zenith angle map | 414 | # Compute zenith angle map |
| 418 | - map = self._zenith_angle_map(nx,ny,dx,dy) | 415 | + zmap = self._zenith_angle_map(nx,ny,dx,dy) |
| 419 | 416 | ||
| 420 | # Setup hour angle weights. They specify for how many hours a given | 417 | # Setup hour angle weights. They specify for how many hours a given |
| 421 | # hour angle is observed during the covered time period. | 418 | # hour angle is observed during the covered time period. |
| @@ -431,14 +428,14 @@ class csviscube(ctools.cscript): | @@ -431,14 +428,14 @@ class csviscube(ctools.cscript): | ||
| 431 | shift = hour_angle['angle'] | 428 | shift = hour_angle['angle'] |
| 432 | 429 | ||
| 433 | # Initialise shifted zenith angle map | 430 | # Initialise shifted zenith angle map |
| 434 | - map_shift = gammalib.GSkyMap('CAR','CEL',shift,0.0,-dx,dy,nx,ny) | 431 | + zmap_shift = gammalib.GSkyMap('CAR','CEL',shift,0.0,-dx,dy,nx,ny) |
| 435 | 432 | ||
| 436 | # Merge zenith angle map into shifted map | 433 | # Merge zenith angle map into shifted map |
| 437 | - map_shift += map | 434 | + zmap_shift += zmap |
| 438 | 435 | ||
| 439 | # Loop over all pixels of the shifted map and add the hours during | 436 | # Loop over all pixels of the shifted map and add the hours during |
| 440 | # which the shifted map occurs to the relevant zenith angle bin | 437 | # which the shifted map occurs to the relevant zenith angle bin |
| 441 | - for i, zenith in enumerate(map_shift): | 438 | + for i, zenith in enumerate(zmap_shift): |
| 442 | iz = int(zenith/dz) | 439 | iz = int(zenith/dz) |
| 443 | if iz < nz: | 440 | if iz < nz: |
| 444 | self._cube[i,iz] += hour_angle['hours'] | 441 | self._cube[i,iz] += hour_angle['hours'] |