Skip to content

Commit

Permalink
Remove trailing empty spaces with pre-commit hook
Browse files Browse the repository at this point in the history
Use the `trailing-whitespace` pre-commit hook
to remove trailing empty spaces in files.
Only the following file extensions are excluded from this rule:
* `.hkli`
* `.nml`
* `.XDS`
  • Loading branch information
fabcor-maxiv committed Feb 20, 2025
1 parent 1341425 commit e437e8b
Show file tree
Hide file tree
Showing 205 changed files with 512 additions and 526 deletions.
15 changes: 1 addition & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,7 @@ repos:
rev: v5.0.0
hooks:
- id: trailing-whitespace
# Exclude files from trailing-whitespace checks until we get around fixing them.
# This way we can check that other files are trailing-whitespace clean in CI.
exclude: |
(?x)^(
mxcubecore/configuration/.*|
mxcubecore/HardwareObjects/(PlateManipulatorMaintenance|TangoMotor)\.py|
mxcubecore/HardwareObjects/DESY/P11(BackLight|Collect|DetectorCover|Shutter)\.py|
mxcubecore/HardwareObjects/LNLS/LNLS(Diffractometer|Energy|PilatusDet)\.py|
mxcubecore/HardwareObjects/LNLS/EPICS(Actuator|Motor|NState)\.py|
mxcubecore/HardwareObjects/LNLS/set_transmission_mnc.py|
mxcubecore/HardwareObjects/EMBL/EMBL(Energy|OnlineProcessing)\.py|
mxcubecore/HardwareObjects/mockup/MotorMockup\.py|
mxcubecore/HardwareObjects/SOLEIL/PX2/PX2Resolution\.py|
)$
exclude: \.(hkli|nml|XDS)$
- id: end-of-file-fixer
exclude: \.(hkli|nml)$
- id: check-case-conflict
Expand Down
2 changes: 1 addition & 1 deletion mxcubecore/HardwareObjects/DESY/P11BackLight.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def _set_value(self, value):
self.cmd_started = time.time()

def update_light_state(self, value=None):
"""Updates light state
"""Updates light state
:return: light state as str
"""
Expand Down
4 changes: 2 additions & 2 deletions mxcubecore/HardwareObjects/DESY/P11Collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ def get_filter_transmission(self):

def xdsapp_maxwell(self):
"""Starts XDSAPP auto-processing on the Maxwell cluster."""

if HWR.beamline.session.get_beamtime_metadata() != None:

self.log.debug("==== XDSAPP AUTOPROCESSING IS STARTED ==========")
Expand Down Expand Up @@ -933,7 +933,7 @@ def xdsapp_maxwell(self):

def autoproc_maxwell(self):
"""Starts AutoProc auto-processing on the Maxwell cluster."""

if HWR.beamline.session.get_beamtime_metadata() != None:

self.log.debug("==== AUTOPROC AUTOPROCESSING IS STARTED ==========")
Expand Down
2 changes: 1 addition & 1 deletion mxcubecore/HardwareObjects/DESY/P11DetectorCover.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def state_closed_changed(self, value):
self.update_cover_state()

def update_cover_state(self):
"""Updates cover state
"""Updates cover state
:return: cover state as str
"""
Expand Down
2 changes: 1 addition & 1 deletion mxcubecore/HardwareObjects/DESY/P11Shutter.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def do_finish_exc(self, exc=None):
self.log.debug("### simulated finished with exception")

