readerbotda 1.4.0__tar.gz → 1.4.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: readerbotda
3
- Version: 1.4.0
3
+ Version: 1.4.2
4
4
  Summary: Pacchetto per lettura e visualizzazione file di log sensore BOTDA Cohaerentia
5
5
  Author: Marco Brunero
6
6
  Author-email: marco.brunero@cohaerentia.com
@@ -0,0 +1,44 @@
1
+ from abc import ABC, abstractmethod
2
+ import numpy.typing as npt
3
+
4
+
5
+ class Plotter(ABC):
6
+
7
+ @abstractmethod
8
+ def single_plot(self, position, profile, title: str = None):
9
+ pass
10
+
11
+ @abstractmethod
12
+ def multiple_plot(self, position, profiles, timestamps, title: str = ""):
13
+ pass
14
+
15
+ @abstractmethod
16
+ def statistics(self, position, mean, std, title: str = ""):
17
+ pass
18
+
19
+ @abstractmethod
20
+ def raw2d_plot(self, position, frequency, BGS, title: str = None):
21
+ pass
22
+
23
+ @abstractmethod
24
+ def rawBGS_plot(
25
+ self,
26
+ frequency,
27
+ BGS,
28
+ positions_m: npt.ArrayLike,
29
+ index: int = None,
30
+ title: str = None,
31
+ ):
32
+ pass
33
+
34
+ @abstractmethod
35
+ def raw3d_plot(self, position, frequency, BGS, title: str = None):
36
+ pass
37
+
38
+ @abstractmethod
39
+ def max_plot(self, position, max, title: str = None):
40
+ pass
41
+
42
+ @abstractmethod
43
+ def max_stat_plot(self, max_mean, max_std, title: str = ""):
44
+ pass
@@ -0,0 +1,115 @@
1
+ from .abc import Plotter
2
+
3
+ from bokeh.plotting import figure
4
+ from bokeh.models.layouts import Column
5
+ from bokeh.plotting.figure import Figure as bokehFigure
6
+ from bokeh.plotting import show as bokehShow
7
+ from bokeh.models import Legend
8
+ from bokeh.layouts import gridplot
9
+ from bokeh.palettes import Bokeh8
10
+ from bokeh.io import curdoc
11
+
12
+ import numpy as np
13
+ import numpy.typing as npt
14
+
15
+
16
+ class Bokeh(Plotter):
17
+ def __init__(self, theme: str = "caliber"):
18
+ curdoc().theme = theme
19
+ # TODO: capire come prendere la palette del tema scelto, invece che usare sempre Bokeh8.
20
+ self.palette = Bokeh8
21
+
22
+ def single_plot(self, position, profile, title: str = None) -> bokehFigure:
23
+ fig = figure(
24
+ title=title,
25
+ x_axis_label="Position (m)",
26
+ y_axis_label="BFS (MHz)",
27
+ sizing_mode="stretch_width",
28
+ )
29
+ fig.line(position, profile)
30
+ return fig
31
+
32
+ def multiple_plot(
33
+ self, position, profiles, timestamps, title: str = ""
34
+ ) -> bokehFigure:
35
+ fig = figure(
36
+ title=title,
37
+ x_axis_label="Position (m)",
38
+ y_axis_label="BFS (MHz)",
39
+ sizing_mode="stretch_width",
40
+ )
41
+ fig.add_layout(Legend(), "right")
42
+ for i, (time, color) in enumerate(zip(timestamps, self.palette)):
43
+ fig.line(
44
+ x=position,
45
+ y=profiles[:, i],
46
+ color=color,
47
+ legend_label=time.strftime("%m/%d/%Y, %H:%M:%S"),
48
+ )
49
+ return fig
50
+
51
+ def statistics(
52
+ self, position, mean: np.ndarray, std: np.ndarray, title: str = ""
53
+ ) -> Column:
54
+ f1 = figure(title=title, y_axis_label="Mean BFS (MHz)")
55
+ f1.line(x=position, y=mean)
56
+ f1.varea(x=position, y1=mean + std, y2=mean - std, fill_alpha=0.3)
57
+ f2 = figure(
58
+ x_axis_label="Position (m)", y_axis_label="Std Dev (MHz)", y_range=(0, 10)
59
+ )
60
+ f2.line(x=position, y=std)
61
+ return gridplot([f1, f2], ncols=1, height=150, sizing_mode="stretch_width")
62
+
63
+ def max_plot(self, position, max, title: str = None) -> bokehFigure:
64
+ fig = figure(
65
+ title=title,
66
+ x_axis_label="Position (m)",
67
+ y_axis_label="Max BGS Amplitude",
68
+ sizing_mode="stretch_width",
69
+ )
70
+ fig.line(x=position, y=max)
71
+ return fig
72
+
73
+ def max_stat_plot(
74
+ self, max_mean: np.ndarray, max_std: np.ndarray, title: str = ""
75
+ ) -> bokehFigure:
76
+ fig = figure(
77
+ title=title, y_axis_label="Max BGS (Volts)", sizing_mode="stretch_width"
78
+ )
79
+ fig.line(y=max_mean)
80
+ fig.varea(y1=max_mean + max_std, y2=max_mean - max_std, fill_alpha=0.3)
81
+ return fig
82
+
83
+ def rawBGS_plot(
84
+ self,
85
+ frequency,
86
+ BGS,
87
+ positions_m: npt.ArrayLike = None,
88
+ index: int = None,
89
+ title: str = None,
90
+ ) -> bokehFigure:
91
+ fig = figure(
92
+ title=title,
93
+ x_axis_label="Frequency (GHz)",
94
+ y_axis_label="Amplitude (V)",
95
+ sizing_mode="stretch_width",
96
+ )
97
+ if not index:
98
+ for single in np.transpose(BGS):
99
+ fig.line(x=frequency, y=single)
100
+ else:
101
+ for single in np.transpose(BGS):
102
+ fig.line(x=frequency, y=single, color="rgba(175,175,175,0.15)")
103
+ fig.line(x=frequency, y=BGS[:, index])
104
+ return fig
105
+
106
+ def raw3d_plot(self, position, frequency, BGS, title: str = None):
107
+ raise NameError("Function raw3d_plot not yet defined for Bokeh plotter.")
108
+
109
+ def raw2d_plot(self, position, frequency, BGS, title: str = None):
110
+ raise NameError("Function raw2d_plot not yet defined for Bokeh plotter.")
111
+
112
+ @staticmethod
113
+ def show(fig) -> None:
114
+ bokehShow(fig)
115
+ pass
@@ -8,6 +8,7 @@ from plotly.subplots import make_subplots
8
8
 
9
9
  from datetime import datetime
10
10
  import numpy as np
11
+ import numpy.typing as npt
11
12
 
12
13
 
13
14
  class Plotly(Plotter):
@@ -201,12 +202,17 @@ class Plotly(Plotter):
201
202
  return self._applyTheme(fig)
202
203
 
203
204
  def rawBGS_plot(
204
- self, frequency, BGS, index: int = None, title: str = None
205
+ self,
206
+ frequency,
207
+ BGS,
208
+ positions_m: npt.ArrayLike,
209
+ index: int = None,
210
+ title: str = None,
205
211
  ) -> go.Figure:
206
212
  fig = go.Figure(
207
213
  layout=dict(
208
214
  title=title,
209
- hovermode=False,
215
+ # hovermode=False,
210
216
  xaxis=dict(title=dict(text="Frequency (GHz)")),
211
217
  yaxis=dict(title=dict(text="Amplitude (V)")),
212
218
  )
@@ -225,6 +231,11 @@ class Plotly(Plotter):
225
231
  line=dict(color="rgba(175,175,175,0.15)"),
226
232
  mode="lines",
227
233
  showlegend=False,
234
+ hovertext=[
235
+ f"Position: {positions_m[i]:.2f} m"
236
+ for _ in range(len(frequency))
237
+ ],
238
+ hoverinfo="text",
228
239
  )
229
240
  )
230
241
  fig.add_trace(
@@ -234,6 +245,11 @@ class Plotly(Plotter):
234
245
  line=dict(color=self.firstColor),
235
246
  mode="lines",
236
247
  showlegend=False,
248
+ hovertext=[
249
+ f"Position: {positions_m[index]:.2f} m"
250
+ for _ in range(len(frequency))
251
+ ],
252
+ hoverinfo="text",
237
253
  )
238
254
  )
239
255
  return self._applyTheme(fig)
@@ -224,6 +224,15 @@ class multipleProfile:
224
224
  )
225
225
  return self.statistics
226
226
 
227
+ def deleteMeasures(self, indices: Union[int, list[int]]):
228
+ """Delete measures from the dataset."""
229
+ if isinstance(indices, int):
230
+ indices = [indices]
231
+ self.BFS = np.delete(self.BFS, indices, axis=1)
232
+ self.MaxGain = np.delete(self.MaxGain, indices, axis=1)
233
+ self.timestamps = np.delete(self.timestamps, indices)
234
+ self.calcStatistics()
235
+
227
236
  def plotStatistics(self, title: str = None):
228
237
  if not title:
229
238
  title = self.folder
@@ -372,7 +381,11 @@ class Raw:
372
381
  if not title:
373
382
  title = self.filename
374
383
  return self.plotter.rawBGS_plot(
375
- self.frequency, self.BGS, index=index, title=title
384
+ self.frequency,
385
+ self.BGS,
386
+ positions_m=self.position,
387
+ index=index,
388
+ title=title,
376
389
  )
377
390
 
378
391
  def plotMax(self, title: str = None):
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "readerbotda"
3
- version = "1.4.0"
3
+ version = "1.4.2"
4
4
  description = "Pacchetto per lettura e visualizzazione file di log sensore BOTDA Cohaerentia"
5
5
  authors = [
6
6
  {name = "Marco Brunero",email = "marco.brunero@cohaerentia.com"}
@@ -1,35 +0,0 @@
1
- from abc import ABC, abstractmethod
2
-
3
- class Plotter(ABC):
4
-
5
- @abstractmethod
6
- def single_plot(self,position, profile, title: str = None):
7
- pass
8
-
9
- @abstractmethod
10
- def multiple_plot(self,position, profiles, timestamps, title: str = ''):
11
- pass
12
-
13
- @abstractmethod
14
- def statistics(self,position,mean,std,title:str = ''):
15
- pass
16
-
17
- @abstractmethod
18
- def raw2d_plot(self,position, frequency, BGS, title: str = None):
19
- pass
20
-
21
- @abstractmethod
22
- def rawBGS_plot(self,frequency, BGS, index: int = None, title: str = None):
23
- pass
24
-
25
- @abstractmethod
26
- def raw3d_plot(self,position, frequency, BGS, title: str = None):
27
- pass
28
-
29
- @abstractmethod
30
- def max_plot(self,position,max,title: str = None):
31
- pass
32
-
33
- @abstractmethod
34
- def max_stat_plot(self,max_mean,max_std, title:str = ''):
35
- pass
@@ -1,74 +0,0 @@
1
- from .abc import Plotter
2
-
3
- from bokeh.plotting import figure
4
- from bokeh.models.layouts import Column
5
- from bokeh.plotting.figure import Figure as bokehFigure
6
- from bokeh.plotting import show as bokehShow
7
- from bokeh.models import Legend
8
- from bokeh.layouts import gridplot
9
- from bokeh.palettes import Bokeh8
10
- from bokeh.io import curdoc
11
-
12
- import numpy as np
13
-
14
- class Bokeh(Plotter):
15
- def __init__(self,theme:str='caliber'):
16
- curdoc().theme = theme
17
- #TODO: capire come prendere la palette del tema scelto, invece che usare sempre Bokeh8.
18
- self.palette = Bokeh8
19
-
20
- def single_plot(self, position, profile, title: str = None) -> bokehFigure:
21
- fig = figure(title=title, x_axis_label='Position (m)', y_axis_label='BFS (MHz)',sizing_mode='stretch_width')
22
- fig.line(position, profile)
23
- return fig
24
-
25
- def multiple_plot(self, position, profiles, timestamps, title: str = '') -> bokehFigure:
26
- fig = figure(title=title, x_axis_label='Position (m)', y_axis_label='BFS (MHz)',sizing_mode='stretch_width')
27
- fig.add_layout(Legend(), 'right')
28
- for i,(time,color) in enumerate(zip(timestamps, self.palette)):
29
- fig.line(x=position,y=profiles[:,i],
30
- color=color,
31
- legend_label=time.strftime("%m/%d/%Y, %H:%M:%S"))
32
- return fig
33
-
34
- def statistics(self, position, mean: np.ndarray,
35
- std: np.ndarray, title:str = '') -> Column:
36
- f1 = figure(title=title,y_axis_label='Mean BFS (MHz)')
37
- f1.line(x=position, y=mean)
38
- f1.varea(x=position, y1=mean+std, y2=mean-std,fill_alpha=0.3)
39
- f2 = figure(x_axis_label='Position (m)', y_axis_label='Std Dev (MHz)', y_range=(0,10))
40
- f2.line(x=position, y=std)
41
- return gridplot([f1,f2],ncols=1,height=150,sizing_mode='stretch_width')
42
-
43
- def max_plot(self, position, max, title: str = None) -> bokehFigure:
44
- fig = figure(title=title, x_axis_label='Position (m)', y_axis_label='Max BGS Amplitude',sizing_mode='stretch_width')
45
- fig.line(x=position,y=max)
46
- return fig
47
-
48
- def max_stat_plot(self,max_mean: np.ndarray, max_std: np.ndarray, title:str = '')-> bokehFigure:
49
- fig = figure(title=title,y_axis_label='Max BGS (Volts)',sizing_mode='stretch_width')
50
- fig.line(y=max_mean)
51
- fig.varea(y1=max_mean+max_std, y2=max_mean-max_std,fill_alpha=0.3)
52
- return fig
53
-
54
- def rawBGS_plot(self, frequency, BGS, index: int = None, title: str = None) -> bokehFigure:
55
- fig = figure(title=title,x_axis_label='Frequency (GHz)', y_axis_label='Amplitude (V)',sizing_mode='stretch_width')
56
- if not index:
57
- for single in np.transpose(BGS):
58
- fig.line(x=frequency,y=single)
59
- else:
60
- for single in np.transpose(BGS):
61
- fig.line(x=frequency,y=single,color='rgba(175,175,175,0.15)')
62
- fig.line(x=frequency,y=BGS[:,index])
63
- return fig
64
-
65
- def raw3d_plot(self, position, frequency, BGS, title: str = None):
66
- raise NameError('Function raw3d_plot not yet defined for Bokeh plotter.')
67
-
68
- def raw2d_plot(self, position, frequency, BGS, title: str = None):
69
- raise NameError('Function raw2d_plot not yet defined for Bokeh plotter.')
70
-
71
- @staticmethod
72
- def show(fig) -> None:
73
- bokehShow(fig)
74
- pass
File without changes