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

mutis.astro   F

Complexity

Total Complexity 86

Size/Duplication

Total Lines 819
Duplicated Lines 11.36 %

Importance

Changes 0
Metric Value
eloc 447
dl 93
loc 819
rs 2
c 0
b 0
f 0
wmc 86

8 Functions

Rating   Name   Duplication   Size   Complexity  
A KnotsIdReadCSV() 0 44 4
F KnotsId2dGUI() 47 265 26
F KnotsIdAuto() 0 113 20
A pol_angle_reshape() 0 20 4
A KnotsIdSaveMod() 0 2 1
F KnotsIdGUI() 46 219 24
A KnotsIdSaveCSV() 0 46 3
A KnotsIdReadMod() 0 56 4

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
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"]
0 ignored issues
show
Bug introduced by
Undefined variable name 'Astro' in __all__
Loading history...
20
21
log = logging.getLogger(__name__)
22
23
24
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...
25
    """
26
        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...
27
    """
28
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
29
    s = np.array(s)
30
    s = np.mod(s,180) # s % 180
0 ignored issues
show
Coding Style introduced by
Exactly one space required after comma
Loading history...
31
32
    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...
33
    for i in range(1,len(s)):
0 ignored issues
show
Coding Style introduced by
Exactly one space required after comma
Loading history...
34
        #if t[i]-t[i-1] < 35:
35
        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...
36
        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...
37
        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...
38
            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...
39
            if np.abs(s[i]+180*m2-sn[i-1]) < d:
40
                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...
41
                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...
42
        sn[i] = s[i]+180*n
43
    return sn 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
44
45
46
47
48
49
50
#########################################
51
################# Knots #################
52
#########################################
53
54
55
56
def  KnotsIdAuto(mod):
0 ignored issues
show
Comprehensibility introduced by
This function exceeds the maximum number of variables (18/15).
Loading history...
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...
57
    """
58
       Identify the knots appearing in several epochs giving them names, based on their position.
59
       
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
60
        Parameters:
61
        -----------
62
         mod : :pd.DataFrame:
63
             pandas.DataFrame containing every knot, with 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
64
             at least columns 'label', 'date', 'X', 'Y', 'Flux (Jy)'.
65
       
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
66
        Returns: mod
67
        --------
68
         mod : :pd.DataFrame:
69
             pandas.DataFrame containing every knot with their altered labels, with 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
70
             at least columns 'label', 'date', 'X', 'Y', 'Flux (Jy)'.
71
         
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
72
    """
73
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
74
    mod_date_dict = dict(list((mod.groupby('date'))))
75
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
76
    mod_dates = list(Time(list(mod_date_dict.keys())).datetime)
77
    mod_dates_str = list(Time(list(mod_date_dict.keys())).strftime('%Y-%m-%d'))
78
    mod_data = list(mod_date_dict.values())
79
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
80
    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...
81
    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...
82
    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...
83
84
85
    thresh = 0.03 #0.062
86
87
    news = 0
88
89
    for i, (date, data) in enumerate(zip(mod_dates, mod_data)):
0 ignored issues
show
unused-code introduced by
Too many nested blocks (6/5)
Loading history...
Unused Code introduced by
The variable date seems to be unused.
Loading history...
90
        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...
91
92
        if not len(data.index) > 0:
93
            log.error(' -> Error, no components found')
94
            break
95
96
        log.debug(f' it has {len(data.index)} components')
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
97
98
        Bx[i] = np.ravel(data['X'])
99
        By[i] = np.ravel(data['Y'])
100
        B[i] = np.full(len(data.index), fill_value=None)
101
102
        # if first epoch, just give them new names...:
103
        if i == 0:
104
            log.debug(' first epoch, giving names...')
105
106
            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...
107
                if data['Flux (Jy)'].iloc[n] < 0.001:
108
                    log.debug('  skipping, too weak')
109
                    break
110
                if n == 0:
111
                    B[i][n] = 'A0'
112
                else:
