Overview

Building on the default functionality shared between the two languages, this vignette goes further to look at how changing the default arguments may affect the results. Along the way the outputs are checked for consistency and all of the arguments for all of the functions are tweaked to look for irregularities. This is necessary before only one language is used to further investigate best practices for dealing with sub-optimal time series in the detection of MHWs.

Preferably this step could have been done programmatically, without creating an army of outputs as seen below. The R package reticulate does not seem to want to play along though so I must rather run the Python code, save the outputs, load them into R and compare the results natively in just R… So let’s get started.

library(tidyverse)
library(ggpubr)
library(heatwaveR)
library(reticulate)
use_condaenv("py27")
# Compare default clims and intensities
cor(default_r$climatology$seas, default_py_clim$seas)
## [1] 0.9999999
sum(default_r$climatology$seas) - sum(default_py_clim$seas)
## [1] -2.053821
cor(default_r$climatology$thresh, default_py_clim$thresh)
## [1] 0.9999996
sum(default_r$climatology$thresh) - sum(default_py_clim$thresh)
## [1] -6.573385
sum(default_r$event$intensity_cumulative) - sum(default_py_event$intensity_cumulative)
## [1] 0.1630294
sum(default_r$event$intensity_max) - sum(default_py_event$intensity_max)
## [1] 0.008673771
##            r                            var
## 1         NA                       event_no
## 2  1.0000000                    index_start
## 3  1.0000000                     index_peak
## 4  1.0000000                      index_end
## 5  1.0000000                       duration
## 6  0.9999991                 intensity_mean
## 7  0.9999997                  intensity_max
## 8  0.9996073                  intensity_var
## 9  1.0000000           intensity_cumulative
## 10 0.9999971       intensity_mean_relThresh
## 11 0.9999994        intensity_max_relThresh
## 12 0.9995693        intensity_var_relThresh
## 13 0.9999996 intensity_cumulative_relThresh
## 14 1.0000000             intensity_mean_abs
## 15 0.9990733              intensity_max_abs
## 16 0.9997263              intensity_var_abs
## 17 1.0000000       intensity_cumulative_abs
## 18 0.9999999                     rate_onset
## 19 0.9999999                   rate_decline

pctile comparisons

Here we look at a few possible settings for the pctile argument and ensure that everything matches up.

First run and save the Python output.

Then run the R output.

pctile_80_r <- detect_event(ts2clm(data = sst_WA, pctile = 80,
                                   climatologyPeriod = c("1982-01-01", "2014-12-31")))
pctile_95_r <- detect_event(ts2clm(data = sst_WA, pctile = 95,
                                   climatologyPeriod = c("1982-01-01", "2014-12-31")))
pctile_99_r <- detect_event(ts2clm(data = sst_WA, pctile = 99,
                                   climatologyPeriod = c("1982-01-01", "2014-12-31")))

Lastly load the Python output and compare the two.

