Skip to content

Instantly share code, notes, and snippets.

View bradlipovsky's full-sized avatar

Brad Lipovsky bradlipovsky

View GitHub Profile
@bradlipovsky
bradlipovsky / vep.py
Created May 2, 2024 04:08
Viscoelastic-plastic oscillator
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
# Function that returns dz/dt = [dx/dt, dv/dt]
def model(z, t):
x = z[0] # "total displacement" -- quotes because this quantity doesn't
# really make physical sense. These should be strains, but there
# is no sense of strain in a 0-D model.
v = z[1] # velocity
@bradlipovsky
bradlipovsky / elastic-plastic.py
Created May 1, 2024 16:37
Elastic/plastic simple harmonic oscillator
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
# Function that returns dz/dt = [dx/dt, dv/dt]
def model(z, t):
x = z[0]
v = z[1]
xp = z[2]
@bradlipovsky
bradlipovsky / fk-filter.py
Created January 17, 2024 23:23
fk-filter
import h5py
import numpy as np
from scipy.fft import fft2, ifft2, fftfreq, fftshift, ifftshift
datafile=h5py.File('/1-fnp/petasaur/p-wd15/rainier-10-14-2023-drive1/rainier/decimator_2023-08-23_19.28.00_UTC.h5')
data=np.array(datafile['/Acquisition/Raw[0]/RawData'])
datafile.close()
import matplotlib.pyplot as plt
plt.imshow(data,aspect='auto',vmin=-1,vmax=1)
@bradlipovsky
bradlipovsky / lstm.py
Created October 24, 2023 23:23
Minimal Example LSTM in Keras
import numpy as np
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import LSTM, Dense
from sklearn.model_selection import train_test_split
# Generate example data (you should replace this with your data)
# Here, we create three input time series and one target time series.
# You should load your own data accordingly.
n_samples = 1000
@bradlipovsky
bradlipovsky / surface-wave-eq-location.py
Last active September 22, 2023 13:52
extremely simplified eq location
import numpy as np
import matplotlib.pyplot as plt
import datetime
import geopy.distance
T0 = datetime.datetime(2023,9,16,12,31,0).timestamp() # test origin time
v = 1 # surface wave speed
def G(lon,lat,m,vv):
#m = (x0,y0,t0) is the source parameter vector
@bradlipovsky
bradlipovsky / aliased-sgws.py
Created August 22, 2023 18:28
Plot aliased FK plots from random SGWs
import numpy as np
import matplotlib.pyplot as plt
from scipy.fft import fftshift, fft2, fftfreq
g = 9.8
H=100
dt = 1
plt.subplots(2,2,figsize=(16,9))
dx_list = (10,20,40)
@bradlipovsky
bradlipovsky / rayleigh-sgws.py
Created May 15, 2023 20:42
Rayleigh waves forced by surface gravity waves
import numpy as np
pp = np.logspace(-5,-1,100)
zz = np.linspace(0,100,101)
q,z=np.meshgrid(pp,zz)
g = 9.8
H=1000
p = np.sqrt(g*q*np.tanh(g*H))
@bradlipovsky
bradlipovsky / 1d-heat-df.py
Created May 5, 2023 16:25
Simple 1d implicit Euler Finite Difference Heat flow calculation
import numpy as np
n = 10
dt = 1
alpha = 1e-6 * 3.15e7
dx = 10
c = dt * alpha / (dx)**2
z = np.arange(0,n*dx,dx)
Q = 0 # change this
k = 1 # change this too
@bradlipovsky
bradlipovsky / opening-lengthening-tradeoff.py
Created May 4, 2023 22:18
Opening versus lengthening effects in moment rate as observed in far field body wave amplitudes
import numpy as np
import matplotlib.pyplot as plt
Lmax = 10.5e3
mustar = 3e9
tmax = 300
D_list = np.logspace(-3,1,100)
H_list = np.logspace(-1,np.log10(400),50)
@bradlipovsky
bradlipovsky / conformal-prediction.py
Created May 4, 2023 16:38
Example conformal prediction
import numpy as np
n_total = 20
mu = 100
sigma = 10
thickness_true = np.random.default_rng().normal(mu, sigma, n_total)
thickness_estimates = np.random.default_rng().normal(mu, sigma, n_total)
# thickness_uncertainty_estimates = np.random.default_rng().normal(2*sigma, 3*sigma, n_total)
thickness_uncertainty_estimates = np.abs(thickness_true - thickness_estimates)