VitorBarrote
To create a user interface element that allows someone to switch between different beam seconds methods you need to use our python interface to Qt widgets. That documentation is for C++, but what is available and the parameters required, etc. are very similar for Python. For example, you could create a QComboBox with the options as follows:
# Import the relevant widget
from iolite.QtGui import QComboBox
# Assuming you already have your main settings widget called 'widget',
# create the QComboBox with 'widget' as its parent
bsMethodComboBox = QComboBox(widget)
# Next you can add some items
bsMethodComboBox.addItems(['Laser log', 'Gaps between samples', 'Cutoff threshold'])
# And then add it to a layout. There are a lot of ways you might do this and how you do it
# will depend on the type of layout you have set for 'widget'. I'm going to assume there is
# a QFormLayout set for 'widget', so then we could do
widget.layout().addRow('Beam seconds method', bsMethodComboBox)
# Finally, we need a way to update the stored settings when the user changes that control
bsMethodComboBox.activated.connect(lambda v: drs.setSetting('BeamSecondsMethod', bsMethodComboBox.currentText))
Now when when the runDRS
function is called you could get the stored setting and do the appropriate calculation
method = drs.setting('BeamSecondsMethod')
if 'log' in method:
drs.createBeamSecondsFromLaserLog()
elif 'samples' in method:
drs.createBeamSecondsFromSamples()
# and so on...
Here is an example DRS that only does beam seconds...
# A python-based data reduction scheme for iolite 4 starts with some metadata
#/ Type: DRS
#/ Name: Beam Seconds
#/ Authors: Joe
#/ Description: Calculates beam seconds
#/ References:
#/ Version: 0
#/ Contact: joe@iolite-software.com
from iolite.QtGui import QWidget, QComboBox, QFormLayout, QLineEdit
def runDRS():
drs.message('Calculating beam seconds...')
drs.progress(0)
# Get settings
method = drs.setting('BeamSecondsMethod')
print(f'Using beam seconds method {method}')
try:
channel = data.timeSeries(drs.setting('BeamSecondsChannel'))
value = float(drs.setting('BeamSecondsValue'))
except Exception as e:
if 'threshold' in method or 'change' in method:
raise Exception(e.what())
else:
pass
if 'log' in method:
drs.createBeamSecondsFromLaserLog()
elif 'samples' in method:
drs.createBeamSecondsFromSamples()
elif 'threshold' in method:
drs.createBeamSecondsFromCutoff(channel, value)
elif 'change' in method:
drs.createBeamSecondsFromJump(channel, value)
drs.message('Finished!')
drs.progress(100)
drs.finished()
def settingsWidget():
widget = QWidget()
formLayout = QFormLayout()
widget.setLayout(formLayout)
bsMethodComboBox = QComboBox(widget)
bsMethodComboBox.addItems(['Laser log', 'Gaps between samples', 'Cutoff threshold', 'Rate of change'])
bsMethodComboBox.activated.connect(lambda v: drs.setSetting('BeamSecondsMethod', bsMethodComboBox.currentText))
bsMethodComboBox.setCurrentText(drs.setting('BeamSecondsMethod'))
formLayout.addRow('Beam seconds method', bsMethodComboBox)
# Also need controls to select which channel/value for threshold or rate
bsChannelComboBox = QComboBox(widget)
bsChannelComboBox.addItems(data.timeSeriesNames(data.Input))
bsChannelComboBox.activated.connect(lambda v: drs.setSetting('BeamSecondsChannel', bsChannelComboBox.currentText))
bsChannelComboBox.setCurrentText(drs.setting('BeamSecondsChannel'))
formLayout.addRow('Beam seconds channel', bsChannelComboBox)
bsValueLineEdit = QLineEdit(widget)
bsValueLineEdit.textEdited.connect(lambda v: drs.setSetting('BeamSecondsValue', float(bsValueLineEdit.text)))
bsValueLineEdit.setText(drs.setting('BeamSecondsValue'))
formLayout.addRow('Beam seconds value', bsValueLineEdit)
drs.setSettingsWidget(widget)
The way you were trying to get the beam seconds that you originally posted looked correct to me, so I think it is just a matter of fixing the indentation (and adding the UI elements, if you want to be able to configure it).
An example of actually doing a down-hole correction using the beam seconds can be found in the U-Pb example. Of particular interest are lines 26-27 (form of function to fit) and lines 126-141 (compiling down-hole data, removing null values, performing the fit, and creating the corrected channel).
I'll make a separate post with instructions on how to upload images.
All the best,