Coder Social home page Coder Social logo

nichemapr's Introduction

NicheMapR

R implementation of Niche Mapper software for biophysical modelling

Copyright (C) 2018 Michael R. Kearney and Warren P. Porter

Installation from github: library(devtools) install_github('mrke/NicheMapR')

See also https://mrke.github.io/getting_started/

Citations:

Kearney, M. R., & Porter, W. P. (2017). NicheMapR - an R package for biophysical modelling: The microclimate model. Ecography, 40(5), 664–674. https://doi.org/10.1111/ecog.02360

Kearney, M. R., & Porter, W. P. (2020). NicheMapR – an R package for biophysical modelling: The ectotherm and Dynamic Energy Budget models. Ecography, 43(1), 85–96. https://doi.org/10.1111/ecog.04680

Kearney, M. R., Briscoe, N. J., Mathewson, P. D., & Porter, W. P. (2021). NicheMapR – an R package for biophysical modelling: The endotherm model. Ecography, 44(11), 1595–1605. https://doi.org/10.1111/ecog.05550

Kearney, M. R., Porter, W. P., & Huey, R. B. (2021). Modelling the joint effects of body size and microclimate on heat budgets and foraging opportunities of ectotherms. Methods in Ecology and Evolution, 12(13), 458–467. https://doi.org/10.1111/2041-210X.13528

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

nichemapr's People

Contributors

goldingn avatar ilyamaclean avatar mrke avatar rafaqz avatar tracipopejoy avatar trollock avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nichemapr's Issues

changed input names for mcera5::point_nc_to_df

Hi Mike,

The inputs to point_nc_to_df & point_nc_to_df_precip have been changed to long & lat instead of x and y. A quick change on lines 740+743 in your code (links below) should allow your function to keep working.

