Assignment 3 - Numpy and Matplotlib

Due Thursday September 27

1 Creating and Manipulating Arrays

First import numpy and matplotlib

In [ ]:
 

1.1. Create two 2D arrays representing coordinates x, y on the cartesian plan

Both should cover the range (-2, 2) and have 100 points in each direction

In [ ]:
 

1.2. Visualize each 2D array using pcolormesh

Use the correct coordiantes for the x and y axes. Provide axis labels for all of your plots in this assignment.

In [ ]:
 

1.3 From your cartesian coordinates, create polar coordinates $r$ and $\varphi$

Refer to the wikipedia page for the conversion formula. You will need to use numpy's arctan2 function. Read its documentation.

In [ ]:
 

1.4. Visualize $r$ and $\varphi$ as functions of $x$ and $y$

In [ ]:
 

1.5 Define the function $f = \cos^2(4r) + \sin^2(4\varphi)$

And plot it as a function of $x$ and $y$

In [ ]:
 

1.6 Plot the mean of f with respect to the x axis

as a function of y

In [ ]:
 

1.7 Plot the mean of f with respect to the y axis

as a function of x

In [ ]:
 

1.8 Plot the mean of $f$ with respect to $r$ (worth 3 points)

This is hard. You will need to define a discrete range of $r$ values and then figure out how to average $f$ within the bins defined by your $r$ grid. There are many different ways to accomplish this.

In [ ]:
 
In [ ]:
 

Part 2: Analyze ARGO Data

1.1 Use the shell command wget to download an example ARGO float profile from the North Atlantic.

The data file's url is http://www.ldeo.columbia.edu/~rpa/argo_float_4901412.npz

In [ ]:
 

1.2 Load the data file

In [ ]:
 

1.3 Extract the temperature, pressure and salinity arrays to arrays T, S, P and masking out invalid data (the nan values from missing points).

In [ ]:
 

1.4 Extract the date, lat, lon, and level arrays.

In [ ]:
 

1.5 Note the shapes of T, S and P compared to these arrays. How do they line up?

In [ ]:
 

1.6 Load the necessary package for plotting using pyplot from matplotlib.

In [ ]:
 

1.7 Make a 1 x 3 array of plots for each column of data in T, S and P.

The vertical scale should be the levels data. Flip the veritcal axis direction so that levels increase downward on the plot. Each plot should have a line for each column of data. It will look messy. Make sure you label the axes and put a title on each subplot.

In [ ]:
 

1.8 Compute the mean and standard deviation of each of T, S and P at each depth in level.

In [ ]:
 

1.9 Now make a similar plot, but show only the mean T, S and P at each depth. Show error bars on each plot using the standard deviations.

Again, make sure you label the axes and put a title on each subplot.

In [ ]:
 

1.10 Compute the mean and standard deviation of each of T, S and P for each time in date.

In [ ]:
 

1.11 Plot the mean T, S and P for each entry in time, now on a 3 x 1 subplot grid with time on the horizontal axis. Show error bars on each plot using the standard deviations.

In [ ]:
 

1.12 Create a scatter plot of the positions of the ARGO float data. Color the positions by the date. Add a grid overlay.

Don't forget to label the axes!

In [ ]: