Skip to content

Commit

Permalink
Refactor imports and introduce DataType usage
Browse files Browse the repository at this point in the history
Organize imports by splitting them into standard library, third party, and module-specific sections for better readability and maintenance. Replace the hardcoded event count cutoff with a constant, EVENT_COUNT_CUTOFF, and introduce the use of the DataType class for more explicit data type handling in the DirectBeamFinder class.

Signed-off-by: Jose Borreguero <[email protected]>
  • Loading branch information
jmborr committed Dec 6, 2024
1 parent c66c21d commit ec2a3b4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
7 changes: 5 additions & 2 deletions src/mr_reduction/data_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class DataInfo:
"""

# Number of events under which we can't consider a direct beam file
n_events_cutoff = 2000
n_events_cutoff = EVENT_COUNT_CUTOFF

def __init__(
self,
Expand Down Expand Up @@ -146,15 +146,18 @@ def __init__(
try:
self.is_direct_beam = run_object.getProperty("data_type").value[0] == 1
self.data_type = 0 if self.is_direct_beam else 1
self.data_type_new = DataType.DIRECT_BEAM if self.is_direct_beam else DataType.REFLECTED_BEAM
except: # noqa E722
self.is_direct_beam = False
self.data_type = 1
self.data_type_new = DataType.REFLECTED_BEAM

if ws.getNumberEvents() < self.n_events_cutoff:
self.data_type = -1
self.data_type_new = DataType.UNKNOWN

# Determine proper cross-section label
self.cross_section_label = get_cross_section_label(ws, cross_section)
self.cross_section_label: str = get_cross_section_label(ws, cross_section)

# Processing options
# Use the ROI rather than finding the ranges
Expand Down
12 changes: 7 additions & 5 deletions src/mr_reduction/mr_direct_beam_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
Find a suitable direct beam file for a data set.
"""

from __future__ import absolute_import, division, print_function

# standard library imports
import json
import logging
import math
import os
import sys

from mantid.simpleapi import *
# third party imports
from mantid.simpleapi import LoadEventNexus, MRGetTheta

from .data_info import DataInfo
from .settings import DIRECT_BEAM_DIR, ar_out_dir, nexus_data_dir
# mr_reduction imports
from mr_reduction.data_info import DataInfo, DataType
from mr_reduction.settings import DIRECT_BEAM_DIR, ar_out_dir, nexus_data_dir


class DirectBeamFinder:
Expand Down

0 comments on commit ec2a3b4

Please sign in to comment.