## [1] 0.9999999
sum(pctile_80_r$climatology$seas) - sum(pctile_80_py_clim$seas)
## [1] -2.053821
cor(pctile_80_r$climatology$thresh, pctile_80_py_clim$thresh)
## [1] 0.9999982
sum(pctile_80_r$climatology$thresh) - sum(pctile_80_py_clim$thresh)
## [1] -14.013
sum(pctile_80_r$event$intensity_cumulative) - sum(pctile_80_py_event$intensity_cumulative)
## [1] 2.444108
sum(pctile_80_r$event$intensity_max) - sum(pctile_80_py_event$intensity_max)
## [1] -1.102694
# 95
cor(pctile_95_r$climatology$seas, pctile_95_py_clim$seas)
## [1] 0.9999999
sum(pctile_95_r$climatology$seas) - sum(pctile_95_py_clim$seas)
## [1] -2.053821
cor(pctile_95_r$climatology$thresh, pctile_95_py_clim$thresh)
## [1] 0.9999999
sum(pctile_95_r$climatology$thresh) - sum(pctile_95_py_clim$thresh)
## [1] -3.402085
sum(pctile_95_r$event$intensity_cumulative) - sum(pctile_95_py_event$intensity_cumulative)
## [1] 0.06129223
sum(pctile_95_r$event$intensity_max) - sum(pctile_95_py_event$intensity_max)
## [1] 0.007555896
# 99
cor(pctile_99_r$climatology$seas, pctile_99_py_clim$seas)
## [1] 0.9999999
sum(pctile_99_r$climatology$seas) - sum(pctile_99_py_clim$seas)
## [1] -2.053821
cor(pctile_99_r$climatology$thresh, pctile_99_py_clim$thresh)
## [1] 0.9999944
sum(pctile_99_r$climatology$thresh) - sum(pctile_99_py_clim$thresh)
## [1] 28.39465
sum(pctile_99_r$event$intensity_cumulative) - sum(pctile_99_py_event$intensity_cumulative)
## [1] -0.003142188
sum(pctile_99_r$event$intensity_max) - sum(pctile_99_py_event$intensity_max)
## [1] -0.0002594781
##            r                            var
## 1         NA                       event_no
## 2  1.0000000                    index_start
## 3  1.0000000                     index_peak
## 4  1.0000000                      index_end
## 5  1.0000000                       duration
## 6  0.9999988                 intensity_mean
## 7  0.9999996                  intensity_max
## 8  0.9988679                  intensity_var
## 9  1.0000000           intensity_cumulative
## 10 0.9999979       intensity_mean_relThresh
## 11 0.9999468        intensity_max_relThresh
## 12 0.9988432        intensity_var_relThresh
## 13 0.9999999 intensity_cumulative_relThresh
## 14 1.0000000             intensity_mean_abs
## 15 0.9997819              intensity_max_abs
## 16 0.9990657              intensity_var_abs
## 17 1.0000000       intensity_cumulative_abs
## 18 0.9999998                     rate_onset
## 19 1.0000000                   rate_decline
##            r                            var
## 1         NA                       event_no
## 2  1.0000000                    index_start
## 3  1.0000000                     index_peak
## 4  1.0000000                      index_end
## 5  1.0000000                       duration
## 6  1.0000000                 intensity_mean
## 7  1.0000000                  intensity_max
## 8  0.9995120                  intensity_var
## 9  1.0000000           intensity_cumulative
## 10 0.9999043       intensity_mean_relThresh
## 11 0.9999951        intensity_max_relThresh
## 12 0.9993619        intensity_var_relThresh
## 13 0.9999383 intensity_cumulative_relThresh
## 14 1.0000000             intensity_mean_abs
## 15 1.0000000              intensity_max_abs
## 16 0.9991278              intensity_var_abs
## 17 1.0000000       intensity_cumulative_abs
## 18 1.0000000                     rate_onset
## 19 1.0000000                   rate_decline

There appears to be an issue with the results when the threshold is set to pctile = 80 as Python detects one more event than R. Let’s take a closer look.

## [1] "2013-12-30"

The issue appears to be that the R code is joining across a four day gap, which it shouldn’t do. So I assume that the threshold is different between the languages. This is curious as the seasonal and threshold climatologies correlate nearly perfectly. Diving deeper, let’s pull out the clim values around the time of this event and see what we see.

As we may see in the figure above, the difference is not perceptible to the human eye. Looking very closely at the clim outputs manually one may see that in the R code, the threshold on 2013-12-29 is just below the temperature value due to a rounding difference from the Python code at the third decimal place.

Also above one may see that even though the values correlate nearly perfectly, the sum of the seasonal climatology value output by R are 1.98122 less than the Python output. Considering that there are 12053 values, the average difference is only 0.00016, which is not terribly much at all. The issue appears to be in the calculation of the threshold climatology. This value is not consistently different based on the pctile value used. It varies quite a bit. With the sum difference at pctile = 80 being -13.86432, the default of pctile = 90 being -6.563516, pctile = 95 being -3.382435, and pctile = 99 being 28.37769. This is strong evidence that the threshold values are being calculated using some different method that needs to be addressed. That being said, even at the largest difference of 28.37769, that is still only an average difference per row of 0.002354409

Digging deeper still, let’s pull up the old RmarineHeatWaves code and run another comparison with that to see if this difference is due to newer changes in the development of the heatwaveR package.

