Passed
Pull Request — main (#26)
by
unknown
02:12
created

mutis.signal.Signal.check_gen()   B

Complexity

Conditions 5

Size

Total Lines 76
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 32
dl 0
loc 76
rs 8.6453
c 0
b 0
f 0
cc 5
nop 5

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
"""Synthetic generation 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
import scipy.optimize as scipy_optimize
0 ignored issues
show
introduced by
Unable to import 'scipy.optimize'
Loading history...
9
import scipy.signal as scipy_signal
0 ignored issues
show
introduced by
Unable to import 'scipy.signal'
Loading history...
10
import scipy.special as scipy_special
0 ignored issues
show
introduced by
Unable to import 'scipy.special'
Loading history...
11
import scipy.stats as scipy_stats
0 ignored issues
show
introduced by
Unable to import 'scipy.stats'
Loading history...
12
from matplotlib.offsetbox import AnchoredText
0 ignored issues
show
introduced by
Unable to import 'matplotlib.offsetbox'
Loading history...
13
14
from mutis.lib.signal import *
0 ignored issues
show
Coding Style introduced by
The usage of wildcard imports like mutis.lib.signal should generally be avoided.
Loading history...
Unused Code introduced by
nfft was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
lc_gen_psd_fft was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
lc_gen_psd_nft was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
lc_gen_psd_c was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
lc_gen_ou was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
lc_gen_samp was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
lc_gen_psd_lombscargle was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
jit was imported with wildcard, but is not used.
Loading history...
15
16
__all__ = ["Signal"]
17
18
log = logging.getLogger(__name__)
19
20
21
class Signal:
0 ignored issues
show
best-practice introduced by
Too many instance attributes (8/7)
Loading history...
22
    """Analysis and generation of a signal.
23
24
    Description goes here.
25
26
    Parameters
27
    ----------
28
    times : :class:`numpy.ndarray` or :class:`pandas.Series`
29
        Values of the time axis.
30
    values : :class:`numpy.ndarray` or :class:`pandas.Series`
31
        Values of the signal axis.
32
    fgen : :class:`str`
33
        Method used to generate the synthetic signal.
34
    """
35
36
    def __init__(self, times, values, dvalues=None, fgen=None):
37
        self.times = np.array(times)
38
        self.values = np.array(values)
39
        self.fgen = fgen
40
41
        self.dvalues = np.array(dvalues) if dvalues is not None else None
42
        self.synth = None
43
44
        # TODO make attributes below specific of OU method / not the entire class
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
45
        self.OU_theta = None
0 ignored issues
show
Coding Style Naming introduced by
Attribute name "OU_theta" 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...
46
        self.OU_mu = None
0 ignored issues
show
Coding Style Naming introduced by
Attribute name "OU_mu" 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...
47
        self.OU_sigma = None
0 ignored issues
show
Coding Style Naming introduced by
Attribute name "OU_sigma" 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...
48
49
    def plot(self, ax=None):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
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...
50
        if ax is None:
51
            ax = plt.gca()
52
        return ax.plot(self.times, self.values, ".-", lw=1, alpha=0.7)
53
54
    def gen_synth(self, samples):
55
        """Description goes here."""
56
57
        self.synth = np.empty((samples, self.times.size))
58
        for n in range(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...
59
            self.synth[n] = fgen_wrapper(fgen=self.fgen, t=self.times, y=self.values,
60
                         fgen_params={'theta':self.OU_theta, 'mu':self.OU_mu, 'sigma':self.OU_sigma})
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (101/100).

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

Loading history...
Coding Style introduced by
Wrong continued indentation (add 16 spaces).
Loading history...
61
62
63
    def OU_fit(self, bins=None, rang=None, a=1e-5, b=100):
0 ignored issues
show
Coding Style Naming introduced by
Method name "OU_fit" 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...
Comprehensibility introduced by
This function exceeds the maximum number of variables (20/15).
Loading history...
Coding Style Naming introduced by
Argument name "b" 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
Argument name "a" 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...
64
        """Fit the signal to an OU stochastic process, using several statistical approaches.
65
66
        This function tries to fit the signal to an OU stochastic
67
        process using both basic curve fitting and the Maximum
68
        Likelihood Estimation method, and returns some plots of
69
        the signals and its properties, and the estimated parameters.
70
        """
71
72
        # TODO: make a generic fit method
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
73
        res = dict()
74
75
        y = self.values
0 ignored issues
show
Coding Style Naming introduced by
Variable name "y" 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...
76
        t = 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...
77
78
        dy = np.diff(y)
0 ignored issues
show
Coding Style Naming introduced by
Variable name "dy" 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...
79
        dt = np.diff(t)
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...
80
81
        # estimate sigma
82
        try:
83
            sigma_est = (np.nanmean(dy ** 2 / y[:-1] ** 2 / dt)) ** 0.5
84
            res["sigma_est"] = sigma_est
85
        except Exception as e:
0 ignored issues
show
Coding Style Naming introduced by
Variable name "e" 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...
Best Practice introduced by
Catching very general exceptions such as Exception is usually not recommended.

Generally, you would want to handle very specific errors in the exception handler. This ensure that you do not hide other types of errors which should be fixed.

So, unless you specifically plan to handle any error, consider adding a more specific exception.

Loading history...
86
            log.error(f"Could not estimate sigma: {e}")
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
87
88
        # plot histogram
89
        if bins is None:
90
            bins = np.int(y.size ** 0.5 / 1.5)  # bins='auto'
91
        if rang is None:
92
            rang = (np.percentile(y, 0), np.percentile(y, 99))
93
94
        p, x = np.histogram(y, density=True, bins=bins, range=rang)  # bins='sqrt')
0 ignored issues
show
Coding Style Naming introduced by
Variable name "p" 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 "x" 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...
95
        x = (x + np.roll(x, -1))[:-1] / 2.0
0 ignored issues
show
Coding Style Naming introduced by
Variable name "x" 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...
96
97
        plt.subplots()
98
99
        plt.hist(y, density=True, alpha=0.75, bins=bins, range=rang)
100
        plt.plot(x, p, "r-", alpha=0.5)
101
102
        anchored_text = AnchoredText(
103
            f"mean    {np.mean(y):.2g} \n "
104
            f"median  {np.median(y):.2g} \n "
105
            f"mode    {scipy_stats.mode(y)[0][0]:.2g} \n "
106
            f"std     {np.std(y):.2g} \n "
107
            f"var     {np.var(y):.2g}",
108
            loc="upper right",
109
        )
110
        plt.gca().add_artist(anchored_text)
111
112
        # curve_fit
113
        try:
114
            popt, pcov = scipy_optimize.curve_fit(f=self.pdf, xdata=x, ydata=p)
115
            # print('curve_fit: (l, mu)')
116
            # print('popt: ')
117
            # print(popt)
118
            # print('pcov: ')
119
            # print(np.sqrt(np.diag(pcov)))
120
            x_c = np.linspace(1e-5, 1.1 * np.max(x), 1000)
121
            plt.plot(x_c, self.pdf(x_c, *popt), "k-", label="curve_fit", alpha=0.8)
122
            res["curve_fit"] = (popt, np.sqrt(np.diag(pcov)))
123
        except Exception as e:
0 ignored issues
show
Coding Style Naming introduced by
Variable name "e" 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...
Best Practice introduced by
Catching very general exceptions such as Exception is usually not recommended.

Generally, you would want to handle very specific errors in the exception handler. This ensure that you do not hide other types of errors which should be fixed.

So, unless you specifically plan to handle any error, consider adding a more specific exception.

Loading history...
124
            log.error(f"Some error fitting with curve_fit {e}")
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
125
126
        # fit pdf with MLE
127
        # TODO: place outside as a helper class
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
128
        #       mu here is different than self.mu
129
        class OU(scipy_stats.rv_continuous):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
130
            def _pdf(self, x, l, mu):
0 ignored issues
show
Coding Style Naming introduced by
Argument name "x" 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 introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
Coding Style Naming introduced by
Argument name "l" 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
Argument name "mu" 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...
131
                return (
132
                    (l * mu) ** (1 + l)
133
                    / scipy_special.gamma(1 + l)
134
                    * np.exp(-l * mu / x)
135
                    / x ** (l + 2)
136
                )
137
138
        try:
139
            fit = OU(a=a, b=np.percentile(y, b)).fit(y, 1, 1, floc=0, fscale=1)
140
            # print('MLE fit: (l, mu)')
141
            # print(fit)
142
            x_c = np.linspace(0, 1.1 * np.max(x), 1000)
143
            plt.plot(x_c, self.pdf(x_c, fit[0], fit[1]), "k-.", label="MLE", alpha=0.8)
144
            res["MLE_fit"] = fit[:-2]
145
        except Exception as e:
0 ignored issues
show
Best Practice introduced by
Catching very general exceptions such as Exception is usually not recommended.

Generally, you would want to handle very specific errors in the exception handler. This ensure that you do not hide other types of errors which should be fixed.

So, unless you specifically plan to handle any error, consider adding a more specific exception.

Loading history...
Coding Style Naming introduced by
Variable name "e" 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...
146
            log.error(f"Some error fitting with MLE {e}")
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
147
148
        plt.legend(loc="lower right")
149
        # plt.show()
150
151
        # estimate theta (from curve_fit)
152
        try:
153
            res["th_est1"] = fit[0] * sigma_est ** 2 / 2
154
        except NameError as e:
0 ignored issues
show
Coding Style Naming introduced by
Variable name "e" 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...
155
            res["th_est1"] = None
156
157
        # estimate theta (from MLE)
158
        try:
159
            res["th_est2"] = popt[0] * sigma_est ** 2 / 2
160
        except NameError as e:
0 ignored issues
show
Coding Style Naming introduced by
Variable name "e" 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
            res["th_est2"] = None
162
163
        return res
164
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
165
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
166
    def check_gen(self, fgen=None, fgen_params=None, fpsd="lombscargle", **axes):
0 ignored issues
show
Comprehensibility introduced by
This function exceeds the maximum number of variables (16/15).
Loading history...
167
        """Check the generation of synthetic signals.
168
169
        This function checks the generation of a synthetic light curve.
170
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
171
        Parameters:
172
        -----------
173
        fgen: :str:
174
            A valid fgen method name.
175
        fgen_params: :dict:
176
            Parameters for fgen (e.g. for fgen='lc_gen_ou', a dict containing
177
            values for theta, mu and sigma).
178
179
        Returns:
180
        --------
181
        axes: :tuple:
182
            Tuple of three axes, on which:
183
            - The first plot show both the original signal and the synthetic one.
184
            - The second plot shows the histogram of the values taken by both signals.
185
            - The third plot shows their PSD.
186
        """
187
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
188
        t, y = self.times, self.values
0 ignored issues
show
Coding Style Naming introduced by
Variable name "y" 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 "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...
189
190
        y2 = fgen_wrapper(fgen=fgen, t=t, y=y, fgen_params=fgen_params)
0 ignored issues
show
Coding Style Naming introduced by
Variable name "y2" 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...
191
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
192
        print(f"Original vs Synthethic:",
0 ignored issues
show
introduced by
Using an f-string that does not have any interpolated variables
Loading history...
193
              f"mean: {np.mean(y)} / {np.mean(y2)}",
194
              f"std: {np.std(y)} / {np.std(y2)}", sep='\n')
195
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
196
        if ("ax1" not in axes) or ("ax2" not in axes) or ("ax3" not in axes):
197
            fig, (axes["ax1"], axes["ax2"], axes["ax3"]) = plt.subplots(
0 ignored issues
show
Unused Code introduced by
The variable fig seems to be unused.
Loading history...
198
                nrows=1, ncols=3, figsize=(20, 4)
199
            )
200
201
        # plot the two signals
202
        axes["ax1"].plot(t, y, "b-", label="orig", lw=0.5, alpha=0.8)
203
204
        # ax1p = ax1.twinx()
205
        axes["ax1"].plot(t, y2, "r-", label="gen", lw=0.5, alpha=0.8)
206
        axes["ax1"].set_title("light curves")
207
208
        # plot their histogram
209
        bins = "auto"  # bins = np.int(y.size**0.5/1.5) #
210
        rang = (np.percentile(y, 0), np.percentile(y, 99))
211
        axes["ax2"].hist(y, density=True, color="b", alpha=0.4, bins=bins, range=rang)
212
213
        # ax2p = ax2.twinx()
214
        bins = "auto"  # bins = np.int(y.size**0.5/1.5) #
215
        rang = (np.percentile(y2, 0), np.percentile(y2, 99))
216
        axes["ax2"].hist(y2, density=True, color="r", alpha=0.4, bins=bins, range=rang)
217
218
        axes["ax2"].set_title("pdf")
219
220
        # plot their PSD
221
        if fpsd == "lombscargle":
222
            k = np.linspace(1e-3, self.values.size / 2, self.values.size // 2)
223
            freqs = k / 2 / np.pi
224
225
            pxx = scipy_signal.lombscargle(t, y, freqs, normalize=True)
226
            axes["ax3"].plot(freqs, pxx, "b-", lw=1, alpha=0.5)
227
228
            pxx2 = scipy_signal.lombscargle(t, y2, freqs, normalize=True)
229
            axes["ax3"].plot(freqs, pxx2, "r-", lw=1, alpha=0.5)
230
231
            axes["ax3"].set_xscale("log")
232
            # ax3.set_yscale('log')
233
        else:
234
            axes["ax3"].psd(y, color="b", lw=1, alpha=0.5)
235
236
            ax3p = axes["ax3"].twinx()
237
            ax3p.psd(y2, color="r", lw=1, alpha=0.5)
238
239
        axes["ax3"].set_title("PSD")
240
241
        return axes
242
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
243
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
244
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
245
    @staticmethod
246
    def pdf(xx, ll, mu):
0 ignored issues
show
Coding Style Naming introduced by
Argument name "mu" 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
Argument name "ll" 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
Argument name "xx" 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...
247
        """Helper func to fit pdf as a curve."""
248
        return (
249
            (ll * mu) ** (1 + ll)
250
            / scipy_special.gamma(1 + ll)
251
            * np.exp(-ll * mu / xx)
252
            / xx ** (ll + 2)
253
        )
254