diff --git a/scripts/ringdown_spectrum_analysis/004_simulation_11_07.py b/scripts/ringdown_spectrum_analysis/004_simulation_11_07.py index 0a4a657..dbc5a69 100644 --- a/scripts/ringdown_spectrum_analysis/004_simulation_11_07.py +++ b/scripts/ringdown_spectrum_analysis/004_simulation_11_07.py @@ -60,7 +60,7 @@ def make_params_and_solve( case "hybrid_to_one_bath": params.drive_override = ( - np.array([params.Ω * (1 - params.δ), params.Ω * params.δ * 2]), + np.array([params.Ω * (1 - params.δ), params.Ω * (1 + params.δ)]), np.ones(2), ) @@ -163,7 +163,7 @@ def generate_phase_one_data( ax_realtime.set_title("Photo-diode AC Intensity") # now we plot the power spectrum - window = (float(params.laser_off_time or 0), t[-1]) + window = (float(params.laser_off_time) or 0, t[-1]) # window = (0, float(params.laser_off_time or 0)) ringdown_params = RingdownParams( @@ -260,3 +260,22 @@ if __name__ == "__main__": """, ) save_figure(fig, "004_05_11_07_simulation_only_a_drive_on_bath") + + fig = generate_phase_one_data( + laser_detuning=13 - 3.25, + g_0=0.3, + drive_mode="hybrid_to_one_bath", + off_factor=0.4, + noise=True, + yscale="log", + extra_title=""" + The same as the first simulation, but with the laser at a bath mode and driving at Ω-δ,Ω+δ i.e coupling Bath-Hyb-Hyb-Bath. + + From a simple analytical estimate, this can be seen as advantageous! + + The log-scale on the spectrum is necessary as the bath mode gets way more excited! However the noise magnitude is the same as in the other simulations. + + Timing is /not/ important here *if* the drive amplitude is low engough! + """, + ) + save_figure(fig, "004_06_11_07_bhhb_best") diff --git a/scripts/ringdown_spectrum_analysis/005_11_07_analysis_on_bath.py b/scripts/ringdown_spectrum_analysis/005_11_07_analysis_on_bath.py new file mode 100644 index 0000000..5638325 --- /dev/null +++ b/scripts/ringdown_spectrum_analysis/005_11_07_analysis_on_bath.py @@ -0,0 +1,110 @@ +from rabifun.system import * +from rabifun.plots import * +from rabifun.utilities import * +from rabifun.analysis import * +from ringfit.data import ScanData +from ringfit.plotting import * +import gc + +path = "../../data/11_07_24/second_signal" +scan = ScanData.from_dir(path, extension="npz") + + +# %% plot scan +gc.collect() +fig = plt.figure("interactive", constrained_layout=True, figsize=(20, 3 * 5)) +fig.clf() +(ax_signal, ax_window, ax_spectrum) = fig.subplot_mosaic("AA;BC").values() +plot_scan(scan, ax=ax_signal, linewidth=0.5, every=1000) + + +# %% window + +# here we select a step that is resonant with a hybridized peak and +# then plot the full photodiode voltage trace and just the window + +T_step = 0.0002 +N = 100 +t_scan_peak = 0.0057815 + 0.1e-6 # T * N_steps +t_scan_peak = 0.0057815 - 0.095e-6 + 28 * T_step # T * N_steps +t_peak = t_scan_peak + N * T_step +win_length = 5e-05 + +window = t_scan_peak, t_scan_peak + win_length * 0.2 + + +ax_signal.axvline(t_peak, color="r", linestyle="--") +ax_signal.axvline(t_scan_peak, color="r", linestyle="--") +ax_signal.axvspan(*window, color="r", linestyle="--") +ax_signal.set_title("Full photodiode voltage trace") +ax_signal.set_xlabel("Time [s]") +ax_signal.set_ylabel("Voltage [arb]") + +mask = (scan.time > window[0]) & (scan.time < window[1]) +ax_window.clear() +ax_window.plot(scan.time[mask], scan.output[mask], linewidth=0.1) +ax_window.set_title("Windowed photodiode voltage trace") +ax_window.set_xlabel("Time [s]") + +# %% peak analysis +## herein we detect the pertinent peaks and refine them using a lorentzian fit +ringdown_params = RingdownParams( + fω_shift=0, + mode_window=(0, 4), + fΩ_guess=12.9e6, + fδ_guess=0.2 * 12.9e6, + η_guess=0.5e6, + absolute_low_cutoff=5e6, +) + +peak_info = find_peaks(scan, ringdown_params, window, prominence=0.1) +peak_info = refine_peaks(peak_info, ringdown_params) +plot_spectrum_and_peak_info(ax_spectrum, peak_info, ringdown_params, annotate=True) + + +# %% hand-crafted interpretation +b1, b2, b3 = peak_info.peak_freqs[[0, 1, 2]] +Ω = b3 - b2 +hyb_freq = b1 - 0.18 * Ω +alt_Ω = b2 - b1 + +hyb_amp = peak_info.power[peak_info.peaks[1]] / (np.sqrt(2) * 5) ** 2 * 10 +hyb_width = peak_info.peak_widths[1] * 5 + +ax_spectrum.plot( + peak_info.freq, + lorentzian(peak_info.freq, hyb_amp, hyb_freq, hyb_width), + color="C3", + label="hybridized mode?", +) +# %% +ax_spectrum.legend() +fig.suptitle( + f""" +Analysis of the data from the 11/07. +We modulated at the FSR (13MHz) and FSR-δ and 2δ. +*Laser on first bath mode* + +Here the laser hits the first bathmode beside the hybidized modes. This is the reason +why the peaks toward higher frequencies are split (we're detuned from the unperturbed spectrum). + +The FSR here is {Ω*1e-6:.2f}MHz as ascertained from the bath modes. According to the simulation for driving +on the bath mode, we should see at least one hybridized mode where the red lorentzian is plotted. It's amplitude +is fantasy, but there certainly there seems to be something there! +""" +) + + +# %% save +if __name__ == "__main__": + save_figure(fig, "005_11_07_analysis_on_bath") + + quick_save_pickle( + dict( + window=window, + peak_info=peak_info, + ringdown_parms=ringdown_params, + Ω=Ω, + ), + "005_results", + ) diff --git a/scripts/ringdown_spectrum_analysis/figs/004_06_11_07_bhhb_best.pdf b/scripts/ringdown_spectrum_analysis/figs/004_06_11_07_bhhb_best.pdf new file mode 100644 index 0000000..550c39c Binary files /dev/null and b/scripts/ringdown_spectrum_analysis/figs/004_06_11_07_bhhb_best.pdf differ diff --git a/scripts/ringdown_spectrum_analysis/figs/004_06_11_07_bhhb_best.pdf.meta.yaml b/scripts/ringdown_spectrum_analysis/figs/004_06_11_07_bhhb_best.pdf.meta.yaml new file mode 100644 index 0000000..564195b --- /dev/null +++ b/scripts/ringdown_spectrum_analysis/figs/004_06_11_07_bhhb_best.pdf.meta.yaml @@ -0,0 +1,8 @@ +change_id: rxrtsmmqspvtqxwvltyzqxntmowrvuxk +commit_id: 27d6a0603bbd5f1af744cecebc9d34e9e817f417 +description: '' +extra_meta: null +function: +name: 004_06_11_07_bhhb_best +refers_to: ./figs/004_06_11_07_bhhb_best.pdf +source: scripts/ringdown_spectrum_analysis/004_simulation_11_07.py diff --git a/scripts/ringdown_spectrum_analysis/figs/004_06_11_07_bhhb_best.png b/scripts/ringdown_spectrum_analysis/figs/004_06_11_07_bhhb_best.png new file mode 100644 index 0000000..9a3555d Binary files /dev/null and b/scripts/ringdown_spectrum_analysis/figs/004_06_11_07_bhhb_best.png differ diff --git a/scripts/ringdown_spectrum_analysis/figs/005_11_07_analysis_on_bath.pdf b/scripts/ringdown_spectrum_analysis/figs/005_11_07_analysis_on_bath.pdf new file mode 100644 index 0000000..ac536da Binary files /dev/null and b/scripts/ringdown_spectrum_analysis/figs/005_11_07_analysis_on_bath.pdf differ diff --git a/scripts/ringdown_spectrum_analysis/figs/005_11_07_analysis_on_bath.pdf.meta.yaml b/scripts/ringdown_spectrum_analysis/figs/005_11_07_analysis_on_bath.pdf.meta.yaml new file mode 100644 index 0000000..4ad82b6 --- /dev/null +++ b/scripts/ringdown_spectrum_analysis/figs/005_11_07_analysis_on_bath.pdf.meta.yaml @@ -0,0 +1,8 @@ +change_id: rxrtsmmqspvtqxwvltyzqxntmowrvuxk +commit_id: 79ac3014d82cc3dbecb65c44ae375c44019795d3 +description: '' +extra_meta: null +function: +name: 005_11_07_analysis_on_bath +refers_to: ./figs/005_11_07_analysis_on_bath.pdf +source: scripts/ringdown_spectrum_analysis/005_11_07_analysis_on_bath.py diff --git a/scripts/ringdown_spectrum_analysis/figs/005_11_07_analysis_on_bath.png b/scripts/ringdown_spectrum_analysis/figs/005_11_07_analysis_on_bath.png new file mode 100644 index 0000000..f8d0158 Binary files /dev/null and b/scripts/ringdown_spectrum_analysis/figs/005_11_07_analysis_on_bath.png differ diff --git a/scripts/ringdown_spectrum_analysis/outputs/005_results.pkl.meta.yaml b/scripts/ringdown_spectrum_analysis/outputs/005_results.pkl.meta.yaml new file mode 100644 index 0000000..e030991 --- /dev/null +++ b/scripts/ringdown_spectrum_analysis/outputs/005_results.pkl.meta.yaml @@ -0,0 +1,6 @@ +change_id: rxrtsmmqspvtqxwvltyzqxntmowrvuxk +commit_id: e2b1c2a8ffea1ab07e45ab07b0a3a66d4ae6207f +description: '' +function: +refers_to: outputs/005_results.pkl +source: scripts/ringdown_spectrum_analysis/005_11_07_analysis_on_bath.py diff --git a/src/plot_utils.py b/src/plot_utils.py index 082704b..07ccce1 100644 --- a/src/plot_utils.py +++ b/src/plot_utils.py @@ -136,6 +136,8 @@ def write_meta(path, **kwargs): @noop_if_interactive def save_figure(fig, name, extra_meta=None, *args, **kwargs): + import pickle + dir = pathlib.Path(f"./figs/") dir.mkdir(exist_ok=True) fig.tight_layout() @@ -146,6 +148,10 @@ def save_figure(fig, name, extra_meta=None, *args, **kwargs): plt.savefig(f"./figs/{name}.png", *args, dpi=600, **kwargs) print(f"Figure saved as ./figs/{name}.pdf") + pickle_path = dir / f"{name}.pkl" + + with open(pickle_path, "wb") as f: + pickle.dump(fig, f) @noop_if_interactive