ts <- RmarineHeatWaves::make_whole(sst_WA)
default_r_old <- RmarineHeatWaves::detect(data = ts, climatology_start = "1982-01-01", climatology_end = "2014-12-31")
default_r_old_event <- default_r_old$event
default_r_old_clim <- default_r_old$clim

# Compare default new and old R clims  and intensities
cor(default_r$climatology$seas, default_r_old_clim$seas_clim_year)
## [1] 1
sum(default_r$climatology$seas) - sum(default_r_old_clim$seas_clim_year)
## [1] -0.07260093
cor(default_r$climatology$thresh, default_r_old_clim$thresh_clim_year)
## [1] 1
sum(default_r$climatology$thresh) - sum(default_r_old_clim$thresh_clim_year)
## [1] -0.009868637
sum(default_r$event$intensity_cumulative) - sum(default_py_event$intensity_cumulative)
## [1] 0.1630294
sum(default_r$event$intensity_max) - sum(default_py_event$intensity_max)
## [1] 0.008673771
##     r                            var
## 1   1                       event_no
## 2   1                    index_start
## 3  NA                     index_peak
## 4  NA                      index_end
## 5   1                       duration
## 6  NA                 intensity_mean
## 7  NA                  intensity_max
## 8  NA                  intensity_var
## 9  NA           intensity_cumulative
## 10 NA       intensity_mean_relThresh
## 11 NA        intensity_max_relThresh
## 12 NA        intensity_var_relThresh
## 13 NA intensity_cumulative_relThresh
## 14 NA             intensity_mean_abs
## 15 NA              intensity_max_abs
## 16 NA              intensity_var_abs
## 17 NA       intensity_cumulative_abs
## 18  1                     rate_onset
## 19  1                   rate_decline
# Compare Python and old R clims and intensities
cor(default_py_clim$seas, default_r_old_clim$seas_clim_year)
## [1] 0.9999999
sum(default_py_clim$seas) - sum(default_r_old_clim$seas_clim_year)
## [1] 1.98122
cor(default_py_clim$thresh, default_r_old_clim$thresh_clim_year)
## [1] 0.9999996
sum(default_py_clim$thresh) - sum(default_r_old_clim$thresh_clim_year)
## [1] 6.563516
sum(default_py_event$intensity_cumulative) - sum(default_r_old_event$int_cum)
## [1] -0.157388
sum(default_py_event$intensity_max) - sum(default_r_old_event$int_max)
## [1] -0.008520925
##     r                 var
## 1   1         index_start
## 2  NA          index_stop
## 3  NA            event_no
## 4   1            duration
## 5  NA            int_mean
## 6  NA             int_max
## 7  NA             int_var
## 8  NA             int_cum
## 9  NA int_mean_rel_thresh
## 10 NA  int_max_rel_thresh
## 11 NA  int_var_rel_thresh
## 12 NA  int_cum_rel_thresh
## 13 NA        int_mean_abs
## 14 NA         int_max_abs
## 15 NA         int_var_abs
## 16 NA         int_cum_abs
## 17 NA       int_mean_norm
## 18 NA        int_max_norm
## 19  1          rate_onset
## 20  1        rate_decline

The differences between the old and new R implementation are minute to the point of being almost imperceptible.

smoothPercentileWidth comparisons

Seeing now that the choice of the pctile threshold may create results different enough as to produce a different counts of events, we need to look closer at the different arguments. I have my suspicions that the smoothing of the threshold values may be the culprit here.

spw_no_r <- detect_event(ts2clm(data = sst_WA, smoothPercentile = FALSE,
                                climatologyPeriod = c("1982-01-01", "2014-12-31")))
spw_11_r <- detect_event(ts2clm(data = sst_WA, smoothPercentileWidth = 11,
                                climatologyPeriod = c("1982-01-01", "2014-12-31")))
spw_51_r <- detect_event(ts2clm(data = sst_WA, smoothPercentileWidth = 51,
                                climatologyPeriod = c("1982-01-01", "2014-12-31")))