113
                    news = news + 1
114
                    B[i][n] = f'B{news}'
115
            log.debug(f' -> FOUND: {B[i]}\n')
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
116
            continue
117
118
        # if not first epoch...:
119
120
        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...
121
            if data['Flux (Jy)'].iloc[n] < 0.001:
122
                    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...
123
                    break
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 16 spaces were expected, but 20 were found.
Loading history...
124
            if n == 0:
125
                B[i][n] = 'A0'
126
            else:
127
                log.debug(f' -> id component {n}...')
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
128
129
                close = None
130
131
                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...
132
                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...
133
                    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...
134
135
                    if not len(Bx[i-a])>0:
0 ignored issues
show
Coding Style introduced by
Exactly one space required around comparison
Loading history...
136
                        break
137
138
                    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 before bracket
Loading history...
Coding Style introduced by
No space allowed after bracket
Loading history...
139
140
                    for m in range(len(dist)):
0 ignored issues
show
unused-code introduced by
Consider using enumerate instead of iterating with range and len
Loading history...
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...
141
                        if B[i-a][m] in B[i]:
142
                            dist[m] = np.inf
143
144
                    if np.amin(dist) < thresh*a**1.5:
145
                        close = np.argmin(dist)
146
147
                    if B[i-a][close] in B[i]:
148
                            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...
149
150
151
                if close is None:
152
                    news = news + 1
153
                    B[i][n] = f'B{news}'
154
                    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...
155
                else:
156
                    log.debug(f'   component {n} is close to {B[i-a][close]} of previous epoch ({a} epochs before)')
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (116/100).

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

Loading history...
introduced by
Use lazy % formatting in logging functions
Loading history...
157
                    B[i][n] = B[i-a][close]
158
159
160
        log.debug(f' -> FOUND: {B[i]}\n')
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
161
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
162
                 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
163
    for i, (date, data) in enumerate(zip(mod_dates, mod_data)):
164
        data['label'] = B[i]
165
         
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
166
    mod = pd.concat(mod_data, ignore_index=True)
167
            
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
168
    return mod
169
170
171
172
def KnotsId2dGUI(mod, use_arrows=False, arrow_pos=1.0):
0 ignored issues
show
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...
Comprehensibility introduced by
This function exceeds the maximum number of variables (33/15).
Loading history...
173
    """
174
        Prompt a GUI to select identified knots and alter their label, reprenting their 2D
175
        spatial distribution in different times.
176
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
177
        It can be used inside jupyter notebooks, using '%matplotlib widget' first.
178
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
179
        Parameters:
180
        -----------
181
         mod : :pd.DataFrame:
182
             pandas.DataFrame containing every knot, with at least columns 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
183
             'label', 'date', 'X', 'Y', 'Flux (Jy)'.
184
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
185
        Returns:
186
        --------
187
         mod : :pd.DataFrame:
188
             pandas.DataFrame containing every knot with their altered labels, with 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
189
             at least columns 'label', 'date', 'X', 'Y', 'Flux (Jy)'.
190
    """
191
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
192
    mod = mod.copy()
193
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
194
    knots = dict(tuple(mod.groupby('label')))
195
    knots_names = list(knots.keys())
196
    knots_values = list(knots.values())
197
    knots_jyears = {k:Time(knots[k]['date'].to_numpy()).jyear for k in knots}
198
    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...
199
    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...
200
201
202
    from matplotlib.widgets import Slider, Button, TextBox, RectangleSelector
0 ignored issues
show
Unused Code introduced by
Unused Button imported from matplotlib.widgets
Loading history...
introduced by
Import outside toplevel (matplotlib.widgets.Slider, matplotlib.widgets.Button, matplotlib.widgets.TextBox, matplotlib.widgets.RectangleSelector)
Loading history...
introduced by
Unable to import 'matplotlib.widgets'
Loading history...
203
204
    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...
205
206
    lineas = list()
207
    flechas = list()
208
    textos = list()
209
210
    def draw_all(val=2008):
