Due: Saturday, October 31 at 11:59 pm PT
Objective: This assignment will give you experience using lists, logical operations, control flow (for loops and if statements), and NumPy arrays and functions.
Instructions:
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.
Acknowledge assistance here:
Useful resources: Lesson #3 on list functions and indexing; Lesson #4 on for loops and list comprehensions
For this question, you are given a list called decimals that contains 5 floating-point numbers:
Please create a new list in which these decimal fractions have been first converted to percents (i.e. between 0-100%), then rounded to 1 decimal place, and finally converted to strings with a percent sign (%) on the end. In other words, your final result should be the following list:
This question has two parts, which should both result in a list identical to percents above:
To round a number, you should use Python's round() function, which takes two arguments: the number, and the number of decimal places to round to. For example, round(23.4173, 2) gives 23.42 as the result.
# Keep this starting line of code:
decimals = [0.0003,0.2342,0.5629,0.6376,0.9731]
# Write your code for Part 1 here:
# Write your code for Part 2 here:
Image: Bathymetry of the seafloor around Axial Seamount (source: Wikipedia, originally from NOAA/PMEL).
Useful resources: Lesson #3 on list indexing; Lesson #4 on for loops and if statements; Lesson #7 on basic plots
During the eruption of a submarine volcano, the seafloor deflates rapidly as magma is expelled into the ocean. Bottom pressure gauges use pressure to measure depth (as you might recall from Assignment #1, pressure is nearly equivalent to depth in the ocean), and so these gauges can detect this deflation. After an eruption, the seafloor slowly inflates and rises as magma accumulates in preparation for the next eruption.
Axial Seamount is an active submarine volcano offshore of the Oregon coast. It last erupted in 2015. Below, we provide a time series of monthly bottom pressure data released by the Ocean Observatories Initiative (OOI) from August 15, 2014 to December 15, 2019, with measurements taken on the 15th day of each month. Times are specified in "fractional years." For example, July 1, 2020 is approximately 2020.5 in fractional years.
Please write only one for loop for this entire question. Do not use NumPy. Organize your code for Parts 1-3 at the top, followed by the print() statements for your answers, followed by your code for the Part 4 plot at the bottom. Write code to answer the following questions:
a. Calculate the actual seafloor drop during the eruption. Round to 1 decimal place (see Question 1 for details on round()).
b. Identify the two measurement times (in fractional years) immediately before and after the eruption.
c. Find the seafloor depth measurement immediately before the eruption. Round to 1 decimal place.
a. How much has the seafloor inflated between the measurement immediately after the eruption and the most recent measurement in this data?
b. How much time has elapsed between these two measurements?
Calculate the approximate rate of seafloor inflation using the values from Part 2. Express your answer in units of centimeters per month, rounded to 1 decimal place.
Use Matplotlib to create a plot of the data with time on the x-axis and depth on the y-axis. Shallower depths should point in the positive y-direction (you will need to search the Matplotlib API to find out how to do this). Format and label your plot such that it looks as similar to this plot as possible:
# Keep these lines of code:
#
# Axial Seamount Central Caldera bottom pressure gauge data
# (times in fractional years; depths in meters)
times = [2014.625,2014.708,2014.792,2014.875,2014.958,2015.042,2015.125,2015.208,2015.292,2015.375,2015.458,2015.542,2015.625,2015.708,2015.792,2015.875,2015.958,2016.042,2016.125,2016.208,2016.292,2016.375,2016.458,2016.542,2016.625,2016.708,2016.792,2016.875,2016.958,2017.042,2017.125,2017.208,2017.292,2017.375,2017.458,2017.542,2017.625,2017.708,2017.792,2017.875,2017.958,2018.042,2018.125,2018.208,2018.292,2018.375,2018.458,2018.542,2018.625,2018.708,2018.792,2018.875,2018.958,2019.042,2019.125,2019.208,2019.292,2019.375,2019.458,2019.542,2019.625,2019.708,2019.792,2019.875,2019.958]
depths = [1510.24,1510.19,1510.14,1510.08,1510.04,1509.96,1509.93,1509.87,1509.83,1512.23,1512.11,1512.04,1511.96,1511.89,1511.79,1511.7,1511.64,1511.57,1511.54,1511.5,1511.47,1511.47,1511.4,1511.35,1511.33,1511.32,1511.31,1511.26,1511.21,1511.19,1511.14,1511.12,1511.05,1511.0,1511.06,1511.04,1511.01,1510.98,1510.93,1510.87,1510.87,1510.91,1510.86,1510.77,1510.75,1510.7,1510.67,1510.68,1510.64,1510.59,1510.56,1510.54,1510.45,1510.51,1510.41,1510.42,1510.39,1510.37,1510.4,1510.42,1510.41,1510.38,1510.33,1510.3,1510.26]
# Your code for Parts 1-3:
# Your print() statements for Parts 1-3:
# Your code to make the plot for Part 4:
Image: The boundary between air and sea as seen from a research vessel.
Useful resources: Lesson #2 on mathematical operations, Lesson #3 on list indexing; Lesson #4 on for loops and if statements; Lesson #5 on NumPy arrays and functions
Background information:
A body of water will lose heat when exposed to cooler air, and it will lose heat faster when there is airflow over it. Think about how you might cool a cup of coffee or tea by blowing on it. The ocean behaves similarly.
"Air-sea heat flux" refers to the rate of this exchange of heat between the ocean surface and atmosphere. When the ocean is warmer than the air, the ocean loses heat. When the ocean is cooler than the air, the ocean gains heat. This exchange happens more rapidly when wind speeds are higher. Here is the equation that describes this heat flux. Notice that this rate of heat exchange, $H$, becomes larger if the wind speed, $U_{10}$, becomes larger:
$H = \rho_a \cdot c_p \cdot C_h \cdot U_{10} \cdot (T_a - T_s)$
The Irminger Sea in the North Atlantic, near Greenland, experiences some of the most extreme air-sea heat fluxes in the world. Below, we provide three lists containing monthly-average data for $T_a$, $T_s$, and $U_{10}$ from 2018 in the Irminger Sea. Here is a plot showing these monthly data:
Questions:
Answer each question below using a print() statement, e.g. "Part 1: The air-sea heat flux in October is <X> W/m^2." For these parts, you may use for loops, but not NumPy:
For these next calculations, you may use NumPy, but not for loops:
# Keep these lines of code:
#
# Monthly ERA-Interim data for the North Atlantic (Irminger Sea at 59.5°N, 40.0°W) from 2018
months = ['January','February','March','April','May','June','July','August','September','October','November','December']
U_10 = [12.91,14.63,8.58,9.32,10.88,7.73,7.15,8.09,8.49,9.77,11.34,9.14]
T_a = [0.55,-1.95,1.52,2.81,2.71,5.13,7.06,8.19,7.08,4.56,3.68,2.61]
T_s = [4.18,3.86,3.72,3.91,4.35,5.29,6.76,8.21,7.37,6.24,5.09,4.42]
# Your code for Part 1:
# Your code for Part 3:
# Your code for Part 4:
# Your code for Part 6:
# Your code for Part 7:
# Your code for Part 8:
# Your code for Part 9:
# Your code for Part 10:
# Your print() statements for Parts 1-6 and 8-10:
Image: The research vessel R/V Polarstern.
Useful resources: Lesson #5 on NumPy arrays and functions, Lesson #6 on multidimensional arrays and datetime objects
During an oceanographic cruise, research vessels will often have an instrument called a thermosalinograph taking temperature measurements throughout the duration of the cruise. To get the most accurate picture of the surrounding conditions, there are usually 2 different temperature sensors in the water, situated at different depths. For this problem you are provided two NumPy arrays of sample data from a cruise in 2003 aboard the R/V Polarstern.
Data arrays:
T_data contains 4 columns (longitude, latitude, temperature [˚C] at 5 meters, and temperature [˚C] at 11 meters)
time_data contains a single dimension with strings containing the date/time information for the temperature measurements with the format %Y-%m-%d %H:%M:%S
Questions:
Answer each question below using a print() statement, e.g. "Part 1a: The measurements were taken over <X> hours."
a. Over how many hours were these measurements taken?
b. What is the frequency of these measurements (e.g. how often did measurements occur)? You can assume that the measurements were all collected at the same frequency.
Find the maximum and minimum values of latitude and longitude in T_data.
Create and print a new 1-dimensional array containing temperatures averaged between 5 meters and 11 meters for each measurement time. If ocean temperatures vary linearly between these two depths, what is the approximate depth in the ocean that these average temperatures represent?
Reshape the average temperature array from Part 3 into a 2-dimensional array with the same number of rows as the number of hours that these measurements span (your solution from Part 1a). Calculate and print a new array that represents the average temperature in each row of the reshaped array. (Notice that this is equivalent to the hourly average temperature!)
Make sure to run the cell below before running your solution cell. Please do not alter the data arrays. Write your code and answers in the cell at the bottom, not this cell.
# Do not alter the code in this cell
import numpy as np
# Data in this array consists of 4 columns:
# Latitude, longitude, T at 5 m (˚C), T at 11 m (˚C)
T_data = np.array([[51.7439,2.4476,14.726,14.736],[51.7147,2.4071,14.746,14.756],[51.6851,2.3664,14.796,14.816],[51.6561,2.3254,14.856,14.866],
[51.627,2.2854,14.866,14.876],[51.5981,2.2454,14.896,14.916],[51.5689,2.2055,14.936,14.946],[51.5404,2.1661,14.946,14.956],
[51.5122,2.127,14.936,14.946],[51.4831,2.087,14.956,14.966],[51.4545,2.0478,15.016,15.026],[51.4271,2.01,15.106,15.116],
[51.3959,1.9686,15.136,15.146],[51.3635,1.9252,15.086,15.086],[51.3304,1.8848,14.826,14.826],[51.2986,1.8437,14.616,14.626],
[51.2679,1.8036,14.527,14.547],[51.2371,1.7642,14.636,14.646],[51.207,1.7255,14.666,14.686],[51.1782,1.6886,14.766,14.786],
[51.1497,1.6519,14.736,14.756],[51.1215,1.6156,14.716,14.726],[51.0984,1.581,14.656,14.666],[51.077,1.5485,14.567,14.577],
[51.0586,1.5198,14.467,14.477],[51.0354,1.4841,14.247,14.257],[51.0088,1.4431,14.117,14.147],[50.9829,1.4033,14.307,14.327],
[50.957,1.3635,14.337,14.347],[50.9314,1.324,14.307,14.327],[50.9077,1.2801,14.327,14.337],[50.8867,1.2301,14.207,14.217],
[50.8654,1.1789,14.157,14.177],[50.8436,1.1266,14.167,14.187],[50.8213,1.0736,14.137,14.157],[50.7988,1.0196,14.257,14.277],
[50.776,0.9649,14.437,14.447],[50.7527,0.9096,14.626,14.646],[50.7295,0.8538,14.796,14.806],[50.7059,0.7976,14.836,14.846],
[50.6826,0.7407,14.806,14.816],[50.6626,0.6806,14.806,14.816],[50.6388,0.6227,14.826,14.836],[50.615,0.5641,14.826,14.836],
[50.6005,0.4986,14.786,14.796],[50.5881,0.4317,14.786,14.786],[50.5756,0.3649,14.756,14.766],[50.5632,0.2975,14.826,14.836],
[50.5509,0.2306,14.886,14.896],[50.5386,0.1641,15.006,15.016],[50.5263,0.0974,15.176,15.186],[50.5138,0.0313,15.196,15.196],
[50.5018,-0.0345,15.186,15.196],[50.4897,-0.0997,15.286,15.296],[50.4778,-0.1644,15.346,15.356],[50.466,-0.2284,15.386,15.396],
[50.454,-0.2916,15.376,15.386],[50.4426,-0.3536,15.366,15.376],[50.4313,-0.4153,15.416,15.416],[50.4168,-0.4275,15.456,15.466],
[50.409,-0.4882,15.436,15.446],[50.4017,-0.5474,15.466,15.476],[50.3933,-0.6047,15.426,15.426],[50.3796,-0.6583,15.396,15.406],
[50.3668,-0.7114,15.396,15.406],[50.3524,-0.763,15.396,15.406],[50.3396,-0.8151,15.396,15.406],[50.3288,-0.8668,15.476,15.486],
[50.3223,-0.9188,15.556,15.566],[50.316,-0.97,15.616,15.636],[50.3092,-1.0191,15.696,15.706],[50.3024,-1.0675,15.746,15.756]])
# Data in this array has only one dimension:
# Date/Time (Y-m-d H:M:S) string
time_data = np.array(['2003-10-23 06:25:00','2003-10-23 06:35:00',
'2003-10-23 06:45:00','2003-10-23 06:55:00','2003-10-23 07:05:00',
'2003-10-23 07:15:00','2003-10-23 07:25:00','2003-10-23 07:35:00',
'2003-10-23 07:45:00','2003-10-23 07:55:00','2003-10-23 08:05:00',
'2003-10-23 08:15:00','2003-10-23 08:25:00','2003-10-23 08:35:00',
'2003-10-23 08:45:00','2003-10-23 08:55:00','2003-10-23 09:05:00',
'2003-10-23 09:15:00','2003-10-23 09:25:00','2003-10-23 09:35:00',
'2003-10-23 09:45:00','2003-10-23 09:55:00','2003-10-23 10:05:00',
'2003-10-23 10:15:00','2003-10-23 10:25:00','2003-10-23 10:35:00',
'2003-10-23 10:45:00','2003-10-23 10:55:00','2003-10-23 11:05:00',
'2003-10-23 11:15:00','2003-10-23 11:25:00','2003-10-23 11:35:00',
'2003-10-23 11:45:00','2003-10-23 11:55:00','2003-10-23 12:05:00',
'2003-10-23 12:15:00','2003-10-23 12:25:00','2003-10-23 12:35:00',
'2003-10-23 12:45:00','2003-10-23 12:55:00','2003-10-23 13:05:00',
'2003-10-23 13:15:00','2003-10-23 13:25:00','2003-10-23 13:35:00',
'2003-10-23 13:45:00','2003-10-23 13:55:00','2003-10-23 14:05:00',
'2003-10-23 14:15:00','2003-10-23 14:25:00','2003-10-23 14:35:00',
'2003-10-23 14:45:00','2003-10-23 14:55:00','2003-10-23 15:05:00',
'2003-10-23 15:15:00','2003-10-23 15:25:00','2003-10-23 15:35:00',
'2003-10-23 15:45:00','2003-10-23 15:55:00','2003-10-23 16:05:00',
'2003-10-23 16:15:00','2003-10-23 16:25:00','2003-10-23 16:35:00',
'2003-10-23 16:45:00','2003-10-23 16:55:00','2003-10-23 17:05:00',
'2003-10-23 17:15:00','2003-10-23 17:25:00','2003-10-23 17:35:00',
'2003-10-23 17:45:00','2003-10-23 17:55:00','2003-10-23 18:05:00',
'2003-10-23 18:15:00','2003-10-23 18:25:00'])