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 testingdata/MSM121_054_1db.cnv- Real CTD data from North Atlantictests/- Automated tests that run when you submitrequirements.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).
Navigate to your messfern folder and activate virtual environment:
cd ~/messfern source .venv/bin/activate # Linux/macOS # OR for Windows: # .\.venv\Scripts\Activate.ps1
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
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
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.ipynbin VS Code
Complete the exercise by filling in code where you see:
# YOUR CODE HERE raise NotImplementedError()
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.
Open Codespace:
Go to your assignment repository on GitHub
Click the green
<> CodebuttonSelect “Codespaces” tab → “Create codespace on main”
Setup environment:
Wait for Codespace to initialize
Open terminal and install dependencies:
pip install -r requirements.txt
Start working:
Navigate to
src/assignment.ipynbSelect Python kernel when prompted
Complete the exercise by filling in
# YOUR CODE HEREsections
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 HEREandraise NotImplementedError()
Completion Steps#
Update student information (first cell) with your name, date, and student ID.
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
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
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
Stage your changes in the Source Control panel (Ctrl+Shift+G)
Add a commit message: “Complete Exercise 1”
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
Open the Source Control panel (Ctrl+Shift+G or click the source control icon on the left sidebar)
Review your changes by clicking on
src/assignment.ipynbin the Changes sectionStage your changes by clicking the + button next to
src/assignment.ipynbAdd a commit message in the text box: “Complete Exercise 1”
Click Commit button
Click Sync Changes to push to GitHub (or click the sync icon in the status bar)
Check Your Results#
Go to your repository on GitHub.com
Click the “Actions” tab to see automated test results
Green checkmark = All tests passed!
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.