def _make_segment_spectrum(self, lc, segment_size): if not isinstance(lc, lightcurve.Lightcurve): raise TypeError("lc must be a lightcurve.Lightcurve object") if self.gti is None: self.gti = lc.gti check_gtis(self.gti) start_inds, end_inds = \ bin_intervals_from_gtis(self.gti, segment_size, lc.time) power_all = [] nphots_all = [] for start_ind, end_ind in zip(start_inds, end_inds): time = lc.time[start_ind:end_ind] counts = lc.counts[start_ind:end_ind] counts_err = lc.counts_err[start_ind:end_ind] lc_seg = lightcurve.Lightcurve(time, counts, err=counts_err, err_dist=lc.err_dist.lower()) power_seg = Powerspectrum(lc_seg, norm=self.norm) power_all.append(power_seg) nphots_all.append(np.sum(lc_seg.counts)) return power_all, nphots_all
def _make_segment_spectrum(self, lc, segment_size): """ Split the light curves into segments of size ``segment_size``, and calculate a power spectrum for each. Parameters ---------- lc : :class:`stingray.Lightcurve` objects\ The input light curve segment_size : ``numpy.float`` Size of each light curve segment to use for averaging. Returns ------- power_all : list of :class:`Powerspectrum` objects A list of power spectra calculated independently from each light curve segment nphots_all : ``numpy.ndarray`` List containing the number of photons for all segments calculated from ``lc`` """ if not isinstance(lc, lightcurve.Lightcurve): raise TypeError("lc must be a lightcurve.Lightcurve object") if self.gti is None: self.gti = lc.gti else: if not np.all(lc.gti == self.gti): self.gti = np.vstack([self.gti, lc.gti]) check_gtis(self.gti) start_inds, end_inds = \ bin_intervals_from_gtis(lc.gti, segment_size, lc.time, dt=lc.dt) power_all = [] nphots_all = [] for start_ind, end_ind in zip(start_inds, end_inds): time = lc.time[start_ind:end_ind] counts = lc.counts[start_ind:end_ind] counts_err = lc.counts_err[start_ind:end_ind] lc_seg = lightcurve.Lightcurve(time, counts, err=counts_err, err_dist=lc.err_dist.lower(), skip_checks=True, dt=lc.dt) power_seg = Powerspectrum(lc_seg, norm=self.norm) power_all.append(power_seg) nphots_all.append(np.sum(lc_seg.counts)) return power_all, nphots_all
def _make_segment_spectrum(self, lc1, lc2, segment_size): # TODO: need to update this for making cross spectra. assert isinstance(lc1, lightcurve.Lightcurve) assert isinstance(lc2, lightcurve.Lightcurve) if lc1.dt != lc2.dt: raise ValueError("Light curves do not have same time binning dt.") if lc1.tseg != lc2.tseg: raise ValueError("Lightcurves do not have same tseg.") if self.gti is None: self.gti = cross_two_gtis(lc1.gti, lc2.gti) check_gtis(self.gti) cs_all = [] nphots1_all = [] nphots2_all = [] start_inds, end_inds = \ bin_intervals_from_gtis(self.gti, segment_size, lc1.time) for start_ind, end_ind in zip(start_inds, end_inds): time_1 = lc1.time[start_ind:end_ind] counts_1 = lc1.counts[start_ind:end_ind] time_2 = lc2.time[start_ind:end_ind] counts_2 = lc2.counts[start_ind:end_ind] lc1_seg = lightcurve.Lightcurve(time_1, counts_1) lc2_seg = lightcurve.Lightcurve(time_2, counts_2) cs_seg = Crossspectrum(lc1_seg, lc2_seg, norm=self.norm) cs_all.append(cs_seg) nphots1_all.append(np.sum(lc1_seg.counts)) nphots2_all.append(np.sum(lc2_seg.counts)) return cs_all, nphots1_all, nphots2_all
def sample_data(): """ Import data from .txt file and return a light curve object. Returns ------- sample: :class:`Lightcurve` object The :class:`Lightcurve` object with the desired time stamps and counts. """ lc_file = pkg_resources.resource_stream(__name__, "datasets/lc_sample.txt") data = np.loadtxt(lc_file) # Extract first and second columns to indicate dates and counts respectively dates = data[0:len(data), 0] counts = data[0:len(data), 1] # Return class:`Lightcurve` object return lightcurve.Lightcurve(dates, counts)
def sample_data(): """ Import data from .txt file and return a light curve object. Returns ------- sample: :class:`Lightcurve` object The :class:`Lightcurve` object with the desired time stamps and counts. """ lc_file = os.path.join(os.path.abspath(os.path.dirname(__file__)), "datasets", "lc_sample.txt") data = np.loadtxt(lc_file) # Extract first and second columns to indicate dates and counts respectively dates = data[0:len(data), 0] counts = data[0:len(data), 1] # Return class:`Lightcurve` object return lightcurve.Lightcurve(dates, counts)
def _make_segment_psd(self, lc, segment_size): assert isinstance(lc, lightcurve.Lightcurve) ## number of bins per segment nbins = int(segment_size / lc.dt) start_ind = 0 end_ind = nbins ps_all = [] nphots_all = [] while end_ind <= lc.counts.shape[0]: time = lc.time[start_ind:end_ind] counts = lc.counts[start_ind:end_ind] lc_seg = lightcurve.Lightcurve(time, counts) ps_seg = Powerspectrum(lc_seg, norm=self.norm) ps_all.append(ps_seg) nphots_all.append(np.sum(lc_seg.counts)) start_ind += nbins end_ind += nbins return ps_all, nphots_all
try: import matplotlib.pyplot as plt except ImportError: raise ImportError("Matplotlib required for plot()") cont = plt.contourf(self.freq, self.freq, self.bispec_phase, 100, cmap=plt.cm.Spectral_r) plt.colorbar(cont) plt.title('Bispectrum Phase') plt.xlabel('freq 1') plt.ylabel('freq 2') if axis is not None: plt.axis(axis) # Save figure if save: if filename is None: plt.savefig('bispec_phase.png') else: plt.savefig(filename) return plt lc = lightcurve.Lightcurve([1, 2, 3, 4, 5], [2, 3, 1, 1, 2]) bs = Bispectrum(lc) print(bs.bispec_mag)