Skip to content

Commit

Permalink
Fix usage of deprecated ruamel.yaml API
Browse files Browse the repository at this point in the history
Also formatted with `black`.
Also removed commented code.
  • Loading branch information
fabcor-maxiv committed Apr 19, 2024
1 parent ff129f3 commit 869130f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 23 deletions.
35 changes: 13 additions & 22 deletions mxcubecore/model/queue_model_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@

try:
from mxcubecore.model import crystal_symmetry
import ruamel.yaml as yaml
from ruamel.yaml import YAML
except Exception:
logging.getLogger("HWR").warning("Cannot import dependenices needed for GPHL workflows - GPhL workflows might not work")
logging.getLogger("HWR").warning(
"Cannot import dependenices needed for GPHL workflows - GPhL workflows might not work"
)

# This module is used as a self contained entity by the BES
# workflows, so we need to make sure that this module can be
Expand Down Expand Up @@ -1609,7 +1611,6 @@ def get_archive_directory(self):
logging.getLogger("HWR").debug(
"PathTemplate (DESY) - (to be defined) directory is %s" % self.directory
)
#archive_directory = self.directory
archive_directory = HWR.beamline.session.get_archive_directory()
elif PathTemplate.synchrotron_name == "ALBA":
logging.getLogger("HWR").debug(
Expand Down Expand Up @@ -2311,19 +2312,17 @@ def init_from_task_data(self, sample_model, params):
"""

from mxcubecore.HardwareObjects.Gphl import GphlMessages
import ruamel.yaml as yaml

if self.automation_mode == "TEST_FROM_FILE":
fname = os.getenv("GPHL_TEST_INPUT")
if os.path.isfile(fname):
with open(fname, "r") as fp0:
task = yaml.load(fp0)["task"]
with open(fname, "r", encoding="utf-8") as fp0:
task = YAML.load(fp0)["task"]
print(task)
params.update(task["parameters"])
else:
print("WARNING no GPHL_TEST_INPUT found. test using default values")


# Set attributes directly from params
self.strategy_settings = HWR.beamline.gphl_workflow.workflow_strategies.get(
params["strategy_name"]
Expand Down Expand Up @@ -2480,6 +2479,7 @@ def cell_parameters(self, value):
self._cell_parameters = tuple(float(x) for x in value)
else:
raise ValueError("invalid value for cell_parameters: %s" % str(value))

@property
def total_strategy_length(self):
"""Total strategy length for a single repetition
Expand All @@ -2491,7 +2491,6 @@ def total_strategy_length(self):
#
return result


def calc_maximum_dose(self, energy=None, exposure_time=None, image_width=None):
"""Dose at transmission=100 for given energy, exposure time and image width
Expand All @@ -2505,30 +2504,22 @@ def calc_maximum_dose(self, energy=None, exposure_time=None, image_width=None):
Returns:
float: Maximum dose in MGy
"""
energy = (
energy
or HWR.beamline.energy.calculate_energy(self.wavelengths[0].wavelength)
energy = energy or HWR.beamline.energy.calculate_energy(
self.wavelengths[0].wavelength
)
dose_rate = HWR.beamline.gphl_workflow.maximum_dose_rate(energy)
exposure_time = exposure_time or self.exposure_time
image_width = image_width or self.image_width
image_width = image_width or self.image_width
total_strategy_length = self.strategy_length * len(self.wavelengths)
if (dose_rate and exposure_time and image_width and total_strategy_length):
return (dose_rate * total_strategy_length * exposure_time / image_width)
if dose_rate and exposure_time and image_width and total_strategy_length:
return dose_rate * total_strategy_length * exposure_time / image_width
msg = (
"WARNING: Dose could not be calculated from:\n"
" energy:%s keV, total_strategy_length:%s deg, exposure_time:%s s, "
"image_width:%s deg, dose_rate: %s"
)
raise UserWarning(
msg
% (
energy,
total_strategy_length,
exposure_time,
image_width,
dose_rate
)
msg % (energy, total_strategy_length, exposure_time, image_width, dose_rate)
)
return 0

Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ force-exclude = '''
| mxcubecore/HardwareObjects/mockup/PlateManipulatorMockup.py
| mxcubecore/model/crystal_symmetry.py
| mxcubecore/HardwareObjects/XSDataMXCuBEv1_4.py
| mxcubecore/model/queue_model_objects.py
| mxcubecore/HardwareObjects/XSDataMXv1.py
)
'''
Expand Down

0 comments on commit 869130f

Please sign in to comment.