Passed
Pull Request — main (#25)
by
unknown
01:58
created

mutis.astro   F

Complexity

Total Complexity 132

Size/Duplication

Total Lines 1131
Duplicated Lines 11.23 %

Importance

Changes 0
Metric Value
wmc 132
eloc 594
dl 127
loc 1131
rs 2
c 0
b 0
f 0

10 Functions

Rating   Name   Duplication   Size   Complexity  
F KnotsIdAuto() 0 115 20
A pol_angle_reshape() 0 20 4
A get_output() 0 16 2
B KnotsIdReadMod_from_diffmap() 0 60 5
A KnotsIdReadCSV() 0 44 4
F KnotsId2dGUI() 64 305 42
C KnotsIdSaveMod() 0 84 11
F KnotsIdGUI() 63 250 31
A KnotsIdSaveCSV() 0 46 3
B KnotsIdReadMod() 0 80 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A plain_printer.clear_output() 0 3 1
A plain_printer.append_stdout() 0 3 1
A plain_printer.display_output() 0 3 1

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complexity

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like mutis.astro 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
0 ignored issues
show
coding-style introduced by
Too many lines in module (1130/1000)
Loading history...
2
"""Utils specific to the field of astrophysics"""
3
4
import logging
5
6
import numpy as np
0 ignored issues
show
introduced by
Unable to import 'numpy'
Loading history...
7
import pandas as pd
0 ignored issues
show
introduced by
Unable to import 'pandas'
Loading history...
8
9
import matplotlib as mplt
0 ignored issues
show
introduced by
Unable to import 'matplotlib'
Loading history...
Unused Code introduced by
Unused matplotlib imported as mplt
Loading history...
10
import matplotlib.pyplot as plt
0 ignored issues
show
introduced by
Unable to import 'matplotlib.pyplot'
Loading history...
11
12
import glob
0 ignored issues
show
introduced by
standard import "import glob" should be placed before "import numpy as np"
Loading history...
13
import re
0 ignored issues
show
introduced by
standard import "import re" should be placed before "import numpy as np"
Loading history...
14
from datetime import datetime
0 ignored issues
show
introduced by
standard import "from datetime import datetime" should be placed before "import numpy as np"
Loading history...
15
16
from astropy.time import Time
0 ignored issues
show
introduced by
Unable to import 'astropy.time'
Loading history...
17
18
19
#__all__ = ["Astro"]
20
21
log = logging.getLogger(__name__)
22
23
# TODO: to be able to save previous labels in _mod.mod and be kepto after processing with diffmap
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
24
25
#############################################################################
26
### Output compatible with IPython widgets and with plain python console: ###
27
#
28
# With this we can follow follow a commen scheme:
29
#
30
# def someGUIfunction():
31
#     out = get_output()
32
#     ... gui things...
33
#         out.clear_output()
34
#         out.append_stdout('some msg')
35
#     out.display_output()
36
#
37
class plain_printer:
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
Coding Style Naming introduced by
Class name "plain_printer" doesn't conform to PascalCase naming style ('[^\\W\\da-z][^\\W_]+$' 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...
38
    @staticmethod
39
    def append_stdout(msg):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
40
        print(msg, end='')
41
    @staticmethod
42
    def clear_output():
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
43
        print('\n')
44
    @staticmethod
45
    def display_output():
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
46
        pass
47
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
48
def get_output():
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
49
    try:
50
        get_ipython().__class__.__name__
0 ignored issues
show
Unused Code Bug introduced by
The expression get_ipython().__class__.__name__ does not seem to have sideeffects and its result is not used.

If a expression has no sideeffects (any lasting effect after it has been called) and its return value is not used, this usually means that this code can be removed or that an assignment is missing.

Loading history...
Comprehensibility Best Practice introduced by
Undefined variable 'get_ipython'
Loading history...
Comprehensibility Best Practice introduced by
The variable get_ipython does not seem to be defined.
Loading history...
51
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
52
        import ipywidgets
0 ignored issues
show
introduced by
Import outside toplevel (ipywidgets)
Loading history...
introduced by
Unable to import 'ipywidgets'
Loading history...
53
        class pretty_printer(ipywidgets.Output):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
Coding Style Naming introduced by
Class name "pretty_printer" doesn't conform to PascalCase naming style ('[^\\W\\da-z][^\\W_]+$' 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...
54
            def __init__(self, *args, **kwargs):
0 ignored issues
show
introduced by
Useless super delegation in method '__init__'
Loading history...
55
                super().__init__(*args, **kwargs)
56
            def display_output(self):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
57
                display(self)
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'display'
Loading history...
Comprehensibility Best Practice introduced by
The variable display does not seem to be defined.
Loading history...
58
                
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
59
        out = pretty_printer(layout={'border': '1px solid black'})
60
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
61
        return out
62
    except:
0 ignored issues
show
Coding Style Best Practice introduced by
General except handlers without types should be used sparingly.

Typically, you would use general except handlers when you intend to specifically handle all types of errors, f.e. when logging. Otherwise, such general error handlers can mask errors in your application that you want to know of.

Loading history...
63
        return plain_printer
64
#############################################################################
65
   
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
66
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
67
def pol_angle_reshape(s):
0 ignored issues
show
Coding Style Naming introduced by
Argument name "s" 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...
68
    """
69
        Reshape a signal as a polarization angle: shifting by 180 degrees in a way it varies as smoothly as possible.
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...
70
    """
71
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
72
    s = np.array(s)
73
    s = np.mod(s,180) # s % 180
0 ignored issues
show
Coding Style introduced by
Exactly one space required after comma
Loading history...
74
75
    sn = np.empty(s.shape)
0 ignored issues
show
Coding Style Naming introduced by
Variable name "sn" 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
    for i in range(1,len(s)):
0 ignored issues
show
Coding Style introduced by
Exactly one space required after comma
Loading history...
77
        #if t[i]-t[i-1] < 35:
78
        d = 181
0 ignored issues
show
Coding Style Naming introduced by
Variable name "d" 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
        n = 0
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...
80
        for m in range(0,100):
0 ignored issues
show
Coding Style Naming introduced by
Variable name "m" 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
Exactly one space required after comma
Loading history...
81
            m2 = (-1)**(m+1)*np.floor((m+1)/2)
0 ignored issues
show
Coding Style Naming introduced by
Variable name "m2" 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...
82
            if np.abs(s[i]+180*m2-sn[i-1]) < d:
83
                d = np.abs(s[i]+180*m2-sn[i-1])
0 ignored issues
show
Coding Style Naming introduced by
Variable name "d" 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...
84
                n = m2
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...
85
        sn[i] = s[i]+180*n
86
    return sn 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
87
88
89
90
91
92
93
###########################################################################
94
################################## Knots ##################################
95
###########################################################################
96
97
98
99
def  KnotsIdAuto(mod):
0 ignored issues
show
Coding Style Naming introduced by
Function name "KnotsIdAuto" 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 (18/15).
Loading history...
100
    """
101
       Identify the knots appearing in several epochs giving them names, based on their position.
102
       
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
103
        Parameters:
104
        -----------
105
         mod : :pd.DataFrame:
106
             pandas.DataFrame containing every knot, with 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
107
             at least columns 'label', 'date', 'X', 'Y', 'Flux (Jy)'.
108
       
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
109
        Returns: mod
110
        --------
111
         mod : :pd.DataFrame:
112
             pandas.DataFrame containing every knot with their altered labels, with 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
113
             at least columns 'label', 'date', 'X', 'Y', 'Flux (Jy)'.
114
         
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
115
    """
116
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
117
    mod_date_dict = dict(list((mod.groupby('date'))))
118
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
119
    mod_dates = list(Time(list(mod_date_dict.keys())).datetime)
120
    mod_dates_str = list(Time(list(mod_date_dict.keys())).strftime('%Y-%m-%d'))
121
    mod_data = list(mod_date_dict.values())
122
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
123
    Bx = [[]]*len(mod_dates)
0 ignored issues
show
Coding Style Naming introduced by
Variable name "Bx" 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
    By = [[]]*len(mod_dates)
0 ignored issues
show
Coding Style Naming introduced by
Variable name "By" 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...
125
    B = [[]]*len(mod_dates)
0 ignored issues
show
Coding Style Naming introduced by
Variable 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...
126
127
128
    thresh = 0.03 #0.062
129
130
    news = 0
131
132
    for i, (date, data) in enumerate(zip(mod_dates, mod_data)):
0 ignored issues
show
Unused Code introduced by
The variable date seems to be unused.
Loading history...
unused-code introduced by
Too many nested blocks (6/5)
Loading history...
133
        log.debug(f'Analysing epoch i {i:3d} ({mod_dates_str[i]})')
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
134
135
        if not len(data.index) > 0:
136
            log.error(' -> Error, no components found')
137
            break
138
139
        log.debug(f' it has {len(data.index)} components')
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
140
141
        Bx[i] = np.ravel(data['X'])
142
        By[i] = np.ravel(data['Y'])
143
        B[i] = np.full(len(data.index), fill_value=None)
144
145
        # if first epoch, just give them new names...:
146
        if i == 0:
147
            log.debug(' first epoch, giving names...')
148
149
            for n in range(0,len(mod_data[i].index)):
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...
Coding Style introduced by
Exactly one space required after comma
Loading history...
150
                if data['Flux (Jy)'].iloc[n] < 0.001:
151
                    log.debug('  skipping, too weak')
152
                    break
153
                if n == 0:
154
                    B[i][n] = 'A0'
155
                else:
156
                    news = news + 1
157
                    B[i][n] = f'B{news}'
158
            log.debug(f' -> FOUND: {B[i]}\n')
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
159
            continue
160
161
        # if not first epoch...:
162
163
        for n in range(0,len(mod_data[i].index)):
0 ignored issues
show
Coding Style introduced by
Exactly one space required after comma
Loading history...
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...
164
            if data['Flux (Jy)'].iloc[n] < 0.001:
165
                    log.debug('  skipping, too weak')
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 16 spaces were expected, but 20 were found.
Loading history...
166
                    break
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 16 spaces were expected, but 20 were found.
Loading history...
167
            if n == 0:
168
                B[i][n] = 'A0'
169
            else:
170
                log.debug(f' -> id component {n}...')
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
171
172
                close = None
173
174
                a = 0
0 ignored issues
show
Coding Style Naming introduced by
Variable 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...
175
                while ( i - a >= 0 and a < 4 and close is None):
0 ignored issues
show
Coding Style introduced by
No space allowed after bracket
Loading history...
176
                    a = a + 1
0 ignored issues
show
Coding Style Naming introduced by
Variable 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...
177
178
                    if not len(Bx[i-a])>0:
0 ignored issues
show
Coding Style introduced by
Exactly one space required around comparison
Loading history...
179
                        break
180
181
                    dist = ( (Bx[i-a]-Bx[i][n]) ** 2 + (By[i-a]-By[i][n]) ** 2 ) ** 0.5
0 ignored issues
show
Coding Style introduced by
No space allowed after bracket
Loading history...
Coding Style introduced by
No space allowed before bracket
Loading history...
182
183
                    for m in range(len(dist)):
0 ignored issues
show
Coding Style Naming introduced by
Variable name "m" 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...
unused-code introduced by
Consider using enumerate instead of iterating with range and len
Loading history...
184
                        if B[i-a][m] in B[i]:
185
                            dist[m] = np.inf
186
187
                    if np.amin(dist) < thresh*a**1.5:
188
                        close = np.argmin(dist)
189
190
                    if B[i-a][close] in B[i]:
191
                            close = None
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 24 spaces were expected, but 28 were found.
Loading history...
192
193
194
                if close is None:
195
                    news = news + 1
196
                    B[i][n] = f'B{news}'
197
                    log.debug(f'   component {n} is new, naming it {B[i][n]}')
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
198
                else:
199
                    log.debug(f'   component {n} is close to {B[i-a][close]} of previous epoch ({a} epochs before)')
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
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...
200
                    B[i][n] = B[i-a][close]
201
202
203
        log.debug(f' -> FOUND: {B[i]}\n')
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
204
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
205
                 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
206
    for i, (date, data) in enumerate(zip(mod_dates, mod_data)):
207
        data['label'] = B[i]
208
         
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
209
    mod = pd.concat(mod_data, ignore_index=True)
210
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
211
    log.debug('Finito!')
212
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
213
    return mod
214
215
216
217
218
############################################
219
############## Knots 2D GUI ################
220
############################################
221
222
def KnotsId2dGUI(mod, twidth=0.75, use_arrows=False, arrow_pos=1.0):
0 ignored issues
show
Comprehensibility introduced by
This function exceeds the maximum number of variables (35/15).
Loading history...
Coding Style Naming introduced by
Function name "KnotsId2dGUI" 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...
223
    """
224
        Prompt a GUI to select identified knots and alter their label, reprenting their 2D
225
        spatial distribution in different times.
226
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
227
        It can be used inside jupyter notebooks, using '%matplotlib widget' first.
228
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
229
        Parameters:
230
        -----------
231
         mod : :pd.DataFrame:
232
             pandas.DataFrame containing every knot, with at least columns 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
233
             'label', 'date', 'X', 'Y', 'Flux (Jy)'.
234
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
235
        Returns:
236
        --------
237
         mod : :pd.DataFrame:
238
             pandas.DataFrame containing every knot with their altered labels, with 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
239
             at least columns 'label', 'date', 'X', 'Y', 'Flux (Jy)'.
240
    """
241
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
242
    mod = mod.copy()
243
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
244
    knots = dict(tuple(mod.groupby('label')))
245
    knots_names = list(knots.keys())
246
    knots_values = list(knots.values())
247
    knots_jyears = {k:Time(knots[k]['date'].to_numpy()).jyear for k in knots}
248
    knots_X = {k:knots[k]['X'].to_numpy() for k in knots}
0 ignored issues
show
Coding Style Naming introduced by
Variable name "knots_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...
249
    knots_Y = {k:knots[k]['Y'].to_numpy() for k in knots}
0 ignored issues
show
Coding Style Naming introduced by
Variable name "knots_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...
250
251
252
    from matplotlib.widgets import Slider, Button, TextBox, RectangleSelector
0 ignored issues
show
Unused Code introduced by
Unused Button imported from matplotlib.widgets
Loading history...
introduced by
Unable to import 'matplotlib.widgets'
Loading history...
introduced by
Import outside toplevel (matplotlib.widgets.Slider, matplotlib.widgets.Button, matplotlib.widgets.TextBox, matplotlib.widgets.RectangleSelector)
Loading history...
253
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
254
    out = get_output()
255
256
    fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(8,8))
