Spectrogram

class radiospectra.spectrogram.Spectrogram(data, time_axis, freq_axis, start, end, t_init=None, t_label='Time', f_label='Frequency', content='', instruments=None)[source]

Bases: Parent

Spectrogram Class.

Warning

This module is under development! Use at your own risk.

data

two-dimensional array of the image data of the spectrogram.

Type:

ndarray

time_axis

one-dimensional array containing the offset from the start for each column of data.

Type:

ndarray

freq_axis

one-dimensional array containing information about the frequencies each row of the image corresponds to.

Type:

ndarray

start

starting time of the measurement

Type:

datetime

end

end time of the measurement

Type:

datetime

t_init

offset from the start of the day the measurement began. If None gets automatically set from start.

Type:

int

t_label

label for the time axis

Type:

str

f_label

label for the frequency axis

Type:

str

content

header for the image

Type:

str

instruments

instruments that recorded the data, may be more than one if it was constructed using combine_frequencies or join_many.

Type:

str array

Attributes Summary

COPY_PROPERTIES

dtype

shape

Methods Summary

at_freq(freq)

auto_const_bg()

Automatically determine background.

auto_find_background([amount])

Automatically find the background.

clip_freq([vmin, vmax])

Return a new spectrogram only consisting of frequencies in the interval.

clip_values([vmin, vmax, out])

Clip intensities to be in the interval [vmin, vmax].

format_freq(freq)

Override to configure default plotting.

format_time(time)

Override to configure default plotting.

freq_overlap(other)

Get frequency range present in both spectrograms.

interpolate(frequency)

Linearly interpolate intensity at unknown frequency using linear interpolation of its two.

linearize_freqs([delta_freq])

Rebin frequencies so that the frequency axis is linear.

peek(*args, **kwargs)

Plot spectrum onto current axes.

plot([figure, overlays, colorbar, vmin, ...])

Plot spectrogram onto figure.

randomized_auto_const_bg(amount)

Automatically determine background.

randomized_subtract_bg(amount)

Perform randomized constant background subtraction.

rescale([vmin, vmax, dtype])

Rescale intensities to [vmin, vmax].

subtract_bg()

Perform constant background subtraction.

time_formatter(x, pos)

This returns the label for the tick of value x at a specified pos on the time axis.

time_to_x(time)

Return x-coordinate in spectrogram that corresponds to the passed datetime.

Attributes Documentation

COPY_PROPERTIES = [('time_axis', 1), ('freq_axis', 1), ('instruments', 1), ('start', 0), ('end', 0), ('t_label', 0), ('f_label', 0), ('content', 0), ('t_init', 0)]
dtype
shape

Methods Documentation

at_freq(freq)[source]
auto_const_bg()[source]

Automatically determine background.

auto_find_background(amount=0.05)[source]

Automatically find the background.

This is done by first subtracting the average value in each channel and then finding those times which have the lowest standard deviation.

Parameters:

amount (float) – The percent amount (out of 1) of lowest standard deviation to consider.

clip_freq(vmin=None, vmax=None)[source]

Return a new spectrogram only consisting of frequencies in the interval.

[vmin, vmax].

Parameters:
  • vmin (float) – All frequencies in the result are greater or equal to this.

  • vmax (float) – All frequencies in the result are smaller or equal to this.

clip_values(vmin=None, vmax=None, out=None)[source]

Clip intensities to be in the interval [vmin, vmax].

Any values greater than the maximum will be assigned the maximum, any values lower than the minimum will be assigned the minimum. If either is left out or None, do not clip at that side of the interval.

Parameters:
  • min (int or float) – New minimum value for intensities.

  • max (int or float) – New maximum value for intensities

static format_freq(freq)[source]

Override to configure default plotting.

static format_time(time)[source]

Override to configure default plotting.

freq_overlap(other)[source]

Get frequency range present in both spectrograms.

Returns (min, max) tuple.

Parameters:

other (Spectrogram) – other spectrogram with which to look for frequency overlap

interpolate(frequency)[source]

Linearly interpolate intensity at unknown frequency using linear interpolation of its two.

neighbours.

Parameters:

frequency (float or int) – Unknown frequency for which to linearly interpolate the intensities. freq_axis[0] >= frequency >= self_freq_axis[-1]

linearize_freqs(delta_freq=None)[source]

Rebin frequencies so that the frequency axis is linear.

Parameters:

delta_freq (float) – Difference between consecutive values on the new frequency axis. Defaults to half of smallest delta in current frequency axis. Compare Nyquist-Shannon sampling theorem.

peek(*args, **kwargs)[source]

Plot spectrum onto current axes.

Parameters:
  • *args (dict) –

  • **kwargs (dict) – Any additional plot arguments that should be used when plotting.

Returns:

fig (Figure) – A plot figure.

plot(figure=None, overlays=[], colorbar=True, vmin=None, vmax=None, linear=True, showz=True, yres=1080, max_dist=None, **matplotlib_args)[source]

Plot spectrogram onto figure.

Parameters:
  • figure (Figure) – Figure to plot the spectrogram on. If None, new Figure is created.

  • overlays (list) – List of overlays (functions that receive figure and axes and return new ones) to be applied after drawing.

  • colorbar (bool) – Flag that determines whether or not to draw a colorbar. If existing figure is passed, it is attempted to overdraw old colorbar.

  • vmin (float) – Clip intensities lower than vmin before drawing.

  • vmax (float) – Clip intensities higher than vmax before drawing.

  • linear (bool) – If set to True, “stretch” image to make frequency axis linear.

  • showz (bool) – If set to True, the value of the pixel that is hovered with the mouse is shown in the bottom right corner.

  • yres (int or None) – To be used in combination with linear=True. If None, sample the image with half the minimum frequency delta. Else, sample the image to be at most yres pixels in vertical dimension. Defaults to 1080 because that’s a common screen size.

  • max_dist (float or None) – If not None, mask elements that are further than max_dist away from actual data points (ie, frequencies that actually have data from the receiver and are not just nearest-neighbour interpolated).

randomized_auto_const_bg(amount)[source]

Automatically determine background.

Only consider a randomly chosen subset of the image.

Parameters:

amount (int) – Size of random sample that is considered for calculation of the background.

randomized_subtract_bg(amount)[source]

Perform randomized constant background subtraction.

Does not produce the same result every time it is run.

Parameters:

amount (int) – Size of random sample that is considered for calculation of the background.

rescale(vmin=0, vmax=1, dtype=dtype('float32'))[source]

Rescale intensities to [vmin, vmax].

Note that vmin ≠ vmax and spectrogram.min() ≠ spectrogram.max().

Parameters:
  • vmin (float or int) – New minimum value in the resulting spectrogram.

  • vmax (float or int) – New maximum value in the resulting spectrogram.

  • dtype (numpy.dtype) – Data-type of the resulting spectrogram.

subtract_bg()[source]

Perform constant background subtraction.

time_formatter(x, pos)[source]

This returns the label for the tick of value x at a specified pos on the time axis.

time_to_x(time)[source]

Return x-coordinate in spectrogram that corresponds to the passed datetime.

value.

Parameters:

time (parse_time compatible str) – datetime to find the x coordinate for.