def update_shutter_state(self, state=None):
"""Updates shutter state
"""Updates shutter state
:return: shutter state as str
"""
Expand Down
2 changes: 1 addition & 1 deletion mxcubecore/HardwareObjects/EMBL/EMBLEnergy.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def energy_position_changed(self, pos):
pos = pos[0]
value = pos / 1000

if self._nominal_value is None or abs(value - self._nominal_value) > 1e-3:
if self._nominal_value is None or abs(value - self._nominal_value) > 1e-3:
self.update_value(value)

def energy_limits_changed(self, limits):
Expand Down
4 changes: 2 additions & 2 deletions mxcubecore/HardwareObjects/EMBL/EMBLOnlineProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ def finish_processing(self):
self.all_frames_dozor_is = False
self.all_frames_batch_processed = False
self.is_count = 0
self.batch_count = 0
self.batch_count = 0

def dozor_average_i_changed(self, average_i_value):
if self.started:
Expand Down Expand Up @@ -730,7 +730,7 @@ def start_crystfel_autoproc_launchjob(self, proc_params, all_file_filename):
acq_params = self.data_collection.acquisitions[0].acquisition_parameters

sample_basename = self.params_dict["template"].split("/")[-1].split("_%d_%0")[0]
# stream_filename = sample_basename + "_crystfel_xgandalf.stream"
# stream_filename = sample_basename + "_crystfel_xgandalf.stream"
stream_filename = sample_basename + cell_name_tag + "_crystfel.stream"
geom_filename = "crystfel_detector.geom"
cell_filename = "crystfel_cell" + cell_name_tag + ".cell"
Expand Down
2 changes: 1 addition & 1 deletion mxcubecore/HardwareObjects/LNLS/EPICSActuator.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def abort(self):
if self.__wait_actuator_task is not None:
self.__wait_actuator_task.kill()
self.update_state(self.STATES.READY)

def _set_value(self, value):
""" Override AbstractActuator method."""
self.set_channel_value(self.ACTUATOR_VAL, value)
6 changes: 3 additions & 3 deletions mxcubecore/HardwareObjects/LNLS/EPICSMotor.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def init(self):
self.get_velocity()
self.__watch_task = gevent.spawn(self._watch)
self.update_state(self.STATES.READY)

def _watch(self):
""" Watch motor current value and update it on the UI."""
while True:
Expand Down Expand Up @@ -85,7 +85,7 @@ def get_limits(self):
if self._nominal_limits in [(0, 0), (float('-inf'), float('inf'))]:
# Treat infinite limits
self._nominal_limits = (None, None)

logging.getLogger("HWR").info('Motor %s limits: %s' % (self.motor_name, self._nominal_limits))
return self._nominal_limits

Expand All @@ -97,7 +97,7 @@ def get_velocity(self):
def set_velocity(self, value):
"""Override AbstractMotor method."""
self.__velocity = self.set_channel_value(self.MOTOR_VELO, value)

def done_movement(self):
""" Return whether motor finished movement or not."""
dmov = self.get_channel_value(self.MOTOR_DMOV)
Expand Down
2 changes: 1 addition & 1 deletion mxcubecore/HardwareObjects/LNLS/EPICSNState.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def valueChanged(self, value):
self.set_value(enum_val)
self.actuatorState = self.states.get(value, "unknown")
self.emit("actuatorStateChanged", (self.actuatorState,))

def actuatorIn(self, wait=True, timeout=None):
try:
self.state_attr = self.moves["in"]
Expand Down
2 changes: 1 addition & 1 deletion mxcubecore/HardwareObjects/LNLS/LNLSDiffractometer.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def calculate_move_to_beam_pos(self, x, y):
if y <= (- x + 1152):
dir_goniox = 1
else:
dir_goniox = -1
dir_goniox = -1
move_goniox = dir_goniox * drx_goniox
# mm to move
move_goniox = move_goniox / self.pixels_per_mm_x
Expand Down
4 changes: 2 additions & 2 deletions mxcubecore/HardwareObjects/LNLS/LNLSEnergy.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ def get_value(self):
#if abs(self._nominal_value - value) < 0.001:
# logging.getLogger("HWR").info("Pilatus threshold is still okay.")
# return value

threshold_ok = self.check_threshold_energy(value)
if threshold_ok:
self._nominal_value = value
else:
value = None # Invalid energy because threshold is invalid

return value

def check_threshold_energy(self, energy):
Expand Down
14 changes: 7 additions & 7 deletions mxcubecore/HardwareObjects/LNLS/LNLSPilatusDet.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,13 @@ def set_wavelength(self, wavelength):
# "Pilatus wavelength still okay."
# )
# return True

# As the set of Pilatus wavelength, det dist and beam xy is fast,
# there is no need to compare the target value with the current one.
logging.getLogger("HWR").info("Setting Pilatus wavelength...")
self.set_channel_value(self.DET_WAVELENGTH, wavelength)
time.sleep(0.6)

print('WAVELENGHT WAS SET: ' + str(wavelength))
self.wavelength = self.get_wavelength()
print('WAVELENGHT GOT: ' + str(self.wavelength))
Expand Down Expand Up @@ -277,7 +277,7 @@ def set_beam_x(self, from_user=False, beam_x=None):
"""
Set detector beam_x and returns whether it was successful or not.
Beam X value can come from different sources. The priority (from
Beam X value can come from different sources. The priority (from
high to low) is:
* from_user
* beam_x argument
Expand Down Expand Up @@ -339,7 +339,7 @@ def set_beam_y(self, from_user=False, beam_y=None):
"""
Set detector beam_y and returns whether it was successful or not.
Beam Y value can come from different sources. The priority (from
Beam Y value can come from different sources. The priority (from
high to low) is:
* from_user
* beam_y argument
Expand Down Expand Up @@ -380,7 +380,7 @@ def set_beam_y(self, from_user=False, beam_y=None):
"Error while setting Pilatus beam Y. Please, check the detector."
)
return False

def get_transmission(self):
"""
Returns:
Expand Down Expand Up @@ -417,7 +417,7 @@ def set_transmission(self, transmission):
"Error while setting Pilatus transmission. Please, check the detector."
)
return False

