How to recall units from Globals list?

32 views
Skip to first unread message

Andrea Fantini

unread,
Mar 5, 2024, 7:21:23 AMMar 5
to the labscript suite
Hi there,
Quick question: is there any function or dataframe that allows me recall the very units of global variables, initialized on runmanager, when I write my labscript code?
Thank y'all for any reply.
Cheers,
Andy

Edvinas Gvozdiovas

unread,
Mar 5, 2024, 10:08:47 AMMar 5
to labscri...@googlegroups.com
Hi Andrea,

I was asking myself this just a few days ago to no avail. I ended up using h5py to grab the units from "globals/folder/units/variable". Let me know if you need further help, I can share a sample code.

--
You received this message because you are subscribed to the Google Groups "the labscript suite" group.
To unsubscribe from this group and stop receiving emails from it, send an email to labscriptsuit...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/labscriptsuite/17168907-5eb6-477f-b7b9-9d5c5809b3aen%40googlegroups.com.

Andrea Fantini

unread,
Mar 5, 2024, 10:23:30 AMMar 5
to labscri...@googlegroups.com
Thanks Edvinas,
If you could share the script it would help me a lot!
Thanks again,
Cheers,
Andy

Edvinas Gvozdiovas

unread,
Mar 5, 2024, 10:37:39 AMMar 5
to labscri...@googlegroups.com
Try the following (adjust globals_group and global accordingly):

import h5py
from lyse import path
globals_group = "DCFields"
global = "B_Forward"
with h5py.File(path,'r') as shot_h5py: global_units =  shot_h5py["globals"][globals_group]["units"].attrs[global]

Andrea Fantini

unread,
Mar 5, 2024, 12:28:13 PMMar 5
to labscri...@googlegroups.com

Andrea Fantini

unread,
Mar 6, 2024, 5:07:50 AMMar 6
to labscri...@googlegroups.com
Ok so, I managed to do so:
    data_frame = data()
    path=data_frame['filepath'].iloc[-1] #lastvalue in dataframe
    units={}
    for globals_group  in runmanager.get_grouplist(path):
        for global_name in runmanager.get_globalslist(path, globals_group):
            with h5py.File(path,'r') as shot_h5py: global_units =  shot_h5py["globals"][globals_group]["units"].attrs[global_name]
            if global_units=='us': #base unit for time
                g_unit=usec
            elif global_units=='ms':
                g_unit=msec
            elif global_units=='s':
                g_unit=sec
            elif global_units=='Hz':#base unit for frequency
                g_unit=1
            elif global_units=='kHz':
                e_unit=1e3
            elif global_units=='MHz':
                g_unit=1e6
            else:
                g_unit=1
            units[str(global_name)]=g_unit
    GLOBALS={}
    for i in runmanager.remote.get_globals():
        GLOBALS[str(i)]=eval(i)*units[str(i)]
but I have still got the problem to address units directly from runmanager, instead of from lyse. If I update my variable unit or put a new global I need the script to learn the unit right away, i.e. before executing the experimental sequence and reading it in lyse. Any ideas?
Thank y'all,
Andy

Andrea Fantini

unread,
Mar 6, 2024, 8:37:55 AMMar 6
to labscri...@googlegroups.com
Hi everybody,
I just solved it!
Sorry for having bothered for such an easy thing.
Cheers,
Andy
Reply all
Reply to author
Forward
0 new messages