nicer.fillgaps

Fill gaps in a time series while preserving its noise characteristics.

Gaps are filled by reflecting and inverting the data on either side of each gap, so that Allan variance (AVAR) curves are preserved. This is an implementation of the algorithm in Howe and Schlossberger, “Characterizing Frequency Stability Measurements having Multiple Data Gaps”.

Can also be run as a script: python fillgaps.py datafile savefile.

Functions

check_both_sides(data, gaps, curgap, ...)

Find the points on both sides of a gap to use for filling it (half from each side).

check_left(data, gaps, curgap, curgap_size, ...)

Find the points to the left of a gap to use for filling it.

check_right(data, gaps, curgap, curgap_size, ...)

Find the points to the right of a gap to use for filling it.

fill(data, gaps, gap_total, gap_num, xcoords)

Fill one gap by reflecting and inverting the data on one or both sides of it.

fillgaps(x, y)

Fill gaps in a time series while preserving its noise characteristics.

fillgaps_main(datafile[, savefile, plotresults])

Read a time series from a file, fill its gaps, and optionally save and plot the result.

filter_all(data)

Apply filterfunction() to each continuous block of data between gaps.

filterfunction(data)

Filter a continuous block of data in the frequency domain.

nicer.fillgaps.fillgaps(x, y)[source]

Fill gaps in a time series while preserving its noise characteristics.

Parameters:
  • x (array_like) -- Times, which should lie on a regular grid with some points missing (the gaps).

  • y (array_like) -- Values (for example, time offsets) at each time in x.

Returns:

  • xfilled (numpy.ndarray) -- The complete, evenly spaced time grid.

  • data (numpy.ndarray) -- The values on that grid, with the gaps filled.

nicer.fillgaps.filterfunction(data)[source]

Filter a continuous block of data in the frequency domain.

The Fourier transform of the data is multiplied by exp(-2**3 f/T).

Parameters:

data (array_like) -- A block of data with no gaps.

Returns:

numpy.ndarray -- The filtered data.

nicer.fillgaps.filter_all(data)[source]

Apply filterfunction() to each continuous block of data between gaps.

Parameters:

data (array_like) -- Data with gaps marked as NaN.

Returns:

numpy.ndarray -- The filtered data.

nicer.fillgaps.check_right(data, gaps, curgap, curgap_size, curgap_num, gap_total)[source]

Find the points to the right of a gap to use for filling it.

Parameters:
  • data (numpy.ndarray) -- The data being filled (modified in place).

  • gaps (dict) -- Maps gap number to the (start, end) indices of each gap.

  • curgap (tuple of int) -- (start, end) indices of the current gap.

  • curgap_size (int) -- Size of the current gap.

  • curgap_num (int) -- Number of the current gap.

  • gap_total (int) -- Total number of gaps.

nicer.fillgaps.check_both_sides(data, gaps, curgap, curgap_size, curgap_num, gap_total)[source]

Find the points on both sides of a gap to use for filling it (half from each side).

Parameters:
  • data (numpy.ndarray) -- The data being filled (modified in place).

  • gaps (dict) -- Maps gap number to the (start, end) indices of each gap.

  • curgap (tuple of int) -- (start, end) indices of the current gap.

  • curgap_size (int) -- Size of the current gap.

  • curgap_num (int) -- Number of the current gap.

  • gap_total (int) -- Total number of gaps.

nicer.fillgaps.check_left(data, gaps, curgap, curgap_size, curgap_num, gap_total)[source]

Find the points to the left of a gap to use for filling it.

Parameters:
  • data (numpy.ndarray) -- The data being filled (modified in place).

  • gaps (dict) -- Maps gap number to the (start, end) indices of each gap.

  • curgap (tuple of int) -- (start, end) indices of the current gap.

  • curgap_size (int) -- Size of the current gap.

  • curgap_num (int) -- Number of the current gap.

  • gap_total (int) -- Total number of gaps.

nicer.fillgaps.fill(data, gaps, gap_total, gap_num, xcoords, reverse=False)[source]

Fill one gap by reflecting and inverting the data on one or both sides of it.

Parameters:
  • data (numpy.ndarray) -- The data being filled (modified in place).

  • gaps (dict) -- Maps gap number to the (start, end) indices of each gap.

  • gap_total (int) -- Total number of gaps.

  • gap_num (int) -- Number of the gap to fill.

  • xcoords (numpy.ndarray) -- Times corresponding to data.

  • reverse (bool, optional) -- If True, work through the data in reverse.

Returns:

tuple of int or None -- The number of the next gap to fill and the number of gaps remaining, or None if the gap could not be filled.

nicer.fillgaps.fillgaps_main(datafile, savefile='NaN', plotresults=True)[source]

Read a time series from a file, fill its gaps, and optionally save and plot the result.

Parameters:
  • datafile (str) -- Input file with two columns: an evenly spaced time (usually seconds) and a value (usually the time offset of one clock relative to another). A .csv file is read as comma-separated; a .txt file as whitespace-separated.

  • savefile (str, optional) -- If given, write the filled time series to this CSV file.

  • plotresults (bool, optional) -- If True, plot the input and filled data.