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

mutis.astro   F

Complexity

Total Complexity 132

Size/Duplication

Total Lines 1107
Duplicated Lines 11.47 %

Importance

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

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 (1106/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
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...
218
    """
219
        Prompt a GUI to select identified knots and alter their label, reprenting their 2D
220
        spatial distribution in different times.
221
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
222
        It can be used inside jupyter notebooks, using '%matplotlib widget' first.
223
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
224
        Parameters:
225
        -----------
226
         mod : :pd.DataFrame:
227
             pandas.DataFrame containing every knot, with at least columns 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
228
             'label', 'date', 'X', 'Y', 'Flux (Jy)'.
229
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
230
        Returns:
231
        --------
232
         mod : :pd.DataFrame:
233
             pandas.DataFrame containing every knot with their altered labels, with 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
234
             at least columns 'label', 'date', 'X', 'Y', 'Flux (Jy)'.
235
    """
236
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
237
    mod = mod.copy()
238
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
239
    knots = dict(tuple(mod.groupby('label')))
240
    knots_names = list(knots.keys())
241
    knots_values = list(knots.values())
242
    knots_jyears = {k:Time(knots[k]['date'].to_numpy()).jyear for k in knots}
243
    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...
244
    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...
245
246
247
    from matplotlib.widgets import Slider, Button, TextBox, RectangleSelector
0 ignored issues
show
introduced by
Unable to import 'matplotlib.widgets'
Loading history...
Unused Code introduced by
Unused Button imported from matplotlib.widgets
Loading history...
introduced by
Import outside toplevel (matplotlib.widgets.Slider, matplotlib.widgets.Button, matplotlib.widgets.TextBox, matplotlib.widgets.RectangleSelector)
Loading history...
248
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
249
    out = get_output()
250
251
    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...
252
253
    lineas = list()
254
    flechas = list()
255
    textos = list()
256
257
    def draw_all(val=2008):
258
        nonlocal lineas, flechas, textos
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable lineas 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 textos does not seem to be defined.
Loading history...
259
260
        # instead of clearing the whole axis, remove artists
261
        for linea in lineas:
262
            if linea is not None:
263
                linea.remove()
264
        for texto in textos:
265
            if texto is not None:
266
                texto.remove()
267
        for flecha in flechas:
268
            if flecha is not None:
269
                flecha.remove()
270
        ax.set_prop_cycle(None)
271
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
272
        lineas = list()
273
        flechas = list()
274
        textos = list()
275
276
        xlim, ylim = ax.get_xlim(), ax.get_ylim()
277
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
278
        #ax.clear() # either clear the whole axis or remove every artist separetly
279
            
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
280
        for i, label in enumerate(knots_names):
281
            years = knots_jyears[label]
282
            idx = (val-twidth < years) & (years < val)
283
            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...
284
            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...
285
286
            if len(x) > 0:
287
                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...
288
                    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...
289
                else:
290
                    lineas.append(ax.plot(x, y, '.-', linewidth=0.6, alpha=0.4, label=label)[0])
291
            else:
292
                lineas.append(None)
293
294
            if use_arrows:
295
                if len(x) > 1 and label != '' and label != 'None':
296
                    flechas.append(ax.quiver(x[:-1], 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
297
                               y[:-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...
298
                               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 14 spaces).
Loading history...
299
                               arrow_pos*(y[1:] - y[:-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...
300
                               scale_units='xy', angles='xy', scale=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...
301
                               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...
302
                               alpha=0.5, color=lineas[i].get_color()))
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (add 14 spaces).
Loading history...
303
                else:
304
                    flechas.append(None)
305
306
            if len(x) > 0:
307
                #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...
308
                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...
309
            else:
310
                textos.append(None)
311
312
        ax.set_xlim(xlim)
313
        ax.set_ylim(ylim)
314
        ax.set_aspect('equal')
315
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
316
        fig.canvas.draw_idle() # if removed every artist separately instead of ax.clear()
317
318
    draw_all()
319
320
    def update(val):
321
        nonlocal lineas, flechas, textos
0 ignored issues
show
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...
Comprehensibility Best Practice introduced by
The variable textos does not seem to be defined.
Loading history...
322
323
        for i, label in enumerate(knots_names):
324
            years = knots_jyears[label]
325
            idx = (val-twidth < years) & (years < val)
326
            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...
327
            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...
328
329 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...
330
                if len(x) > 0:
331
                    lineas[i].set_xdata(x)
332
                    lineas[i].set_ydata(y)
333
                else:
334
                    lineas[i].remove()
335
                    lineas[i] = None
336
            else:
337
                if len(x) > 0:
338
                    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...
339
                        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...
340
                    else:
341
                        lineas[i] = ax.plot(x, y, '.-', linewidth=0.8, alpha=0.5, label=label)[0]
342
                
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
343
344
            if textos[i] is not None:
345
                if len(x) > 0:    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
346
                    textos[i].set_position((x[-1]+0.015, y[-1]+0.015))
347
                    textos[i].set_text(label)
348
                else:
349
                    textos[i].remove()
350
                    textos[i] = None
351
                    #textos[i].set_position((10, 10))
352
            else:
353
                if len(x) > 0:    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
354
                    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...
355
356
            if use_arrows:
357
                if flechas[i] is not None:
358
                    flechas[i].remove()
359
                    flechas[i] = None
360
                if len(x) > 1 and label != '' and label != 'None':
361
                    flechas[i] = ax.quiver(x[:-1], 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
362
                                       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...
363
                                       arrow_pos*(x[1:] - x[:-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...
364
                                       arrow_pos*(y[1:] - 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...
365
                                       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...
366
                                       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...
367
                                       alpha=0.5, color=lineas[i].get_color())
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (add 4 spaces).
Loading history...
368
369
        fig.canvas.draw_idle()
370
371
372
373
    selected_knot = None
374
    selected_ind = None
375
    selected_x = None
376
    selected_y = None
377
378
379 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...
380
        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 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...
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_values 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...
381
382
        log.debug('Submited with:')
383
        log.debug(f'   selected_knot {selected_knot}')
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
384
        log.debug(f'   selected_ind {selected_ind}')
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
385
        log.debug(f'   selected_x {selected_x}')
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
386
        log.debug(f'   selected_y {selected_y}')
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
387
388
        if selected_knot is not None:        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
389
            mod.loc[selected_ind, 'label'] = text.upper().strip(' ')
390
391
            knots = dict(tuple(mod.groupby('label')))
392
            knots_names = list(knots.keys())
393
            knots_values = list(knots.values())
394
            knots_jyears = {k:Time(knots[k]['date'].to_numpy()).jyear for k in knots}
395
            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...
396
            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...
397
398
            log.debug(f"Updated index {selected_ind} to {text.upper()}")
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
399
        else:
400
            pass
401
402
        draw_all(slider_date.val)
403
404
405
    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...
406
        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_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...
Comprehensibility Best Practice introduced by
The variable selected_x does not seem to be defined.
Loading history...
407
408
        # 1 eclick and erelease are the press and release events
409
        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...
410
        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...
411
        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...
412
        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...
413
414
        selected_knot = None
415
        selected_x = None
416
        selected_y = None
417
        selected_ind = None
418
419
        for i, label in enumerate(knots_names):
0 ignored issues
show
Unused Code introduced by
The variable i seems to be unused.
Loading history...
420
            years = knots_jyears[label]
421
            idx = (slider_date.val-twidth < years) & (years < slider_date.val)
422
423
            if np.sum(idx) == 0:
424
                continue # we did not select any component from this component, next one
425
426
            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...
427
            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...
428
429
            # get points iside current rectangle for current date
430
            rect_idx = (x1 < x) & ( x < x2) & (y1 < y) & ( y < y2) & idx 
0 ignored issues
show
Coding Style introduced by
No space allowed after bracket
Loading history...
Coding Style introduced by
Trailing whitespace
Loading history...
431
432 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...
433
                textbox.set_val(label)
434
                
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
435
                selected_knot = label
436
                selected_x = x[rect_idx].ravel()
437
                selected_y = y[rect_idx].ravel()
438
                selected_ind = knots[label].index[rect_idx]
439
                
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
440
                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...
441
            
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
442
                textbox.begin_typing(None)
443
                break # if we find selected components in this epoch, continue with renaming
444
            else:
445
                pass
446
447
        # print epoch of selected points:
448
        if selected_knot is not None:
449
            out.clear_output()
450
            out.append_stdout('Selected:\n')
451
            for idx in selected_ind:
452
                #print(f"Selected {mod.loc[idx, 'label']} {mod.loc[idx, 'date']}")
453
                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...
454
                
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
455
        update(slider_date.val)
456
457
458 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...
459
        log.debug('GUI: Key pressed.')
460
        if event.key in ['Q', 'q'] and toggle_selector.RS.active:
461
            log.debug('Selector deactivated.')
462
            toggle_selector.RS.set_active(False)
463
        if event.key in ['S', 's'] and not toggle_selector.RS.active:
464
            log.debug('Selector activated.')
465
            toggle_selector.RS.set_active(True)
466
        if event.key in ['R', 'r']:
467
            log.debug('Selector deactivated.')
468
            toggle_selector.RS.set_active(False)
469
            textbox.begin_typing(None)
470
            #textbox.set_val('')
471
        if event.key in ['E', 'e']:
472
            out.append_stdout('-> Close\n')
473
            plt.close()
474
475
476
    toggle_selector.RS = RectangleSelector(ax, line_select_callback,
477
                                           drawtype='box', useblit=True,
478
                                           button=[1, 3],  # don't use middle button
479
                                           minspanx=0, minspany=0,
480
                                           spancoords='data',
481
                                           interactive=False)
482
483
484
    #plt.connect('key_press_event', toggle_selector)
485
    fig.canvas.mpl_connect('key_press_event', toggle_selector)
486
487
488
489
    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...
490
491
    divider_slider = make_axes_locatable(ax)
492
    slider_ax = divider_slider.append_axes("top", size="3%", pad="4%")  
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
493
    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...
494
    slider_date.on_changed(update)
495
496
    #divider_textbox = make_axes_locatable(ax)
497
    #textbox_ax = divider_textbox.append_axes("bottom", size="3%", pad="4%") 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
498
    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...
499
    textbox = TextBox(textbox_ax, 'Knot name:', initial='None')
500
    textbox.on_submit(submit_textbox)
501
502
503
504
    ax.set_xlim([-1.0, +1.0])
505
    ax.set_ylim([-1.0, +1.0])
506
    ax.set_aspect('equal')
507
508
    fig.suptitle('S to select, R to rename, Q to deactivate selector, E to exit')
509
510
    print('Usage:',
511
          '-> S to select, R to rename, Q to deactivate selector, E to exit',
512
          '-> To delete the knot, name it with a whitespace', 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
513
          '-> You can select points from one component at a time',
514
          '-> If you use the zoom or movement tools, remember to unselect them',
515
          sep='\n')
516
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
517
    plt.show()
518
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
519
    out.display_output()
520
  
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
521
    return mod
522
523
524
525
526
527
528
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...
529
    """
530
        Prompt a GUI to select identified knots and alter their label, reprenting their
531
        time evolution.
532
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
533
        It can be used inside jupyter notebooks, using '%matplotlib widget' first.
534
       
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
535
        Parameters:
536
        -----------
537
         mod : :pd.DataFrame:
538
             pandas.DataFrame containing every knot, with at least columns 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
539
             'label', 'date', 'X', 'Y', 'Flux (Jy)'.
540
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
541
        Returns:
542
        --------
543
         mod : :pd.DataFrame:
544
             pandas.DataFrame containing every knot with their altered labels, with 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
545
             at least columns 'label', 'date', 'X', 'Y', 'Flux (Jy)'.
546
    """
547
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
548
    mod = mod.copy()
549
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
550
    knots = dict(tuple(mod.groupby('label')))
551
    knots_names = list(knots.keys())
552
    knots_values = list(knots.values())
553
    knots_jyears = {k:Time(knots[k]['date'].to_numpy()).jyear for k in knots}
554
    knots_dates = {k:knots[k]['date'].to_numpy() for k in knots}
555
    knots_fluxes = {k:knots[k]['Flux (Jy)'].to_numpy() for k in knots}
556
557
    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...
558
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
559
    out = get_output()
560
561
    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...
562
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
563
    lineas = list()
564
    textos = list()
565
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
566
    def draw_all():
567
        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...
568
569
        for linea in lineas:
570
            if linea is not None:
571
                linea.remove()
572
        for texto in textos:
573
            if texto is not None:
574
                texto.remove()
575
576
        ax.set_prop_cycle(None)
577
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
578
        lineas = list()
579
        textos = list()
580
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
581
        #ax.clear() # either clear the whole axis or remove every artist separetly
582
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
583
        for i, label in enumerate(knots_names):
584
            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...
585
586
            if len(x) > 0:
587
                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...
588
                    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...
589
                else:
590
                    lineas.append(ax.plot(x, y, '.-', linewidth=0.8, alpha=0.5, label=label)[0])
591
            else:
592
                lineas.append(None)
593
                
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
594
            if len(x) > 0:
595
                #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...
596
                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...
597
            else:
598
                textos.append(None)
599
                
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
600
        fig.canvas.draw_idle() # if removed every artist separately instead of ax.clear()
601
602
603
    def update():
604
        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...
605
606
        for i, label in enumerate(knots_names):   
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
607
            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...
608
609 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...
610
                if len(x) > 0:
611
                    lineas[i].set_xdata(x)
612
                    lineas[i].set_ydata(y)
613
                else:
614
                    lineas[i].remove()
615
                    lineas[i] = None
616
            else:
617
                if len(x) > 0:
618
                    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...
619
                        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...
620
                    else:
621
                        lineas[i] = ax.plot(x, y, '.-', linewidth=0.8, alpha=0.5, label=label)[0]
622
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
623
            if textos[i] is not None:
624
                if len(x) > 0:    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
625
                    textos[i].set_position((x[0], y[0]))
626
                    textos[i].set_text(label)
627
                else:
628
                    textos[i].remove()
629
                    textos[i] = None
630
                    #textos[i].set_position((10, 10))
631
            else:
632
                if len(x) > 0:    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
633
                    #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...
634
                    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...
635
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
636
        fig.canvas.draw_idle()    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
637
   
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
638
639
    selected_knot = None
640
    selected_ind = None
641
    selected_date = None
642
    selected_flux = None
643
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
644 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...
645
        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 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_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_fluxes 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...
646
647
        log.debug('Submited with:')
648
        log.debug(f'   selected_knot {selected_knot}')
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
649
        log.debug(f'   selected_ind {selected_ind}')
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
650
        log.debug(f'   selected_flux {selected_flux}')
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
651
        log.debug(f'   selected_date {selected_date}')
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
652
653
        if selected_knot is not None:        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
654
            mod.loc[selected_ind, 'label'] = text.upper().strip(' ')
655
656
            knots = dict(tuple(mod.groupby('label')))
657
            knots_names = list(knots.keys())
658
            knots_values = list(knots.values())
659
            knots_jyears = {k:Time(knots[k]['date'].to_numpy()).jyear for k in knots}
660
            knots_dates = {k:knots[k]['date'].to_numpy() for k in knots}
661
            knots_fluxes = {k:knots[k]['Flux (Jy)'].to_numpy() for k in knots}
662
663
            print(f"Updated index {selected_ind} to {text.upper()}")
664
        else:
665
            pass
666
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
667
        draw_all()
668
669
    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...
670
        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...
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...
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...
671
672
        # 1 eclick and erelease are the press and release events
673
        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...
674
        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...
675
        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...
676
        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...
677
678
        selected_knot = None
679
        selected_date = None
680
        selected_flux = None
681
        selected_ind = None
682
683
        for i, label in enumerate(knots_names):
0 ignored issues
show
Unused Code introduced by
The variable i seems to be unused.
Loading history...
684
            years = knots_jyears[label]
685
            fluxes = knots_fluxes[label]
686
            
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
687
            # get points iside current rectangle for current date
688
            rect_idx = (x1 < years) & ( years < x2) & (y1 < fluxes) & ( fluxes < y2) 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
Coding Style introduced by
No space allowed after bracket
Loading history...
689
            
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
690
            if np.sum(rect_idx) == 0:
691
                continue # we did not select any component from this component, next one
692
693
            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...
694
            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...
695
696 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...
697
                textbox.set_val(label)
698
                selected_knot = label
699
                selected_x = x[rect_idx].ravel()
0 ignored issues
show
Unused Code introduced by
The variable selected_x seems to be unused.
Loading history...
700
                selected_y = y[rect_idx].ravel()
0 ignored issues
show
Unused Code introduced by
The variable selected_y seems to be unused.
Loading history...
701
                selected_ind = knots[label].index[rect_idx]
702
                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...
703
                break # if we find selected components in this epoch, continue with renaming
704
            else:
705
                pass
706
707
        # print epoch of selected points:
708
        if selected_knot is not None:
709
            out.clear_output()
710
            out.append_stdout('Selected:\n')
711
            for idx in selected_ind:
712
                #print(f"Selected {mod.loc[idx, 'label']} {mod.loc[idx, 'date']}")
713
                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...
714
           
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
715
        update()
716
717
718 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...
719
        log.debug('GUI: Key pressed.')
720
        if event.key in ['Q', 'q'] and toggle_selector.RS.active:
721
            log.debug('Selector deactivated.')
722
            toggle_selector.RS.set_active(False)
723
        if event.key in ['S', 's'] and not toggle_selector.RS.active:
724
            log.debug('Selector activated.')
725
            toggle_selector.RS.set_active(True)
726
        if event.key in ['R', 'r']:
727
            log.debug('Selector deactivated.')
728
            toggle_selector.RS.set_active(False)
729
            textbox.begin_typing(None)
730
            #textbox.set_val('')
731
        if event.key in ['E', 'e']:
732
            out.append_stdout('-> Close\n')
733
            plt.close()
734
735
736
    toggle_selector.RS = RectangleSelector(ax, line_select_callback,
737
                                           drawtype='box', useblit=True,
738
                                           button=[1, 3],  # don't use middle button
739
                                           minspanx=0, minspany=0,
740
                                           spancoords='data',
741
                                           interactive=False)
742
743
744
    fig.canvas.mpl_connect('key_press_event', toggle_selector)
745
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
746
    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...
747
748
    divider_textbox = make_axes_locatable(ax)
749
    textbox_ax = divider_textbox.append_axes("bottom", size="10%", pad="15%") 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
750
    #textbox_ax = fig.add_axes([0.3,0,0.5,0.05])
751
    textbox = TextBox(textbox_ax, 'Knot name:', initial='None')
752
    textbox.on_submit(submit_textbox)
753
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
754
    draw_all()
755
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
756
    #ax.autoscale()
757
    ax.set_xlabel('date (year)')
758
    ax.set_ylabel('Flux (Jy)')
759
    ax.set_title('Flux from each component')
760
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
761
    xlims = Time(np.amin(mod['date'])).jyear, Time(np.amax(mod['date'])).jyear
762
    ax.set_xlim((xlims[0]-0.03*np.abs(xlims[1]-xlims[0]), xlims[1]+0.03*np.abs(xlims[1]-xlims[0])))
763
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
764
    fig.suptitle('S to select, R to rename, Q to deactivate selector, E to exit')
765
766
    print('Usage:',
767
          '-> S to select, R to rename, Q to deactivate selector, E to exit',
768
          '-> To delete the knot, name it with a whitespace', 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
769
          '-> You can select points from one component at a time',
770
          '-> If you use the zoom or movement tools, remember to unselect them',
771
          sep='\n')
772
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
773
    plt.show()
774
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
775
    out.display_output()
776
777
    return mod
778
779
780
781
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...
782
    """
783
        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...
784
        to be worked on for labelling and to be used with these GUIs.
785
   
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
786
        Parameters:
787
        -----------
788
         path : :str:
789
             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...
790
             '%Y-%m-%d_mod.mod', for example, path = 'vlbi/ftree/*/*_mod.mod'.
791
             
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
792
        Returns:
793
        -----------
794
         mod : :pd.DataFrame:
795
             pandas.DataFrame containing every knot, with at least columns 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
796
             'label', 'date', 'X', 'Y', 'Flux (Jy)'.
797
    """
798
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
799
    if path is None:
800
        log.error('Path not specified')
801
        raise Exception('Path not specified')
802
            
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
803
    mod_dates_str = list()
804
    mod_dates = list()
805
    mod_data = list()
806
807
    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...
808
        match = re.findall(r'([0-9]{4}-[0-9]{2}-[0-9]{2})_mod.mod', f)
809
        if not len(match) > 0:
810
            continue
811
812
        date_str = match[0]
813
        date = datetime.strptime(date_str, '%Y-%m-%d')
814
815
        mod_dates_str.append(date_str)
816
        mod_dates.append(date)
817
        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...
818
819
    # sort by date    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
820
    idx = np.argsort(mod_dates)
821
    mod_dates_str = list(np.array(mod_dates_str, dtype=object)[idx])
822
    mod_dates = list(np.array(mod_dates, dtype=object)[idx])
823
    mod_data = list(np.array(mod_data, dtype=object)[idx])
824
825
    # fix stupid 'v' in columns, insert a label field, add X, Y columns
826
    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...
827
        mod_data[i].insert(0, 'label', value=None)
828
        mod_data[i].insert(1, 'date', value=mod_dates[i])
829
830
        mod_data[i]['Flux (Jy)'] = mod_data[i]['Flux (Jy)'].str.strip('v').astype(float)
831
        mod_data[i]['Radius (mas)'] = mod_data[i]['Radius (mas)'].str.strip('v').astype(float)
832
        mod_data[i]['Theta (deg)'] = mod_data[i]['Theta (deg)'].str.strip('v').astype(float)
833
834
        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...
835
        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...
836
837
     
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
838
    mod = pd.concat(mod_data, ignore_index=True)
839
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
840
    return mod
841
842
843
844
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...
845
    """
846
        Save Knots data to *_mod.mod files ready to be re-proccessed with diffmap.
847
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
848
        Actually only useful to remove stupid knots and fit it again with diffmap.
849
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
850
        Parameters:
851
        -----------
852
         mod : :pd.DataFrame:
853
             pandas.DataFrame containing every knot
854
         path: :str:
855
             string containing the path to which the files are to be saved, eg:
856
             path = 'my_knots/'
857
         rewrite: :bool:
858
             If rewrite is True, path is interpreted as a regex for which files
859
             to overwrite.
860
         drop_blanks: :bool:
861
             If True, knots without label (or whose label is a whitspace) are dropped.
862
             If False (default), they are saved without label.
863
             
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
864
        Returns:
865
        --------
866
         None
867
    """
868
869
    if path is None:
870
        log.error('Path not specified')
871
        raise Exception('Path not specified')
872
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
873
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
874
    mod = mod.copy()
875
876
877
    if drop_blanks:
878
        mod = mod.drop(mod[mod['label'].str.strip('') == ''].index)
879
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
880
881
    mod_dict = dict(list(mod.groupby('date')))
882
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
883
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
884
    if rewrite:
885
        file_list = list()
886
        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...
887
            match = re.findall(r'([0-9]{4}-[0-9]{2}-[0-9]{2})_mod.mod', f)
888
            
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
889
            if not len(match) > 0:
890
                continue
891
            
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
892
            date = datetime.strptime(match[0], '%Y-%m-%d')
893
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
894
            if date not in mod_dict:
895
                raise Exception('Specified regex includes files for which there are no knots')
896
                
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
897
            file_list.append(f)
898
899
        if len(file_list) != len(mod_dict):
900
            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...
901
    else:
902
        file_list = list()
903
        for date in mod_dict.keys():
904
               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...
905
  
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
906
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
907
    for fname, (date, data) in zip(file_list, mod_dict.items()):
908
        data = data.copy()
909
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
910
        #data = data.drop(columns=['label'])
911
        #data = data.drop(columns=['X'])
912
        #data = data.drop(columns=['Y'])
913
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
914
        data['Flux (Jy)'] = data['Flux (Jy)'].astype(str) + 'v'
915
        data['Radius (mas)'] = data['Radius (mas)'].astype(str) + 'v'
916
        data['Theta (deg)'] = data['Theta (deg)'].astype(str) + 'v'
917
918
        ## add previous labels in comments (so diffmap does not get stuck with it)
919
        data['label'] = '!' + data['label']
920
921
        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...
922
            f.write("! Generated by mutis\n"
923
                    "! Columns\n"
924
                    "! '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...
925
            data.to_csv(f,
926
                        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...
927
                        index=False, sep=' ', header=None)
928
929
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
930
931
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...
932
    """
933
        Read Knots data to .csv files (as done by Svetlana? ##)
934
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
935
        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...
936
        columns should be modified to:
937
        'Date' (jyear), 'MJD', 'X(mas)', 'Y(mas)', 'Flux(Jy)'
938
        These columns are derived from the ones in `mod`, old ones are removed.
939
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
940
        Parameters:
941
        -----------
942
         path: :str:
943
             string containing the path to read files from eg:
944
             path = 'myknows/*.csv'
945
        Returns:
946
        --------
947
         mod : :pd.DataFrame:
948
             pandas.DataFrame containing every knot, with at least columns 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
949
             'label', 'date', 'X', 'Y', 'Flux (Jy)'.
950
    """
951
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
952
    if path is None:
953
        log.error('Path not specified')
954
        raise Exception('Path not specified')
955
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
956
    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...
957
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
958
    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...
959
        match = re.findall(r'/(.*).csv', f)
960
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
961
        if not len(match) > 0:
962
            continue
963
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
964
        knot_name = match[0]
965
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
966
        log.debug(f'Loading {knot_name} from {f}')
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
967
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
968
        knot_data = pd.read_csv(f, parse_dates=['date'], date_parser=pd.to_datetime)
969
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
970
        dataL.append((knot_name, knot_data))
971
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
972
    mod = pd.concat(dict(dataL), ignore_index=True)
973
974
    return mod
975
976
977
978
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...
979
    """
980
        Save Knots data to .csv files (as done by Svetlana? ##)
981
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
982
        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...
983
        columns should be modified to:
984
        'Date' (jyear), 'MJD', 'X(mas)', 'Y(mas)', 'Flux(Jy)'
985
        These columns are derived from the ones in `mod`, old ones are removed.
986
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
987
        Parameters:
988
        -----------
989
         mod : :pd.DataFrame:
990
             pandas.DataFrame containing every knot, with at least columns 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
991
             'label', 'date', 'X', 'Y', 'Flux (Jy)'.
992
         path: :str:
993
             string containing the path to which the files are to be saved, eg:
994
             path = 'my_knots/'
995
             
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
996
        Returns:
997
        --------
998
         None
999
    """
1000
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1001
    if path is None:
1002
        log.error('Path not specified')
1003
        raise Exception('Path not specified')
1004
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1005
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1006
    mod = mod.copy()
1007
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1008
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1009
    mod_dict = dict(list(mod.groupby('label')))
1010
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1011
    for label, data in mod_dict.items():
1012
        data = data.copy()
1013
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1014
        #data.insert(0, 'Date', Time(data['date']).jyear)
1015
        #data.insert(1, 'MJD', Time(data['date']).mjd)
1016
        #data = data.rename(columns={'X': 'X (mas)', 'Y': 'Y (mas)'})
1017
        #data = data.drop(columns=['date'])
1018
        #data = data.drop(columns=['label'])
1019
        #if 'Radius (mas)' in data.columns:
1020
        #    data = data.rename(columns={'Radius (mas)':'R(mas)'})
1021
        #data.columns = data.columns.str.replace(' ', '')
1022
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1023
        data.to_csv(f'{path}/{label}.csv', index=False)
1024
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1025
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1026
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1027
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...
1028
    """
1029
        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...
1030
        to be worked on for labelling and to be used with these GUIs.
1031
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1032
        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...
1033
        it searchs for a hidden label column to load previous label names (unnamed labels
1034
   
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1035
        Parameters:
1036
        -----------
1037
         path : :str:
1038
             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...
1039
             '%Y-%m-%d_mod.mod', for example, path = 'vlbi/ftree/*/*_mod.mod'.
1040
             
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1041
        Returns:
1042
        -----------
1043
         mod : :pd.DataFrame:
1044
             pandas.DataFrame containing every knot, with at least columns 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1045
             'label', 'date', 'X', 'Y', 'Flux (Jy)'.
1046
    """
1047
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1048
    if path is None:
1049
        log.error('Path not specified')
1050
        raise Exception('Path not specified')
1051
            
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1052
    mod_dates_str = list()
1053
    mod_dates = list()
1054
    mod_data = list()
1055
1056
    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...
1057
        match = re.findall(r'([0-9]{4}-[0-9]{2}-[0-9]{2})_mod.mod', f)
1058
        if not len(match) > 0:
1059
            continue
1060
1061
        date_str = match[0]
1062
        date = datetime.strptime(date_str, '%Y-%m-%d')
1063
1064
        mod_dates_str.append(date_str)
1065
        mod_dates.append(date)
1066
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1067
        with open(f) as fobj:
1068
            firstline = fobj.readline()
1069
            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...
1070
                generated_by_mutis = True
1071
            else:
1072
                generated_by_mutis = False
1073
                
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1074
        if generated_by_mutis:
1075
            data = pd.read_csv(f, sep='\s+', 
0 ignored issues
show
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...
Coding Style introduced by
Trailing whitespace
Loading history...
1076
                               skiprows=3, 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1077
                               #converters={'label':(lambda l: '' if l == '' else l)}, 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1078
                               dtype={'label':str},
1079
                               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...
1080
                                      'label'])
1081
            data['label'] = data['label'].str.strip('!')
1082
        else:
1083
            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
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...
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...
1084
            #data.insert(0, 'label', value=None)
1085
            data.insert(0, 'label', value='')
1086
1087
        data.insert(1, 'date', value=date)
1088
1089
        data['Flux (Jy)'] = data['Flux (Jy)'].str.strip('v').astype(float)
1090
        data['Radius (mas)'] = data['Radius (mas)'].str.strip('v').astype(float)
1091
        data['Theta (deg)'] = data['Theta (deg)'].str.strip('v').astype(float)
1092
1093
        data.insert(5, 'X', data['Radius (mas)']*np.cos(np.pi/180*(data['Theta (deg)']-90)))
1094
        data.insert(6, 'Y', data['Radius (mas)']*np.sin(np.pi/180*(data['Theta (deg)']-90)))
1095
1096
        mod_data.append(data)
1097
             
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1098
    # sort by date    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1099
    idx = np.argsort(mod_dates)
1100
    mod_dates_str = list(np.array(mod_dates_str, dtype=object)[idx])
1101
    mod_dates = list(np.array(mod_dates, dtype=object)[idx])
1102
    mod_data = list(np.array(mod_data, dtype=object)[idx])
1103
     
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1104
    mod = pd.concat(mod_data, ignore_index=True)
1105
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1106
    return mod
0 ignored issues
show
Coding Style introduced by
Final newline missing
Loading history...