{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"Assignment #3.ipynb","provenance":[],"collapsed_sections":["YuQ4b6_rvi_w","aIPIlgRwM4jb","1vTW3oy-vdni","sntgfyMLAzFw"],"toc_visible":true},"kernelspec":{"name":"python3","display_name":"Python 3"}},"cells":[{"cell_type":"markdown","metadata":{"id":"9KbWMJ-yMBh-"},"source":["# Assignment \\#3\n","\n","**Due:** Saturday, November 14th at 11:59 pm PT\n","\n","**Objective:**\n","This assignment will give you experience loading CSV and netCDF data files using NumPy, Pandas, and xarray, and plotting data using Matplotlib.\n","\n","**Instructions:**\n","1. This version of the assignment cannot be edited. To save an editable version, copy this Colab file to your individual class Google Drive folder (\"OCEAN 215 - Autumn '20 - {your name}\") by right clicking on this file and selecting \"Move to\".\n","2. Open the version you copied.\n","3. Complete the assignment by writing and executing text and code cells as specified. **To complete this assignment, you do not need any material beyond Lesson #11.** However, you may use material from beyond Lesson #11 if you wish as long as it has been discussed in a lesson or class, and is not prohibited in the question.\n","4. When you're finished and are ready to submit the assignment, simply save the Colab file (\"File\" menu –> \"Save\") before the deadline, close the file, and keep it in your individual class Google Drive folder.\n","5. If you need more time, please see the section \"Late work policy\" in the syllabus for details.\n","\n","**Honor code:** In the space below, you can acknowledge and describe any assistance you've received on this assignment, whether that was from an instructor, classmate (either directly or on Piazza), and/or online resources other than official Python documentation websites like docs.python.org or numpy.org. Alternatively, if you prefer, you may acknowledge assistance at the relevant point(s) in your code using a Python comment (#). You do not have to acknowledge OCEAN 215 class or lesson resources."]},{"cell_type":"markdown","metadata":{"id":"XkLuTQSuMqf6"},"source":["*Acknowledge assistance here:*"]},{"cell_type":"markdown","metadata":{"id":"YuQ4b6_rvi_w"},"source":["## Question 1 (6 points)\n","### **APIs for loading files using NumPy, Pandas, and xarray**\n","\n","*Useful resources:* Class #7 discussion on APIs, Lesson #7 on loading data using NumPy, Lesson #9 on Pandas and xarray"]},{"cell_type":"markdown","metadata":{"id":"3y_DcDGTwC7w"},"source":["Data is imperfect, and reading it in Python can require a lot of configuration to make sure that your data is being treated properly. Fortunately, the functions we use to read data all have optional arguments that can help us get exactly what we want from our files. These arguments are well-documented and available at each package's API website. Use the linked APIs for each of the three file-reading functions we have learned about in class to understand how to use certain arguments.\n","\n","1. Answer the following questions about arguments you can use in `np.genfromtxt` ([API linked here](https://numpy.org/doc/stable/reference/generated/numpy.genfromtxt.html)).\n","> **a.** What argument name allows you to skip lines at the beginning of the file that are not the data you want to read?\n",">\n","> **b.** What argument name allows you to select only certain columns to load data from?\n","\n","2. Answer the following questions about arguments you can use in `pd.read_csv()` ([API linked here](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html)).\n","> **a.** What argument name allows you to handle an unusual string used as a placeholder for missing data?\n",">\n","> **b.** What argument name tells Pandas to ignore lines or portions of lines beginning with a certain character?\n","\n","3. Answer the following questions about arguments you can use in `xr.open_dataset()` ([API linked here](http://xarray.pydata.org/en/stable/generated/xarray.open_dataset.html)).\n","> **a.** What argument name can be used to exclude a variable from being loaded?\n",">\n","> **b.** When using the `decode_times` argument, what object type is required as the input? What is the default value of `decode_times`?\n","\n","Write a print statement with the answer to each part.\n","\n","**Example:** What is the argument that specifies the separation character used in a file?\n"]},{"cell_type":"code","metadata":{"id":"IPLYv6Xl89nc","executionInfo":{"status":"ok","timestamp":1604207865655,"user_tz":420,"elapsed":191,"user":{"displayName":"Ethan C Campbell","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GjCBYTiuomqOsCakND1k_5wj0kYvFY53Jt7kunt=s64","userId":"11255944928409084259"}},"outputId":"f093b238-682f-4d37-9f48-edf7fc7675cc","colab":{"base_uri":"https://localhost:8080/"}},"source":["# Example:\n","print('Part 0a: delimiter')"],"execution_count":null,"outputs":[{"output_type":"stream","text":["Part 0a: delimiter\n"],"name":"stdout"}]},{"cell_type":"code","metadata":{"id":"YNmH_tnJ3Hb-"},"source":["# Your answers below:\n"],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"aIPIlgRwM4jb"},"source":["## Question 2 (13 points)\n","\n","### **Hydrographic profiles**\n","\n","*Useful resources:* Lesson #7 on loading data and plotting; Lesson #11 on advanced plotting"]},{"cell_type":"markdown","metadata":{"id":"cpASYyf1UAHt"},"source":["Research cruises are invaluable data sources for oceanographers. During a cruise, measurements of the water column known as CTD casts are conducted. In each cast, data are collected about the seawater salinity (from conductivity), temperature, and pressure (or depth) (hence \"CTD\") as well as chemical properties such as dissolved oxygen concentrations and chlorophyll fluorescence. \n","\n","Historically, hydrographic cruise programs such as CLIVAR, WOCE, and GO-SHIP have repeated measurements at [approximately the same locations](https://www.go-ship.org/RefSecs/goship_ref_secs.html) at intervals of a few years or decades. Repeating these cruises and casts enables us to see how the ocean changes over time!\n","\n","