Commit 7c9d9804b0adff24e17ee9cf5a2709d9faabceb5

Authored by Jürgen Knödlseder
1 parent 1aa478ab

Adapt comobsbin script to new phase interface and add parameters for pulsar phase selection

modules/comscripts/comobsbin.par
@@ -23,31 +23,33 @@ outfolder, s, a, $COMDATASTORE,,, "Output folder for files" @@ -23,31 +23,33 @@ outfolder, s, a, $COMDATASTORE,,, "Output folder for files"
23 # 23 #
24 # Script parameters 24 # Script parameters
25 #================== 25 #==================
26 -ebinalg, s, a, FILE,FILE|LIN|LOG,, "Algorithm for defining energy bins"  
27 -emin, r, a, 0.75,0.05,50.0, "Minimum energy (MeV)"  
28 -emax, r, a, 30.0,0.05,50.0, "Maximum energy (MeV)"  
29 -phase, s, a, NONE,,, "Phase expression in the format phasemin0-phasemax0;phasemin1-phasemax1;..."  
30 -phase0, t, a, JD 2451943.09,,, "Date of Phase 0 (UTC string, JD, MJD or MET in seconds)"  
31 -period, r, a, 3.90603,,, "Period (days)"  
32 -enumbins, i, a, 1,1,20, "Number of energy bins"  
33 -ebinfile, f, a, ebounds.fits,,, "Name of the file containing the energy bin definition"  
34 -coordsys, s, a, GAL,CEL|GAL,,"Coordinate system (CEL - celestial, GAL - galactic)"  
35 -proj, s, a, TAN,AIT|AZP|CAR|GLS|MOL|SFL|SIN|STG|TAN,, "Projection method"  
36 -usepnt, b, h, yes,,, "Use pointing instead of chi0/psi0 parameters?"  
37 -chi0, r, a, 83.63,0,360, "Chi of DRI centre in degrees (RA or Galactic longitude)"  
38 -psi0, r, a, 22.51,-90,90, "Psi of DRI centre in degrees (DEC or Galactic latitude)"  
39 -dchi, r, h, 1.0,0.1,10.0, "Bin size in Chi direction (deg)"  
40 -dpsi, r, h, 1.0,0.1,10.0, "Bin size in Psi direction (deg)"  
41 -dphibar, r, h, 2.0,0.1,10.0, "Bin size in Phibar direction (deg)"  
42 -nchi, i, h, 80,1,800, "Number of bins in Chi direction"  
43 -npsi, i, h, 80,1,800, "Number of bins in Psi direction"  
44 -nphibar, i, h, 25,1,500, "Number of bins in Phibar direction"  
45 -psdmin, i, h, 0,0,110, "Minimum PSD value"  
46 -psdmax, i, h, 110,0,110, "Maximum PSD value"  
47 -zetamin, r, h, 5.0,0.0,10.0, "Minimum Earth horizon - Phibar (zeta) angle (deg)"  
48 -fpmtflag, i, h, 0,0,2, "Handling of D2 modules with failed PMT flag (0: exclude, 1: include, 2: exclude PMT)"  
49 -d1use, s, h, 1111111,,, "D1 module usage (1: use, 0: don't use)"  
50 -d2use, s, h, 11111111111111,,, "D2 module usage (1: use, 0: don't use)" 26 +ebinalg, s, a, FILE,FILE|LIN|LOG,, "Algorithm for defining energy bins"
  27 +emin, r, a, 0.75,0.05,50.0, "Minimum energy (MeV)"
  28 +emax, r, a, 30.0,0.05,50.0, "Maximum energy (MeV)"
  29 +phase, s, a, NONE,,, "Phase expression in the format phasemin0-phasemax0;phasemin1-phasemax1;..."
  30 +psrname, s, a, NONE,,, "Pulsar name"
  31 +ephemerides, f, a, NONE,,, "Pulsar ephemerides file"
  32 +phase0, t, a, JD 2451943.09,,, "Date of Phase 0 (UTC string, JD, MJD or MET in seconds)"
  33 +period, r, a, 3.90603,,, "Period (days)"
  34 +enumbins, i, a, 1,1,20, "Number of energy bins"
  35 +ebinfile, f, a, ebounds.fits,,, "Name of the file containing the energy bin definition"
  36 +coordsys, s, a, CEL,CEL|GAL,,"Coordinate system (CEL - celestial, GAL - galactic)"
  37 +proj, s, a, TAN,AIT|AZP|CAR|GLS|MOL|SFL|SIN|STG|TAN,, "Projection method"
  38 +usepnt, b, h, yes,,, "Use pointing instead of chi0/psi0 parameters?"
  39 +chi0, r, a, 83.63,0,360, "Chi of DRI centre in degrees (RA or Galactic longitude)"
  40 +psi0, r, a, 22.51,-90,90, "Psi of DRI centre in degrees (DEC or Galactic latitude)"
  41 +dchi, r, h, 1.0,0.1,10.0, "Bin size in Chi direction (deg)"
  42 +dpsi, r, h, 1.0,0.1,10.0, "Bin size in Psi direction (deg)"
  43 +dphibar, r, h, 2.0,0.1,10.0, "Bin size in Phibar direction (deg)"
  44 +nchi, i, h, 80,1,800, "Number of bins in Chi direction"
  45 +npsi, i, h, 80,1,800, "Number of bins in Psi direction"
  46 +nphibar, i, h, 25,1,500, "Number of bins in Phibar direction"
  47 +psdmin, i, h, 0,0,110, "Minimum PSD value"
  48 +psdmax, i, h, 110,0,110, "Maximum PSD value"
  49 +zetamin, r, h, 5.0,0.0,10.0, "Minimum Earth horizon - Phibar (zeta) angle (deg)"
  50 +fpmtflag, i, h, 0,0,2, "Handling of D2 modules with failed PMT flag (0: exclude, 1: include, 2: exclude PMT)"
  51 +d1use, s, h, 1111111,,, "D1 module usage (1: use, 0: don't use)"
  52 +d2use, s, h, 11111111111111,,, "D2 module usage (1: use, 0: don't use)"