0 ignored issues
show
Coding Style introduced by
Exactly one space required after comma
Loading history...
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...
257
258
    lineas = list()
259
    flechas = list()
260
    textos = list()
261
262
    def draw_all(val=2008):
263
        nonlocal lineas, flechas, textos
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable textos does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable flechas does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable lineas does not seem to be defined.
Loading history...
264
265
        # instead of clearing the whole axis, remove artists
266
        for linea in lineas:
267
            if linea is not None:
268
                linea.remove()
269
        for texto in textos:
270
            if texto is not None:
271
                texto.remove()
272
        for flecha in flechas:
273
            if flecha is not None:
274
                flecha.remove()
275
        ax.set_prop_cycle(None)
276
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
277
        lineas = list()
278
        flechas = list()
279
        textos = list()
280
281
        xlim, ylim = ax.get_xlim(), ax.get_ylim()
282
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
283
        #ax.clear() # either clear the whole axis or remove every artist separetly
284
            
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
285
        for i, label in enumerate(knots_names):
286
            years = knots_jyears[label]
287
            idx = (val-twidth < years) & (years < val)
288
            x = knots_X[label][idx]
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...
289
            y = knots_Y[label][idx]
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...
290
291
            if len(x) > 0:
292
                if label == '' or label == 'None': # if it is unlabelled, do not connect it.
