Skip to content

Commit

Permalink
Merge pull request #38591 from mantidproject/pychop_sns_update
Browse files Browse the repository at this point in the history
Update pychop definitions for SNS instruments
  • Loading branch information
AndreiSavici authored Jan 15, 2025
2 parents 6c62fe3 + e744dff commit 6be0546
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 56 deletions.
4 changes: 4 additions & 0 deletions docs/source/interfaces/direct/PyChop.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ Currently, the four direct geometry spectrometers at ISIS (LET, MAPS, MARI, and
MERLIN) and the four direct geometry spectrometers at SNS (ARCS, CNCS, HYSPEC,
SEQUOIA) are supported.

.. note::
For SNS instruments the flux is given in n/cm\ :sup:`2`/s/MW whereas for
ISIS instruments it is n/cm\ :sup:`2`/s at a nominal proton current of 160uA.

For MERLIN and LET, in addition, PyChop will also calculate the allowed Ei's in
multi-rep mode, and plot the time-distance diagrams for the desired setting.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- Definition files for :ref:`PyChop <PyChop>` for SNS instruments ARCS and SEQUOIA fixed.

This was due to the wrong files from the original `repository <https://github.com/sns-chops/resolution>`_
being included into Mantid. The correct files are now include so that PyChop calculations in Mantid
now agree with that from the `online SNS calculator <https://rez.mcvine.ornl.gov/>`_.
Please note that the flux values for SNS instruments are in n/cm^2/s/MW whereas for ISIS instruments
it is in n/cm^2/s at a nominal proton current of 160uA.
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def setInstrument(self, instname):
nframe = self.engine.moderator.n_frame if hasattr(self.engine.moderator, "n_frame") else 1
self.repfig_nframe_edit.setText(str(nframe))
self.repfig_nframe_rep1only.setChecked(False)
self.flux_units = self.engine.moderator.flux_units
if hasattr(self.engine.chopper_system, "default_frequencies"):
cb = [self.widgets["FrequencyCombo"]["Combo"], self.widgets["PulseRemoverCombo"]["Combo"]]
for idx, freq in enumerate(self.engine.chopper_system.default_frequencies):
Expand Down Expand Up @@ -368,7 +369,7 @@ def plot_res(self):
if not self.flux[ie]:
continue
(line,) = self.resaxes.plot(en, self.res[ie])
label_text = "%s_%3.2fmeV_%dHz_Flux=%fn/cm2/s" % (inst, Ei, freq, self.flux[ie])
label_text = "%s_%3.2fmeV_%dHz_Flux=%f%s" % (inst, Ei, freq, self.flux[ie], self.flux_units)
line.set_label(label_text)
if self.tabs.isTabEnabled(self.qetabID):
self.plot_qe(Ei, label_text, hold=True)
Expand All @@ -378,7 +379,7 @@ def plot_res(self):
en = np.linspace(0, 0.95 * ei, 200)
(line,) = self.resaxes.plot(en, self.res)
chopper = self.engine.getChopper()
label_text = "%s_%s_%3.2fmeV_%dHz_Flux=%fn/cm2/s" % (inst, chopper, ei, freq, self.flux)
label_text = "%s_%s_%3.2fmeV_%dHz_Flux=%f%s" % (inst, chopper, ei, freq, self.flux, self.flux_units)
line.set_label(label_text)
if self.tabs.isTabEnabled(self.qetabID):
self.plot_qe(ei, label_text, overplot)
Expand Down Expand Up @@ -471,7 +472,7 @@ def plot_flux_ei(self, **kwargs):
self.flxaxes1.set_xlim([mn, mx])
self.flxaxes2.set_xlim([mn, mx])
self.flxaxes1.set_xlabel("Incident Energy (meV)")
self.flxaxes1.set_ylabel("Flux (n/cm$^2$/s)")
self.flxaxes1.set_ylabel("Flux (%s)" % (self.flux_units.replace("cm^2", "cm$^2$")))
self.flxaxes1.set_xlabel("Incident Energy (meV)")
self.flxaxes2.set_ylabel("Elastic Resolution FWHM (meV)")
lg = self.flxaxes2.legend()
Expand Down Expand Up @@ -530,7 +531,7 @@ def plot_flux_hz(self):
self.frqaxes2.clear()
self.setFreq(manual_freq=freq0)
self.frqaxes1.set_xlabel("Chopper Frequency (Hz)")
self.frqaxes1.set_ylabel("Flux (n/cm$^2$/s)")
self.frqaxes1.set_ylabel("Flux (%s)" % (self.flux_units.replace("cm^2", "cm$^2$")))
(line,) = self.frqaxes1.plot(freqs, flux, "o-")
self.frqaxes1.set_xlim([0, np.max(freqs)])
self.frqaxes2.set_xlabel("Chopper Frequency (Hz)")
Expand Down Expand Up @@ -651,7 +652,7 @@ def _gen_text_ei(self, ei, obj_in):
first_component = "chopper 1"
txt = "# ------------------------------------------------------------- #\n"
txt += "# Ei = %8.2f meV\n" % (ei)
txt += "# Flux = %8.2f n/cm2/s\n" % (flux)
txt += "# Flux = %8.2f %s\n" % (flux, self.flux_units)
txt += "# Elastic resolution = %6.2f meV\n" % (res[0])
txt += "# Time width at sample = %6.2f us, of which:\n" % (1e6 * np.sqrt(tsqvan[0]))
for ky, val in list(tsqdic.items()):
Expand Down
10 changes: 5 additions & 5 deletions qt/python/mantidqtinterfaces/test/PyChopInstrumentTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,28 +387,28 @@ def test_merlin_specials(self):
def test_pychop_numerics(self):
# Tests all instruments resolution and flux values against reference
instruments = ["ARCS", "CNCS", "HYSPEC", "LET", "MAPS", "MARI", "MERLIN", "SEQUOIA"]
choppers = ["ARCS-100-1.5-AST", "High Flux", "OnlyOne", "High Flux", "S", "S", "G", "SEQ-100-2.0-AST"]
choppers = ["ARCS-100-1.5-AST", "High Flux", "OnlyOne", "High Flux", "S", "S", "G", "High-Resolution"]
freqs = [[300], [300, 60], [180], [240, 120], [400, 50], [400], [400], [300]]
eis = [120, 3.7, 45, 3.7, 120, 80, 120, 120]
ref_res = [
10.278744237772832,
6.072831079992827,
0.13188102618129077,
3.6751279831313703,
0.08079912729715726,
4.9611687063450995,
2.6049587487601764,
6.8755979524827255,
5.396705255853653,
3.599331977438773,
]
ref_flux = [
2055.562054927915,
22192.86718280959,
128986.24972543867,
0.014779264739956933,
45438.33797146135,
24196.496233770937,
5747.118187298609,
22287.647098883135,
4063.3113893387676,
16015.853669861977,
]
for inst, ch, frq, ei, res0, flux0 in zip(instruments, choppers, freqs, eis, ref_res, ref_flux):
res, flux = Instrument.calculate(inst, ch, frq, ei, 0)
Expand Down
11 changes: 7 additions & 4 deletions scripts/pychop/Instruments.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,9 +570,12 @@ class Moderator(object):

def __init__(self, inval=None):
wrap_attributes(self, inval, self.__allowed_var_names)
self.flux_units = "n/cm^2/s"
if hasattr(self, "measured_flux") and self.measured_flux:
if "scale_factor" in self.measured_flux:
self.measured_flux["flux"] = np.array(self.measured_flux["flux"]) * float(self.measured_flux["scale_factor"])
if "units" in self.measured_flux:
self.flux_units = self.measured_flux["units"]
idx = np.argsort(self.measured_flux["wavelength"])
wavelength = np.array(self.measured_flux["wavelength"])[idx]
flux = np.array(self.measured_flux["flux"])[idx]
Expand Down Expand Up @@ -872,8 +875,8 @@ def getVanVar(self, Ei_in=None, frequency=None, Etrans=0):
Ei, _ = _check_input(self.chopper_system, Ei_in, frequency)
Etrans = np.array(Etrans if np.shape(Etrans) else [Etrans])
if frequency:
oldfreq = self.frequency
self.frequency = frequency
oldfreq = self.chopper_system.frequency
self.chopper_system.frequency = frequency
tsqmod = self.moderator.getWidthSquared(Ei)
tsqchp = self.chopper_system.getWidthSquared(Ei)
tsqjit = self.tjit**2
Expand All @@ -888,7 +891,7 @@ def getVanVar(self, Ei_in=None, frequency=None, Etrans=0):
tsqchp = tsqchp[0]
tsqmodchop = np.array([tsqmod, tsqchp, x0])
# Propagate the time widths to the sample position
omega = self.frequency[0] * 2 * np.pi
omega = self.chopper_system.frequency[0] * 2 * np.pi
vi = E2V * np.sqrt(Ei)
vf = E2V * np.sqrt(Ei - Etrans)
vratio = (vi / vf) ** 3
Expand Down Expand Up @@ -920,7 +923,7 @@ def getVanVar(self, Ei_in=None, frequency=None, Etrans=0):
vsqvan += tsqsam
outdic["sample"] = tsqsam
if frequency:
self.frequency = oldfreq
self.chopper_system.frequency = oldfreq
return vsqvan, outdic, tsqmodchop

