|
135 | 135 | url_list <- |
136 | 136 | paste0(base, "catalog.html") %>% |
137 | 137 | read_html() %>% |
138 | | - as_list() %$% |
| 138 | + xml2::as_list() %$% |
139 | 139 | html %$% |
140 | 140 | body %$% |
141 | 141 | table %>% |
|
177 | 177 | ## |
178 | 178 | if(var_name %in% "rs_current"){ |
179 | 179 | ## check if IMOS Ocean Current DM data covers detection data range |
180 | | - ## Ocean current: 1993-01-01 - 2020-12-31 |
| 180 | + ## Ocean current (delayed mode): 1993-01-01 - 2020-12-31 |
| 181 | + ## IMOS near real time data: 2011-09-01 ongoing |
| 182 | + |
| 183 | + |
181 | 184 | ## example : "http://thredds.aodn.org.au/thredds/catalog/IMOS/OceanCurrent/GSLA/DM/" |
| 185 | + # |
182 | 186 | if(date_range[1] < as.Date("1993-01-01")){ |
183 | 187 | warning("IMOS ocean current data is currently only available from 1993-01-01 onwards,\ndetections prior to this date will not have current data associated") |
184 | | - } else if(date_range[2] > as.Date("2020-12-31") & !.nrt) { |
| 188 | + } |
| 189 | + if(date_range[2] > as.Date("2020-12-31") & !.nrt) { |
185 | 190 | warning("IMOS Ocean Current Delayed-Mode data is currently only available from 1993-01-01 to 2020-12-31,\ndetections after this date range will not have current data associated") |
186 | 191 | } |
| 192 | + if(date_range[2] > as.Date("2020-12-31") & .nrt) { |
| 193 | + message("IMOS Ocean Current Near-real-time data will be used for locations after 2020-12-31") |
| 194 | + } |
| 195 | + |
187 | 196 | sub_dates <- dates[dates > as.Date("1993-01-01")] |
188 | | - |
| 197 | + |
189 | 198 | ## IDJ - 19/05/2023: directory name on thredds server has changed from: http://thredds.aodn.org.au/thredds/catalog/IMOS/OceanCurrent/GSLA/DM00/ |
190 | 199 | ## to http://thredds.aodn.org.au/thredds/catalog/IMOS/OceanCurrent/GSLA/DM/ |
191 | 200 | catalog <- |
192 | 201 | tibble(date = sub_dates, |
193 | | - fdates = format(date, "%Y%m%d"), |
194 | | - year = format(date, "%Y"), |
195 | | - base_url = paste0("http://thredds.aodn.org.au/thredds/catalog/IMOS/OceanCurrent/GSLA/DM/", year, "/"), |
196 | | - start_url = paste0("http://thredds.aodn.org.au/thredds/fileServer/IMOS/OceanCurrent/GSLA/DM/", year, "/")) |
197 | | - |
| 202 | + fdates = format(date, "%Y%m%d"), |
| 203 | + year = format(date, "%Y"), |
| 204 | + base_url = paste0("http://thredds.aodn.org.au/thredds/catalog/IMOS/OceanCurrent/GSLA/DM/", year, "/IMOS_OceanCurrent_HV_"), |
| 205 | + start_url = paste0("http://thredds.aodn.org.au/thredds/fileServer/IMOS/OceanCurrent/GSLA/DM/", year, "/IMOS_OceanCurrent_HV_")) |
| 206 | + #end_url = "000000Z_GSLA_FV02_DM02.nc") |
| 207 | + |
198 | 208 | ## if .nrt == TRUE then substitute NRT data for DM when year > 2020 |
199 | 209 | if(.nrt) { |
200 | | - catalog <- catalog %>% |
201 | | - mutate(base_url = ifelse(year > 2020, |
202 | | - paste0("http://thredds.aodn.org.au/thredds/catalog/IMOS/OceanCurrent/GSLA/NRT/", year, "/"), |
203 | | - paste0("http://thredds.aodn.org.au/thredds/catalog/IMOS/OceanCurrent/GSLA/DM/", year, "/") |
204 | | - )) %>% |
205 | | - mutate(start_url = ifelse(year > 2020, |
206 | | - paste0("http://thredds.aodn.org.au/thredds/fileServer/IMOS/OceanCurrent/GSLA/NRT/", year, "/"), |
207 | | - paste0("http://thredds.aodn.org.au/thredds/fileServer/IMOS/OceanCurrent/GSLA/DM/", year, "/") |
208 | | - )) |
209 | | - |
210 | | - } |
| 210 | + catalog$base_url[catalog$year > 2020] <- paste0(paste0("http://thredds.aodn.org.au/thredds/catalog/IMOS/OceanCurrent/GSLA/NRT/", catalog$year[catalog$year > 2020], "/IMOS_OceanCurrent_HV_")) |
| 211 | + catalog$start_url[catalog$year > 2020] <- paste0(paste0("http://thredds.aodn.org.au/thredds/catalog/IMOS/OceanCurrent/GSLA/NRT/", catalog$year[catalog$year > 2020], "/IMOS_OceanCurrent_HV_")) |
| 212 | +# catalog$end_url[catalog$year > 2020] <- "T000000Z_GSLA_FV02_NRT.nc" |
| 213 | + } |
211 | 214 |
|
212 | 215 | if(verbose){ |
213 | 216 | message("Finding IMOS Ocean Current data...") |
214 | 217 | } |
215 | 218 |
|
216 | 219 | find_url <- function(m){ |
| 220 | + |
| 221 | + |
| 222 | + |
217 | 223 | base <- unique(m$base_url)[1] |
218 | 224 | url_list <- |
219 | 225 | paste0(base, "catalog.html") %>% |
220 | | - read_html() %>% |
221 | | - as_list() %$% |
| 226 | + xml2::read_html() %>% |
| 227 | + xml2::as_list() %$% |
222 | 228 | html %$% |
223 | 229 | body %$% |
224 | 230 | table %>% |
225 | | - map_dfr(function(x){if(is.null(x$td$a$tt[[1]])) return(NULL) |
| 231 | + purrr::map_dfr(function(x){if(is.null(x$td$a$tt[[1]])) return(NULL) |
226 | 232 | tibble(end_url = x$td$a$tt[[1]], |
227 | 233 | fdates = substr(end_url, start = 22, stop = 29), |
228 | 234 | date = as.Date(fdates, "%Y%m%d"))}) %>% |
|
239 | 245 | split(., .$year) %>% |
240 | 246 | map( ~ try(find_url(.x), silent = T), .progress = T) |
241 | 247 |
|
242 | | - |
243 | 248 | idx <- sapply(find_df, function(x) inherits(x, "try-error")) |
244 | 249 |
|
245 | 250 | if(any(idx)) { |
|
0 commit comments