Passed
Pull Request — main (#21)
by Jose Enrique
01:53
created

mutis.correlation.Correlation.gen_corr()   F

Complexity

Conditions 20

Size

Total Lines 114
Code Lines 89

Duplication

Lines 18
Ratio 15.79 %

Importance

Changes 0
Metric Value
eloc 89
dl 18
loc 114
rs 0
c 0
b 0
f 0
cc 20
nop 3

How to fix   Long Method    Complexity   

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:

Complexity

Complex classes like mutis.correlation.Correlation.gen_corr() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

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
fkroedel was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
fwelsh was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
kroedel was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
welsh 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
        self.times = np.array([])
34
        self.dts = np.array([])
35
        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...
36
37
        # 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...
38
        self.samples = None
39
        self.l1s = None
40
        self.l2s = None
41
        self.l3s = None
42
        self.values = None
43
44
        t1, t2 = self.signal1.times, self.signal2.times
0 ignored issues
show
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...
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...
45
        self.tmin_full = t2.min() - t1.max()
46
        self.tmax_full = t2.max() - t1.min()
47
        self.t0_full = (self.tmax_full + self.tmin_full) / 2
48
        self.tmin_same = -(np.max([t1.max() - t1.min(), t2.max() - t2.min()])) / 2 + self.t0_full
49
        self.tmax_same = (np.max([t1.max() - t1.min(), t2.max() - t2.min()])) / 2 + self.t0_full
50
        self.tmin_valid = (
51
            -(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...
52
            / 2
53
            + self.t0_full
54
        )
55
        self.tmax_valid = (
56
            +(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...
57
            / 2
58
            + self.t0_full
59
        )
60
61
    def gen_synth(self, samples):
62
        """Generates the synthetic light curves.
63
64
        Generates the specified number `samples` of synthetic light
65
        curves for each signal, to be used to compute the significance
66
        the correlation.
67
68
        Parameters
69
        ----------
70
        samples : :py:class:`~int`
71
            Number of synthetic light curves to be generated for each signal.
72
        """
73
74
        self.samples = samples
75
        self.signal1.gen_synth(samples)
76
        self.signal2.gen_synth(samples)
77
78
    def gen_corr(self, uncert=True, dsamples=500):
79
        """Generates the correlation of the signals.
80
81
        Generates the correlation of the signals, and computes their
82
        confidence level from the synthetic light curves, which must
83
        have been generated before.
84
        """
85
86
        if (uncert is True) and (self.signal1.dvalues is None):
87
            log.error("uncert is True but no uncertainties for Signal 1 were specified")
88
            uncert = False
89
        if (uncert is True) and (self.signal2.dvalues is None):
90
            log.error("uncert is True but no uncertainties for Signal 2 were specified")
91
            uncert = False
92
93
        if not len(self.times) or not len(self.dts):
0 ignored issues
show
Unused Code introduced by
Do not use len(SEQUENCE) without comparison to determine if a sequence is empty
Loading history...
94
            raise Exception(
95
                "You need to define the times on which to calculate the correlation."
96
                "Please use gen_times() or manually set them."
97
            )
98
99
        # 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...
100
        mc_corr = np.empty((self.samples, self.times.size))
101
        mc_sig = np.empty((dsamples, self.times.size))
102
103
        if self.fcorr == "welsh_ab":
104
            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...
105
                mc_corr[n] = welsh_ab(
106
                    self.signal1.times,
107
                    self.signal1.synth[n],
108
                    self.signal2.times,
109
                    self.signal2.synth[n],
110
                    self.times,
111
                    self.dts,
112
                )
113 View Code Duplication
            if uncert is True:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
114
                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...
115
                    mc_sig[n] = welsh_ab(
116
                        self.signal1.times,
117
                        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...
118
                        self.signal2.times,
119
                        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...
120
                        self.times,
121
                        self.dts,
122
                    )
123
            self.values = welsh_ab(
124
                self.signal1.times,
125
                self.signal1.values,
126
                self.signal2.times,
127
                self.signal2.values,
128
                self.times,
129
                self.dts,
130
            )
131
        elif self.fcorr == "kroedel_ab":
132
            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...
133
                mc_corr[n] = kroedel_ab(
134
                    self.signal1.times,
135
                    self.signal1.synth[n],
136
                    self.signal2.times,
137
                    self.signal2.synth[n],
138
                    self.times,
139
                    self.dts,
140
                )
141 View Code Duplication
            if uncert is True:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
142
                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...
143
                    mc_sig[n] = kroedel_ab(
144
                        self.signal1.times,
145
                        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...
146
                        self.signal2.times,
147
                        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...
148
                        self.times,
149
                        self.dts,
150
                    )
151
            self.values = kroedel_ab(
152
                self.signal1.times,
153
                self.signal1.values,
154
                self.signal2.times,
155
                self.signal2.values,
156
                self.times,
157
                self.dts,
158
            )
159
        elif self.fcorr == "numpy":
160
            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...
161
                mc_corr[n] = nindcf(
162
                    self.signal1.times,
163
                    self.signal1.synth[n],
164
                    self.signal2.times,
165
                    self.signal2.synth[n],
166
                )
167
            if uncert is True:
168
                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...
169
                    mc_sig[n] = nindcf(
170
                        self.signal1.times,
171
                        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...
172
                        self.signal2.times,
173
                        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...
174
                    )
175
            self.values = nindcf(
176
                self.signal1.times,
177
                self.signal1.values,
178
                self.signal2.times,
179
                self.signal2.values,
180
            )
181
        else:
182
            raise Exception("Unknown method " + self.fcorr + " for correlation.")
183
184
        self.l3s = np.percentile(mc_corr, [0.135, 99.865], axis=0)
185
        self.l2s = np.percentile(mc_corr, [2.28, 97.73], axis=0)
186
        self.l1s = np.percentile(mc_corr, [15.865, 84.135], axis=0)
187
188
        if uncert is True:
189
            self.s3s = np.percentile(mc_sig, [0.135, 99.865], axis=0)
0 ignored issues
show
Coding Style introduced by
The attribute s3s was defined outside __init__.

It is generally a good practice to initialize all attributes to default values in the __init__ method:

class Foo:
    def __init__(self, x=None):
        self.x = x
Loading history...
190
            self.s2s = np.percentile(mc_sig, [2.28, 97.73], axis=0)
0 ignored issues
show
Coding Style introduced by
The attribute s2s was defined outside __init__.

It is generally a good practice to initialize all attributes to default values in the __init__ method:

class Foo:
    def __init__(self, x=None):
        self.x = x
Loading history...
191
            self.s1s = np.percentile(mc_sig, [15.865, 84.135], axis=0)
0 ignored issues
show
Coding Style introduced by
The attribute s1s was defined outside __init__.

It is generally a good practice to initialize all attributes to default values in the __init__ method:

class Foo:
    def __init__(self, x=None):
        self.x = x
Loading history...
192
193
    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...
194
        """Sets times and bins using the method defined by ftimes parameter.
195
196
        Parameters
197
        ----------
198
        ftimes : :py:class:`~str`
199
            Method used to bin the time interval of the correlation.
200
            Possible values are:
201
            - "canopy": Computes a binning as dense as possible, with
202
            variable bin width and (with a minimum and a maximum
203
            resolution) and a minimum statistic.
204
            - "rawab": Computes a binning with variable bin width,
205
            a given step, maximum bin size and a minimum statistic.
206
            - "uniform": Computes a binning with uniform bin width
207
            and a minimum statistic.
208
            - "numpy": Computes a binning suitable for method='numpy'.
209
        """
210
        if ftimes == "canopy":
211
            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...
212
        elif ftimes == "rawab":
213
            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...
214
        elif ftimes == "uniform":
215
            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...
216
        elif ftimes == "numpy":
217
            t1, t2 = self.signal1.times, self.signal1.times
0 ignored issues
show
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...
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...
218
            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...
219
            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...
220
            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...
221
            self.times = np.linspace(self.tmin_full, self.tmax_full, n1 + n2 - 1)
222
            self.dts = np.full(self.times.size, (self.tmax_full - self.tmin_full) / (n1 + n2))
223
        else:
224
            raise Exception("Unknown method " + ftimes + ", please indicate how to generate times.")
225
226
    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...
227
        """Plots the correlation of the signals.
228
229
        Plots the correlation of the signal, and the confidence limits
230
        computed from the synthetic curves.
231
232
        Parameters
233
        ----------
234
        ax : :class:`matplotlib.axes.Axes`
235
            Axes to be used (default None, it creates a new axes).
236
        legend : :py:class:`~bool`
237
            Whether to add a legend indicating the confidence levels.
238
        """
239
240
        # 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...
241
        #       this will considerably shorten the
242
        #       number of attributes of this class
243
244
        # plt.figure()
245
        if ax is None:
246
            ax = plt.gca()
247
248
        ax.plot(self.times, self.l1s[0], "c-.")
249
        ax.plot(self.times, self.l1s[1], "c-.", label=r"$1\sigma$")
250
        ax.plot(self.times, self.l2s[0], "k--")
251
        ax.plot(self.times, self.l2s[1], "k--", label=r"$2\sigma$")
252
        ax.plot(self.times, self.l3s[0], "r-")
253
        ax.plot(self.times, self.l3s[1], "r-", label=r"$3\sigma$")
254
        ax.plot(self.times, self.values, "b.--", lw=1)
255
256
        # full limit
257
        ax.axvline(x=self.tmin_full, ymin=-1, ymax=+1, color="red", linewidth=4, alpha=0.5)
258
        ax.axvline(x=self.tmax_full, ymin=-1, ymax=+1, color="red", linewidth=4, alpha=0.5)
259
        # same limit
260
        ax.axvline(x=self.tmin_same, ymin=-1, ymax=+1, color="black", linewidth=2, alpha=0.5)
261
        ax.axvline(x=self.tmax_same, ymin=-1, ymax=+1, color="black", linewidth=2, alpha=0.5)
262
        # valid limit
263
        ax.axvline(x=self.tmin_valid, ymin=-1, ymax=+1, color="cyan", linewidth=1, alpha=0.5)
264
        ax.axvline(x=self.tmax_valid, ymin=-1, ymax=+1, color="cyan", linewidth=1, alpha=0.5)
265
266
267
        if uncert is True:
268
            ax.fill_between(x=self.times, y1=self.s1s[0], y2=self.s1s[1], color="b", alpha=0.5)
269
            ax.fill_between(x=self.times, y1=self.s2s[0], y2=self.s2s[1], color="b", alpha=0.3)
270
            ax.fill_between(x=self.times, y1=self.s3s[0], y2=self.s3s[1], color="b", alpha=0.1)
271
272
        if legend:
273
            ax.legend()
274
275
        # plt.show()
276
        return ax
277
278
    def plot_times(self, rug=False):
279
        """Plots the time binning generated previously.
280
281
        Plots the number of total bins, their distribution and the
282
        number of points in each bin for the generated time binning,
283
        previously generated with Correlation().gen_times(...).
284
285
        Parameters
286
        ----------
287
        rug : :py:class:`~bool`
288
            Whether to make a rug plot just below the binning, to make
289
            it easier to visually understand the density and distribution
290
            of the generated bins.
291
292
        """
293
294
        # 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...
295
        #       this will considerably shorten the
296
        #       number of attributes of this class
297
298
        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...
299
        tab, dtab, nab = self.times, self.dts, self.nb
300
301
        fig.suptitle("Total bins: {:d}".format(self.times.size))
302
        ax[0].plot(tab, nab, "b.")
303
        ax[0].errorbar(x=tab, y=nab, xerr=dtab / 2, fmt="none")
304
        ax[0].set_ylabel("$n_i$")
305
        ax[0].grid()
306
        ax[0].axvline(x=self.tmin_full, ymin=-1, ymax=+1, color="red", linewidth=4, alpha=0.5)
307
        ax[0].axvline(x=self.tmax_full, ymin=-1, ymax=+1, color="red", linewidth=4, alpha=0.5)
308
        ax[0].axvline(x=self.tmin_same, ymin=-1, ymax=+1, color="black", linewidth=2, alpha=0.5)
309
        ax[0].axvline(x=self.tmax_same, ymin=-1, ymax=+1, color="black", linewidth=2, alpha=0.5)
310
        ax[0].axvline(x=self.tmin_valid, ymin=-1, ymax=+1, color="cyan", linewidth=1, alpha=0.5)
311
        ax[0].axvline(x=self.tmax_valid, ymin=-1, ymax=+1, color="cyan", linewidth=1, alpha=0.5)
312
        ax[1].plot(tab, dtab, "b.")
313
        ax[1].set_ylabel("$dt_i$")
314
        # ax[1].grid()
315
        ax[1].axvline(x=self.tmin_full, ymin=-1, ymax=+1, color="red", linewidth=4, alpha=0.5)
316
        ax[1].axvline(x=self.tmax_full, ymin=-1, ymax=+1, color="red", linewidth=4, alpha=0.5)
317
        ax[1].axvline(x=self.tmin_same, ymin=-1, ymax=+1, color="black", linewidth=2, alpha=0.5)
318
        ax[1].axvline(x=self.tmax_same, ymin=-1, ymax=+1, color="black", linewidth=2, alpha=0.5)
319
        ax[1].axvline(x=self.tmin_valid, ymin=-1, ymax=+1, color="cyan", linewidth=1, alpha=0.5)
320
        ax[1].axvline(x=self.tmax_valid, ymin=-1, ymax=+1, color="cyan", linewidth=1, alpha=0.5)
321
322
        if rug is True:
323
            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...
324
                ax[1].axvline(x=t, ymin=0, ymax=0.2, color="black", linewidth=0.8, alpha=1.0)
325
            # ax[1].plot(self.t, ax[1].get_ylim()[0]+np.zeros(self.t.size), 'k|', alpha=0.8, lw=1)
326
327
        ax[1].grid()
328
        # fig.show()
329
330
    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...
331
        """Plots the signals involved in this correlation.
332
333
        Plots the signals involved in this correlation, in the same window
334
        but with different twin y-axes and different colors.
335
336
        Parameters
337
        ----------
338
        ax : :py:class:`~matplotlib.axes.Axes`
339
            Axes to be used for plotting.
340
        """
341
342
        # 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...
343
        #       this will considerably shorten the
344
        #       number of attributes of this class
345
346
        if ax is None:
347
            ax = plt.gca()
348
349
        ax.plot(self.signal1.times, self.signal1.values, "b.-", lw=1, alpha=0.4)
350
        ax.tick_params(axis="y", labelcolor="b")
351
        ax.set_ylabel("sig 1", color="b")
352
353
        ax2 = ax.twinx()
354
        ax2.plot(self.signal2.times, self.signal2.values, "r.-", lw=1, alpha=0.4)
355
        ax2.tick_params(axis="y", labelcolor="r")
356
        ax2.set_ylabel("sig 2", color="r")
357