<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Plotting a builtin waveform
In the tools sub-package is a module called plot_source_wave which can be used to plot any of the builtin waveforms in time and frequency domains. The module takes the following arguments
Step1:  Plotting a user-defined waveform
This notebook can be used to plot a user-defined waveform in time and frequency domains.
You can use the following code to experiment (in this notebook) with plotting different waveforms.
Step2:  Determining a spatial resolution
You can use the following code as a guide to determining a spatial resolution for a simulation.
<ASSISTANT_TASK:>
Python Code:
%matplotlib inline
from gprMax.waveforms import Waveform
from tools.plot_source_wave import check_timewindow, mpl_plot
w = Waveform()
w.type = 'ricker'
w.amp = 1
w.freq = 25e6
timewindow = 300e-9
dt = 8.019e-11
timewindow, iterations = check_timewindow(timewindow, dt)
plt = mpl_plot(w, timewindow, dt, iterations, fft=True)
Explanation: Plotting a builtin waveform
In the tools sub-package is a module called plot_source_wave which can be used to plot any of the builtin waveforms in time and frequency domains. The module takes the following arguments:
type is the type of the waveform, e.g. ricker
amp is the amplitude of the waveform
freq is the centre frequency of the waveform
timewindow is the time window used to view the waveform, i.e. the time window of the proposed simulation
dt is the time step used to view the waveform, i.e. the time step of the proposed simulation
There is an optional argument:
-fft a switch to turn on the FFT plotting for a single field component or current
For example (to use the module outside this notebook) to plot a Ricker waveform (and FFT) with an amplitude of 1, centre frequency of 1.5GHz and with a time window of 3ns and time step of 1.926ps:
python -m tools.plot_source_wave ricker 1 1.5e9 3e-9 1.926e-12 -fft
You can use the following code to experiment (in this notebook) with plotting different waveforms.
End of explanation
%matplotlib inline
import numpy as np
from gprMax.waveforms import Waveform
from tools.plot_source_wave import check_timewindow, mpl_plot
waveformvalues = np.loadtxt('/Users/cwarren/Desktop/sajad/SW_corrected.txt', skiprows=1, dtype=np.float32)
w = Waveform()
w.type = 'user'
w.amp = 1
w.freq = 0
w.uservalues = waveformvalues[:]
timewindow = 2e-9
dt = 4.71731e-12
timewindow, iterations = check_timewindow(timewindow, dt)
w.uservalues = np.zeros(iterations, dtype=np.float32)
w.uservalues[0:len(waveformvalues)] = waveformvalues[:]
plt = mpl_plot(w, timewindow, dt, iterations, fft=True)
Explanation: Plotting a user-defined waveform
This notebook can be used to plot a user-defined waveform in time and frequency domains.
You can use the following code to experiment (in this notebook) with plotting different waveforms.
End of explanation
from math import sqrt
# Speed of light in vacuum (m/s)
c = 299792458
# Highest relative permittivity present in model
er = 81
# Maximum frequency present in model
fmax = 80e6
# Minimum wavelength
wmin = c / (fmax * sqrt(er))
# Maximum spatial resolution (allowing 10 cells per wavelength)
dmin = wmin / 10
# Time steps at CFL limits for cubic cells
dt3D = dmin / (sqrt(3) * c)
dt2D = dmin / (sqrt(2) * c)
print('Minimum wavelength: {:g} m'.format(wmin))
print('Maximum spatial resolution: {:g} m'.format(dmin))
print('Time step for 3D cubic cell: {:g} s'.format(dt3D))
print('Time step for 2D square cell: {:g} s'.format(dt2D))
Explanation: Determining a spatial resolution
You can use the following code as a guide to determining a spatial resolution for a simulation.
End of explanation
<END_TASK>