@property
Expand Down
24 changes: 11 additions & 13 deletions scripts/pychop/arcs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ chopper_system:
isPi: False # Should the PI pulse (at 180 deg rotation) be transmitted by this package?
ARCS-100-1.5-SMI:
name: ARCS 100 meV Sloppy
pslit: 1.52 # Neutron transparent slit width (mm)
pslit: 1.5 # Neutron transparent slit width (mm)
pslat: 0.41 # Neutron absorbing slat width (mm)
radius: 50.0 # Chopper package radius (mm)
rho: 580.0 # Chopper package curvature (mm)
rho: 640.0 # Chopper package curvature (mm)
tjit: 0.0 # Jitter time (us)
fluxcorr: 3.0 # (Empirical/Fudge) factor to scale calculated flux by
isPi: False # Should the PI pulse (at 180 deg rotation) be transmitted by this package?
ARCS-700-1.5-SMI:
name: ARCS 700 meV Sloppy
pslit: 1.52 # Neutron transparent slit width (mm)
pslit: 1. # Neutron transparent slit width (mm)
pslat: 0.41 # Neutron absorbing slat width (mm)
radius: 50.0 # Chopper package radius (mm)
rho: 1535.0 # Chopper package curvature (mm)
Expand Down Expand Up @@ -106,15 +106,13 @@ moderator:
name: Ambient Water # A==water, AP==poisoned water, CH4==methane, H2==hydrogen. This is only used for analytical calculations
# of the flux distribution for ISIS TS1 moderators. If measured_flux is defined below, name can be anything
imod: 1 # Moderator time profile type: 0==chi^2, 1==Old_Ikeda-Carpenter, 2==modified chi^2, 3==polynomial, 4==Tobyfit Ikeda-Carpenter
mod_pars: [119.63, 33.618, # Parameters for time profile (for I-K is: [S1, S2, B1, B2, Emod]
.037, .17, 172.42] # where tau_f=1/(sqrt(Ei)*E2V*sqrt(S1^2+(S2*lam)^2), tau_s=B1 for E<=130meV, B2 otherwise, R=exp(-Ei/Emod)
mod_pars: [281., 79.0, # Parameters for time profile (for I-K is: [S1, S2, B1, B2, Emod]
.087, .4, 172.] # where tau_f=1/(sqrt(Ei)*E2V*sqrt(S1^2+(S2*lam)^2), tau_s=1/B1 for E<=130meV, 1/B2 otherwise, R=exp(-Ei/Emod)
# and the overall variance (not FWHM) is: tau^2 = 3*tau_f^2 + R*(2-R)*tau_s^2
theta: -13.75 # Angle beamline makes with moderator face (degrees)
source_rep: 60 # Frequency of source (Hz)
measured_flux: # Table of measured flux vs wavelength. Wavelength in Angstrom. Flux in n/cm^2/s/uA/Angstrom
scale_factor: 10000000 # A factor to scale the flux values below by
wavelength: [0.0285984265, 0.2335051748, 0.2859842653, 0.310193488, 0.3418165757, 0.3856211047, 0.4521808267, 0.4834016372,
0.522133444, 0.5719685306, 0.6394802577, 0.6936137254, 0.7643250991, 0.8255654628, 0.9043616533, 0.9809179374,
1.0809189212, 1.2194410046, 1.4299213265, 1.5286501982, 1.6511309256, 1.8087233066, 2.0222141331, 2.3350517482]
flux: [1, 1, 1.0769418795, 1.0912234366, 1.1117847541, 1.143928794, 1.201252718, 1.2318227972, 1.2731629789, 1.3321623679,
1.4236719322, 1.5075346925, 1.6322258496, 1.7551658109, 1.9353360797, 2.1356198518, 2.4386575654, 2.9461376015,
3.8879041876, 4.331779711, 4.8546361998, 5.4701373626, 6.1966620127, 7.3007339739]
measured_flux: # Table of measured flux vs wavelength. Wavelength in Angstrom.
units: n/cm^2/s/MW # Units (optional, if omitted assumes n/cm^2/s)
scale_factor: 600. # A factor to scale the flux values below by
wavelength: [0.28601414576833351, 0.29616861080662232, 0.30668359353866664, 0.31757189355627352, 0.32884676487984915, 0.34052193209214343, 0.35261160704479783, 0.36513050615803061, 0.37809386833452097, 0.39151747350929472, 0.40541766185819367, 0.41981135368831168, 0.43471607003460611, 0.45014995398775937, 0.46613179277925221, 0.48268104065052947, 0.49981784253410028, 0.5175630585753952, 0.53593828952523304, 0.55496590303380511, 0.57466906087818581, 0.59507174715650868, 0.61619879748313355, 0.63807592922033896, 0.66072977278334122, 0.68418790405674834, 0.70847887796190545, 0.73363226321599551, 0.75967867832520353, 0.78664982885576173, 0.81457854602823976, 0.84349882668206377, 0.87344587465890866, 0.90445614365534355, 0.93656738159688513, 0.969818676587485, 1.0042505044903745, 1.0399047781981905, 1.0768248986523594, 1.1150558076738351, 1.1546440426695133, 1.1956377932809006, 1.2380869600440081, 1.2820432151318641, 1.3275600652535944, 1.3746929167866273, 1.4234991432213153, 1.4740381550000654, 1.5263714718359951, 1.5805627975991423, 1.6366780978613906, 1.6947856801944969, 1.7549562773189731, 1.8172631332050293, 1.8817820922303938, 1.9485916915035324, 2.0177732564646584, 2.0894109998808901, 2.1635921243560827, 2.2404069284800938, 2.3199489167467102, 2.4023149133740307, 2.4876051801658536, 2.5759235385575425, 2.6673774959949301, 2.762078376800098, 2.8601414576833353, 2.9616861080662242, 3.0668359353866661, 3.1757189355627351, 3.2884676487984921, 3.4052193209214345, 3.5261160704479786, 3.6513050615803064, 3.780938683345211, 3.9151747350929473, 4.0541766185819386, 4.1981135368831177, 4.3471607003460608, 4.5014995398775941, 4.6613179277925214, 4.8268104065052952, 4.9981784253410035, 5.175630585753952, 5.3593828952523292, 5.5496590303380522, 5.7466906087818588, 5.9507174715650875, 6.1619879748313364, 6.3807592922033907, 6.6072977278334157, 6.8418790405674859, 7.0847887796190561, 7.3363226321599546, 7.5967867832520346, 7.866498288557616, 8.1457854602823971, 8.4349882668206373, 8.7344587465890875, 9.0445614365534368]
flux: [25276.821244674764, 28722.723407923262, 30360.473049322729, 33984.736292474241, 35854.454907360159, 37721.888451513369, 41792.101597201276, 45450.508563093113, 48323.974753436923, 52677.150482905265, 53810.476756526761, 58355.292747301173, 60130.332759471909, 65066.09090594935, 69045.858337315658, 72437.898974947966, 80728.676179699396, 87002.521650256065, 91084.890656927688, 98323.28542422819, 105006.17676779242, 114322.08986347441, 126171.54613173187, 139218.61294605921, 151521.41609409908, 161409.6958591649, 189259.48264800446, 210587.69758960878, 242242.73125719716, 268099.91882613447, 301397.72323530738, 340189.43392865575, 386431.19630181114, 439606.75079753564, 490872.55069392739, 559056.15358305548, 598054.68010369327, 642867.30642169702, 682214.88617398019, 735770.18390646728, 789062.37807587918, 843435.70552473445, 892067.84175600309, 932069.58753616642, 960829.52260059584, 977838.59389104007, 991797.75904680265, 1000337.9175057374, 982396.29545647511, 966139.49995927035, 951371.50707512058, 957975.67004690482, 970869.50658444816, 979478.07901000162, 986052.74143295304, 967911.34861546499, 896279.74583482195, 829475.87333898549, 779461.92206302506, 748939.9422760657, 720475.04177324544, 693928.58029561746, 673063.46634146478, 654417.17264869832, 637027.57674385677, 620809.98140205501, 605685.3977078927, 559996.66818095162, 517387.20610928442, 477649.47917235375, 440589.94203344069, 406028.09366374754, 373795.59819970129, 343735.46505153348, 320318.31796563335, 300587.22403512523, 282185.93979786616, 265024.84053124895, 249020.34191900652, 234094.49294804141, 220174.5962426459, 207192.8539869253, 195086.037710865, 183795.1803317109, 173265.28895073067, 163445.07700651177, 154286.71448023061, 145745.59493625097, 137780.11826340586, 130351.48805879033, 129879.12053379402, 129879.12053379402, 129879.12053379402, 129879.12053379402, 129879.12053379402, 129879.12053379402, 129879.12053379402, 129879.12053379402, 129879.12053379402, 129879.12053379402]
3 changes: 2 additions & 1 deletion scripts/pychop/cncs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ moderator:
51.03, 42.13, 34.74, 28.75, 23.98, 20.19, 17.17, 14.77,
12.85, 11.29 ]
isSigma: false
measured_flux: # Table of measured flux vs wavelength. Wavelength in Angstrom. Flux in n/cm^2/s/uA/Angstrom
measured_flux: # Table of measured flux vs wavelength. Wavelength in Angstrom.
units: n/cm^2/s/MW # Units (optional, if omitted assumes n/cm^2/s)
scale_factor: 63276.8362 # A factor to scale the flux values below by
wavelength: [0.5, 0.6, 0.7, 0.8, 0.9, 1. , 1.1, 1.2, 1.3,
1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2. , 2.1, 2.2,
Expand Down
3 changes: 2 additions & 1 deletion scripts/pychop/hyspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ moderator:
51.03, 42.13, 34.74, 28.75, 23.98, 20.19, 17.17, 14.77,
12.85, 11.29 ]
isSigma: false
measured_flux: # Table of measured flux vs wavelength. Wavelength in Angstrom. Flux in n/cm^2/s/uA/Angstrom
measured_flux: # Table of measured flux vs wavelength. Wavelength in Angstrom.
units: n/cm^2/s/MW # Units (optional, if omitted assumes n/cm^2/s)
scale_factor: 1.0 # A factor to scale the flux values below by
wavelength: [1.28,1.53,1.74,2.02,2.34,3.3,3.69,4.04,4.64]
flux: [4.23,8.42,12.52,21.27,30.67,24.92,18.72,12.33,11.60] #from V_fits2, sheet PGApr2014, yellow
Expand Down
3 changes: 2 additions & 1 deletion scripts/pychop/let.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ moderator:
isSigma: False # Indicates measurements are FWHM
wavelength: [3.8063, 2.1961, 6.2121, 5.3820, 1.4371, 1.7010, 2.6920, 1.9013]
width: [90.4, 40.8, 154.4, 131.2, 22.4, 25.6, 52.4, 32.4]
measured_flux: # Table of measured flux vs wavelength. Wavelength in Angstrom. Flux in n/cm^2/s/uA/Angstrom
measured_flux: # Table of measured flux vs wavelength. Wavelength in Angstrom.
units: n/cm^2/s/160uA # Units (optional, if omitted assumes n/cm^2/s)
scale_factor: 63276.8362 # A factor to scale the flux values below by
wavelength: [0.5, 0.6, 0.7, 0.8, 0.9, 1. , 1.1, 1.2, 1.3,
1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2. , 2.1, 2.2,
Expand Down
3 changes: 2 additions & 1 deletion scripts/pychop/maps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ moderator:
isSigma: False # Indicates measurements are FWHM
wavelength: [3.81593, 5.39537, 2.2052, 2.70006, 3.25499, 1.70813, 3.11649, 1.44378, 2.41516, 1.91018, 2.47745, 1.27303, 2.07872, 1.05928, 1.55951]
width: [54, 62, 40, 44, 48, 35, 47, 30, 41, 37, 40, 25, 38, 20, 31]
measured_flux: # Table of measured flux vs wavelength. Wavelength in Angstrom. Flux in n/cm^2/s/uA/Angstrom
measured_flux: # Table of measured flux vs wavelength. Wavelength in Angstrom.
units: n/cm^2/s/160uA # Units (optional, if omitted assumes n/cm^2/s)
wavelength: [0.0181, 0.0511, 0.0841, 0.1170, 0.1500, 0.1829, 0.2159, 0.2489, 0.2818, 0.3148, 0.3477, 0.3807, 0.4137, 0.4466, 0.4796,
0.5126, 0.5455, 0.5785, 0.6114, 0.6444, 0.6774, 0.7103, 0.7433, 0.7762, 0.8092, 0.8422, 0.8751, 0.9081, 0.9411, 0.9740,
1.0070, 1.0399, 1.0729, 1.1059, 1.1388, 1.1718, 1.2047, 1.2377, 1.2707, 1.3036, 1.3366, 1.3696, 1.4025, 1.4355, 1.4684,
Expand Down
3 changes: 2 additions & 1 deletion scripts/pychop/mari.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ moderator:
isSigma: False # Indicates measurements are FWHM
wavelength: [4.0240, 5.6898, 2.3250, 2.8480, 1.5224, 3.4331, 1.8009, 1.1167]
width: [53.2, 62, 39.2, 44.8, 18.8, 48.8, 27.2, 12.4]
measured_flux: # Table of measured flux vs wavelength. Wavelength in Angstrom. Flux in n/cm^2/s/uA/Angstrom
measured_flux: # Table of measured flux vs wavelength. Wavelength in Angstrom.
units: n/cm^2/s/160uA # Units (optional, if omitted assumes n/cm^2/s)
wavelength: [1.5000e-01, 2.5000e-01, 3.5000e-01, 4.5000e-01, 5.5000e-01, 6.5000e-01, 7.5000e-01, 8.5000e-01, 9.5000e-01, 1.0500e+00,
1.1500e+00, 1.2500e+00, 1.3500e+00, 1.4500e+00, 1.5500e+00, 1.6500e+00, 1.7500e+00, 1.8500e+00, 1.9500e+00, 2.0500e+00,
2.1500e+00, 2.2500e+00, 2.3500e+00, 2.4500e+00, 2.5500e+00, 2.6500e+00, 2.7500e+00, 2.8500e+00, 2.9500e+00, 3.0500e+00,
Expand Down
Loading

0 comments on commit 6be0546

Please sign in to comment.