Last updated: 2019-11-06

• R Markdown file: up-to-date

Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

• Environment: empty

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

• Seed: set.seed(666)

The command set.seed(666) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

• Session information: recorded

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

• Repository version: 7da5f6a

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility. The version displayed above was the version of the Git repository at the time these results were generated.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:

Ignored files:
Ignored:    .Rhistory
Ignored:    .Rproj.user/
Ignored:    data/global/
Ignored:    data/global_results.Rda
Ignored:    data/global_test_trend.Rda
Ignored:    data/global_var_trend.Rda
Ignored:    data/global_var_trend_old.Rda
Ignored:    data/random_bp_results_100.Rda
Ignored:    data/random_bp_results_1000.Rda
Ignored:    data/random_results_100.Rda
Ignored:    data/random_results_1000.Rda
Ignored:    data/sst_ALL_bp_results.Rda

Untracked files:
Untracked:  analysis/WA_pixels.Rda
Untracked:  analysis/WA_pixels_res.Rda

Unstaged changes:
Modified:   .DS_Store
Modified:   .Rprofile
Modified:   .gitignore
Modified:   CODE_OF_CONDUCT.md
Modified:   LaTeX/FMars.csl
Modified:   LaTeX/Frontiers_Template.docx
Modified:   LaTeX/MHWdetection.docx
Modified:   LaTeX/MHWdetection.tex
Modified:   LaTeX/PDF examples/frontiers.pdf
Modified:   LaTeX/PDF examples/frontiers_SupplementaryMaterial.pdf
Modified:   LaTeX/Supplementary_Material.docx
Modified:   LaTeX/YM-logo.eps
Modified:   LaTeX/fig_1.jpg
Modified:   LaTeX/fig_1.pdf
Modified:   LaTeX/fig_1_flat.jpg
Modified:   LaTeX/fig_1_flat.pdf
Modified:   LaTeX/fig_2.jpg
Modified:   LaTeX/fig_2.pdf
Modified:   LaTeX/fig_3.jpg
Modified:   LaTeX/fig_3.pdf
Modified:   LaTeX/fig_4.jpg
Modified:   LaTeX/fig_4.pdf
Modified:   LaTeX/fig_5.jpg
Modified:   LaTeX/fig_5.pdf
Modified:   LaTeX/fig_6.jpg
Modified:   LaTeX/fig_6.pdf
Modified:   LaTeX/fig_S1.jpg
Modified:   LaTeX/fig_S1.pdf
Modified:   LaTeX/fig_S2.jpg
Modified:   LaTeX/fig_S2.pdf
Modified:   LaTeX/fig_S3.jpg
Modified:   LaTeX/fig_S3.pdf
Modified:   LaTeX/fig_S4.jpg
Modified:   LaTeX/fig_S4.pdf
Modified:   LaTeX/fig_S5.jpg
Modified:   LaTeX/fig_S5.pdf
Modified:   LaTeX/figures.zip
Modified:   LaTeX/frontiers.tex
Modified:   LaTeX/frontiersFPHY.cls
Modified:   LaTeX/frontiersHLTH.cls
Modified:   LaTeX/frontiers_SupplementaryMaterial.tex
Modified:   LaTeX/frontiers_suppmat.cls
Modified:   LaTeX/frontiersinHLTH&FPHY.bst
Modified:   LaTeX/frontiersinSCNS_ENG_HUMS.bst
Modified:   LaTeX/logo1.eps
Modified:   LaTeX/logo1.jpg
Modified:   LaTeX/logo2.eps
Modified:   LaTeX/logos.eps
Modified:   LaTeX/logos.jpg
Modified:   LaTeX/stfloats.sty
Modified:   LaTeX/table_1.xlsx
Modified:   LaTeX/table_2.xlsx
Modified:   LaTeX/test.bib
Modified:   MHWdetection.Rproj
Modified:   TODO
Modified:   _references/1-s2.0-S0921818106002736-main.pdf
Modified:   _references/1-s2.0-S092181810600275X-main.pdf
Modified:   _references/1-s2.0-S0921818106002761-main.pdf
Modified:   _references/1-s2.0-S0921818106002852-main.pdf
Modified:   _references/1405.3904.pdf
Modified:   _references/1520-0450%282001%29040%3C0762%3Aotdoah%3E2.0.co%3B2.pdf
Modified:   _references/2013_Extremes_Workshop_Report.pdf
Modified:   _references/24868781.pdf
Modified:   _references/24870362.pdf
Modified:   _references/26192647.pdf
Modified:   _references/994.full.pdf
Modified:   _references/A_1019841717369.pdf
Modified:   _references/Banzon et al 2014.pdf
Modified:   _references/Brown_et_al-2008-Journal_of_Geophysical_Research%3A_Atmospheres_%281984-2012%29.pdf
Modified:   _references/Different_ways_to_compute_temperature_re.pdf
Modified:   _references/Gilleland et al 2013.pdf
Modified:   _references/Gilleland_2006.pdf
Modified:   _references/Kuglitsch_et_al-2010-Geophysical_Research_Letters.pdf
Modified:   _references/Modeling Waves of Extreme Temperature The Changing Tails of Four Cities.pdf
Modified:   _references/Normals-Guide-to-Climate-190116_en.pdf
Modified:   _references/Reynolds et al 2007.pdf
Modified:   _references/Risk_of_Extreme_Events_Under_Nonstationa.pdf
Modified:   _references/Russo_et_al-2014-Journal_of_Geophysical_Research%3A_Atmospheres.pdf
Modified:   _references/WCDMP_72_TD_1500_en__1.pdf
Modified:   _references/WMO 49 v1 2015.pdf
Modified:   _references/WMO No 1203.pdf
Modified:   _references/WMO-TD No 1377.pdf
Modified:   _references/WMO_100_en.pdf
Modified:   _references/bams-d-12-00066.1.pdf
Modified:   _references/c058p193.pdf
Modified:   _references/cc100.pdf
Modified:   _references/clivar14.pdf
Modified:   _references/coles1994.pdf
Modified:   _references/ecology.pdf
Modified:   _references/joc.1141.pdf
Modified:   _references/joc.1432.pdf
Modified:   _references/returnPeriod.pdf
Modified:   _references/s00382-014-2287-1.pdf
Modified:   _references/s00382-014-2345-8.pdf
Modified:   _references/s00382-015-2638-6.pdf
Modified:   _references/s10584-006-9116-4.pdf
Modified:   _references/s10584-007-9392-7.pdf
Modified:   _references/s10584-010-9944-0.pdf
Modified:   _references/s10584-012-0659-2.pdf
Modified:   _references/s10584-014-1254-5.pdf
Modified:   _references/s13253-013-0161-y.pdf
Modified:   _references/wcrpextr.pdf
Modified:   _workflowr.yml
Modified:   analysis/Climatologies_and_baselines.Rmd
Modified:   analysis/Short_climatologies.Rmd
Modified:   analysis/best_practices.Rmd
Modified:   analysis/bibliography.bib
Modified:   analysis/gridded_products.Rmd
Modified:   analysis/missing_data.Rmd
Modified:   analysis/r_vs_python_arguments.Rmd
Modified:   analysis/time_series_length.Rmd
Modified:   analysis/trend.Rmd
Modified:   analysis/variance.Rmd
Modified:   data/.gitignore
Modified:   data/best_table_average.Rda
Modified:   data/best_table_focus.Rda
Modified:   data/python/clim_py.csv
Modified:   data/python/clim_py_joinAG_1.csv
Modified:   data/python/clim_py_joinAG_5.csv
Modified:   data/python/clim_py_joinAG_no.csv
Modified:   data/python/clim_py_minD_3.csv
Modified:   data/python/clim_py_minD_7.csv
Modified:   data/python/clim_py_pctile_80.csv
Modified:   data/python/clim_py_pctile_95.csv
Modified:   data/python/clim_py_pctile_99.csv
Modified:   data/python/clim_py_random.csv
Modified:   data/python/clim_py_spw_11.csv
Modified:   data/python/clim_py_spw_51.csv
Modified:   data/python/clim_py_spw_no.csv
Modified:   data/python/clim_py_whw_3.csv
Modified:   data/python/clim_py_whw_7.csv
Modified:   data/python/mhwBlock.csv
Modified:   data/python/mhws_py.csv
Modified:   data/python/mhws_py_joinAG_1.csv
Modified:   data/python/mhws_py_joinAG_5.csv
Modified:   data/python/mhws_py_joinAG_no.csv
Modified:   data/python/mhws_py_minD_3.csv
Modified:   data/python/mhws_py_minD_7.csv
Modified:   data/python/mhws_py_pctile_80.csv
Modified:   data/python/mhws_py_pctile_95.csv
Modified:   data/python/mhws_py_pctile_99.csv
Modified:   data/python/mhws_py_random.csv
Modified:   data/python/mhws_py_spw_11.csv
Modified:   data/python/mhws_py_spw_51.csv
Modified:   data/python/mhws_py_spw_no.csv
Modified:   data/python/mhws_py_whw_3.csv
Modified:   data/python/mhws_py_whw_7.csv
Modified:   data/python/sst_WA.csv
Modified:   data/python/sst_WA_miss_ice.csv
Modified:   data/python/sst_WA_miss_random.csv
Modified:   data/sst_ALL_results.Rda
Modified:   data/table_1.csv
Modified:   data/table_2.csv
Modified:   docs/.nojekyll
Modified:   docs/portrait.pdf
Modified:   output/effect_event.pdf
Modified:   output/fig_2_missing_only.pdf
Modified:   output/stitch_plot_WA.pdf
Modified:   output/stitch_sub_plot_WA.pdf
Modified:   poster/Figures/CSIRO_logo.jpeg
Modified:   poster/Figures/Dal_logo.jpg
Modified:   poster/Figures/all_logo_long.jpg
Modified:   poster/Figures/all_logos.jpg
Modified:   poster/Figures/logo_stitching.odp
Modified:   poster/Figures/ofi_logo.jpg
Modified:   poster/Figures/uwc-logo.jpg
Modified:   poster/MHWdetection.bib
Modified:   poster/MyBib.bib
Modified:   poster/landscape.Rmd
Modified:   poster/landscape.pdf
Modified:   poster/portrait.Rmd
Modified:   poster/portrait.pdf


Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.
Expand here to see past versions:
File Version Author Date Message
html 158aa0b robwschlegel 2019-05-06 Updated project interface
html fa7fd57 robwschlegel 2019-03-19 Build site.
Rmd 64ac134 robwschlegel 2019-03-19 Publish analysis files