0 ignored issues
show
Unused Code introduced by
Consider merging these comparisons with "in" to "label in ('', 'None')"
Loading history...
293
                    lineas.append(ax.plot(x, y, '.', linewidth=0.6, alpha=0.4, label=label, color='black')[0])
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (110/100).

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

Loading history...
294
                else:
295
                    lineas.append(ax.plot(x, y, '.-', linewidth=0.6, alpha=0.4, label=label)[0])
296
            else:
297
                lineas.append(None)
298
299
            if use_arrows:
300
                if len(x) > 1 and label != '' and label != 'None':
301
                    flechas.append(ax.quiver(x[:-1], 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
302
                               y[:-1], 
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (add 14 spaces).
Loading history...
Coding Style introduced by
Trailing whitespace
Loading history...
303
                               arrow_pos*(x[1:] - x[:-1]), 
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (add 14 spaces).
Loading history...
Coding Style introduced by
Trailing whitespace
Loading history...
304
                               arrow_pos*(y[1:] - y[:-1]), 
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (add 14 spaces).
Loading history...
Coding Style introduced by
Trailing whitespace
Loading history...
305
                               scale_units='xy', angles='xy', scale=1, 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
Coding Style introduced by
Wrong continued indentation (add 14 spaces).
Loading history...
306
                               width=0.0015, headwidth=10, headlength=10, headaxislength=6,
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (add 14 spaces).
Loading history...
307
                               alpha=0.5, color=lineas[i].get_color()))
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (add 14 spaces).
Loading history...
308
                else:
309
                    flechas.append(None)
310
311
            if len(x) > 0:
312
                #textos.append(ax.annotate(label, (x[0], y[0]), (-28,-10), textcoords='offset points', color=lineas[i].get_color(), fontsize=14))
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (145/100).

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

Loading history...
313
                textos.append(ax.text(x[-1]+0.015, y[-1]+0.015, label, {'color':lineas[i].get_color(), 'fontsize':14}))
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (119/100).

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

Loading history...
314
            else:
315
                textos.append(None)
316
317
        ax.set_xlim(xlim)
318
        ax.set_ylim(ylim)
319
        ax.set_aspect('equal')
320
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
321
        fig.canvas.draw_idle() # if removed every artist separately instead of ax.clear()
322
323
    draw_all()
324
325
    def update(val):
326
        nonlocal lineas, flechas, textos
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable textos does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable flechas does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable lineas does not seem to be defined.
Loading history...
327
328
        for i, label in enumerate(knots_names):
329
            years = knots_jyears[label]
330
            idx = (val-twidth < years) & (years < val)
331
            x = knots_X[label][idx]
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...
332
            y = knots_Y[label][idx]
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...
333
334 View Code Duplication
            if lineas[i] is not None:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
335
                if len(x) > 0:
336
                    lineas[i].set_xdata(x)
337
                    lineas[i].set_ydata(y)
338
                else:
339
                    lineas[i].remove()
340
                    lineas[i] = None
341
            else:
342
                if len(x) > 0:
343
                    if label == '' or label == 'None': # if it is unlabelled, do not connect it.
0 ignored issues
show
Unused Code introduced by
Consider merging these comparisons with "in" to "label in ('', 'None')"
Loading history...
344
                        lineas[i] = ax.plot(x, y, '.', linewidth=0.8, alpha=0.5, label=label, color='black')[0]
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...
345
                    else:
346
                        lineas[i] = ax.plot(x, y, '.-', linewidth=0.8, alpha=0.5, label=label)[0]
347
                
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
348
349
            if textos[i] is not None:
350
                if len(x) > 0:    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
351
                    textos[i].set_position((x[-1]+0.015, y[-1]+0.015))
352
                    textos[i].set_text(label)
353
                else:
354
                    textos[i].remove()
355
                    textos[i] = None
356
                    #textos[i].set_position((10, 10))
357
            else:
358
                if len(x) > 0:    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
359
                    textos[i] = ax.text(x[-1]+0.02, y[-1]+0.02, label, {'color':lineas[i].get_color(), 'fontsize':14})
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...
360
361
            if use_arrows:
362
                if flechas[i] is not None:
363
                    flechas[i].remove()
364
                    flechas[i] = None
365
                if len(x) > 1 and label != '' and label != 'None':
366
                    flechas[i] = ax.quiver(x[:-1], 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
367
                                       y[:-1], 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
Coding Style introduced by
Wrong continued indentation (add 4 spaces).
Loading history...
368
                                       arrow_pos*(x[1:] - x[:-1]), 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
Coding Style introduced by
Wrong continued indentation (add 4 spaces).
Loading history...
369
                                       arrow_pos*(y[1:] - y[:-1]), 
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (add 4 spaces).
Loading history...
Coding Style introduced by
Trailing whitespace
Loading history...
370
                                       scale_units='xy', angles='xy', scale=1, 
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (add 4 spaces).
Loading history...
Coding Style introduced by
Trailing whitespace
Loading history...
371
                                       width=0.0015, headwidth=10, headlength=10, headaxislength=6, 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
Coding Style introduced by
Wrong continued indentation (add 4 spaces).
Loading history...
372
                                       alpha=0.5, color=lineas[i].get_color())
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (add 4 spaces).
Loading history...
373
374
        fig.canvas.draw_idle()
375
376
377
378
    selected_knot = None
379
    selected_ind = None
380
    selected_x = None
381
    selected_y = None
382
383
384 View Code Duplication
    def submit_textbox(text):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
385
        nonlocal mod, knots, knots_names, knots_values, knots_jyears, knots_X, knots_Y
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable knots_names does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable knots_Y does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable knots_jyears does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable knots does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable knots_values does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable knots_X does not seem to be defined.
Loading history...
386
387
        log.debug('Submited with:')
388
        log.debug(f'   selected_knot {selected_knot}')
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
389
        log.debug(f'   selected_ind {selected_ind}')
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
390
        log.debug(f'   selected_x {selected_x}')
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
391
        log.debug(f'   selected_y {selected_y}')
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
392
393
        if selected_knot is not None:        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
394
            mod.loc[selected_ind, 'label'] = text.upper().strip(' ')
395
396
            knots = dict(tuple(mod.groupby('label')))
397
            knots_names = list(knots.keys())
398
            knots_values = list(knots.values())
399
            knots_jyears = {k:Time(knots[k]['date'].to_numpy()).jyear for k in knots}
400
            knots_X = {k:knots[k]['X'].to_numpy() for k in knots}
0 ignored issues
show
Coding Style Naming introduced by
Variable name "knots_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...
401
            knots_Y = {k:knots[k]['Y'].to_numpy() for k in knots}
