10. Align double ended measurements¶
The cable length was initially configured during the DTS measurement. For double ended measurements it is important to enter the correct length so that the forward channel and the backward channel are aligned.
This notebook shows how to better align the forward and the backward measurements. Do this before the calibration steps.
[1]:
import os
from dtscalibration import read_silixa_files
from dtscalibration.datastore_utils import (
suggest_cable_shift_double_ended,
shift_double_ended,
)
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
[2]:
?suggest_cable_shift_double_ended
[3]:
filepath = os.path.join("..", "..", "tests", "data", "double_ended2")
ds_aligned = read_silixa_files(
directory=filepath, timezone_netcdf="UTC", file_ext="*.xml"
) # this one is already correctly aligned
6 files were found, each representing a single timestep
6 recorded vars were found: LAF, ST, AST, REV-ST, REV-AST, TMP
Recorded at 1693 points along the cable
The measurement is double ended
Reading the data from disk
/home/docs/checkouts/readthedocs.org/user_builds/python-dts-calibration/envs/latest/lib/python3.9/site-packages/dtscalibration/datastore.py:81: UserWarning: Converting non-nanosecond precision timedelta values to nanosecond precision. This behavior can eventually be relaxed in xarray, as it is an artifact from pandas which is now beginning to support non-nanosecond precision values. This warning is caused by passing non-nanosecond np.datetime64 or np.timedelta64 values to the DataArray or Variable constructor; it can be silenced by converting the values to nanosecond precision ahead of time.
super().__init__(*args, **kwargs)
/home/docs/checkouts/readthedocs.org/user_builds/python-dts-calibration/envs/latest/lib/python3.9/site-packages/dtscalibration/datastore.py:81: UserWarning: Converting non-nanosecond precision timedelta values to nanosecond precision. This behavior can eventually be relaxed in xarray, as it is an artifact from pandas which is now beginning to support non-nanosecond precision values. This warning is caused by passing non-nanosecond np.datetime64 or np.timedelta64 values to the DataArray or Variable constructor; it can be silenced by converting the values to nanosecond precision ahead of time.
super().__init__(*args, **kwargs)
/home/docs/checkouts/readthedocs.org/user_builds/python-dts-calibration/envs/latest/lib/python3.9/site-packages/dtscalibration/datastore.py:81: UserWarning: Converting non-nanosecond precision timedelta values to nanosecond precision. This behavior can eventually be relaxed in xarray, as it is an artifact from pandas which is now beginning to support non-nanosecond precision values. This warning is caused by passing non-nanosecond np.datetime64 or np.timedelta64 values to the DataArray or Variable constructor; it can be silenced by converting the values to nanosecond precision ahead of time.
super().__init__(*args, **kwargs)
/home/docs/checkouts/readthedocs.org/user_builds/python-dts-calibration/envs/latest/lib/python3.9/site-packages/dtscalibration/datastore.py:81: UserWarning: Converting non-nanosecond precision timedelta values to nanosecond precision. This behavior can eventually be relaxed in xarray, as it is an artifact from pandas which is now beginning to support non-nanosecond precision values. This warning is caused by passing non-nanosecond np.datetime64 or np.timedelta64 values to the DataArray or Variable constructor; it can be silenced by converting the values to nanosecond precision ahead of time.
super().__init__(*args, **kwargs)
Because our loaded files were already nicely aligned, we are purposely offsetting the forward and backward channel by 3 `spacial indices’.
[4]:
ds_notaligned = shift_double_ended(ds_aligned, 3)
I dont know what to do with the following data ['tmp']
The device-calibrated temperature doesnot have a valid meaning anymore and is dropped
[5]:
suggested_shift = suggest_cable_shift_double_ended(
ds_notaligned, np.arange(-5, 5), plot_result=True, figsize=(12, 8)
)
/home/docs/checkouts/readthedocs.org/user_builds/python-dts-calibration/envs/latest/lib/python3.9/site-packages/dtscalibration/datastore_utils.py:892: RuntimeWarning: invalid value encountered in log
i_f = np.log(st / ast)
/home/docs/checkouts/readthedocs.org/user_builds/python-dts-calibration/envs/latest/lib/python3.9/site-packages/dtscalibration/datastore_utils.py:893: RuntimeWarning: invalid value encountered in log
i_b = np.log(rst / rast)

The two approaches suggest a shift of -3 and -4. It is up to the user which suggestion to follow. Usually the two suggested shift are close
[6]:
ds_restored = shift_double_ended(ds_notaligned, suggested_shift[0])
[7]:
print(ds_aligned.x, 3 * "\n", ds_restored.x)
<xarray.DataArray 'x' (x: 1693)>
array([-80.5043, -80.3772, -80.2501, ..., 134.294 , 134.421 , 134.548 ])
Coordinates:
* x (x) float64 -80.5 -80.38 -80.25 -80.12 ... 134.2 134.3 134.4 134.5
Attributes:
name: distance
description: Length along fiber
long_description: Starting at connector of forward channel
units: m
<xarray.DataArray 'x' (x: 1687)>
array([-80.123 , -79.9959, -79.8688, ..., 133.913 , 134.04 , 134.167 ])
Coordinates:
* x (x) float64 -80.12 -80.0 -79.87 -79.74 ... 133.8 133.9 134.0 134.2
Attributes:
name: distance
description: Length along fiber
long_description: Starting at connector of forward channel
units: m
Note that our fiber has become shorter by 2*3 spatial indices