soilQuery merge

This commit is contained in:
Roland Hollós 2020-05-13 11:01:55 +02:00
parent 9852ccbc17
commit 557aca40c2
24 changed files with 253 additions and 174 deletions

View File

@ -7,6 +7,7 @@ export(cleanupMuso)
export(compareMuso)
export(copyMusoExampleTo)
export(corrigMuso)
export(createSoilFile)
export(getAnnualOutputList)
export(getDailyOutputList)
export(getMeteoData1BGC)
@ -68,7 +69,12 @@ importFrom(ggplot2,theme)
importFrom(ggplot2,theme_classic)
importFrom(ggplot2,xlab)
importFrom(ggplot2,ylab)
importFrom(glue,glue)
importFrom(gridExtra,grid.arrange)
importFrom(httr,GET)
importFrom(httr,config)
importFrom(httr,content)
importFrom(httr,with_config)
importFrom(jsonlite,write_json)
importFrom(limSolve,xsample)
importFrom(lubridate,leap_year)
@ -85,6 +91,7 @@ importFrom(openxlsx,read.xlsx)
importFrom(rmarkdown,pandoc_version)
importFrom(rmarkdown,render)
importFrom(scales,percent)
importFrom(stats,approx)
importFrom(tcltk,tk_choose.dir)
importFrom(tcltk,tk_choose.files)
importFrom(tibble,rownames_to_column)

63
RBBGCMuso/R/recent.soi Normal file
View File

@ -0,0 +1,63 @@
SOILPROP FILE - lat: 60, lon: 50, created in: Mon Apr 20 10:44:56 2020
----------------------------------------------------------------------------------------
NITROGEN AND DECOMPOSITION PARAMETERS
0.1 (prop.) denitrification rate per g of CO2 respiration of SOM
0.2 (prop.) nitrification coefficient 1
0.07 (prop.) nitrification coefficient 2
0.02 (prop.) coefficient of N2O emission of nitrification
0.1 (prop.) NH4 mobilen proportion
1.0 (prop.) NO3 mobilen proportion
10 (m) e-folding depth of decomposition rate's depth scalar
0.002 (prop.) fraction of dissolved part of SOIL1 organic matter
0.002 (prop.) fraction of dissolved part of SOIL2 organic matter
0.002 (prop.) fraction of dissolved part of SOIL3 organic matter
0.002 (prop.) fraction of dissolved part of SOIL4 organic matter
0.1 (prop.) minimum WFPS for scalar of nitrification calculation
0.45 (prop.) lower optimum WFPS for scalar of nitrification calculation
0.55 (prop.) higher optimum WFPS for scalar of nitrification calculation
0.2 (prop.) minimum value for saturated WFPS scalar of nitrification calculation
10 (ppm) critical value of dissolved N and C in bottom (inactive layer)
----------------------------------------------------------------------------------------
RATE SCALARS
0.35 (prop) respiration fractions for fluxes between compartments (l1s1)
0.50 (prop) respiration fractions for fluxes between compartments (l2s2)
0.26 (prop) respiration fractions for fluxes between compartments (l4s3)
0.25 (prop) respiration fractions for fluxes between compartments (s1s2)
0.41 (prop) respiration fractions for fluxes between compartments (s2s3)
0.50 (prop) respiration fractions for fluxes between compartments (s3s4)
0.7 (1/day) rate constant scalar of labile litter pool
0.07 (1/day) rate constant scalar of cellulose litter pool
0.014 (1/day) rate constant scalar of lignin litter pool
0.07 (1/day) rate constant scalar of fast microbial recycling pool
0.014 (1/day) rate constant scalar of medium microbial recycling pool
0.0014 (1/day) rate constant scalar of slow microbial recycling pool
0.0001 (1/day) rate constant scalar of recalcitrant SOM (humus) pool
0.001 (1/day) rate constant scalar of physical fragmentation of coarse woody debris
----------------------------------------------------------------------------------------
CH4 PARAMETERS
212.5 (DIM) soil CH4 emission bulk density dependence parameter1
1.81 (DIM) soil CH4 emission bulk density dependence parameter2
-1.353 (DIM) soil CH4 emission soil water content dependence parameter1
0.2 (DIM) soil CH4 emission soil water content dependence parameter2
2 (DIM) soil CH4 emission soil water content dependence parameter3
6.786 (DIM) soil CH4 emission soil water content dependence parameter4
0.010 (DIM) soil CH4 emission soil temperature dependence parameter1
----------------------------------------------------------------------------------------
SOIL PARAMETERS
2 (m) depth of soil
6 (mm)42 42 43 47 48 49 49 49 51 51 limit of first stage evaporation
20.00 (mm) maximum height of pond water
1 (dimless) curvature of soil stress function
-9999 (dimless) measured runoff curve number (-9999: no measured data, model estimation)
----------------------------------------------------------------------------------------
SOIL COMPOSITION AND CHARACTERISTIC VALUES (-9999: no measured data)
30.0 30.0 30.0 30.0 30.0 30.0 30.0 30.0 30.0 30.0 (%) sand percentage by volume in rock-free soil
50.0 50.0 50.0 50.0 50.0 50.0 50.0 50.0 50.0 50.0 (%) silt percentage by volume in rock-free soil
7.0 7.0 7.0 7.0 7.0 7.0 7.0 7.0 7.0 7.0 (dimless) soil pH (dimless) measured runoff curve number
-9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 (g/cm3) bulk density
-9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 (m3/m3) SWC at saturation
-9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 (m3/m3) SWC at field capacity
-9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 (m3/m3) SWC at wilting point
-9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 (m3/m3) SWC at hygroscopic water content
-9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 (dimless) drainage coefficient
-9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 (cm/day) hydraulic condictivity at saturation