## [1] 0.9999992
sum(spw_no_r$climatology$seas) - sum(spw_no_py_clim$seas)
## [1] -2.124743
cor(spw_no_r$climatology$thresh, spw_no_py_clim$thresh)
## [1] 0.9999965
sum(spw_no_r$climatology$thresh) - sum(spw_no_py_clim$thresh)
## [1] -6.492852
sum(spw_no_r$event$intensity_cumulative) - sum(spw_no_py_event$intensity_cumulative)
## [1] 0.1128817
sum(spw_no_r$event$intensity_max) - sum(spw_no_py_event$intensity_max)
## [1] 0.01567827
# 11 days
cor(spw_11_r$climatology$seas, spw_11_py_clim$seas)
## [1] 0.9999997
sum(spw_11_r$climatology$seas) - sum(spw_11_py_clim$seas)
## [1] -2.053809
cor(spw_11_r$climatology$thresh, spw_11_py_clim$thresh)
## [1] 0.999999
sum(spw_11_r$climatology$thresh) - sum(spw_11_py_clim$thresh)
## [1] -6.294534
sum(spw_11_r$event$intensity_cumulative) - sum(spw_11_py_event$intensity_cumulative)
## [1] 0.1236748
sum(spw_11_r$event$intensity_max) - sum(spw_11_py_event$intensity_max)
## [1] 0.006339516
# 51 days
cor(spw_51_r$climatology$seas, spw_51_py_clim$seas)
## [1] 0.9999999
sum(spw_51_r$climatology$seas) - sum(spw_51_py_clim$seas)
## [1] -2.049584
cor(spw_51_r$climatology$thresh, spw_51_py_clim$thresh)
## [1] 0.9999998
sum(spw_51_r$climatology$thresh) - sum(spw_51_py_clim$thresh)
## [1] -6.601041
sum(spw_51_r$event$intensity_cumulative) - sum(spw_51_py_event$intensity_cumulative)
## [1] 0.1554402
sum(spw_51_r$event$intensity_max) - sum(spw_51_py_event$intensity_max)
## [1] 0.006590975
##            r                            var
## 1         NA                       event_no
## 2  1.0000000                    index_start
## 3  1.0000000                     index_peak
## 4  1.0000000                      index_end
## 5  1.0000000                       duration
## 6  0.9999980                 intensity_mean
## 7  0.9999991                  intensity_max
## 8  0.9993833                  intensity_var
## 9  0.9999999           intensity_cumulative
## 10 0.9999956       intensity_mean_relThresh
## 11 0.9997743        intensity_max_relThresh
## 12 0.9993307        intensity_var_relThresh
## 13 0.9999995 intensity_cumulative_relThresh
## 14 1.0000000             intensity_mean_abs
## 15 0.9989767              intensity_max_abs
## 16 0.9995815              intensity_var_abs
## 17 1.0000000       intensity_cumulative_abs
## 18 0.9999991                     rate_onset
## 19 0.9999993                   rate_decline
##            r                            var
## 1         NA                       event_no
## 2  1.0000000                    index_start
## 3  1.0000000                     index_peak
## 4  1.0000000                      index_end
## 5  1.0000000                       duration
## 6  0.9999983                 intensity_mean
## 7  0.9999994                  intensity_max
## 8  0.9994320                  intensity_var
## 9  0.9999999           intensity_cumulative
## 10 0.9999963       intensity_mean_relThresh
## 11 0.9999581        intensity_max_relThresh
## 12 0.9994217        intensity_var_relThresh
## 13 0.9999996 intensity_cumulative_relThresh
## 14 1.0000000             intensity_mean_abs
## 15 0.9989804              intensity_max_abs
## 16 0.9996098              intensity_var_abs
## 17 1.0000000       intensity_cumulative_abs
## 18 0.9999985                     rate_onset
## 19 0.9999995                   rate_decline
##            r                            var
## 1         NA                       event_no
## 2  1.0000000                    index_start
## 3  1.0000000                     index_peak
## 4  1.0000000                      index_end
## 5  1.0000000                       duration
## 6  0.9999995                 intensity_mean
## 7  0.9999999                  intensity_max
## 8  0.9996564                  intensity_var
## 9  1.0000000           intensity_cumulative
## 10 0.9999968       intensity_mean_relThresh
## 11 0.9999679        intensity_max_relThresh
## 12 0.9996309        intensity_var_relThresh
## 13 0.9999996 intensity_cumulative_relThresh
## 14 1.0000000             intensity_mean_abs
## 15 0.9992145              intensity_max_abs
## 16 0.9997404              intensity_var_abs
## 17 1.0000000       intensity_cumulative_abs
## 18 1.0000000                     rate_onset
## 19 1.0000000                   rate_decline

