{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [], "collapsed_sections": [ "tYzchKpM7DlA", "i4UTa6PqGjn4", "7jf1Ar-fKD64" ] }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "markdown", "source": [ "# **MATE Floats! Coding Notebook** - Day 4\n", "\n", "Created by Ethan C. Campbell for NCAT/MATE/GO-BGC Marine Technology Summer Program\n", "\n", "Thursday, August 24, 2023" ], "metadata": { "id": "OxvLAQ1SWpeR" } }, { "cell_type": "code", "source": [ "import numpy as np # NumPy is an array and math library\n", "import matplotlib.pyplot as plt # Matplotlib is a visualization (plotting) library\n", "import pandas as pd # Pandas lets us work with spreadsheet (.csv) data\n", "from datetime import datetime, timedelta # Datetime helps us work with dates and times" ], "metadata": { "id": "oMjc5MqnJrgv" }, "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "source": [ "## Part 1: Loading and plotting R/V Rachel Carson CTD casts" ], "metadata": { "id": "tYzchKpM7DlA" } }, { "cell_type": "markdown", "source": [ "First, let's download three `.csv` data files from Google Drive here: https://drive.google.com/drive/folders/1Am6XdlB-APQ3ccOvLeGK8DFPQ2OnPeJD?usp=sharing. Two of the files are CTD casts that were collected from the R/V Rachel Carson off of Carkeek Park near Seattle. ***Save these two files to your computer.***\n", "\n", "Let's first take a look at the raw files, including their headers.\n", "\n", "Next, we can upload the files to this Google Colab notebook. ***Click the sidebar folder icon on the left, then use the page-with-arrow icon at the top to select the files and upload them.*** NOTE: uploaded files will be deleted from Google Colab when you refresh this notebook!\n", "\n", "We will specify each **filepath** using string variables:" ], "metadata": { "id": "czGyp7MTAc5T" } }, { "cell_type": "code", "source": [ "filepath_0 = '/content/2023051001001_Carkeek.csv'\n", "filepath_1 = '/content/2023051101001_Carkeek.csv'" ], "metadata": { "id": "gnrD640dB5ds" }, "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "source": [ "Now, we can load the files using `pandas`:\n", "\n", "> **`pd.read_csv(FILEPATH, ARGUMENTS...)`**\n", "\n", "This function is very customizable using the many optional `ARGUMENTS`, which allow it to handle almost any file. You can find documentation about the arguments [at this link](https://pandas.pydata.org/docs/reference/api/pandas.read_csv.html).\n", "\n", "***Let's first take a look at the data file using a simple text editor. Notice the long header. What argument can we use to exclude the header from being loaded?***\n", "\n", "Below, we'll load each data file using ``pd.read_csv()`` and store each file into a new variable.\n", "\n", "We can look at the data using **`display()`** (which is a fancy version of `print()` for DataFrames):" ], "metadata": { "id": "XaUCH7ikB6Sy" } }, { "cell_type": "code", "source": [ "data_0 = pd.read_csv(filepath_0,comment='#')\n", "data_1 = pd.read_csv(filepath_1,comment='#')\n", "\n", "display(data_0)" ], "metadata": { "id": "4boQwvSg7R5J", "colab": { "base_uri": "https://localhost:8080/", "height": 461 }, "outputId": "a59792ca-8e90-487c-91e3-181925361bdd" }, "execution_count": null, "outputs": [ { "output_type": "display_data", "data": { "text/plain": [ " Unnamed: 0 altM CStarTr0 c0mS/cm density00 depSM latitude \\\n", "0 0 98.53 71.0825 31.662958 1021.7317 2.101 47.71418 \n", "1 1 98.53 71.0825 31.662061 1021.7317 2.005 47.71418 \n", "2 2 98.53 71.0825 31.661464 1021.7323 2.045 47.71418 \n", "3 3 98.53 71.0825 31.660448 1021.7323 2.005 47.71418 \n", "4 4 98.53 71.0825 31.658416 1021.7325 1.981 47.71418 \n", "... ... ... ... ... ... ... ... \n", "8200 8200 11.99 83.1087 31.920640 1024.1134 173.726 47.71316 \n", "8201 8201 11.99 83.1087 31.920640 1024.1135 173.726 47.71316 \n", "8202 8202 11.99 83.1087 31.920820 1024.1141 173.846 47.71316 \n", "8203 8203 11.99 83.1087 31.920579 1024.1129 173.613 47.71316 \n", "8204 8204 11.99 83.1087 31.920340 1024.1135 173.846 47.71316 \n", "\n", " longitude flECO-AFL modError sbeox0Mg/L sbeox0ML/L ph \\\n", "0 -122.40854 2.8127 0 10.6450 7.4488 9.271 \n", "1 -122.40854 2.8127 0 10.6446 7.4484 9.271 \n", "2 -122.40854 2.8127 0 10.6443 7.4483 9.271 \n", "3 -122.40854 2.8713 0 10.6441 7.4481 9.271 \n", "4 -122.40854 3.1057 0 10.6443 7.4483 9.271 \n", "... ... ... ... ... ... ... \n", "8200 -122.40812 0.1753 0 7.0198 4.9120 8.788 \n", "8201 -122.40812 0.1753 0 7.0201 4.9123 8.788 \n", "8202 -122.40812 0.1753 0 7.0204 4.9125 8.788 \n", "8203 -122.40812 0.1753 0 7.0205 4.9125 8.783 \n", "8204 -122.40812 0.1753 0 7.0209 4.9128 8.788 \n", "\n", " potemp090C prDM sal00 t090C scan nbf flag \n", "0 10.2155 2.119 28.3385 10.2157 3408 0 0.0 \n", "1 10.2140 2.022 28.3388 10.2143 3409 0 0.0 \n", "2 10.2129 2.062 28.3391 10.2131 3410 0 0.0 \n", "3 10.2117 2.022 28.3390 10.2119 3411 0 0.0 \n", "4 10.2093 1.998 28.3389 10.2095 3412 0 0.0 \n", "... ... ... ... ... ... ... ... \n", "8200 8.3719 175.266 30.0190 8.3887 11608 0 0.0 \n", "8201 8.3717 175.266 30.0191 8.3886 11609 0 0.0 \n", "8202 8.3718 175.387 30.0191 8.3887 11610 0 0.0 \n", "8203 8.3719 175.152 30.0190 8.3887 11611 0 0.0 \n", "8204 8.3720 175.387 30.0184 8.3889 11612 0 0.0 \n", "\n", "[8205 rows x 20 columns]" ], "text/html": [ "\n", "
\n", " | Unnamed: 0 | \n", "altM | \n", "CStarTr0 | \n", "c0mS/cm | \n", "density00 | \n", "depSM | \n", "latitude | \n", "longitude | \n", "flECO-AFL | \n", "modError | \n", "sbeox0Mg/L | \n", "sbeox0ML/L | \n", "ph | \n", "potemp090C | \n", "prDM | \n", "sal00 | \n", "t090C | \n", "scan | \n", "nbf | \n", "flag | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "0 | \n", "98.53 | \n", "71.0825 | \n", "31.662958 | \n", "1021.7317 | \n", "2.101 | \n", "47.71418 | \n", "-122.40854 | \n", "2.8127 | \n", "0 | \n", "10.6450 | \n", "7.4488 | \n", "9.271 | \n", "10.2155 | \n", "2.119 | \n", "28.3385 | \n", "10.2157 | \n", "3408 | \n", "0 | \n", "0.0 | \n", "
1 | \n", "1 | \n", "98.53 | \n", "71.0825 | \n", "31.662061 | \n", "1021.7317 | \n", "2.005 | \n", "47.71418 | \n", "-122.40854 | \n", "2.8127 | \n", "0 | \n", "10.6446 | \n", "7.4484 | \n", "9.271 | \n", "10.2140 | \n", "2.022 | \n", "28.3388 | \n", "10.2143 | \n", "3409 | \n", "0 | \n", "0.0 | \n", "
2 | \n", "2 | \n", "98.53 | \n", "71.0825 | \n", "31.661464 | \n", "1021.7323 | \n", "2.045 | \n", "47.71418 | \n", "-122.40854 | \n", "2.8127 | \n", "0 | \n", "10.6443 | \n", "7.4483 | \n", "9.271 | \n", "10.2129 | \n", "2.062 | \n", "28.3391 | \n", "10.2131 | \n", "3410 | \n", "0 | \n", "0.0 | \n", "
3 | \n", "3 | \n", "98.53 | \n", "71.0825 | \n", "31.660448 | \n", "1021.7323 | \n", "2.005 | \n", "47.71418 | \n", "-122.40854 | \n", "2.8713 | \n", "0 | \n", "10.6441 | \n", "7.4481 | \n", "9.271 | \n", "10.2117 | \n", "2.022 | \n", "28.3390 | \n", "10.2119 | \n", "3411 | \n", "0 | \n", "0.0 | \n", "
4 | \n", "4 | \n", "98.53 | \n", "71.0825 | \n", "31.658416 | \n", "1021.7325 | \n", "1.981 | \n", "47.71418 | \n", "-122.40854 | \n", "3.1057 | \n", "0 | \n", "10.6443 | \n", "7.4483 | \n", "9.271 | \n", "10.2093 | \n", "1.998 | \n", "28.3389 | \n", "10.2095 | \n", "3412 | \n", "0 | \n", "0.0 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
8200 | \n", "8200 | \n", "11.99 | \n", "83.1087 | \n", "31.920640 | \n", "1024.1134 | \n", "173.726 | \n", "47.71316 | \n", "-122.40812 | \n", "0.1753 | \n", "0 | \n", "7.0198 | \n", "4.9120 | \n", "8.788 | \n", "8.3719 | \n", "175.266 | \n", "30.0190 | \n", "8.3887 | \n", "11608 | \n", "0 | \n", "0.0 | \n", "
8201 | \n", "8201 | \n", "11.99 | \n", "83.1087 | \n", "31.920640 | \n", "1024.1135 | \n", "173.726 | \n", "47.71316 | \n", "-122.40812 | \n", "0.1753 | \n", "0 | \n", "7.0201 | \n", "4.9123 | \n", "8.788 | \n", "8.3717 | \n", "175.266 | \n", "30.0191 | \n", "8.3886 | \n", "11609 | \n", "0 | \n", "0.0 | \n", "
8202 | \n", "8202 | \n", "11.99 | \n", "83.1087 | \n", "31.920820 | \n", "1024.1141 | \n", "173.846 | \n", "47.71316 | \n", "-122.40812 | \n", "0.1753 | \n", "0 | \n", "7.0204 | \n", "4.9125 | \n", "8.788 | \n", "8.3718 | \n", "175.387 | \n", "30.0191 | \n", "8.3887 | \n", "11610 | \n", "0 | \n", "0.0 | \n", "
8203 | \n", "8203 | \n", "11.99 | \n", "83.1087 | \n", "31.920579 | \n", "1024.1129 | \n", "173.613 | \n", "47.71316 | \n", "-122.40812 | \n", "0.1753 | \n", "0 | \n", "7.0205 | \n", "4.9125 | \n", "8.783 | \n", "8.3719 | \n", "175.152 | \n", "30.0190 | \n", "8.3887 | \n", "11611 | \n", "0 | \n", "0.0 | \n", "
8204 | \n", "8204 | \n", "11.99 | \n", "83.1087 | \n", "31.920340 | \n", "1024.1135 | \n", "173.846 | \n", "47.71316 | \n", "-122.40812 | \n", "0.1753 | \n", "0 | \n", "7.0209 | \n", "4.9128 | \n", "8.788 | \n", "8.3720 | \n", "175.387 | \n", "30.0184 | \n", "8.3889 | \n", "11612 | \n", "0 | \n", "0.0 | \n", "
8205 rows × 20 columns
\n", "\n", " | sg_data_point | \n", "time | \n", "pressure | \n", "depth | \n", "temperature | \n", "conductivity | \n", "salinity | \n", "sigma_theta | \n", "density | \n", "latitude | \n", "longitude | \n", "buoyancy | \n", "speed | \n", "glide_angle | \n", "horz_speed | \n", "vert_speed | \n", "polar_heading | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "0 | \n", "2023-05-12 19:14:17.464999936 | \n", "1.076991 | \n", "1.067980 | \n", "11.409176 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "47.715300 | \n", "-122.398800 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "1.495747 | \n", "
1 | \n", "1 | \n", "2023-05-12 19:14:22.731000064 | \n", "1.117253 | \n", "1.107904 | \n", "11.409607 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "47.715302 | \n", "-122.398799 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "1.628392 | \n", "
2 | \n", "2 | \n", "2023-05-12 19:14:29.736000000 | \n", "1.157514 | \n", "1.147829 | \n", "11.411506 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "47.715306 | \n", "-122.398797 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "1.516691 | \n", "
3 | \n", "3 | \n", "2023-05-12 19:14:35.012999936 | \n", "1.157514 | \n", "1.147829 | \n", "11.414287 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "47.715310 | \n", "-122.398795 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "1.621411 | \n", "
4 | \n", "4 | \n", "2023-05-12 19:14:40.288000000 | \n", "1.268233 | \n", "1.257621 | \n", "11.412624 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "47.715314 | \n", "-122.398794 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "1.574287 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
335 | \n", "335 | \n", "2023-05-12 20:06:59.275000064 | \n", "0.513332 | \n", "0.509038 | \n", "11.268633 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "47.724696 | \n", "-122.397495 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "2.405064 | \n", "
336 | \n", "336 | \n", "2023-05-12 20:07:04.279000064 | \n", "0.402614 | \n", "0.399245 | \n", "11.278361 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "47.724699 | \n", "-122.397493 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "2.466150 | \n", "
337 | \n", "337 | \n", "2023-05-12 20:07:08.697999872 | \n", "0.422744 | \n", "0.419208 | \n", "11.290254 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "47.724703 | \n", "-122.397491 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "2.069960 | \n", "
338 | \n", "338 | \n", "2023-05-12 20:07:14.273999872 | \n", "0.372418 | \n", "0.369302 | \n", "11.305961 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "47.724706 | \n", "-122.397490 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "2.134538 | \n", "
339 | \n", "339 | \n", "2023-05-12 20:07:19.279000064 | \n", "0.342222 | \n", "0.339359 | \n", "11.332550 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "47.724710 | \n", "-122.397488 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "1.870993 | \n", "
340 rows × 17 columns
\n", "