Commit eedbd684 authored by jfuser's avatar jfuser
Browse files

Merge branch 'master' of gitlab.paca.inra.fr:CSIRO-INRA/landsepi

parents 05cf6052 01915e31
Pipeline #44 failed with stage
......@@ -43,6 +43,6 @@ nTSpY = 120
fichierP <- "/home/julien/Documents/Documents/modelisation/CSIRO_INRA/landsepi/data/TEST_dispP.txt"
fichierH <- "/home/julien/Documents/Documents/modelisation/CSIRO_INRA/landsepi/data/TEST_dispH.txt"
modeleLandsLPI(times = list(nYears=nYears,nTSpY=nTSpY) , landscape, dispersion=list(dispP=fichierP,dispH=fichierH), inits=list(C_0=0.1, PI0=5e-4), val_seed=12345, host=list(Nhote=3))
modeleLandsLPI(times = list(nYears=nYears,nTSpY=nTSpY,timesStep=1:120) , landscape, dispersion=list(dispP=fichierP,dispH=fichierH), inits=list(C_0=0.1, PI0=5e-4), val_seed=12345, host=list(Nhote=3))
}
......@@ -141,3 +141,28 @@ void tradeoff(int n, double *x, double *y, double beta){
y[i] = 1 - pow(1-pow(x[i],1/beta),beta);
}
void addField(OGRLayer * poLayer, const char * fieldname, const double * values) {
OGRFieldDefn oField( fieldname, OFTReal );
oField.SetPrecision(32);
if( poLayer->CreateField( &oField ) != OGRERR_NONE )
{
cerr<< "Creating Name field failed.\n" ;
}
OGRFeature *poFeature;
int ind = 0;
poLayer->ResetReading();
while( (poFeature = poLayer->GetNextFeature()) != NULL )
{
//cerr<<ind<<" "<< values[ind]<<endl;
poFeature->SetField(fieldname,values[ind++]);
poLayer->SetFeature(poFeature);
OGRFeature::DestroyFeature( poFeature );
}
}
......@@ -2,6 +2,19 @@
#define __FUNCTIONS__
#include <math.h>
#include <iostream>
#include <gdal/gdal.h>
//#include <gdal/org_api.h>
#include <gdal/ogrsf_frmts.h>
using namespace std;
#ifndef GDALV2
#if GDAL_VERSION_MAJOR >= 2
# define GDALV2 1
#endif
#endif
/****************************************************************/
/* functions.c */
......@@ -43,4 +56,6 @@ void sigmoid(double s, double k, double sig, double x, double *y);
/* Trade-off function on aggressiveness traits (cf Debarre et al. JEB 2010) */
void tradeoff(int n, double *x, double *y, double beta);
void addField(OGRLayer * poLayer, const char * fieldname, const double * values);
#endif
......@@ -485,7 +485,7 @@ void infection(const gsl_rng *gen, int t, int nTSpY, int Nhote, int Npatho, int
/* DYNAMIC OF THE EPIDEMIC */
/* --------------------------- */
void dynepi(const gsl_rng *gen, int nYears, int nTSpY, int Npoly, int Nhote, int Npatho, int *area, int **habitat, int *rotation, double *C0, double pI0, double pSurv, double *Cmax, double **mort, double *delta, double *reproH, double **disphote, double **disppatho, double eff, double *Tlat, double repro, double *Tspo, double **mutkernelMG, double **mutkernelQR, int **pathoToAggr, int ********aggrToPatho, int Naggr, double **infect, double **aggr, char *strat, int **resistance, int *adaptation, int printOn){
void dynepi(const gsl_rng *gen, int nYears, int nTSpY, int Npoly, int Nhote, int Npatho, int *area, int **habitat, int *rotation, double *C0, double pI0, double pSurv, double *Cmax, double **mort, double *delta, double *reproH, double **disphote, double **disppatho, double eff, double *Tlat, double repro, double *Tspo, double **mutkernelMG, double **mutkernelQR, int **pathoToAggr, int ********aggrToPatho, int Naggr, double **infect, double **aggr, char *strat, int **resistance, int *adaptation, int printOn, OGRLayer *poLayer, NumericVector timesStep){
int year, t, poly;
char name_fH[15], name_fHjuv[15], name_fS[15], name_fL[15], name_fI[15], name_fR[15];
......@@ -540,12 +540,17 @@ void dynepi(const gsl_rng *gen, int nYears, int nTSpY, int Npoly, int Nhote, int
fI = fopen(name_fI,"wb");
fS = fopen(name_fS,"wb");
fR = fopen(name_fR,"wb");
int INDtime=0;
/* Loop for all the timesteps of the cropping season */
for (t = 0 ; t < nTSpY ; t++){
/* Writing model output for timestep t */
write_HHjuvSLIR(Npoly, Npatho, Nhote, t, H, Hjuv, S, L, I, R, fH, fHjuv, fS, fL, fI, fR, printOn);
if(t==timesStep[INDtime]){
sortie_layer(poLayer,H,Npoly,Nhote,t,year);
INDtime=INDtime+1;
}
//write_HHjuvSLIR(Npoly, Npatho, Nhote, t, H, Hjuv, S, L, I, R, fH, fHjuv, fS, fL, fI, fR, printOn);
reproDisp(gen, Npoly, Nhote, Npatho, Naggr, H, Hjuv, S, I, reproH, repro, disphote, disppatho, resistance, adaptation, mutkernelMG, mutkernelQR, pathoToAggr, aggrToPatho, aggr);
for (poly = 0 ; poly < Npoly ; poly++){
// printf("poly %d\n", poly);
......@@ -557,7 +562,8 @@ void dynepi(const gsl_rng *gen, int nYears, int nTSpY, int Npoly, int Nhote, int
} /* for t */
/* last time-step of the season: bottleneck before starting a new season */
write_HHjuvSLIR(Npoly, Npatho, Nhote, nTSpY, H, Hjuv, S, L, I, R, fH, fHjuv, fS, fL, fI, fR, printOn); /* Writing model output for last timestep */
sortie_layer(poLayer,H,Npoly,Nhote,nTSpY,year);
//write_HHjuvSLIR(Npoly, Npatho, Nhote, nTSpY, H, Hjuv, S, L, I, R, fH, fHjuv, fS, fL, fI, fR, printOn); /* Writing model output for last timestep */
bottleneck(gen, Npoly, Nhote, Npatho, pSurv, Tspo, L, I, aggr, resistance, pathoToAggr, eqIsurv, printOn); /* Calculation of the equivalent number of I */
init_HHjuvSLIR(Npoly, Nhote, Npatho, H, Hjuv, S, L, I, R); /* Re-initialisation at 0 */
init_L2I2R(Npoly, Npatho, Nhote, nTSpY, L2I, I2R); /* Re-initialisation at 0 */
......@@ -593,22 +599,44 @@ void dynepi(const gsl_rng *gen, int nYears, int nTSpY, int Npoly, int Nhote, int
}
/*------------------------------------------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------------------------------------------*/
int main(){
void sortie_layer(OGRLayer *poLayer,int **H,int Npoly, int Nhote, int pastemps, int year){
char nomH[256];
double *resH;
resH=init_d1(Npoly);
for (int i=0; i<Nhote; i++){
for (int j=0; j<Npoly; j++){
resH[j] = H[j][i];
}
sprintf(nomH, "H%i_%i-%i", i, year, pastemps);
addField(poLayer, nomH, resH);
}
free(resH);
}
/*------------------------------------------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------------------------------------------*/
}
void modeleLandsLPI(Rcpp::List times, Rcpp::List landscape, Rcpp::List dispersion, Rcpp::List inits ,int val_seed, Rcpp::List host) {
int nYears = Rcpp::as<int>(times["nYears"]);
int nTSpY = Rcpp::as<int>(times["nTSpY"]);
NumericVector timesStep=Rcpp::as<NumericVector>(times["timesStep"]);
CharacterVector shapefilename = Rcpp::as<CharacterVector>(landscape["shapefilename"]);
CharacterVector layername_hab = Rcpp::as<CharacterVector>(landscape["layername_hab"]);
CharacterVector layername_res = Rcpp::as<CharacterVector>(landscape["layername_res"]);
char * strat = (char*)Rcpp::as<std::string>(Rcpp::as<CharacterVector>(landscape["strat"])).c_str();
IntegerVector rotation_tmp = Rcpp::as<IntegerVector>(landscape["rotation"]);
double propRR = Rcpp::as<double>(landscape["propRR"]);
......@@ -902,11 +930,20 @@ void modeleLandsLPI(Rcpp::List times, Rcpp::List landscape, Rcpp::List dispersio
/* Epidemic model */
/* -------------- */
Rprintf("\n*** SPATIOTEMPORAL MODEL SIMULATING THE SPREAD OF AN EPIDEMIC IN A LANDSCAPE ***\n\n");
dynepi(gen, nYears, nTSpY, NPoly, Nhote, Npatho, area, habitat, rotation, C0, pI0, pSurv, Cmax, mort, delta, reproH, disphote, disppatho, eff, Tlat, repro, Tspo, mutkernelMG, mutkernelQR, pathoToAggr, aggrToPatho, Naggr, infect, aggr, strat, resistance, adaptation, printOn);
poLayer = poDS->GetLayerByName( Rcpp::as<std::string>(layername_res).c_str());
dynepi(gen, nYears, nTSpY, NPoly, Nhote, Npatho, area, habitat, rotation, C0, pI0, pSurv, Cmax, mort, delta, reproH, disphote, disppatho, eff, Tlat, repro, Tspo, mutkernelMG, mutkernelQR, pathoToAggr, aggrToPatho, Naggr, infect, aggr, strat, resistance, adaptation, printOn, poLayer, timesStep);
/* ----------- */
/* Free memory */
/* ----------- */
/* ----------- */
#ifdef GDALV2
GDALClose( poDS );
#else
OGRDataSource::DestroyDataSource( poDS );
#endif
// free(areaTot);
free(area);
......
......@@ -92,9 +92,9 @@ void contamination(const gsl_rng *gen, int Nhote, int Npatho, int *H, int *S, in
void infection(const gsl_rng *gen, int t, int nTSpY, int Nhote, int Npatho, int *H, int **Hcontaminated, int **L, int **I, int **R, int ***L2I, int ***I2R, double eff, double *Tlat, double *Tspo, int **resistance, int **pathoToAggr, double **infect, double **aggr);
void dynepi(const gsl_rng *gen, int nYears, int nTSpY, int Npoly, int Nhote, int Npatho, int *area, int **habitat, int *rotation, double *C0, double pI0, double pSurv, double *Cmax, double **mort, double *delta, double *reproH, double **disphote, double **disppatho, double eff, double *Tlat, double repro, double *Tspo, double **mutkernelMG, double **mutkernelQR, int **pathoToAggr, int ********aggrToPatho, int Naggr, double **infect, double **aggr, char *strat, int **resistance, int *adaptation, int printOn);
void dynepi(const gsl_rng *gen, int nYears, int nTSpY, int Npoly, int Nhote, int Npatho, int *area, int **habitat, int *rotation, double *C0, double pI0, double pSurv, double *Cmax, double **mort, double *delta, double *reproH, double **disphote, double **disppatho, double eff, double *Tlat, double repro, double *Tspo, double **mutkernelMG, double **mutkernelQR, int **pathoToAggr, int ********aggrToPatho, int Naggr, double **infect, double **aggr, char *strat, int **resistance, int *adaptation, int printOn, OGRLayer *poLayer, NumericVector timesStep);
void sortie_layer(OGRLayer *poLayer,int **H,int Npoly, int Nhote, int pastemps, int year);
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment