Exercise 1 - Plot profiles in python#

📅 Due Date: November 10, 2025 at 18:00

Aim: To work with vertical profile data and make standard oceanographic calculations.

Context: This exercise uses real CTD data from R/V Maria S. Merian (North Atlantic, 2023) to demonstrate oceanographic data workflows.

Goals: At the end of this exercise, you will be able to:

  • Run python with jupyter notebooks and automated testing

  • Convert Sea-Bird CNV files to netCDF format using seasenselib

  • Calculate TEOS-10 parameters (Absolute Salinity, Conservative Temperature)

  • Create oceanographic profile plots

  • Generate Temperature-Salinity diagrams with density contours

  • Use real research data from the North Atlantic Ocean

Required Outputs: Four figures showing oceanographic data.


Step 1: Accept GitHub Classroom Assignment#

📝 Accept Assignment: Exercise 1 - CTD Profile Data

Click the link above to start the assignment. You may need to create a GitHub account or link your existing account to your name.

Your assignment repository will be automatically created with:

  • src/assignment.ipynb - Main exercise notebook with automated testing

  • data/MSM121_054_1db.cnv - Real CTD data from North Atlantic

  • tests/ - Automated tests that run when you submit

  • requirements.txt - All required Python packages

Step 2: Choose where to work on the assignment#

Option 1: Work on your own computer#

Prerequisites: Python 3.12 with VS Code setup complete (see Python Installation Guide).

  1. Navigate to your messfern folder and activate virtual environment:

    cd ~/messfern
    source .venv/bin/activate  # Linux/macOS
    # OR for Windows:
    # .\.venv\Scripts\Activate.ps1
    
  2. Clone your assignment repository:

    • On your assignment repository page, click the green “Code” button

    • Copy the entire URL and run this in your terminal:

    git clone https://github.com/ifmeo-courses/assignment-name-your-username.git
    cd assignment-name-your-username
    
    # Example for username "eleanorfrajka":
    git clone https://github.com/ifmeo-courses/exercise-1-ctd-eleanorfrajka
    cd exercise-1-ctd-eleanorfrajka
    
  3. Install dependencies: Now use the requirements.txt file from your cloned assignment (this contains all the packages needed for the exercise, unlike the simple test file from the setup guide):

    In your terminal (macOS Terminal app / Linux terminal / Windows PowerShell) with venv activated:

    pip install -r requirements.txt
    
  4. Open assignment folder in VS Code:

    • Launch VS Code

    • Go to File → Open Folder

    • Select your cloned assignment folder (inside ~/messfern/your-assignment-repo)

    • Open src/assignment.ipynb in VS Code

  5. Complete the exercise by filling in code where you see:

    # YOUR CODE HERE
    raise NotImplementedError()
    
  6. Test your work locally:

    python -m pytest tests/ -v
    

Option 2: GitHub Codespaces (if local isn’t working)#

No local installation required! Work directly in your browser.

  1. Open Codespace:

    • Go to your assignment repository on GitHub

    • Click the green <> Code button

    • Select “Codespaces” tab → “Create codespace on main”

  2. Setup environment:

    • Wait for Codespace to initialize

    • Open terminal and install dependencies:

    pip install -r requirements.txt
    
  3. Start working:

    • Navigate to src/assignment.ipynb

    • Select Python kernel when prompted

    • Complete the exercise by filling in # YOUR CODE HERE sections

  4. Test your work:

    python -m pytest tests/ -v
    

Tip

Automatic Testing: When you commit and push changes, GitHub Actions will automatically run tests and provide feedback in the “Actions” tab.

Step 3: Complete the Exercise#

The assignment notebook is structured with both instructional content and coding tasks.

Exercise Structure#

📝 Markdown cells contain instructions and explanations using Markdown syntax.

💻 Code cells contain Python code. You’ll encounter two types:

  • Completed examples - Run these to understand the workflow

  • Tasks for you - Look for # YOUR CODE HERE and raise NotImplementedError()

Completion Steps#

  1. Update student information (first cell) with your name, date, and student ID.

  2. Complete each coding section:

    • File Setup: Configure figure output directory

    • Data Loading: Convert CNV to netCDF using seasenselib

    • TEOS-10 Calculations: Compute Absolute Salinity and Conservative Temperature

    • Figure Creation: Generate 4 professional oceanographic plots

    • Analysis Questions: Interpret your results scientifically

  3. Key Python concepts you’ll learn:

    • Import statements: Loading packages (import matplotlib.pyplot as plt)

    • Variables: Storing data and file paths (figdir = '../figures/')

    • Functions: Calling oceanographic tools (gsw.conversions.SA_from_SP(...))

    • Plotting: Creating figures with matplotlib

  4. Oceanographic workflow:

    • Convert Sea-Bird sensor data to standard format

    • Calculate modern oceanographic parameters using TEOS-10

    • Visualize vertical profiles and water mass properties

    • Interpret T-S diagrams with density contours

