Skip to content

Instantly share code, notes, and snippets.

View bradlipovsky's full-sized avatar

Brad Lipovsky bradlipovsky

View GitHub Profile
@bradlipovsky
bradlipovsky / PlotOnImagery.py
Last active August 25, 2020 14:04
Plot a dataset overlain on imagery
#
# First, Convert the ground track to imagery coordinate system
#
from pyproj import Transformer
transformer = Transformer.from_crs("EPSG:4326", "EPSG:32617")
#
# Make a plot for the imagery
#
@bradlipovsky
bradlipovsky / is2-nsidc-cloud.py
Created May 19, 2021 17:02
ICESat-2 NSIDC Cloud Access
import subprocess
import s3fs
import h5py
import numpy as np
# Get Credentials
# See https://nsidc.org/support/how/how-do-i-programmatically-request-data-services#mac
inquiry = subprocess.run(['curl', "-b", "/home/ec2-user/.urs_cookies", \
"-c", "/home/ec2-user/.urs_cookies", \
@bradlipovsky
bradlipovsky / github-ssh.sh
Last active April 4, 2022 18:42
Getting started on GitHub
# First, check to see if you have a .ssh directory.
ls ~/.ssh
# If this doesn't return an error: continue to create a new SSH key.
# If this does return an error, make a .ssh directory:
mkdir ~/.ssh
# Create a new SSH key
ssh-keygen -t ed25519 -C "your_email@example.com"
# Default file location and name are fine. I prefer to not use a passcode, but that's up to you.
# To do both of those things, hit enter three times!
@bradlipovsky
bradlipovsky / sermeq-plot-ronne-rifts.py
Created November 11, 2021 17:25
An example of how to plot some data on the UW sermeq machine
import pickle
import pandas as pd
import numpy as np
import os
from matplotlib import cm
import matplotlib.pyplot as plt
shelf_name = 'ronne'
datapath = '/data/fast1/arc/'
@bradlipovsky
bradlipovsky / napkin-dv.py
Created March 15, 2022 21:55
dV Back of the envelope
dx_apparent = 14 # Known source-receiver distance
vtrue = 6e3 # Known p-wave speed
t0 = 380/48e3 # Measured travel time
dt = (5/48e3) # Measured travel time change
dx_true = t0 * vtrue # Actual propagation path >> source-receiver distance
print('True propagation path length: %f'%dx_true)
v1 = dx_true/t0
v2 = dx_true/(t0-dt)
@bradlipovsky
bradlipovsky / fgws.py
Last active May 11, 2022 15:27
Calculate the dispersion of flexural gravity waves (FGWs)
'''
Code to calculate the dispersion relation of Flexural Gravity Waves
'''
import numpy as np
import matplotlib.pyplot as plt
g=9.81 # Gravity, m/s**2
hw=100 # Water depth, m
hi = 300 # Ice thickness, m
rhow=1000 # Water density, kg/m**3
@bradlipovsky
bradlipovsky / firedrake_elasticity.py
Created July 14, 2022 17:35
Use firedrake to solve the equations of 2D linear elasticity
import matplotlib.pyplot as plt
from firedrake import *
length = 1
width = 0.2
mesh = RectangleMesh(40, 20, length, width)
V = VectorFunctionSpace(mesh, "Lagrange", 1)
bc = DirichletBC(V, Constant([0, 0]), 1)
rho = Constant(0.01)
@bradlipovsky
bradlipovsky / mode1strains.py
Last active July 28, 2022 16:25
Plot the strains on a line running parallel to a mode 1 (opening) crack
import numpy as np
import matplotlib.pyplot as plt
# Analytical solutions found in Zehnder
a = 10
x1 = np.linspace(0,2*a,401)
x2 = np.linspace(0,1.5*a,201)
X1,X2 = np.meshgrid(x1,x2)
Z = X1 + 1j*X2
@bradlipovsky
bradlipovsky / surface-gravity-wave-dispersion.py
Created August 2, 2022 20:31
Plots of the dispersion relation for SGWs with added physics
import numpy as np
import matplotlib.pyplot as plt
cs=1500
g=9.8
h=100
kappa = np.linspace(-0.08,0.08,100)
fig,ax=plt.subplots(1,4,figsize=(15,4))
plt.subplot(141)
@bradlipovsky
bradlipovsky / fenicsx-poisson-minimal.py
Created August 4, 2022 18:57
Minimal FEniCSx example
# Motivated by this example:
# https://jorgensd.github.io/dolfinx-tutorial/chapter1/fundamentals.html
# ... but hopefully even simpler!
from mpi4py import MPI
from dolfinx import mesh
from dolfinx.fem import FunctionSpace
from dolfinx import fem
import numpy as np
import ufl