211
        nonlocal lineas, flechas, textos
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable textos does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable flechas does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable lineas does not seem to be defined.
Loading history...
212
213
        # instead of clearing the whole axis, remove artists
214
        for linea in lineas:
215
            if linea is not None:
216
                linea.remove()
217
        for texto in textos:
218
            if texto is not None:
219
                texto.remove()
220
        for flecha in flechas:
221
            if flecha is not None:
222
                flecha.remove()
223
        ax.set_prop_cycle(None)
224
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
225
        lineas = list()
226
        flechas = list()
227
        textos = list()
228
229
        xlim, ylim = ax.get_xlim(), ax.get_ylim()
230
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
231
        #ax.clear() # either clear the whole axis or remove every artist separetly
232
            
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
233
        for i, label in enumerate(knots_names):
234
            years = knots_jyears[label]
235
            idx = (val-1.5 < years) & (years < val)
236
            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...
237
            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...
238
239
            lineas.append(ax.plot(x, y, '.-', linewidth=0.6, alpha=0.4, label=label)[0])
240
241
            if use_arrows:
242
                if len(x) > 1:
243
                    flechas.append(ax.quiver(x[:-1], 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
244
                               y[:-1], 
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (add 14 spaces).
Loading history...
Coding Style introduced by
Trailing whitespace
Loading history...
245
                               arrow_pos*(x[1:] - x[:-1]), 
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (add 14 spaces).
Loading history...
Coding Style introduced by
Trailing whitespace
Loading history...
246
                               arrow_pos*(y[1:] - y[:-1]), 
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (add 14 spaces).
Loading history...
Coding Style introduced by
Trailing whitespace
Loading history...
247
                               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...
248
                               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...
249
                               alpha=0.5, color=lineas[i].get_color()))
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (add 14 spaces).
Loading history...
250
                else:
251
                    flechas.append(None)
252
253
            if len(x) > 0:
254
                #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...
255
                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...
256
            else:
257
                textos.append(None)
258
259
        ax.set_xlim(xlim)
260
        ax.set_ylim(ylim)
261
        ax.set_aspect('equal')
262
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
263
        fig.canvas.draw_idle() # if removed every artist separately instead of ax.clear()
264
265
    draw_all()
266
267
    def update(val):
268
        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 textos does not seem to be defined.
Loading history...
269
270
        for i, label in enumerate(knots_names):
271
            years = knots_jyears[label]
272
            idx = (val-1.5 < years) & (years < val)
273
            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...
274
            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...
275
276
            lineas[i].set_xdata(x)
277
            lineas[i].set_ydata(y)
278
279
            if textos[i] is not None:
280
                if len(x) > 0:    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
281
                    textos[i].set_position((x[-1]+0.015, y[-1]+0.015))
282
                    textos[i].set_text(label)
283
                else:
284
                    textos[i].remove()
285
                    textos[i] = None
286
                    #textos[i].set_position((10, 10))
287
            else:
288
                if len(x) > 0:    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
289
                    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...
290
291
            if use_arrows:
292
                if flechas[i] is not None:
293
                    flechas[i].remove()
294
                    flechas[i] = None
295
296
                flechas[i] = 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
Wrong continued indentation (add 4 spaces).
Loading history...
Coding Style introduced by
Trailing whitespace
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 4 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 4 spaces).
Loading history...
300
                                   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...
301
                                   width=0.0015, headwidth=10, headlength=10, headaxislength=6, 
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (add 4 spaces).
Loading history...
Coding Style introduced by
Trailing whitespace
Loading history...
302
                                   alpha=0.5, color=lineas[i].get_color())
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (add 4 spaces).
Loading history...
303
304
        fig.canvas.draw_idle()
305
306
307
308
    selected_knot = None
309
    selected_ind = None
310
    selected_x = None
311
    selected_y = None
312
313
314 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...
315
        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_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_Y does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable knots does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable knots_X 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...
316
317
        log.debug('Submited with:')
