Python - making a \(\theta\)-S diagram#

Aim: Create at \(\theta\)-S diagram with density contoured.

Data: Use the same profile that you started with for python 2.

Directions: Create an *.ipynb and 1 figures. This will form your answer to a question on the exercise sheet.


Import your packages#

You will likely need xarray, matplotlib, numpy, and gsw.

Create an *.ipynb containing the commands for this assignment, or rename this file, e.g., computing-regoz-3-<Lastname>.ipynb

# Your code here
import numpy as np

Open the notebook in jupyter#

Copy over the required lines from last time which allow you to load the CTD profile data.

# Your code here
filepath = ''

Make a \(\theta-S\) plot#

Recall that a \(\theta-S\) plot should have salinity on the x-axis and temperature (as potential or conservative temperature) on the y-axis.

Hint

Above, it specifies “potential” or “conservative” temperature. This is a hint to you that you should be converting your data using the Gibb’s Seawater Toolbox gsw-python to create variables for “conservative temperature” and “absolute salinity” rather than using the default “temperature” which is in situ and includes the effect of pressure, and “psal” or practical salinity.

You may want to reference your code from last time, but change the two inputs you give to plt.plot to correspond to your new axes.

See also

Cheatsheets for matplotlib

# Your code here

Add density#

Normally, a \(\theta-S\) diagram is not useful without adding density contours. However, you don’t just need the density data. In order to create a contour plot, you need a 2-dimensional matrix which provides the density for each absolute salinity and conservative temperature that can be found within your plot limits.

Create a vector for temperature and for salinity#

  • Try looking at help(np.linspace) for ideas.

# Your code here

Now make a 2-dimensional matrix using the vectors#

  • Try looking at help(np.meshgrid) for ideas

# Your code here

Calculate density from the matrix#

Using the GSW toolbox, calculate density (as e.g., \(\sigma_2\)) at each location in your temperature-salinity plot.

See for example help(gsw.density.sigma2) to see how to calculate it.

Try typing gsw.density. and then hitting the “tab” key to see what other density calculations are available.

Add the density as contours#

  1. Contour the density matrix on the same axes where you’ve plotted the T-S diagram.

  1. Add contour labels.

  2. Spend a little time making your figure more legible: https://matplotlib.org/cheatsheets/_images/cheatsheets-2.png

# Your code here