sigmt 2.2.1__tar.gz → 2.3.0__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.
Files changed (57) hide show
  1. sigmt-2.3.0/MANIFEST.in +4 -0
  2. {sigmt-2.2.1/sigmt.egg-info → sigmt-2.3.0}/PKG-INFO +1 -1
  3. {sigmt-2.2.1 → sigmt-2.3.0}/setup.py +2 -0
  4. {sigmt-2.2.1 → sigmt-2.3.0}/sigmt/__version__.py +1 -1
  5. sigmt-2.3.0/sigmt/core/colormaps.py +37 -0
  6. {sigmt-2.2.1 → sigmt-2.3.0}/sigmt/core/plots.py +0 -155
  7. {sigmt-2.2.1 → sigmt-2.3.0}/sigmt/gui/about_dialog.py +2 -2
  8. sigmt-2.3.0/sigmt/gui/common/coherency_plot_window.py +244 -0
  9. sigmt-2.3.0/sigmt/gui/common/icons.py +15 -0
  10. sigmt-2.3.0/sigmt/gui/common/pd_plot_window.py +125 -0
  11. sigmt-2.3.0/sigmt/gui/common/plot_validation.py +71 -0
  12. sigmt-2.3.0/sigmt/gui/edi_merger/__init__.py +3 -0
  13. sigmt-2.3.0/sigmt/gui/edi_merger/calculations.py +30 -0
  14. sigmt-2.3.0/sigmt/gui/edi_merger/data_checks.py +67 -0
  15. sigmt-2.3.0/sigmt/gui/edi_merger/edi_export.py +231 -0
  16. sigmt-2.3.0/sigmt/gui/edi_merger/main.py +851 -0
  17. {sigmt-2.2.1 → sigmt-2.3.0}/sigmt/gui/metronix/metronix.py +39 -12
  18. {sigmt-2.2.1 → sigmt-2.3.0}/sigmt/gui/phoenix/phoenix.py +39 -12
  19. {sigmt-2.2.1 → sigmt-2.3.0}/sigmt/main.py +3 -2
  20. sigmt-2.3.0/sigmt/utils/phoenix/__init__.py +0 -0
  21. {sigmt-2.2.1 → sigmt-2.3.0/sigmt.egg-info}/PKG-INFO +1 -1
  22. {sigmt-2.2.1 → sigmt-2.3.0}/sigmt.egg-info/SOURCES.txt +11 -1
  23. {sigmt-2.2.1 → sigmt-2.3.0}/sigmt.egg-info/requires.txt +1 -1
  24. sigmt-2.2.1/MANIFEST.in +0 -4
  25. sigmt-2.2.1/sigmt/gui/edi_merger.py +0 -634
  26. {sigmt-2.2.1 → sigmt-2.3.0}/LICENSE +0 -0
  27. {sigmt-2.2.1 → sigmt-2.3.0}/README.md +0 -0
  28. {sigmt-2.2.1 → sigmt-2.3.0}/setup.cfg +0 -0
  29. {sigmt-2.2.1 → sigmt-2.3.0}/sigmt/__init__.py +0 -0
  30. {sigmt-2.2.1 → sigmt-2.3.0}/sigmt/core/band_averaging.py +0 -0
  31. {sigmt-2.2.1 → sigmt-2.3.0}/sigmt/core/data_selection_tools.py +0 -0
  32. {sigmt-2.2.1 → sigmt-2.3.0}/sigmt/core/perform_data_selection.py +0 -0
  33. {sigmt-2.2.1 → sigmt-2.3.0}/sigmt/core/robust_estimation.py +0 -0
  34. {sigmt-2.2.1 → sigmt-2.3.0}/sigmt/core/sigproc.py +0 -0
  35. {sigmt-2.2.1 → sigmt-2.3.0}/sigmt/core/statistics.py +0 -0
  36. {sigmt-2.2.1 → sigmt-2.3.0}/sigmt/gui/__init__.py +0 -0
  37. {sigmt-2.2.1/sigmt/gui/metronix → sigmt-2.3.0/sigmt/gui/common}/__init__.py +0 -0
  38. {sigmt-2.2.1/sigmt/gui/phoenix → sigmt-2.3.0/sigmt/gui/metronix}/__init__.py +0 -0
  39. {sigmt-2.2.1 → sigmt-2.3.0}/sigmt/gui/metronix/metronix_dialogs.py +0 -0
  40. {sigmt-2.2.1/sigmt/utils → sigmt-2.3.0/sigmt/gui/phoenix}/__init__.py +0 -0
  41. {sigmt-2.2.1 → sigmt-2.3.0}/sigmt/gui/project_related/create_project.py +0 -0
  42. {sigmt-2.2.1 → sigmt-2.3.0}/sigmt/gui/project_related/edit_project.py +0 -0
  43. {sigmt-2.2.1 → sigmt-2.3.0}/sigmt/images/sigmt.ico +0 -0
  44. {sigmt-2.2.1/sigmt/utils/phoenix → sigmt-2.3.0/sigmt/utils}/__init__.py +0 -0
  45. {sigmt-2.2.1 → sigmt-2.3.0}/sigmt/utils/edi/edi_ops.py +0 -0
  46. {sigmt-2.2.1 → sigmt-2.3.0}/sigmt/utils/frequency_table.py +0 -0
  47. {sigmt-2.2.1 → sigmt-2.3.0}/sigmt/utils/metronix/cal_from_metronix_txt.py +0 -0
  48. {sigmt-2.2.1 → sigmt-2.3.0}/sigmt/utils/metronix/cal_from_xml.py +0 -0
  49. {sigmt-2.2.1 → sigmt-2.3.0}/sigmt/utils/metronix/calibration.py +0 -0
  50. {sigmt-2.2.1 → sigmt-2.3.0}/sigmt/utils/metronix/metronix_utils.py +0 -0
  51. {sigmt-2.2.1 → sigmt-2.3.0}/sigmt/utils/phoenix/calibration.py +0 -0
  52. {sigmt-2.2.1 → sigmt-2.3.0}/sigmt/utils/phoenix/phoenix_readers.py +0 -0
  53. {sigmt-2.2.1 → sigmt-2.3.0}/sigmt/utils/phoenix/phoenix_utils.py +0 -0
  54. {sigmt-2.2.1 → sigmt-2.3.0}/sigmt/utils/utils.py +0 -0
  55. {sigmt-2.2.1 → sigmt-2.3.0}/sigmt.egg-info/dependency_links.txt +0 -0
  56. {sigmt-2.2.1 → sigmt-2.3.0}/sigmt.egg-info/entry_points.txt +0 -0
  57. {sigmt-2.2.1 → sigmt-2.3.0}/sigmt.egg-info/top_level.txt +0 -0