51 53
52 # 54 #
53 # Standard parameters 55 # Standard parameters
modules/comscripts/comobsbin.py
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 # ========================================================================== 2 # ==========================================================================
3 # Bin COMPTEL observations 3 # Bin COMPTEL observations
4 # 4 #
5 -# Copyright (C) 2019-2021 Juergen Knoedlseder 5 +# Copyright (C) 2019-2022 Juergen Knoedlseder
6 # 6 #
7 # 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
8 # 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
@@ -62,8 +62,11 @@ class comobsbin(ctools.csobservation): @@ -62,8 +62,11 @@ class comobsbin(ctools.csobservation):
62 self._get_ebounds() 62 self._get_ebounds()
63 self._get_phases() 63 self._get_phases()
64 if not self._phases.is_empty(): 64 if not self._phases.is_empty():
65 - self['phase0'].time()  
66 - self['period'].real() 65 + if gammalib.toupper(self['psrname'].string()) != 'NONE':
  66 + self['ephemerides'].filename()
  67 + else:
  68 + self['phase0'].time()
  69 + self['period'].real()
67 self['coordsys'].string() 70 self['coordsys'].string()
68 self['proj'].string() 71 self['proj'].string()
69 if not self['usepnt'].boolean(): 72 if not self['usepnt'].boolean():
@@ -80,7 +83,7 @@ class comobsbin(ctools.csobservation): @@ -80,7 +83,7 @@ class comobsbin(ctools.csobservation):
80 self['psdmax'].integer() 83 self['psdmax'].integer()
81 self['zetamin'].real() 84 self['zetamin'].real()
82 self['fpmtflag'].integer() 85 self['fpmtflag'].integer()
83 - 86 +
84 # Get D1 and D2 module usage strings 87 # Get D1 and D2 module usage strings
85 d1use = self['d1use'].string() 88 d1use = self['d1use'].string()
86 d2use = self['d2use'].string() 89 d2use = self['d2use'].string()
@@ -183,39 +186,62 @@ class comobsbin(ctools.csobservation): @@ -183,39 +186,62 @@ class comobsbin(ctools.csobservation):
183 # Clear selection set 186 # Clear selection set
184 self._select.clear() 187 self._select.clear()
185 188
186 - # If phases are set then set the phase curve and phases of the  
187 - # selection set 189 + # If phases are set then handle phase selection
188 if not self._phases.is_empty(): 190 if not self._phases.is_empty():
189 191
190 - # Raise error if period is not positive  
191 - if self['period'].real() <= 0.0:  
192 - msg = 'Period %f is not positive. Please specify a positive period.'  
193 - raise RuntimeError(msg) 192 + # If pulsar string is valid then handle pulsar
  193 + psrname = self['psrname'].string()
  194 + if gammalib.toupper(psrname) != 'NONE':
  195 +
  196 + # Log pulsar phase selection
  197 + self._log_string(gammalib.NORMAL, 'Phase selection for pulsar "%s"' %
  198 + psrname)
  199 +
  200 + # Read ephemerides
  201 + pulsar = gammalib.GPulsar(self['ephemerides'].filename(), psrname)
  202 +
  203 + # Set pulsar ephemerides
  204 + self._select.pulsar(pulsar)
  205 +
  206 + # Set pulsar phases
  207 + self._select.pulsar_phases(self._phases)
194 208
195 - # Get frequency of variability in units of Hz  
196 - f0 = 1.0 / (self['period'].real() * gammalib.sec_in_day) 209 + # Set phase suffix
  210 + suffix = '_pulphase'
  211 +
  212 + # Set DRE, DRG and DRX suffix
  213 + phases = self['phase'].string()
  214 + self._dre_suffix = suffix+phases.replace(';', '_')
  215 + self._drg_suffix = suffix
  216 + self._drx_suffix = suffix
  217 +
  218 + # ... otherwise handle orbital phase selection
  219 + else:
  220 +
  221 + # Raise error if period is not positive
  222 + period = self['period'].real()
  223 + if period <= 0.0:
  224 + msg = 'Period %f is not positive. Please specify a positive period.'
  225 + raise RuntimeError(msg)