Tip

Testing as you go: Each major section has test cells that verify your work automatically. Use these to check progress before moving on.

Quick Python Reference for This Exercise#

🔍 Getting help when stuck:

help(gsw.conversions.SA_from_SP)  # Learn about TEOS-10 functions
help(ctd_ds.plot)                 # How to plot xarray data
print(ctd_ds)                     # See your CTD dataset structure

📊 Understanding CTD data:

print(ctd_ds.data_vars)           # What measurements do we have?
print(ctd_ds.mean())              # Mean values of all variables
print(f"Depth range: {ctd_ds.pressure.min().values:.1f} to {ctd_ds.pressure.max().values:.1f} dbar")

Tip

Need more Python help? Check out the comprehensive Python Tips & Troubleshooting guide with debugging strategies, data exploration techniques, and solutions to common errors.

💡 Success Strategies for Your First Exercise#

🎯 Before You Start:

  • Make sure your Python environment has all packages installed

  • Test that you can open and run the first few notebook cells

  • Don’t worry if you don’t understand everything - focus on completing the tasks, then try to parse the code

🔬 While Working:

  • Read each cell carefully before running it

  • Look at the outputs - they tell you if things worked

  • Don’t skip the test cells - they catch problems early

  • Ask for help if you’re stuck for more than 15 minutes

🆘 Common First-Timer Issues:

# If CNV file doesn't load:
import os
print("Looking for:", os.path.abspath('data/MSM121_054_1db.cnv'))
print("File exists:", os.path.exists('data/MSM121_054_1db.cnv'))

# If plots don't appear:
%matplotlib inline             # Force plots to show in notebook

# If calculations give weird results:
print("Check your units and data ranges!")

Step 4: Submission and Grading#

Automatic Testing#

Your work is tested automatically when you submit! The assignment includes:

  • File creation checks - All 4 required figures generated

  • Code functionality - CNV conversion, TEOS-10 calculations working

  • Data validation - Proper variable creation and data loading

  • Template completion - No placeholder text remaining

Submit Your Work#

Option A: GitHub Codespaces

  1. Stage your changes in the Source Control panel (Ctrl+Shift+G)

  2. Add a commit message: “Complete Exercise 1”

  3. Click “Commit” → “Sync Changes”

Option B: Local Computer

git add src/assignment.ipynb
git commit -m "Complete Exercise 1"
git push origin main

Option C: VS Code Source Control

  1. Open the Source Control panel (Ctrl+Shift+G or click the source control icon on the left sidebar)

  2. Review your changes by clicking on src/assignment.ipynb in the Changes section

  3. Stage your changes by clicking the + button next to src/assignment.ipynb

  4. Add a commit message in the text box: “Complete Exercise 1”

  5. Click Commit button

  6. Click Sync Changes to push to GitHub (or click the sync icon in the status bar)

Check Your Results#

  1. Go to your repository on GitHub.com

  2. Click the “Actions” tab to see automated test results

  3. Green checkmark = All tests passed!

  4. Red X = Review failed tests and fix issues

Grading#

This assignment uses a tiered PASS system:

PASS (Basic Requirements):

  • All required files created (NetCDF files, 4 figures)

  • All automated tests pass (data valid, figures contain content)

  • Personal information completed

  • Code executes without errors

🌟 PASS PLUS (Professional Quality): All PASS requirements PLUS:

  • Sensible legends and titles on all figures

  • Good choices for figure plotting (appropriate aspect ratios, professional color scales, clear line styles)

  • All axes have proper labels with units (e.g., “Temperature (°C)”, “Pressure (dbar)”, “Salinity (g/kg)”)

  • Thoughtful formatting (readable fonts, appropriate figure sizes)

  • Professional T-S diagram styling with proper density contour labels

FAIL Conditions:

  • Missing required outputs

  • Test failures (invalid data, empty figures)

  • Code execution errors

  • Template placeholders not replaced

Tip

Multiple attempts allowed! You can revise and resubmit until the deadline. Each commit triggers new automated tests.