Skip to content

Commit 2248a02

Browse files
authored
Develop (#14)
* Added docker file * Added commands to run Dockerfile * Added Dockefile to .Buildignore * #13 Deprecated function - decompress_gz - import_geff_data_from_tar - mean_percs - stack_netcdf_files * Fixed tests and updated description * removed linters * Fixed message in deprecated functions
1 parent 721ac93 commit 2248a02

31 files changed

+385
-233
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111
^NOTICE$
1212
^docs$
1313
^_pkgdown\.yml$
14+
^Dockerfile$

.travis.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ dist: xenial
66

77
addons:
88
apt:
9+
sources:
10+
- sourceline: 'ppa:ubuntugis/ubuntugis-unstable'
911
packages:
10-
- libssl-dev
11-
- libnetcdf-dev
12-
- netcdf-bin
13-
- libhdf5-dev
14-
- libproj-dev
15-
- libgdal-dev
16-
- gdal-bin
12+
- libssl-dev
13+
- libproj-dev
14+
- libgeos-dev
15+
- libhdf4-alt-dev
16+
- libhdf5-serial-dev
17+
- libgdal-dev
18+
- libnetcdf-dev
1719

1820
r_github_packages:
1921
- jimhester/lintr

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ Suggests:
4343
lintr
4444
VignetteBuilder: knitr
4545
Encoding: UTF-8
46-
SystemRequirements: GDAL binaries, PROJ.4, netcdf4, hdf5, openssl
46+
SystemRequirements: GDAL with HDF4&5 support, PROJ.4, netcdf4, hdf5, openssl
4747
License: Apache License 2.0
4848
RoxygenNote: 6.1.1

Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM s22s/geo-swak
2+
3+
RUN set -eux \
4+
&& apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9 \
5+
&& add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu cosmic-cran35/' \
6+
&& apt-get update --yes
7+
8+
RUN set -eux \
9+
&& env DEBIAN_FRONTEND=noninteractive \
10+
apt install --yes \
11+
libssl-dev \
12+
r-base-dev
13+
14+
RUN set -eux \
15+
&& R -e 'install.packages("devtools")' \
16+
&& R -e 'devtools::install_github("ecmwf/caliver")'

NAMESPACE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
export(anomaly)
44
export(classify_index)
55
export(daily_clima)
6+
export(decompress_gz)
67
export(firegram)
78
export(forecast_summary)
89
export(forecast_summary_clima)
@@ -11,8 +12,10 @@ export(get_fire_season)
1112
export(get_gfed4)
1213
export(get_perc_risk_index)
1314
export(get_percentile_raster)
15+
export(import_geff_data_from_tar)
1416
export(mask_crop_subset)
1517
export(mask_with_fuelmodel)
18+
export(mean_percs)
1619
export(plot_anomaly)
1720
export(plot_classified_index)
1821
export(plot_fire_pdf)

R/anomaly.R

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222

2323
anomaly <- function(r, clima){
2424

25-
options(warn = -1)
26-
2725
if (round(r@extent@xmin, 0) == 0) {
2826

2927
# Rotate a Raster* object that has x coordinates (longitude) from 0 to 360,
@@ -46,7 +44,6 @@ anomaly <- function(r, clima){
4644

4745
anomaly_map_cat <- r
4846
for (i in 1:raster::nlayers(r)){
49-
print(i)
5047
rx <- r[[i]]
5148
# Get the forecast dates
5249
forecast_date <- substr(x = names(rx), start = 7, stop = 11)

R/decompress_gz.R

Lines changed: 0 additions & 25 deletions
This file was deleted.

R/deprecated.R

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
#' @title decompress_gz (DEPRECATED)
2+
#'
3+
#' @description This function decompresses all .gz files in a given folder
4+
#'
5+
#' @param input_dir directory path where all the files to read have been stored
6+
#'
7+
#' @export
8+
#'
9+
#' @examples
10+
#' \dontrun{
11+
#' decompress_gz(input_dir = "/var/tmp/moc0/forestfire/")
12+
#' }
13+
#'
14+
15+
decompress_gz <- function(input_dir = getwd()){
16+
17+
.Deprecated()
18+
message(paste("NOTE: Since GEFF v2.2 this function is no longer needed.",
19+
"It is now deprecated and",
20+
"will be removed in the next release."))
21+
22+
list_of_gzfiles <- list.files(path = input_dir,
23+
pattern = "*.gz", full.names = TRUE)
24+
25+
# Decompress any gz files
26+
for (i in seq_along(list_of_gzfiles)){
27+
28+
R.utils::gunzip(list_of_gzfiles[i], overwrite = TRUE)
29+
30+
}
31+
32+
}
33+
34+
35+
#' @title import_geff_data_from_tar (DEPRECATED)
36+
#'
37+
#' @description This function imports GEFF data (reanalysis or realtime) from a
38+
#' tar file into a raster stack. Depending on the user's query to the web
39+
#' portal, the stack can contain different variables.
40+
#'
41+
#' @param archive file path to the tar file
42+
#' @param stack_ncfiles logical (TRUE by default) variable to decided wheteher
43+
#' decompressed nc files should be stacked or not.
44+
#'
45+
#' @export
46+
#'
47+
#' @return If \code{stack_ncfiles} is TRUE, the function returns a RasterBrick.
48+
#' If \code{stack_ncfiles} is FALSE, it returns the list of uncompressed files.
49+
#'
50+
#' @examples
51+
#' \dontrun{
52+
#' s <- import_geff_data_from_tar(archive = "test.tar")
53+
#' }
54+
#'
55+
56+
import_geff_data_from_tar <- function(archive, stack_ncfiles = TRUE){
57+
58+
.Deprecated()
59+
message(paste("NOTE: Since GEFF v2.2 this function is no longer needed.",
60+
"It is now deprecated and",
61+
"will be removed in the next release."))
62+
63+
# From .tar to .gz, and finally to .nc
64+
my_temp_dir <- tempdir()
65+
list_of_gzfiles <- file.path(my_temp_dir, utils::untar(tarfile = archive,
66+
exdir = my_temp_dir,
67+
list = TRUE))
68+
69+
# Untar files
70+
utils::untar(tarfile = archive, exdir = my_temp_dir)
71+
72+
# Decompress any gz files
73+
for (i in seq_along(list_of_gzfiles)){
74+
75+
R.utils::gunzip(list_of_gzfiles[i])
76+
77+
}
78+
79+
if (stack_ncfiles == TRUE){
80+
81+
s <- raster::stack(tools::file_path_sans_ext(list_of_gzfiles))
82+
83+
return(raster::brick(s))
84+
85+
} else {
86+
87+
return(tools::file_path_sans_ext(list_of_gzfiles))
88+
89+
}
90+
91+
}
92+
93+
94+
#' @title mean_percs (DEPRECATED)
95+
#'
96+
#' @description Calculate average percentile
97+
#'
98+
#' @param vals is the a raster object
99+
#' @param perc_val is the percentile value used as a threshold
100+
#' @param mod defines if the values considered for the mean are above ("gt") or
101+
#' below ("lt") the threshold
102+
#'
103+
#' @export
104+
#'
105+
106+
mean_percs <- function(vals, perc_val, mod){
107+
108+
.Deprecated()
109+
message(paste("NOTE: Since GEFF v2.2 this function is no longer needed.",
110+
"It is now deprecated and",
111+
"will be removed in the next release."))
112+
113+
.Deprecated(msg = "This function is deprecated.")
114+
115+
p_val <- stats::quantile(vals, perc_val / 100, na.rm = TRUE)
116+
117+
if (mod == "gt") {
118+
119+
v_perc <- vals[vals >= p_val]
120+
121+
} else if (mod == "lt") {
122+
123+
v_perc <- vals[vals <= p_val]
124+
125+
} else {
126+
127+
stop("mod should be 'lt' or 'gt'")
128+
129+
}
130+
131+
return(mean(v_perc, na.rm = TRUE))
132+
133+
}
134+
135+
136+
#' @title stack_netcdf_files (DEPRECATED)
137+
#'
138+
#' @description This function merges all the netcdf files in a given directory
139+
#' over the time dimension. It saves the merged file in the working directory.
140+
#'
141+
#' @param input_dir is the directory where all the files to read are stored
142+
#' @param varname name of the variable to extract
143+
#' @param pattern regular expression pattern to select a subset of files
144+
#' @param recursive logical (TRUE by default). If set to TRUE it looks in
145+
#' folders and subfolders
146+
#' @param output_file output filename (including path)
147+
#'
148+
#' @export
149+
#'
150+
#' @examples
151+
#' \dontrun{
152+
#' # Mergetime using single variable nc files
153+
#' stack_netcdf_files(input_dir = "/var/tmp/moc0/forestfire",
154+
#' varname = NULL,
155+
#' pattern = "geff_reanalysis_an_fwis_fwi_",
156+
#' recursive = TRUE,
157+
#' output_file = "outfile.nc")
158+
#' }
159+
#'
160+
161+
stack_netcdf_files <- function(input_dir = NULL,
162+
varname = NULL,
163+
pattern = NULL,
164+
recursive = FALSE,
165+
output_file = NULL){
166+
167+
.Deprecated("raster::stack()")
168+
message(paste("NOTE: Since GEFF v2.2 this function is no longer needed.",
169+
"It is now deprecated and",
170+
"will be removed in the next release."))
171+
172+
if (is.null(input_dir)) stop("Please specify data folder 'input_dir'!")
173+
174+
ifiles <- list.files(path = input_dir,
175+
pattern = pattern,
176+
recursive = recursive,
177+
full.names = TRUE)
178+
179+
if (is.null(output_file)) output_file <- tempfile(fileext = ".nc")
180+
181+
if (is.null(varname)) varname <- ""
182+
s <- raster::stack(x = ifiles, varname = varname)
183+
184+
if (!is.null(output_file)) {
185+
raster::writeRaster(s, filename = output_file,
186+
format = "CDF", overwrite = TRUE)
187+
}
188+
189+
return(s)
190+
191+
}

0 commit comments

Comments
 (0)