## Overview

In this last comparison vignette between the two languages we will look at the additional functions that they come with. Slightly different approaches have been taken to provide the user with the ability to calculate block averages from the detection outputs as well as categorising the ‘extremeness’ of events. We will compare these different workflows/outputs below.

library(tidyverse)
library(ggpubr)
library(heatwaveR)
compare_event <- function(res_event_R, res_event_Python){
# Remove non-numeric columns
res_event_num <- res_event_R %>%
select_if(is.numeric)
# Run the loop
res_event <- data.frame()
for(i in 1:length(colnames(res_event_num))){
if(colnames(res_event_num)[i] %in% colnames(res_event_Python)){
x1 <- res_event_R[colnames(res_event_R) == colnames(res_event_num)[i]]
x2 <- res_event_Python[colnames(res_event_Python) == colnames(res_event_num)[i]]
x <- data.frame(r = round(cor(x1, x2, use = "complete.obs"), 4),
sum = round(sum(x1, na.rm = T) - sum(x2, na.rm = T), 4),
var = colnames(res_event_num)[i])
colnames(x)[1] <- "r"
rownames(x) <- NULL
} else {
x <- data.frame(r = NA, sum = NA, var = colnames(res_event_num)[i])
}
res_event <- rbind(res_event, x)
}
return(res_event)
}
library(reticulate)
use_condaenv("py27")
import numpy as np
from datetime import date
import pandas as pd
import marineHeatWaves as mhw
# The date values
t = np.arange(date(1982,1,1).toordinal(),date(2014,12,31).toordinal()+1)
# The temperature values
sst = np.loadtxt(open("data/sst_WA.csv", "r"), delimiter = ',', skiprows = 1)
# The event metrics
mhws, clim = mhw.detect(t, sst)

