-
Notifications
You must be signed in to change notification settings - Fork 5
/
example_simple_OSPAR.r
151 lines (151 loc) · 3.8 KB
/
example_simple_OSPAR.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# # Intro ----
#
# # This is a very simple example that assesses a small subset of the biota data
# # used in the OSPAR 2022 CEMP assessment
#
#
# # Setup ----
#
# # Sources functions (folder R) and reference tables (folder information)
# # The functions and reference tables folders are assumed to be in the current
# # R project folder
#
#
# rm(list = objects())
#
# devtools::load_all()
#
#
# # Read data from ICES extraction ----
#
# # There are three input data sets:
# # - the contaminant data
# # - the station dictionary
# # - the quality assurance data (more accurately called a chemical methods file);
# # this will disappear before release
#
# biota_data <- read_data(
# compartment = "biota",
# purpose = "OSPAR",
# contaminants = "test_data.csv",
# stations = "station_dictionary.csv",
# QA = "quality_assurance.csv",
# data_dir = file.path("data", "example_simple_OSPAR"),
# data_format = "ICES_old",
# info_files = list(
# determinand = "determinand_simple_OSPAR.csv",
# thresholds = "thresholds_biota_simple_OSPAR.csv"
# ),
# info_dir = "information",
# extraction = "2022/01/11",
# max_year = 2020L,
# control = list(
# region = list(id = c("OSPAR_region", "OSPAR_subregion"))
# )
# )
#
#
# # Prepare data for next stage ----
#
# # gets correct variable and streamlines some of the data files
#
# biota_data <- tidy_data(biota_data)
#
#
# # Construct timeseries ----
#
# # identifies groups of data that form a coherent timeseries
# # also does a lot of data cleaning and processing (creates oddities folder)
#
# biota_timeseries <- create_timeseries(
# biota_data,
# determinands = c("CD", "CB153", "HBCD","HBCDA", "HBCDG", "PYR1OH"),
# determinands.control = list(
# HBCD = list(det = c("HBCDA", "HBCDB", "HBCDG"), action = "sum"),
# "LIPIDWT%" = list(det = c("EXLIP%", "FATWT%"), action = "bespoke")
# ),
# get_basis = get_basis_biota_OSPAR
# )
#
# # identical (apart from call) to:
# #
# # ctsm_create_timeSeries(
# # biota_data,
# # determinands = ctsm_get_determinands("biota"),
# # determinands.control = list(
# # HBCD = list(det = c("HBCDA", "HBCDB", "HBCDG"), action = "sum"),
# # "LIPIDWT%" = list(det = c("EXLIP%", "FATWT%"), action = "bespoke")
# # )
# # )
# #
# # ctsm_create_timeSeries(
# # biota_data,
# # determinands.control = list(
# # HBCD = list(det = c("HBCDA", "HBCDB", "HBCDG"), action = "sum"),
# # "LIPIDWT%" = list(det = c("EXLIP%", "FATWT%"), action = "bespoke")
# # )
# # )
#
#
# # Assessment ----
#
# # do the statistical analysis
#
# biota_assessment <- run_assessment(
# biota_timeseries,
# AC = c("BAC", "EAC", "EQS", "HQS")
# )
#
#
# # can supply own function for calculating AC - in the example below it
# # will generate exactly the same results
#
# # my_get_AC <- get_AC$biota
# #
# # biota_assessment <- ctsm_assessment(
# # biota_timeSeries,
# # AC = c("BAC", "EAC", "EQS", "HQS"),
# # get_AC_fn = my_get_AC
# # )
#
#
#
# # check convergence - no errors this time
#
# check_assessment(biota_assessment)
#
#
# # Summary files ----
#
# webGroups <- list(
# levels = c("Metals", "Metabolites", "Organobromines", "Chlorobiphenyls"),
# labels = c(
# "Metals", "PAH metabolites", "Organobromines", "Polychlorinated biphenyls"
# )
# )
#
# classColour <- list(
# below = c(
# "BAC" = "blue",
# "EAC" = "green",
# "EQS" = "green",
# "HQS" = "green"
# ),
# above = c(
# "BAC" = "orange",
# "EAC" = "red",
# "EQS" = "red",
# "HQS" = "red"
# ),
# none = "black"
# )
#
# write_summary_table(
# biota_assessment,
# determinandGroups = webGroups,
# classColour = classColour,
# collapse_AC = list(EAC = c("EAC", "EQS")),
# output_dir = file.path("output", "example_simple_OSPAR"),
# )
#
#