{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "This block contains comments as markdown code\n", "# **Chapter 1** \n", "**ATMOS 5340: Environmental Programming and Statistics** \n", "**John Horel **\n", "\n", "- If you are viewing using a linux terminal window, are you in your atmos_5340/chapter1 directory?\n", "- If you are viewing using Jupyter notebook, then ignore the following\n", "- Don't type the ' ' quote marks\n", "- check! 'pwd'\n", "- If not, then 'cd'\n", "- 'cd atmos_5340/chapter1'\n", "- Do the following. Note the dot after the space\n", "- 'cp ~u0035056/atmos_5340_2021/chapter1/* . '\n", "- Have you already copied the data directory? If not, you'll need to do that too\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Using Python modules\n", "\n", "`numpy` provides routines to handle arrays and many calculations efficiently and is imported by convention as `np`. Numpy functions are very good at handling homogeneous data arrays (and similar in that respect to matlab functions).\n", "\n", "`pandas` is really good at handling tabular/array data that may have heterogeneous types (floating and text, for example). It is imported by convention as `pd`. \n", "\n", "There are a couple sets of panda library routines (`Series`, and `DataFrame`) used so frequently that we'll import those directly too.\n", "\n", "`scipy` has a bunch of statistical functions and we'll import `stats` from `scipy`\n", "\n", "\n", "`pyplot` is a _submodule_ of matplotlib. It is typically imported as the alias `plt` to handle basic plotting" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# these are python modules used in the program\n", "import numpy as np\n", "import pandas as pd\n", "from pandas import Series, DataFrame\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Alta snowfall\n", "https://utahavalanchecenter.org/alta-monthly-snowfall\n", "\n", "\n", "Look in the `data` folder at the called `alta_snow.csv`\n", "\n", "Open the `alta_snow.csv` file see the column contents and the units.\n", "\n", "- The 0th column is the Year at Season End\n", "- The 1st-6th column are the total snowfall in each month from November to April (in inches)\n", "- The 7th column is the Nov-Apr total snowfall (inches)\n", "\n", "Begins in the 1946 season and ends in 2021" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[ 949.96 1394.46 1328.42 1211.58 886.46 1628.14 1043.94 972.82\n", " 1198.88 1168.4 980.44 1421.13 980.44 1004.57 828.04 1019.81\n", " 1018.54 1437.64 1455.42 1099.82 1381.76 1217.93 1437.894 1165.86\n", " 1223.01 1185.164 1261.11 1512.824 1536.7 1116.33 798.83 1332.23\n", " 1493.52 1305.56 993.14 1767.84 1617.98 1888.49 1160.78 1521.46\n", " 969.772 1042.162 1477.01 1137.92 1473.708 1003.3 1652.016 1245.362\n", " 1893.316 1427.48 1521.714 1460.246 1164.336 1132.84 1193.038 1441.958\n", " 1014.476 1449.832 1406.144 1609.09 904.24 1661.16 1468.12 1092.2\n", " 1404.62 836.93 971.55 908.05 679.45 998.22 1347.47 731.52\n", " 1206.5 1056.64 949.96 ]\n", "Min: 679.5 Max: 1893.3\n" ] } ], "source": [ "#read the year of the Alta snowfall data\n", "year = np.genfromtxt('../data/alta_snow.csv', delimiter=',', usecols=0, skip_header=2)\n", "#read the seasonal total and convert from inches to cm\n", "snow = 2.54 * np.genfromtxt('../data/alta_snow.csv', delimiter=',', usecols=7, skip_header=2)\n", "#print out the data after converting it to cm\n", "print(snow)\n", "#what are the min and max values?\n", "print(\"Min: %.1f Max: %.1f\" % (np.min(snow),np.max(snow)))" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | Alta Snow (cm) | \n", "
---|---|
1947 | \n", "950.0 | \n", "
1948 | \n", "1394.5 | \n", "
1949 | \n", "1328.4 | \n", "
1950 | \n", "1211.6 | \n", "
1951 | \n", "886.5 | \n", "
1952 | \n", "1628.1 | \n", "
1953 | \n", "1043.9 | \n", "
1954 | \n", "972.8 | \n", "
1955 | \n", "1198.9 | \n", "
1956 | \n", "1168.4 | \n", "
1957 | \n", "980.4 | \n", "
1958 | \n", "1421.1 | \n", "
1959 | \n", "980.4 | \n", "
1960 | \n", "1004.6 | \n", "
1961 | \n", "828.0 | \n", "
1962 | \n", "1019.8 | \n", "
1963 | \n", "1018.5 | \n", "
1964 | \n", "1437.6 | \n", "
1965 | \n", "1455.4 | \n", "
1966 | \n", "1099.8 | \n", "
1967 | \n", "1381.8 | \n", "
1968 | \n", "1217.9 | \n", "
1969 | \n", "1437.9 | \n", "
1970 | \n", "1165.9 | \n", "
1971 | \n", "1223.0 | \n", "
1972 | \n", "1185.2 | \n", "
1973 | \n", "1261.1 | \n", "
1974 | \n", "1512.8 | \n", "
1975 | \n", "1536.7 | \n", "
1976 | \n", "1116.3 | \n", "
... | \n", "... | \n", "
1992 | \n", "1003.3 | \n", "
1993 | \n", "1652.0 | \n", "
1994 | \n", "1245.4 | \n", "
1995 | \n", "1893.3 | \n", "
1996 | \n", "1427.5 | \n", "
1997 | \n", "1521.7 | \n", "
1998 | \n", "1460.2 | \n", "
1999 | \n", "1164.3 | \n", "
2000 | \n", "1132.8 | \n", "
2001 | \n", "1193.0 | \n", "
2002 | \n", "1442.0 | \n", "
2003 | \n", "1014.5 | \n", "
2004 | \n", "1449.8 | \n", "
2005 | \n", "1406.1 | \n", "
2006 | \n", "1609.1 | \n", "
2007 | \n", "904.2 | \n", "
2008 | \n", "1661.2 | \n", "
2009 | \n", "1468.1 | \n", "
2010 | \n", "1092.2 | \n", "
2011 | \n", "1404.6 | \n", "
2012 | \n", "836.9 | \n", "
2013 | \n", "971.6 | \n", "
2014 | \n", "908.1 | \n", "
2015 | \n", "679.5 | \n", "
2016 | \n", "998.2 | \n", "
2017 | \n", "1347.5 | \n", "
2018 | \n", "731.5 | \n", "
2019 | \n", "1206.5 | \n", "
2020 | \n", "1056.6 | \n", "
2021 | \n", "950.0 | \n", "
75 rows × 1 columns
\n", "