318
        log.debug(f'   selected_knot {selected_knot}')
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
319
        log.debug(f'   selected_ind {selected_ind}')
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
320
        log.debug(f'   selected_x {selected_x}')
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
321
        log.debug(f'   selected_y {selected_y}')
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
322
323
        if selected_knot is not None:        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
324
            mod.loc[selected_ind, 'label'] = text.upper()
325
326
            knots = dict(tuple(mod.groupby('label')))
327
            knots_names = list(knots.keys())
328
            knots_values = list(knots.values())
329
            knots_jyears = {k:Time(knots[k]['date'].to_numpy()).jyear for k in knots}
330
            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...
331
            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...
332
333
            print(f"Updated index {selected_ind} to {text.upper()}")
334
        else:
335
            pass
336
337
        draw_all(slider_date.val)
338
339
    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...
340
        nonlocal selected_knot,selected_x, selected_y, selected_ind
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable selected_x does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable selected_knot does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable selected_ind does not seem to be defined.
Loading history...
Coding Style introduced by
Exactly one space required after comma
Loading history...
Comprehensibility Best Practice introduced by
The variable selected_y does not seem to be defined.
Loading history...
341
342
        # 1 eclick and erelease are the press and release events
343
        x1, y1 = eclick.xdata, eclick.ydata
0 ignored issues
show
Coding Style Naming introduced by
Variable name "x1" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

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

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

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

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

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

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

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

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

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

Loading history...
344
        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...
345
        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...
346
        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...
347
348
        selected_knot = None
349
        selected_x = None
350
        selected_y = None
351
        selected_ind = None
352
353
        for i, label in enumerate(knots_names):
0 ignored issues
show
Unused Code introduced by
The variable i seems to be unused.
Loading history...
354
            years = knots_jyears[label]
355
            idx = (slider_date.val-1.5 < years) & (years < slider_date.val)
356
357
            if np.sum(idx) == 0:
358
                continue # we did not select any component from this component, next one
359
360
            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...
361
            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...
362
363
            # get points iside current rectangle for current date
364
            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...
365
366 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...
367
                textbox.set_val(label)
368
                selected_knot = label
369
                selected_x = x[rect_idx].ravel()
370
                selected_y = y[rect_idx].ravel()
371
                selected_ind = knots[label].index[rect_idx]
372
                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...
373
                textbox.begin_typing(None)
374
                break # if we find selected components in this epoch, continue with renaming
375
            else:
376
                pass
377
378
        update(slider_date.val)
379
380
381 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...
382
        log.debug('GUI: Key pressed.')
383
        if event.key in ['Q', 'q'] and toggle_selector.RS.active:
384
            log.debug('Selector deactivated.')
385
            toggle_selector.RS.set_active(False)
386
        if event.key in ['S', 's'] and not toggle_selector.RS.active:
387
            log.debug('Selector activated.')
388
            toggle_selector.RS.set_active(True)
389
        if event.key in ['R', 'r']:
390
            log.debug('Selector deactivated.')
391
            toggle_selector.RS.set_active(False)
392
            textbox.begin_typing(None)
393
            #textbox.set_val('')
394
395
396
    toggle_selector.RS = RectangleSelector(ax, line_select_callback,
397
                                           drawtype='box', useblit=True,
398
                                           button=[1, 3],  # don't use middle button
399
                                           minspanx=0, minspany=0,
400
                                           spancoords='data',
401
                                           interactive=False)
402
403
404
    #plt.connect('key_press_event', toggle_selector)
405
    fig.canvas.mpl_connect('key_press_event', toggle_selector)
406
407
408
409
    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...
410
411
    divider_slider = make_axes_locatable(ax)
412
    slider_ax = divider_slider.append_axes("top", size="3%", pad="4%")  
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
413
    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...
414
    slider_date.on_changed(update)
415
416
    #divider_textbox = make_axes_locatable(ax)
417
    #textbox_ax = divider_textbox.append_axes("bottom", size="3%", pad="4%") 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