## block_average() comparisons

First up we take a peak at the block_average() functions and the outputs they produce.

mhwBlock = mhw.blockAverage(t, mhws, clim)
mhwsBlock_df = pd.DataFrame.from_dict(mhwBlock)
mhwsBlock_df.to_csv('data/mhwBlock.csv', sep = ',', index = False)
default_r <- detect_event(ts2clm(data = sst_WA, climatologyPeriod = c("1982-01-01", "2014-12-31")))
block_r <- block_average(default_r)
block_py <- read_csv("data/mhwBlock.csv")

### Overlapping column names

Initially we want to see how well the naming conventions for the columns hold up.

cols_r <- colnames(block_r)[!(colnames(block_r) %in% colnames(block_py))]
cols_r
cols_py <- colnames(block_py)[!(colnames(block_py) %in% colnames(block_r))]
cols_py

The two columns that the R code outputs that the Python code lacks is year and duration_max. We may see that the Python code creates years_centre, years_end, and years_start. The difference for this is that the Python version is set up to allow for block averages to be calculated for units of time other than single years, whereas the R version only outputs single annual means. I don’t know that this needs to be expanded upon in the R code. I don’t see this functions as terribly useful, to be honest. Surely if a user has gotten to this point, they can calculate block averages on their own to their own preferences.

