Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gauge interp #148

Merged
merged 2 commits into from
May 3, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions src/python/visclaw/gauge_interp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@

"""
Tools to assist interpolating from fort.gauge output to a given
set of times (e.g. equally spaced).

Example:
Set gaugeno to the desired gauge number, iq to the component of q to
plot, e.g. iq=3 for surface eta.

import gauge_interp
getgauge = gauge_interp.make_getgauge(output='_outdir')
gf,t1,t2 = gauge_interp.gauge_function(getgauge, gaugeno, iq)
t = numpy.linspace(t1,t2,50) # desired times of interpolation
gt = gf(t)

Then gt will be an array of the same length as t containing interpolated
values (piecewise linear).

See also the test function below, which can be run via:

$ cd $CLAW/geoclaw/examples/tsunami/chile2010
$ make .output
$ python
>>> from clawpack.visclaw import gauge_interp
>>> gauge_interp.test()

"""


def make_getgauge(outdir='_output'):
"""
Create function getgauge that will grab one set of gauge data
from the fort.gauge file in directory specified by outdir.
"""
from clawpack.visclaw.data import ClawPlotData
plotdata = ClawPlotData()
plotdata.outdir = outdir
getgauge = plotdata.getgauge
return getgauge


def gauge_function(getgauge, gaugeno, iq):
"""
Given getgauge function, return a function that
can be used to evaluate the iq component of q at any time
in the interval covered by the gauge output.

Also returns t1, t2 the end points of validity.

Does piecewise linear interpolation based on g.q and g.q[iq,:]
where g is the gauge data.
"""

from scipy import interpolate

g = getgauge(gaugeno)
gf = interpolate.interp1d(g.t, g.q[iq,:])
t1 = g.t[0]
t2 = g.t[-1]
return gf, t1, t2


def test(gaugeno=32412, iq=3):

# Test should work in $CLAW/geoclaw/examples/tsunami/chile2010
import numpy
import matplotlib.pyplot as plt

# interpolate at a set of times t:
getgauge = make_getgauge(outdir='_output')
gf,t1,t2 = gauge_function(getgauge, gaugeno, iq)
t = numpy.linspace(t1,t2,100)
gt = gf(t)

# Plot the two for comparison:
plt.plot(t,gt,'ro', markersize=5, label='interpolated')
g = getgauge(gaugeno)
plt.plot(g.t, g.q[iq,:], 'k-',label='original data')
plt.legend()
plt.show()