def get_start_angle(self):
"""
Returns:
Expand Down Expand Up @@ -454,7 +454,7 @@ def set_start_angle(self, start_angle):
"Error while setting Pilatus start angle. Please, check the detector."
)
return False

def get_angle_incr(self):
"""
Returns:
Expand Down
24 changes: 12 additions & 12 deletions mxcubecore/HardwareObjects/LNLS/set_transmission_mnc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""Transmission control for MANACA.
Attenuator: ABS-300-12-C-DN-DN40 Flanges.
Foils: #1, 8 um Al;
Expand Down Expand Up @@ -37,7 +37,7 @@ def read_input():

def get_transmission(energy, transmission):
transmission = transmission/100
# Expressions (interpolation) for calculations of MU (linear attenuation coeficient [cm^-1]) for each material in function of the beam energy.
# Expressions (interpolation) for calculations of MU (linear attenuation coeficient [cm^-1]) for each material in function of the beam energy.
# The data used to obtain the expressions (curve fitting) are from "https://physics.nist.gov/PhysRefData/FFast/html/form.html"
# This attenuation coeficients can be verified and optimised after experimental validation at the beamline.
MU_Al = (78657.01011 * math.exp(-energy/0.65969)) + (6406.36151 * math.exp(-energy/1.63268)) + (492.29999 * math.exp(-energy/4.42554)) + (3.2588)
Expand All @@ -47,7 +47,7 @@ def get_transmission(energy, transmission):
MU_Zr = (11143.28458 * math.exp(-energy/5.87029)) + (102.27474)
MU_EMPTY = 0.0
# Foils in ABS-attenuator. The dictionary gives the foil position and material in the key (e.g. 'F1_Al', position 1 occuped by an aluminium foil),
# and the thickness [um] in the value. The list gives the positions and materials, similar to the dictionary, and it is used in the combination.
# and the thickness [um] in the value. The list gives the positions and materials, similar to the dictionary, and it is used in the combination.
foils_dict = {'F0_EMPTY':0, 'F1_Al':8, 'F2_Al':10, 'F3_Al':20, 'F4_Al':80, 'F5_Al':160, 'F6_Al':320, 'F7_Al':800,
'F8_Al':1500, 'F9_Ti':8, 'F10_Cu':10, 'F11_Au':5, 'F12_Zr':25}

Expand All @@ -64,18 +64,18 @@ def get_transmission(energy, transmission):
attenuator_position = attenuator_position[0:12]
elif energy >= 18.5:
attenuator_position = attenuator_position[0:13]

foils_comb = []
atten_coef_sum = []

# calculate the all possible unique combinations
for i in range(1, len(attenuator_position)+1):
product = itertools.combinations(attenuator_position, i)
for item in product:
foils_comb.append(list(item))
# calculate the product of MU (cm^-1) * thickness (cm) for each material (MU * d)
# and sum the products to obtain the total (final) attenuation for each possible combination.
# and put the results (total attenuation) in a list.
# and put the results (total attenuation) in a list.
comb_sum = []
for item in foils_comb:
comb_tmp = []
Expand Down Expand Up @@ -114,11 +114,11 @@ def get_transmission(energy, transmission):


def set_foils(filter_combination):

