Skip to content

Commit

Permalink
adding a back scan
Browse files Browse the repository at this point in the history
  • Loading branch information
LemurPwned committed Dec 22, 2024
1 parent 4b5aeeb commit 01cd4c3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
21 changes: 17 additions & 4 deletions view/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,20 @@ def plot_optim(hvals, target, simulation, title="Optimisation"):
st.pyplot(fig)


def plot_data(Hscan, freqs, spec, mag=None, title="Resonance spectrum"):
def plot_data(
Hscan, freqs, spec, mag=None, title: str = "Resonance spectrum", mode: str = "none"
):
Hscan_spec = Hscan
if st.session_state["Hreturn"] and mode.lower() == "pimm":
print("Adding spectrum")
Hlen = len(Hscan) // 2
Hscan_spec = Hscan[:Hlen]
spec_left_right = spec[:Hlen, :]
spec_right_left = spec[Hlen:, :]
# invert the right side
spec_right_left = spec_right_left[::-1, :]
spec = spec_left_right + spec_right_left

with plt.style.context(["dark_background"]):
if mag is not None:
fig = plt.figure(dpi=300)
Expand All @@ -77,7 +90,7 @@ def plot_data(Hscan, freqs, spec, mag=None, title="Resonance spectrum"):
else:
fig, ax1 = plt.subplots(dpi=300)
ax1.pcolormesh(
Hscan / 1e3,
Hscan_spec / 1e3,
freqs / 1e9,
10 * np.log10(np.abs(spec.T)),
shading="auto",
Expand Down Expand Up @@ -123,7 +136,7 @@ def simulate_vsd():
Hoex_mag=st.session_state.Hoex_mag,
)
spec = Filters.detrend_axis(spec, axis=0)
plot_data(Hscan, freqs, spec, title="VSD spectrum")
plot_data(Hscan, freqs, spec, title="VSD spectrum", mode='vsd')


def simulate_pimm():
Expand All @@ -137,4 +150,4 @@ def simulate_pimm():
sim_time=st.session_state.sim_time * 1e-9,
)
mag = np.asarray(output["m_avg"])
plot_data(Hscan, freqs, spec, mag=mag, title="PIMM spectrum")
plot_data(Hscan, freqs, spec, mag=mag, title="PIMM spectrum", mode='pimm')
9 changes: 7 additions & 2 deletions view/simulation_fns.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,14 @@ def get_pimm_data(
htheta, hphi = get_axis_angles(H_axis)
hmin, hmax = min([Hmin, Hmax]), max([Hmin, Hmax]) # fix user input
Hscan, Hvecs = FieldScan.amplitude_scan(
hmin, hmax, Hsteps, htheta, hphi, back=st.session_state["Hreturn"]
hmin, hmax, Hsteps, htheta, hphi
)
if st.session_state["Hreturn"]:
Hscan = np.concatenate((Hscan, Hscan[::-1]))
Hvecs = np.concatenate((Hvecs, Hvecs[::-1]))
j, rparams = prepare_simulation()
# avoid wait if the user sim's too short
wtime = 4e-9 if sim_time >= 6e-9 else 0.0
spec, freqs, out = PIMM_procedure(
j,
Hvecs=Hvecs,
Expand All @@ -156,7 +161,7 @@ def get_pimm_data(
max_frequency=st.session_state["max_freq"] * 1e9,
simulation_duration=sim_time,
disturbance=1e-6,
wait_time=4e-9,
wait_time=wtime,
)
return spec, freqs, out, Hscan

Expand Down

0 comments on commit 01cd4c3

Please sign in to comment.