Surprisingly the smoothing window, regardless if it is applied or not, seems to make little difference. But again, let’s compare the old R code against Python as well.

ts <- RmarineHeatWaves::make_whole(sst_WA)
spw_no_r_old <- RmarineHeatWaves::detect(data = ts, climatology_start = "1982-01-01", climatology_end = "2014-12-31", smooth_percentile = FALSE)
spw_no_r_old_event <- spw_no_r_old$event
spw_no_r_old_clim <- spw_no_r_old$clim

# Compare new and old R code
sum(spw_no_r$climatology$seas) - sum(spw_no_r_old_clim$seas_clim_year)
## [1] -0.06278893
sum(spw_no_r$climatology$thresh) - sum(spw_no_r_old_clim$thresh_clim_year)
## [1] 0.006147504
# Compare old & new R against Python
sum(spw_no_py_clim$seas) - sum(spw_no_r_old_clim$seas_clim_year)
## [1] 2.061954
sum(spw_no_py_clim$seas) - sum(spw_no_r$climatology$seas)
## [1] 2.124743
sum(spw_no_py_clim$thresh) - sum(spw_no_r_old_clim$thresh_clim_year)
## [1] 6.499
sum(spw_no_py_clim$thresh) - sum(spw_no_r$climatology$thresh)
## [1] 6.492852

Again, almost no difference.

windowHalfWidth comparisons

We’ve now seen that the differences between both the new & old R code and the Python code hold consistently different regardless of the changing of the pctile or smoothWindowPercentile. This then leads me to think that this is just a rounding issue between the two languages, and that there is not some fundamentally different calculation happening somewhere in the code. That being said, it is still necessary to be thorough and so I’ll go through the rest of the arguments now. Starting with windowHalfWidth.

whw_3_r <- detect_event(ts2clm(data = sst_WA, windowHalfWidth = 3,
                               climatologyPeriod = c("1982-01-01", "2014-12-31")))
whw_7_r <- detect_event(ts2clm(data = sst_WA, windowHalfWidth = 7,
                               climatologyPeriod = c("1982-01-01", "2014-12-31")))
## [1] 0.9999999
sum(whw_3_r$climatology$seas) - sum(whw_3_py_clim$seas)
## [1] -1.284023
cor(whw_3_r$climatology$thresh, whw_3_py_clim$thresh)
## [1] 0.9999999
sum(whw_3_r$climatology$thresh) - sum(whw_3_py_clim$thresh)
## [1] -3.022406
sum(whw_3_r$event$intensity_cumulative) - sum(whw_3_py_event$intensity_cumulative)
## [1] 0.103755
sum(whw_3_r$event$intensity_max) - sum(whw_3_py_event$intensity_max)
## [1] 0.005514523
# 7 days
cor(whw_7_r$climatology$seas, whw_7_py_clim$seas)
## [1] 0.9999998
sum(whw_7_r$climatology$seas) - sum(whw_7_py_clim$seas)
## [1] -2.859033
cor(whw_7_r$climatology$thresh, whw_7_py_clim$thresh)
## [1] 0.999998
sum(whw_7_r$climatology$thresh) - sum(whw_7_py_clim$thresh)
## [1] -13.58322
sum(whw_7_r$event$intensity_cumulative) - sum(whw_7_py_event$intensity_cumulative)
## [1] 8.303694
sum(whw_7_r$event$intensity_max) - sum(whw_7_py_event$intensity_max)
## [1] 1.901248
##            r                            var
## 1         NA                       event_no
## 2  1.0000000                    index_start
## 3  1.0000000                     index_peak
## 4  1.0000000                      index_end
## 5  1.0000000                       duration
## 6  0.9999997                 intensity_mean
## 7  0.9999999                  intensity_max
## 8  0.9996480                  intensity_var
## 9  1.0000000           intensity_cumulative
## 10 0.9999993       intensity_mean_relThresh
## 11 0.9999938        intensity_max_relThresh
## 12 0.9996042        intensity_var_relThresh
## 13 0.9999999 intensity_cumulative_relThresh
## 14 1.0000000             intensity_mean_abs
## 15 0.9993263              intensity_max_abs
## 16 0.9997486              intensity_var_abs
## 17 1.0000000       intensity_cumulative_abs
## 18 1.0000000                     rate_onset
## 19 1.0000000                   rate_decline