@@ -0,0 +1,4 @@
1
+ include LICENSE
2
+ include README.md
3
+
4
+ recursive-include sigmt/images *.ico
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sigmt
3
- Version: 2.2.1
3
+ Version: 2.3.0
4
4
  Summary: A tool for magnetotelluric time series processing
5
5
  Home-page: https://github.com/ajithabhks/sigmt
6
6
  Author: Ajithabh K.S.
@@ -10,6 +10,8 @@ setup(
10
10
  version=__version__,
11
11
  packages=['sigmt', 'sigmt.core',
12
12
  'sigmt.gui', 'sigmt.utils',
13
+ 'sigmt.gui.common',
14
+ 'sigmt.gui.edi_merger',
13
15
  'sigmt.gui.metronix',
14
16
  'sigmt.gui.phoenix',
15
17
  'sigmt.utils.edi', 'sigmt.utils.metronix',
@@ -1,4 +1,4 @@
1
1
  """
2
2
  Returns version of the package
3
3
  """
4
- __version__ = "2.2.1"
4
+ __version__ = "2.3.0"
@@ -0,0 +1,37 @@
1
+ from matplotlib.colors import LinearSegmentedColormap
2
+
3
+
4
+ def get_coherency_colormap() -> LinearSegmentedColormap:
5
+ """
6
+ Create and return a custom colormap for coherency plots.
7
+
8
+ :return: Custom colormap
9
+ :rtype: LinearSegmentedColormap
10
+
11
+ """
12
+ color_dictionary = {'red': [(0.0, 0.0, 0.0),
13
+ (0.1, 0.5, 0.5),
14
+ (0.2, 0.0, 0.0),
15
+ (0.4, 0.2, 0.2),
16
+ (0.6, 0.0, 0.0),
17
+ (0.8, 1.0, 1.0),
18
+ (1.0, 1.0, 1.0)],
19
+ 'green': [(0.0, 0.0, 0.0),
20
+ (0.1, 0.0, 0.0),
21
+ (0.2, 0.0, 0.0),
22
+ (0.4, 1.0, 1.0),
23
+ (0.6, 1.0, 1.0),
24
+ (0.8, 1.0, 1.0),
25
+ (1.0, 0.0, 0.0)],
26
+ 'blue': [(0.0, 0.0, 0.0),
27
+ (0.1, 0.5, 0.5),
28
+ (0.2, 1.0, 1.0),
29
+ (0.4, 1.0, 1.0),
30
+ (0.6, 0.0, 0.0),
31
+ (0.8, 0.0, 0.0),
32
+ (1.0, 0.0, 0.0)]}
33
+ return LinearSegmentedColormap(
34
+ name='my_colormap',
35
+ segmentdata=color_dictionary,
36
+ N=256,
37
+ )
@@ -6,7 +6,6 @@ import os
6
6
  from datetime import datetime
7
7
  from typing import Optional
8
8
 
9
- import matplotlib
10
9
  import numpy as np
11
10
  import xarray as xr
12
11
  from matplotlib import pyplot as plt
@@ -215,157 +214,3 @@ def plot_coherency(dataset: xr.Dataset, procinfo: dict, save_path: Optional[str]
215
214
  plt.close()
216
215
  else:
217
216
  plt.show()
218
-
219
-
220
- def plot_coherencies_all(dataset: xr.Dataset) -> None:
221
- """
222
- Plots coherency values for all frequencies
223
-
224
- :param dataset: Dataset containing band averaged values
225
- :type dataset: xr.Dataset
226
- :return: None
227
- :rtype: None
228
-
229
- """
230
- if not dataset:
231
- raise ValueError('dataset invalid')
232
-
233
- custom_colormap = _get_custom_colormap()
234
-
235
- num_coh = 0
236
- coh_keys = []
237
- if 'coh_ex' in dataset:
238
- num_coh = num_coh + 1
239
- coh_keys.append('coh_ex')
240
- if 'coh_ey' in dataset:
241
- num_coh = num_coh + 1
242
- coh_keys.append('coh_ey')
243
- if 'coh_hz' in dataset:
244
- num_coh = num_coh + 1
245
- coh_keys.append('coh_hz')
246
- #
247
- for freq in dataset['frequency']:
248
- # Select data for the current frequency
249
- data_for_freq = dataset.sel(frequency=freq)
250
- if num_coh == 1:
251
- tf_component = _get_tf_key(coh_keys, 0)
252
- plt.figure()
253
- plt.scatter(data_for_freq[tf_component].real, data_for_freq[tf_component].imag, c=data_for_freq[coh_keys[0]],
254
- cmap=custom_colormap,
255
- vmin=0, vmax=1)
256
- plt.colorbar(label=coh_keys[0]) # Add color bar for reference
257
- plt.title(f"Coherency ({coh_keys[0]}) plot for {freq.values} Hz", fontsize=12)
258
- plt.xlabel(f'Real ({tf_component})')
259
- plt.ylabel(f'Imag ({tf_component})')
260
- elif num_coh == 2:
261
- fig, axes = plt.subplots(1, 2, figsize=(10, 5))
262
- for i in range(2):
263
- tf_component = _get_tf_key(coh_keys, i)
264
- sc = axes[i].scatter(data_for_freq[tf_component].real, data_for_freq[tf_component].imag,
265
- c=data_for_freq[coh_keys[i]],
266
- cmap=custom_colormap, vmin=0, vmax=1)
267
- fig.colorbar(sc, ax=axes[i], label=coh_keys[i])
268
- axes[i].set_title(coh_keys[i])
269
- axes[i].set_xlabel(f'Real ({tf_component})')
270
- axes[i].set_ylabel(f'Imag ({tf_component})')
271
- fig.suptitle(f"Coherency plots for {freq.values} Hz", fontsize=12)
272
- elif num_coh == 3:
273
- fig, axes = plt.subplots(1, 3, figsize=(15, 5)) # 3 horizontal subplots
274
- for i in range(3):
275
- tf_component = _get_tf_key(coh_keys, i)
276
- sc = axes[i].scatter(data_for_freq[tf_component].real, data_for_freq[tf_component].imag,
277
- c=data_for_freq[coh_keys[i]],
278
- cmap=custom_colormap, vmin=0, vmax=1)
279
- fig.colorbar(sc, ax=axes[i], label=coh_keys[i])
280
- axes[i].set_title(coh_keys[i])
281
- axes[i].set_xlabel(f'Real ({tf_component})')
282
- axes[i].set_ylabel(f'Imag ({tf_component})')
283
- fig.suptitle(f"Coherency plots for {freq.values} Hz", fontsize=12)
284
-
285
- plt.tight_layout()
286
- plt.show()
287
-
288
-
289
- def _get_tf_key(coh_keys, i) -> str:
290
- """
291
- Get transfer function key.
292
-
293
- """
294
- key = ""
295
- if coh_keys[i] == 'coh_ex':
296
- key = 'zxy'
297
- if coh_keys[i] == 'coh_ey':
298
- key = 'zyx'
299
- if coh_keys[i] == 'coh_hz':
300
- key = 'tzx'
301
- return key
302
-
303
-
304
- def plot_pd_all(dataset: xr.Dataset) -> None:
305
- """
306
- Plots polarization directions values for all frequencies
307
-
308
- :param dataset: Dataset containing band averaged values
309
- :type dataset: xr.Dataset
310
- :return: None
311
- :rtype: None
312
-
313
- """
314
- if not dataset:
315
- raise ValueError('dataset invalid')
316
-
317
- afont = {'fontname': 'Arial'}
318
- yticks = np.arange(-90, 100, 20)
319
-
320
- for freq in dataset['frequency']:
321
- data_for_freq = dataset.sel(frequency=freq)
322
- time_array = np.arange(data_for_freq.coords['time_window'].size)
323
- plt.figure()
324
-
325
- plt.subplot(211)
326
- plt.suptitle(f"Polarization directions for {freq.values} Hz", fontsize=12)
327
- plt.scatter(time_array, data_for_freq['alpha_h'].values)
328
- plt.ylim(-90, 90)
329
- plt.ylabel(r'$\alpha_H$ (deg.)')
330
- plt.xticks(**afont, fontsize=12)
331
- plt.yticks(yticks, **afont, fontsize=12)
332
-
333
- plt.subplot(212)
334
- plt.scatter(time_array, data_for_freq['alpha_e'].values)
335
- plt.ylim(-90, 90)
336
- plt.ylabel(r'$\alpha_E$ (deg.)')
337
- plt.xlabel('Time window')
338
- plt.xticks(**afont, fontsize=12)
339
- plt.yticks(yticks, **afont, fontsize=12)
340
-
341
- plt.show(block=False)
342
-
343
-
344
- def _get_custom_colormap() -> matplotlib.colors.LinearSegmentedColormap:
345
- """
346
- Creates and returns a custom colormap for coherency plots
347
-
348
- :return: Custom colormap
349
- """
350
- color_dictionary = {'red': [(0.0, 0.0, 0.0),
351
- (0.1, 0.5, 0.5),
352
- (0.2, 0.0, 0.0),
353
- (0.4, 0.2, 0.2),
354
- (0.6, 0.0, 0.0),
355
- (0.8, 1.0, 1.0),
356
- (1.0, 1.0, 1.0)],
357
- 'green': [(0.0, 0.0, 0.0),
358
- (0.1, 0.0, 0.0),
359
- (0.2, 0.0, 0.0),
360
- (0.4, 1.0, 1.0),
361
- (0.6, 1.0, 1.0),
362
- (0.8, 1.0, 1.0),
363
- (1.0, 0.0, 0.0)],
364
- 'blue': [(0.0, 0.0, 0.0),
365
- (0.1, 0.5, 0.5),
366
- (0.2, 1.0, 1.0),
367
- (0.4, 1.0, 1.0),
368
- (0.6, 0.0, 0.0),
369
- (0.8, 0.0, 0.0),
370
- (1.0, 0.0, 0.0)]}
371
- return matplotlib.colors.LinearSegmentedColormap('my_colormap', color_dictionary, 256)
@@ -2,10 +2,10 @@
2
2
  Dialog box with information about the package
3
3
  """
4
4
  from PyQt5.QtCore import Qt
5
- from PyQt5.QtGui import QIcon
6
5
  from PyQt5.QtWidgets import QDialog, QVBoxLayout, QLabel
7
6
 
8
7
  from sigmt.__version__ import __version__
8
+ from sigmt.gui.common.icons import get_app_icon
9
9
 
10
10
 
11
11
  class AboutDialog(QDialog):
@@ -44,7 +44,7 @@ class AboutDialog(QDialog):
44
44
  """
45
45
  self.setWindowTitle("About")
46
46
  self.setFixedSize(400, 200)
47
- self.setWindowIcon(QIcon(r'sigmt\images\sigmt.ico'))
47
+ self.setWindowIcon(get_app_icon())
48
48
 
49
49
  def get_citation_label(self) -> None:
50
50
  """
@@ -0,0 +1,244 @@
1
+ from typing import Optional, Tuple
2
+
3
+ import numpy as np
4
+ import xarray as xr
5
+ from PyQt5.QtWidgets import (
6
+ QApplication,
7
+ QWidget,
8
+ QVBoxLayout,
9
+ QHBoxLayout,
10
+ QLabel,
11
+ QComboBox,
12
+ )
13
+ from matplotlib.backends.backend_qt5agg import (
14
+ FigureCanvasQTAgg as FigureCanvas,
15
+ NavigationToolbar2QT as NavigationToolbar,
16
+ )
17
+ from matplotlib.axes import Axes
18
+ from matplotlib.figure import Figure
19
+
20
+ from sigmt.core.colormaps import get_coherency_colormap
21
+ from sigmt.gui.common.plot_validation import validate_plot_dataset, validate_plot_variable
22
+
23
+ TF_OPTIONS = {
24
+ "coh_ex": ["zxy", "zxx"],
25
+ "coh_ey": ["zyx", "zyy"],
26
+ "coh_hz": ["tzx", "tzy"],
27
+ }
28
+
29
+
30
+ class CoherencyPlotWindow(QWidget):
31
+ def __init__(
32
+ self,
33
+ dataset: Optional[xr.Dataset],
34
+ parent: Optional[QWidget] = None,
35
+ ) -> None:
36
+ """
37
+ Initialize the interactive coherency viewer.
38
+
39
+ :param dataset: Band-averaged dataset to visualize
40
+ :type dataset: Optional[xr.Dataset]
41
+ :param parent: Optional parent widget
42
+ :type parent: Optional[QWidget]
43
+ :return: None
44
+ :rtype: NoneType
45
+
46
+ """
47
+ super().__init__(parent)
48
+
49
+ dataset = validate_plot_dataset(dataset=dataset)
50
+
51
+ self.dataset = dataset
52
+ self.custom_colormap = get_coherency_colormap()
53
+
54
+ self.coh_keys = []
55
+ if "coh_ex" in dataset:
56
+ self.coh_keys.append("coh_ex")
57
+ if "coh_ey" in dataset:
58
+ self.coh_keys.append("coh_ey")
59
+ if "coh_hz" in dataset:
60
+ self.coh_keys.append("coh_hz")
61
+
62
+ if not self.coh_keys:
63
+ raise ValueError("No coherency variables found in dataset")
64
+
65
+ for coh_key in self.coh_keys:
66
+ validate_plot_variable(dataset=dataset, key=coh_key)
67
+ tf_keys = [key for key in TF_OPTIONS[coh_key] if key in dataset]
68
+ if not tf_keys:
69
+ raise ValueError(f"No valid TF components found in dataset for {coh_key}")
70
+ for tf_key in tf_keys:
71
+ validate_plot_variable(dataset=dataset, key=tf_key, allow_complex=True)
72
+
73
+ self.setWindowTitle("Coherency Viewer")
74
+ screen = self.screen() if hasattr(self, "screen") else QApplication.primaryScreen()
75
+ if screen is None:
76
+ screen = QApplication.primaryScreen()
77
+ if screen is None:
78
+ self.resize(1400, 800)
79
+ else:
80
+ available = screen.availableGeometry()
81
+ self.resize(
82
+ min(1400, int(available.width() * 0.9)),
83
+ min(800, int(available.height() * 0.9)),
84
+ )
85
+
86
+ self.freq_label = QLabel("Frequency:")
87
+ self.freq_combo = QComboBox()
88
+
89
+ self.frequencies = self.dataset["frequency"].values
90
+ for freq in self.frequencies:
91
+ self.freq_combo.addItem(f"{freq:.6g} Hz", freq)
92
+
93
+ self.freq_combo.currentIndexChanged.connect(self.update_plot)
94
+
95
+ top_layout = QHBoxLayout()
96
+ top_layout.addWidget(self.freq_label)
97
+ top_layout.addWidget(self.freq_combo)
98
+
99
+ self.tf_selectors = {}
100
+ for coh_key in self.coh_keys:
101
+ label = QLabel(f"{coh_key}:")
102
+ combo = QComboBox()
103
+
104
+ for tf_key in TF_OPTIONS[coh_key]:
105
+ if tf_key in dataset:
106
+ combo.addItem(tf_key)
107
+
108
+ combo.currentIndexChanged.connect(self.update_plot)
109
+ self.tf_selectors[coh_key] = combo
110
+
111
+ top_layout.addSpacing(12)
112
+ top_layout.addWidget(label)
113
+ top_layout.addWidget(combo)
114
+
115
+ top_layout.addStretch()
116
+
117
+ self.figure = Figure(constrained_layout=True)
118
+ self.canvas = FigureCanvas(figure=self.figure)
119
+ self.toolbar = NavigationToolbar(canvas=self.canvas, parent=self)
120
+
121
+ main_layout = QVBoxLayout()
122
+ main_layout.addLayout(top_layout)
123
+ main_layout.addWidget(self.toolbar)
124
+ main_layout.addWidget(self.canvas)
125
+ self.setLayout(main_layout)
126
+
127
+ self.update_plot()
128
+
129
+ @staticmethod
130
+ def _clean_xy(
131
+ x: np.ndarray,
132
+ y: np.ndarray,
133
+ ) -> Tuple[np.ndarray, np.ndarray]:
134
+ """
135
+ Flatten coordinate arrays and retain pairs of finite values.
136
+
137
+ :param x: Real-coordinate values
138
+ :type x: np.ndarray
139
+ :param y: Imaginary-coordinate values
140
+ :type y: np.ndarray
141
+ :return: Filtered coordinate arrays
142
+ :rtype: Tuple[np.ndarray, np.ndarray]
143
+
144
+ """
145
+ x = np.asarray(a=x).ravel()
146
+ y = np.asarray(a=y).ravel()
147
+ mask = np.isfinite(x) & np.isfinite(y)
148
+ return x[mask], y[mask]
149
+
150
+ @staticmethod
151
+ def _set_square_equal(
152
+ ax: Axes,
153
+ x: np.ndarray,
154
+ y: np.ndarray,
155
+ pad_frac: float = 0.05,
156
+ ) -> None:
157
+ """
158
+ Set square axes with equal coordinate scales and padded data limits.
159
+
160
+ :param ax: Axes to configure
161
+ :type ax: Axes
162
+ :param x: Real-coordinate values
163
+ :type x: np.ndarray
164
+ :param y: Imaginary-coordinate values
165
+ :type y: np.ndarray
166
+ :param pad_frac: Fractional padding around the coordinate range
167
+ :type pad_frac: float
168
+ :return: None
169
+ :rtype: NoneType
170
+
171
+ """
172
+ x, y = CoherencyPlotWindow._clean_xy(x=x, y=y)
173
+
174
+ if x.size == 0:
175
+ ax.set_box_aspect(aspect=1)
176
+ ax.set_aspect(aspect="equal", adjustable="datalim")
177
+ return
178
+
179
+ xmin, xmax = x.min(), x.max()
180
+ ymin, ymax = y.min(), y.max()
181
+
182
+ xmid = 0.5 * (xmin + xmax)
183
+ ymid = 0.5 * (ymin + ymax)
184
+
185
+ half = max(xmax - xmin, ymax - ymin) / 2.0
186
+ if half == 0:
187
+ half = 1.0
188
+
189
+ half *= (1.0 + pad_frac)
190
+
191
+ ax.set_xlim(left=xmid - half, right=xmid + half)
192
+ ax.set_ylim(bottom=ymid - half, top=ymid + half)
193
+ ax.set_box_aspect(aspect=1)
194
+ ax.set_aspect(aspect="equal", adjustable="box")
195
+
196
+ def update_plot(
197
+ self,
198
+ ) -> None:
199
+ """
200
+ Redraw the coherency plots for the selected frequency.
201
+
202
+ :return: None
203
+ :rtype: NoneType
204
+
205
+ """
206
+ freq = self.freq_combo.currentData()
207
+ data_for_freq = self.dataset.sel(frequency=freq)
208
+
209
+ self.figure.clear()
210
+ self.figure.suptitle(t=f"Coherency plots for {freq} Hz")
211
+ num_coh = len(self.coh_keys)
212
+
213
+ axes = self.figure.subplots(nrows=1, ncols=num_coh, squeeze=False)[0]
214
+
215
+ for i, ax in enumerate(axes):
216
+ coh_key = self.coh_keys[i]
217
+ tf_component = self.tf_selectors[coh_key].currentText()
218
+
219
+ x = data_for_freq[tf_component].real.values
220
+ y = data_for_freq[tf_component].imag.values
221
+ c = data_for_freq[coh_key].values
222
+
223
+ sc = ax.scatter(
224
+ x=x,
225
+ y=y,
226
+ c=c,
227
+ cmap=self.custom_colormap,
228
+ vmin=0,
229
+ vmax=1,
230
+ s=35,
231
+ edgecolors="none",
232
+ )
233
+
234
+ ax.set_xlabel(xlabel=f"Real ({tf_component})", fontsize=11)
235
+ ax.set_ylabel(ylabel=f"Imag ({tf_component})", fontsize=11)
236
+
237
+ self._set_square_equal(ax=ax, x=x, y=y)
238
+
239
+ cbar = self.figure.colorbar(mappable=sc, ax=ax, fraction=0.046, pad=0.04)
240
+ cbar.set_label(label=coh_key, fontsize=11)
241
+
242
+ ax.grid(True, alpha=0.25)
243
+
244
+ self.canvas.draw()
@@ -0,0 +1,15 @@
1
+ from pathlib import Path
2
+
3
+ from PyQt5.QtGui import QIcon
4
+
5
+
6
+ def get_app_icon() -> QIcon:
7
+ """
8
+ Load the SigMT icon from the installed package directory.
9
+
10
+ :return: SigMT application icon
11
+ :rtype: QIcon
12
+
13
+ """
14
+ icon_path = Path(__file__).resolve().parents[2] / "images" / "sigmt.ico"
15
+ return QIcon(str(icon_path))
@@ -0,0 +1,125 @@
1
+ from typing import Optional
2
+
3
+ import numpy as np
4
+ import xarray as xr
5
+
6
+ from PyQt5.QtWidgets import (
7
+ QApplication,
8
+ QWidget,
9
+ QVBoxLayout,
10
+ QHBoxLayout,
11
+ QLabel,
12
+ QComboBox,
13
+ )
14
+ from matplotlib.backends.backend_qt5agg import (
15
+ FigureCanvasQTAgg as FigureCanvas,
16
+ NavigationToolbar2QT as NavigationToolbar,
17
+ )
18
+ from matplotlib.figure import Figure
19
+
20
+ from sigmt.gui.common.plot_validation import validate_plot_dataset, validate_plot_variable
21
+
22
+
23
+ class PolarizationDirectionWindow(QWidget):
24
+ def __init__(
25
+ self,
26
+ dataset: Optional[xr.Dataset],
27
+ parent: Optional[QWidget] = None,
28
+ ) -> None:
29
+ """
30
+ Initialize the interactive polarization direction viewer.
31
+
32
+ :param dataset: Band-averaged dataset to visualize
33
+ :type dataset: Optional[xr.Dataset]
34
+ :param parent: Optional parent widget
35
+ :type parent: Optional[QWidget]
36
+ :return: None
37
+ :rtype: NoneType
38
+
39
+ """
40
+ super().__init__(parent)
41
+
42
+ dataset = validate_plot_dataset(dataset=dataset)
43
+
44
+ for key in ("alpha_h", "alpha_e"):
45
+ validate_plot_variable(dataset=dataset, key=key)
46
+
47
+ self.dataset = dataset
48
+
49
+ self.setWindowTitle("Polarization Direction Viewer")
50
+ screen = self.screen() if hasattr(self, "screen") else QApplication.primaryScreen()
51
+ if screen is None:
52
+ screen = QApplication.primaryScreen()
53
+ if screen is None:
54
+ self.resize(1100, 800)
55
+ else:
56
+ available = screen.availableGeometry()
57
+ self.resize(
58
+ min(1100, int(available.width() * 0.9)),
59
+ min(800, int(available.height() * 0.9)),
60
+ )
61
+
62
+ self.freq_label = QLabel("Frequency:")
63
+ self.freq_combo = QComboBox()
64
+
65
+ self.frequencies = self.dataset["frequency"].values
66
+ for freq in self.frequencies:
67
+ self.freq_combo.addItem(f"{freq:.6g} Hz", freq)
68
+
69
+ self.freq_combo.currentIndexChanged.connect(self.update_plot)
70
+
71
+ top_layout = QHBoxLayout()
72
+ top_layout.addWidget(self.freq_label)
73
+ top_layout.addWidget(self.freq_combo)
74
+ top_layout.addStretch()
75
+
76
+ self.figure = Figure(constrained_layout=True)
77
+ self.canvas = FigureCanvas(figure=self.figure)
78
+ self.toolbar = NavigationToolbar(canvas=self.canvas, parent=self)
79
+
80
+ main_layout = QVBoxLayout()
81
+ main_layout.addLayout(top_layout)
82
+ main_layout.addWidget(self.toolbar)
83
+ main_layout.addWidget(self.canvas)
84
+ self.setLayout(main_layout)
85
+
86
+ self.update_plot()
87
+
88
+ def update_plot(
89
+ self,
90
+ ) -> None:
91
+ """
92
+ Redraw the polarization direction plots for the selected frequency.
93
+
94
+ :return: None
95
+ :rtype: NoneType
96
+
97
+ """
98
+ freq = self.freq_combo.currentData()
99
+ data_for_freq = self.dataset.sel(frequency=freq)
100
+
101
+ self.figure.clear()
102
+ self.figure.suptitle(t=f"Polarization directions for {freq} Hz")
103
+
104
+ ax1, ax2 = self.figure.subplots(nrows=2, ncols=1, sharex=True)
105
+
106
+ time_array = np.arange(data_for_freq.coords["time_window"].size)
107
+ yticks = np.arange(-90, 100, 20)
108
+
109
+ alpha_h = np.asarray(a=data_for_freq["alpha_h"].values).ravel()
110
+ alpha_e = np.asarray(a=data_for_freq["alpha_e"].values).ravel()
111
+
112
+ ax1.scatter(x=time_array, y=alpha_h, s=20)
113
+ ax1.set_ylim(bottom=-90, top=90)
114
+ ax1.set_ylabel(ylabel=r"$\alpha_H$ (deg.)")
115
+ ax1.set_yticks(ticks=yticks)
116
+ ax1.grid(True, alpha=0.25)
117
+
118
+ ax2.scatter(x=time_array, y=alpha_e, s=20)
119
+ ax2.set_ylim(bottom=-90, top=90)
120
+ ax2.set_ylabel(ylabel=r"$\alpha_E$ (deg.)")
121
+ ax2.set_xlabel(xlabel="Time window")
122
+ ax2.set_yticks(ticks=yticks)
123
+ ax2.grid(True, alpha=0.25)
124
+
125
+ self.canvas.draw()