Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable LUT selection for emodulus computation in analysis view #166

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
2.18.2
- enh: enable lut selection for emodulus computation (#71)
2.18.1
- setup: bump dclab to 0.61.3 (replace rpy2 with wrapper) (#73 #161)
2.18.0
Expand Down
22 changes: 21 additions & 1 deletion shapeout2/gui/analysis/ana_slot.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def __init__(self, *args, **kwargs):
# init
self._update_emodulus_medium_choices()
self._update_emodulus_temp_choices()
self._update_emodulus_lut_choices()

self.update_content()

Expand All @@ -63,6 +64,7 @@ def __getstate__(self):
emod_visc = self.doubleSpinBox_visc.value() # user input
scenario = None
emod_visc_model = self.comboBox_visc_model.currentText()
emod_select_lut = self.comboBox_lut.currentText()
state = {
"identifier": slot_state["identifier"],
"name": self.lineEdit_name.text(),
Expand All @@ -83,7 +85,7 @@ def __getstate__(self):
},
"emodulus": {
"emodulus enabled": slot_state["emodulus"]["emodulus enabled"],
"emodulus lut": "LE-2D-FEM-19",
"emodulus lut": emod_select_lut,
# It is ok if we have user-defined strings here, because
# only media in KNOWN_MEDIA are passed to dclab in the end.
"emodulus medium": self.comboBox_medium.currentData(),
Expand Down Expand Up @@ -143,6 +145,9 @@ def __setstate__(self, state):
# use defaults from previous session (Herold-2107)
idx_vm = 1
self.comboBox_visc_model.setCurrentIndex(idx_vm)
# Set current state of the emodulus lut
idx_lut = self.comboBox_lut.findData(emodulus.get("emodulus lut", ""))
self.comboBox_lut.setCurrentIndex(idx_lut)
# This has to be done after setting the scenario
# (otherwise it might be overridden in the frontend)
self.doubleSpinBox_temp.setValue(emodulus["emodulus temperature"])
Expand Down Expand Up @@ -264,6 +269,21 @@ def _update_emodulus_temp_choices(self):
self.comboBox_temp.setCurrentIndex(idx)
self.comboBox_temp.blockSignals(False)

def _update_emodulus_lut_choices(self):
"""update currently available LUT choices for YM

The previous selection is preserved. Signals are blocked.
"""
self.comboBox_lut.blockSignals(True)
cursel = self.comboBox_lut.currentData()
self.comboBox_lut.clear()
lut_dict = dclab.features.emodulus.load.get_internal_lut_names_dict()
for lut_id in lut_dict.keys():
self.comboBox_lut.addItem(lut_id, lut_id)
idx = self.comboBox_lut.findData(cursel)
self.comboBox_lut.setCurrentIndex(idx)
self.comboBox_lut.blockSignals(False)

@property
def current_slot_state(self):
if self.slot_ids:
Expand Down
142 changes: 78 additions & 64 deletions shapeout2/gui/analysis/ana_slot.ui
Original file line number Diff line number Diff line change
Expand Up @@ -194,18 +194,12 @@
<string>Young's modulus</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="5">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>20</height>
</size>
<item row="1" column="0">
<widget class="QLabel" name="label_temp">
<property name="text">
<string>Temperature</string>
</property>
</spacer>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_6">
Expand All @@ -214,21 +208,63 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Viscosity</string>
</property>
</widget>
<item row="3" column="2">
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QComboBox" name="comboBox_lut"/>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_temp">
<item row="0" column="2">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QComboBox" name="comboBox_medium">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<item>
<property name="text">
<string>CellCarrier</string>
</property>
</item>
<item>
<property name="text">
<string>CellCarrier B</string>
</property>
</item>
<item>
<property name="text">
<string>water</string>
</property>
</item>
<item>
<property name="text">
<string>other</string>
</property>
</item>
<item>
<property name="text">
<string>unknown</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Temperature</string>
<string>Select LUT</string>
</property>
</widget>
</item>
<item row="2" column="1">
<item row="2" column="2">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QComboBox" name="comboBox_visc_model">
Expand Down Expand Up @@ -259,7 +295,7 @@
</item>
</layout>
</item>
<item row="1" column="1">
<item row="1" column="2">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QComboBox" name="comboBox_temp">
Expand Down Expand Up @@ -307,49 +343,27 @@
</item>
</layout>
</item>
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QComboBox" name="comboBox_medium">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<item>
<property name="text">
<string>CellCarrier</string>
</property>
</item>
<item>
<property name="text">
<string>CellCarrier B</string>
</property>
</item>
<item>
<property name="text">
<string>water</string>
</property>
</item>
<item>
<property name="text">
<string>other</string>
</property>
</item>
<item>
<property name="text">
<string>unknown</string>
</property>
</item>
</widget>
</item>
</layout>
<item row="1" column="6">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="4">
<item row="2" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Viscosity</string>
</property>
</widget>
</item>
<item row="0" column="5">
<widget class="QLabel" name="label_5">
<property name="text">
<string>&lt;a href=&quot;https://shapeout2.readthedocs.io/en/stable/sec_qg_youngs_modulus.html&quot;&gt; help &lt;/a&gt;</string>
Expand Down
54 changes: 54 additions & 0 deletions tests/test_gui_emodulus.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,57 @@ def test_user_defined_medium_should_work(qtbot):
assert np.isnan(wsl.__getstate__()["emodulus"]["emodulus temperature"])
assert wsl.__getstate__()["emodulus"]["emodulus medium"] == "MyMedium"
assert wsl.__getstate__()["emodulus"]["emodulus scenario"] is None


def test_changeable_lut_selection(qtbot):
mw = ShapeOut2()
qtbot.addWidget(mw)

# add fake measurement
path1 = make_dataset(medium="CellCarrier", temp=22.5, temp_range=[22, 23])

mw.add_dataslot(paths=[path1])
wsl = mw.widget_ana_view.widget_slot
ds = mw.pipeline.slots[0].get_dataset()

assert ds.config["setup"]["medium"] == "CellCarrier", "sanity check"
assert wsl.comboBox_medium.currentData() == "CellCarrier"

# set viscosity model manually
idvm = wsl.comboBox_visc_model.findText("buyukurganci-2022")
wsl.comboBox_visc_model.setCurrentIndex(idvm)
# set lut manually
idlut = wsl.comboBox_lut.findData("HE-2D-FEM-22")
wsl.comboBox_lut.setCurrentIndex(idlut)
qtbot.mouseClick(wsl.pushButton_apply, QtCore.Qt.LeftButton)
QtWidgets.QApplication.processEvents(QtCore.QEventLoop.AllEvents, 300)

# check LUT selection
assert wsl.comboBox_lut.currentData() == "HE-2D-FEM-22"

# check whether that worked
assert wsl.get_dataset(
).config["calculation"]["emodulus lut"] == "HE-2D-FEM-22"
assert wsl.get_dataset(
).config["calculation"]["emodulus viscosity model"] == "buyukurganci-2022"

# set different lut manually
idlut = wsl.comboBox_lut.findData("HE-3D-FEM-22")
wsl.comboBox_lut.setCurrentIndex(idlut)
qtbot.mouseClick(wsl.pushButton_apply, QtCore.Qt.LeftButton)
QtWidgets.QApplication.processEvents(QtCore.QEventLoop.AllEvents, 300)

# check new LUT selection
assert wsl.comboBox_lut.currentData() == "HE-3D-FEM-22"
# check whether that worked
assert wsl.get_dataset(
).config["calculation"]["emodulus lut"] == "HE-3D-FEM-22"

# This is the actual test
assert wsl.comboBox_visc_model.currentText() == "buyukurganci-2022"
assert wsl.comboBox_lut.currentText() == "HE-3D-FEM-22"

try:
path1.unlink()
except BaseException:
pass
Loading