0 ignored issues
show
Coding Style Naming introduced by
Variable name "knots_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...
402
403
            log.debug(f"Updated index {selected_ind} to {text.upper()}")
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
404
        else:
405
            pass
406
407
        draw_all(slider_date.val)
408
409
410
    def line_select_callback(eclick, erelease):
0 ignored issues
show
Comprehensibility introduced by
This function exceeds the maximum number of variables (17/15).
Loading history...
411
        nonlocal selected_knot,selected_x, selected_y, selected_ind
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable selected_knot does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable selected_x does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable selected_y does not seem to be defined.
Loading history...
Coding Style introduced by
Exactly one space required after comma
Loading history...
Comprehensibility Best Practice introduced by
The variable selected_ind does not seem to be defined.
Loading history...
412
413
        # 1 eclick and erelease are the press and release events
414
        x1, y1 = eclick.xdata, eclick.ydata
0 ignored issues
show
Coding Style Naming introduced by
Variable name "x1" 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 "y1" 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...
415
        x2, y2 = erelease.xdata, erelease.ydata
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...
Coding Style Naming introduced by
Variable name "x2" 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...
416
        log.debug("GUI: (%3.2f, %3.2f) --> (%3.2f, %3.2f)" % (x1, y1, x2, y2))
0 ignored issues
show
Coding Style Best Practice introduced by
Use lazy % formatting in logging functions
Loading history...
417
        log.debug("GUI:  The button you used were: %s %s" % (eclick.button, erelease.button))
0 ignored issues
show
Coding Style Best Practice introduced by
Use lazy % formatting in logging functions
Loading history...
418
419
        selected_knot = None
420
        selected_x = None
421
        selected_y = None
422
        selected_ind = None
423
424
        for i, label in enumerate(knots_names):
0 ignored issues
show
Unused Code introduced by
The variable i seems to be unused.
Loading history...
425
            years = knots_jyears[label]
426
            idx = (slider_date.val-twidth < years) & (years < slider_date.val)
427
428
            if np.sum(idx) == 0:
429
                continue # we did not select any component from this component, next one
430
431
            x = np.array(knots_X[label])
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...
432
            y = np.array(knots_Y[label])
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...
433
434
            # get points iside current rectangle for current date
435
            rect_idx = (x1 < x) & ( x < x2) & (y1 < y) & ( y < y2) & idx 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
Coding Style introduced by
No space allowed after bracket
Loading history...
436
437 View Code Duplication
            if np.sum(rect_idx) > 0:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
Unused Code introduced by
Unnecessary "else" after "break"
Loading history...
438
                textbox.set_val(label)
439
                
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
440
                selected_knot = label
441
                selected_x = x[rect_idx].ravel()
442
                selected_y = y[rect_idx].ravel()
443
                selected_ind = knots[label].index[rect_idx]
444
                
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
445
                log.debug(f'Selected {label} points  rect_idx {rect_idx} x {x[rect_idx]}, y {y[rect_idx]} with indices {selected_ind}')
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (135/100).

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

Loading history...
introduced by
Use lazy % formatting in logging functions
Loading history...
446
            
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
447
                textbox.begin_typing(None)
448
                break # if we find selected components in this epoch, continue with renaming
449
            else:
450
                pass
451
452
        # print epoch of selected points:
453
        if selected_knot is not None:
454
            out.clear_output()
455
            out.append_stdout('Selected:\n')
456
            for idx in selected_ind:
457
                #print(f"Selected {mod.loc[idx, 'label']} {mod.loc[idx, 'date']}")
458
                out.append_stdout(f" -> {mod.loc[idx, 'label']} {mod.loc[idx, 'date'].strftime('%Y-%m-%d')}\n")
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...
459
                
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
460
        update(slider_date.val)
461
462
463 View Code Duplication
    def toggle_selector(event):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
464
        log.debug('GUI: Key pressed.')
465
        if event.key in ['Q', 'q'] and toggle_selector.RS.active:
466
            log.debug('Selector deactivated.')
467
            toggle_selector.RS.set_active(False)
468
        if event.key in ['S', 's'] and not toggle_selector.RS.active:
469
            log.debug('Selector activated.')
470
            toggle_selector.RS.set_active(True)
471
        if event.key in ['R', 'r']:
472
            log.debug('Selector deactivated.')
473
            toggle_selector.RS.set_active(False)
474
            textbox.begin_typing(None)
475
            #textbox.set_val('')
476
        if event.key in ['E', 'e']:
477
            out.append_stdout('-> Close\n')
478
            plt.close()
479
480
481
    toggle_selector.RS = RectangleSelector(ax, line_select_callback,
482
                                           drawtype='box', useblit=True,
483
                                           button=[1, 3],  # don't use middle button
484
                                           minspanx=0, minspany=0,
485
                                           spancoords='data',
486
                                           interactive=False)
487
488
489
    #plt.connect('key_press_event', toggle_selector)
490
    fig.canvas.mpl_connect('key_press_event', toggle_selector)
491
492
493
494
    from mpl_toolkits.axes_grid1 import make_axes_locatable
0 ignored issues
show
introduced by
Import outside toplevel (mpl_toolkits.axes_grid1.make_axes_locatable)
Loading history...
introduced by
Unable to import 'mpl_toolkits.axes_grid1'
Loading history...
495
496
    divider_slider = make_axes_locatable(ax)
497
    slider_ax = divider_slider.append_axes("top", size="3%", pad="4%")  
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
498
    slider_date = Slider(ax=slider_ax, label="Date", valmin=2007, valmax=2020, valinit=2008, valstep=0.2, orientation="horizontal")
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (131/100).

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

Loading history...
499
    slider_date.on_changed(update)
500
501
    #divider_textbox = make_axes_locatable(ax)
502
    #textbox_ax = divider_textbox.append_axes("bottom", size="3%", pad="4%") 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
503
    textbox_ax = fig.add_axes([0.3,0.015,0.5,0.05])
0 ignored issues
show
Coding Style introduced by
Exactly one space required after comma
Loading history...
504
    textbox = TextBox(textbox_ax, 'Knot name:', initial='None')
505
    textbox.on_submit(submit_textbox)
506
507
508
509
    ax.set_xlim([-1.0, +1.0])
510
    ax.set_ylim([-1.0, +1.0])
511
    ax.set_aspect('equal')
512
513
    fig.suptitle('S to select, R to rename, Q to deactivate selector, E to exit')
514
515
    print('Usage:',
516
          '-> S to select, R to rename, Q to deactivate selector, E to exit',
517
          '-> To delete the knot, name it with a whitespace', 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
518
          '-> You can select points from one component at a time',
519
          '-> If you use the zoom or movement tools, remember to unselect them',
520
          sep='\n')
521
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
522
    plt.show()
523
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
524
    out.display_output()
525
  
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
526
    return mod
527
528
529
530
531
############################################
532
################ Knots GUI #################
533
############################################
534
535
536
537
def KnotsIdGUI(mod):
0 ignored issues
show
Coding Style Naming introduced by
Function name "KnotsIdGUI" 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 (28/15).
Loading history...
538
    """
539
        Prompt a GUI to select identified knots and alter their label, reprenting their
540
        time evolution.
541
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
542
        It can be used inside jupyter notebooks, using '%matplotlib widget' first.
543
       
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
544
        Parameters:
545
        -----------
546
         mod : :pd.DataFrame:
547
             pandas.DataFrame containing every knot, with at least columns 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
548
             'label', 'date', 'X', 'Y', 'Flux (Jy)'.
549
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
550
        Returns:
551
        --------
552
         mod : :pd.DataFrame:
553
             pandas.DataFrame containing every knot with their altered labels, with 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
554
             at least columns 'label', 'date', 'X', 'Y', 'Flux (Jy)'.
555
    """
