{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Plot an interferogram\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import os\nif \"SPHINX_DOC_BUILD\" in os.environ:\n os.chdir(r\"X:\\msnoise2\")\n\nimport matplotlib\nmatplotlib.use(\"agg\")\n\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport pandas as pd\nfrom pandas.plotting import register_matplotlib_converters\nregister_matplotlib_converters()\n\nplt.style.use(\"ggplot\")\n\nfrom msnoise.api import connect, get_results, build_movstack_datelist, get_params, get_t_axis\n\n# connect to the database\ndb = connect()\n\n# Obtain a list of dates between ``start_date`` and ``enddate``\nstart, end, datelist = build_movstack_datelist(db)\n\n# Get the list of parameters from the DB:\nparams = get_params(db)\n\n# Get the time axis for plotting the CCF:\ntaxis = get_t_axis(db)\n\n# Get the results for two station, filter id=1, ZZ component, mov_stack=1 and the results as a 2D array:\nn, ccfs = get_results(db, \"YA.FLR.00\", \"YA.FOR.00\", 1, \"ZZ\", datelist, 1, format=\"matrix\", params=params)\n\n# Convert to a pandas DataFrame object for convenience, and drop empty rows:\ndf = pd.DataFrame(ccfs, index=pd.DatetimeIndex(datelist), columns=taxis)\ndf = df.dropna()\n\n# Define the 99% percentile of the data, for visualisation purposes:\nclim = df.mean(axis=\"index\").quantile(0.99)\n\nfig, ax = plt.subplots()\nplt.pcolormesh(df.columns, df.index.to_pydatetime(), df.values,\n vmin=-clim, vmax=clim, rasterized=True)\nplt.colorbar()\nplt.title(\"Interferogram\")\nplt.xlabel(\"Lag Time (s)\")\nplt.ylim(df.index[0],df.index[-1])\nplt.xlim(df.columns[0], df.columns[-1])\nplt.subplots_adjust(left=0.15)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Running a simple moving window average can be done with pandas's functions:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "smooth = df.rolling(5).mean()\n\nfig, ax = plt.subplots()\nplt.pcolormesh(smooth.columns, smooth.index.to_pydatetime(), smooth.values,\n vmin=-clim, vmax=clim, rasterized=True)\nplt.colorbar()\nplt.title(\"Interferogram (smoothed over 5 days)\")\nplt.xlabel(\"Lag Time (s)\")\nplt.ylim(smooth.index[0],smooth.index[-1])\nplt.xlim(smooth.columns[0], smooth.columns[-1])\nplt.subplots_adjust(left=0.15)\n\n\nplt.show() \n#EOF" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.10" } }, "nbformat": 4, "nbformat_minor": 0 }