large cleanup, part 1
This commit is contained in:
195
cristallina.py
195
cristallina.py
@ -1,36 +1,42 @@
|
||||
#!/usr/bin/env python
|
||||
import sys
|
||||
import os
|
||||
os.chdir('/sf/cristallina/applications/slic/cristallina')
|
||||
|
||||
import re
|
||||
# setup logging
|
||||
import logging
|
||||
logger = logging.getLogger("slic")
|
||||
logger.setLevel(logging.INFO)
|
||||
import time
|
||||
from time import sleep
|
||||
|
||||
from tracemalloc import start
|
||||
import numpy as np
|
||||
|
||||
os.chdir("/sf/cristallina/applications/slic/cristallina_cleanup")
|
||||
|
||||
# setup logging
|
||||
from loguru import logger
|
||||
|
||||
logger.remove()
|
||||
logger.add(
|
||||
sys.stderr,
|
||||
format="{time:YYYY-MM-DD at HH:mm:ss} | {level} | {message}",
|
||||
level="INFO",
|
||||
)
|
||||
logger.info("Loading started.")
|
||||
|
||||
# create file handler which logs
|
||||
try:
|
||||
fh = logging.FileHandler('/sf/cristallina/applications/slic/cristallina/log/cristallina.log')
|
||||
fh.setLevel(logging.DEBUG)
|
||||
logger.addHandler(fh)
|
||||
# TODO: better directory for log files? should not be pgroup specific so that this always works
|
||||
try:
|
||||
logger.add(
|
||||
"/sf/cristallina/applications/slic/cristallina/log/cristallina.log",
|
||||
format="{time:YYYY-MM-DD at HH:mm:ss} | {level} | {message}",
|
||||
level="DEBUG",
|
||||
)
|
||||
except PermissionError as e:
|
||||
logger.warning("Cannot write log file.")
|
||||
logger.warning(e)
|
||||
|
||||
|
||||
from time import sleep
|
||||
from tracemalloc import start
|
||||
|
||||
from epics import PV
|
||||
|
||||
from stand_client import Client
|
||||
|
||||
stand_client = Client(host='saresc-vcons-02.psi.ch', port=9090)
|
||||
|
||||
|
||||
from alignment_laser import AlignmentLaser
|
||||
from devices.alignment_laser import AlignmentLaser
|
||||
from slic.gui import GUI
|
||||
from slic.core.adjustable import Adjustable, PVAdjustable, DummyAdjustable
|
||||
from slic.core.acquisition import SFAcquisition, PVAcquisition
|
||||
@ -43,26 +49,55 @@ from slic.devices.xoptics.pulsepicker import PulsePicker
|
||||
from slic.utils import devices, Marker, as_shortcut
|
||||
from slic.utils import Channels, Config, Elog, Screenshot, PV
|
||||
from slic.core.acquisition.fakeacquisition import FakeAcquisition
|
||||
from slic.devices.timing.events import CTASequencer
|
||||
|
||||
from bs_channels import detectors, bs_channels, camera_channels
|
||||
from pv_channels import pvs
|
||||
from slic.devices.timing.events import CTASequencer
|
||||
|
||||
from channels.bs_channels import detectors, bs_channels, camera_channels
|
||||
from channels.pv_channels import pvs
|
||||
from spreadsheet import overview
|
||||
from channels_minimal import detectors_min, channels_min, pvs_min
|
||||
from pp_shutter import PP_Shutter
|
||||
# from channels_minimal import detectors_min, channels_min, pvs_min
|
||||
from devices.pp_shutter import PP_Shutter
|
||||
|
||||
|
||||
# DEVICES
|
||||
# TODO: requires the stand client, need small howto how to start and configure or let it run all the time
|
||||
# from slic.core.acquisition.spreadsheet import Spreadsheet
|
||||
|
||||
try:
|
||||
from stand_client import Client
|
||||
|
||||
stand_host = "saresc-vcons-02.psi.ch"
|
||||
stand_client = Client(host=stand_host, port=9090)
|
||||
response = stand_client.get()
|
||||
logger.info("Connected to stand server")
|
||||
except Exception as error:
|
||||
# catching with a broad net because different connection errors can occur.
|
||||
logger.warning(f"Cannot connect to stand server on {stand_host}. Caught {error}.")
|
||||
|
||||
# spreadsheet = Spreadsheet(adjs, placeholders=PLACEHOLDERS, host="127.0.0.1", port=8080))
|
||||
|
||||
################# DEVICES #################
|
||||
dummy = DummyAdjustable(units="au")
|
||||
|
||||
# Attenuators
|
||||
from slic.devices.xoptics.aramis_attenuator import Attenuator
|
||||
from knife_edge import KnifeEdge
|
||||
from standa import standa
|
||||
from devices.knife_edge import KnifeEdge
|
||||
from devices.standa import standa
|
||||
|
||||
standa = standa
|
||||
Newport_large = Motor("SARES30-MOBI1:MOT_5")
|
||||
OWIS = Motor("SARES30-MOBI1:MOT_6") # small OWIS linear stage
|
||||
|
||||
attenuator = Attenuator("SAROP31-OATA150", description="Cristallina attenuator OATA150")
|
||||
|
||||
def test_attenuator():
|
||||
tfundamental = attenuator.get_transmission()
|
||||
try:
|
||||
assert tfundamental > 0
|
||||
except TypeError:
|
||||
logger.warning("No transmission value reported from {attenuator.ID}")
|
||||
|
||||
|
||||
test_attenuator()
|
||||
|
||||
front_end_attenuator = Attenuator("SARFE10-OATT053", description="Front end attenuator OATT053")
|
||||
cta = CTASequencer("SAR-CCTA-ESC")
|
||||
|
||||
@ -77,26 +112,26 @@ pbps149 = IntensityMonitorPBPS(
|
||||
"SAROP31-PBPS149",
|
||||
# vme_crate="SAROP31-CVME-PBPS2", # please check this!
|
||||
# link=9,
|
||||
description="Intensity/position monitor in the experimental hutch"
|
||||
description="Intensity/position monitor in the experimental hutch",
|
||||
)
|
||||
|
||||
def test_attenuator():
|
||||
tfundamental = attenuator.get_transmission()
|
||||
try:
|
||||
assert tfundamental > 0
|
||||
except TypeError:
|
||||
logger.warning("No transmission value reported from {attenuator.ID}")
|
||||
|
||||
test_attenuator()
|
||||
|
||||
|
||||
# Undulators
|
||||
import undulator
|
||||
from beamline import undulator
|
||||
|
||||
undulators = undulator.Undulators()
|
||||
logger.info(f"Using undulator (Aramis) offset to PSSS energy of {undulator.energy_offset} eV.")
|
||||
|
||||
|
||||
# Shutter
|
||||
shutter = PP_Shutter("SARES30-LTIM01-EVR0:RearUniv0-Ena-SP", name="Cristallina pulse picker shutter") # Shutter buttton when using the pulse picker
|
||||
pulsepicker = PulsePicker("SAROP31-OPPI151","SARES30-LTIM01-EVR0:Pul3", name="Cristallina X-ray pulse picker OPPI151")
|
||||
shutter = PP_Shutter(
|
||||
"SARES30-LTIM01-EVR0:RearUniv0-Ena-SP", name="Cristallina pulse picker shutter"
|
||||
) # Shutter buttton when using the pulse picker
|
||||
pulsepicker = PulsePicker(
|
||||
"SAROP31-OPPI151",
|
||||
"SARES30-LTIM01-EVR0:Pul3",
|
||||
name="Cristallina X-ray pulse picker OPPI151",
|
||||
)
|
||||
|
||||
# Alignment laser
|
||||
alaser = AlignmentLaser("SAROP31-OLAS147:MOTOR_1", name="Cristallina alignment laser OLAS147")
|
||||
@ -105,23 +140,22 @@ alaser = AlignmentLaser("SAROP31-OLAS147:MOTOR_1", name="Cristallina alignment l
|
||||
from slic.devices.xoptics import slits
|
||||
|
||||
## Smaract & attocube stages
|
||||
from smaract_device_def import smaract_Juraj, smaract_mini_XYZ
|
||||
from attocube_device_def import attocube
|
||||
from jj_device_def import jjslits
|
||||
from devices.smaract_device_def import smaract_Juraj, smaract_mini_XYZ
|
||||
from devices.attocube_device_def import attocube
|
||||
from devices.jj_device_def import jjslits
|
||||
|
||||
# KBs
|
||||
from slic.devices.xoptics.kb import KBHor,KBVer
|
||||
kbHor = KBHor(
|
||||
"SAROP31-OKBH154",
|
||||
description="Cristallina horizontal KB mirror"
|
||||
)
|
||||
kbVer = KBVer(
|
||||
"SAROP31-OKBV153",
|
||||
description="Cristallina vertical KB mirror"
|
||||
)
|
||||
from slic.devices.xoptics.kb import KBHor, KBVer
|
||||
|
||||
kbHor = KBHor("SAROP31-OKBH154", description="Cristallina horizontal KB mirror")
|
||||
kbVer = KBVer("SAROP31-OKBV153", description="Cristallina vertical KB mirror")
|
||||
|
||||
# Bernina monochromator
|
||||
from beamline.bernina_mono import BerninaMono
|
||||
BerninaDCM = BerninaMono("SAROP21-ODCM098")
|
||||
|
||||
|
||||
###########################################
|
||||
################# DAQ Setup #################
|
||||
instrument = "cristallina"
|
||||
|
||||
# pgroup = "p19739" # commissioning March 2022 -- July 2022
|
||||
@ -131,46 +165,67 @@ instrument = "cristallina"
|
||||
# pgroup = "p20557" # CrQ PMS commisioning 1
|
||||
# pgroup = "p20509" # CrQ commissoing DilSc1
|
||||
# pgroup = "p20519" # beamline commissioning 2
|
||||
# pgroup = "p20840" # Cr beamline commisioning (Jan-Feb 2023)
|
||||
# pgroup = "p20841" # CrQ PMS commisioning 2 (Jan 2023)
|
||||
# pgroup = "p20993" # CrQ commissoing DilSc2 (March 2023)
|
||||
pgroup = "p21147" # SAXS
|
||||
# pgroup = "p21147" # SAXS
|
||||
# pgroup = "p21238" # Cristallina photon diagnostics p-group with Chris
|
||||
# pgroup = "p21224" # SwissMX commissioning 7
|
||||
|
||||
# pgroup = "p19150" # Scratch
|
||||
pgroup = "p19150" # Scratch
|
||||
# pgroup = "p19152" # Scratch
|
||||
|
||||
# pgroup = "p20840" # Cr beamline commisioning (Jan-Feb 2023)
|
||||
# pgroup = "p21261" # CrQ PMS-3 July 2023
|
||||
|
||||
# pgroup = "p21528" # Cr-MX Colletier 2023-09-05
|
||||
|
||||
daq = SFAcquisition(
|
||||
instrument,
|
||||
pgroup,
|
||||
default_channels=bs_channels ,
|
||||
default_channels=bs_channels,
|
||||
default_pvs=pvs,
|
||||
default_detectors=detectors,
|
||||
rate_multiplicator=1,
|
||||
)
|
||||
# There is a new EPICS buffer, so the archiver is no longer used. This makes sure we are taking PVs from the right place.
|
||||
daq.update_config_pvs()
|
||||
|
||||
# daq = FakeAcquisition(instrument, pgroup)
|
||||
# daqPV = PVAcquisition(instrument, pgroup, default_channels=channels_ks) # workaround for KS not going to DB
|
||||
|
||||
# scan = Scanner(scan_info_dir=f"/sf/{instrument}/data/{pgroup}/res/scan_info", default_acquisitions=[daq], condition=None)
|
||||
|
||||
# Run the scan only when gas monitor value larger than 10uJ (and smaller than 2000uJ):
|
||||
# required fraction defines ammount of data recorded to save the step and move on to the next one
|
||||
check_intensity_gas_monitor = PVCondition("SARFE10-PBPG050:PHOTON-ENERGY-PER-PULSE-US", vmin=10, vmax=2000, wait_time=0.5, required_fraction=0.8)
|
||||
check_intensity_gas_monitor = PVCondition(
|
||||
"SARFE10-PBPG050:PHOTON-ENERGY-PER-PULSE-US",
|
||||
vmin=-100,
|
||||
vmax=2000,
|
||||
wait_time=0.5,
|
||||
required_fraction=0.8,
|
||||
)
|
||||
|
||||
scan = Scanner(default_acquisitions=[daq], condition = check_intensity_gas_monitor)
|
||||
scan = Scanner(default_acquisitions=[daq], condition=check_intensity_gas_monitor)
|
||||
gui = GUI(scan, show_goto=True, show_spec=True)
|
||||
|
||||
logger.info(f"Running at {instrument} with pgroup {pgroup}.")
|
||||
logger.info("Loading finished.")
|
||||
|
||||
def simple_acquisition(filename):
|
||||
task = daq.acquire(filename)
|
||||
#fname = task.filenames[0]
|
||||
#pattern = r"run([0-9]{4})"
|
||||
#match = re.search(pattern, fname)
|
||||
#run_number = int(match.groups()[0])
|
||||
|
||||
#stand_client.add_row(run_number=run_number)
|
||||
|
||||
stand_client.add_row(run_number=-4,step=0, smaract_x=smaract_mini_XYZ.x.get_current_value(),smaract_y=smaract_mini_XYZ.y.get_current_value(),smaract_z=smaract_mini_XYZ.z.get_current_value()
|
||||
slow_daq_test = SFAcquisition(
|
||||
instrument,
|
||||
"p19150",
|
||||
default_channels=bs_channels,
|
||||
default_pvs=pvs,
|
||||
default_detectors=detectors,
|
||||
rate_multiplicator=100,
|
||||
)
|
||||
|
||||
slow_daq = SFAcquisition(
|
||||
instrument,
|
||||
pgroup,
|
||||
default_channels=bs_channels,
|
||||
default_pvs=pvs,
|
||||
default_detectors=detectors,
|
||||
rate_multiplicator=100,
|
||||
)
|
||||
|
||||
|
Reference in New Issue
Block a user