556
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
557
    mod = mod.copy()
558
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
559
    knots = dict(tuple(mod.groupby('label')))
560
    knots_names = list(knots.keys())
561
    knots_values = list(knots.values())
562
    knots_jyears = {k:Time(knots[k]['date'].to_numpy()).jyear for k in knots}
563
    knots_dates = {k:knots[k]['date'].to_numpy() for k in knots}
564
    knots_fluxes = {k:knots[k]['Flux (Jy)'].to_numpy() for k in knots}
565
566
    from matplotlib.widgets import TextBox, RectangleSelector
0 ignored issues
show
introduced by
Unable to import 'matplotlib.widgets'
Loading history...
introduced by
Import outside toplevel (matplotlib.widgets.TextBox, matplotlib.widgets.RectangleSelector)
Loading history...
567
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
568
    out = get_output()
569
570
    fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(8,5))
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...
Coding Style introduced by
Exactly one space required after comma
Loading history...
571
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
572
    lineas = list()
573
    textos = list()
574
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
575
    def draw_all():
576
        nonlocal lineas, textos
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable textos does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable lineas does not seem to be defined.
Loading history...
577
578
        for linea in lineas:
579
            if linea is not None:
580
                linea.remove()
581
        for texto in textos:
582
            if texto is not None:
583
                texto.remove()
584
585
        ax.set_prop_cycle(None)
586
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
587
        lineas = list()
588
        textos = list()
589
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
590
        #ax.clear() # either clear the whole axis or remove every artist separetly
591
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
592
        for i, label in enumerate(knots_names):
593
            x, y = knots_jyears[label], knots_fluxes[label]
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 "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...
594
595
            if len(x) > 0:
596
                if label == '' or label == 'None': # if it is unlabelled, do not connect it.
0 ignored issues
show
Unused Code introduced by
Consider merging these comparisons with "in" to "label in ('', 'None')"
Loading history...
597
                    lineas.append(ax.plot(x, y, '.', linewidth=0.8, alpha=0.5, label=label, color='black')[0])
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (110/100).

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

Loading history...
598
                else:
599
                    lineas.append(ax.plot(x, y, '.-', linewidth=0.8, alpha=0.5, label=label)[0])
600
            else:
601
                lineas.append(None)
602
                
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
603
            if len(x) > 0:
604
                #textos.append(ax.annotate(label, (x[0], y[0]), (-28,-10), textcoords='offset points', color=lineas[i].get_color(), fontsize=14))
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (145/100).

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

Loading history...
605
                textos.append(ax.text(x[0], y[0], label, {'color':lineas[i].get_color(), 'fontsize':14}))
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (105/100).

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

Loading history...
606
            else:
607
                textos.append(None)
608
                
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
609
        fig.canvas.draw_idle() # if removed every artist separately instead of ax.clear()
610
611
612
    def update():
613
        nonlocal lineas, textos
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable textos does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable lineas does not seem to be defined.
Loading history...
614
615
        for i, label in enumerate(knots_names):   
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
616
            x, y = knots_jyears[label], knots_fluxes[label]
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...
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...
617
618 View Code Duplication
            if lineas[i] is not None:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
619
                if len(x) > 0:
620
                    lineas[i].set_xdata(x)
621
                    lineas[i].set_ydata(y)
622
                else:
623
                    lineas[i].remove()
624
                    lineas[i] = None
625
            else:
626
                if len(x) > 0:
627
                    if label == '' or label == 'None': # if it is unlabelled, do not connect it.
0 ignored issues
show
Unused Code introduced by
Consider merging these comparisons with "in" to "label in ('', 'None')"
Loading history...
628
                        lineas[i] = ax.plot(x, y, '.', linewidth=0.8, alpha=0.5, label=label, color='black')[0]
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...
629
                    else:
630
                        lineas[i] = ax.plot(x, y, '.-', linewidth=0.8, alpha=0.5, label=label)[0]
631
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
632
            if textos[i] is not None:
633
                if len(x) > 0:    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
634
                    textos[i].set_position((x[0], y[0]))
635
                    textos[i].set_text(label)
636
                else:
637
                    textos[i].remove()
638
                    textos[i] = None
639
                    #textos[i].set_position((10, 10))
640
            else:
641
                if len(x) > 0:    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
642
                    #textos[i] = ax.annotate(label, (x[0], y[0]), (-24,-10), textcoords='offset points', color=lineas[i].get_color(), fontsize=15)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (146/100).

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

Loading history...
643
                    textos[i] = ax.text(x[0], y[0], label, {'color':lineas[i].get_color(), 'fontsize':14})
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (106/100).

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

Loading history...
644
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
645
        fig.canvas.draw_idle()    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
646
   
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
647
648
    selected_knot = None
649
    selected_ind = None
650
    selected_date = None
651
    selected_flux = None
652
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
653 View Code Duplication
    def submit_textbox(text):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
654
        nonlocal mod, knots, knots_names, knots_values, knots_jyears, knots_dates, knots_fluxes
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable knots_jyears does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable knots_values does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable knots_names does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable knots_dates does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable knots_fluxes does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable knots does not seem to be defined.
Loading history...
655
656
        log.debug('Submited with:')
657
        log.debug(f'   selected_knot {selected_knot}')
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
658
        log.debug(f'   selected_ind {selected_ind}')
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
659
        log.debug(f'   selected_flux {selected_flux}')
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
660
        log.debug(f'   selected_date {selected_date}')
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
661
662
        if selected_knot is not None:        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
663
            mod.loc[selected_ind, 'label'] = text.upper().strip(' ')
664
665
            knots = dict(tuple(mod.groupby('label')))
666
            knots_names = list(knots.keys())
667
            knots_values = list(knots.values())
668
            knots_jyears = {k:Time(knots[k]['date'].to_numpy()).jyear for k in knots}
669
            knots_dates = {k:knots[k]['date'].to_numpy() for k in knots}
670
            knots_fluxes = {k:knots[k]['Flux (Jy)'].to_numpy() for k in knots}
671
672
            print(f"Updated index {selected_ind} to {text.upper()}")
673
        else:
674
            pass
675
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
676
        draw_all()
677
678
    def line_select_callback(eclick, erelease):
0 ignored issues
show
Comprehensibility introduced by
This function exceeds the maximum number of variables (20/15).
Loading history...
679
        nonlocal selected_knot,selected_date, selected_flux, selected_ind
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable selected_ind does not seem to be defined.
Loading history...
Coding Style introduced by
Exactly one space required after comma
Loading history...
Comprehensibility Best Practice introduced by
The variable selected_knot does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable selected_date does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable selected_flux does not seem to be defined.
Loading history...
680
681
        # 1 eclick and erelease are the press and release events
682
        x1, y1 = eclick.xdata, eclick.ydata
0 ignored issues
show
Coding Style Naming introduced by
Variable name "y1" 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 "x1" 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...
683
        x2, y2 = erelease.xdata, erelease.ydata
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...
Coding Style Naming introduced by
Variable name "x2" 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...
684
        log.debug("GUI: (%3.2f, %3.2f) --> (%3.2f, %3.2f)" % (x1, y1, x2, y2))
0 ignored issues
show
Coding Style Best Practice introduced by
Use lazy % formatting in logging functions
Loading history...
685
        log.debug("GUI:  The button you used were: %s %s" % (eclick.button, erelease.button))
