Here we present a series of functions and code for facilitating the recreation of our multi-scale modeling work as part of Bat One Health. The functions described below enable the estimation of monthly Hendra virus prevalence within a region of eastern Australia from the years 2008 to 2019 at a spatial resolution of 5 km. Most of the functions are a series of helper functions used to allow for the attachment of environmental data to coordinates that are used in all of the component models. These environmental data can be currently found in a FigShare repository here.
The main script you will be working with to run this model is MultiScaleExample.Rmd
which is mainly concerned with small bits of setup for the running of the estimatePrevalence
function.
The boundaries of our study area are shown in the polygon designated below.
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"id": 1,
"properties": {
"ID": 0
},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[147.23671,-20.88779], [147.57085,-20.85158], [147.57696,-20.90067],
[147.95872,-20.85807], [147.96501,-20.90715], [148.39431,-20.85768],
[148.40082,-20.90673], [148.78224,-20.86139], [148.78893,-20.91043],
[149.17019,-20.8638], [149.17707,-20.91281], [149.55815,-20.8649],
[149.56522,-20.91388], [149.75571,-20.88944], [149.76288,-20.93841],
[149.90576,-20.91986], [149.913,-20.96884], [150.15113,-20.93751],
[150.15849,-20.98647], [150.30136,-20.96742], [150.30879,-21.01638],
[150.45168,-20.99714], [150.45919,-21.04609], [150.55446,-21.03316],
[150.56202,-21.08211], [150.60967,-21.07561], [150.61726,-21.12456],
[150.71259,-21.1115], [150.72023,-21.16045], [150.81558,-21.1473],
[150.82328,-21.19625], [150.96632,-21.17636], [150.97409,-21.2253],
[151.06946,-21.21194], [151.07729,-21.26088], [151.17268,-21.24743],
[151.18056,-21.29637], [151.22827,-21.28961], [151.23617,-21.33855],
[151.33162,-21.32497], [151.33958,-21.37391], [151.38731,-21.36708],
[151.3953,-21.41602], [151.44306,-21.40917], [151.45108,-21.45811],
[151.49884,-21.45124], [151.50689,-21.50019], [151.55468,-21.49329],
[151.56276,-21.54223], [151.61056,-21.53531], [151.62679,-21.63322],
[151.67463,-21.62627], [151.68278,-21.67522], [151.73063,-21.66825],
[151.747,-21.76617], [151.79489,-21.75917], [151.81134,-21.85711],
[151.85927,-21.85008], [151.88407,-21.99702], [151.93206,-21.98996],
[151.96533,-22.18595], [152.01341,-22.17885], [152.12272,-22.81642],
[152.17109,-22.80924], [152.18808,-22.9074], [152.23649,-22.9002],
[152.24502,-22.94928], [152.34186,-22.9348], [152.35044,-22.98388],
[152.39888,-22.97661], [152.40749,-23.02569], [152.45594,-23.01839],
[152.46459,-23.06748], [152.56152,-23.05281], [152.57893,-23.15097],
[152.62743,-23.1436], [152.63617,-23.19269], [152.68469,-23.18529],
[152.69346,-23.23437], [152.74199,-23.22695], [152.75961,-23.32513],
[152.80818,-23.31768], [152.81703,-23.36678], [152.86561,-23.3593],
[152.88338,-23.45749], [152.932,-23.44999], [152.94092,-23.49909],
[152.98956,-23.49156], [152.99852,-23.54066], [153.29034,-23.49503],
[153.29944,-23.54411], [153.49394,-23.51327], [153.50314,-23.56233],
[153.60039,-23.54678], [153.60965,-23.59584], [153.70692,-23.58021],
[153.71623,-23.62926], [153.81351,-23.61353], [153.82288,-23.66258],
[153.92018,-23.64676], [153.9296,-23.69581], [153.97826,-23.68787],
[153.98772,-23.73691], [154.03639,-23.72894], [154.04588,-23.77799],
[154.09457,-23.76999], [154.1041,-23.81904], [154.1528,-23.81102],
[154.16236,-23.86006], [154.21108,-23.85202], [154.23027,-23.95011],
[154.27903,-23.94204], [154.2983,-24.04014], [154.34709,-24.03204],
[154.36645,-24.13015], [154.41529,-24.12202], [154.44446,-24.2692],
[154.49336,-24.26103], [154.56194,-24.60458], [154.61099,-24.59636],
[154.69014,-24.98919], [154.6409,-24.99745], [154.68061,-25.19397],
[154.63126,-25.20223], [154.65113,-25.30053], [154.60173,-25.30878],
[154.62159,-25.4071], [154.57213,-25.41534], [154.58205,-25.46451],
[154.53256,-25.47273], [154.55239,-25.57109], [154.50284,-25.57931],
[154.51274,-25.6285], [154.46316,-25.63669], [154.5326,-25.98115],
[154.48284,-25.98936], [154.51267,-26.13705], [154.46283,-26.14525],
[154.48272,-26.24374], [154.43283,-26.25193], [154.46267,-26.39969],
[154.41269,-26.40788], [154.50254,-26.85136], [154.45233,-26.85956],
[154.49242,-27.05675], [154.54273,-27.04852], [154.61347,-27.39366],
[154.66395,-27.38538], [154.71491,-27.63195], [154.7655,-27.62362],
[154.79628,-27.77157], [154.84694,-27.76321], [154.96089,-28.30577],
[154.90996,-28.31419], [154.92035,-28.36353], [154.97131,-28.35511],
[155.00265,-28.50312], [154.95161,-28.51155], [155.00393,-28.75828],
[154.95276,-28.76672], [154.9842,-28.91478], [154.93294,-28.92321],
[154.9644,-29.0713], [154.91306,-29.07972], [154.93404,-29.17846],
[154.88263,-29.18687], [154.9036,-29.28562], [154.85213,-29.29402],
[154.86261,-29.3434], [154.81111,-29.35178], [154.82157,-29.40117],
[154.77003,-29.40953], [154.78048,-29.45892], [154.72891,-29.46727],
[154.74978,-29.56607], [154.69815,-29.5744], [154.72946,-29.72261],
[154.67774,-29.73094], [154.70907,-29.87917], [154.65726,-29.88749],
[154.67815,-29.98632], [154.62628,-29.99463], [154.64716,-30.09347],
[154.59523,-30.10176], [154.62655,-30.25004], [154.57453,-30.25832],
[154.58497,-30.30775], [154.53292,-30.31602], [154.56421,-30.46432],
[154.51207,-30.47258], [154.53294,-30.57146], [154.48073,-30.57971],
[154.50159,-30.67859], [154.44932,-30.68683], [154.50152,-30.93406],
[154.44911,-30.94229], [154.48048,-31.09064], [154.42798,-31.09887],
[154.45937,-31.24722], [154.40678,-31.25544], [154.42771,-31.35435],
[154.37505,-31.36255], [154.39597,-31.46147], [154.34325,-31.46966],
[154.36416,-31.56858], [154.31138,-31.57676], [154.33228,-31.67568],
[154.27943,-31.68385], [154.30032,-31.78278], [154.24741,-31.79093],
[154.26829,-31.88986], [154.21531,-31.898], [154.23618,-31.99694],
[154.18314,-32.00506], [154.19357,-32.05453], [154.14049,-32.06264],
[154.1509,-32.11211], [154.09778,-32.1202], [154.11857,-32.21916],
[154.06539,-32.22723], [154.07578,-32.27671], [154.02256,-32.28476],
[154.04331,-32.38373], [153.99003,-32.39177], [154.00039,-32.44125],
[153.94707,-32.44928], [153.95742,-32.49876], [153.90407,-32.50677],
[153.93509,-32.65523], [153.88164,-32.66323], [153.90233,-32.7622],
[153.84881,-32.77018], [153.86948,-32.86916], [153.8159,-32.87713],
[153.82623,-32.92661], [153.77261,-32.93456], [153.79323,-33.03355],
[153.73955,-33.04148], [153.74985,-33.09097], [153.69613,-33.09889],
[153.70641,-33.14838], [153.65265,-33.15628], [153.66292,-33.20578],
[153.55532,-33.22151], [153.56554,-33.27102], [153.51169,-33.27885],
[153.5219,-33.32836], [153.41412,-33.34398], [153.42428,-33.39349],
[153.31641,-33.40902], [153.32652,-33.45854], [153.27254,-33.46627],
[153.28264,-33.51579], [153.22862,-33.52351], [153.2387,-33.57303],
[153.18465,-33.58073], [153.19471,-33.63025], [153.08652,-33.64559],
[153.09653,-33.69512], [152.98824,-33.71038], [152.99821,-33.75991],
[152.83563,-33.78264], [152.84552,-33.83218], [152.79127,-33.83971],
[152.81103,-33.93879], [152.75672,-33.94631], [152.76659,-33.99585],
[152.71224,-34.00335], [152.72209,-34.0529], [152.6677,-34.06038],
[152.69722,-34.209], [152.64274,-34.21647], [152.66241,-34.31554],
[152.60786,-34.323], [152.62752,-34.42207], [152.5729,-34.42951],
[152.58272,-34.47904], [152.52807,-34.48646], [152.53786,-34.536],
[152.48317,-34.5434], [152.50274,-34.64247], [152.44798,-34.64986],
[152.45775,-34.69939], [152.34814,-34.7141], [152.35786,-34.76364],
[152.30301,-34.77096], [152.31271,-34.8205], [152.25783,-34.82781],
[152.26751,-34.87734], [152.15765,-34.89189], [152.16729,-34.94144],
[152.05733,-34.9559], [152.06692,-35.00545], [151.90182,-35.02698],
[151.91133,-35.07653], [151.69097,-35.10493], [151.70037,-35.15449],
[151.20376,-35.21707], [151.19463,-35.16747], [150.97382,-35.19466],
[150.96482,-35.14505], [150.79921,-35.16519], [150.79031,-35.11556],
[150.67992,-35.12887], [150.6711,-35.07923], [150.61592,-35.08584],
[150.60714,-35.0362], [150.49682,-35.04935], [150.4881,-34.99969],
[150.43296,-35.00623], [150.42429,-34.95657], [150.31404,-34.96957],
[150.30544,-34.9199], [150.25033,-34.92636], [150.24177,-34.87668],
[150.18668,-34.88312], [150.17816,-34.83344], [150.1231,-34.83984],
[150.11461,-34.79015], [150.05957,-34.79654], [150.05112,-34.74684],
[149.99611,-34.7532], [149.9793,-34.65379], [149.92434,-34.66011],
[149.91598,-34.6104], [149.86104,-34.6167], [149.84441,-34.51726],
[149.78952,-34.52353], [149.77298,-34.42408], [149.71815,-34.43032],
[149.6935,-34.2811], [149.63875,-34.28731], [149.54134,-33.69019],
[149.59574,-33.68402], [149.5715,-33.5347], [149.62581,-33.52852],
[149.60964,-33.42896], [149.66387,-33.42276], [149.64768,-33.32321],
[149.70185,-33.31699], [149.69373,-33.26722], [149.74787,-33.26098],
[149.73161,-33.16143], [149.78568,-33.15518], [149.77753,-33.1054],
[149.83157,-33.09913], [149.71806,-32.40216], [149.77168,-32.39591],
[149.75555,-32.29633], [149.80911,-32.29007], [149.79295,-32.19049],
[149.84645,-32.18421], [149.83027,-32.08463], [149.8837,-32.07834],
[149.8756,-32.02855], [149.92899,-32.02223], [149.91276,-31.92267],
[149.96609,-31.91634], [149.95795,-31.86655], [150.01125,-31.8602],
[150.0031,-31.81042], [150.05635,-31.80405], [150.04818,-31.75428],
[150.15462,-31.74148], [150.1464,-31.69171], [150.19958,-31.68528],
[150.19134,-31.63551], [150.29763,-31.62259], [150.28934,-31.57283],
[150.39554,-31.55983], [150.38721,-31.51007], [150.49332,-31.49699],
[150.48494,-31.44724], [150.74994,-31.41416], [150.74143,-31.36443],
[151.11193,-31.31721], [151.10323,-31.2675], [151.1561,-31.26067],
[151.13868,-31.16126], [151.19149,-31.15442], [151.16535,-31.00531],
[151.21807,-30.99846], [151.19193,-30.84936], [151.24455,-30.84249],
[151.22712,-30.74311], [151.27968,-30.73622], [151.25352,-30.58715],
[151.30599,-30.58026], [151.23641,-30.18277], [151.28866,-30.17588],
[151.22808,-29.82813], [151.28013,-29.82124], [151.25422,-29.67223],
[151.20225,-29.6791], [151.15938,-29.43073], [151.10753,-29.43756],
[151.082,-29.28854], [151.03022,-29.29533], [151.00485,-29.14631],
[150.95315,-29.15307], [150.93633,-29.05372], [150.88467,-29.06046],
[150.85959,-28.91143], [150.80801,-28.91813], [150.79969,-28.86845],
[150.74813,-28.87513], [150.73157,-28.77577], [150.68005,-28.78242],
[150.67181,-28.73274], [150.62031,-28.73936], [150.61211,-28.68968],
[150.56063,-28.69627], [150.55246,-28.64659], [150.501,-28.65316],
[150.48474,-28.55379], [150.43332,-28.56033], [150.42523,-28.51064],
[150.37383,-28.51716], [150.36577,-28.46747], [150.3144,-28.47396],
[150.30637,-28.42427], [150.25501,-28.43073], [150.24703,-28.38104],
[150.19569,-28.38748], [150.17979,-28.28809], [150.1285,-28.2945],
[150.12059,-28.24481], [150.06931,-28.25119], [150.06143,-28.2015],
[150.01018,-28.20786], [150.00234,-28.15816], [149.9511,-28.1645],
[149.93549,-28.0651], [149.8843,-28.07141], [149.86878,-27.97201],
[149.81763,-27.97829], [149.80991,-27.92859], [149.75878,-27.93484],
[149.74341,-27.83545], [149.69233,-27.84167], [149.68469,-27.79197],
[149.63362,-27.79817], [149.6184,-27.69878], [149.56739,-27.70495],
[149.55225,-27.60555], [149.50128,-27.61169], [149.48623,-27.5123],
[149.4353,-27.51841], [149.42033,-27.41902], [149.36945,-27.42511],
[149.3397,-27.22635], [149.28892,-27.2324], [149.19342,-26.58668],
[149.24387,-26.58068], [149.22194,-26.43175], [149.27231,-26.42573],
[149.25767,-26.32647], [149.30798,-26.32044], [149.29333,-26.2212],
[149.34359,-26.21516], [149.32891,-26.11594], [149.37911,-26.10988],
[149.36441,-26.01068], [149.41456,-26.00461], [149.4072,-25.95502],
[149.45731,-25.94893], [149.44993,-25.89935], [149.50001,-25.89324],
[149.49261,-25.84366], [149.54267,-25.83754], [149.52784,-25.73841],
[149.57784,-25.73227], [149.57042,-25.68271], [149.62038,-25.67656],
[149.61294,-25.62701], [149.66287,-25.62083], [149.64052,-25.47222],
[149.69037,-25.46604], [149.67545,-25.36698], [149.62565,-25.37316],
[149.61823,-25.32364], [149.56844,-25.32979], [149.56105,-25.28026],
[149.51129,-25.28639], [149.49658,-25.18735], [149.44685,-25.19344],
[149.43954,-25.14393], [149.38983,-25.15], [149.38255,-25.10048],
[149.33286,-25.10653], [149.3256,-25.05701], [149.27594,-25.06304],
[149.26871,-25.01352], [149.21906,-25.01952], [149.21187,-24.97001],
[149.16224,-24.97598], [149.15508,-24.92647], [149.10547,-24.93242],
[149.09834,-24.8829], [149.04875,-24.88883], [149.04165,-24.83932],
[148.99208,-24.84522], [148.98501,-24.79571], [148.93545,-24.80159],
[148.92842,-24.75208], [148.87888,-24.75793], [148.87188,-24.70842],
[148.82236,-24.71425], [148.81539,-24.66474], [148.76589,-24.67055],
[148.75895,-24.62104], [148.70947,-24.62682], [148.70256,-24.57731],
[148.6531,-24.58307], [148.64622,-24.53356], [148.59678,-24.5393],
[148.58993,-24.48979], [148.49107,-24.50119], [148.48428,-24.45168],
[148.43487,-24.45735], [148.42811,-24.40784], [148.37872,-24.41348],
[148.37199,-24.36398], [148.32261,-24.3696], [148.31592,-24.32009],
[148.26656,-24.32569], [148.2599,-24.27619], [148.21056,-24.28175],
[148.20392,-24.23225], [148.1546,-24.2378], [148.148,-24.1883],
[148.0987,-24.19382], [148.09213,-24.14432], [147.99356,-24.1553],
[147.98704,-24.1058], [147.93777,-24.11125], [147.93128,-24.06176],
[147.88203,-24.06718], [147.87558,-24.01769], [147.82634,-24.02309],
[147.81992,-23.9736], [147.77071,-23.97898], [147.76431,-23.92949],
[147.71512,-23.93485], [147.7024,-23.83587], [147.65325,-23.8412],
[147.64692,-23.79172], [147.59779,-23.79703], [147.59149,-23.74755],
[147.54238,-23.75283], [147.53611,-23.70335], [147.48702,-23.70861],
[147.48078,-23.65913], [147.4317,-23.66437], [147.4193,-23.56543],
[147.37027,-23.57063], [147.3641,-23.52117], [147.31508,-23.52635],
[147.30894,-23.47689], [147.25995,-23.48205], [147.25384,-23.43259],
[147.20486,-23.43772], [147.19879,-23.38827], [147.14983,-23.39338],
[147.13774,-23.29447], [147.08882,-23.29956], [147.08281,-23.25011],
[147.03391,-23.25517], [147.02793,-23.20573], [146.97905,-23.21077],
[146.9731,-23.16132], [146.92424,-23.16634], [146.91832,-23.1169],
[146.86948,-23.12189], [146.8577,-23.02302], [146.8089,-23.02799],
[146.80305,-22.97856], [146.75427,-22.9835], [146.74844,-22.93407],
[146.69968,-22.93899], [146.69388,-22.88957], [146.64515,-22.89446],
[146.63938,-22.84504], [146.59066,-22.84992], [146.57918,-22.75108],
[146.5305,-22.75593], [146.5248,-22.70652], [146.47614,-22.71134],
[146.45913,-22.56314], [146.41054,-22.56794], [146.39927,-22.46916],
[146.35072,-22.47393], [146.28387,-21.88176], [146.33214,-21.87703],
[146.31548,-21.72914], [146.36367,-21.7244], [146.35255,-21.62585],
[146.40069,-21.62109], [146.39511,-21.57183], [146.44322,-21.56705],
[146.43204,-21.46855], [146.4801,-21.46376], [146.47449,-21.41453],
[146.52253,-21.40972], [146.5169,-21.3605], [146.56491,-21.35567],
[146.55926,-21.30646], [146.60724,-21.30162], [146.60158,-21.25241],
[146.64954,-21.24756], [146.64386,-21.19836], [146.7397,-21.18859],
[146.73398,-21.13941], [146.82976,-21.12957], [146.824,-21.0804],
[146.91972,-21.07049], [146.91392,-21.02133], [147.05739,-21.00633],
[147.05153,-20.95719], [147.24266,-20.93691], [147.23671,-20.88779]
]
]
}
}
]
}
Environmental data should be downloaded from the link above, unzipped, and placed in a folder named AustralianClimateData that is to be placed in the working directory. You should download 15 total items from the FigShare link (bat roost predictions, maximum temperature, minimum temperature, temperature difference, precipitation, precipitation anomaly, NDVI, soil moisture, morning vapor pressure, solar exposure, potential evapotranspiration, land cover, ONI, SOI, and SAM). The folder structure should be as follows:
Your_Working_Directory
\NewRoostPredictedSurfacesModel.Rdata
\RehabModel_01062022.Rdata
\shortage_reduced_environmental.txt
\AustralianClimateData
\\BatRoostPredictions
\\Evapotranspiration
\\PrecipitationLag
\\\PrecipitationLag2Months
\\\PrecipitationLag3Months
\\\PrecipitationLag6Months
...
Make sure that the two model objects and the food shortage model results found in the data folder of this repository are in your working directory as well as the folder containing all of the environmental data. This setup will help to prevent some troubleshooting problems. If you download all of the items in the FigShare and place them in a containing folder (AustralianClimateData
shown above), the structure described above should be retained.
The output of the main estimatePrevalence function will be a series of rasters estimating Hendra virus prevalence for all months in the specified years. Depending on the model components chosen (see estimatePrevalence function and MultiScaleExample for more information), you will output rasters for estimated prevalence, rehab stress, new roost stress, and a null expectation of stress derived from roost environmental suitability. The output will always include estimated prevalence and the null expectation, with new roost and rehab stress rasters only created when those model components are included.
Note that function will not produce an object in R. If there are no error messages produced after the function runs, you should see the aforementioned raster files created in your working directory.
The following are descriptions of each of the items included in this repository and how they work together:
This is an example script showing all of the packages, how to source the functions and data mentioned further below, and how to implement the estimatePrevalence function to generate Hendra virus prevalence predictions for our study area. This file is commented throughout on what each code chunk is doing and further information on each particular function can be found on their respective pages in this repository.
A helper function for the attachAustraliaEnv function that is used to access raster data for a particular environmental variable matching characteristics given (lag time, year, month).
A function used to attach environmental data to a given set of points for use in further modeling processes. Requires a two column data.frame of coordinates in the GDA 2020 coordinate reference system (or an sf points object with the same CRS) along with vectors of years and months related to those points.
A function that uses a quarterly survey of roost counts with a generalized additive model (GAM) to produce estimates of number of roosts present on a quarterly basis within the time frame of our study. This allows us to account for shifts in the number of roosts based on seasonal changes rather than assuming a static number of roosts at all times.
This is the main function used to estimate prevalence within our study area. Given a vector of years and months, this function will estimate prevalence within the area based on stress. If wanted, the user can modify the number of repetitions for each year-month calculation of prevalence, change the reference max prevalence (currently based on estimates from field data from Field et al. 2015), and parallelize the calculations.
These are descriptions of all of the objects placed in \data
A CSV file of roost location estimates from Field et al. 2015 PLoS One paper.
Hendra virus prevalence data from tested urine pools by Field et al. 2015. These data are accessible from the Queensland government's Open Data Portal.
This is a CSV of black flying fox roost counts summarized from the Flying Fox Monitoring Program by quarter of the year. This dataset is used by the roost.counts function above to estimate the number of roosts for a given month.
This is a text file containing the monthly results from a model predicting food shortages (Lagergren and Ruiz-Aravena et al. in prep).
This is a gbm model object representing a model trained on roosts that were determined to be newly formed. This model is used to predict stress deriving from the formation of new roosts when used with data from each month queried by the estimatePrevalence function.
This is also a gbm model object representing a model trained on bat rehabilitation data. This model is used to predict stress that would lead to bats ending up at a rehabilitation center (this is not necessarily limited to food stress) when used with data from each month queried by the estimatePrevalence function.