We see here that the windowHalfWidth has a large effect on the difference between the results than anything else so far. The difference per row is still low at ~0.001 so isn’t much cause for alarm. We do however detect a different number of events if windowHalfWidth = 7. Let’s see how they differ.

## [1] "2006-03-05"

The difference lies in the R code detecting a five day event that the Python code must have seen as only 4 days or less. Again due to very narrow differences in the threshold values.

Let’s look if there is a difference between the old and new R code.

ts <- RmarineHeatWaves::make_whole(sst_WA)
whw_7_r_old <- RmarineHeatWaves::detect(data = ts, climatology_start = "1982-01-01", climatology_end = "2014-12-31", window_half_width = 7)

# Compare new and old R code
sum(whw_7_r$climatology$seas) - sum(whw_7_r_old$clim$seas_clim_year)
## [1] -0.06257652
sum(whw_7_r$climatology$thresh) - sum(whw_7_r_old$clim$thresh_clim_year)
## [1] 0.003332891
sum(whw_7_r$event$intensity_cumulative) - sum(whw_7_r_old$event$int_cum)
## [1] 0.004781785
sum(whw_7_r$event$intensity_max) - sum(whw_7_r_old$event$int_max)
## [1] 0.0001258996

Everything matches up between old and new R for windowHalfWidth = 7.

minDuration comparisons

Now we move away form the arguments that effect the climatology calculations, and focus just on those that determine the classification of events.

minD_3_r <- detect_event(ts2clm(data = sst_WA, climatologyPeriod = c("1982-01-01", "2014-12-31")), 
                         minDuration = 3)
minD_7_r <- detect_event(ts2clm(data = sst_WA, climatologyPeriod = c("1982-01-01", "2014-12-31")), 
                         minDuration = 7)
## [1] 0.9999999
sum(minD_3_r$climatology$seas) - sum(minD_3_py_clim$seas)
## [1] -2.053821
cor(minD_3_r$climatology$thresh, minD_3_py_clim$thresh)
## [1] 0.9999996
sum(minD_3_r$climatology$thresh) - sum(minD_3_py_clim$thresh)
## [1] -6.573385
sum(minD_3_r$event$intensity_cumulative) - sum(minD_3_py_event$intensity_cumulative)
## [1] 0.1969908
sum(minD_3_r$event$intensity_max) - sum(minD_3_py_event$intensity_max)
## [1] 0.01369288
# 7 days
cor(minD_7_r$climatology$seas, minD_7_py_clim$seas)
## [1] 0.9999999
sum(minD_7_r$climatology$seas) - sum(minD_7_py_clim$seas)
## [1] -2.053821
cor(minD_7_r$climatology$thresh, minD_7_py_clim$thresh)
## [1] 0.9999996
sum(minD_7_r$climatology$thresh) - sum(minD_7_py_clim$thresh)
## [1] -6.573385
sum(minD_7_r$event$intensity_cumulative) - sum(minD_7_py_event$intensity_cumulative)
## [1] 0.1169319
sum(minD_7_r$event$intensity_max) - sum(minD_7_py_event$intensity_max)
## [1] 0.007283979
##            r                            var
## 1         NA                       event_no
## 2  1.0000000                    index_start
## 3  1.0000000                     index_peak
## 4  1.0000000                      index_end
## 5  1.0000000                       duration
## 6  0.9999988                 intensity_mean
## 7  0.9999997                  intensity_max
## 8  0.9987979                  intensity_var
## 9  1.0000000           intensity_cumulative
## 10 0.9999895       intensity_mean_relThresh
## 11 0.9999946        intensity_max_relThresh
## 12 0.9987109        intensity_var_relThresh
## 13 0.9999996 intensity_cumulative_relThresh
## 14 1.0000000             intensity_mean_abs
## 15 0.9991713              intensity_max_abs
## 16 0.9990268              intensity_var_abs
## 17 1.0000000       intensity_cumulative_abs
## 18 1.0000000                     rate_onset
## 19 0.9999999                   rate_decline
##            r                            var
## 1         NA                       event_no
## 2  1.0000000                    index_start
## 3  1.0000000                     index_peak
## 4  1.0000000                      index_end
## 5  1.0000000                       duration
## 6  0.9999992                 intensity_mean
## 7  0.9999997                  intensity_max
## 8  0.9992868                  intensity_var
## 9  1.0000000           intensity_cumulative
## 10 0.9999965       intensity_mean_relThresh
## 11 0.9999768        intensity_max_relThresh
## 12 0.9992416        intensity_var_relThresh
## 13 0.9999995 intensity_cumulative_relThresh
## 14 1.0000000             intensity_mean_abs
## 15 0.9996425              intensity_max_abs
## 16 0.9994579              intensity_var_abs
## 17 1.0000000       intensity_cumulative_abs
## 18 0.9999999                     rate_onset
## 19 0.9999999                   rate_decline