0 ignored issues
show
Coding Style Best Practice introduced by
Use lazy % formatting in logging functions
Loading history...
686
687
        selected_knot = None
688
        selected_date = None
689
        selected_flux = None
690
        selected_ind = None
691
692
        for i, label in enumerate(knots_names):
0 ignored issues
show
Unused Code introduced by
The variable i seems to be unused.
Loading history...
693
            years = knots_jyears[label]
694
            fluxes = knots_fluxes[label]
695
            
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
696
            # get points iside current rectangle for current date
697
            rect_idx = (x1 < years) & ( years < x2) & (y1 < fluxes) & ( fluxes < y2) 
0 ignored issues
show
Coding Style introduced by
No space allowed after bracket
Loading history...
Coding Style introduced by
Trailing whitespace
Loading history...
698
            
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
699
            if np.sum(rect_idx) == 0:
700
                continue # we did not select any component from this component, next one
701
702
            x = np.array(years)
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...
703
            y = np.array(fluxes)
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...
704
705 View Code Duplication
            if np.sum(rect_idx) > 0:
0 ignored issues
show
Unused Code introduced by
Unnecessary "else" after "break"
Loading history...
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
706
                textbox.set_val(label)
707
                selected_knot = label
708
                selected_x = x[rect_idx].ravel()
0 ignored issues
show
Unused Code introduced by
The variable selected_x seems to be unused.
Loading history...
709
                selected_y = y[rect_idx].ravel()
0 ignored issues
show
Unused Code introduced by
The variable selected_y seems to be unused.
Loading history...
710
                selected_ind = knots[label].index[rect_idx]
711
                log.debug(f'Selected {label} points  rect_idx {rect_idx} date {x[rect_idx]}, flux {y[rect_idx]} with indices {selected_ind}')
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (141/100).

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

Loading history...
introduced by
Use lazy % formatting in logging functions
Loading history...
712
                break # if we find selected components in this epoch, continue with renaming
713
            else:
714
                pass
715
716
        # print epoch of selected points:
717
        if selected_knot is not None:
718
            out.clear_output()
719
            out.append_stdout('Selected:\n')
720
            for idx in selected_ind:
721
                #print(f"Selected {mod.loc[idx, 'label']} {mod.loc[idx, 'date']}")
722
                out.append_stdout(f" -> {mod.loc[idx, 'label']} {mod.loc[idx, 'date'].strftime('%Y-%m-%d')}\n")
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...
723
           
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
724
        update()
725
726
727 View Code Duplication
    def toggle_selector(event):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
728
        log.debug('GUI: Key pressed.')
729
        if event.key in ['Q', 'q'] and toggle_selector.RS.active:
730
            log.debug('Selector deactivated.')
731
            toggle_selector.RS.set_active(False)
732
        if event.key in ['S', 's'] and not toggle_selector.RS.active:
733
            log.debug('Selector activated.')
734
            toggle_selector.RS.set_active(True)
735
        if event.key in ['R', 'r']:
736
            log.debug('Selector deactivated.')
737
            toggle_selector.RS.set_active(False)
738
            textbox.begin_typing(None)
739
            #textbox.set_val('')
740
        if event.key in ['E', 'e']:
741
            out.append_stdout('-> Close\n')
742
            plt.close()
743
744
745
    toggle_selector.RS = RectangleSelector(ax, line_select_callback,
746
                                           drawtype='box', useblit=True,
747
                                           button=[1, 3],  # don't use middle button
748
                                           minspanx=0, minspany=0,
749
                                           spancoords='data',
750
                                           interactive=False)
751
752
753
    fig.canvas.mpl_connect('key_press_event', toggle_selector)
754
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
755
    from mpl_toolkits.axes_grid1 import make_axes_locatable
0 ignored issues
show
introduced by
Unable to import 'mpl_toolkits.axes_grid1'
Loading history...
introduced by
Import outside toplevel (mpl_toolkits.axes_grid1.make_axes_locatable)
Loading history...
756
757
    divider_textbox = make_axes_locatable(ax)
758
    textbox_ax = divider_textbox.append_axes("bottom", size="10%", pad="15%") 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
759
    #textbox_ax = fig.add_axes([0.3,0,0.5,0.05])
760
    textbox = TextBox(textbox_ax, 'Knot name:', initial='None')
761
    textbox.on_submit(submit_textbox)
762
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
763
    draw_all()
764
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
765
    #ax.autoscale()
766
    ax.set_xlabel('date (year)')
767
    ax.set_ylabel('Flux (Jy)')
768
    ax.set_title('Flux from each component')
769
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
770
    xlims = Time(np.amin(mod['date'])).jyear, Time(np.amax(mod['date'])).jyear
771
    ax.set_xlim((xlims[0]-0.03*np.abs(xlims[1]-xlims[0]), xlims[1]+0.03*np.abs(xlims[1]-xlims[0])))
772
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
773
    fig.suptitle('S to select, R to rename, Q to deactivate selector, E to exit')
774
775
    print('Usage:',
776
          '-> S to select, R to rename, Q to deactivate selector, E to exit',
777
          '-> To delete the knot, name it with a whitespace', 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
778
          '-> You can select points from one component at a time',
779
          '-> If you use the zoom or movement tools, remember to unselect them',
780
          sep='\n')
781
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
782
    plt.show()
783
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
784
    out.display_output()
785
786
    return mod
787
788
789
790
###################################################
791
########### Knots Read Mod (diffmap only) #########
792
###################################################
793
794
def KnotsIdReadMod_from_diffmap(path=None):
0 ignored issues
show
Coding Style Naming introduced by
Function name "KnotsIdReadMod_from_diffmap" 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...
795
    """
796
        Read *_mod.mod files as printed by diffmap, return a dataframe containing all information ready
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (103/100).

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

Loading history...
797
        to be worked on for labelling and to be used with these GUIs.
798
   
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
799
        Parameters:
800
        -----------
801
         path : :str:
802
             string indicating the path to the mod files to be used, their names must end in the format
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (103/100).

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

Loading history...
803
             '%Y-%m-%d_mod.mod', for example, path = 'vlbi/ftree/*/*_mod.mod'.
804
             
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
805
        Returns:
806
        -----------
807
         mod : :pd.DataFrame:
808
             pandas.DataFrame containing every knot, with at least columns 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
809
             'label', 'date', 'X', 'Y', 'Flux (Jy)'.
810
    """
811
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
812
    if path is None:
813
        log.error('Path not specified')
814
        raise Exception('Path not specified')
815
            
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
816
    mod_dates_str = list()
817
    mod_dates = list()
818
    mod_data = list()
819
820
    for f in glob.glob(f'{path}'):
0 ignored issues
show
Coding Style Naming introduced by
Variable name "f" 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...
821
        match = re.findall(r'([0-9]{4}-[0-9]{2}-[0-9]{2})_mod.mod', f)
822
        if not len(match) > 0:
823
            continue
824
825
        date_str = match[0]
826
        date = datetime.strptime(date_str, '%Y-%m-%d')
827
828
        mod_dates_str.append(date_str)
829
        mod_dates.append(date)
830
        mod_data.append(pd.read_csv(f, sep='\s+', comment='!', names=['Flux (Jy)', 'Radius (mas)', 'Theta (deg)', 'Major FWHM (mas)', 'Axial ratio', 'Phi (deg)', 'T', 'Freq (Hz)', 'SpecIndex']))
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (194/100).

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

Loading history...
Bug introduced by
A suspicious escape sequence \s was found. Did you maybe forget to add an r prefix?

