diff --git a/book/modules/08_Vector_TimeSeries_SNOTEL/08_GNSS_trajectory_demo.ipynb b/book/modules/08_Vector_TimeSeries_SNOTEL/08_GNSS_trajectory_demo.ipynb index 0c78599..049a9b4 100644 --- a/book/modules/08_Vector_TimeSeries_SNOTEL/08_GNSS_trajectory_demo.ipynb +++ b/book/modules/08_Vector_TimeSeries_SNOTEL/08_GNSS_trajectory_demo.ipynb @@ -69,6 +69,15 @@ "df" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "df['GPS Date'].iloc[0]" + ] + }, { "cell_type": "code", "execution_count": null, @@ -78,6 +87,15 @@ "pd.to_datetime(df['GPS Date'] + ' ' + df['GPS Time'])" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#pd.read_csv?" + ] + }, { "cell_type": "code", "execution_count": null, @@ -141,6 +159,15 @@ "df.head()" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "df.index" + ] + }, { "cell_type": "code", "execution_count": null, diff --git a/book/modules/08_Vector_TimeSeries_SNOTEL/08_Timestamp_demo.ipynb b/book/modules/08_Vector_TimeSeries_SNOTEL/08_Timestamp_demo.ipynb index f6f1d2d..58e4687 100644 --- a/book/modules/08_Vector_TimeSeries_SNOTEL/08_Timestamp_demo.ipynb +++ b/book/modules/08_Vector_TimeSeries_SNOTEL/08_Timestamp_demo.ipynb @@ -12,6 +12,7 @@ "## Introduction\n", "* https://csit.kutztown.edu/~schwesin/fall20/csc223/lectures/Pandas_Time_Series.html\n", "* Multiple options to represent datetime objects - easy to convert\n", + "* https://en.wikipedia.org/wiki/Second\n", "\n", "### Python `datetime`\n", "* Built-in module called `datetime` which contains classes for `datetime` object (and `timedelta` object) - can be confusing\n", @@ -42,7 +43,8 @@ "* December 31 = 365 \n", "\n", "### Water year\n", - "* Starts October 1, ends September" + "* Starts October 1, ends September\n", + "* Southern hemisphere?" ] }, { @@ -92,7 +94,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -103,7 +105,34 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "\u001b[0;31mInit signature:\u001b[0m \u001b[0mdatetime\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m/\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mDocstring:\u001b[0m \n", + "datetime(year, month, day[, hour[, minute[, second[, microsecond[,tzinfo]]]]])\n", + "\n", + "The year, month and day arguments are required. tzinfo may be None, or an\n", + "instance of a tzinfo subclass. The remaining arguments may be ints.\n", + "\u001b[0;31mFile:\u001b[0m /srv/conda/envs/notebook/lib/python3.9/datetime.py\n", + "\u001b[0;31mType:\u001b[0m type\n", + "\u001b[0;31mSubclasses:\u001b[0m ABCTimestamp, _NaT\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "datetime?" + ] + }, + { + "cell_type": "code", + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -113,52 +142,251 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2022-02-26 01:55:25.626477\n" + ] + } + ], "source": [ "print(dt2)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "datetime.datetime(2022, 2, 26, 1, 55, 25, 626477)" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dt2" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2022" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "dt2.year" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "\u001b[0;31mDocstring:\u001b[0m format -> strftime() style string.\n", + "\u001b[0;31mType:\u001b[0m builtin_function_or_method\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ + "dt2.strftime?" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Side note: formatting timestamp strings" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'20220226'" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#YYYYMMDD is best\n", "dt2.strftime('%Y%m%d')" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'02262022'" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "dt2 - dt1" + "#This won't sort alphanumerically\n", + "dt2.strftime('%m%d%Y')" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, "outputs": [], + "source": [ + "dt_diff = dt2 - dt1" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "datetime.timedelta(days=4, seconds=6925, microseconds=626477)" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dt_diff" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "352525.626477" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dt_diff.total_seconds()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### How many seconds in a day? In a year?\n", + "* approximately `pi * 10^7`\n", + "* What is a second anyway?" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "86400" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "60*60*24" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "datetime.datetime(2022, 2, 26, 1, 55, 25, 626477)" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dt2" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Timestamp('2022-02-26 01:55:25.626477')" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "pd.to_datetime(dt2)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, "outputs": [], "source": [ @@ -167,7 +395,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": {}, "outputs": [], "source": [ @@ -176,25 +404,47 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "Timestamp('2019-02-01 12:00:00')" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "ts1" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "Timestamp('2019-02-06 00:00:00')" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "ts2" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": {}, "outputs": [], "source": [ @@ -203,45 +453,120 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "Timedelta('4 days 12:00:00')" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "dt" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "Timestamp('2019-02-01 12:00:00')" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ts1" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Timestamp('2019-02-06 00:00:00')" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "ts1 + dt" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "Timestamp('2019-02-10 12:00:00')" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "ts2 + dt" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "Timestamp('2019-01-31 12:00:00')" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "ts1 - pd.Timedelta(days=1)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "388800.0" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "dt.total_seconds()" ]