Revision b6072700
Added by Benoit Parmentier almost 12 years ago
climate/research/oregon/interpolation/master_script_temp.R | ||
---|---|---|
6 | 6 |
#STAGE 1: LST climatology calculation |
7 | 7 |
#STAGE 2: Covariates preparation: aspect, land cover, distance to coast etc. |
8 | 8 |
#STAGE 3: Data preparation: database query, extraction of covariates from stack |
9 |
#STAGE 4: Raster prediction: run interpolation methode -- gam fusion, gam CAI, ...
|
|
9 |
#STAGE 4: Raster prediction: run interpolation method -- gam fusion, gam CAI, ... |
|
10 | 10 |
#STAGE 5: Output analyses-visualization of results for specific dates... |
11 | 11 |
# |
12 | 12 |
#AUTHOR: Benoit Parmentier |
13 |
#DATE: 03/05/2013
|
|
13 |
#DATE: 03/12/2013
|
|
14 | 14 |
|
15 | 15 |
#PROJECT: NCEAS INPLANT: Environment and Organisms --TASK#363, TASK$568-- |
16 | 16 |
|
... | ... | |
43 | 43 |
|
44 | 44 |
script_path<-"/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/" |
45 | 45 |
#list_script_files<- |
46 |
stages_to_run<-c(1,2,3,4,5) #May decide on antoher strategy later on... |
|
46 | 47 |
|
48 |
#####SCRIPT USED FOR THE PREDICTIONS |
|
47 | 49 |
|
48 |
############ STAGE 1: LST Climatology ############### |
|
50 |
#master_script_temp_03052013.R |
|
51 |
|
|
52 |
#IN MASTER SCRIPT: |
|
49 | 53 |
|
50 |
#Call run through python |
|
51 | 54 |
#/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/climatology_01252013b.py |
55 |
#/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/covariates_production_temperatures_02062013.R |
|
56 |
|
|
57 |
#source(file.path(script_path,"Database_stations_covariates_processing_function_03052013.R")) |
|
58 |
#source(file.path(script_path,"GAM_fusion_analysis_raster_prediction_multisampling_03052013.R")) |
|
59 |
#source(file.path(script_path,"results_interpolation_date_output_analyses_03052013.R")) |
|
60 |
|
|
61 |
#CALLED FROM GAM FUSION ANALYSIS RASTER PREDICTION |
|
62 |
|
|
63 |
#source(file.path(script_path,"sampling_script_functions_03052013.R")) |
|
64 |
#source(file.path(script_path,"GAM_fusion_function_multisampling_03052013.R")) #Include GAM_CAI |
|
65 |
#source(file.path(script_path,"GAM_fusion_function_multisampling_validation_metrics_02262013.R")) |
|
66 |
|
|
67 |
|
|
68 |
############ STAGE 1: LST Climatology ############### |
|
69 |
|
|
70 |
if (stages_to_run[1]==1){ |
|
71 |
#Call run through python |
|
72 |
#/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/climatology_01252013b.py |
|
73 |
} |
|
52 | 74 |
|
53 | 75 |
############ STAGE 2: Covariate production ################ |
54 | 76 |
|
55 |
#Transform into function... |
|
56 |
#/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/covariates_production_temperatures_02062013.R |
|
77 |
if (stages_to_run[2]==2){ |
|
78 |
#Transform into function... |
|
79 |
#/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/covariates_production_temperatures_02062013.R |
|
80 |
} |
|
57 | 81 |
|
58 | 82 |
############# STAGE 3: Data preparation ############### |
59 | 83 |
|
60 | 84 |
source(file.path(script_path,"Database_stations_covariates_processing_function_03052013.R")) |
61 | 85 |
|
62 |
|
|
63 | 86 |
#Setting up input argurments for script function... |
64 | 87 |
|
65 | 88 |
db.name <- "ghcn" # name of the Postgres database |
... | ... | |
68 | 91 |
range_years_clim<-c("2000","2011") #right bound not included in the range!! |
69 | 92 |
infile1<- "outline_venezuela_region__VE_01292013.shp" #This is the shape file of outline of the study area #It is an input/output of the covariate script |
70 | 93 |
infile2<-"/home/layers/data/climate/ghcn/v2.92-upd-2012052822/ghcnd-stations.txt" #This is the textfile of station locations from GHCND |
71 |
infile_covariates<-"covariates__venezuela_region__VE_01292013.tif" #this is an output from covariate script |
|
94 |
infile_covariates<-"covariates__venezuela_region__VE_01292013.tif" #this is an output from covariate script and used in stage 3 and stage 4
|
|
72 | 95 |
CRS_locs_WGS84<-CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +towgs84=0,0,0") #Station coords WGS84: same as earlier |
73 | 96 |
in_path <- "/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/input_data/" |
74 | 97 |
out_prefix<-"_365d_GAM_fus5_all_lstd_03052013" #User defined output prefix |
... | ... | |
93 | 116 |
|
94 | 117 |
############### STAGE 4: RASTER PREDICTION ################# |
95 | 118 |
|
96 |
#Prepare parameters for for raster prediction... Turn this into a function |
|
119 |
#Prepare parameters for for raster prediction... |
|
120 |
|
|
121 |
#Collect parameters from the previous stage: data preparation stage |
|
122 |
|
|
123 |
#3 parameters from output |
|
124 |
infile_monthly<-list_outfiles$monthly_covar_ghcn_data #outile4 from database_covar script |
|
125 |
infile_daily<-list_outfiles$daily_covar_ghcn_data #outfile3 from database_covar script |
|
126 |
infile_locs<- list_outfiles$loc_stations_ghcn #outfile2? from database covar script |
|
127 |
|
|
128 |
list_param_data_prep<-list(infile_monthly,infile_daily,infile_locs,infile_covariates,covar_names,var,out_prefix,CRS_locs_WGS84) |
|
129 |
|
|
130 |
names(list_param_data_prep)<-c("infile_monthly","infile_daily","infile_locs","infile_covariates","covar_names","var","out_prefix","CRS_locs_WGS84") |
|
131 |
|
|
132 |
#Set additional parameters |
|
133 |
#Input for sampling function... |
|
134 |
seed_number<- 100 #if seed zero then no seed? |
|
135 |
nb_sample<-1 #number of time random sampling must be repeated for every hold out proportion |
|
136 |
step<-0 |
|
137 |
constant<-0 #if value 1 then use the same samples as date one for the all set of dates |
|
138 |
prop_minmax<-c(0.3,0.3) #if prop_min=prop_max and step=0 then predicitons are done for the number of dates... |
|
139 |
infile_dates<-"list_365_dates_04212012.txt" |
|
140 |
|
|
141 |
#Models to run...this can be change for each run |
|
142 |
list_models<-c("y_var ~ s(elev_1)", |
|
143 |
"y_var ~ s(LST)", |
|
144 |
"y_var ~ s(elev_1,LST)", |
|
145 |
"y_var ~ s(lat) + s(lon)+ s(elev_1)", |
|
146 |
"y_var ~ s(lat,lon,elev_1)", |
|
147 |
"y_var ~ s(lat,lon) + s(elev_1) + s(N_w,E_w) + s(LST)", |
|
148 |
"y_var ~ s(lat,lon) + s(elev_1) + s(N_w,E_w) + s(LST) + s(LC2)", |
|
149 |
"y_var ~ s(lat,lon) + s(elev_1) + s(N_w,E_w) + s(LST) + s(LC6)", |
|
150 |
"y_var ~ s(lat,lon) + s(elev_1) + s(N_w,E_w) + s(LST) + s(DISTOC)") |
|
151 |
|
|
152 |
#Choose interpolation method... |
|
153 |
interpolation_method<-c("gam_fusion","gam_CAI") #other otpions to be added later |
|
154 |
|
|
155 |
#Default name of LST avg to be matched |
|
156 |
lst_avg<-c("mm_01","mm_02","mm_03","mm_04","mm_05","mm_06","mm_07","mm_08","mm_09","mm_10","mm_11","mm_12") |
|
157 |
in_path<-"/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/input_data" |
|
158 |
#Create on the fly output folder... |
|
159 |
out_path<-"/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/output_data" |
|
160 |
script_path<-"/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/" |
|
161 |
|
|
162 |
#Collect all parameters in a list |
|
163 |
list_param_raster_prediction<-list(list_param_data_prep, |
|
164 |
seed_number,nb_sample,step,constant,prop_minmax,infile_dates, |
|
165 |
list_models,lst_avg,in_path,out_path,script_path, |
|
166 |
interpolation_method) |
|
167 |
|
|
168 |
names(list_param_raster_prediction)<-c("list_param_data_prep", |
|
169 |
"seed_number","nb_sample","step","constant","prop_minmax","infile_dates", |
|
170 |
"list_models","lst_avg","in_path","out_path","script_path", |
|
171 |
"interpolation_method") |
|
172 |
|
|
173 |
#Source file |
|
174 |
source(file.path(script_path,"GAM_fusion_analysis_raster_prediction_multisampling_03122013b.R")) |
|
175 |
|
|
176 |
#Make the function call |
|
177 |
raster_prediction_gam_fus_obj <-raster_prediction_gam_fusion(list_param_raster_prediction) |
|
97 | 178 |
|
98 |
source(file.path(script_path,"GAM_fusion_analysis_raster_prediction_multisampling_03052013.R")) |
|
99 | 179 |
|
100 | 180 |
############## STAGE 5: OUTPUT ANALYSES ################## |
101 | 181 |
|
Also available in: Unified diff
Temperature prediction, master script now calling raster prediction as a function with explicit arguments