Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
else:
self.bytes_per_spectra = (self.bits_per_sample * self.samples_per_spectra) // 8
self.samples_per_subint = self.samples_per_spectra * self.spectra_per_subint
self.bytes_per_subint = self.bytes_per_spectra * self.spectra_per_subint
# Flip the band?
if self.hi_freq < self.lo_freq:
tmp = self.hi_freq
self.hi_freq = self.lo_freq
self.lo_freq = tmp
self.df *= -1.0
self.need_flipband = True
# Compute the bandwidth
self.BW = self.num_channels * self.df
self.mjd = int(self.start_MJD[0])
self.secs = (self.start_MJD[0] % 1)*pc.SECPERDAY
def dms_to_rad(deg, min, sec):
"""
dms_to_rad(deg, min, sec):
Convert degrees, minutes, and seconds of arc to radians.
"""
if (deg < 0.0):
sign = -1
elif (deg == 0.0 and (min < 0.0 or sec < 0.0)):
sign = -1
else:
sign = 1
return sign * pc.ARCSECTORAD * \
(60.0 * (60.0 * Num.fabs(deg) +
Num.fabs(min)) + Num.fabs(sec))
def fwhm_func(k, fwhm=fwhm):
if (fwhm < 0.02):
return Num.arccos(1.0 - Num.log(2.0) / k) / pc.PI - fwhm
else:
return Num.arccos(Num.log(0.5 * (Num.exp(k) +
Num.exp(-k))) / k) / pc.PI - fwhm
def GAMMA(porb, e, Mp, Mc):
"""
GAMMA(porb, e, Mp, Mc):
Return the predicted value of relativistic gamma (sec) given the
orbital period (days), eccentricity, and pulsar and companion masses.
"""
return e * (porb * pc.SECPERDAY / pc.TWOPI) ** (1.0 / 3.0) * \
pc.Tsun ** (2.0 / 3.0) * (Mp + Mc) ** (-4.0 / 3.0) * Mc * (Mp + 2.0 * Mc)
self.poln_type = primary['FD_POLN']
self.ra_str = primary['RA']
self.dec_str = primary['DEC']
self.fctr = primary['OBSFREQ']
self.orig_num_chan = primary['OBSNCHAN']
self.orig_df = primary['OBSBW']
self.beam_FWHM = primary['BMIN']
# CHAN_DM card is not in earlier versions of PSRFITS
if 'CHAN_DM' not in list(primary.keys()):
self.chan_dm = 0.0
else:
self.chan_dm = primary['CHAN_DM']
self.start_MJD[ii] = primary['STT_IMJD'] + (primary['STT_SMJD'] + \
primary['STT_OFFS'])/pc.SECPERDAY
# Are we tracking
track = (primary['TRK_MODE'] == "TRACK")
if ii==0:
self.tracking = track
else:
if track != self.tracking:
warnings.warn("'TRK_MODE' values don't match for files 0 and %d" % ii)
# Now switch to the subint HDU header
subint = hdus['SUBINT'].header
self.dt = subint['TBIN']
self.num_channels = subint['NCHAN']
self.num_polns = subint['NPOL']
def pulsar_age(f, fdot, n=3, fo=1e99):
"""
pulsar_age(f, fdot, n=3, fo=1e99):
Return the age of a pulsar (in years) given the spin frequency
and frequency derivative. By default, the characteristic age
is returned (assuming a braking index 'n'=3 and an initial
spin freqquency fo >> f). But 'n' and 'fo' can be set.
"""
return -f / ((n - 1.0) * fdot) * (1.0 - (f / fo) ** (n - 1.0)) / pc.SECPERJULYR
def rad_to_dms(rad):
"""
rad_to_dms(rad):
Convert radians to degrees, minutes, and seconds of arc.
"""
if (rad < 0.0):
sign = -1
else:
sign = 1
arc = pc.RADTODEG * Num.fmod(Num.fabs(rad), pc.PI)
d = int(arc)
arc = (arc - d) * 60.0
m = int(arc)
s = (arc - m) * 60.0
if sign == -1 and d == 0:
return (sign * d, sign * m, sign * s)
else:
return (sign * d, m, s)
def hms_to_rad(hour, min, sec):
"""
hms_to_rad(hour, min, sec):
Convert hours, minutes, and seconds of arc to radians
"""
if (hour < 0.0):
sign = -1
else:
sign = 1
return sign * pc.SECTORAD * \
(60.0 * (60.0 * Num.fabs(hour) +
Num.fabs(min)) + Num.fabs(sec))
def GAMMA(porb, e, Mp, Mc):
"""
GAMMA(porb, e, Mp, Mc):
Return the predicted value of relativistic gamma (sec) given the
orbital period (days), eccentricity, and pulsar and companion masses.
"""
return e * (porb * pc.SECPERDAY / pc.TWOPI) ** (1.0 / 3.0) * \
pc.Tsun ** (2.0 / 3.0) * (Mp + Mc) ** (-4.0 / 3.0) * Mc * (Mp + 2.0 * Mc)
def z_to_accel(z, T, reffreq, harm=1):
"""
z_to_accel(z, T, reffreq, harm=1):
Return the acceleration (in m/s/s) corresponding to the
accelsearch 'z' (i.e. number of bins drifted) at a
reference frequency 'reffreq', for an observation
of duration 'T'. You can specify the harmonic number
in 'harm'.
"""
return z * pc.SOL / (harm * reffreq * T * T)