# declare a list with available foils and a dictionary with epics PV class (FOIL ACT, FOIL IN, FOIL OUT) for each foil
attenuator_position = ['F1_Al', 'F2_Al', 'F3_Al', 'F4_Al', 'F5_Al', 'F6_Al', 'F7_Al', 'F8_Al',
'F9_Ti', 'F10_Cu', 'F11_Au', 'F12_Zr']

foils_pv = {'F1_Al':(PV('MNC:B:RIO01:9474C:bo0'), PV('MNC:B:RIO01:9425A:bi11'), PV('MNC:B:RIO01:9425A:bi12')),
'F2_Al':(PV('MNC:B:RIO01:9474C:bo1'), PV('MNC:B:RIO01:9425A:bi10'), PV('MNC:B:RIO01:9425A:bi13')),
'F3_Al':(PV('MNC:B:RIO01:9474C:bo2'), PV('MNC:B:RIO01:9425A:bi9'), PV('MNC:B:RIO01:9425A:bi14')),
Expand All @@ -133,9 +133,9 @@ def set_foils(filter_combination):
'F12_Zr':(PV('MNC:B:RIO01:9474D:bo3'), PV('MNC:B:RIO01:9425A:bi0'), PV('MNC:B:RIO01:9425A:bi23'))}

# setup the foils: check foil status, put the foils in the 'filter_combination' and remove the others

wt = 0.1

# the commented lines bellow works for the attenuator expected logic (0 for foil out and 1 for foil in).
# as the current logic is inverted (1 is foil out and 0 is foil in) use the uncommented lines.

Expand Down Expand Up @@ -166,7 +166,7 @@ def set_foils(filter_combination):
elif foils_pv[foil][1].get() == foils_pv[foil][2].get():
status = 1
break

return status


Expand All @@ -176,7 +176,7 @@ def main():
transmission_setup = get_transmission(energy, transmission)
# transmission required by the user
user_transmission = transmission_setup[0] * 100
# real transmission got with calculated foil combination
# real transmission got with calculated foil combination
actual_transmission = round(transmission_setup[1] * 100, 2)
# calculated foil combination to get the required transmission
filter_combination = transmission_setup[2]
Expand Down
12 changes: 6 additions & 6 deletions mxcubecore/HardwareObjects/PlateManipulatorMaintenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class PlateManipulatorMaintenance(HardwareObject):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

def init(self):
self._sc = self.get_object_by_role("sample_changer")
self._scan_limits = ''
Expand All @@ -28,7 +28,7 @@ def _do_abort(self):
:rtype: None
"""
return self._sc._do_abort()

def _move_to_crystal_position(self, args):
"""
command to move MD head to x, y crystal position
Expand All @@ -38,7 +38,7 @@ def _move_to_crystal_position(self, args):
:rtype: None
"""
return self._sc.move_to_crystal_position(args)


def _do_change_mode(self, args):
self._sc._do_change_mode(args)
Expand Down Expand Up @@ -66,7 +66,7 @@ def _get_scan_limits(self, args):
def _update_global_state(self):
state_dict, cmd_state, message = self.get_global_state()
self.emit("globalStateChanged", (state_dict, cmd_state, message))

def get_global_state(self):
"""
"""
Expand All @@ -90,7 +90,7 @@ def get_global_state(self):

return state_dict, cmd_state, message



def get_cmd_info(self):
""" return information about existing commands for this object
Expand Down Expand Up @@ -121,5 +121,5 @@ def send_command(self, cmdname, args=None):
if cmdname == "setPlateBarcode":
self.set_plate_barcode(args)
# if cmdname == "change_mode":
# self._do_change_mode(args)
# self._do_change_mode(args)
return True
4 changes: 2 additions & 2 deletions mxcubecore/HardwareObjects/SOLEIL/PX2/PX2Resolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ def __init__(self, name):
super(PX2Resolution, self).__init__(name)
self.resolution_motor = resolution()
self.beam_center = beam_center()

def connect_notify(self, signal):
if signal == "stateChanged":
self.update_state(self.get_state())

def get_value(self):
self._nominal_value = self.resolution_motor.get_resolution()
return self._nominal_value

def _set_value(self, value):
self.resolution_motor.set_resolution(value)

Expand Down
Loading

0 comments on commit e437e8b

Please sign in to comment.