Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add processes parameter #31

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions nuance/periodic_search.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""
The periodic search module provides functions to compute the probability of
a periodic signal to be present in the data, using quantities computed from single
The periodic search module provides functions to compute the probability of
a periodic signal to be present in the data, using quantities computed from single
events statistics.
"""

import os

import multiprocess as mp
import numpy as np
from tqdm.auto import tqdm
Expand All @@ -12,7 +14,8 @@
from nuance.utils import interp_split_times


def periodic_search(epochs, durations, ls, snr_f, progress=True):
def periodic_search(epochs, durations, ls, snr_f, progress=True,
processes=os.cpu_count()):
"""Returns a function that performs the periodic search given an array of periods.

Parameters
Expand All @@ -27,6 +30,8 @@ def periodic_search(epochs, durations, ls, snr_f, progress=True):
Function that computes the SNR given the epoch, duration and period.
progress : bool, optional
wether to show progress bar, by default True
processes : int, optional
Number of processes to use, by default mp.cpu_count()

Returns
-------
Expand All @@ -43,7 +48,7 @@ def function(periods):
snr = np.zeros(len(periods))
params = np.zeros((len(periods), 3))

with mp.Pool() as pool:
with mp.Pool(processes) as pool:
for p, (epoch, duration_i, period) in enumerate(
_progress(pool.imap(_solve, periods), total=len(periods))
):
Expand Down
Loading