{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# A4. Loading sensortran files\n", "This example loads sensortran files. Only single-ended measurements are currently supported.\n", "Sensortran files are in binary format. The library requires the `*BinaryRawDTS.dat` and `*BinaryTemp.dat` files." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2022-04-06T08:12:41.112269Z", "iopub.status.busy": "2022-04-06T08:12:41.111317Z", "iopub.status.idle": "2022-04-06T08:12:42.789532Z", "shell.execute_reply": "2022-04-06T08:12:42.788997Z" } }, "outputs": [], "source": [ "import os\n", "import glob\n", "import matplotlib.pyplot as plt\n", "from pandas.plotting import register_matplotlib_converters\n", "\n", "register_matplotlib_converters()\n", "\n", "from dtscalibration import read_sensortran_files" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The example data files are located in `./python-dts-calibration/tests/data`." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2022-04-06T08:12:42.792673Z", "iopub.status.busy": "2022-04-06T08:12:42.792258Z", "iopub.status.idle": "2022-04-06T08:12:42.796234Z", "shell.execute_reply": "2022-04-06T08:12:42.795702Z" } }, "outputs": [], "source": [ "filepath = os.path.join(\"..\", \"..\", \"tests\", \"data\", \"sensortran_binary\")\n", "print(filepath)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2022-04-06T08:12:42.823281Z", "iopub.status.busy": "2022-04-06T08:12:42.823092Z", "iopub.status.idle": "2022-04-06T08:12:42.827800Z", "shell.execute_reply": "2022-04-06T08:12:42.827277Z" } }, "outputs": [], "source": [ "filepathlist = sorted(glob.glob(os.path.join(filepath, \"*.dat\")))\n", "filenamelist = [os.path.basename(path) for path in filepathlist]\n", "\n", "for fn in filenamelist:\n", " print(fn)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We will simply load in the binary files" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2022-04-06T08:12:42.830273Z", "iopub.status.busy": "2022-04-06T08:12:42.830100Z", "iopub.status.idle": "2022-04-06T08:12:43.014938Z", "shell.execute_reply": "2022-04-06T08:12:43.014369Z" } }, "outputs": [], "source": [ "ds = read_sensortran_files(directory=filepath)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The object tries to gather as much metadata from the measurement files as possible (temporal and spatial coordinates, filenames, temperature probes measurements). All other configuration settings are loaded from the first files and stored as attributes of the `xarray.Dataset`. Sensortran's data files contain less information than the other manufacturer's devices, one being the acquisition time. The acquisition time is needed for estimating variances, and is set a constant 1s." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2022-04-06T08:12:43.017404Z", "iopub.status.busy": "2022-04-06T08:12:43.017183Z", "iopub.status.idle": "2022-04-06T08:12:43.028561Z", "shell.execute_reply": "2022-04-06T08:12:43.027986Z" } }, "outputs": [], "source": [ "print(ds)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The sensortran files differ from other manufacturers, in that they return the 'counts' of the Stokes and anti-Stokes signals. These are not corrected for offsets, which has to be done manually for proper calibration. \n", "\n", "Based on the data available in the binary files, the library estimates a zero-count to correct the signals, but this is not perfectly accurate or constant over time. For proper calibration, the offsets would have to be incorporated into the calibration routine." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2022-04-06T08:12:43.031140Z", "iopub.status.busy": "2022-04-06T08:12:43.030922Z", "iopub.status.idle": "2022-04-06T08:12:43.068201Z", "shell.execute_reply": "2022-04-06T08:12:43.067535Z" } }, "outputs": [], "source": [ "ds" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2022-04-06T08:12:43.071120Z", "iopub.status.busy": "2022-04-06T08:12:43.070796Z", "iopub.status.idle": "2022-04-06T08:12:43.129632Z", "shell.execute_reply": "2022-04-06T08:12:43.128673Z" } }, "outputs": [], "source": [ "ds0 = ds.isel(time=0)\n", "\n", "plt.figure()\n", "ds0.st.plot(label=\"Stokes signal\")\n", "plt.axhline(ds0.st_zero.values, c=\"r\", label=\"'zero' measurement\")\n", "plt.legend()\n", "plt.title(\"\")\n", "plt.axhline(c=\"k\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "After a correction and rescaling (for human readability) the data will look more like other manufacturer's devices" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2022-04-06T08:12:43.133192Z", "iopub.status.busy": "2022-04-06T08:12:43.132864Z", "iopub.status.idle": "2022-04-06T08:12:43.149273Z", "shell.execute_reply": "2022-04-06T08:12:43.148278Z" } }, "outputs": [], "source": [ "ds[\"st\"] = (ds.st - ds.st_zero) / 1e4\n", "ds[\"ast\"] = (ds.ast - ds.ast_zero) / 1e4" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2022-04-06T08:12:43.154281Z", "iopub.status.busy": "2022-04-06T08:12:43.153959Z", "iopub.status.idle": "2022-04-06T08:12:43.197810Z", "shell.execute_reply": "2022-04-06T08:12:43.196411Z" } }, "outputs": [], "source": [ "ds.isel(time=0).st.plot(label=\"Stokes intensity\")\n", "ds.isel(time=0).ast.plot(label=\"anti-Stokes intensity\")\n", "plt.legend()\n", "plt.axhline(c=\"k\", lw=1)\n", "plt.xlabel(\"\")\n", "plt.title(\"\")\n", "plt.ylim([-50, 500])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.9.11" } }, "nbformat": 4, "nbformat_minor": 2 }