Skip to content

Commit 0a7d0f1

Browse files
authored
Merge pull request #97 from lgbouma/master
Add `verbose` kwarg
2 parents 86aff9f + 9b5728d commit 0a7d0f1

File tree

3 files changed

+34
-26
lines changed

3 files changed

+34
-26
lines changed

docs/source/Python interface.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ This describes the Python interface to TLS.
77
Define data for a search
88
------------------------
99

10-
.. class:: transitleastsquares.model(t, y, dy)
10+
.. class:: transitleastsquares.model(t, y, dy, verbose=True)
1111

1212
:t: *(array)* Time series of the data (**in units of days**)
1313
:y: *(array)* Flux series of the data, so that ``1`` is nominal flux (out of transit) and ``0`` is darkness. A transit may be represented by a flux of e.g., ``0.99``
1414
:dy: *(array, optional)* Measurement errors of the data
15+
:verbose: *(bool, optional)* Whether to print important information about the TLS run. Default True.
1516

1617
.. note::
1718

transitleastsquares/main.py

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,15 @@
4444
class transitleastsquares(object):
4545
"""Compute the transit least squares of limb-darkened transit models"""
4646

47-
def __init__(self, t, y, dy=None):
47+
def __init__(self, t, y, dy=None, verbose=True):
4848
self.t, self.y, self.dy = validate_inputs(t, y, dy)
49+
self.verbose = verbose
4950

5051
def power(self, **kwargs):
5152
"""Compute the periodogram for a set of user-defined parameters"""
5253

53-
print(tls_constants.TLS_VERSION)
54+
if self.verbose:
55+
print(tls_constants.TLS_VERSION)
5456
self, kwargs = validate_args(self, kwargs)
5557

5658
periods = period_grid(
@@ -81,36 +83,39 @@ def power(self, **kwargs):
8183
w=self.w,
8284
u=self.u,
8385
limb_dark=self.limb_dark,
86+
verbose=self.verbose
8487
)
8588

86-
print(
87-
"Searching "
88-
+ str(len(self.y))
89-
+ " data points, "
90-
+ str(len(periods))
91-
+ " periods from "
92-
+ str(round(min(periods), 3))
93-
+ " to "
94-
+ str(round(max(periods), 3))
95-
+ " days"
96-
)
89+
if self.verbose:
90+
print(
91+
"Searching "
92+
+ str(len(self.y))
93+
+ " data points, "
94+
+ str(len(periods))
95+
+ " periods from "
96+
+ str(round(min(periods), 3))
97+
+ " to "
98+
+ str(round(max(periods), 3))
99+
+ " days"
100+
)
97101

98102
# Python 2 multiprocessing with "partial" doesn't work
99103
# For now, only single-threading in Python 2 is supported
100104
if sys.version_info[0] < 3:
101105
self.use_threads = 1
102106
warnings.warn("This TLS version supports no multithreading on Python 2")
103107

104-
if self.use_threads == multiprocessing.cpu_count():
105-
print("Using all " + str(self.use_threads) + " CPU threads")
106-
else:
107-
print(
108-
"Using "
109-
+ str(self.use_threads)
110-
+ " of "
111-
+ str(multiprocessing.cpu_count())
112-
+ " CPU threads"
113-
)
108+
if self.verbose:
109+
if self.use_threads == multiprocessing.cpu_count():
110+
print("Using all " + str(self.use_threads) + " CPU threads")
111+
else:
112+
print(
113+
"Using "
114+
+ str(self.use_threads)
115+
+ " of "
116+
+ str(multiprocessing.cpu_count())
117+
+ " CPU threads"
118+
)
114119

115120
if self.show_progress_bar:
116121
bar_format = "{desc}{percentage:3.0f}%|{bar}| {n_fmt}/{total_fmt} periods | {elapsed}<{remaining}"

transitleastsquares/transit.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,14 @@ def fractional_transit(
9595
return result
9696

9797

98-
def get_cache(durations, maxwidth_in_samples, per, rp, a, inc, ecc, w, u, limb_dark):
98+
def get_cache(durations, maxwidth_in_samples, per, rp, a, inc, ecc, w, u,
99+
limb_dark, verbose=True):
99100
"""Fetches (size(durations)*size(depths)) light curves of length
100101
maxwidth_in_samples and returns these LCs in a 2D array, together with
101102
their metadata in a separate array."""
102103

103-
print("Creating model cache for", str(len(durations)), "durations")
104+
if verbose:
105+
print("Creating model cache for", str(len(durations)), "durations")
104106
lc_arr = []
105107
rows = numpy.size(durations)
106108
lc_cache_overview = numpy.zeros(

0 commit comments

Comments
 (0)