418
    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...
419
    textbox = TextBox(textbox_ax, 'Knot name:', initial='None')
420
    textbox.on_submit(submit_textbox)
421
422
423
424
    ax.set_xlim([-1.0, +1.0])
425
    ax.set_ylim([-1.0, +1.0])
426
    ax.set_aspect('equal')
427
428
    fig.suptitle('S to select, R to rename, Q to deactivate selector')
429
430
    print('S to select, R to rename, Q to deactivate selector')
431
    print('(you can select points from one component at a time)')
432
    print('(if you use the zoom or movement tools, remember to unselect them)')
433
434
    plt.show()
435
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
436
    return mod
437
438
439
440
441
442
443
def KnotsIdGUI(mod):
0 ignored issues
show
Comprehensibility introduced by
This function exceeds the maximum number of variables (27/15).
Loading history...
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...
444
    """
445
        Prompt a GUI to select identified knots and alter their label, reprenting their
446
        time evolution.
447
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
448
        It can be used inside jupyter notebooks, using '%matplotlib widget' first.
449
       
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
450
        Parameters:
451
        -----------
452
         mod : :pd.DataFrame:
453
             pandas.DataFrame containing every knot, with at least columns 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
454
             'label', 'date', 'X', 'Y', 'Flux (Jy)'.
455
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
456
        Returns:
457
        --------
458
         mod : :pd.DataFrame:
459
             pandas.DataFrame containing every knot with their altered labels, with 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
460
             at least columns 'label', 'date', 'X', 'Y', 'Flux (Jy)'.
461
    """
462
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
463
    mod = mod.copy()
464
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
465
    knots = dict(tuple(mod.groupby('label')))
466
    knots_names = list(knots.keys())
467
    knots_values = list(knots.values())
468
    knots_jyears = {k:Time(knots[k]['date'].to_numpy()).jyear for k in knots}
469
    knots_dates = {k:knots[k]['date'].to_numpy() for k in knots}
470
    knots_fluxes = {k:knots[k]['Flux (Jy)'].to_numpy() for k in knots}
471
472
    from matplotlib.widgets import TextBox, RectangleSelector
0 ignored issues
show
introduced by
Import outside toplevel (matplotlib.widgets.TextBox, matplotlib.widgets.RectangleSelector)
Loading history...
introduced by
Unable to import 'matplotlib.widgets'
Loading history...
473
474
    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...
475
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
476
    lineas = list()
477
    textos = list()
478
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
479
    def draw_all():
480
        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...
481
482
        for linea in lineas:
483
            if linea is not None:
484
                linea.remove()
485
        for texto in textos:
486
            if texto is not None:
487
                texto.remove()
488
489
        ax.set_prop_cycle(None)
490
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
491
        lineas = list()
492
        textos = list()
493
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
494
        #ax.clear() # either clear the whole axis or remove every artist separetly
495
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
496
        for i, label in enumerate(knots_names):
497
            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...
498
499
            if len(x) > 0:
500
                lineas.append(ax.plot(x, y, '.-', linewidth=0.8, alpha=0.5, label=label)[0])
501
            else:
502
                lineas.append(None)
503
                
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
504
            if len(x) > 0:
505
                #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...
506
                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...
507
            else:
508
                textos.append(None)
509
                
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
510
        fig.canvas.draw_idle() # if removed every artist separately instead of ax.clear()
511
512
513
    def update():
514
        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...
515
516
        for i, label in enumerate(knots_names):   
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
517
            x, y = knots_jyears[label], knots_fluxes[label]
0 ignored issues
show
Coding Style Naming introduced by
Variable name "y" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

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

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

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

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

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

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

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

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

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

Loading history...
518
519
            if lineas[i] is not None:
520
                if len(x) > 0:
521
                    lineas[i].set_xdata(x)
522
                    lineas[i].set_ydata(y)
523
                else:
524
                    lineas[i].remove()
525
                    lineas[i] = None
526
            else:
