import os import zprocess import runmanager import h5py from labscript_utils.labconfig import LabConfig h5_filename = "test_shot_file_001.h5" params = {'laser_detuning': 7.0, 'magnetic_field_on': True} # Make a HDF5 file and put the parameters of this shot into it runmanager.make_single_run_file(filename=h5_filename, sequenceglobals=None, shot_globals=params, sequence_id='test', sequence_index=0, notes='', run_no=0, n_runs=1) with h5py.File(h5_filename) as f: # Put all your other data in the HDF5 file here pass # Send the hdf5 file to lyse, assuming it is running on localhost: config = LabConfig() port = int(config.get('ports','lyse')) data = {'filepath': os.path.abspath(h5_filename)} response = zprocess.zmq_get(port, 'localhost', data) if response != 'added successfully': raise Exception(response)
--
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 labscriptsuite+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to a topic in the Google Groups "The labscript suite" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/labscriptsuite/ZKAhU3fQFs0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to labscriptsuit...@googlegroups.com.
# Send the hdf5 file to lyse, assuming it is running on localhost: config = LabConfig() port = int(config.get('ports','lyse')) data = {'filepath': os.path.abspath(h5_filename)} response = zprocess.zmq_get(port, 'localhost', data) if response != 'added successfully': raise Exception(response)
here, the config stuff is just about getting the TCP port number that lyse is listening on. Unless you have changed it, there will be a default configuration file (in labscript_suite/labconfig) with the default port number. Lyse reads the config file to see what port it should listen on, and the above code similarly reads the config file to see what port to send data to. It sends lyse a dictionary containing the absolute filepath to the HDF5 file in question. We then use the zprocess library to connect to lyse and send data, and get a response. Lyse should respond "added successfully" if it worked, so that's what the error checking is doing there.
So, it would make most sense to add the above code to whatever program is creating the HDF5 files - that way you can tell lyse about them as soon as they have been created.
If however for some reason you can't do this, then you could write a standalone program that watched the folder and send any new filepaths it sees to lyse.
Something like this (also mostly untested):
import os import time import zprocess from labscript_utils.labconfig import LabConfig def submit_to_lyse(h5_filename):
# Send the hdf5 file to lyse, assuming it is running on localhost: config = LabConfig() port = int(config.get('ports','lyse')) data = {'filepath': os.path.abspath(h5_filename)} response = zprocess.zmq_get(port, 'localhost', data) if response != 'added successfully': raise Exception(response)
def watch_for_new_h5_files(): previous_h5_files = set() while True: # Check shot folder every 1 second for new files and submit them to lyse: shot_folder = time.strftime('/Usr/Data/%Y-%m-%d') # Use new date each loop so code can run overnight if os.path.isdir(shot_folder): h5_files = set(os.path.join(shot_folder, f) for f in os.listdir(shot_folder) if f.endswith('.h5')) new_h5_files = h5_files.difference(previous_h5_files) for h5_file in new_h5_files: submit_to_lyse(h5_file) previous_h5_files = h5_files else: print("Shot folder doesn't exist (yet?)") time.sleep(1) if __name__ == "__main__": watch_for_new_h5_files()Hope that helps!-Chris
--
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 labscriptsuite+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
import os import time import zprocess from labscript_utils.labconfig import LabConfig
# Send the hdf5 file to lyse, assuming it is running on localhost: config = LabConfig() port = int(config.get('ports','lyse')) data = {'filepath': os.path.abspath(h5_filename)} response = zprocess.zmq_get(port, 'localhost', data) if response != 'added successfully': raise Exception(response)
To unsubscribe from this group and stop receiving emails from it, send an email to labscriptsuit...@googlegroups.com.
Traceback (most recent call last):
File "/Users/fnj/miniconda2/envs/lyse2/lib/python2.7/runpy.py", line 174, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/Users/fnj/miniconda2/envs/lyse2/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/Users/fnj/labscript_suite2/lyse/__main__.py", line 2143, in <module>
logger = setup_logging('lyse')
File "labscript_utils/setup_logging.py", line 88, in setup_logging
File "/Users/fnj/miniconda2/envs/lyse2/lib/python2.7/site-packages/zprocess/zlog/__init__.py", line 156, in __init__
check_access(self.filepath)
File "/Users/fnj/miniconda2/envs/lyse2/lib/python2.7/site-packages/zprocess/zlog/__init__.py", line 200, in check_access
return _zmq_log_client.check_access(filepath, timeout)
File "/Users/fnj/miniconda2/envs/lyse2/lib/python2.7/site-packages/zprocess/zlog/__init__.py", line 120, in check_access
raise exc_class(message)
OSError: [Errno 2] No such file or directory: u'/Users/fnj/labscript_suite2/lyse/lyse/lyse.log'
Am 24.10.2018 um 17:01 schrieb Chris Billington <chrisjbi...@gmail.com>:HI Fred,I've been running lyse with Python 3, and had considered its port to Python 3 complete. If you report any issues you come up against, I'll look into them!
The error you're seeing now is some path issue, I've seen it before. It's something about exactly which folder the current working directory is set to when you run lyse. How are you starting lyse when you get this error, and if you're staring it from the terminal, which folder are you in when you run the command? I suspect this is the same class of errors as we fixed in BLACS by removing all reference to __file__ when computing paths. It can be wrong in Python 2 in some contexts due to an inconsistency between absolute and relative paths, which has been resolved in Python 3.In the error message, there is an extra '/lyse/' in the filepath to the log, and the zlog server is complaining that the folder doesn't exist, in which it is supposed to create the log file. I could make zlog create intermediate folders in log paths, or better, I should fix whatever has led to the incorrect calculation of the log file path. I do not think the Python logging library creates intermediate folders for log files, so I'm not sure why this issue would be new, I don't think it is unique to us having moved to a logging server (zlog).In the meantime, creating the folder '/Users/fnj/labscript_suite2/lyse/lyse/' ought to stop the error message from appearing - the only consequence is that the log file will be in an extra subfolder.
-Chris
On Wed, Oct 24, 2018 at 10:44 AM Fred Jendrzejewski <fred.jend...@gmail.com> wrote:
Hi,I recently felt like adventures and decided to update lyse, even trying to run it under python 3, which did not work out. Is this supposed to work ?Additionially, I tried to reinstall the python2 version with the current labscript installer. However, this did not work either as I always get the following error:
Traceback (most recent call last):
File "/Users/fnj/miniconda2/envs/lyse2/lib/python2.7/runpy.py", line 174, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/Users/fnj/miniconda2/envs/lyse2/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/Users/fnj/labscript_suite2/lyse/__main__.py", line 2143, in <module>
logger = setup_logging('lyse')
File "labscript_utils/setup_logging.py", line 88, in
setup_logging
File "/Users/fnj/miniconda2/envs/lyse2/lib/python2.7/site-packages/zprocess/zlog/__init__.py", line 156,in __init__
check_access(self.filepath)
File "/Users/fnj/miniconda2/envs/lyse2/lib/python2.7/site-packages/zprocess/zlog/__init__.py", line 200,in check_access
return _zmq_log_client.check_access(filepath, timeout)
File "/Users/fnj/miniconda2/envs/lyse2/lib/python2.7/site-packages/zprocess/zlog/__init__.py", line 120,in check_access
raise exc_class(message)
--
You received this message because you are subscribed to a topic in the Google Groups "The labscript suite" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/labscriptsuite/ZKAhU3fQFs0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to labscriptsuit...@googlegroups.com.