snowmodelina: Create object of class microsnowin with weather data as an...

View source: R/microclimatemodel.R

snowmodelinaR Documentation

Create object of class microsnowin with weather data as an array

Description

The function snowmodelina creates an object of class microsnowin which unpacks various component inputs and reformats as required for running the model in hourly timesteps. Here it is assumed that the input weather data are as arrays - i.e. variable in space

Usage

snowmodelina(
  climarray,
  precarray,
  tme,
  r,
  altcorrect = 0,
  snow,
  STparams,
  dtm,
  pai,
  hgt,
  x,
  clump,
  windhgt = 2
)

Arguments

climarray

a list of arrays of weather variables (see details). See also nctoarray()

precarray

an array of daily precipitation (see details)

tme

an object of class POSIXlt giving the dates and times for each weather variable stroed in the array

r

a SpatRaster object giving the resolution, spatial extent, and projection of the weather data (see details)

altcorrect

a single numeric value indicating whether to apply an elevational lapse rate correction to temperatures (0 = no correction, 1 = fixed lapse rate correction, 2 = humidity-dependent variable lapse rate correction, see details)

snow

an object of class snow as created by modelsnowdepth()

STparams

now temperature model coefficients as derived by fitsnowtemp()

dtm

a SpatRaster object of elevations (see details)

pai

a single numeric value, matrix, SpatRast or array of plant area idex values.

hgt

ackedSpatRaster or SpatRast of vegetation heights

x

optional single numeric value, SpatRast, matrix or array of leaf angle coefficients (see details)

clump

a single numeric value or array of values between 0 and 1 indicating the fraction of radiation passing through larger gaps in the canopy,

windhgt

height above round of wind speed measurement (m)

Details

The units of climarray must follow those in the dataset climdata. It must be a list with each component of the list an array, named using the same names as the column headers in weather (e.g. temp for temperature), excluding obs_time. Dimensions 1 and 2 of the array must be the same as r and dimension 3 must have the same length as tme. If r has a different resolution to dtm the climate data are resampled to match the resolution of dtm. The array of Plant Area index values in vegp must of the same x and y dims as dtm but can contain any number of repeated measures up to the number of entries in tme. Data are interpolated to the time increment of tme. Other vegetation paramaters, including vegetation height are assumed time-invarient. The SpatRaster datasets in soilc must have the same x and y dims as dtm. The x,y and z units of dtm must be all be in meters and the coordinate reference system must be defined. If altcorrect>0, and the dimensions of r are not identical to those of dtm, the elevation difference between each pixel of the dtm and the dtm coarsened to the resolution of r is calculated and an elevational lapse rate correction is applied to the temperature data to accoutn for these elevation differences. If altcorrect=1, a fixed lapse rate of 5 degrees per 100m is applied. If altcorrect=2, humidity-dependent lapse rates are calculate and applied.

Value

an object of class microsnowin used by runmicrosnow_hr()

Examples

## Not run: 
if(interactive()){
 require(terra)
 require(NicheMapR)
 tme<-as.POSIXlt(climdata$obs_time,tz="UTC")
sel<-which(tme$mon+1 == 4 & tme$year+1900==2018)
weather<-climdata[sel,]
tmed<-as.POSIXlt(c(0:546)*24*3600,origin="2017-10-02",tz="UTC")
sel<-which(tmed$mon+1 == 4 & tmed$year+1900==2018)
precapr<-microsnow::precd[sel]
# Derive estimates of snow melt temperature parameters using NicheMapR
nmrout<-runNMRSnow(weather,precapr,66.215,29.293,ALTT = 360)
STparams<-fitsnowtemp(weather,precapr,nmrout$SNOWDEP,nmrout$SNOWTEMP)
meltfact<-fitsnowdepth(weather,nmrout$SNOWDEP,precapr,STparams=STparams)$meltfact
# Run snow model with defaults (takes 20 seconds)
snowdepth<-nmrout$SNOWDEP
snow<-modelsnowdepth(weather,precapr,snowdepth,dtm,pai,hgt,STparams,meltfact,spatial=T)
# ======== Create dummy array datasets ========= #
# ~~ Function to turn vector into 5 x 5 array ~~ #
toarray<-function(x,xdim=5,ydim=5) {
  xl<-rep(x,each=ydim*xdim)
  xl<-array(xl,dim=c(ydim,xdim,length(x)))
  xl
}
# ~~ Create list of climate variable arrays ~~ #
climarray<-list(temp=toarray(weather$temp),
                relhum=toarray(weather$relhum),
                pres=toarray(weather$pres),
                swrad=toarray(weather$swrad),
                difrad=toarray(weather$difrad),
                skyem=toarray(weather$skyem),
                windspeed=toarray(weather$windspeed),
                winddir=toarray(weather$winddir))
# ~~ Create precipitation array ~~ #
precarray<-toarray(precapr)
# ~~ Create other variables ~~ #
tme<-as.POSIXlt(weather$obs_time)
microsnow<-snowmodelina(climarray,precarray,tme,r,altcorrect=0,snow,STparams,dtm,pai,hgt,x,clump,windhgt=2)
 }

## End(Not run)

ilyamaclean/microsnow documentation built on April 7, 2023, 8:55 a.m.