{
"cells": [
{
"cell_type": "markdown",
"id": "584e338a-77e7-4345-a150-caac88337650",
"metadata": {},
"source": [
"\n",
"\n",
"# Chapter 4: Spectral Analysis\n",
"\n",
"by [Julien Emile-Geay](https://orcid.org/0000-0001-5920-4751), University of Southern California\n",
"\n",
"\n",
"Recall that in spectral analysis we step into a \"bizarro world\", switching from the time domain to the frequency domain. There, two essential features are of interest: peaks, and background. In this tutorial, we will perform spectral analysis on Rio Grande streamflow, and see if we can learn anything interesting about it in this way.\n",
"\n",
"### Packages\n",
"In addition to the Scientific Python stack (numpy, scipy, matplotlib), this tutorial showcases: \n",
"- [pandas](https://pandas.pydata.org/)\n",
"- [Pyleoclim](http://linked.earth/PyleoTutorials/) was designed for the analysis of paleoclimate timeseries, but we show here that is perfectly able to deal with any timeseries.\n",
"\n",
"### Dataset \n",
"We will be looking at the daily discharge of the Rio Grande, which has been measured at \n",
"Embudo, NM since 1889. The data and their associated metadata may be retrieved from\n",
"the [USGS website](https://waterdata.usgs.gov/nwis/dv?cb_00060=on&format=html&site_no=08279500&legacy=&referred_module=sw&period=&begin_date=2023-05-21&end_date=2024-05-20\n",
"). Let's load them and have a look:\n",
"\n",
"## Data Wrangling \n",
"\n",
"Once again we use pandas to load the data from the web. We need to give it a little help by specifying the column names:"
]
},
{
"cell_type": "code",
"execution_count": 152,
"id": "a5cbfdbd-e5ad-4409-9e5d-c585f64fa853",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n", " | agency | \n", "site_no | \n", "datetime | \n", "discharge (cf/s) | \n", "code | \n", "
---|---|---|---|---|---|
0 | \n", "USGS | \n", "8279500 | \n", "1889-01-01 | \n", "398.0 | \n", "A | \n", "
1 | \n", "USGS | \n", "8279500 | \n", "1889-01-02 | \n", "385.0 | \n", "A | \n", "
2 | \n", "USGS | \n", "8279500 | \n", "1889-01-03 | \n", "395.0 | \n", "A | \n", "
3 | \n", "USGS | \n", "8279500 | \n", "1889-01-04 | \n", "400.0 | \n", "A | \n", "
4 | \n", "USGS | \n", "8279500 | \n", "1889-01-05 | \n", "413.0 | \n", "A | \n", "