CTD profiles - minimal example¶
📥 Download: CTD profiles - minimal example.ipynb
In this notebook
Load multiple
.cnvfiles containing shipboard profiles from a SeaBird CTD.Quick overview and basic plots.
# Import the ctd module from kval.data
from kval.data import ctd
# Set the plotting backed so we can interact with figures
%matplotlib widget
/home/docs/checkouts/readthedocs.org/user_builds/kval/conda/latest/lib/python3.12/site-packages/kval/__init__.py:9: UserWarning: NOTE_ Matplotlib >=3.9 may *in some cases* break some ipympl interactive plots. If you experience trouble with plots not displaying correctly, try downgrading to matplotlib 3.8.x.
warnings.warn(
Load data from .cnv files into a single xarray Dataset¶
Specify a directory cnv_dir where we have .cnv files collected from a SBE CTD.
NOTE: Loading the data in this manner will load all the .cnv files in the directory. Make sure cnv_dir/ only contains the files you want to include.
NOTE: In this case, the .cnv files contain pressure-gridded data. It is also possible to load ungridded profiles - profiles will then be pressure gridded within kval.
cnv_dir = ('../../../../tests/test_data/'
'sbe_files/sbe911plus/atwain_cruise_ctds/')
Load all .cnv files into a single xarray
Dataset - the object we will work with and ultimately export to netCDF.
ds = ctd.ctds_from_cnv_dir(cnv_dir)
Found 3 .cnv files in "../../../../tests/test_data/sbe_files/sbe911plus/atwain_cruise_ctds/".
NOTE: It seems the input data already binned -> using preexisting binning.
/home/docs/checkouts/readthedocs.org/user_builds/kval/conda/latest/lib/python3.12/site-packages/kval/data/ship_ctd_tools/_ctd_tools.py:168: FutureWarning: In a future version of xarray the default value for join will change from join='outer' to join='exact'. This change will result in the following ValueError: cannot be aligned with join='exact' because index/labels/sizes are not equal along these coordinates (dimensions): 'PRES' ('PRES',) The recommendation is to set join explicitly for this case.
N = xr.concat([N, n], dim = 'TIME', data_vars="all")
The xarray Dataset ds should contain 1-D and 2-D fields gridded on pressure (PRES) and time (TIME).
When available, metadata such as serial numbers and calibration data have been parsed into variable attributes. The PROCESSING variable should include a description of the processing steps and a python script that can be used to reproduce the processing we do here (we add to these fields as we apply methods to the dataset).
Have a look at the data¶
Take a first look at the dataset
To have a look around, run ds in a cell and browse (if you are running the notebook interactively). Click the ⛃ and 🗎 symbols on the right to display data and metadata.
ds
<xarray.Dataset> Size: 93kB
Dimensions: (TIME: 3, PRES: 527)
Coordinates:
* TIME (TIME) float64 24B 1.743e+04 1.743e+04 1.743e+04
* PRES (PRES) float64 4kB 3.0 4.0 5.0 6.0 ... 527.0 528.0 529.0
STATION (TIME) <U5 60B 'AT285' 'AT286' 'AT287'
LATITUDE (TIME) float64 24B 80.11 80.07 80.04
LONGITUDE (TIME) float64 24B 9.875 10.38 10.75
Data variables:
TEMP (TIME, PRES) float64 13kB nan 6.362 6.367 ... nan nan nan
PTEMP (TIME, PRES) float64 13kB nan 6.362 6.367 ... nan nan nan
CNDC (TIME, PRES) float64 13kB nan 34.68 34.69 ... nan nan nan
PSAL (TIME, PRES) float64 13kB nan 34.98 34.98 ... nan nan nan
SIGTH (TIME, PRES) float64 13kB nan 27.49 27.49 ... nan nan nan
CHLA_fluorescence (TIME, PRES) float64 13kB nan 1.39 1.293 ... nan nan nan
SBE_FLAG (TIME, PRES) float64 13kB nan 0.0 0.0 0.0 ... nan nan nan
PROCESSING object 8B None
Attributes:
binned: 1 decibars (SBE software)
source_file: E.g. AT287.hex, AT287.XMLCON -> AT287.CNV
history: 2017-09-24 to 2017-09-24: Data collection.\n2018-07-23...
instrument_model: Sea-Bird SBE 9
featureType: profileQuick map¶
Show a quick map of the profile locations. May or may not be useful depending on your dataset.
ctd.map(ds)
/home/docs/checkouts/readthedocs.org/user_builds/kval/conda/latest/lib/python3.12/site-packages/cartopy/io/__init__.py:242: DownloadWarning: Downloading: https://naturalearth.s3.amazonaws.com/50m_physical/ne_50m_land.zip
warnings.warn(f'Downloading: {url}', DownloadWarning)
Contour plots¶
The ctd.contour() function displays two contour plots. You can interactively change which variables are displayed and adjust the axes.
ctd.contour(ds)
Profile plots¶
Have a quick look at individual profiles. Interactively select profiles and variables.
ctd.inspect_profiles(ds)