527
                if len(x) > 0:    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
528
                    lineas[i] = ax.plot(x, y, '.-', linewidth=0.8, alpha=0.5, label=label)[0]
529
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
530
            if textos[i] is not None:
531
                if len(x) > 0:    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
532
                    textos[i].set_position((x[0], y[0]))
533
                    textos[i].set_text(label)
534
                else:
535
                    textos[i].remove()
536
                    textos[i] = None
537
                    #textos[i].set_position((10, 10))
538
            else:
539
                if len(x) > 0:    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
540
                    #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...
541
                    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...
542
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
543
        fig.canvas.draw_idle()    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
544
   
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
545
546
    selected_knot = None
547
    selected_ind = None
548
    selected_date = None
549
    selected_flux = None
550
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
551 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...
552
        nonlocal mod, knots, knots_names, knots_values, knots_jyears, knots_dates, knots_fluxes
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable knots_jyears does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable knots_dates does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable knots_fluxes does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable knots does not seem to be defined.
Loading history...
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...
553
554
        log.debug('Submited with:')
555
        log.debug(f'   selected_knot {selected_knot}')
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
556
        log.debug(f'   selected_ind {selected_ind}')
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
557
        log.debug(f'   selected_flux {selected_flux}')
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
558
        log.debug(f'   selected_date {selected_date}')
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
559
560
        if selected_knot is not None:        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
561
            mod.loc[selected_ind, 'label'] = text.upper()
562
563
            knots = dict(tuple(mod.groupby('label')))
564
            knots_names = list(knots.keys())
565
            knots_values = list(knots.values())
566
            knots_jyears = {k:Time(knots[k]['date'].to_numpy()).jyear for k in knots}
567
            knots_dates = {k:knots[k]['date'].to_numpy() for k in knots}
568
            knots_fluxes = {k:knots[k]['Flux (Jy)'].to_numpy() for k in knots}
569
570
            print(f"Updated index {selected_ind} to {text.upper()}")
571
        else:
572
            pass
573
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
574
        draw_all()
575
576
    def line_select_callback(eclick, erelease):
0 ignored issues
show
Comprehensibility introduced by
This function exceeds the maximum number of variables (19/15).
Loading history...
577
        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_knot 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_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...
578
579
        # 1 eclick and erelease are the press and release events
580
        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...
581
        x2, y2 = erelease.xdata, erelease.ydata
0 ignored issues
show
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...
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...
582
        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...
583
        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...
584
585
        selected_knot = None
586
        selected_date = None
587
        selected_flux = None
588
        selected_ind = None
589
590
        for i, label in enumerate(knots_names):
0 ignored issues
show
Unused Code introduced by
The variable i seems to be unused.
Loading history...
591
            years = knots_jyears[label]
592
            fluxes = knots_fluxes[label]
593
            
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
594
            # get points iside current rectangle for current date
595
            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...
596
            
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
597
            if np.sum(rect_idx) == 0:
598
                continue # we did not select any component from this component, next one
599
600
            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...
601
            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...
602
603 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...
604
                textbox.set_val(label)
605
                selected_knot = label
606
                selected_x = x[rect_idx].ravel()
0 ignored issues
show
Unused Code introduced by
The variable selected_x seems to be unused.
Loading history...
607
                selected_y = y[rect_idx].ravel()
0 ignored issues
show
Unused Code introduced by
The variable selected_y seems to be unused.
Loading history...
608
                selected_ind = knots[label].index[rect_idx]
609
                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
introduced by
Use lazy % formatting in logging functions
Loading history...
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...
610
                break # if we find selected components in this epoch, continue with renaming
611
            else:
612
                pass
613
614
        update()
615
616
617 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...
618
        log.debug('GUI: Key pressed.')
619
        if event.key in ['Q', 'q'] and toggle_selector.RS.active:
620
            log.debug('Selector deactivated.')
621
            toggle_selector.RS.set_active(False)
622
        if event.key in ['S', 's'] and not toggle_selector.RS.active:
