Skip to content

Instantly share code, notes, and snippets.

View emolch's full-sized avatar

Sebastian Heimann emolch

View GitHub Profile
@emolch
emolch / defaults.py
Created July 10, 2017 09:37
How to create child objects with defaults with guts
from pyrocko.guts import Object, Float
class Location(Object):
lat = Float.T()
lon = Float.T()
class Setup(Object):
location = Location.T(default=Location.D(lat=10., lon=20.))
@emolch
emolch / range_check.py
Created April 11, 2017 13:08
How to implement range checking with guts.
from pyrocko.guts import Float, Object, ValidationError, List
def float_or_none(x):
if x is None:
return None
else:
return float(x)
@emolch
emolch / extract_topo.py
Created April 10, 2017 08:21
How download extract and save some topography data as .grd file for GMT.
from pyrocko import topo, gmtpy
wesn = (171., 176., -44., -40.)
for dem in ('ETOPO1', 'SRTMGL3'):
t = topo.get(dem, wesn)
gmtpy.savegrd(
t.x(), t.y(), t.data,
filename='topo_%s_%g_%g_%g_%g.grd' % ((dem, ) + wesn),
@emolch
emolch / beach.py
Created February 8, 2017 11:18
How to plot full MT, deviatoric and double-couble focal mechanism solutions with Pyrocko
from matplotlib import pyplot as plt
from pyrocko import beachball, moment_tensor as pmt, plot
fig = plt.figure(figsize=(4., 2.))
fig.subplots_adjust(left=0., right=1., bottom=0., top=1.)
axes = fig.add_subplot(1, 1, 1)
axes.set_xlim(0., 4.)
axes.set_ylim(0., 2.)
axes.set_axis_off()
import sys
from pyrocko.fdsn import station as fs
# Example on how to manipulate StationXML with Pyrocko (pyrocko.fdsn.station)
#
# Reads StationXML file and replaces sensor orientation and input unit
# information
sx = fs.load_xml(filename=sys.argv[1])
import gmtpy
import subprocess
import os
wh = 2.0*gmtpy.cm
mw = 0.1*gmtpy.cm
inch = 2.54*gmtpy.cm
beachball_config = dict(
from subprocess import check_call, check_output
import os
import random
import shutil
import traceback
import tempfile
from pyrocko import moment_tensor as pmt
from obspy.imaging import beachball as opb
import gmtpy
import mopad