hourlydata <- mcera5::point_nc_to_df(nc = paste0(spatial, '_', years, '.nc'), x = loc[1], y = loc[2],

dailyprecip <- point_nc_to_df_precip(nc = paste0(spatial, '_', years, '.nc'), x = loc[1], y = loc[2],

Cheers

James

reminder to change function names

Latest version of mcera5 has different function names:

e.g.

hourlydata <- mcera5::point_nc_to_df(nc = paste0(spatial, '_', years, '.nc'), long = loc[1], lat = loc[2],

You'll need to change:

point_nc_to_df -> extract_clim
point_nc_to_df_precip -> extract_precip

Cheers,

James

pedotransfer function returns error

I cannot get this function to work. Here is a repeatable example

tsp2 = rbind(c(10,1.81,23.50,52.00,24.50), c(5,1.60,13.50,57.00,29.50))
pedotransfer(soilpro = tsp2)

which returns

Error in pedotransfer(soilpro = tsp2, model = 1) :
object 'clay' not found

New version?

Is there a version for R 4.0?

I get the error

Error: package or namespace load failed for ‘NicheMapR’:
package ‘NicheMapR’ was installed before R 4.0.0: please re-install it

question than issue

Hello Marc and Expert,

I am asking a question on a situation (extreme event) with rain and a drop in temperature for 4 consecutive days. This had dramatic consequences with more than 500, 000 deaths in livestock (mainly ovine). Many suspect the temperature. and I wonder if, with NichemapR, there is a way to compute a parameter linked to temperature that can explain this or any suggestion? I am a climatolodist not an ecologist.

Thank you

Issue with opening URL in function micro_ncep

Hello,

I try to learn this package but when I run the example about function micro_ncep. It shows that can not open the URL of dataset website.

library(NicheMapR)
dstart <- "02/01/2017"
dfinish <- "30/12/2017"
loc <- c(-91.415669, -0.287145) # Isla Fernandina Galapagos
micro<-micro_ncep(loc = loc, dstart = dstart, dfinish = dfinish)

If program is crashing, try run.gads = 2.

downloading DEM via package elevatr 
 Accessing raster elevation [=========================] 100%
Mosaicing & Projecting
Note: Elevation units are in meters.
downloading weather data with package RNCEP via package microclima 
trying URL 'http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis2/gaussian_grid/air.2m.gauss.2017.nc.das'
downloaded 2626 bytes

trying URL 'http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis2/gaussian_grid/air.2m.gauss.2017.nc.ascii?air[0:1459][0][46:47][143:144]'
trying URL 'http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis2/gaussian_grid/air.2m.gauss.2017.nc.ascii?air[0:1459][0][46:47][143:144]'
trying URL 'http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis2/gaussian_grid/air.2m.gauss.2017.nc.ascii?air[0:1459][0][46:47][143:144]'
trying URL 'http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis2/gaussian_grid/air.2m.gauss.2017.nc.ascii?air[0:1459][0][46:47][143:144]'
trying URL 'http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis2/gaussian_grid/air.2m.gauss.2017.nc.ascii?air[0:1459][0][46:47][143:144]'
Error in NCEP.gather.gaussian(variable = variable, months.minmax = months.minmax,  : 
  
There is a problem connecting to the NCEP database with the information provided.
	
Try entering http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis2/gaussian_grid/air.2m.gauss.2017.nc.ascii?air[0:1459][0][46:47][143:144] into a web browser to obtain an error message.
In addition: Warning messages:
1: In download.file(paste("http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis",  :
  downloaded length 0 != reported length 2257
2: In download.file(paste("http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis",  :
  cannot open URL 'https://psl.noaa.gov/thredds/dodsC/Datasets/ncep.reanalysis2/gaussian_grid/air.2m.gauss.2017.nc.ascii?air[0:1459][0][46:47][143:144]': HTTP status was '400 Bad Request'
3: In download.file(paste("http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis",  :
  downloaded length 0 != reported length 2257
4: In download.file(paste("http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis",  :
  cannot open URL 'https://psl.noaa.gov/thredds/dodsC/Datasets/ncep.reanalysis2/gaussian_grid/air.2m.gauss.2017.nc.ascii?air[0:1459][0][46:47][143:144]': HTTP status was '400 Bad Request'
5: In download.file(paste("http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis",  :
  downloaded length 0 != reported length 2257
6: In download.file(paste("http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis",  :
  cannot open URL 'https://psl.noaa.gov/thredds/dodsC/Datasets/ncep.reanalysis2/gaussian_grid/air.2m.gauss.2017.nc.ascii?air[0:1459][0][46:47][143:144]': HTTP status was '400 Bad Request'
7: In download.file(paste("http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis",  :
  downloaded length 0 != reported length 2257
8: In download.file(paste("http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis",  :
  cannot open URL 'https://psl.noaa.gov/thredds/dodsC/Datasets/ncep.reanalysis2/gaussian_grid/air.2m.gauss.2017.nc.ascii?air[0:1459][0][46:47][143:144]': HTTP status was '400 Bad Request'
9: In download.file(paste("http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis",  :
  downloaded length 0 != reported length 2257
10: In download.file(paste("http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis",  :
  cannot open URL 'https://psl.noaa.gov/thredds/dodsC/Datasets/ncep.reanalysis2/gaussian_grid/air.2m.gauss.2017.nc.ascii?air[0:1459][0][46:47][143:144]': HTTP status was '400 Bad Request'

I have followed the information of run.gads = 2, but still doesn't work.

micro<-micro_ncep(loc = loc, dstart = dstart, dfinish = dfinish,run.gads = 2)

Any help on what I should do would be greatly appreciated!
Thanks

rain imputation in micro_global errors where months have no rain days

I'm running some microclimate models for dry places, and some spots have no rainy days in some months in the micro_global() source data. Niamey, Niger is one example. This leads to divide-by-zeros putting NAs in the rainfall data, when used with daily predictions and rainfrac=0, and then the fortran bit errors:

library(NicheMapR)
micro <- micro_global(
  loc = c(2.0840132, 13.5127664),
  timeinterval = 365,
  rainfrac = 0
)
#> If program is crashing, try run.gads = 2.
#> extracting climate data
#> extracting soil moisture data
#> running microclimate model for 365 days by 1 years at site long 2.0840132 lat 13.5127664
#> Note: the output column `SOLR` in metout and shadmet is for unshaded horizontal plane solar radiation
#> Error in microclimate(micro): NA/NaN/Inf in foreign function call (arg 24)

Created on 2023-08-18 with reprex v2.0.2

The offending lines are here (but possibly duplicated in other parts of the package?), and could be patched with some error handling

NicheMapR/R/micro_global.R

Lines 915 to 919 in 329eb11

RAINFALL1[m]<-(RAINFALL[i]*(1-rainfrac)*rainmult)/RAINYDAYS[i] # make remaining rain fall evenly over the remaining number of rainy days for the month, starting at the beginning of the month
}
}else{
if(rainfrac==0){
RAINFALL1[m]<-(RAINFALL[i]*rainmult)/RAINYDAYS[i]

feature request: user-submitted DOYs for microclimate model?

Hi Mike,

For one of my current uses, I was hoping to run micro_global() for just a subset of winter days (let's say 12 days in a row in winter). But due to computational restraints (the project entails a large spatiotemporal scale) I can't afford to run the model for timeinterval = 365 and then subset to just my few days of interest. So I wanted to see if it's possible to have user-submitted choice of DOYs handed to micro_global() or the other microclimate model wrappers.

My tampering with things in micro_global() by adding an argument for user's choice ofdoys to replace doys12 ended up not changing anything, even if doys was also 12 days (micro_global() returned the same output as it did for middle-of-each-month 12 days)....so I'm guessing there's more to this than my simple approach (see here for my tampering).

Would it be a heavy lift to allow users to choose the specific days of the year to run the microclimate model? From my understanding of how daily initial conditions are set, this might be straightforward to do if the DOYs are right next to each other, but less so if it's a random subset of the year. I'd imagine there may be other users who are also interested in just a particular temporal window but have similar computational restraints that prevent running for 365 days.

Apologies if I've missed that this functionality is already available somewhere. And as always, thanks for your hard and consistent work on the package.

Cheers, Dave

micro_aust doesn't work for dates before 1990

Hi mrke,
I've been trying to use micro_aust and ectotherm to calculate microclimate variables and lizard activity times for dates between 1920 and 2006. I've had success running micro_aust for dates after 1990 but dates earlier than 1990 end up with this error when extracting the climate data:

Error in RNetCDF::open.nc(paste0(baseurl, var, "/day/", year, "/bom-", :
NetCDF: file not found

I saw on your website that micro_aust can calculate microclimates from 1911 onwards, so I'm not sure why this error is occurring! Any help would be appreciated!
Thanks,
Chris

R version

Which version of R does this run on?

Latest commit breaks compilation

Hi, the latest commit 141b3c2 has broken compilation for me under R3.6.3:

> library(devtools) # Required to install packages from Github
> devtools::install_github("mrke/nichemapr")

....


** R
** data
*** moving datasets to lazyload DB
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
Error: package or namespace load failed for ‘NicheMapR’ in namespaceExport(ns, exports):
 undefined exports: micro_aust_forecast
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/Library/Frameworks/R.framework/Versions/3.6/Resources/library/NicheMapR’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/3.6/Resources/library/NicheMapR’
Error: Failed to install 'NicheMapR' from GitHub:
  (converted from warning) installation of package ‘/var/folders/pj/5gycy5z54mb8x318q07v8kx80000gn/T//Rtmp2MJqpM/file122b67528a72d/NicheMapR_2.0.0.tar.gz’ had non-zero exit status
Execution halted

Compilation was successful yesterday before this change.

Thanks!

Looks for libR.dylib in the wrong place

After installing NicheMapR 1.1.3 on a Mac OS X using R 3.4.2, the library failed to load with the following error. Notice that it is looking in the R version 3.3 folder for libR.dylib:

Loading required package: NicheMapR
Error: package or namespace load failed for ‘NicheMapR’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/Library/Frameworks/R.framework/Versions/3.4/Resources/library/NicheMapR/libs/gads.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.4/Resources/library/NicheMapR/libs/gads.so, 6): Library not loaded: /Library/Frameworks/R.framework/Versions/3.3/Resources/lib/libR.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/3.4/Resources/library/NicheMapR/libs/gads.so
Reason: image not found

I manually created the path for /Library/Frameworks/R.framework/Versions/3.3/Resources/lib/ and copied in libR.dylib from the 3.4 path. NicheMapR then loaded successfully.

Memory mapping error

Hi mrke,

I get a memory mapping error when compiled, and run with Spectre & Meltdown patches. Is it possible to have .so regenerated with the patches?

R 4 binary for mac

Thank you for the new version, nice effort. Could also post a binary for mac (.tgz) compile with R version 4?

Thanks

NicheMapR error when deploying Shiny app

Hi,

I'm new to Shiny deployment, but i do have an issue related to NicheMapR package. Every packages are well installed when using the rsconnect procedure, but when it tries to install NicheMapR i get the following error :

[2022-03-06T08:41:01.263975518+0000] Building R package: NicheMapR (3.1.0)
/mnt/packages/build /mnt
make: Entering directory '/tmp/Rtmp93Dhy1/R.INSTALL86925a1b468/mrke-NicheMapR-e173e34/src'
gfortran -fno-optimize-sibling-calls -fpic -g -O2 -c AACOMMONDAT.f -o AACOMMONDAT.o
gfortran -fno-optimize-sibling-calls -fpic -g -O2 -c ABOVEGROUND.f -o ABOVEGROUND.o
gfortran -fno-optimize-sibling-calls -fpic -g -O2 -c ADJREC.f -o ADJREC.o
gfortran -fno-optimize-sibling-calls -fpic -g -O2 -c BELOWGROUND.f -o BELOWGROUND.o
make: Leaving directory '/tmp/Rtmp93Dhy1/R.INSTALL86925a1b468/mrke-NicheMapR-e173e34/src'
make: Entering directory '/tmp/Rtmp93Dhy1/R.INSTALL86925a1b468/mrke-NicheMapR-e173e34/src'
make: Leaving directory '/tmp/Rtmp93Dhy1/R.INSTALL86925a1b468/mrke-NicheMapR-e173e34/src'
Warning: unknown option ‘--vanilla’
Warning in untar2(tarfile, files, list, exdir, restore_times) :
skipping pax global extended headers

  • installing to library ‘/opt/R/4.0.3/lib/R/library’

  • installing source package ‘NicheMapR’ ...
    ** using staged installation
    ** libs
    BELOWGROUND.f:22:9:

    22 | USE AACOMMONDAT
    | 1
    Fatal Error: Cannot read module file ‘aacommondat.mod’ opened at (1), because it was created by a different version of GNU Fortran
    compilation terminated.
    ABOVEGROUND.f:22:9:

    22 | USE AACOMMONDAT
    | 1
    Fatal Error: Cannot read module file ‘aacommondat.mod’ opened at (1), because it was created by a different version of GNU Fortran
    compilation terminated.
    make: *** [/opt/R/4.0.3/lib/R/etc/Makeconf:195: ABOVEGROUND.o] Error 1
    make: *** Waiting for unfinished jobs....
    make: *** [/opt/R/4.0.3/lib/R/etc/Makeconf:195: BELOWGROUND.o] Error 1
    ERROR: compilation failed for package ‘NicheMapR’

  • removing ‘/opt/R/4.0.3/lib/R/library/NicheMapR’
    ################################# End Task Log #################################
    Erreur : Unhandled Exception: Child Task 1112156452 failed: Error building image: Build exited with non-zero status: 1

It seems that several Fortran version have been used, but I don't know how to fix this. If you got any tip to avoid this problem that would be amazing.

Thanks,

Martin

Issue with installing NicheMapR

Hello,

I am having trouble installing NicheMapR to my mac. I have tried to install it through the multiple ways that are listed on the NicheMap website:

  1. Install the latest release of NicheMapR, go to the NicheMapR releases page

install.packages("NicheMapR_3.1.0.tgz", repos = NULL,

  •              type = .Platform$pkgType)
    

library(NicheMapR)
Error: package or namespace load failed for ‘NicheMapR’:
package ‘NicheMapR’ was installed before R 4.0.0: please re-install it

  1. To install NicheMapR from source via github you will need the devtools package for R as well as a Fortran compiler for your platform. I downloaded gfortran-ARM-12.1-Monterey.dmg for Apple Silicon computers. Then tried to run the script.

install.packages('devtools')
Error in install.packages : Updating loaded packages

Restarting R session...

install.packages("devtools")
trying URL 'https://cran.rstudio.com/bin/macosx/big-sur-arm64/contrib/4.1/devtools_2.4.4.tgz'
Content type 'application/x-gzip' length 422640 bytes (412 KB)
==================================================
downloaded 412 KB

The downloaded binary packages are in
/var/folders/qn/rg86xsy10x97896c5xhgxx280000gn/T//RtmpwOExSH/downloaded_packages

library(devtools)
Loading required package: usethis
Warning messages:
1: package ‘devtools’ was built under R version 4.1.1
2: package ‘usethis’ was built under R version 4.1.1
devtools::install_github('mrke/NicheMapR')
Downloading GitHub repo mrke/NicheMapR@HEAD
✔ checking for file ‘/private/var/folders/qn/rg86xsy10x97896c5xhgxx280000gn/T/RtmpwOExSH/remotes66d751fbab98/mrke-NicheMapR-cd40f0b/DESCRIPTION’ ...
─ preparing ‘NicheMapR’:
✔ checking DESCRIPTION meta-information ...
─ cleaning src
─ checking for LF line-endings in source and make files and shell scripts
─ checking for empty or unneeded directories
─ building ‘NicheMapR_3.2.0.tar.gz’

  • installing source package ‘NicheMapR’ ...
    ** using staged installation
    ** libs
    /opt/R/arm64/bin/gfortran -mtune=native -fno-optimize-sibling-calls -fPIC -Wall -g -O2 -c AACOMMONDAT.f -o AACOMMONDAT.o
    make: /opt/R/arm64/bin/gfortran: No such file or directory
    make: *** [AACOMMONDAT.o] Error 1
    ERROR: compilation failed for package ‘NicheMapR’
  • removing ‘/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/NicheMapR’
  • restoring previous ‘/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/NicheMapR’
    Warning message:
    In i.p(...) :
    installation of package ‘/var/folders/qn/rg86xsy10x97896c5xhgxx280000gn/T//RtmpwOExSH/file66d77d38f90e/NicheMapR_3.2.0.tar.gz’ had non-zero exit status

Any help on what I should do would be greatly appreciated!
Thanks

micro_aust

Hi,
when running the mico_aust function to get the microclimate for an Australian location I get the following error.
Error in RNetCDF::open.nc(paste0(baseurl, var, "/day/", year, "/bom-", :
NetCDF: Malformed or inaccessible DAP DDS

When tracing back I think the problem lies in the provided baseurl to get the climate data as this is no longer available. I tried to find the correct link but could not find it. Currenlty it points to:

"http://rs-data1-mel.csiro.au/thredds/dodsC/bawap/"

which does not work anymore.

Any help here?

Thanks and cheers, Bernd

Inconsistent air temperature from the outputs of micro_global() and ectotherm()

When I was running through the ecotherm vignette, I found that air temperature TALOC in shadmet from micro_global() is very different from air temperature TA in environ from ectotherm(), for the same location. Any insights and/or interpretations would be appreciated. Thanks.

# example code
longlat <- c(139.3109, -33.888) 
loc <- longlat
ystart <- 2008
yfinish <- 2010
nyears <- yfinish - ystart + 1
micro <- micro_global(loc = longlat, nyears = nyears)
ecto <- ectotherm(nyears = nyears)

# output
min(as.data.frame(ect$environ)$TA) =7.219361
min(as.data.frame(micro$shadmet)$TALOC) = 5.195637

Issue about the combination of DEB and Endotherm

Hello, I have installed the NicheMapR. I noticed that the DEB model only has examples of combining with Ectotherm model, but there are no examples of combining with Endotherm model. I hope to try simulating the feeding and physiological characteristics of sheep and other livestock under different climate conditions. Could this be achieved through the combination of DEB and Endotherm model? If possible, what should I do? Thank you, looking forward to your reply.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.