Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
# pylint: disable=too-many-branches,too-many-locals, invalid-name
# ruff: noqa: E741 # Ambiguous variable name
from mantid.api import AlgorithmFactory, FileAction, FileProperty, PythonAlgorithm, WorkspaceProperty
from mantid.kernel import Direction
from mantid.simpleapi import logger, CreateWorkspace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
# pylint: disable=too-many-branches,too-many-locals, invalid-name
# ruff: noqa: E741 # Ambiguous variable name
from mantid.api import AlgorithmFactory, FileAction, FileProperty, PythonAlgorithm, WorkspaceProperty
from mantid.kernel import Direction
from mantid.simpleapi import logger, CreateWorkspace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
# pylint: disable=no-init,invalid-name
# ruff: noqa: E741 # Ambiguous variable name
import mantid.simpleapi as api
from mantid.api import (
AlgorithmFactory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -773,10 +773,10 @@ def _sum_rom(self, n_scat, n_abs, a, r1, r2, ms, theta, amu_scat, amu_tot_i, amu
Area_y = r * r_step * omega_ster * amu_scat[n_scat]
sum_1 = 0.0
sum_2 = 0.0
I = 1
i = 1
Area_sum = 0.0
for _ in range(1, number_omega + 1):
omega = I * omega_ster + omega_deg
omega = i * omega_ster + omega_deg
distance = r * math.sin(omega)

skip = True
Expand All @@ -790,11 +790,11 @@ def _sum_rom(self, n_scat, n_abs, a, r1, r2, ms, theta, amu_scat, amu_tot_i, amu
LIS.append(LISN - LIST)
#
# CALCULATE DISTANCE SCATTERED NEUTRON PASSES THROUGH EACH ANNULUS
O = omega + theta_deg
omega_scattered = omega + theta_deg
LSS = []
for j in range(0, nan):
LSST = self._distance(r, self._radii[j], O)
LSSN = self._distance(r, self._radii[j + 1], O)
LSST = self._distance(r, self._radii[j], omega_scattered)
LSSN = self._distance(r, self._radii[j + 1], omega_scattered)
LSS.append(LSSN - LSST)
#
# CALCULATE ABSORPTION FOR PATH THROUGH ALL ANNULI,AND THROUGH INNER ANNULI
Expand All @@ -810,9 +810,9 @@ def _sum_rom(self, n_scat, n_abs, a, r1, r2, ms, theta, amu_scat, amu_tot_i, amu
skip = False

if skip:
I = number_omega - I + 2
i = number_omega - i + 2
else:
I += 1
i += 1
AAA += sum_1 * Area_y
BBB += sum_2 * Area_y
Area += Area_sum * Area_y
Expand Down
1 change: 1 addition & 0 deletions Framework/PythonInterface/plugins/algorithms/DeltaPDF3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# NScD Oak Ridge National Laboratory, European Spallation Source,
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
# ruff: noqa: E741 # Ambiguous variable name
from mantid.api import PythonAlgorithm, AlgorithmFactory, IMDHistoWorkspaceProperty, PropertyMode, WorkspaceProperty, Progress
from mantid.kernel import (
Direction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# NScD Oak Ridge National Laboratory, European Spallation Source,
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
# ruff: noqa: E741 # Ambiguous variable name
from contextlib import contextmanager
import numpy
import os
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ def PyExec(self):
groupname = str(groupnum)
ids = spectra[i, j : j + pixelsx, k : k + pixelsy].reshape(-1)
detids = []
for l in ids:
detids.append(__w.getDetector(int(l)).getID())
for id in ids:
detids.append(__w.getDetector(int(id)).getID())

detids = str(detids).replace("[", "").replace("]", "")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@ def _get_value(name, default=None):
if len(meta_data.strip()) > 0:
content += "#\n"
lines = meta_data.strip().split("\n")
for l in lines:
content += "# %s\n" % l
for line in lines:
content += f"# {line}\n"
content += "#\n"
except:
logger.error("Could not write meta-data to reflectivity file.")
Expand Down
1 change: 1 addition & 0 deletions Framework/PythonInterface/plugins/algorithms/LinkedUBs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# NScD Oak Ridge National Laboratory, European Spallation Source,
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
# ruff: noqa: E741 # Ambiguous variable name
from mantid.api import DataProcessorAlgorithm, mtd, AlgorithmFactory, WorkspaceProperty, PropertyMode, ITableWorkspaceProperty
from mantid.simpleapi import CalculateUMatrix, PredictPeaks, FilterPeaks, DeleteWorkspace, CreatePeaksWorkspace
from mantid.kernel import Direction, FloatBoundedValidator, IntBoundedValidator, StringMandatoryValidator, StringListValidator, V3D
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
# pylint: disable=no-init,invalid-name
# ruff: noqa: E741 # Ambiguous variable name
from mantid.api import (
PythonAlgorithm,
AlgorithmFactory,
Expand Down Expand Up @@ -236,8 +237,8 @@ def _parseFullprofPrfFile(self, filename):

rawlines = pfile.readlines()
lines = []
for l in rawlines:
line = l.strip()
for line in rawlines:
line = line.strip()
if len(line) > 0:
lines.append(line)

Expand Down
28 changes: 14 additions & 14 deletions Framework/PythonInterface/plugins/algorithms/LoadNMoldyn3Ascii.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,45 +20,45 @@
# ==============================================================================


def _find_starts(data, c, l1):
for l in range(l1, len(data)):
char = data[l]
def _find_starts(data, c, start_i):
for i in range(start_i, len(data)):
char = data[i]
if char.startswith(c):
line = l
line = i
break
return line


# ==============================================================================


def _find_tab_starts(data, c, l1):
for l in range(l1, len(data)):
char = data[l][1:]
def _find_tab_starts(data, c, start_i):
for i in range(start_i, len(data)):
char = data[i][1:]
if char.startswith(c):
line = l
line = i
break
return line


# ==============================================================================


def _find_ends(data, c, l1):
for l in range(l1, len(data)):
char = data[l]
def _find_ends(data, c, start_i):
for i in range(start_i, len(data)):
char = data[i]
if char.endswith(c):
line = l
line = i
break
return line


# ==============================================================================


def _make_list(a, l1, l2):
def _make_list(a, start_i, end_i):
data = ""
for m in range(l1, l2 + 1):
for m in range(start_i, end_i + 1):
data += a[m]
alist = data.split(",")
return alist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
# pylint: disable=too-many-branches,too-many-locals, invalid-name
# ruff: noqa: E741 # Ambiguous variable name
from mantid.api import AlgorithmFactory, FileAction, FileProperty, PythonAlgorithm, WorkspaceProperty
from mantid.kernel import logger, Direction
from mantid.simpleapi import CreateWorkspace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ def _ws_or_none(s):
return mtd[s] if s != "" else None


def _elems_or_none(l):
return l if len(l) != 0 else None
def _elems_or_none(iterable):
return iterable if len(iterable) != 0 else None


def add_missing_elements(from_list, to_list):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ def PyInit(self):

# ================================TR INPUT RUNS================================#

for l in range(N_LAMBDAS):
p_name = f"SampleTrRunsW{l+1}"
for i in range(N_LAMBDAS):
p_name = f"SampleTrRunsW{i+1}"
self.declareProperty(
MultipleFileProperty(name=p_name, action=FileAction.OptionalLoad, extensions=["nxs"], allow_empty=True),
doc=f"Sample transmission run(s) at the wavelength #{l+1}.",
doc=f"Sample transmission run(s) at the wavelength #{i+1}.",
)
self.setPropertyGroup(p_name, "Transmission Numors")

Expand Down Expand Up @@ -338,8 +338,8 @@ def _check_sample_runs_dimensions(self):
def _check_tr_runs_dimensions(self):
"""Makes sure all the sample transmission inputs have matching extents"""
issues = dict()
for l in range(self.lambda_rank):
prop = f"SampleTrRunsW{l+1}"
for i in range(self.lambda_rank):
prop = f"SampleTrRunsW{i+1}"
n_items = self.getPropertyValue(prop).count(",") + 1
if n_items > 1 and n_items != self.n_samples:
issues[prop] = f"{prop} has {n_items} elements instead of {self.n_samples}"
Expand Down Expand Up @@ -550,8 +550,8 @@ def _set_rank(self):
def _set_lambda_rank(self):
"""Sets the actual lambda rank"""
self.lambda_rank = 0
for l in range(N_LAMBDAS):
if self.getPropertyValue(f"SampleTrRunsW{l+1}"):
for i in range(N_LAMBDAS):
if self.getPropertyValue(f"SampleTrRunsW{i+1}"):
self.lambda_rank += 1
self.log().notice(f"Set the lambda rank of reduction to {self.lambda_rank}")

Expand Down Expand Up @@ -584,22 +584,22 @@ def get_beam_radius(self, d):
else:
return radii[d]

def get_tr_beam_radius(self, l):
def get_tr_beam_radius(self, i):
"""Returns transmission beam radius at the given wavelength"""
radii = self.getProperty("TrBeamRadius").value
if len(radii) == 1:
return radii[0]
else:
return radii[l]
return radii[i]

# ================================PROCESSING ALL===============================#

def process_all_transmissions(self):
"""Calculates all the transmissions"""
all_outputs = []
for l in range(self.lambda_rank):
transmissions = self.process_all_transmissions_at_lambda(l)
self.progress.report((l + 1) * self.n_samples, f"Calculated transmissions for wavelength index {l+1}")
for i in range(self.lambda_rank):
transmissions = self.process_all_transmissions_at_lambda(i)
self.progress.report((i + 1) * self.n_samples, f"Calculated transmissions for wavelength index {i+1}")
all_outputs.append(transmissions)
return all_outputs

Expand All @@ -625,14 +625,14 @@ def process_all_samples(self, transmissions):
all_outputs.append(outputs)
return all_outputs

def process_all_transmissions_at_lambda(self, l):
def process_all_transmissions_at_lambda(self, i):
"""
Calculates transmissions at the given lambda index
"""
tr_dark_current_ws = self.process_tr_dark_current(l)
[tr_empty_beam_ws, tr_empty_beam_flux] = self.process_tr_empty_beam(l, tr_dark_current_ws)
tr_empty_can_ws = self.process_empty_can_tr(l, tr_dark_current_ws, tr_empty_beam_ws, tr_empty_beam_flux)
tr_sample_ws = self.process_sample_tr(l, tr_dark_current_ws, tr_empty_beam_ws, tr_empty_beam_flux)
tr_dark_current_ws = self.process_tr_dark_current(i)
[tr_empty_beam_ws, tr_empty_beam_flux] = self.process_tr_empty_beam(i, tr_dark_current_ws)
tr_empty_can_ws = self.process_empty_can_tr(i, tr_dark_current_ws, tr_empty_beam_ws, tr_empty_beam_flux)
tr_sample_ws = self.process_sample_tr(i, tr_dark_current_ws, tr_empty_beam_ws, tr_empty_beam_flux)
results = dict()
if tr_sample_ws:
results["SampleTransmission"] = tr_sample_ws
Expand Down Expand Up @@ -705,11 +705,11 @@ def load_solvent(self, d):

# ================================PROCESS REDUCTIONS================================#

def process_tr_dark_current(self, l):
def process_tr_dark_current(self, i):
"""Processes the dark current at the tranmission configuration"""
runs = self.getPropertyValue("TrDarkCurrentRuns")
if runs:
tr_dark_current = runs.split(",")[l]
tr_dark_current = runs.split(",")[i]
[process_tr_dark_current, tr_dark_current_ws] = needs_processing(tr_dark_current, "DarkCurrent")
if process_tr_dark_current:
SANSILLReduction(
Expand All @@ -722,11 +722,11 @@ def process_tr_dark_current(self, l):
else:
return ""

def process_tr_empty_beam(self, l, tr_dark_current_ws):
def process_tr_empty_beam(self, i, tr_dark_current_ws):
"""Processes the empty beam at the tranmission configuration"""
runs = self.getPropertyValue("TrEmptyBeamRuns")
if runs:
tr_empty_beam = runs.split(",")[l]
tr_empty_beam = runs.split(",")[i]
[process_tr_empty_beam, tr_empty_beam_ws] = needs_processing(tr_empty_beam, "EmptyBeam")
tr_empty_beam_flux = tr_empty_beam_ws + "Flux"
if process_tr_empty_beam:
Expand All @@ -735,19 +735,19 @@ def process_tr_empty_beam(self, l, tr_dark_current_ws):
ProcessAs="EmptyBeam",
DarkCurrentWorkspace=tr_dark_current_ws,
NormaliseBy=self.getProperty("NormaliseBy").value,
TransmissionBeamRadius=self.get_tr_beam_radius(l),
TransmissionBeamRadius=self.get_tr_beam_radius(i),
OutputWorkspace=tr_empty_beam_ws,
OutputFluxWorkspace=tr_empty_beam_flux,
)
return [tr_empty_beam_ws, tr_empty_beam_flux]
else:
return ["", ""]

def process_empty_can_tr(self, l, tr_dark_current_ws, tr_empty_beam_ws, tr_empty_beam_flux):
def process_empty_can_tr(self, i, tr_dark_current_ws, tr_empty_beam_ws, tr_empty_beam_flux):
"""Processes the empty container transmission at the given wavelength"""
runs = self.getPropertyValue("ContainerTrRuns")
if runs:
tr_empty_can = runs.split(",")[l]
tr_empty_can = runs.split(",")[i]
[process_tr_empty_can, tr_empty_can_ws] = needs_processing(tr_empty_can, "Transmission")
if process_tr_empty_can:
SANSILLReduction(
Expand All @@ -757,16 +757,16 @@ def process_empty_can_tr(self, l, tr_dark_current_ws, tr_empty_beam_ws, tr_empty
EmptyBeamWorkspace=tr_empty_beam_ws,
FluxWorkspace=tr_empty_beam_flux,
NormaliseBy=self.getProperty("NormaliseBy").value,
TransmissionBeamRadius=self.get_tr_beam_radius(l),
TransmissionBeamRadius=self.get_tr_beam_radius(i),
OutputWorkspace=tr_empty_can_ws,
)
return tr_empty_can_ws
else:
return ""

def process_sample_tr(self, l, tr_dark_current_ws, tr_empty_beam_ws, tr_empty_beam_flux):
def process_sample_tr(self, i, tr_dark_current_ws, tr_empty_beam_ws, tr_empty_beam_flux):
"""Processes the sample transmissions at the given wavelength"""
tr_sample = self.getPropertyValue(f"SampleTrRunsW{l+1}")
tr_sample = self.getPropertyValue(f"SampleTrRunsW{i+1}")
if tr_sample:
[_, tr_sample_ws] = needs_processing(tr_sample, "Transmission")
SANSILLReduction(
Expand All @@ -776,10 +776,10 @@ def process_sample_tr(self, l, tr_dark_current_ws, tr_empty_beam_ws, tr_empty_be
EmptyBeamWorkspace=tr_empty_beam_ws,
FluxWorkspace=tr_empty_beam_flux,
NormaliseBy=self.getProperty("NormaliseBy").value,
TransmissionBeamRadius=self.get_tr_beam_radius(l),
TransmissionBeamRadius=self.get_tr_beam_radius(i),
OutputWorkspace=tr_sample_ws,
startProgress=l * self.n_samples / self.n_reports,
endProgress=(l + 1) * self.n_samples / self.n_reports,
startProgress=i * self.n_samples / self.n_reports,
endProgress=(i + 1) * self.n_samples / self.n_reports,
)
return tr_sample_ws
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,9 @@ def _draw_peaks(self, xmin, hist, peaks):

for index, width in zip(peaks, peak_widths.tolist()):
gamma_by_2 = width / 2
for l in range(-n_lorentz, n_lorentz):
if index + l > 0:
dos[index + l] += hist[index] * gamma_by_2 / (l**2 + gamma_by_2**2) / math.pi
for i in range(-n_lorentz, n_lorentz):
if index + i > 0:
dos[index + i] += hist[index] * gamma_by_2 / (i**2 + gamma_by_2**2) / math.pi

return dos

Expand Down
Loading
Loading