Escape sequences in Python are generally interpreted according to rules similar to standard C. Only if strings are prefixed with r or R are they interpreted as regular expressions.

The escape sequence that was used indicates that you might have intended to write a regular expression.

Learn more about the available escape sequences. in the Python documentation.

Loading history...
831
832
    # sort by date    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
833
    idx = np.argsort(mod_dates)
834
    mod_dates_str = list(np.array(mod_dates_str, dtype=object)[idx])
835
    mod_dates = list(np.array(mod_dates, dtype=object)[idx])
836
    mod_data = list(np.array(mod_data, dtype=object)[idx])
837
838
    # fix stupid 'v' in columns, insert a label field, add X, Y columns
839
    for i in range(len(mod_dates)):
0 ignored issues
show
unused-code introduced by
Consider using enumerate instead of iterating with range and len
Loading history...
840
        mod_data[i].insert(0, 'label', value=None)
841
        mod_data[i].insert(1, 'date', value=mod_dates[i])
842
843
        mod_data[i]['Flux (Jy)'] = mod_data[i]['Flux (Jy)'].str.strip('v').astype(float)
844
        mod_data[i]['Radius (mas)'] = mod_data[i]['Radius (mas)'].str.strip('v').astype(float)
845
        mod_data[i]['Theta (deg)'] = mod_data[i]['Theta (deg)'].str.strip('v').astype(float)
846
847
        mod_data[i].insert(5, 'X', mod_data[i]['Radius (mas)']*np.cos(np.pi/180*(mod_data[i]['Theta (deg)']-90)))
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...
848
        mod_data[i].insert(6, 'Y', mod_data[i]['Radius (mas)']*np.sin(np.pi/180*(mod_data[i]['Theta (deg)']-90)))
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...
849
850
     
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
851
    mod = pd.concat(mod_data, ignore_index=True)
852
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
853
    return mod
854
855
856
###################################################
857
################## Knots Save Mod #################
858
###################################################
859
860
def KnotsIdSaveMod(mod, path=None, rewrite=False, drop_blanks=False):
0 ignored issues
show
Coding Style Naming introduced by
Function name "KnotsIdSaveMod" 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...
861
    """
862
        Save Knots data to *_mod.mod files ready to be re-proccessed with diffmap.
863
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
864
        Actually only useful to remove stupid knots and fit it again with diffmap.
865
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
866
        Parameters:
867
        -----------
868
         mod : :pd.DataFrame:
869
             pandas.DataFrame containing every knot
870
         path: :str:
871
             string containing the path to which the files are to be saved, eg:
872
             path = 'my_knots/'
873
         rewrite: :bool:
874
             If rewrite is True, path is interpreted as a regex for which files
875
             to overwrite.
876
         drop_blanks: :bool:
877
             If True, knots without label (or whose label is a whitspace) are dropped.
878
             If False (default), they are saved without label.
879
             
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
880
        Returns:
881
        --------
882
         None
883
    """
884
885
    if path is None:
886
        log.error('Path not specified')
887
        raise Exception('Path not specified')
888
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
889
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
890
    mod = mod.copy()
891
892
893
    if drop_blanks:
894
        mod = mod.drop(mod[mod['label'].str.strip('') == ''].index)
895
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
896
897
    mod_dict = dict(list(mod.groupby('date')))
898
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
899
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
900
    if rewrite:
901
        file_list = list()
902
        for f in glob.glob(f'{path}'):
0 ignored issues
show
Coding Style Naming introduced by
Variable name "f" 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...
903
            match = re.findall(r'([0-9]{4}-[0-9]{2}-[0-9]{2})_mod.mod', f)
904
            
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
905
            if not len(match) > 0:
906
                continue
907
            
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
908
            date = datetime.strptime(match[0], '%Y-%m-%d')
909
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
910
            if date not in mod_dict:
911
                raise Exception('Specified regex includes files for which there are no knots')
912
                
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
913
            file_list.append(f)
914
915
        if len(file_list) != len(mod_dict):
916
            raise Exception(f'Specified files by path regex does not match the number of epochs ({len(file_list)} vs {len(mod_dict)})')
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (135/100).

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

Loading history...
917
    else:
918
        file_list = list()
919
        for date in mod_dict.keys():
920
               file_list.append(f"{path}/{date.strftime('%Y-%m-%d')}_mod.mod")
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 12 spaces were expected, but 15 were found.
Loading history...
921
  
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
922
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
923
    for fname, (date, data) in zip(file_list, mod_dict.items()):
924
        data = data.copy()
925
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
926
        #data = data.drop(columns=['label'])
927
        #data = data.drop(columns=['X'])
928
        #data = data.drop(columns=['Y'])
929
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
930
        data['Flux (Jy)'] = data['Flux (Jy)'].astype(str) + 'v'
931
        data['Radius (mas)'] = data['Radius (mas)'].astype(str) + 'v'
932
        data['Theta (deg)'] = data['Theta (deg)'].astype(str) + 'v'
933
934
        ## add previous labels in comments (so diffmap does not get stuck with it)
935
        data['label'] = '!' + data['label']
936
937
        with open(fname, 'w') as f:
0 ignored issues
show
Coding Style Naming introduced by
Variable name "f" 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...
938
            f.write("! Generated by mutis\n"
939
                    "! Columns\n"
940
                    "! 'Flux (Jy)', 'Radius (mas)', 'Theta (deg)', 'Major FWHM (mas)', 'Axial ratio', 'Phi (deg)', 'T', 'Freq (Hz)', 'SpecIndex', '!label'\n")
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (158/100).

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

Loading history...
941
            data.to_csv(f,
942
                        columns=['Flux (Jy)', 'Radius (mas)', 'Theta (deg)', 'Major FWHM (mas)', 'Axial ratio', 'Phi (deg)', 'T', 'Freq (Hz)', 'SpecIndex', 'label'],
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (165/100).

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

Loading history...
943
                        index=False, sep=' ', header=None)
944
945
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
946
947
###################################################
948
################## Knots Read Mod #################
949
###################################################        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
950
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
951
def KnotsIdReadMod(path=None):
0 ignored issues
show
Coding Style Naming introduced by
Function name "KnotsIdReadMod" 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...
952
    """
953
        Read *_mod.mod files as printed by diffmap, return a dataframe containing all information ready
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (103/100).

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

Loading history...
954
        to be worked on for labelling and to be used with these GUIs.
955
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
956
        It detects whether the file was generated by mutis. If it was then 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
957
        it searchs for a hidden label column to load previous label names (unnamed labels
958
   
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
959
        Parameters:
960
        -----------
961
         path : :str:
962
             string indicating the path to the mod files to be used, their names must end in the format
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (103/100).

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

Loading history...
963
             '%Y-%m-%d_mod.mod', for example, path = 'vlbi/ftree/*/*_mod.mod'.
964
             
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
965
        Returns:
966
        -----------
967
         mod : :pd.DataFrame:
968
             pandas.DataFrame containing every knot, with at least columns 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
969
             'label', 'date', 'X', 'Y', 'Flux (Jy)'.
970
    """
971
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
972
    if path is None:
973
        log.error('Path not specified')
974
        raise Exception('Path not specified')
975
            
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
976
    mod_dates_str = list()
977
    mod_dates = list()
978
    mod_data = list()
979
980
    for f in glob.glob(f'{path}'):
0 ignored issues
show
Coding Style Naming introduced by
Variable name "f" 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...
981
        match = re.findall(r'([0-9]{4}-[0-9]{2}-[0-9]{2})_mod.mod', f)
982
        if not len(match) > 0:
983
            continue
