Skip to content

Commit

Permalink
Modify MulpyRep to sim t-d graphs for single chopper inst
Browse files Browse the repository at this point in the history
  • Loading branch information
mducle committed Dec 30, 2023
1 parent cd76cbc commit 5ff9034
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
3 changes: 2 additions & 1 deletion PyChop/Instruments.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ def setFrequency(self, *args, **kwargs):
if argdict["freq"]:
self.frequency = argdict["freq"]
if argdict["phase"]:
self.phase = argdict["phase"]
self.phase = [str(p) if isinstance(self.defaultPhase[i], str) else float(p)
for i, p in enumerate(argdict["phase"])]

def getFrequency(self):
return self.frequency
Expand Down
12 changes: 12 additions & 0 deletions PyChop/MulpyRep.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,15 @@ def calcChopTimes(efocus, freq, instrumentpars, chop2Phase=5):
uSec = 1e6 # seconds to microseconds
lam = np.sqrt(81.8042 / efocus) # convert from energy to wavelenth

# if there's only one disk we prepend a dummy disk with full opening at zero distance
# so that the distance calculations (which needs the difference between disk pos) works
if len(instrumentpars[0]) == 1:
for d1, i in zip([[0], [1], None, [3141], [10], [500], [1]], range(7)):
instrumentpars[i] = (d1 + instrumentpars[i]) if d1 is not None else [d1, instrumentpars[i]]
prepend_disk = True
else:
prepend_disk = False

# extracts the instrument parameters
dist, nslot, slots_ang_pos, slot_width, guide_width, radius, numDisk = tuple(instrumentpars[:7])
samp_det, chop_samp, rep, tmod, frac_ei, ph_ind_v = tuple(instrumentpars[7:])
Expand All @@ -219,6 +228,9 @@ def calcChopTimes(efocus, freq, instrumentpars, chop2Phase=5):
source_rep, nframe = tuple(rep[:2]) if (hasattr(rep, "__len__") and len(rep) > 1) else (rep, 1)
p_frames = source_rep / nframe

if prepend_disk:
freq = np.array([source_rep, freq[0]])

# first we optimise on the main Ei
for i in range(len(dist)):
# loop over each chopper
Expand Down
5 changes: 4 additions & 1 deletion webapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
<body>
<div class="main-wrapper">

<div id="ControlPanel"> </div>
<div id="ControlPanel">
<p> Please wait, loading Python ... </p>
<noscript>Error: This app only works with Javascript enabled.</noscript>
</div>

<div class="tab-wrapper">
<div class="tabs">
Expand Down
7 changes: 3 additions & 4 deletions webapp/pychop.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ class PyChopInstrument extends Preact.Component {
curr_chopper.value = choppers[instindx[curr_inst.value]][0]
curr_freq.value = deffreqs[instindx[curr_inst.value]]
curr_phase.value = phases[instindx[curr_inst.value]].def
console.log(curr_inst.value + " " + curr_chopper.value + " " + curr_freq.value + " " + curr_ei.value + " " + curr_phase.value)
}
eichange = (ev) => {
curr_ei.value = Number(ev.target.value)
Expand Down Expand Up @@ -265,7 +264,7 @@ function runCalc() {
inst.setChopper(curr_chopper.value)
inst.setEi(curr_ei.value)
if (curr_phase.value.length > 0) {
console.log('Setting phase')
//console.log('Setting phase')
inst.setFrequency(curr_freq.value, curr_phase.value)
} else {
inst.setFrequency(curr_freq.value)
Expand Down Expand Up @@ -326,7 +325,7 @@ function runCalc() {
if (curr_inst.value != d_ei.inst || curr_chopper.value != d_ei.chop || curr_freq.value[0] != d_ei.freq) {
//console.log('Calculating Ei-dep')
let flux = [], elres = [];
const eis = linspace(Math.max(inst.emin, 0.1), inst.emax, 200)
const eis = linspace(Math.max(inst.emin, 0.1), inst.emax, 100)
for (const ei of eis) {
flux.push(Number(inst.getFlux(ei).toJs()))
elres.push(Number(inst.getResolution(0.0, ei).toJs()))
Expand All @@ -344,7 +343,7 @@ function runCalc() {
//console.log('Calculating Freq-dep')
const ei = curr_ei.value, en = linspace(-ei/5, ei, 100), enr = en.toReversed();
let flux = [], elres = [], e2 = [], q2 = [];
const fqs = Array(maxfreqs[instid][0] / reps[instid] + 1).fill().map((_, idx) => idx * reps[instid])
const fqs = Array(maxfreqs[instid][0] / reps[instid]).fill().map((_, idx) => (idx+1) * reps[instid])
for (const freq of fqs) {
inst.setFrequency([freq].concat(curr_freq.value.slice(1)))
flux.push(Number(inst.getFlux(ei).toJs()))
Expand Down

0 comments on commit 5ff9034

Please sign in to comment.