{ "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 if \"MSNOISE_DOC\" in os.environ:\n os.chdir(os.environ[\"MSNOISE_DOC\"])\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, xr_get_ccf\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 first mov_stack configured:\nmov_stack = params.mov_stack[0]\n\n# Get the results for two station, filter id=1, ZZ component, mov_stack=1 and the results as a 2D array:\nccf = xr_get_ccf(\"PF.FJS.00\", \"PF.FOR.00\", \"ZZ\", 1, mov_stack, taxis, format=\"xarray\")\n\n# Plot the interferogram\nccf.plot(robust=True, figsize=(10,8))" ] }, { "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 = ccf.rolling(times=5).mean()\n\nsmooth.plot(robust=True, figsize=(10,8))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Plotting the sub-daily stacks and zooming on +- 20 seconds:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "if \"SPHINX_DOC_BUILD\" in os.environ:\n if \"MSNOISE_DOC\" in os.environ:\n os.chdir(os.environ[\"MSNOISE_DOC\"])\n\n# Get the last mov_stack configured:\nmov_stack = params.mov_stack[-1]\n\n# Get the results for two station, filter id=1, ZZ component, mov_stack=1 and the results as a 2D array:\nccf = xr_get_ccf(\"PF.FJS.00\", \"PF.FOR.00\", \"ZZ\", 1, mov_stack, taxis, format=\"xarray\")\n\n# Plot the interferogram and zoom in around +- 10 seconds lag\nccf.loc[:,-20:20].plot(robust=True, figsize=(10,8))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Finally, stacking to a Reference function\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "ccf.mean(axis=0).plot(figsize=(10,8))\n\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 }