Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ticket8378 #17

Merged
merged 3 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
7668662f988eb94e162c82f8281a4f4f5bdafd00
73e5560b4b19e445d7fc3957cb31fa9da600eb42
7 changes: 7 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: Linter
on: [pull_request]
jobs:
call-workflow:
uses: ISISComputingGroup/reusable-workflows/.github/workflows/linters.yml@main
with:
compare-branch: origin/master
21 changes: 0 additions & 21 deletions .github/workflows/pylint.yml

This file was deleted.

29 changes: 19 additions & 10 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
# pylint: disable=too-few-public-methods

from enum import Enum

from LSI import LSI_Param # pylint: disable=import-error
from pvdb import STATIC_PV_DATABASE, Records # pylint: disable=unused-import

from pvdb import Records # pylint: disable=unused-import


class Constants:
"""
Constants used by the LSICorrelator
"""

DELTA_T = 0.0524288 # Magic number, seems to be time between measurements.
DELTA_T = 0.0524288 # Magic number, seems to be time between measurements.
SLEEP_BETWEEN_MEASUREMENTS = 0.5
DATA_DIR = r"c:\Data"
SIMULATE_ARCHIVE_DAT_FILE_NAME = "LSICORR_IOC_test_archive_save.dat"
Expand All @@ -23,6 +26,7 @@
"""
Macros used by the LSICorrelator
"""

SIMULATE = {"macro": "SIMULATE"}
ADDRESS = {"macro": "ADDR"}
FILEPATH = {"macro": "FILEPATH"}
Expand All @@ -30,7 +34,7 @@

# pylint: disable=function-redefined, invalid-overridden-method
@property
def name(self):

Check failure on line 37 in config.py

View workflow job for this annotation

GitHub Actions / call-workflow / ruff

Ruff (ANN201)

config.py:37:9: ANN201 Missing return type annotation for public function `name`
return self.value["macro"]


Expand All @@ -44,13 +48,14 @@
TITLE = "DAE:TITLE"
INSTNAME = "DAE:INSTNAME"

def add_prefix(self, prefix):

Check failure on line 51 in config.py

View workflow job for this annotation

GitHub Actions / call-workflow / ruff

Ruff (ANN201)

config.py:51:9: ANN201 Missing return type annotation for public function `add_prefix`

Check failure on line 51 in config.py

View workflow job for this annotation

GitHub Actions / call-workflow / ruff

Ruff (ANN001)

config.py:51:26: ANN001 Missing type annotation for function argument `prefix`
"""
Add a prefix to the PV name
@param prefix (str): the prefix to add
"""
return f"{prefix}{self.value}"