The variable duration_max shows the maximum duration of an event detected in a given year, and was added to heatwaveR v0.3.5 at the request of a user. There is talk of including it in Python, too.

### Comparison of outputs

Up next we look at how well the outputs correlate and sum up. As we saw in the previous vignette, correlation values are useful for showing how consistently similar the results are, but not for if they are exact. For that we will compare sums as well.

compare_event(block_r, block_py)

As expected, the results correlate and sum up to nearly identical values. The mismatch being a product of rounding differences between the languages.

## Trend comparisons

There is no comparable R functions that performs these calculations. One could be created if the desire exists…

mean, trend, dtrend = mhw.meanTrend(mhwBlock)
#print(mean)
#print(trend)
#print(dtrend)
# Print out results in R as desired
#py$mean #py$trend
#py\$dtrend

## Category comparisons

The final bit of extra functionality that must be compared between the two languages is the newest addition for both. This is the calculation of categories for MHWs as seen in Hobday et al. (2018). The two languages go about the calculation of these events in rather different ways. And produce different outputs. This is however intentional and so it must be decided if this is to be made more consistent, or be left as it is.

# Load Python category results
select(date_peak, category, intensity_max, duration,
duration_moderate, duration_strong, duration_severe, duration_extreme)
category_py

# Calculate categories in R
category_r <- category(default_r, name = "WA")
category_r

I won’t go about comparing the outputs of these functions the same as I have for the other functions because, as stated above, they show different information. The R output is specifically tailored to match the information style of Table 2 in Hobday et al. (2018). This is one final point on which a decision must be made about whether or not the extra functionality of the languages should be brought to be the exact same, or allowed to differ. I think it is fine the way it is now.

## Conclusion

Two questions still beg an answer:

1. Do we want to have a built in trend detecting function in the R code, a la meanTrend in the Python package? I don’t think so. We have posted a vignette on the heatwaveR site showing users how to perform this calculation themselves, so I don’t think it needs to be included as a function. It would be simple to do should the desire exist.
2. The output of the category information between the two languages is quite different. The Python code provides, as part of the base detect output, the days spent within each category, as well as the maximum category reached. The R output rather provides the proportion of time spent in each category, as well as the maximum category. The R code has additional columns added in to better match Table 2 in Hobday et al. (2018). I think this is useful as a user would probably want a summary output of the category information. But I could be convinced that it is the days, rather than proportions, that should be provided without the additional columns as well.

That wraps up the comparisons of the languages. It can be said that where small rounding differences persist between the languages, the base outputs are comparable and the languages may be used interchangeably. The extra functionality also matches up, minus a couple of issues that probably don’t need to be addressed. There are some difference, but these are stylistic and it is not clear that they should be changed/addressed.

One persistent problem is the impact that missing data have on the calculation of the 90th percentile threshold. THis must still be investigated at depth in the source code of both languages to nail down just exactly where they handle missing data differently.

It is now time to get started on looking at how to be go about consistently and reliably detecting thermal events in time series given a range of potential sub-optimal conditions.

## References

Hobday, Alistair J., Eric C.J. Oliver, Alex Sen Gupta, Jessica A. Benthysen, Michael T. Burrows, Markus G. Donat, Neil J. Holbrook, et al. 2018. “Categorizing and naming marine heatwaves.” Oceanography 31 (2). https://doi.org/10.5670/oceanog.2018.205.

## Session information

sessionInfo()

This reproducible R Markdown analysis was created with workflowr 1.1.1