Skip to content

Commit

Permalink
Update optical_tweezers.py
Browse files Browse the repository at this point in the history
updated corner_freq function to include optional plotting suppression
  • Loading branch information
aibishop committed Apr 18, 2023
1 parent 13e02c4 commit a3b28ac
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions monashspa/PHS3000/optical_tweezers.py
Expand Up @@ -31,7 +31,7 @@
from monashspa.PHS3000 import model_fit as __model_fit
from monashspa.PHS3000 import get_fit_parameters as __get_fit_parameters

def corner_freq(f, ps, initial_fc):
def corner_freq(f, ps, initial_fc, call_show = True):
r"""Finds the corner frequency value for a lorentzian power spectrum
Finds the corner frequency (:math:`f_c`) of a power spectrum of the form:
Expand All @@ -42,8 +42,15 @@ def corner_freq(f, ps, initial_fc):
ps: A 1D numpy array containing the power spectrum data (must be the
same length as :code:`f`)
initial_fc: An initial guess for the corner frequency
Keyword Arguments:
call_show: Whether to call :code:`matplotlib.pyplot.show()` at the end
of the function (prior to returning). Defaults to :code:`True`.
Set this to :code:`False` if you are not using Spyder/IPython
and wish your entire script to complete before showing any
plots. Note, you will need to explicitly call
:code:`matplotlib.pyplot.show()` if you set this to :code:`False`.
Returns:
a 1D numpy array (:math:`f_c`, :math:`uf_c`) which contains
the best estimate for the corner frequency :math:`f_c` and the uncertainty in the corner frequency :math:`uf_c`.
Expand Down Expand Up @@ -87,16 +94,20 @@ def corner_freq(f, ps, initial_fc):
u_fc=fit_parameters["u_fc"]

#plotting
plt.close(1)
plt.figure(1)
#plt.close(1)
#plt.figure(1)

plt.figure()
plt.loglog(ff, y*max_y, label='data') # correct for normalisation
plt.loglog(ff,fitted_lorentzian, label='fit')
plt.title('Power Spectrum Analysis')
plt.xlabel('Frequency (Hz)')
plt.ylabel(r'Power Spectral Density ($V^2$/Hz)')
plt.legend()
plt.show()


if call_show:
plt.show()

return fc_val, u_fc

def trap_k_theory(r, w, alpha, eccentricity, I):
Expand Down

0 comments on commit a3b28ac

Please sign in to comment.