{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Save and wrangle point observations data" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To launch this notebook interactively in a Jupyter notebook-like browser interface, please click the \"Launch Binder\" button below. Note that Binder may take several minutes to launch.\n", "\n", "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/hydroframe/subsettools-binder/HEAD?labpath=hf_hydrodata/point/example_pandas.ipynb)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The hf_hydrodata `get_point_data` and `get_point_metadata` functions return data in [pandas DataFrames](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.html). This notebook goes through some common tasks using pandas, such as saving to a .csv file, saving to a NetCDF file, creating a new variable, and slicing out a particular value. For a more comprehensive introduction to working with data in pandas, please see their [10 minutes to pandas](https://pandas.pydata.org/docs/user_guide/10min.html#min) introduction or [Coming From..](https://pandas.pydata.org/docs/getting_started/index.html#coming-from) documentation to see comparisons to working in R, SQL, Excel, Stata, or SAS.\n", "\n", "Please see the [hf_hydrodata](https://hf-hydrodata.readthedocs.io) documentation for information on what data is available, our data collection process, and new features we are working on! Our [Metadata Description](https://hf-hydrodata.readthedocs.io/en/latest/available_metadata.html#point-observations-metadata) page itemizes the fields that get returned from `get_point_metadata`." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# Import packages\n", "import pandas as pd\n", "import xarray as xr\n", "import numpy as np\n", "from hf_hydrodata import register_api_pin, get_point_data, get_point_metadata" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# You need to register on https://hydrogen.princeton.edu/pin \n", "# and run the following with your registered information\n", "# before you can use the hydrodata utilities\n", "register_api_pin(\"your_email\", \"your_pin\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 1: Working with pandas DataFrames" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this first example, we will showcase several common pandas commands that can be used to inspect a DataFrame.\n", "\n", "Note that `get_point_data` and `get_point_metadata` require mandatory parameters of `dataset`, `variable`, `temporal_resolution`, and `aggregation` (and `depth_level` if asking for soil moisture data). Please see [the documentation](https://hf-hydrodata.readthedocs.io/en/latest/available_data.html) for information about what point observation datasets are available and the parameters used to query them. \n", "\n", "The [hf_hydrodata API Reference](https://hf-hydrodata.readthedocs.io/en/latest/hf_hydrodata.point.html) includes information on what optional filtering parameters are available. These include filters for things like a geographic region or date range. Those parameters work cumulatively, so if `state` and `site_ids` are both supplied, for example, then only sites within `site_ids` that are *also* in `state` will be returned." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# Let's explore daily streamflow data with optional filters for a date range and bounding box. \n", "\n", "# Get observations data and site-level metadata\n", "data_df = get_point_data(dataset=\"usgs_nwis\", variable=\"streamflow\", temporal_resolution=\"daily\", aggregation=\"mean\",\n", " date_start=\"2002-01-01\", date_end=\"2002-01-05\",\n", " latitude_range=(45, 50), longitude_range=(-75, -50))\n", "\n", "metadata_df = get_point_metadata(dataset=\"usgs_nwis\", variable=\"streamflow\", temporal_resolution=\"daily\", aggregation=\"mean\",\n", " date_start=\"2002-01-01\", date_end=\"2002-01-05\",\n", " latitude_range=(45, 50), longitude_range=(-75, -50))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First we will explore pandas' [head](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.head.html) method for DataFrames. `head` will display the first n rows of the DataFrame, with the default to show the first 5 rows." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
site_idsite_namesite_typeagencystatelatitudelongitudefirst_date_data_availablelast_date_data_availablerecord_count...doihuc8conus1_xconus1_yconus2_xconus2_ygagesii_drainage_areagagesii_classgagesii_site_elevationusgs_drainage_area
001011000Allagash River near Allagash, Mainestream gaugeUSGSME47.069722-69.0794441910-07-012023-11-3034028...None01010002nannan421027833186.8440Non-ref187.01478.00
101013500Fish River near Fort Kent, Mainestream gaugeUSGSME47.237500-68.5827781903-07-292023-12-0136507...None01010003nannan423728102252.6960Ref157.0873.00
201015800Aroostook River near Masardis, Mainestream gaugeUSGSME46.523056-68.3716671957-09-142023-12-0124185...None01010004nannan427627472313.7550Non-ref166.0892.00
301017000Aroostook River at Washburn, Mainestream gaugeUSGSME46.777222-68.1572221930-08-012023-12-0134091...None01010004nannan428127734278.9070Non-ref131.01654.00
401017550Williams Brook at Phair, Mainestream gaugeUSGSME46.628056-67.9530561999-11-012023-12-018797...None01010005nannan4300276210.0323Ref176.03.82
\n", "

5 rows × 23 columns

\n", "
" ], "text/plain": [ " site_id site_name site_type agency state \\\n", "0 01011000 Allagash River near Allagash, Maine stream gauge USGS ME \n", "1 01013500 Fish River near Fort Kent, Maine stream gauge USGS ME \n", "2 01015800 Aroostook River near Masardis, Maine stream gauge USGS ME \n", "3 01017000 Aroostook River at Washburn, Maine stream gauge USGS ME \n", "4 01017550 Williams Brook at Phair, Maine stream gauge USGS ME \n", "\n", " latitude longitude first_date_data_available last_date_data_available \\\n", "0 47.069722 -69.079444 1910-07-01 2023-11-30 \n", "1 47.237500 -68.582778 1903-07-29 2023-12-01 \n", "2 46.523056 -68.371667 1957-09-14 2023-12-01 \n", "3 46.777222 -68.157222 1930-08-01 2023-12-01 \n", "4 46.628056 -67.953056 1999-11-01 2023-12-01 \n", "\n", " record_count ... doi huc8 conus1_x conus1_y conus2_x conus2_y \\\n", "0 34028 ... None 01010002 nan nan 4210 2783 \n", "1 36507 ... None 01010003 nan nan 4237 2810 \n", "2 24185 ... None 01010004 nan nan 4276 2747 \n", "3 34091 ... None 01010004 nan nan 4281 2773 \n", "4 8797 ... None 01010005 nan nan 4300 2762 \n", "\n", " gagesii_drainage_area gagesii_class gagesii_site_elevation \\\n", "0 3186.8440 Non-ref 187.0 \n", "1 2252.6960 Ref 157.0 \n", "2 2313.7550 Non-ref 166.0 \n", "3 4278.9070 Non-ref 131.0 \n", "4 10.0323 Ref 176.0 \n", "\n", " usgs_drainage_area \n", "0 1478.00 \n", "1 873.00 \n", "2 892.00 \n", "3 1654.00 \n", "4 3.82 \n", "\n", "[5 rows x 23 columns]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# The default is to show the first 5 rows.\n", "metadata_df.head()" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
site_idsite_namesite_typeagencystatelatitudelongitudefirst_date_data_availablelast_date_data_availablerecord_count...doihuc8conus1_xconus1_yconus2_xconus2_ygagesii_drainage_areagagesii_classgagesii_site_elevationusgs_drainage_area
001011000Allagash River near Allagash, Mainestream gaugeUSGSME47.069722-69.0794441910-07-012023-11-3034028...None01010002nannan421027833186.844Non-ref187.01478.0
101013500Fish River near Fort Kent, Mainestream gaugeUSGSME47.237500-68.5827781903-07-292023-12-0136507...None01010003nannan423728102252.696Ref157.0873.0
201015800Aroostook River near Masardis, Mainestream gaugeUSGSME46.523056-68.3716671957-09-142023-12-0124185...None01010004nannan427627472313.755Non-ref166.0892.0
\n", "

3 rows × 23 columns

\n", "
" ], "text/plain": [ " site_id site_name site_type agency state \\\n", "0 01011000 Allagash River near Allagash, Maine stream gauge USGS ME \n", "1 01013500 Fish River near Fort Kent, Maine stream gauge USGS ME \n", "2 01015800 Aroostook River near Masardis, Maine stream gauge USGS ME \n", "\n", " latitude longitude first_date_data_available last_date_data_available \\\n", "0 47.069722 -69.079444 1910-07-01 2023-11-30 \n", "1 47.237500 -68.582778 1903-07-29 2023-12-01 \n", "2 46.523056 -68.371667 1957-09-14 2023-12-01 \n", "\n", " record_count ... doi huc8 conus1_x conus1_y conus2_x conus2_y \\\n", "0 34028 ... None 01010002 nan nan 4210 2783 \n", "1 36507 ... None 01010003 nan nan 4237 2810 \n", "2 24185 ... None 01010004 nan nan 4276 2747 \n", "\n", " gagesii_drainage_area gagesii_class gagesii_site_elevation \\\n", "0 3186.844 Non-ref 187.0 \n", "1 2252.696 Ref 157.0 \n", "2 2313.755 Non-ref 166.0 \n", "\n", " usgs_drainage_area \n", "0 1478.0 \n", "1 873.0 \n", "2 892.0 \n", "\n", "[3 rows x 23 columns]" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# However, a user can specify the number of rows they'd like to see.\n", "# Here we are showing the first three records.\n", "metadata_df.head(3)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Next, we will use the [shape](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.shape.html) method to get information on the dimensions of a DataFrame. We can use this to answer questions like: how many sites were returned from my query parameters?" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "DataFrame dimensions for metadata_df: (31, 23)\n", "Number of rows (sites) in metadata_df: 31\n", "Number of columns (attributes) in metadata_df: 23\n" ] } ], "source": [ "print(f\"DataFrame dimensions for metadata_df: {metadata_df.shape}\")\n", "print(f\"Number of rows (sites) in metadata_df: {metadata_df.shape[0]}\")\n", "print(f\"Number of columns (attributes) in metadata_df: {metadata_df.shape[1]}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "DataFrames have a method called [columns](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.columns.html) that contains a list of all of the columns names. Notice how in `metadata_df` there is a set of ellipses (...) when we use the `head` method. These represent a whole set of columns that are not explicitly named or previewed. We can use `columns` to see a list of all of the columns that are in a given DataFrame." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['site_id', 'site_name', 'site_type', 'agency', 'state', 'latitude', 'longitude', 'first_date_data_available', 'last_date_data_available', 'record_count', 'site_query_url', 'date_metadata_last_updated', 'tz_cd', 'doi', 'huc8', 'conus1_x', 'conus1_y', 'conus2_x', 'conus2_y', 'gagesii_drainage_area', 'gagesii_class', 'gagesii_site_elevation', 'usgs_drainage_area']\n" ] } ], "source": [ "print(list(metadata_df.columns))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Finally, let's extract one of the columns from the DataFrame returned by `get_point_metadata`. We'll use the [.loc()](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.loc.html) method for this." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
site_idusgs_drainage_area
0010110001478.00
101013500873.00
201015800892.00
3010170001654.00
4010175503.82
501018000175.00
601019000228.30
701027200232.00
801029200173.00
901029500837.00
10010305001418.00
1101031300118.00
120103145095.40
1301031500298.00
1401033000326.00
15010340001162.00
16010345006422.00
17010425001590.00
1801043500516.00
1901044550193.00
200104600090.00
21010465002715.00
2201129200254.00
23010100001341.00
2401010070171.00
25010105002680.00
26010140005929.00
2701018500413.00
28010210001374.00
2904264331298800.00
300429430034.50
\n", "
" ], "text/plain": [ " site_id usgs_drainage_area\n", "0 01011000 1478.00\n", "1 01013500 873.00\n", "2 01015800 892.00\n", "3 01017000 1654.00\n", "4 01017550 3.82\n", "5 01018000 175.00\n", "6 01019000 228.30\n", "7 01027200 232.00\n", "8 01029200 173.00\n", "9 01029500 837.00\n", "10 01030500 1418.00\n", "11 01031300 118.00\n", "12 01031450 95.40\n", "13 01031500 298.00\n", "14 01033000 326.00\n", "15 01034000 1162.00\n", "16 01034500 6422.00\n", "17 01042500 1590.00\n", "18 01043500 516.00\n", "19 01044550 193.00\n", "20 01046000 90.00\n", "21 01046500 2715.00\n", "22 01129200 254.00\n", "23 01010000 1341.00\n", "24 01010070 171.00\n", "25 01010500 2680.00\n", "26 01014000 5929.00\n", "27 01018500 413.00\n", "28 01021000 1374.00\n", "29 04264331 298800.00\n", "30 04294300 34.50" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Let's extract just the site ID and USGS drainage area field.\n", "metadata_df.loc[:, ['site_id', 'usgs_drainage_area']]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2: Save data to .csv" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this example, we will show how to use pandas' [to_csv](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_csv.html) method to save a DataFrame into a .csv file." ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "# Let's explore daily streamflow data with optional filters for a date range and bounding box. \n", "\n", "# Get observations data and site-level metadata\n", "data_df = get_point_data(dataset=\"usgs_nwis\", variable=\"streamflow\", temporal_resolution=\"daily\", aggregation=\"mean\",\n", " date_start=\"2002-01-01\", date_end=\"2002-01-05\",\n", " latitude_range=(45, 50), longitude_range=(-75, -50))\n", "\n", "metadata_df = get_point_metadata(dataset=\"usgs_nwis\", variable=\"streamflow\", temporal_resolution=\"daily\", aggregation=\"mean\",\n", " date_start=\"2002-01-01\", date_end=\"2002-01-05\",\n", " latitude_range=(45, 50), longitude_range=(-75, -50))" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "# The following saves these files as .csv files in the same directory as this notebook. \n", "# You may provide a full file path to save the file(s) elsewhere in your local directory.\n", "# We will set index=False to not have the DataFrame index written to a column.\n", "data_df.to_csv('streamflow_observations.csv', index=False)\n", "metadata_df.to_csv('streamflow_site_metadata.csv', index=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 3: Save data to NetCDF" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Using the same query parameters as in the prior examples, here we will use [xarray](https://docs.xarray.dev/en/stable/index.html) to construct an xarray [Dataset](https://docs.xarray.dev/en/stable/generated/xarray.Dataset.html) from our point observations pandas DataFrame. We will then use xarray's built-in [to_netcdf](https://docs.xarray.dev/en/stable/generated/xarray.Dataset.to_netcdf.html) method to save the Dataset into a NetCDF file." ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
date010110000101350001015800010170000101755001018000010190000102720001029200...01046500011292000101000001010070010105000101400001018500010210000426433104294300
02002-01-019.706913.810412.904821.30990.013301NaN3.08471.986662.43663...46.12923.998411.91431.4829224.055061.4119.112621.90426084.50.2547
12002-01-029.537113.414212.055820.03640.012169NaN3.05641.918742.39135...46.69523.828611.68791.4150023.489059.7139.027721.90426056.20.2547
22002-01-039.339013.074611.518119.07420.011886NaN3.02811.881952.36305...46.97823.828611.51811.3584023.064558.5818.914521.90426084.50.2547
32002-01-049.169212.650111.093626.43220.011320NaN3.05641.836672.34890...51.50623.630511.29171.3131222.640057.4498.857921.90426056.20.2547
42002-01-058.999412.282210.669125.18700.010754NaN3.02811.791392.32060...37.63923.602211.09361.2763322.215556.3178.744721.90425546.80.2830
\n", "

5 rows × 32 columns

\n", "
" ], "text/plain": [ " date 01011000 01013500 01015800 01017000 01017550 01018000 \\\n", "0 2002-01-01 9.7069 13.8104 12.9048 21.3099 0.013301 NaN \n", "1 2002-01-02 9.5371 13.4142 12.0558 20.0364 0.012169 NaN \n", "2 2002-01-03 9.3390 13.0746 11.5181 19.0742 0.011886 NaN \n", "3 2002-01-04 9.1692 12.6501 11.0936 26.4322 0.011320 NaN \n", "4 2002-01-05 8.9994 12.2822 10.6691 25.1870 0.010754 NaN \n", "\n", " 01019000 01027200 01029200 ... 01046500 01129200 01010000 01010070 \\\n", "0 3.0847 1.98666 2.43663 ... 46.129 23.9984 11.9143 1.48292 \n", "1 3.0564 1.91874 2.39135 ... 46.695 23.8286 11.6879 1.41500 \n", "2 3.0281 1.88195 2.36305 ... 46.978 23.8286 11.5181 1.35840 \n", "3 3.0564 1.83667 2.34890 ... 51.506 23.6305 11.2917 1.31312 \n", "4 3.0281 1.79139 2.32060 ... 37.639 23.6022 11.0936 1.27633 \n", "\n", " 01010500 01014000 01018500 01021000 04264331 04294300 \n", "0 24.0550 61.411 9.1126 21.9042 6084.5 0.2547 \n", "1 23.4890 59.713 9.0277 21.9042 6056.2 0.2547 \n", "2 23.0645 58.581 8.9145 21.9042 6084.5 0.2547 \n", "3 22.6400 57.449 8.8579 21.9042 6056.2 0.2547 \n", "4 22.2155 56.317 8.7447 21.9042 5546.8 0.2830 \n", "\n", "[5 rows x 32 columns]" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Let's explore daily streamflow data with optional filters for a date range and bounding box. \n", "\n", "# Get observations data\n", "data_df = get_point_data(dataset=\"usgs_nwis\", variable=\"streamflow\", temporal_resolution=\"daily\", aggregation=\"mean\",\n", " date_start=\"2002-01-01\", date_end=\"2002-01-05\",\n", " latitude_range=(45, 50), longitude_range=(-75, -50))\n", "\n", "# Inspect first five rows\n", "data_df.head(5)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
<xarray.Dataset>\n",
       "Dimensions:     (date: 5, site: 31)\n",
       "Coordinates:\n",
       "  * site        (site) <U8 '01011000' '01013500' ... '04264331' '04294300'\n",
       "  * date        (date) <U10 '2002-01-01' '2002-01-02' ... '2002-01-05'\n",
       "Data variables:\n",
       "    streamflow  (date, site) float64 9.707 13.81 12.9 ... 21.9 5.547e+03 0.283
" ], "text/plain": [ "\n", "Dimensions: (date: 5, site: 31)\n", "Coordinates:\n", " * site (site)