623
            log.debug('Selector activated.')
624
            toggle_selector.RS.set_active(True)
625
        if event.key in ['R', 'r']:
626
            log.debug('Selector deactivated.')
627
            toggle_selector.RS.set_active(False)
628
            textbox.begin_typing(None)
629
            #textbox.set_val('')
630
631
632
    toggle_selector.RS = RectangleSelector(ax, line_select_callback,
633
                                           drawtype='box', useblit=True,
634
                                           button=[1, 3],  # don't use middle button
635
                                           minspanx=0, minspany=0,
636
                                           spancoords='data',
637
                                           interactive=False)
638
639
640
    fig.canvas.mpl_connect('key_press_event', toggle_selector)
641
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
642
    from mpl_toolkits.axes_grid1 import make_axes_locatable
0 ignored issues
show
introduced by
Import outside toplevel (mpl_toolkits.axes_grid1.make_axes_locatable)
Loading history...
introduced by
Unable to import 'mpl_toolkits.axes_grid1'
Loading history...
643
644
    divider_textbox = make_axes_locatable(ax)
645
    textbox_ax = divider_textbox.append_axes("bottom", size="10%", pad="15%") 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
646
    #textbox_ax = fig.add_axes([0.3,0,0.5,0.05])
647
    textbox = TextBox(textbox_ax, 'Knot name:', initial='None')
648
    textbox.on_submit(submit_textbox)
649
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
650
    draw_all()
651
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
652
    #ax.autoscale()
653
    ax.set_xlabel('date (year)')
654
    ax.set_ylabel('Flux (Jy)')
655
    ax.set_title('Flux from each component')
656
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
657
    xlims = Time(np.amin(mod['date'])).jyear, Time(np.amax(mod['date'])).jyear
658
    ax.set_xlim((xlims[0]-0.03*np.abs(xlims[1]-xlims[0]), xlims[1]+0.03*np.abs(xlims[1]-xlims[0])))
659
    plt.show()
660
661
    return mod
