Fixed file_path, added file_prefix
This commit is contained in:
@@ -10,6 +10,7 @@ import json
|
||||
from time import sleep
|
||||
from threading import Thread
|
||||
import requests
|
||||
import os
|
||||
|
||||
from ophyd import Device, Signal, Component, Kind, Staged
|
||||
from ophyd.status import SubscriptionStatus
|
||||
@@ -20,6 +21,7 @@ from websockets.exceptions import ConnectionClosedOK, ConnectionClosedError
|
||||
from ophyd_devices.interfaces.base_classes.psi_detector_base import PSIDetectorBase as PSIDeviceBase
|
||||
from ophyd_devices.interfaces.base_classes.psi_detector_base import CustomDetectorMixin as CustomDeviceMixin
|
||||
from bec_lib import bec_logger
|
||||
from bec_lib.file_utils import FileWriter
|
||||
logger = bec_logger.logger
|
||||
|
||||
|
||||
@@ -47,7 +49,21 @@ class StdDaqMixin(CustomDeviceMixin):
|
||||
if 'nr_writers' in scanargs and scanargs['nr_writers'] != None:
|
||||
d['nr_writers'] = scanargs['nr_writers']
|
||||
if 'file_path' in scanargs and scanargs['file_path']!=None:
|
||||
self.parent.file_path.set(scanargs['file_path']).wait()
|
||||
self.parent.file_path.set(scanargs['file_path'].replace('data','gpfs')).wait()
|
||||
print(scanargs['file_path'])
|
||||
if os.path.isdir(scanargs['file_path']):
|
||||
print("isdir")
|
||||
pass
|
||||
else:
|
||||
print("creating")
|
||||
try:
|
||||
os.makedirs(scanargs['file_path'], 0o777)
|
||||
os.system('chmod -R 777 ' + scanargs['base_path'])
|
||||
except:
|
||||
print('Problem with creating folder')
|
||||
if 'file_prefix' in scanargs and scanargs['file_prefix']!=None:
|
||||
print(scanargs['file_prefix'])
|
||||
self.parent.file_prefix.set(scanargs['file_prefix']).wait()
|
||||
|
||||
if "daq_num_points" in scanargs:
|
||||
d["num_points_total"] = scanargs["daq_num_points"]
|
||||
@@ -138,7 +154,8 @@ class StdDaqClient(PSIDeviceBase):
|
||||
runstatus = Component(Signal, value="unknown", kind=Kind.normal, metadata={'write_access': False})
|
||||
num_images = Component(Signal, value=10000, kind=Kind.config)
|
||||
file_path = Component(Signal, value="/gpfs/test/test-beamline", kind=Kind.config)
|
||||
# Configuration attributes
|
||||
file_prefix = Component(Signal, value="file", kind=Kind.config)
|
||||
# Configuration attributes
|
||||
rest_url = Component(Signal, kind=Kind.config, metadata={'write_access': False})
|
||||
cfg_detector_name = Component(Signal, kind=Kind.config)
|
||||
cfg_detector_type = Component(Signal, kind=Kind.config)
|
||||
@@ -245,6 +262,7 @@ class StdDaqClient(PSIDeviceBase):
|
||||
nr_writers: int, optional
|
||||
Number of writers [int].
|
||||
"""
|
||||
|
||||
# Configuration parameters
|
||||
if 'image_width' in d and d['image_width']!=None:
|
||||
self.cfg_pixel_width.set(d['image_width']).wait()
|
||||
@@ -257,8 +275,6 @@ class StdDaqClient(PSIDeviceBase):
|
||||
# Run parameters
|
||||
if 'num_points_total' in d:
|
||||
self.num_images.set(d['num_points_total']).wait()
|
||||
if 'file_path' in d and d['file_path']!=None:
|
||||
self.file_path.set(d['file_path']).wait()
|
||||
|
||||
# Restart the DAQ if resolution changed
|
||||
cfg = self.get_daq_config()
|
||||
@@ -288,10 +304,8 @@ class StdDaqClient(PSIDeviceBase):
|
||||
it for obvious failures.
|
||||
"""
|
||||
# Can't stage into a running exposure
|
||||
print('Before')
|
||||
if self.state() != 'idle':
|
||||
raise RuntimeError(f"[{self.name}] stdDAQ can't stage from state: {self.state()}")
|
||||
print('After')
|
||||
|
||||
# Must make sure that image size matches the data source
|
||||
if self.data_source_name is not None:
|
||||
@@ -308,10 +322,12 @@ class StdDaqClient(PSIDeviceBase):
|
||||
|
||||
file_path = self.file_path.get()
|
||||
num_images = self.num_images.get()
|
||||
file_prefix = self.file_prefix.get()
|
||||
print(file_prefix)
|
||||
|
||||
# New connection
|
||||
self._wsclient = self.connect()
|
||||
message = {"command": "start", "path": file_path, "n_image": num_images, }
|
||||
message = {"command": "start", "path": file_path, "file_prefix": file_prefix, "n_image": num_images, }
|
||||
reply = self.message(message)
|
||||
|
||||
if reply is not None:
|
||||
@@ -413,7 +429,7 @@ class StdDaqClient(PSIDeviceBase):
|
||||
if r.status_code != 200:
|
||||
raise ConnectionError(f"[{self.name}] Error {r.status_code}:\t{r.text}")
|
||||
# Wait for service to restart (and connect to make sure)
|
||||
sleep(settle_time)
|
||||
#sleep(settle_time)
|
||||
self.connect()
|
||||
return r.json()
|
||||
|
||||
@@ -423,16 +439,15 @@ class StdDaqClient(PSIDeviceBase):
|
||||
"""
|
||||
url = self.rest_url.get() + '/api/h5/create_interleaved_vds'
|
||||
file_path = self.file_path.get()
|
||||
file_prefix = self.file_prefix.get()
|
||||
|
||||
r = requests.post(
|
||||
url,
|
||||
params = {'user': 'ioc'},
|
||||
data = {'base_path': file_path, 'output_file': 'fede_virtual_test'},
|
||||
json = {'base_path': file_path, 'file_prefix': file_prefix, 'output_file': file_prefix.rstrip('_') + '.h5'},
|
||||
timeout = 2,
|
||||
headers = {'Content-type': 'application/json'}
|
||||
)
|
||||
print(r)
|
||||
print(file_path)
|
||||
|
||||
def nuke(self, restarttime=5):
|
||||
""" Reconfigures the stdDAQ to restart the services. This causes
|
||||
|
||||
@@ -4,7 +4,6 @@ import numpy as np
|
||||
from bec_lib.device import DeviceBase
|
||||
from bec_server.scan_server.scans import Acquire, AsyncFlyScanBase
|
||||
|
||||
|
||||
class AcquireDark(Acquire):
|
||||
scan_name = "acquire_dark"
|
||||
required_kwargs = ["exp_burst"]
|
||||
|
||||
@@ -26,13 +26,10 @@ class Measurement:
|
||||
"""
|
||||
Build and set filename for bec and stddaq
|
||||
"""
|
||||
bec.system_config.file_suffix = self.sample_name
|
||||
bec.system_config.file_directory = os.path.join(self.data_path,self.sample_name)
|
||||
self.file_path = '/data/test/test-beamline/test_fede'
|
||||
if os.path.isdir(self.file_path):
|
||||
pass
|
||||
else:
|
||||
os.mkdir(self.file_path)
|
||||
#bec.system_config.file_suffix = self.sample_name
|
||||
self.scan_sample_name = 'S' + str(bec.queue.next_scan_number) + '_' + self.sample_name
|
||||
print(self.scan_sample_name)
|
||||
bec.system_config.file_directory = os.path.join(self.data_path,self.sample_name,self.scan_sample_name)
|
||||
|
||||
def configure(self,sample_name=None, data_path=None, exposure_time=None,
|
||||
exposure_period=None, roix=None, roiy=None,nimages=None,
|
||||
@@ -84,9 +81,27 @@ class Measurement:
|
||||
self.roiy = roiy
|
||||
|
||||
self.build_filename()
|
||||
|
||||
def show_all(self):
|
||||
|
||||
"""
|
||||
Show configuration
|
||||
|
||||
TODO: check active devices, write the config for each device and if none read from device
|
||||
"""
|
||||
|
||||
print("Sample name: " + self.sample_name)
|
||||
print("Data path: " + self.data_path)
|
||||
print("Number of images: " + str(self.nimages))
|
||||
print("Number of darks: " + str(self.nimages_dark))
|
||||
print("Number of flats: " + str(self.nimages_white))
|
||||
print("Exposure time: " + str(self.exposure_time))
|
||||
print("Exposure period: " + str(self.exposure_period))
|
||||
print("Roix: " + str(self.roix))
|
||||
print("Roiy: " + str(self.roiy))
|
||||
|
||||
def acquire_darks(self,nimages_dark, exposure_time=None, exposure_period=None,
|
||||
roix=None, roiy=None, acq_mode=None, file_path=None):
|
||||
roix=None, roiy=None, acq_mode=None):
|
||||
"""
|
||||
Acquire a set of dark images with shutters closed.
|
||||
|
||||
@@ -104,8 +119,6 @@ class Measurement:
|
||||
ROI size in the y-direction [pixels]
|
||||
acq_mode : str, optional
|
||||
Predefined acquisition mode (default=None)
|
||||
file_path : str, optional
|
||||
File path for standard daq (default=None)
|
||||
|
||||
Example:
|
||||
--------
|
||||
@@ -150,14 +163,17 @@ class Measurement:
|
||||
self.roix = roix
|
||||
if roiy != None:
|
||||
self.roiy = roiy
|
||||
|
||||
if file_path!=None:
|
||||
if os.path.isdir(file_path):
|
||||
pass
|
||||
else:
|
||||
os.mkdir(file_path)
|
||||
|
||||
|
||||
# To add folder with device name
|
||||
file_path = os.path.join('/data/test/test-beamline',bec.system_config.file_directory, '_device_dat') # _device_dat does not work for now.
|
||||
print(file_path)
|
||||
# A hack for now
|
||||
base_path = os.path.join('/data/test/test-beamline',self.data_path)
|
||||
print(base_path)
|
||||
file_prefix = self.scan_sample_name + '_data_dark_' # to add device name
|
||||
print(file_prefix)
|
||||
### TODO: camera reset
|
||||
print("Handing over to 'scans.acquire_dark")
|
||||
scans.acquire_dark(exp_burst=nimages_dark, exp_time=self.exposure_time, exp_period=self.exposure_period, image_width=self.roix,
|
||||
image_height=self.roiy, acq_mode=acq_mode, file_path=file_path, nr_writers=2)
|
||||
image_height=self.roiy, acq_mode=acq_mode, file_path=file_path, nr_writers=2, base_path=base_path,
|
||||
file_prefix=file_prefix)
|
||||
Reference in New Issue
Block a user