# Fold¶

class baseband_tasks.integration.Fold(ih, n_phase, phase, step=None, *, start=0, average=True, samples_per_frame=1, dtype=None)[source] [edit on github]

Fold pulse profiles in fixed time intervals.

Parameters
ihtask or baseband stream reader

Input data stream, with time as the first axis.

n_phaseint

Number of bins per pulse period.

phasecallable

Should return pulse phases (with or without cycle count) for given input time(s), passed in as an ‘~astropy.time.Time’ object. The output can be an Quantity with angular units or a regular array of float (in which case units of cycles are assumed).

stepint or Quantity, optional

Number of input samples or time interval over which to fold. If not given, the whole file will be folded into a single profile.

startTime or int, optional

Time or offset at which to start the integration. If an offset or if step is integer, the actual start time will the underlying sample time nearest to the requested one. Default: 0 (start of stream).

averagebool, optional

Whether the output pulse profile should be the average of all entries that contributed to it, or rather the sum, in a structured array that holds both 'data' and 'count' items.

samples_per_frameint, optional

Number of sample times to process in one go. This can be used to optimize the process, though in general the default of 1 should work.

dtypedtype, optional

Output dtype. Generally, the default of the dtype of the underlying stream is good enough, but can be used to increase precision. Note that if average=True, it is the user’s responsibilty to pass in a structured dtype.

Stack
If there are only few input samples per phase bin (i.e., its inverse sample rate is similar to the time per phase bin), then it is important to ensure the samples_per_frame of the underlying stream is not small (larger than, say, 20), to avoid a large overhead in calculating phases.
Since the sample time is not necessarily an integer multiple of the pulse period, the returned profiles will generally not contain the same number of samples in each phase bin. The actual number of samples is counted, and for average=True, the sums have been divided by these counts, with bins with no points set to NaN. For average=False, the arrays returned by read are structured arrays with data and count fields.