{ "cells": [ { "cell_type": "markdown", "id": "ff9b6fac", "metadata": {}, "source": [ "# 08: Ancillary variables\n", "\n", "In science you often don't just want to publish your data variables. You might want to include extra or secondary variables that are related or provide further context to your primary data variables.\n", "\n", "For example, you might have sea water chlorophyll A data taken from water samples at different depths. You might want to also publish \n", "* the volume of your water sample\n", "* other values you have measured in order to compute the chlorophyll A values\n", "* quality flags\n", "\n", "In the CF conventions, these variables are referred to as ancillary data, and this section of the CF conventions is dedicated to them:\n", "https://cfconventions.org/Data/cf-conventions/cf-conventions-1.11/cf-conventions.html#ancillary-data\n", "\n", "In this tutorial, we will look at how you can include ancillary data in a CF-NetCDF file and encode how the variables relate to each other in a machine-understandable way.\n", "\n", "## Basic example without ancillary data" ] }, { "cell_type": "code", "execution_count": 3, "id": "a7306929", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset>\n", "Dimensions: (depth: 5)\n", "Coordinates:\n", " * depth (depth) int64 10 20 30 40 50\n", "Data variables:\n", " Chlorophyll_A (depth) float64 0.411 0.152 0.067 0.017 0.014
<xarray.Dataset>\n", "Dimensions: (depth: 5)\n", "Coordinates:\n", " * depth (depth) int64 10 20 30 40 50\n", "Data variables:\n", " Chlorophyll_A (depth) float64 0.411 0.152 0.067 0.017 0.014\n", " Chlorophyll_A_quality_flags (depth) int64 1 1 1 2 1
<xarray.DataArray 'Chlorophyll_A_quality_flags' (depth: 5)>\n", "array([1, 1, 1, 2, 1])\n", "Coordinates:\n", " * depth (depth) int64 10 20 30 40 50\n", "Attributes:\n", " long_name: Chlorophyll A quality flag\n", " standard_name: quality_flag\n", " flag_values: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n", " flag_meanings: no_qc_performed good_data probably_good_data bad_data_tha...\n", " valid_range: [0, 9]\n", " _FillValue: -127
<xarray.Dataset>\n", "Dimensions: (depth: 5)\n", "Coordinates:\n", " * depth (depth) int64 10 20 30 40 50\n", "Data variables:\n", " Chlorophyll_A (depth) float64 0.411 0.152 0.067 0.017 0.014\n", " Chlorophyll_A_quality_flags (depth) int64 1 1 1 2 1\n", "Attributes:\n", " Conventions: CF-1.8, ACDD-1.3, OceanSITES Manual 1.4
<xarray.DataArray 'Chlorophyll_A' (depth: 5)>\n", "array([0.411, 0.152, 0.067, nan, 0.014])\n", "Coordinates:\n", " * depth (depth) int64 10 20 30 40 50\n", "Attributes:\n", " standard_name: mass_concentration_of_chlorophyll_a_in_sea_water\n", " long_name: Mass concentration of chlorophyll a in sea water ...\n", " units: μg L-1\n", " coverage_content_type: physicalMeasurement\n", " ancillary_variables: Chlorophyll_A_quality_flags
<xarray.DataArray 'Chlorophyll_A' (depth: 4)>\n", "array([0.411, 0.152, 0.067, 0.014])\n", "Coordinates:\n", " * depth (depth) int64 10 20 30 50\n", "Attributes:\n", " standard_name: mass_concentration_of_chlorophyll_a_in_sea_water\n", " long_name: Mass concentration of chlorophyll a in sea water ...\n", " units: μg L-1\n", " coverage_content_type: physicalMeasurement\n", " ancillary_variables: Chlorophyll_A_quality_flags
<xarray.Dataset>\n", "Dimensions: (depth: 5)\n", "Coordinates:\n", " * depth (depth) int64 10 20 30 40 50\n", "Data variables:\n", " Chlorophyll_A (depth) float64 0.411 0.152 0.067 0.017 0.014\n", " Chlorophyll_A_quality_flags (depth) int64 1 1 1 2 1\n", " Filtered_volume (depth) float64 0.8 1.2 0.7 0.8 1.0\n", "Attributes:\n", " Conventions: CF-1.8, ACDD-1.3, OceanSITES Manual 1.4