From c25c6b17c0bae38a7115f6dff48db89d87ad690d Mon Sep 17 00:00:00 2001 From: "Frajka-Williams, Eleanor" <eleanor.frajka@uni-hamburg.de> Date: Wed, 29 Nov 2023 12:59:38 +0000 Subject: [PATCH] Starter file for the Messmethoden Uebungen. --- Messmethoden_U6/ctd-pycnv-starter.ipynb | 205 ++++++++++++++++++++++++ 1 file changed, 205 insertions(+) create mode 100644 Messmethoden_U6/ctd-pycnv-starter.ipynb diff --git a/Messmethoden_U6/ctd-pycnv-starter.ipynb b/Messmethoden_U6/ctd-pycnv-starter.ipynb new file mode 100644 index 0000000..f351b9a --- /dev/null +++ b/Messmethoden_U6/ctd-pycnv-starter.ipynb @@ -0,0 +1,205 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Importing the required module for plotting data\n", + "import gsw # See https://teos-10.github.io/GSW-Python/\n", + "import pycnv # See https://pypi.org/project/pycnv/\n", + "import pylab as pl\n", + "\n", + "# Defining the file path where the CNV file is located\n", + "# Choose either Seepraktikum 2023 data: https://bit.ly/3ut6NtV\n", + "file_path = 'Seepraktikum_2023/SBE19plus_01907321_2023_05_12_Cast36_loop_window.cnv'\n", + "# Or MSM121 data: https://bit.ly/3Ri19E2\n", + "file_path = 'msm121_profiles/MSM121_015_1db.cnv'\n", + "# Or MSM121 to-yo profiles: https://bit.ly/3GlQh1D\n", + "# file_path = 'MSM121_060/MSM121_060_001_05db.cnv'\n", + "\n", + "# Load the data from the given file_path (may need to update to match your file location)\n", + "cnv = pycnv.pycnv(file_path)\n", + "\n", + "# Print some info to the screen\n", + "print('Test if we are in the Baltic Sea (usage of different equation of state): ' + str(cnv.baltic))\n", + "print('Position of cast is: Longitude:', cnv.lon,'Latitude:',cnv.lat)\n", + "print('Time of cast was:', cnv.date)\n", + "print('Number of sensor entries (len(cnv.data.keys())):',len(cnv.data.keys()))\n", + "print('Names of sensor entries (cnv.data.keys()):',cnv.data.keys())\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Get data of entry\n", + "key0 = list(cnv.data.keys())[0]\n", + "data0 = cnv.data[key0]\n", + "\n", + "# Get derived data:\n", + "keyd0 = list(cnv.cdata.keys())[0]\n", + "datad0 = cnv.cdata[keyd0]\n", + "# Get unit of derived data\n", + "datad0_unit = cnv.cunits[keyd0]\n", + "\n", + "# Standard names are mapped to\n", + "# cnv.p,cnv.CT,cnv.T,cnv.SP,cnv.oxy\n", + "# units are _unit, e.g. cnv.p_unit\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Plot standard parameters\n", + "pl.figure(1)\n", + "pl.clf()\n", + "pl.subplot(1,2,1)\n", + "pl.plot(cnv.SA,cnv.p) # Note that pycnv has done the TEOS-10 conversion to SA for you using gsw\n", + "pl.xlabel('Absolute salinity [' + cnv.SA_unit + ']')\n", + "pl.ylabel('Pressure [' + cnv.p_unit + ']')\n", + "pl.gca().invert_yaxis() # Question: What happens if you comment out this line?\n", + "\n", + "\n", + "# Step 1a: Add grid lines\n", + "\n", + "# Step 1b: Limit the top of the plot to the surface (p=0)\n", + "\n", + "# Step 1c: Add a second plot for temperature, to the right of the salinity plot\n", + "\n", + "# Step 1d: Add a title to your figure, perhaps the station number, latitude and longitude\n", + "\n", + "# Step 1e: Print the figure to a *png file " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Plotting profile data on the same axes\n", + "pl.subplot(1,2,2)\n", + "pl.plot(cnv.oxy,cnv.p)\n", + "pl.plot(cnv.cdata['oxy0'],cnv.p)\n", + "pl.plot(cnv.cdata['oxy1'],cnv.p)\n", + "pl.xlabel('Oxygen [' + cnv.oxy_unit + ']')\n", + "pl.ylabel('Pressure [' + cnv.p_unit + ']')\n", + "pl.gca().invert_yaxis()\n", + "\n", + "# Step 2a-e: Clean up the figure as above\n", + "\n", + "# Step 2f (optional): Compute the apparent oxygen utilisation \n", + "# See: https://en.wikipedia.org/wiki/Apparent_oxygen_utilisation\n", + "# you will need to calculate oxygen solubility (see the gsw documentation for O2_sol)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Make a T-S diagram\n", + "pl.figure(1)\n", + "pl.clf()\n", + "pl.subplot(1,2,1)\n", + "pl.plot(cnv.SA,cnv.CT)\n", + "pl.xlabel('Absolute salinity [' + cnv.SA_unit + ']')\n", + "pl.ylabel('Conservative temperature [' + cnv.CT_unit + ']')\n", + "\n", + "# Step 3a: Add contours of potential density\n", + "# - Hint, you will need to create a vector of temperature and salinity spanning at \n", + "# least the ranges in the profile\n", + "# - You will then need to use these gridded vectors to calculate potential density using the gsw toolbox\n", + "\n", + "\n", + "# Step 3b: Add contour labels for the density\n", + "\n", + "# Step 3c: Add a title\n", + "\n", + "# Step 3d: Print the figure as a *png" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Challenge 4: Load multiple cnv files into python.\n", + "\n", + "# Step 4a: Plot a map of the stations\n", + "\n", + "# Step 4b (optional): Add bathymetry \n", + "# - see e.g. GEBCO https://www.gebco.net/data_and_products/gridded_bathymetry_data/\n", + "# - or ETOPO1. Note these files are big when full resolution and global.\n", + "# You will probably want to slice/prepare the data in a separate python notebook/file\n", + "\n", + "# Step 4c: Load multiple stations into python\n", + "# - Option one: Keep them all as separate variables (cnv1, cnv2, cnv3, etc)\n", + "# - Option two: Combine them into a multidimensaionl np.ndarray\n", + "# In order to combine them, they will need to be interpolated onto the same \n", + "# pressure grid (suggested 1 dbar grid). \n", + "\n", + "# Step 4d: Plot multiple temperature profiles on a single set of axes (see Step 1)\n", + "\n", + "# Step 4e: Repeat for salinity\n", + "\n", + "# Step 4f: Repeat for T-S diagrams (see Step 3)\n", + "\n", + "# Noting the data type that cnv is using may help:\n", + "type(cnv.SA)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Challenge 5: Only works with option two in challenge 4.\n", + "\n", + "# Step 5a: Choose stations that are in a line (plot a map)\n", + "\n", + "# Step 5b: Calculate buoyancy frequency N^2 = db/dz. See gsw.Nsquared\n", + "# - Plot this. Note where it is large / small.\n", + "\n", + "# Step 5b: Calculate distance between CTD profiles\n", + "\n", + "# Step 5c: Calculate buoyancy b = -g\\rho/\\rho_0. \n", + "# - See e.g. Clement et al. 2023: https://doi.org/10.1175/JPO-D-22-0178.1\n", + "\n", + "# Step 5d: Calculate the density gradient db/dx where x is the distance between stations\n", + "\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} -- GitLab