{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 13. Fixing calibration parameters\n", "In this notebook we will demonstrate how to fix the calibration parameters $\\gamma$ and $\\alpha$. This can be useful in setups where you have insufficient reference sections to calibrate these, but you do have information on these parameters from previous setups with the same fiber.\n", "\n", "We will be using the same dataset as notebook 5. Calibration of single-ended measurement with OLS" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2022-04-06T08:11:15.471807Z", "iopub.status.busy": "2022-04-06T08:11:15.470954Z", "iopub.status.idle": "2022-04-06T08:11:17.137093Z", "shell.execute_reply": "2022-04-06T08:11:17.136561Z" } }, "outputs": [], "source": [ "import os\n", "\n", "from dtscalibration import read_silixa_files\n", "\n", "# The following line introduces the .dts accessor for xarray datasets\n", "import dtscalibration # noqa: E401 # noqa: E401\n", "from dtscalibration.variance_stokes import variance_stokes_constant\n", "import matplotlib.pyplot as plt\n", "\n", "filepath = os.path.join(\"..\", \"..\", \"tests\", \"data\", \"single_ended\")\n", "\n", "ds = read_silixa_files(directory=filepath, timezone_netcdf=\"UTC\", file_ext=\"*.xml\")\n", "\n", "ds100 = ds.sel(x=slice(-30, 101)) # only calibrate parts of the fiber, in meters\n", "sections = {\n", " \"probe1Temperature\": [\n", " slice(20, 25.5)\n", " ], # we only use the warm bath in this notebook\n", "}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "From the previous calibration we know that the $\\gamma$ parameter value was 481.9 and the $\\alpha$ value was -2.014e-05.\n", "We define these, along with their variance. In this case we do not know what the variance was, as we ran an OLS calibration, so we will set the variance to 0.\n", "\n", "It is important to note that when setting parameters, the covariances between the parameters are not taken into account in the uncertainty." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2022-04-06T08:11:17.162098Z", "iopub.status.busy": "2022-04-06T08:11:17.161917Z", "iopub.status.idle": "2022-04-06T08:11:17.193198Z", "shell.execute_reply": "2022-04-06T08:11:17.192690Z" } }, "outputs": [], "source": [ "fix_gamma = (481.9, 0) # (gamma value, gamma variance)\n", "fix_dalpha = (-2.014e-5, 0) # (alpha value, alpha variance)\n", "\n", "st_var, resid = variance_stokes_constant(\n", " ds.dts.st, sections, ds.dts.acquisitiontime_fw, reshape_residuals=True\n", ")\n", "ast_var, _ = variance_stokes_constant(\n", " ds.dts.ast, sections, ds.dts.acquisitiontime_fw, reshape_residuals=False\n", ")\n", "out = ds100.dts.calibrate_single_ended(\n", " sections=sections,\n", " st_var=st_var,\n", " ast_var=ast_var,\n", " fix_gamma=fix_gamma,\n", " fix_dalpha=fix_dalpha,\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's see if fixing the parameters worked:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2022-04-06T08:11:17.195822Z", "iopub.status.busy": "2022-04-06T08:11:17.195484Z", "iopub.status.idle": "2022-04-06T08:11:17.199167Z", "shell.execute_reply": "2022-04-06T08:11:17.198526Z" } }, "outputs": [], "source": [ "print(\"gamma used in calibration:\", out.gamma.values)\n", "print(\"dalpha used in calibration:\", out.dalpha.values)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's plot the calibrated temperature. You'll see that this gives the same result as in notebook 05." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2022-04-06T08:11:17.201528Z", "iopub.status.busy": "2022-04-06T08:11:17.201340Z", "iopub.status.idle": "2022-04-06T08:11:17.411075Z", "shell.execute_reply": "2022-04-06T08:11:17.410449Z" } }, "outputs": [], "source": [ "out.isel(time=0).tmpf.plot(\n", " linewidth=1, figsize=(12, 8), label=\"User calibrated\"\n", ") # plot the temperature calibrated by us\n", "ds100.isel(time=0).tmp.plot(\n", " linewidth=1, label=\"Device calibrated\"\n", ") # plot the temperature calibrated by the device\n", "plt.title(\"Temperature at the first time step\")\n", "plt.legend()" ] } ], "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.10.10" } }, "nbformat": 4, "nbformat_minor": 4 }