class LSiPVSeverity(Enum):
"""
Severity states of the LSi PV
Expand All @@ -61,10 +66,12 @@
INFO = "INFO"
INVALID = "INVALID"


class Defaults:
"""
Default values for the LSICorrelator
"""

# Set up the PV database
defaults = {
Records.CORRELATIONTYPE.value: LSI_Param.CorrelationType.AUTO,
Expand All @@ -90,22 +97,24 @@
Records.OUTPUTFILE.value: "No data taken yet",
Records.SIM.value: 0,
Records.DISABLE.value: 0,
Records.MIN_TIME_LAG.value: 200
Records.MIN_TIME_LAG.value: 200,
}

metadata_records = [
Records.SCATTERING_ANGLE,
Records.MEASUREMENTDURATION,
Records.LASER_WAVELENGTH,
Records.SOLVENT_REFRACTIVE_INDEX,
Records.SOLVENT_VISCOSITY,
Records.SAMPLE_TEMP
]
Records.SCATTERING_ANGLE,
Records.MEASUREMENTDURATION,
Records.LASER_WAVELENGTH,
Records.SOLVENT_REFRACTIVE_INDEX,
Records.SOLVENT_VISCOSITY,
Records.SAMPLE_TEMP,
]


class Schema:
"""
File schema for the LSICorrelator
"""

FILE_SCHEME = """{datetime}
Pseudo Cross Correlation
Scattering angle:\t{scattering_angle:.1f}
Expand Down
41 changes: 26 additions & 15 deletions correlator_driver_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,48 @@
"""
# pylint: disable=wrong-import-position

from __future__ import print_function, unicode_literals, division, absolute_import
from __future__ import absolute_import, division, print_function, unicode_literals

import sys
import os
import sys
import traceback
from functools import wraps
from typing import Dict, TextIO, Tuple
from time import sleep
from typing import Dict, TextIO, Tuple

sys.path.insert(1, os.path.join(os.getenv("EPICS_KIT_ROOT"), "support", "lsicorr_vendor", "master"))
sys.path.insert(2, os.path.join(os.getenv("EPICS_KIT_ROOT"), "ISIS", "inst_servers", "master"))

import numpy as np # pylint: disable=import-error
from LSICorrelator import (
LSICorrelator, # pylint: disable=import-error, wrong-import-position, wrong-import-order
)
from server_common.utilities import (
print_and_log, # pylint: disable=import-error, wrong-import-position, wrong-import-order
)

from data_file_interaction import DataArrays, DataFile
from config import Constants, Macro
from data_file_interaction import DataArrays, DataFile
from mocked_correlator_api import MockedCorrelatorAPI

from server_common.utilities import print_and_log # pylint: disable=import-error, wrong-import-position, wrong-import-order
from LSICorrelator import LSICorrelator # pylint: disable=import-error, wrong-import-position, wrong-import-order


def _error_handler(func):

Check failure on line 32 in correlator_driver_functions.py

View workflow job for this annotation

GitHub Actions / call-workflow / ruff

Ruff (ANN202)

correlator_driver_functions.py:32:5: ANN202 Missing return type annotation for private function `_error_handler`

Check failure on line 32 in correlator_driver_functions.py

View workflow job for this annotation

GitHub Actions / call-workflow / ruff

Ruff (ANN001)

correlator_driver_functions.py:32:20: ANN001 Missing type annotation for function argument `func`
"""
A wrapper for the correlator driver functions that catches any errors and
prints them to the log file.
@param func: The function to wrap.
@return: The wrapped function.
"""

# pylint: disable=inconsistent-return-statements
@wraps(func)
def _wrapper(*args, **kwargs):

Check failure on line 42 in correlator_driver_functions.py

View workflow job for this annotation

GitHub Actions / call-workflow / ruff

Ruff (ANN202)

correlator_driver_functions.py:42:9: ANN202 Missing return type annotation for private function `_wrapper`

Check failure on line 42 in correlator_driver_functions.py

View workflow job for this annotation

GitHub Actions / call-workflow / ruff

Ruff (ANN002)

correlator_driver_functions.py:42:18: ANN002 Missing type annotation for `*args`

Check failure on line 42 in correlator_driver_functions.py

View workflow job for this annotation

GitHub Actions / call-workflow / ruff

Ruff (ANN003)

correlator_driver_functions.py:42:25: ANN003 Missing type annotation for `**kwargs`
try:
return func(*args, **kwargs)
# pylint: disable=broad-except
except Exception:
print_and_log(traceback.format_exc(), src="lsi ")

return _wrapper


Expand All @@ -65,8 +70,8 @@
except KeyError as key_error:
raise RuntimeError("No IP address specified, cannot start") from key_error
firmware_revision = macros.get(
Macro.FIRMWARE_REVISION.name,
Macro.FIRMWARE_REVISION.value["default"])
Macro.FIRMWARE_REVISION.name, Macro.FIRMWARE_REVISION.value["default"]
)

if simulated:
self.mocked_api = MockedCorrelatorAPI()
Expand All @@ -80,7 +85,9 @@
self.has_data = False

@staticmethod
def remove_data_with_time_lags_lower_than_minimum(lags: np.ndarray, corr: np.ndarray, min_time_lag: float) -> Tuple[np.ndarray, np.ndarray]: # pylint: disable=line-too-long
def remove_data_with_time_lags_lower_than_minimum(
lags: np.ndarray, corr: np.ndarray, min_time_lag: float
) -> Tuple[np.ndarray, np.ndarray]: # pylint: disable=line-too-long
"""
Remove lags and corresponding corr values which have lags values below the minimum time lag
@param lags (np.ndarray): The original time lags values to remove values from
Expand All @@ -92,12 +99,14 @@
"""
indices = [count for count in range(0, len(lags)) if lags[count] < min_time_lag]

lags = np.delete(lags,indices)
corr = np.delete(corr,indices)
lags = np.delete(lags, indices)
corr = np.delete(corr, indices)

return lags, corr

def get_data_as_arrays(self, min_time_lag) -> Tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray, np.ndarray]: # pylint: disable=line-too-long
def get_data_as_arrays(
self, min_time_lag

Check failure on line 108 in correlator_driver_functions.py

View workflow job for this annotation

GitHub Actions / call-workflow / ruff

Ruff (ANN001)

correlator_driver_functions.py:108:15: ANN001 Missing type annotation for function argument `min_time_lag`
) -> Tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray, np.ndarray]: # pylint: disable=line-too-long
"""
Collects the correlation function, time lags, raw traces and time trace as numpy arrays.
The correlation function and time lags are filtered to finite values only.
Expand All @@ -124,7 +133,7 @@
trace_b = np.asarray(self.device.TraceChB)

# Time axis is number of data points collected * scaling factor
trace_time = np.arange(len(trace_a))*Constants.DELTA_T
trace_time = np.arange(len(trace_a)) * Constants.DELTA_T

return corr, lags, trace_a, trace_b, trace_time

Expand All @@ -136,7 +145,7 @@
self.device.configure()

@_error_handler
def take_data(self, min_time_lag) -> None:

Check failure on line 148 in correlator_driver_functions.py

View workflow job for this annotation

GitHub Actions / call-workflow / ruff

Ruff (ANN001)

correlator_driver_functions.py:148:25: ANN001 Missing type annotation for function argument `min_time_lag`
"""
Starts taking data from the LSi Correlator once with the currently
configured device settings.
Expand All @@ -158,7 +167,9 @@
self.corr = corr
self.lags = lags

def save_data(self, min_time_lag: float, user_file: TextIO, archive_file: TextIO, metadata: Dict) -> None: # pylint: disable=line-too-long
def save_data(
self, min_time_lag: float, user_file: TextIO, archive_file: TextIO, metadata: Dict
) -> None: # pylint: disable=line-too-long
"""
Save the data to file.
@param min_time_lag (float): The minimum time lag to include.
Expand Down
Loading
Loading