Added ease-of-access function update_parameters to OTFModule. Updated code reference

This commit is contained in:
2025-08-27 14:26:11 +02:00
parent 558bbfded9
commit a590027c44
2 changed files with 19 additions and 4 deletions

View File

@@ -18,6 +18,8 @@ import frappy_psi.tnmr.sequence_generation as seq_gen
import frappy.core as fc import frappy.core as fc
import frappy import frappy
from frappy.errors import ProgrammingError
import win32com import win32com
import pythoncom import pythoncom
import numpy as np import numpy as np
@@ -27,6 +29,8 @@ import time
import os import os
import traceback import traceback
TNMR_MAX_PULSES = 100
class ProgrammedSequence(fc.Drivable): # Drivable only for kill() funcitonality class ProgrammedSequence(fc.Drivable): # Drivable only for kill() funcitonality
"""An NMR device being driven by an instance of TNMR. Requires that an instance of TNMR is opened before creation. """An NMR device being driven by an instance of TNMR. Requires that an instance of TNMR is opened before creation.
@@ -43,6 +47,8 @@ class ProgrammedSequence(fc.Drivable): # Drivable only for kill() funcitonality
Acquisition Parameters Acquisition Parameters
---------------------- ----------------------
These parameters can be set from a dictionary, using the update_parameters method/command.
title: a title which will be embedded to the sequence files. Use this for identification. title: a title which will be embedded to the sequence files. Use this for identification.
acquisition_time: float (usecs) which describes the length of acquisition acquisition_time: float (usecs) which describes the length of acquisition
ringdown_time: float (usecs) which describes the length of ringdown ringdown_time: float (usecs) which describes the length of ringdown
@@ -51,6 +57,7 @@ class ProgrammedSequence(fc.Drivable): # Drivable only for kill() funcitonality
acq_phase_cycle: str, the phase cycle to run on acquisition (eg., '0 1 1 2', '0 1 2 3', '1 1 2 2 0 0 3 3 1 2 3 4', ...) acq_phase_cycle: str, the phase cycle to run on acquisition (eg., '0 1 1 2', '0 1 2 3', '1 1 2 2 0 0 3 3 1 2 3 4', ...)
num_acqs: int (ct), the number of 1D scans to take per sequence num_acqs: int (ct), the number of 1D scans to take per sequence
obs_freq: float (MHz), the NMR frequency obs_freq: float (MHz), the NMR frequency
Commands Commands
-------- --------
@@ -90,7 +97,7 @@ class ProgrammedSequence(fc.Drivable): # Drivable only for kill() funcitonality
sequence_data = fc.Parameter('sequence_config', fc.ArrayOf(fc.StructOf(pulse_width=fc.FloatRange(unit='usecs'), sequence_data = fc.Parameter('sequence_config', fc.ArrayOf(fc.StructOf(pulse_width=fc.FloatRange(unit='usecs'),
pulse_height=fc.FloatRange(unit='%'), pulse_height=fc.FloatRange(unit='%'),
delay_time=fc.FloatRange(unit='usecs'), delay_time=fc.FloatRange(unit='usecs'),
phase_cycle=fc.StringType()), minlen=0), default=[{'pulse_width':0,'pulse_height':0,'delay_time':0,'phase_cycle':''}]*100, readonly=False) phase_cycle=fc.StringType()), minlen=0), default=[{'pulse_width':0,'pulse_height':0,'delay_time':0,'phase_cycle':''}]*TNMR_MAX_PULSES, readonly=False)
num_acqs_actual = fc.Parameter('num_acqs', fc.IntRange(), readonly=True, default=0) num_acqs_actual = fc.Parameter('num_acqs', fc.IntRange(), readonly=True, default=0)
# final details # final details
@@ -155,6 +162,14 @@ class ProgrammedSequence(fc.Drivable): # Drivable only for kill() funcitonality
except: except:
traceback.print_exc() traceback.print_exc()
pass pass
@fc.Command(description='Updates any device parameters via a dictionary', argument={'type': 'dict'})
def update_parameters(self, dct):
for k, v in dct.items():
if(hasattr(self, k)):
setattr(self, k, v)
else:
self.logger.info(f'Bad TNMR parameter: {k}')
### READ/WRITE ### READ/WRITE
@@ -246,7 +261,7 @@ class ProgrammedSequence(fc.Drivable): # Drivable only for kill() funcitonality
seq = [] seq = []
seq += t seq += t
print(seq) print(seq)
seq += [{'pulse_width':0,'pulse_height':0,'delay_time':0,'phase_cycle':''}] * (100-self.sequence_length) # because nicos will only send the smallest size it has ever sent... seq += [{'pulse_width':0,'pulse_height':0,'delay_time':0,'phase_cycle':''}] * (TNMR_MAX_PULSES-self.sequence_length) # because nicos will only send the smallest size it has ever sent...
self.sequence_data = seq self.sequence_data = seq
return self.read_sequence_data() return self.read_sequence_data()
@@ -336,10 +351,10 @@ class ProgrammedSequence(fc.Drivable): # Drivable only for kill() funcitonality
# then, load the thing into TNMR # then, load the thing into TNMR
success = self.tnmr().load_sequence(filename) success = self.tnmr().load_sequence(filename)
if not(success): if not(success):
print('Retrying load sequence') self.logger.info('Retrying load pulse sequence')
success = self.tnmr().load_sequence(filename) success = self.tnmr().load_sequence(filename)
if not(success): if not(success):
print('WARNING: Failed!') self.logger.info('Failed pulse sequence load!')
raise Exception() raise Exception()
# load some parameters back to TNMR # load some parameters back to TNMR

Binary file not shown.