662
663
664
665
def KnotsIdReadMod(path=None, file_list=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...
Unused Code introduced by
The argument file_list seems to be unused.
Loading history...
666
    """
667
        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...
668
        to be worked on for labelling and to be used with these GUIs.
669
   
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
670
        Parameters:
671
        -----------
672
         path : :str:
673
             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...
674
             '%Y-%m-%d_mod.mod', for example, path = 'vlbi/ftree/*/*_mod.mod'.
675
             
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
676
        Returns:
677
        -----------
678
         mod : :pd.DataFrame:
679
             pandas.DataFrame containing every knot, with at least columns 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
680
             'label', 'date', 'X', 'Y', 'Flux (Jy)'.
681
    """
682
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
683
    mod_dates_str = list()
684
    mod_dates = list()
685
    mod_data = list()
686
687
    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...
688
        match = re.findall(r'([0-9]{4}-[0-9]{2}-[0-9]{2})_mod.mod', f)
689
        if not len(match) > 0:
690
            continue
691
692
        date_str = match[0]
693
        date = datetime.strptime(date_str, '%Y-%m-%d')
694
695
        mod_dates_str.append(date_str)
696
        mod_dates.append(date)
697
        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
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 (194/100).

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

Loading history...
698
699
    # sort by date    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
700
    idx = np.argsort(mod_dates)
701
    mod_dates_str = list(np.array(mod_dates_str, dtype=object)[idx])
702
    mod_dates = list(np.array(mod_dates, dtype=object)[idx])
703
    mod_data = list(np.array(mod_data, dtype=object)[idx])
704
705
    # fix stupid 'v' in columns, insert a label field, add X, Y columns
706
    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...
707
        mod_data[i].insert(0, 'label', value=None)
708
        mod_data[i].insert(1, 'date', value=mod_dates[i])
709
710
        mod_data[i]['Flux (Jy)'] = mod_data[i]['Flux (Jy)'].str.strip('v').astype(float)
711
        mod_data[i]['Radius (mas)'] = mod_data[i]['Radius (mas)'].str.strip('v').astype(float)
712
        mod_data[i]['Theta (deg)'] = mod_data[i]['Theta (deg)'].str.strip('v').astype(float)
713
714
        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...
715
        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...
716
717
     
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
718
    mod = pd.concat(mod_data, ignore_index=True)
719
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
720
    return mod
721
722
723
def KnotsIdSaveMod(mod, path=None):
0 ignored issues
show
Unused Code introduced by
The argument path seems to be unused.
Loading history...
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...
Unused Code introduced by
The argument mod seems to be unused.
Loading history...
introduced by
Missing function or method docstring
Loading history...
724
    pass
725
726
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...
727
    """
728
        Read Knots data to .csv files (as done by Svetlana? ##)
729
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
730
        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...
731
        columns should be modified to:
732
        'Date' (jyear), 'MJD', 'X(mas)', 'Y(mas)', 'Flux(Jy)'
733
        These columns are derived from the ones in `mod`, old ones are removed.
734
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
735
        Parameters:
736
        -----------
737
         path: :str:
738
             string containing the path to read files from eg:
739
             path = 'myknows/*.csv'
740
        Returns:
741
        --------
742
         mod : :pd.DataFrame:
743
             pandas.DataFrame containing every knot, with at least columns 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
744
             'label', 'date', 'X', 'Y', 'Flux (Jy)'.
745
    """
746
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
747
    if path is None:
748
        log.error('Path not specified')
749
        raise Exception('Path not specified')
750
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
751
    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...
752
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
753
    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...
754
        match = re.findall(r'/(.*).csv', f)
755
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
756
        if not len(match) > 0:
757
            continue
758
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
759
        knot_name = match[0]
760
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
761
        log.debug(f'Loading {knot_name} from {f}')
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
762
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
763
        knot_data = pd.read_csv(f, parse_dates=['date'], date_parser=pd.to_datetime)
764
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
765
        dataL.append((knot_name, knot_data))
766
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
767
    mod = pd.concat(dict(dataL), ignore_index=True)
768
769
    return mod
770
771
772
773
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...
774
    """
775
        Save Knots data to .csv files (as done by Svetlana? ##)
776
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
777
        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...
778
        columns should be modified to:
779
        'Date' (jyear), 'MJD', 'X(mas)', 'Y(mas)', 'Flux(Jy)'
780
        These columns are derived from the ones in `mod`, old ones are removed.
781
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
782
        Parameters:
783
        -----------
784
         mod : :pd.DataFrame:
785
             pandas.DataFrame containing every knot, with at least columns 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
786
             'label', 'date', 'X', 'Y', 'Flux (Jy)'.
787
         path: :str:
788
             string containing the path to which the files are to be saved, eg:
789
             path = 'my_knots/'
790
             
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
791
        Returns:
792
        --------
793
         None
794
    """
795
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
796
    if path is None:
797
        log.error('Path not specified')
798
        raise Exception('Path not specified')
799
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
800
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
801
    mod = mod.copy()
802
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
803
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
804
    mod_dict = dict(list(mod.groupby('label')))
805
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
806
    for label, data in mod_dict.items():
807
        data = data.copy()
808
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
809
        #data.insert(0, 'Date', Time(data['date']).jyear)
810
        #data.insert(1, 'MJD', Time(data['date']).mjd)
811
        #data = data.rename(columns={'X': 'X (mas)', 'Y': 'Y (mas)'})
812
        #data = data.drop(columns=['date'])
813
        #data = data.drop(columns=['label'])
814
        #if 'Radius (mas)' in data.columns:
815
        #    data = data.rename(columns={'Radius (mas)':'R(mas)'})
816
        #data.columns = data.columns.str.replace(' ', '')
817
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
818
        data.to_csv(f'{path}/{label}.csv', index=False) 
0 ignored issues
show
Coding Style introduced by
Final newline missing
Loading history...