Completed
Push — main ( c56d9c...c85ca6 )
by Jose Enrique
15s queued 12s
created

mutis.correlation.Correlation.plot_corr()   B

Complexity

Conditions 8

Size

Total Lines 58
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 29
dl 0
loc 58
rs 7.3173
c 0
b 0
f 0
cc 8
nop 4

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
# Licensed under a 3-clause BSD style license - see LICENSE
2
"""Analysis of correlation of light curves."""
3
4
import logging
5
6
import matplotlib.pyplot as plt
0 ignored issues
show
introduced by
Unable to import 'matplotlib.pyplot'
Loading history...
7
import numpy as np
0 ignored issues
show
introduced by
Unable to import 'numpy'
Loading history...
8
9
from mutis.lib.correlation import *
0 ignored issues
show
Coding Style introduced by
The usage of wildcard imports like mutis.lib.correlation should generally be avoided.
Loading history...
Unused Code introduced by
kroedel_ab_p was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
welsh_ab_p was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
ndcf was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
get_grid was imported with wildcard, but is not used.
Loading history...
10
11
__all__ = ["Correlation"]
12
13
log = logging.getLogger(__name__)
14
15
16
class Correlation:
0 ignored issues
show
best-practice introduced by
Too many instance attributes (21/7)
Loading history...
17
    """Analysis of the correlation of two signals.
18
19
    Parameters
20
    ----------
21
    signal1 : :class:`~mutis.signal.Signal`
22
        Values of the time axis.
23
    signal2 : :class:`~mutis.signal.Signal`
24
        Values of the signal axis.
25
    fcorr : :py:class:`~str`
26
        Method used to correlate the signals.
27
    """
28
29
    def __init__(self, signal1, signal2, fcorr):
30
        self.signal1 = signal1
31
        self.signal2 = signal2
32
        self.fcorr = fcorr
33
34
        self.times = np.array([])
35
        self.dts = np.array([])
36
        self.nb = np.array([])
0 ignored issues
show
Coding Style Naming introduced by
Attribute name "nb" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
37
38
        self.values = None
39
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
40
        # TODO: have a much smaller set of attributes
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
41
        self.samples = None
42
        # storage of the significance limits of the correlation
43
        self.l1s = None
44
        self.l2s = None
45
        self.l3s = None
46
        # storage of the uncertainties of the correlation
47
        self.s1s = None
48
        self.s2s = None
49
        self.s3s = None
50
51
        # attributes indicating the ranges where the correlations are defined
52
        t1, t2 = self.signal1.times, self.signal2.times
0 ignored issues
show
Coding Style Naming introduced by
Variable name "t2" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style Naming introduced by
Variable name "t1" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
53
        self.tmin_full = t2.min() - t1.max()
54
        self.tmax_full = t2.max() - t1.min()
55
        self.t0_full = (self.tmax_full + self.tmin_full) / 2
56
        self.tmin_same = -(np.max([t1.max() - t1.min(), t2.max() - t2.min()])) / 2 + self.t0_full
57
        self.tmax_same = (np.max([t1.max() - t1.min(), t2.max() - t2.min()])) / 2 + self.t0_full