64
RBBGCMuso/R/soilQuery.R Normal file
View File

@ -0,0 +1,64 @@
#' getSoilDataFull
#'
#' This function collects soil data from a given restapi, de default is soilGrid
#'
#' @author Roland HOLLÓS
#' @name getSoilDataFull
#' @importFrom glue glue
#' @importFrom httr config with_config GET content
getSoilDataFull <- function(lat, lon, apiURL, port) {
if(missing(apiURL)){
apiURL <- "https://81.169.232.36"
}
if(missing(port)){
port <- 4445
}
apiString <- glue("{apiURL}:{port}/query?lon={lon}&lat={lat}")
soilREST <- with_config(config(ssl_verifypeer=0L, ssl_verifyhost=0L),
GET(apiString)) # This is temporary solution ssl_verification wont bypass
content(soilREST)
}
#' createSoilFile
#'
#' This function collects soil data from a given restapi, de default is soilGrid
#'
#' @author Roland HOLLOS
#' @name createSoilFile
#' @importFrom glue glue
#' @importFrom stats approx
#' @importFrom magrittr '%>%'
#' @export
createSoilFile <- function(lat,lon,
outputFile="recent.soi",
method="constant",apiURL,
apiPort,template=system.file("examples/hhs/hhs.soi",package="RBBGCMuso")) {
if(missing(apiURL)){
apiURL <- "https://81.169.232.36"
}
if(missing(apiPort)){
apiPort <- 4445
}
outFile <- suppressWarnings(readLines(template))
outFile[1] <- sprintf("SOILPROP FILE - lat: %s, lon: %s, created in: %s",lat,lon,date())
musoCenters <- c(1.5,6.5,20.0,45.0,75.0,105.0,135.0,175.0,300.0,700.0)
soilGridDepths <- c(0,5,15,30,60,100,200)
rest<- getSoilDataFull(lat,lon, apiURL, apiPort)
if(rest$properties$soilmask=="nodata"){
stop("There is no data for the given coordinates");
}
createMusoLayers <- function(values,depths=soilGridDepths,centers=musoCenters,intMethod=method){
approx(x=depths,y=values, xout = centers, method=intMethod,rule=2)$y %>%
paste(.,collapse="\t") %>% paste0(.," ")
}
soilDepth <- unlist(rest$properties$BDRICM$M)/100
outFile[42] <- sub("([0-9.]*\\s+){1}",paste0(soilDepth," "),outFile[42], outFile[42])
outFile[48] <- sub("([0-9.]*\\s+){10}",createMusoLayers(unlist(rest$properties$SNDPPT$M)),outFile[48])
outFile[49] <- sub("([0-9.]*\\s+){10}",createMusoLayers(unlist(rest$properties$SLTPPT$M)),outFile[49])
outFile[50] <- sub("([0-9.]*\\s+){10}",createMusoLayers(unlist(rest$properties$PHIHOX$M)/10),outFile[50])
writeLines(outFile,outputFile)
}
# createSoilFile(60,50)

