Skip to content

Commit

Permalink
move warning to note
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanhammonds committed Feb 5, 2021
1 parent 08b0158 commit d7e3d28
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions neurodsp/sim/periodic.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Simulating time series, with periodic activity."""

import warnings
from itertools import repeat

import numpy as np
Expand Down Expand Up @@ -39,6 +38,13 @@ def sim_oscillation(n_seconds, fs, freq, cycle='sine', phase=0, **cycle_params):
sig : 1d array
Simulated oscillation.
Notes
-----
When `freq` and `fs` are not evenly divisible, there will non-integer number of samples
per cycle. In the frequency domain, this can lead to power in non-simulated frequencies in the
power spectrum. Consider updating ``freq and ``fs`` to an integer divisor/multiple when
investigating spectral properties.
Examples
--------
Simulate a continuous sinusoidal oscillation at 5 Hz:
Expand All @@ -51,9 +57,6 @@ def sim_oscillation(n_seconds, fs, freq, cycle='sine', phase=0, **cycle_params):
... cycle='asine', phase=0.5, rdsym=0.75)
"""

# Check if tiling can produce full oscillations
_check_tiling(fs, freq)

# Figure out how many cycles are needed for the signal
n_cycles = int(np.ceil(n_seconds * freq))

Expand Down Expand Up @@ -154,9 +157,6 @@ def sim_bursty_oscillation(n_seconds, fs, freq, burst_def='prob', burst_params={
if burst_def == 'prob' and burst_param not in burst_params:
burst_params[burst_param] = temp

# Check if tiling can produce full oscillations
_check_tiling(fs, freq)

# Simulate a normalized cycle to use for bursts
n_seconds_cycle = 1/freq
osc_cycle = sim_normalized_cycle(n_seconds_cycle, fs, cycle, **cycle_params)
Expand Down Expand Up @@ -310,15 +310,3 @@ def get_burst_samples(is_oscillating, fs, freq):
bursts = np.repeat(is_oscillating, n_samples_cycle)

return bursts


def _check_tiling(fs, freq):
"""Check if tiling will produce an integer number of cycles for the simulated oscillation."""

if not (fs/freq).is_integer():

warnings.warn('''
The settings for the frequency and sampling rate are not evenly divisible. In the frequency
domain, this can lead to power in non-simulated frequencies in the power spectrum. Consider
updating freq and fs to an integer divisor/multiple pair."
''', category=RuntimeWarning)

0 comments on commit d7e3d28

Please sign in to comment.