If the main goal is to detect whether only the most recent point is anomalous in a univariate time series, your current two-step CNN approach (global + local) is a bit overcomplicated and delicate due to the daily masking/cleaning loop.
Alternatively:
A. Use a rolling forecast error approach:
Develop a model (e.g., ARIMA, LSTM, or even a simple moving average) to predict the next point. Then:
python
Copy-edit
error = abs(actual[-1] - predicted[-1])
is anomaly = error > threshold
Cultivate the limit using a rolling error distribution or confidence interval (e.g., mean + 3*std of past residuals).
B. Statistical test or z-score on residuals:
Establish a baseline model (even just a rolling mean), then for the latest value:
python
CopyEdit
residual = actual[-1] - rolling_mean[-1]
z_score = residual / rolling_std[-1]
is_anomaly = abs(z_score) > 3