197 226
198 - # Set temporal phase curve  
199 - phase_curve = gammalib.GModelTemporalPhaseCurve() 227 + # Log orbital phase selection
  228 + self._log_string(gammalib.NORMAL, 'Orbital selection for period %f days' %
  229 + period)
200 230
201 - # Set phase curve elements  
202 - phase_curve.mjd(self['phase0'].time()) # Reference time  
203 - phase_curve.phase(0.0) # Phase @ reference time  
204 - phase_curve.f0(f0) # Frequency @ reference time  
205 - phase_curve.f1(0.0) # No frequency derivative  
206 - phase_curve.f2(0.0) # No 2nd frequency derivative 231 + # Set orbital period
  232 + self._select.orbital_period(period, self['phase0'].time())
207 233
208 - # Set phase curve  
209 - self._select.phase_curve(phase_curve) 234 + # Set orbital phases
  235 + self._select.orbital_phases(self._phases)
210 236
211 - # Set phases  
212 - self._select.phases(self._phases) 237 + # Set phase suffix
  238 + suffix = '_orbphase'
213 239
214 - # Set DRE, DRG and DRX suffix  
215 - phases = self['phase'].string()  
216 - self._dre_suffix = '_phases'+phases.replace(';', '_')  
217 - self._drg_suffix = '_phases'+phases.replace(';', '_')  
218 - self._drx_suffix = '_phases'+phases.replace(';', '_') 240 + # Set DRE, DRG and DRX suffix
  241 + phases = self['phase'].string()
  242 + self._dre_suffix = suffix+phases.replace(';', '_')
  243 + self._drg_suffix = suffix+phases.replace(';', '_')
  244 + self._drx_suffix = suffix+phases.replace(';', '_')
219 245
220 # If PSD interval differs from standard interval then set the interval 246 # If PSD interval differs from standard interval then set the interval
221 # and append flag to suffix 247 # and append flag to suffix
test/test_comobsbin.py
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 # ========================================================================== 2 # ==========================================================================
3 # This scripts performs unit tests for the comobsbin script. 3 # This scripts performs unit tests for the comobsbin script.
4 # 4 #
5 -# Copyright (C) 2021 Juergen Knoedlseder 5 +# Copyright (C) 2021-2022 Juergen Knoedlseder
6 # 6 #
7 # 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
8 # 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
@@ -81,6 +81,7 @@ class Test(test): @@ -81,6 +81,7 @@ class Test(test):
81 # Setup command 81 # Setup command
82 cmd = comobsbin+' inobs="'+self._obs+'" ebinalg="FILE" '+ \ 82 cmd = comobsbin+' inobs="'+self._obs+'" ebinalg="FILE" '+ \
83 'ebinfile="'+self._ebounds+'" phase="NONE" '+ \ 83 'ebinfile="'+self._ebounds+'" phase="NONE" '+ \
  84 + 'coordsys="GAL" proj="TAN" '+ \
84 'outfolder="comobsbin_cmd1" outobs="comobsbin_cmd1.xml" '+ \ 85 'outfolder="comobsbin_cmd1" outobs="comobsbin_cmd1.xml" '+ \
85 'logfile="comobsbin_cmd1.log" chatter=1' 86 'logfile="comobsbin_cmd1.log" chatter=1'
86 87
@@ -94,6 +95,7 @@ class Test(test): @@ -94,6 +95,7 @@ class Test(test):
94 # Setup command 95 # Setup command
95 cmd = comobsbin+' inobs="file_that_does_not_exist.xml" ebinalg="FILE" '+ \ 96 cmd = comobsbin+' inobs="file_that_does_not_exist.xml" ebinalg="FILE" '+ \
96 'ebinfile="'+self._ebounds+'" phase="NONE" '+ \ 97 'ebinfile="'+self._ebounds+'" phase="NONE" '+ \
  98 + 'coordsys="GAL" proj="TAN" '+ \
97 'outfolder="comobsbin_cmd2" outobs="comobsbin_cmd2.xml" '+ \ 99 'outfolder="comobsbin_cmd2" outobs="comobsbin_cmd2.xml" '+ \
98 'logfile="comobsbin_cmd2.log" chatter=1' 100 'logfile="comobsbin_cmd2.log" chatter=1'
99 101
@@ -118,6 +120,8 @@ class Test(test): @@ -118,6 +120,8 @@ class Test(test):
118 bin['ebinalg'] = 'FILE' 120 bin['ebinalg'] = 'FILE'
119 bin['ebinfile'] = self._ebounds 121 bin['ebinfile'] = self._ebounds
120 bin['phase'] = 'NONE' 122 bin['phase'] = 'NONE'
  123 + bin['coordsys'] = 'GAL'
  124 + bin['proj'] = 'TAN'
121 bin['outfolder'] = 'comobsbin_py1' 125 bin['outfolder'] = 'comobsbin_py1'
122 bin['outobs'] = 'comobsbin_py1.xml' 126 bin['outobs'] = 'comobsbin_py1.xml'
123 bin['logfile'] = 'comobsbin_py1.log' 127 bin['logfile'] = 'comobsbin_py1.log'