37
RBBGCMuso/algo.md Normal file
View File

@ -0,0 +1,37 @@
---
title: "An easy grouping algorithm"
author: "Hollós Roland"
date: "10/1/2019"
output: pdf_document
---
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```r
summary(cars)
```
```
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
```
## Including Plots
You can also embed plots, for example:
![plot of chunk pressure](figure/pressure-1.png)
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

View File

@ -4,16 +4,9 @@
\alias{alignData}
\title{alignData}
\usage{
alignData(
mdata,
dataCol,
modellSettings = NULL,
startDate = NULL,
endDate = NULL,
formatString = "\%Y-\%m-\%d",
leapYear = TRUE,
continious = FALSE
)
alignData(mdata, dataCol, modellSettings = NULL, startDate = NULL,
endDate = NULL, formatString = "\%Y-\%m-\%d", leapYear = TRUE,
continious = FALSE)
}
\description{
This function align the data to the model and the model to the data

View File

@ -4,14 +4,8 @@
\alias{changemulline}
\title{This is the function which is capable to change multiple specific lines to others using their row numbers.}
\usage{
changemulline(
filePaths,
calibrationPar,
contents,
fileOut,
fileToChange,
modifyOriginal = FALSE
)
changemulline(filePaths, calibrationPar, contents, fileOut, fileToChange,
modifyOriginal = FALSE)
}
\description{
The function uses the previous changspecline function to operate.

View File

@ -4,12 +4,8 @@
\alias{checkMeteoBGC}
\title{checkMeteoBGC}
\usage{
checkMeteoBGC(
settings = NULL,
skip = 4,
numericReport = FALSE,
type = "normal"
)
checkMeteoBGC(settings = NULL, skip = 4, numericReport = FALSE,
type = "normal")
}
\arguments{
\item{settings}{The output of setupMuso}

View File

@ -4,15 +4,9 @@
\alias{compareMuso}
\title{compareMuso}
\usage{
compareMuso(
settings = NULL,
parameters,
variable = 1,
calibrationPar = NULL,
fileToChange = "epc",
skipSpinup = TRUE,
timeFrame = "day"
)
compareMuso(settings = NULL, parameters, variable = 1,
calibrationPar = NULL, fileToChange = "epc", skipSpinup = TRUE,
timeFrame = "day")
}
\arguments{
\item{settings}{RBBGCMuso uses variables that define the entire simulation environment. Those environment variables include the name of the INI files, the name of the meteorology files, the path to the model executable and its file name, the entire output list, the entire output variable matrix, the dependency rules for the EPC parameters etc. Using the runMuso function RBBGCMuso can automatically create those environment variables by inspecting the files in the working directory (this happens through the setupMuso function). It means that by default model setup is performed automatically in the background and the user has nothing to do. With this settings parameter we can force runMuso to skip automatic environment setup as we provide the environment settings to runMuso. In a typical situation the user can skip this option.}

View File

@ -0,0 +1,11 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/soilQuery.R
\name{createSoilFile}
\alias{createSoilFile}
\title{createSoilFile}
\description{
This function collects soil data from a given restapi, de default is soilGrid
}
\author{
Roland HOLLOS
}

View File

@ -4,24 +4,15 @@
\alias{getMeteoData1BGC}
\title{getMeteoData1BGC}
\usage{
getMeteoData1BGC(
startYear = 2017,
endYear = 2017,
lon = 18.8,
lat = 47.3,
timeOut = 7200,
monthList = sprintf("\%02d", 1:12),
dayList = sprintf("\%02d", 1:31),
hourList = sprintf("\%02d:00", 0:23),
destDir = NULL,
apiFile = NULL,
fileDir = NULL
)
getMeteoData1BGC(startYear = 2017, endYear = 2017, lon = 18.8,
lat = 47.3, timeOut = 7200, monthList = sprintf("\%02d", 1:12),
dayList = sprintf("\%02d", 1:31), hourList = sprintf("\%02d:00",
0:23), destDir = NULL, apiFile = NULL, fileDir = NULL)
}
\arguments{
\item{startYear}{Start year of the downloading data. It shall be greater than 1978.}
\item{endYear}{End year of the downloading data. It shall be smaller than 2019.}
\item{endYear}{End year of the downloading data. It shall be smaller than 2020.}
\item{lon}{Geographical longitude of the selected grid point (negative values: W, positive values: E). It shall be between -180 and 180. The value is rounded to two decimal places.}
@ -35,7 +26,7 @@ getMeteoData1BGC(
\item{hourList}{Hour selector (e.g. to download data for 00 UTC then write "00:00", to download data for 01 UTC and 15 UTC then write c("01","15")}
\item{destDir}{Directory where the mtc43 file will be created. If it is NULL then destDir is the same as fileDir.}
\item{destDir}{Directory where the wth file will be created. If it is NULL then destDir is the same as fileDir.}
\item{apiFile}{Directory where the cdsapirc file is located}

View File

@ -0,0 +1,11 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/soilQuery.R
\name{getSoilDataFull}
\alias{getSoilDataFull}
\title{getSoilDataFull}
\description{
This function collects soil data from a given restapi, de default is soilGrid
}
\author{
Roland HOLLÓS
}

View File

@ -4,14 +4,8 @@
\alias{musoDate}
\title{musoDate}
\usage{
musoDate(
startYear,
endYears = NULL,
numYears,
combined = TRUE,
leapYearHandling = FALSE,
prettyOut = FALSE
)
musoDate(startYear, endYears = NULL, numYears, combined = TRUE,
leapYearHandling = FALSE, prettyOut = FALSE)
}
\description{
This function generates MuSo compatibla dates for the data

View File

@ -4,26 +4,12 @@
\alias{musoMonte}
\title{musoMonte}
\usage{
musoMonte(
settings = NULL,
parameters = NULL,
inputDir = "./",
outLoc = "./calib",
iterations = 10,
preTag = "mont-",
outputType = "moreCsv",
fun = mean,
varIndex = 1,
outVars = NULL,
silent = TRUE,
skipSpinup = TRUE,
debugging = FALSE,
keepEpc = FALSE,
constrains = NULL,
skipZero = TRUE,
postProcString = NULL,
...
)
musoMonte(settings = NULL, parameters = NULL, inputDir = "./",
outLoc = "./calib", iterations = 10, preTag = "mont-",
outputType = "moreCsv", fun = mean, varIndex = 1, outVars = NULL,
silent = TRUE, skipSpinup = TRUE, debugging = FALSE,
keepEpc = FALSE, constrains = NULL, skipZero = TRUE,
postProcString = NULL, ...)
}
\arguments{
\item{settings}{A list of environmental variables for the Monte Carlo experiment. These settings are generated by the setupMuso function. By default the settings parameter is generated automatically.}

View File

@ -4,16 +4,9 @@
\alias{musoQuickEffect}
\title{musoQuickEffect}
\usage{
musoQuickEffect(
settings = NULL,
calibrationPar = NULL,
startVal,
endVal,
nSteps = 1,
fileToChange = "epc",
outVar,
parName = "parVal"
)
musoQuickEffect(settings = NULL, calibrationPar = NULL, startVal,
endVal, nSteps = 1, fileToChange = "epc", outVar,
parName = "parVal")
}
\arguments{
\item{settings}{RBBGCMuso uses variables that define the entire simulation environment. Those environment variables include the name of the INI files, the name of the meteorology files, the path to the model executable and its file name, the entire output list, the entire output variable matrix, the dependency rules for the EPC parameters etc. Using the runMuso function RBBGCMuso can automatically create those environment variables by inspecting the files in the working directory (this happens through the setupMuso function). It means that by default model setup is performed automatically in the background and the user has nothing to do. With this settings parameter we can force runMuso to skip automatic environment setup as we provide the environment settings to runMuso. In a typical situation the user can skip this option.}

View File

@ -4,7 +4,8 @@
\alias{musoRand}
\title{musoRand}
\usage{
musoRand(parameters, iterations = 3000, fileType = "epc", constrains = NULL)
musoRand(parameters, iterations = 3000, fileType = "epc",
constrains = NULL)
}
\arguments{
\item{parameters}{This is a dataframe (heterogeneous data-matrix), where the first column is the name of the parameter, the second is a numeric vector of the rownumbers of the given variable in the input EPC file, and the last two columns describe the minimum and the maximum of the parameter (i.e. the parameter ranges), defining the interval for the randomization.}

View File

@ -4,26 +4,13 @@
\alias{musoSensi}
\title{musoSensi}
\usage{
musoSensi(
monteCarloFile = NULL,
parameters = NULL,
settings = NULL,
inputDir = "./",
outLoc = "./calib",
outVars = NULL,
iterations = 30,
preTag = "mont-",
outputType = "moreCsv",
fun = mean,
varIndex = 1,
outputFile = "sensitivity.csv",
plotName = "sensitivity.png",
plotTitle = "Sensitivity",
skipSpinup = TRUE,
skipZero = TRUE,
postProcString = NULL,
dpi = 300
)
musoSensi(monteCarloFile = NULL, parameters = NULL, settings = NULL,
inputDir = "./", outLoc = "./calib", outVars = NULL,
iterations = 30, preTag = "mont-", outputType = "moreCsv",
fun = mean, varIndex = 1, outputFile = "sensitivity.csv",
plotName = "sensitivity.png", plotTitle = "Sensitivity",
skipSpinup = TRUE, skipZero = TRUE, postProcString = NULL,
dpi = 300)
}
\arguments{
\item{parameters}{This is a dataframe (heterogen data-matrix), which first column is the name of the parameters, the second is a numeric vector of the rownumbers of the given variable in the epc-fie, the last two column consist the endpont of the parameter-ranges, where the parameters will be randomized.}

View File

@ -4,27 +4,14 @@
\alias{optiMuso}
\title{optiMuso}
\usage{
optiMuso(
measuredData,
parameters = NULL,
startDate = NULL,
endDate = NULL,
formatString = "\%Y-\%m-\%d",
leapYearHandling = TRUE,
dataVar,
outLoc = "./calib",
preTag = "cal-",
settings = NULL,
outVars = NULL,
iterations = 30,
skipSpinup = TRUE,
constrains = NULL,
plotName = "calib.jpg",
likelihood = function(x, y) { exp(-sqrt(mean((x - y)^2))) },
continious,
modelVar = 3009,
postProcString = NULL
)
optiMuso(measuredData, parameters = NULL, startDate = NULL,
endDate = NULL, formatString = "\%Y-\%m-\%d",
leapYearHandling = TRUE, dataVar, outLoc = "./calib",
preTag = "cal-", settings = NULL, outVars = NULL,
iterations = 30, skipSpinup = TRUE, constrains = NULL,
plotName = "calib.jpg", likelihood = function(x, y) {
exp(-sqrt(mean((x - y)^2))) }, continious, modelVar = 3009,
postProcString = NULL)
}
\arguments{
\item{parameters}{b}

View File

@ -4,14 +4,9 @@
\alias{paramSweep}
\title{paramSweep}
\usage{
paramSweep(
inputDir = "./",
parameters = NULL,
outputDir = NULL,
iterations = 10,
outVar = "daily_gpp",
htmlOutName = "paramsweep.html"
)
paramSweep(inputDir = "./", parameters = NULL, outputDir = NULL,
iterations = 10, outVar = "daily_gpp",
htmlOutName = "paramsweep.html")
}
\arguments{
\item{inputDir}{The directory which contains the MuSo model's ini files}

View File

@ -4,13 +4,8 @@
\alias{randEpc}
\title{randEpc}
\usage{
randEpc(
parameterFile = "parameters.csv",
location = "./epcDir",
sourceEpc = "maize.epc",
iterations = 1000,
constrains = NULL
)
randEpc(parameterFile = "parameters.csv", location = "./epcDir",
sourceEpc = "maize.epc", iterations = 1000, constrains = NULL)
}
\arguments{
\item{parameterFile}{parameters.csv file location}

View File

@ -4,19 +4,11 @@
\alias{readObservedData}
\title{readMeasuredMuso}
\usage{
readObservedData(
inFile,
naString = NULL,
sep = ",",
leapYearHandling = TRUE,
convert.var = NULL,
convert.scalar = 1,
readObservedData(inFile, naString = NULL, sep = ",",
leapYearHandling = TRUE, convert.var = NULL, convert.scalar = 1,
convert.fun = (function(x) { x * convert.scalar }),
convert.file = NULL,
filterCol = NULL,
filterVal = 1,
selVar = NULL
)
convert.file = NULL, filterCol = NULL, filterVal = 1,
selVar = NULL)
}
\description{
MuSo data reader

View File

@ -4,15 +4,9 @@
\alias{saveAllMusoPlots}
\title{saveAllMusoPlots}
\usage{
saveAllMusoPlots(
settings = NULL,
plotName = ".png",
silent = TRUE,
type = "line",
outFile = "annual.csv",
colour = NULL,
skipSpinup = FALSE
)
saveAllMusoPlots(settings = NULL, plotName = ".png", silent = TRUE,
type = "line", outFile = "annual.csv", colour = NULL,
skipSpinup = FALSE)
}
\arguments{
\item{settings}{RBBGCMuso uses variables that define the entire simulation environment. Those environment variables include the name of the INI files, the name of the meteorology files, the path to the model executable and its file name, the entire output list, the entire output variable matrix, the dependency rules for the EPC parameters etc. Using the runMuso function RBBGCMuso can automatically create those environment variables by inspecting the files in the working directory (this happens through the setupMuso function). It means that by default model setup is performed automatically in the background and the user has nothing to do. With this settings parameter we can force runMuso to skip automatic environment setup as we provide the environment settings to runMuso. In a typical situation the user can skip this option.}

View File

@ -4,15 +4,8 @@
\alias{stampAndDir}
\title{stampAndCopy}
\usage{
stampAndDir(
outputLoc,
names,
stampDir,
wrongDir,
type = "output",
errorsign,
logfiles
)
stampAndDir(outputLoc, names, stampDir, wrongDir, type = "output",
errorsign, logfiles)
}
\arguments{
\item{outputLoc}{This is the location of the output files.}

View File

@ -4,7 +4,8 @@
\alias{updateMusoMapping}
\title{updateMusoMapping}
\usage{
updateMusoMapping(excelName, dest = "./", version = getOption("RMuso_version"))
updateMusoMapping(excelName, dest = "./",
version = getOption("RMuso_version"))
}
\arguments{
\item{excelName}{Name of the excelfile which contains the parameters}