<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Read in example data from one CML
Step1:  Do a simple wet/dry classification
Step2:  Derive a constant baseline
Let's just focus on the rain events on 2016-10-25
Step3:  Or derive a linear baseline
Step4:  Compare the results from constant and linear baseline
Step5:  NaN handling
The algorithms for constant and linear baseline handle NaNs differently
Step6:  Constant baseline
Step7:  Linear baseline (default)
default = set baseline for whole wet event to NaN if it contains at least one wet NaN
Step8:  Linear baseline (ignoring NaNs)
<ASSISTANT_TASK:>
Python Code:
cml = pycml.io.examples.read_one_cml()
# Remove artifacts and plot data
cml.process.quality_control.set_to_nan_if('tx', '>=', 100)
cml.process.quality_control.set_to_nan_if('rx', '==', -99.9)
cml.plot_data(['tx', 'rx', 'txrx']);
Explanation: Read in example data from one CML
End of explanation
cml.process.wet_dry.std_dev(window_length=30, threshold=0.8)
cml.plot_data(['txrx', 'wet']);
Explanation: Do a simple wet/dry classification
End of explanation
cml.process.baseline.constant()
cml.process.baseline.calc_A()
ax = cml.plot_data(['txrx', 'wet', 'baseline', 'A']);
ax[0].set_xlim('2016-10-25 00:00', '2016-10-25 10:00');
# Save a copy of these results for comparing them to the linear baseline later
baseline_constant = cml.channel_1.data.baseline.copy()
A_constant = cml.channel_1.data.A.copy()
Explanation: Derive a constant baseline
Let's just focus on the rain events on 2016-10-25
End of explanation
cml.process.baseline.linear()
cml.process.baseline.calc_A()
ax = cml.plot_data(['txrx', 'wet', 'baseline', 'A']);
ax[0].set_xlim('2016-10-25 00:00', '2016-10-25 10:00');
# Save a copy of these results for comparing them to the constant baseline
baseline_linear = cml.channel_1.data.baseline.copy()
A_linear = cml.channel_1.data.A.copy()
Explanation: Or derive a linear baseline
End of explanation
fig, ax = plt.subplots(2, 1, figsize=(10, 4), sharex=True)
ax[0].plot(baseline_constant, color='C3', label='constant baseline')
ax[0].plot(baseline_linear, color='C4', label='linear baseline')
ax[1].plot(A_constant, color='C3', label='constant baseline')
ax[1].plot(A_linear, color='C4', label='linear baseline')
ax[0].set_xlim('2016-10-25 00:00', '2016-10-25 10:00');
ax[0].set_ylabel('baseline')
ax[1].set_ylabel('A')
ax[0].legend();
Explanation: Compare the results from constant and linear baseline
End of explanation
# Exchange the current `wet` pd.Series in `channel_1` with a different series of floats with some `NaN`s
wet_temp = cml.channel_1.data.wet.astype(float)
wet_temp['2016-10-25 04:45': '2016-10-25 05:00'] = np.NaN
cml.channel_1.data.wet = wet_temp
Explanation: NaN handling
The algorithms for constant and linear baseline handle NaNs differently:
* constant baseline:
    * For NaN values in wet the baseline is also set to NaN.
    * All baseline values following a NaN during a wet event are also set to NaN till the next dry event starts. This has to be done, since we do not know if a new wet event started during a NaN period and hence we do not know at which level the constant baseline should be.
* linear baseline:
    * Default:
    The baseline for a whole wet event is set to NaN if there is at least one wet NaN within this period. This makes sense, since for the interpolation of the linear baseline the correct end of the wet period has to be known to its txrx value. Since the wet event could have ended during the NaN period, we do not know the end of the wet period and hence cannot savely assume a txrx endpoint for the interpolation.
    * Option to ignore_nan:
    If you know what you are doing, e.g. because you know that your only have very few consecutive wet NaNs and hecne can assume that a wet event will not stop during your wet NaN, then you can ignore all NaNs. This will take the next switch from wet to dry as endpoint of the wet event and do the interpolation accordingly.
End of explanation
cml.process.baseline.constant()
cml.process.baseline.calc_A()
ax = cml.plot_data(['txrx', 'wet', 'baseline', 'A']);
ax[0].set_xlim('2016-10-25 00:00', '2016-10-25 10:00');
Explanation: Constant baseline
End of explanation
cml.process.baseline.linear()
cml.process.baseline.calc_A()
ax = cml.plot_data(['txrx', 'wet', 'baseline', 'A']);
ax[0].set_xlim('2016-10-25 00:00', '2016-10-25 10:00');
Explanation: Linear baseline (default)
default = set baseline for whole wet event to NaN if it contains at least one wet NaN
End of explanation
cml.process.baseline.linear(ignore_nan=True)
cml.process.baseline.calc_A()
ax = cml.plot_data(['txrx', 'wet', 'baseline', 'A']);
ax[0].set_xlim('2016-10-25 00:00', '2016-10-25 10:00');
Explanation: Linear baseline (ignoring NaNs)
End of explanation
<END_TASK>