58
        self.tmin_valid = (
59
            -(np.max([t1.max() - t1.min(), t2.max() - t2.min()]) - np.min([t1.max() - t1.min(), t2.max() - t2.min()]))
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (118/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
60
            / 2
61
            + self.t0_full
62
        )
63
        self.tmax_valid = (
64
            +(np.max([t1.max() - t1.min(), t2.max() - t2.min()]) - np.min([t1.max() - t1.min(), t2.max() - t2.min()]))
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (118/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
65
            / 2
66
            + self.t0_full
67
        )
68
69
    def gen_synth(self, samples):
70
        """Generates the synthetic light curves.
71
72
        Generates the specified number `samples` of synthetic light
73
        curves for each signal, to be used to compute the significance
74
        the correlation.
75
76
        Parameters
77
        ----------
78
        samples : :py:class:`~int`
79
            Number of synthetic light curves to be generated for each signal.
80
        """
81
82
        self.samples = samples
83
        self.signal1.gen_synth(samples)
84
        self.signal2.gen_synth(samples)
85
86
    def gen_corr(self, uncert=True, dsamples=500):
87
        """Generates the correlation of the signals.
88
89
        Generates the correlation of the signals, and computes their
90
        confidence level from the synthetic light curves, which must
91
        have been generated before.
92
        """
93
94
        if uncert and self.signal1.dvalues is None:
95
            log.error("uncert is True but no uncertainties for Signal 1 were specified, setting uncert to False")
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (113/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
96
            uncert = False
97
        if uncert and self.signal2.dvalues is None:
98
            log.error("uncert is True but no uncertainties for Signal 2 were specified, setting uncert to False")
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (113/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
99
            uncert = False
100
101
        if len(self.times) == 0 or len(self.dts) == 0:
102
            raise Exception(
103
                "You need to define the times on which to calculate the correlation."
104
                "Please use gen_times() or manually set them."
105
            )
106
107
        # TODO: refactor if/elif with a helper function
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
108
        mc_corr = np.empty((self.samples, self.times.size))
109
        if uncert:
110
            mc_sig = np.empty((dsamples, self.times.size))
111
112
        if self.fcorr == "welsh_ab":
113
            for n in range(self.samples):
0 ignored issues
show
Coding Style Naming introduced by
Variable name "n" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
114
                mc_corr[n] = welsh_ab(
115
                    self.signal1.times,
116
                    self.signal1.synth[n],
117
                    self.signal2.times,
118
                    self.signal2.synth[n],
119
                    self.times,
120
                    self.dts,
121
                )
122
            if uncert:
123
                for n in range(dsamples):
0 ignored issues
show
Coding Style Naming introduced by
Variable name "n" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
124
                    mc_sig[n] = welsh_ab(
125
                        self.signal1.times,
126
                        self.signal1.values + self.signal1.dvalues * np.random.randn(self.signal1.values.size),
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (111/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
127
                        self.signal2.times,
128
                        self.signal2.values + self.signal2.dvalues * np.random.randn(self.signal2.values.size),
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (111/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
129
                        self.times,
130
                        self.dts,
131
                    )
132
            self.values = welsh_ab(
133
                self.signal1.times,
134
                self.signal1.values,
135
                self.signal2.times,
136
                self.signal2.values,
137
                self.times,
138
                self.dts,
139
            )
140
        elif self.fcorr == "kroedel_ab":
141
            for n in range(self.samples):
0 ignored issues
show
Coding Style Naming introduced by
Variable name "n" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
142
                mc_corr[n] = kroedel_ab(
143
                    self.signal1.times,
144
                    self.signal1.synth[n],
145
                    self.signal2.times,
146
                    self.signal2.synth[n],
147
                    self.times,
148
                    self.dts,
149
                )
150
            if uncert:
151
                for n in range(dsamples):
0 ignored issues
show
Coding Style Naming introduced by
Variable name "n" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
152
                    mc_sig[n] = kroedel_ab(
153
                        self.signal1.times,
154
                        self.signal1.values + self.signal1.dvalues * np.random.randn(self.signal1.values.size),
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (111/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
155
                        self.signal2.times,
156
                        self.signal2.values + self.signal2.dvalues * np.random.randn(self.signal2.values.size),
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (111/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
157
                        self.times,
158
                        self.dts,
159
                    )
160
            self.values = kroedel_ab(
161
                self.signal1.times,
162
                self.signal1.values,
163
                self.signal2.times,
164
                self.signal2.values,
165
                self.times,
166
                self.dts,
167
            )
168
        elif self.fcorr == "numpy":
169
            for n in range(self.samples):
0 ignored issues
show
Coding Style Naming introduced by
Variable name "n" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
170
                mc_corr[n] = nindcf(
171
                    self.signal1.times,
172
                    self.signal1.synth[n],
173
                    self.signal2.times,
174
                    self.signal2.synth[n],
175
                )
176
            if uncert:
177
                for n in range(dsamples):
0 ignored issues
show
Coding Style Naming introduced by
Variable name "n" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
178
                    mc_sig[n] = nindcf(
179
                        self.signal1.times,
180
                        self.signal1.values + self.signal1.dvalues * np.random.randn(self.signal1.values.size),
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (111/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
181
                        self.signal2.times,
182
                        self.signal2.values + self.signal2.dvalues * np.random.randn(self.signal2.values.size),
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (111/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
183
                    )
184
            self.values = nindcf(
185
                self.signal1.times,
186
                self.signal1.values,
187
                self.signal2.times,
188
                self.signal2.values,
189
            )
190
        else:
191
            raise Exception("Unknown method " + self.fcorr + " for correlation.")
192
193
        self.l3s = np.percentile(mc_corr, [0.135, 99.865], axis=0)
194
        self.l2s = np.percentile(mc_corr, [2.28, 97.73], axis=0)
195
        self.l1s = np.percentile(mc_corr, [15.865, 84.135], axis=0)
196
197
        if uncert:
198
            self.s3s = np.percentile(mc_sig, [0.135, 99.865], axis=0)
0 ignored issues
show
introduced by
The variable mc_sig does not seem to be defined in case uncert on line 109 is False. Are you sure this can never be the case?
Loading history...
199
            self.s2s = np.percentile(mc_sig, [2.28, 97.73], axis=0)
200
            self.s1s = np.percentile(mc_sig, [15.865, 84.135], axis=0)
201
202
    def gen_times(self, ftimes="canopy", *args, **kwargs):
0 ignored issues
show
introduced by
Keyword argument before variable positional arguments list in the definition of gen_times function
Loading history...
203
        """Sets times and bins using the method defined by ftimes parameter.
204
205
        Parameters
206
        ----------
207
        ftimes : :py:class:`~str`
208
            Method used to bin the time interval of the correlation.
209
            Possible values are:
210
            - "canopy": Computes a binning as dense as possible, with
211
            variable bin width and (with a minimum and a maximum
212
            resolution) and a minimum statistic.
213
            - "rawab": Computes a binning with variable bin width,
214
            a given step, maximum bin size and a minimum statistic.
215
            - "uniform": Computes a binning with uniform bin width
216
            and a minimum statistic.
217
            - "numpy": Computes a binning suitable for method='numpy'.
218
        """
219
        if ftimes == "canopy":
220
            self.times, self.dts, self.nb = gen_times_canopy(self.signal1.times, self.signal2.times, *args, **kwargs)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (117/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
221
        elif ftimes == "rawab":
222
            self.times, self.dts, self.nb = gen_times_rawab(self.signal1.times, self.signal2.times, *args, **kwargs)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (116/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
223
        elif ftimes == "uniform":
224
            self.times, self.dts, self.nb = gen_times_uniform(self.signal1.times, self.signal2.times, *args, **kwargs)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (118/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
225
        elif ftimes == "numpy":
226
            t1, t2 = self.signal1.times, self.signal1.times
0 ignored issues
show
Coding Style Naming introduced by
Variable name "t2" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style Naming introduced by
Variable name "t1" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
227
            dt = np.max([(t1.max() - t1.min()) / t1.size, (t2.max() - t2.min()) / t2.size])
0 ignored issues
show
Coding Style Naming introduced by
Variable name "dt" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
228
            n1 = int(np.ptp(t1) / dt * 10.0)
0 ignored issues
show
Coding Style Naming introduced by
Variable name "n1" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
229
            n2 = int(np.ptp(t1) / dt * 10.0)
0 ignored issues
show
Coding Style Naming introduced by
Variable name "n2" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
230
            self.times = np.linspace(self.tmin_full, self.tmax_full, n1 + n2 - 1)
231
            self.dts = np.full(self.times.size, (self.tmax_full - self.tmin_full) / (n1 + n2))
232
        else:
233
            raise Exception("Unknown method " + ftimes + ", please indicate how to generate times.")
234
235
    def plot_corr(self, uncert=True, ax=None, legend=False):
0 ignored issues
show
Coding Style Naming introduced by
Argument name "ax" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
236
        """Plots the correlation of the signals.
237
238
        Plots the correlation of the signal, and the confidence limits
239
        computed from the synthetic curves.
240
241
        Parameters
242
        ----------
243
        ax : :class:`matplotlib.axes.Axes`
244
            Axes to be used (default None, it creates a new axes).
245
        legend : :py:class:`~bool`
246
            Whether to add a legend indicating the confidence levels.
247
        """
248
249
        # TODO: develop a plotting object for plots
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
250
        #       this will considerably shorten the
251
        #       number of attributes of this class
252
253
        if uncert and self.signal1.dvalues is None:
254
            log.error("uncert is True but no uncertainties for Signal 1 were specified, setting uncert to False")
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (113/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
255
            uncert = False
256
        if uncert and self.signal2.dvalues is None:
257
            log.error("uncert is True but no uncertainties for Signal 2 were specified, setting uncert to False")
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (113/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
258
            uncert = False
259
            
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
260
        # plt.figure()
261
        if ax is None:
262
            ax = plt.gca()
263
264
        ax.plot(self.times, self.l1s[0], "c-.")
265
        ax.plot(self.times, self.l1s[1], "c-.", label=r"$1\sigma$")
266
        ax.plot(self.times, self.l2s[0], "k--")
267
        ax.plot(self.times, self.l2s[1], "k--", label=r"$2\sigma$")
268
        ax.plot(self.times, self.l3s[0], "r-")
269
        ax.plot(self.times, self.l3s[1], "r-", label=r"$3\sigma$")
270
        ax.plot(self.times, self.values, "b.--", lw=1)
271
272
        # full limit
273
        ax.axvline(x=self.tmin_full, ymin=-1, ymax=+1, color="red", linewidth=4, alpha=0.5)
274
        ax.axvline(x=self.tmax_full, ymin=-1, ymax=+1, color="red", linewidth=4, alpha=0.5)
275
        # same limit
276
        ax.axvline(x=self.tmin_same, ymin=-1, ymax=+1, color="black", linewidth=2, alpha=0.5)
277
        ax.axvline(x=self.tmax_same, ymin=-1, ymax=+1, color="black", linewidth=2, alpha=0.5)
278
        # valid limit
279
        ax.axvline(x=self.tmin_valid, ymin=-1, ymax=+1, color="cyan", linewidth=1, alpha=0.5)
280
        ax.axvline(x=self.tmax_valid, ymin=-1, ymax=+1, color="cyan", linewidth=1, alpha=0.5)
281
282
283
        if uncert:
284
            ax.fill_between(x=self.times, y1=self.s1s[0], y2=self.s1s[1], color="b", alpha=0.5)
285
            ax.fill_between(x=self.times, y1=self.s2s[0], y2=self.s2s[1], color="b", alpha=0.3)
286
            ax.fill_between(x=self.times, y1=self.s3s[0], y2=self.s3s[1], color="b", alpha=0.1)
287
288
        if legend:
289
            ax.legend()
290
291
        # plt.show()
292
        return ax
293
294
    def plot_times(self, rug=False):
295
        """Plots the time binning generated previously.
296
297
        Plots the number of total bins, their distribution and the
298
        number of points in each bin for the generated time binning,
299
        previously generated with Correlation().gen_times(...).
300
301
        Parameters
302
        ----------
303
        rug : :py:class:`~bool`
304
            Whether to make a rug plot just below the binning, to make
305
            it easier to visually understand the density and distribution
306
            of the generated bins.
307
308
        """
309
310
        # TODO: develop a plotting object for plots
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
311
        #       this will considerably shorten the
312
        #       number of attributes of this class
313
314
        fig, ax = plt.subplots(nrows=2, ncols=1, sharex=True)
0 ignored issues
show
Coding Style Naming introduced by
Variable name "ax" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
315
        tab, dtab, nab = self.times, self.dts, self.nb
316
317
        fig.suptitle("Total bins: {:d}".format(self.times.size))
318
        ax[0].plot(tab, nab, "b.")
319
        ax[0].errorbar(x=tab, y=nab, xerr=dtab / 2, fmt="none")
320
        ax[0].set_ylabel("$n_i$")
321
        ax[0].grid()
322
        ax[0].axvline(x=self.tmin_full, ymin=-1, ymax=+1, color="red", linewidth=4, alpha=0.5)
323
        ax[0].axvline(x=self.tmax_full, ymin=-1, ymax=+1, color="red", linewidth=4, alpha=0.5)
324
        ax[0].axvline(x=self.tmin_same, ymin=-1, ymax=+1, color="black", linewidth=2, alpha=0.5)
325
        ax[0].axvline(x=self.tmax_same, ymin=-1, ymax=+1, color="black", linewidth=2, alpha=0.5)
326
        ax[0].axvline(x=self.tmin_valid, ymin=-1, ymax=+1, color="cyan", linewidth=1, alpha=0.5)
327
        ax[0].axvline(x=self.tmax_valid, ymin=-1, ymax=+1, color="cyan", linewidth=1, alpha=0.5)
328
        ax[1].plot(tab, dtab, "b.")
329
        ax[1].set_ylabel("$dt_i$")
330
        # ax[1].grid()
331
        ax[1].axvline(x=self.tmin_full, ymin=-1, ymax=+1, color="red", linewidth=4, alpha=0.5)
332
        ax[1].axvline(x=self.tmax_full, ymin=-1, ymax=+1, color="red", linewidth=4, alpha=0.5)
333
        ax[1].axvline(x=self.tmin_same, ymin=-1, ymax=+1, color="black", linewidth=2, alpha=0.5)
334
        ax[1].axvline(x=self.tmax_same, ymin=-1, ymax=+1, color="black", linewidth=2, alpha=0.5)
335
        ax[1].axvline(x=self.tmin_valid, ymin=-1, ymax=+1, color="cyan", linewidth=1, alpha=0.5)
336
        ax[1].axvline(x=self.tmax_valid, ymin=-1, ymax=+1, color="cyan", linewidth=1, alpha=0.5)
337
338
        if rug is True:
339
            for t in self.times:
0 ignored issues
show
Coding Style Naming introduced by
Variable name "t" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
340
                ax[1].axvline(x=t, ymin=0, ymax=0.2, color="black", linewidth=0.8, alpha=1.0)
341
            # ax[1].plot(self.t, ax[1].get_ylim()[0]+np.zeros(self.t.size), 'k|', alpha=0.8, lw=1)
342
343
        ax[1].grid()
344
        # fig.show()
345
346
    def plot_signals(self, ax=None):
0 ignored issues
show
Coding Style Naming introduced by
Argument name "ax" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
347
        """Plots the signals involved in this correlation.
348
349
        Plots the signals involved in this correlation, in the same window
350
        but with different twin y-axes and different colors.
351
352
        Parameters
353
        ----------
354
        ax : :py:class:`~matplotlib.axes.Axes`
355
            Axes to be used for plotting.
356
        """
357
358
        # TODO: develop a plotting object for plots
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
359
        #       this will considerably shorten the
360
        #       number of attributes of this class
361
362
        if ax is None:
363
            ax = plt.gca()
364
365
        ax.plot(self.signal1.times, self.signal1.values, "b.-", lw=1, alpha=0.4)
366
        ax.tick_params(axis="y", labelcolor="b")
367
        ax.set_ylabel("sig 1", color="b")
368
369
        ax2 = ax.twinx()
370
        ax2.plot(self.signal2.times, self.signal2.values, "r.-", lw=1, alpha=0.4)
371
        ax2.tick_params(axis="y", labelcolor="r")
372
        ax2.set_ylabel("sig 2", color="r")
373