-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref: add qmap files (from previous commit)
- Loading branch information
1 parent
ad68882
commit 5af6c03
Showing
2 changed files
with
272 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import pkg_resources | ||
|
||
import nanite | ||
from PyQt5 import uic, QtWidgets | ||
|
||
from .mpl_qmap import MPLQMap | ||
|
||
|
||
class TabQMap(QtWidgets.QWidget): | ||
def __init__(self, *args, **kwargs): | ||
super(TabQMap, self).__init__(*args, **kwargs) | ||
path_ui = pkg_resources.resource_filename("pyjibe.fd", | ||
"tab_qmap.ui") | ||
uic.loadUi(path_ui, self) | ||
|
||
# Setup the matplotlib interface for 2D map plotting | ||
self.mpl_qmap = MPLQMap() | ||
self.mpl_qmap.add_toolbar(self.qmap_mplwidget) | ||
self.qmap_mpllayout.addWidget(self.mpl_qmap.canvas) | ||
self.qmap_mpllayout.addWidget(self.mpl_qmap.toolbar) | ||
# set colormaps | ||
cmaps = ["viridis", "plasma", "afmhot", "seismic"] | ||
for cm in cmaps: | ||
self.qmpa_cmap_cb.addItem(cm) | ||
self.qmpa_cmap_cb.setCurrentIndex(0) | ||
self.qmap_data_cb.currentIndexChanged.connect( | ||
self.on_qmap_data_changed) | ||
self.qmpa_cmap_cb.currentIndexChanged.connect( | ||
self.on_qmap_cmap_changed) | ||
self.qmap_sp_range1.valueChanged.connect(self.on_qmap_min_max_changed) | ||
self.qmap_sp_range2.valueChanged.connect(self.on_qmap_min_max_changed) | ||
self.mpl_qmap.connect_curve_selection_event(self.on_qmap_selection) | ||
|
||
def on_qmap_cmap_changed(self): | ||
"""colormap selection changed""" | ||
self.update_qmap() | ||
|
||
def on_qmap_data_changed(self): | ||
"""data column selection changed""" | ||
# set previous spin control values if existent | ||
self.qmap_sp_range1.blockSignals(True) | ||
self.qmap_sp_range2.blockSignals(True) | ||
if hasattr(self, "_cache_qmap_spin_ctl"): | ||
data = self.qmap_data_cb.currentIndex() | ||
if data in self._cache_qmap_spin_ctl: | ||
vmin, vmax = self._cache_qmap_spin_ctl[data] | ||
else: | ||
vmin = vmax = 0 | ||
self.qmap_sp_range1.setValue(vmin) | ||
self.qmap_sp_range2.setValue(vmax) | ||
self.qmap_sp_range1.blockSignals(False) | ||
self.qmap_sp_range2.blockSignals(False) | ||
self.update_qmap() | ||
|
||
def on_qmap_min_max_changed(self): | ||
"""min or max spin controls changed""" | ||
# store spin control values for data column | ||
vmin = self.qmap_sp_range1.value() | ||
vmax = self.qmap_sp_range2.value() | ||
data = self.qmap_data_cb.currentIndex() | ||
if not hasattr(self, "_cache_qmap_spin_ctl"): | ||
self._cache_qmap_spin_ctl = {} | ||
self._cache_qmap_spin_ctl[data] = (vmin, vmax) | ||
self.update_qmap() | ||
|
||
def on_qmap_selection(self, idx): | ||
"""Show the curve indexed in the current qmap""" | ||
# Perform operations on ForceDistance | ||
fd = self.parent().parent().parent().parent() | ||
# Get the qmap name | ||
cc = fd.current_curve | ||
# idx is `enum` and curves are sorted | ||
curves = [ci for ci in fd.data_set if ci.path == cc.path] | ||
fdist = curves[idx] | ||
idcurve = fd.data_set.index(fdist) | ||
item = fd.list_curves.topLevelItem(idcurve) | ||
fd.list_curves.setCurrentItem(item) | ||
|
||
def update_qmap(self, fdist_map, index): | ||
# Build list of possible selections | ||
selist = nanite.qmap.available_features | ||
|
||
# Get plotting parameter and check if it makes sense | ||
feature = self.qmap_data_cb.currentText() | ||
if not feature or feature not in selist: | ||
# Use a default plotting map | ||
feature = "data min height" | ||
|
||
# Make sure that we have a valid property to plot | ||
assert feature in selist | ||
|
||
# Update dropdown menu with possible selections | ||
# disable signals while updating the combobox | ||
self.qmap_data_cb.blockSignals(True) | ||
# remove all items | ||
for _i in range(self.qmap_data_cb.count()): | ||
self.qmap_data_cb.removeItem(0) | ||
# add new items | ||
for item in selist: | ||
self.qmap_data_cb.addItem(item) | ||
self.qmap_data_cb.setCurrentIndex(selist.index(feature)) | ||
self.qmap_data_cb.blockSignals(False) | ||
|
||
if len(fdist_map) > 1: | ||
# Get map data | ||
qmap = nanite.QMap(fdist_map) | ||
# update plot | ||
self.mpl_qmap.update(qmap=qmap, | ||
feature=feature, | ||
cmap=self.qmpa_cmap_cb.currentText(), | ||
vmin=self.qmap_sp_range1.value(), | ||
vmax=self.qmap_sp_range2.value()) | ||
self.mpl_qmap.set_selection_by_index(index) | ||
else: | ||
self.mpl_qmap.reset() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>Form</class> | ||
<widget class="QWidget" name="Form"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>400</width> | ||
<height>300</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>Form</string> | ||
</property> | ||
<layout class="QVBoxLayout" name="verticalLayout"> | ||
<item> | ||
<layout class="QHBoxLayout" name="horizontalLayout_12"> | ||
<property name="spacing"> | ||
<number>5</number> | ||
</property> | ||
<property name="bottomMargin"> | ||
<number>0</number> | ||
</property> | ||
<item> | ||
<layout class="QVBoxLayout" name="verticalLayout_14"> | ||
<item> | ||
<widget class="QLabel" name="label_15"> | ||
<property name="sizePolicy"> | ||
<sizepolicy hsizetype="Minimum" vsizetype="Minimum"> | ||
<horstretch>0</horstretch> | ||
<verstretch>0</verstretch> | ||
</sizepolicy> | ||
</property> | ||
<property name="text"> | ||
<string>QMap data</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<widget class="QLabel" name="label_18"> | ||
<property name="text"> | ||
<string>Color map</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<widget class="QLabel" name="label_17"> | ||
<property name="text"> | ||
<string>Data range</string> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</item> | ||
<item> | ||
<layout class="QVBoxLayout" name="verticalLayout_15"> | ||
<property name="leftMargin"> | ||
<number>0</number> | ||
</property> | ||
<item> | ||
<widget class="QComboBox" name="qmap_data_cb"> | ||
<property name="sizePolicy"> | ||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed"> | ||
<horstretch>0</horstretch> | ||
<verstretch>0</verstretch> | ||
</sizepolicy> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<widget class="QComboBox" name="qmpa_cmap_cb"/> | ||
</item> | ||
<item> | ||
<layout class="QHBoxLayout" name="horizontalLayout_14"> | ||
<item> | ||
<widget class="QDoubleSpinBox" name="qmap_sp_range1"> | ||
<property name="decimals"> | ||
<number>10</number> | ||
</property> | ||
<property name="minimum"> | ||
<double>-1000000000.000000000000000</double> | ||
</property> | ||
<property name="maximum"> | ||
<double>1000000000.000000000000000</double> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<widget class="QDoubleSpinBox" name="qmap_sp_range2"> | ||
<property name="decimals"> | ||
<number>10</number> | ||
</property> | ||
<property name="minimum"> | ||
<double>-100000000.000000000000000</double> | ||
</property> | ||
<property name="maximum"> | ||
<double>100000000.000000000000000</double> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</item> | ||
</layout> | ||
</item> | ||
</layout> | ||
</item> | ||
<item> | ||
<widget class="QWidget" name="widget_5" native="true"> | ||
<layout class="QVBoxLayout" name="verticalLayout_12"> | ||
<property name="spacing"> | ||
<number>0</number> | ||
</property> | ||
<property name="leftMargin"> | ||
<number>0</number> | ||
</property> | ||
<property name="topMargin"> | ||
<number>0</number> | ||
</property> | ||
<property name="rightMargin"> | ||
<number>0</number> | ||
</property> | ||
<property name="bottomMargin"> | ||
<number>0</number> | ||
</property> | ||
</layout> | ||
</widget> | ||
</item> | ||
<item> | ||
<widget class="QWidget" name="qmap_mplwidget" native="true"> | ||
<layout class="QVBoxLayout" name="qmap_mpllayout"> | ||
<property name="spacing"> | ||
<number>7</number> | ||
</property> | ||
<property name="sizeConstraint"> | ||
<enum>QLayout::SetDefaultConstraint</enum> | ||
</property> | ||
<property name="leftMargin"> | ||
<number>0</number> | ||
</property> | ||
<property name="topMargin"> | ||
<number>0</number> | ||
</property> | ||
<property name="rightMargin"> | ||
<number>0</number> | ||
</property> | ||
<property name="bottomMargin"> | ||
<number>0</number> | ||
</property> | ||
</layout> | ||
</widget> | ||
</item> | ||
</layout> | ||
</widget> | ||
<resources/> | ||
<connections/> | ||
</ui> |