Skip to content

Commit bd9faae

Browse files
*.nc changed tempfile()
1 parent c3906ef commit bd9faae

File tree

2 files changed

+67
-2
lines changed

2 files changed

+67
-2
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#Test the extraction of data
2+
test_that("netCDF grid can be created",
3+
{
4+
5+
Sys.setenv(R_TESTS="")
6+
7+
expect_no_error(
8+
{
9+
# Set dates for building netCDFs and extracting data from yesterday to one week ago.
10+
startDate = as.Date("2010-08-01","%Y-%m-%d")
11+
endDate = as.Date("2010-09-30","%Y-%m-%d")
12+
13+
# define temp direcory for netCDF files
14+
fdir = tempdir()
15+
setwd(fdir)
16+
17+
# Set names for netCDF files (in the system temp. directory).
18+
ncdfFilename = tempfile(fileext = '.nc')
19+
ncdfSolarFilename = tempfile(fileext = '.nc')
20+
21+
# Build netCDF grids for all data but only over the defined time period.
22+
file.names = makeNetCDF_file(ncdfFilename=ncdfFilename,
23+
ncdfSolarFilename=ncdfSolarFilename,
24+
updateFrom=startDate, updateTo=endDate)
25+
},
26+
message='Testing creaion of two month netCDF grids.'
27+
)
28+
29+
expect_no_error(
30+
{
31+
# Load example catchment boundaries.
32+
data("catchments")
33+
34+
# Extract catchment average monthly data P for Bet Bet Creek.
35+
climateData= extractCatchmentData(ncdfFilename=ncdfFilename,
36+
ncdfSolarFilename=ncdfSolarFilename,
37+
extractFrom=startDate, extractTo=endDate,
38+
locations=catchments[1,],
39+
getTmin = F, getTmax = F, getVprp = F, getSolarrad = F, getET = F,
40+
temporal.timestep = 'monthly', temporal.function.name = 'sum',
41+
spatial.function.name='var');
42+
},
43+
message='Testing extraction of P monthly data.'
44+
)
45+
46+
# expect_no_error(
47+
# {
48+
# # Load the ET constants
49+
# data(constants,package='Evapotranspiration')
50+
#
51+
# # Extract catchment average data for Bet Bet Creek with
52+
# # the Mortons CRAE estimate of potential ET.
53+
# climateData= extractCatchmentData(ncdfFilename=ncdfFilename,
54+
# ncdfSolarFilename=ncdfSolarFilename,
55+
# extractFrom=startDate, extractTo=endDate,
56+
# locations=catchments[1,],
57+
# temporal.timestep = 'monthly', temporal.function.name = 'sum',
58+
# spatial.function.name='var',
59+
# ET.function='ET.MortonCRAE',
60+
# ET.timestep='monthly', ET.constants=constants);
61+
# },
62+
# message='Testing extraction of P monthly and PET data.'
63+
# )
64+
}
65+
)

tests/testthat/test-makeNetCDF_file.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ test_that("netCDF grid can be created",
1414
setwd(fdir)
1515

1616
# Set names for netCDF files (in the system temp. directory).
17-
ncdfFilename = 'data.nc'
18-
ncdfSolarFilename = 'solar.nc'
17+
ncdfFilename = tempfile(fileext = '.nc')
18+
ncdfSolarFilename = tempfile(fileext = '.nc')
1919

2020
# Build netCDF grids for all data but only over the defined time period.
2121
file.names = makeNetCDF_file(ncdfFilename=ncdfFilename,

0 commit comments

Comments
 (0)