984
985
        date_str = match[0]
986
        date = datetime.strptime(date_str, '%Y-%m-%d')
987
988
        mod_dates_str.append(date_str)
989
        mod_dates.append(date)
990
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
991
        with open(f) as fobj:
992
            firstline = fobj.readline()
993
            if firstline == '! Generated by mutis\n':
0 ignored issues
show
Unused Code introduced by
The if statement can be replaced with 'var = bool(test)'
Loading history...
994
                generated_by_mutis = True
995
            else:
996
                generated_by_mutis = False
997
                
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
998
        if generated_by_mutis:
999
            data = pd.read_csv(f, sep='\s+', 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
Bug introduced by
A suspicious escape sequence \s was found. Did you maybe forget to add an r prefix?

Escape sequences in Python are generally interpreted according to rules similar to standard C. Only if strings are prefixed with r or R are they interpreted as regular expressions.

The escape sequence that was used indicates that you might have intended to write a regular expression.

Learn more about the available escape sequences. in the Python documentation.

Loading history...
1000
                               skiprows=3, 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1001
                               #converters={'label':(lambda l: '' if l == '' else l)}, 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1002
                               dtype={'label':str},
1003
                               names=['Flux (Jy)', 'Radius (mas)', 'Theta (deg)', 'Major FWHM (mas)', 'Axial ratio', 'Phi (deg)', 'T', 'Freq (Hz)', 'SpecIndex',
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (160/100).

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

Loading history...
1004
                                      'label'])
1005
            data['label'] = data['label'].str.strip('!')
1006
        else:
1007
            data = pd.read_csv(f, sep='\s+', comment='!', names=['Flux (Jy)', 'Radius (mas)', 'Theta (deg)', 'Major FWHM (mas)', 'Axial ratio', 'Phi (deg)', 'T', 'Freq (Hz)', 'SpecIndex'])
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (188/100).

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

Loading history...
Bug introduced by
A suspicious escape sequence \s was found. Did you maybe forget to add an r prefix?

Escape sequences in Python are generally interpreted according to rules similar to standard C. Only if strings are prefixed with r or R are they interpreted as regular expressions.

The escape sequence that was used indicates that you might have intended to write a regular expression.

Learn more about the available escape sequences. in the Python documentation.

Loading history...
1008
            #data.insert(0, 'label', value=None)
1009
            data.insert(0, 'label', value='')
1010
1011
        data.insert(1, 'date', value=date)
1012
1013
        data['Flux (Jy)'] = data['Flux (Jy)'].str.strip('v').astype(float)
1014
        data['Radius (mas)'] = data['Radius (mas)'].str.strip('v').astype(float)
1015
        data['Theta (deg)'] = data['Theta (deg)'].str.strip('v').astype(float)
1016
1017
        data.insert(5, 'X', data['Radius (mas)']*np.cos(np.pi/180*(data['Theta (deg)']-90)))
1018
        data.insert(6, 'Y', data['Radius (mas)']*np.sin(np.pi/180*(data['Theta (deg)']-90)))
1019
1020
        mod_data.append(data)
1021
             
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1022
    # sort by date    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1023
    idx = np.argsort(mod_dates)
1024
    mod_dates_str = list(np.array(mod_dates_str, dtype=object)[idx])
1025
    mod_dates = list(np.array(mod_dates, dtype=object)[idx])
1026
    mod_data = list(np.array(mod_data, dtype=object)[idx])
1027
     
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1028
    mod = pd.concat(mod_data, ignore_index=True)
1029
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1030
    return mod
1031
1032
1033
1034
###################################################
1035
########### Knots CSV final outputting ############
1036
###################################################
1037
1038
def KnotsIdSaveCSV(mod, path=None):
0 ignored issues
show
Coding Style Naming introduced by
Function name "KnotsIdSaveCSV" 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...
1039
    """
1040
        Save Knots data to .csv files (as done by Svetlana? ##)
1041
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1042
        Each knot label has its own {label}.csv. To be compatible with Svetlana's format, 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1043
        columns should be modified to:
1044
        'Date' (jyear), 'MJD', 'X(mas)', 'Y(mas)', 'Flux(Jy)'
1045
        These columns are derived from the ones in `mod`, old ones are removed.
1046
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1047
        Parameters:
1048
        -----------
1049
         mod : :pd.DataFrame:
1050
             pandas.DataFrame containing every knot, with at least columns 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1051
             'label', 'date', 'X', 'Y', 'Flux (Jy)'.
1052
         path: :str:
1053
             string containing the path to which the files are to be saved, eg:
1054
             path = 'my_knots/'
1055
             
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1056
        Returns:
1057
        --------
1058
         None
1059
    """
1060
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1061
    if path is None:
1062
        log.error('Path not specified')
1063
        raise Exception('Path not specified')
1064
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1065
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1066
    mod = mod.copy()
1067
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1068
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1069
    mod_dict = dict(list(mod.groupby('label')))
1070
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1071
    for label, data in mod_dict.items():
1072
        data = data.copy()
1073
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1074
        #data.insert(0, 'Date', Time(data['date']).jyear)
1075
        #data.insert(1, 'MJD', Time(data['date']).mjd)
1076
        #data = data.rename(columns={'X': 'X (mas)', 'Y': 'Y (mas)'})
1077
        #data = data.drop(columns=['date'])
1078
        #data = data.drop(columns=['label'])
1079
        #if 'Radius (mas)' in data.columns:
1080
        #    data = data.rename(columns={'Radius (mas)':'R(mas)'})
1081
        #data.columns = data.columns.str.replace(' ', '')
1082
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1083
        data.to_csv(f'{path}/{label}.csv', index=False)
1084
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1085
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1086
1087
def KnotsIdReadCSV(path=None):
0 ignored issues
show
Coding Style Naming introduced by
Function name "KnotsIdReadCSV" 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...
1088
    """
1089
        Read Knots data to .csv files (as done by Svetlana? ##)
1090
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1091
        Each knot label has its own {label}.csv. To be compatible with Svetlana's format, 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1092
        columns should be modified to:
1093
        'Date' (jyear), 'MJD', 'X(mas)', 'Y(mas)', 'Flux(Jy)'
1094
        These columns are derived from the ones in `mod`, old ones are removed.
1095
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1096
        Parameters:
1097
        -----------
1098
         path: :str:
1099
             string containing the path to read files from eg:
1100
             path = 'myknows/*.csv'
1101
        Returns:
1102
        --------
1103
         mod : :pd.DataFrame:
1104
             pandas.DataFrame containing every knot, with at least columns 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1105
             'label', 'date', 'X', 'Y', 'Flux (Jy)'.
1106
    """
1107
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1108
    if path is None:
1109
        log.error('Path not specified')
1110
        raise Exception('Path not specified')
1111
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1112
    dataL = list()
0 ignored issues
show
Coding Style Naming introduced by
Variable name "dataL" 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...
1113
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1114
    for f in glob.glob(f'{path}'):
0 ignored issues
show
Coding Style Naming introduced by
Variable name "f" 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...
1115
        match = re.findall(r'/(.*).csv', f)
1116
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1117
        if not len(match) > 0:
1118
            continue
1119
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1120
        knot_name = match[0]
1121
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1122
        log.debug(f'Loading {knot_name} from {f}')
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
1123
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1124
        knot_data = pd.read_csv(f, parse_dates=['date'], date_parser=pd.to_datetime)
1125
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1126
        dataL.append((knot_name, knot_data))
1127
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1128
    mod = pd.concat(dict(dataL), ignore_index=True)
1129
1130
    return mod
1131