As expected, changing the minimum duration of events has no effect on the threshold calculations. It is however gratifying to see that the same number of events is calculated between languages, regardless of the minimum duration. The difference these cause in the intensities of the events is also negligible between languages.

joinAcrossGaps comparisons

Now for the final argument in the base functionality. This too should not effect the climatologies. Only the events.

joinAG_no_r <- detect_event(ts2clm(data = sst_WA, climatologyPeriod = c("1982-01-01", "2014-12-31")), 
                            joinAcrossGaps = FALSE)
joinAG_1_r <- detect_event(ts2clm(data = sst_WA, climatologyPeriod = c("1982-01-01", "2014-12-31")), 
                           maxGap = 1)
joinAG_5_r <- detect_event(ts2clm(data = sst_WA, climatologyPeriod = c("1982-01-01", "2014-12-31")), 
                           maxGap = 5)
## [1] 0.9999999
sum(joinAG_no_r$climatology$seas) - sum(joinAG_no_py_clim$seas)
## [1] -2.053821
cor(joinAG_no_r$climatology$thresh, joinAG_no_py_clim$thresh)
## [1] 0.9999996
sum(joinAG_no_r$climatology$thresh) - sum(joinAG_no_py_clim$thresh)
## [1] -6.573385
sum(joinAG_no_r$event$intensity_cumulative) - sum(joinAG_no_py_event$intensity_cumulative)
## [1] 0.1559537
sum(joinAG_no_r$event$intensity_max) - sum(joinAG_no_py_event$intensity_max)
## [1] 0.01446085
# 1 day
cor(joinAG_1_r$climatology$seas, joinAG_1_py_clim$seas)
## [1] 0.9999999
sum(joinAG_1_r$climatology$seas) - sum(joinAG_1_py_clim$seas)
## [1] -2.053821
cor(joinAG_1_r$climatology$thresh, joinAG_1_py_clim$thresh)
## [1] 0.9999996
sum(joinAG_1_r$climatology$thresh) - sum(joinAG_1_py_clim$thresh)
## [1] -6.573385
sum(joinAG_1_r$event$intensity_cumulative) - sum(joinAG_1_py_event$intensity_cumulative)
## [1] 0.1584107
sum(joinAG_1_r$event$intensity_max) - sum(joinAG_1_py_event$intensity_max)
## [1] 0.01211662
# 7 days
cor(joinAG_5_r$climatology$seas, joinAG_5_py_clim$seas)
## [1] 0.9999999
sum(joinAG_5_r$climatology$seas) - sum(joinAG_5_py_clim$seas)
## [1] -2.053821
cor(joinAG_5_r$climatology$thresh, joinAG_5_py_clim$thresh)
## [1] 0.9999996
sum(joinAG_5_r$climatology$thresh) - sum(joinAG_5_py_clim$thresh)
## [1] -6.573385
sum(joinAG_5_r$event$intensity_cumulative) - sum(joinAG_5_py_event$intensity_cumulative)
## [1] 0.1610846
sum(joinAG_5_r$event$intensity_max) - sum(joinAG_5_py_event$intensity_max)
## [1] 0.008638111
##            r                            var
## 1         NA                       event_no
## 2  1.0000000                    index_start
## 3  1.0000000                     index_peak
## 4  1.0000000                      index_end
## 5  1.0000000                       duration
## 6  0.9999989                 intensity_mean
## 7  0.9999996                  intensity_max
## 8  0.9989905                  intensity_var
## 9  1.0000000           intensity_cumulative
## 10 0.9999973       intensity_mean_relThresh
## 11 0.9999993        intensity_max_relThresh
## 12 0.9989440        intensity_var_relThresh
## 13 0.9999996 intensity_cumulative_relThresh
## 14 1.0000000             intensity_mean_abs
## 15 0.9997855              intensity_max_abs
## 16 0.9992315              intensity_var_abs
## 17 1.0000000       intensity_cumulative_abs
## 18 0.9999999                     rate_onset
## 19 0.9999999                   rate_decline
##            r                            var
## 1         NA                       event_no
## 2  1.0000000                    index_start
## 3  1.0000000                     index_peak
## 4  1.0000000                      index_end
## 5  1.0000000                       duration
## 6  0.9999991                 intensity_mean
## 7  0.9999997                  intensity_max
## 8  0.9992930                  intensity_var
## 9  1.0000000           intensity_cumulative
## 10 0.9999971       intensity_mean_relThresh
## 11 0.9999832        intensity_max_relThresh
## 12 0.9992473        intensity_var_relThresh
## 13 0.9999996 intensity_cumulative_relThresh
## 14 1.0000000             intensity_mean_abs
## 15 0.9997788              intensity_max_abs
## 16 0.9995174              intensity_var_abs
## 17 1.0000000       intensity_cumulative_abs
## 18 0.9999999                     rate_onset
## 19 0.9999999                   rate_decline
##            r                            var
## 1         NA                       event_no
## 2  1.0000000                    index_start
## 3  1.0000000                     index_peak
## 4  1.0000000                      index_end
## 5  1.0000000                       duration
## 6  0.9999990                 intensity_mean
## 7  0.9999997                  intensity_max
## 8  0.9995542                  intensity_var
## 9  1.0000000           intensity_cumulative
## 10 0.9999960       intensity_mean_relThresh
## 11 0.9999993        intensity_max_relThresh
## 12 0.9995227        intensity_var_relThresh
## 13 0.9999995 intensity_cumulative_relThresh
## 14 1.0000000             intensity_mean_abs
## 15 0.9966753              intensity_max_abs
## 16 0.9997826              intensity_var_abs
## 17 1.0000000       intensity_cumulative_abs
## 18 0.9999999                     rate_onset
## 19 0.9999999                   rate_decline

A little surprising, but good to see, is that the length of gap between events does not cause a different number of events to be calculated between languages considering all other arguments are kept at the default.

Conclusion

It appears as though, down to a very small degree, there are differences between the outputs of the two languages. That being said, these differences appear to be due to the rounding differences that exist between the languages and so it is not a fault of the code in either, nor are there fundamentally different processes being employed to make the calculations. Indeed, though minute differences may be found in the calculations of the seasonal and threshold climatologies, these differences are consistent. They do not vary. They may change in magnitude depending on the arguments supplied, but these differences never become larger than ~0.001 per row, which has been deemed here as acceptable. Interestingly, though not surprising in hindsight, is that the changing of the windowHalfWidth argument causes the largest difference between the languages. This makes sense because this argument determines how many values are meaned together in the beginning of the climatology calculations. And as the differences are due to rounding, that numerical fingerprint is boldest here.

Depending on how some of the arguments were tweaked, the two languages very rarely would detect one event more or less than the other. This was due to the odd day being just above or below the threshold by ~0.001 degrees or so. Very rare, but so is existence, hypothetically.

Ultimately, I am very confident in saying that the outputs of these two languages are comparable.