Project

General

Profile

« Previous | Next » 

Revision 3c422b41

Added by Benoit Parmentier over 11 years ago

master script modifications regarding outputs and clean up

View differences:

climate/research/oregon/interpolation/master_script_temp.R
10 10
#STAGE 5: Output analyses-visualization of results for specific dates...
11 11
#
12 12
#AUTHOR: Benoit Parmentier                                                                       
13
#DATE: 05/01/2013                                                                                 
13
#DATE: 05/09/2013                                                                                 
14 14

  
15 15
#PROJECT: NCEAS INPLANT: Environment and Organisms --TASK#363, TASK$568--   
16 16

  
......
48 48

  
49 49
#####SCRIPT USED FOR THE PREDICTIONS: Source all scripts here to avoid confusion on versions being run!!!!
50 50

  
51
#source(file.path(script_path,"master_script_temp_04022013.R")) #Master script can be run directly...
51
#source(file.path(script_path,"master_script_temp_05062013.R")) #Master script can be run directly...
52 52

  
53 53
#CALLED FROM MASTER SCRIPT:
54 54

  
55 55
#/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/climatology_03192013.py
56 56
source(file.path(script_path,"covariates_production_temperatures_03212013.R"))
57
source(file.path(script_path,"Database_stations_covariates_processing_function_04042013.R"))
58
source(file.path(script_path,"GAM_fusion_analysis_raster_prediction_multisampling_04302013.R"))
59
source(file.path(script_path,"results_interpolation_date_output_analyses_04302013.R"))
57
source(file.path(script_path,"Database_stations_covariates_processing_function_05062013.R"))
58
source(file.path(script_path,"GAM_fusion_analysis_raster_prediction_multisampling_05062013.R"))
59
source(file.path(script_path,"results_interpolation_date_output_analyses_05062013.R"))
60 60
#source(file.path(script_path,"results_covariates_database_stations_output_analyses_04012013.R"))
61 61

  
62 62
#FUNCTIONS CALLED FROM GAM ANALYSIS RASTER PREDICTION ARE FOUND IN...
63 63

  
64 64
source(file.path(script_path,"sampling_script_functions_03122013.R"))
65
source(file.path(script_path,"GAM_fusion_function_multisampling_04302013.R")) #Include GAM_CAI
66
source(file.path(script_path,"GAM_fusion_function_multisampling_validation_metrics_04302013.R"))
65
source(file.path(script_path,"GAM_fusion_function_multisampling_05062013.R")) #Include GAM_CAI
66
source(file.path(script_path,"GAM_fusion_function_multisampling_validation_metrics_05062013.R"))
67 67

  
68 68
############ STAGE 1: LST Climatology ###############
69 69

  
......
76 76

  
77 77
##Paths to inputs and output
78 78
var<-"TMAX"
79
out_prefix<-"_365d_GAM_CAI_all_lst_05092013"                #User defined output prefix
80

  
81
#Change input path?? for LST stage ??
79 82
in_path  <- "/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/input_data/"
80
out_path <- "/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/output_data/"
81 83
#in_path <-"/home/parmentier/Data/IPLANT_project/Oregon_interpolation/Oregon_03142013/input"
82
#out_path <-"/home/parmentier/Data/IPLANT_project/Oregon_interpolation/Oregon_03142013/output"
83

  
84
#in_path <- out_path
85
out_path <- paste("/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/output_data",
86
                  out_prefix,"/",sep="")
87
if (!file.exists(out_path)){
88
  dir.create(out_path)
89
#} else{
90
#  out_path <-paste(out_path..)
91
#}
84 92

  
85 93
lc_path<-"/home/layers/data/land-cover/lc-consensus-global"
86 94
infile_modis_grid<-"modis_sinusoidal_grid_world.shp" #Give path!!! NEED TO CHANGE THIS...
87

  
88 95
infile_elev<-"/home/layers/data/terrain/dem-cgiar-srtm-1km-tif/srtm_1km.tif"  #this is the global file: replace later with the input produced by the DEM team
89 96
infile_canheight<-"/home/layers/data/land-cover/treeheight-simard2011/Simard_Pinto_3DGlobalVeg_JGR.tif"              #Canopy height
90 97
list_tiles_modis <- c('h11v08','h11v07','h12v07','h12v08','h10v07','h10v08') #tile for Venezuel and surrounding area
......
95 102

  
96 103
CRS_interp<-"+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181 +b=6371007.181 +units=m +no_defs";
97 104
#CRS_interp <-"+proj=lcc +lat_1=43 +lat_2=45.5 +lat_0=41.75 +lon_0=-120.5 +x_0=400000 +y_0=0 +ellps=GRS80 +units=m +no_defs";
98

  
99 105
CRS_locs_WGS84<-CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +towgs84=0,0,0") #Station coords WGS84
100 106
out_region_name<-"_venezuela_region" #generated on the fly
101
out_suffix<-"_VE_04162013"
107
out_suffix<-"_VE_05092013"
102 108
ref_rast_name<-""  #local raster name defining resolution, exent, local projection--. set on the fly??
103 109
#ref_rast_name<-"mean_day244_rescaled.rst"  #local raster name defining resolution, exent: oregon
104 110

  
......
119 125
                                      "list_tiles_modis","infile_reg_outline","CRS_interp","CRS_locs_WGS84","out_region_name",
120 126
                                      "out_suffix","ref_rast_name","covar_names") 
121 127

  
128
## Modify to store infile_covar_brick in output folder!!!
122 129
if (stages_to_run[2]==2){
123 130
  #Transform into function...
124 131
  #/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/covariates_production_temperatures_03212013.R
125 132
  infile_covar_brick<-covariates_production_temperature(list_param_covar_production)
133
}else{
134
  #Provide brick of covariates if stage 2 is not run
135
  infile_covariates<-"/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/covariates__venezuela_region__VE_01292013.tif" #this is an output from covariate script and used in stage 3 and stage 4
136
  #infile_covariates<-"/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/covariates__venezuela_region_TMIN__VE_03192013.tif" #covariates stack for TMIN
137
  #infile_covariates<- "/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/covariates_Oregon_region_TMAX__OR_04052013.tif" #Oregon covar TMAX from earlier codes...for continuity
126 138
}
127 139

  
128 140
############# STAGE 3: Data preparation ###############
......
131 143
#set up earlier
132 144
#var <- "TMIN"           # name of the variables to keep: TMIN, TMAX or PRCP --already set up earlier
133 145

  
134
infile_covariates<-"covariates__venezuela_region__VE_01292013.tif" #this is an output from covariate script and used in stage 3 and stage 4
135
#infile_covariates<-"covariates__venezuela_region_TMIN__VE_03192013.tif" #covariates stack for TMIN
136
#infile_covariates<- "covariates_Oregon_region_TMAX__OR_04052013.tif" #Oregon covar TMAX from earlier codes...for continuity
137

  
138 146
#CRS_locs_WGS84<-CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +towgs84=0,0,0") #Station coords WGS84: same as earlier
139
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
147
infile1<- "/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/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
140 148
#infile_reg_outline <- "OR83M_state_outline.shp"  #input region outline defined by polygon: Oregon
141 149
#infile1 <-"OR83M_state_outline.shp" #remove this parameter!!!
142

  
143 150
#covar_names see stage 2
144 151

  
145 152
#specific to this stage
......
148 155
range_years_clim<-c("2000","2011") #right bound not included in the range!!
149 156
infile2<-"/home/layers/data/climate/ghcn/v2.92-upd-2012052822/ghcnd-stations.txt"                              #This is the textfile of station locations from GHCND
150 157
#in_path <- "/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/input_data/"
151
out_prefix<-"_365d_GAM_CAI_all_lst_04162013"                #User defined output prefix
158
#out_prefix<-"_365d_GAM_CAI_all_lst_04162013"                #User defined output prefix
152 159
qc_flags_stations<-c("0","S")    #flags allowed for screening after the query from the GHCND??
153 160
#qc_flags_stations<-c("0")   #flags allowed for screening after the query from the GHCND??
154 161

  
155 162
#list of 12 parameters for input in the function...
156 163

  
157
list_param_prep<-list(db.name,var,range_years,range_years_clim,infile1,infile2,infile_covariates,CRS_locs_WGS84,in_path,covar_names,qc_flags_stations,out_prefix)
158
cnames<-c("db.name","var","range_years","range_years_clim","infile1","infile2","infile_covariates","CRS_locs_WGS84","in_path","covar_names","qc_flags_stations","out_prefix")
164
list_param_prep<-list(db.name,var,range_years,range_years_clim,infile1,infile2,infile_covariates,CRS_locs_WGS84,in_path,out_path,covar_names,qc_flags_stations,out_prefix)
165
cnames<-c("db.name","var","range_years","range_years_clim","infile1","infile2","infile_covariates","CRS_locs_WGS84","in_path","out_path","covar_names","qc_flags_stations","out_prefix")
159 166
names(list_param_prep)<-cnames
160 167

  
161 168
##### RUN SCRIPT TO GET STATION DATA WITH COVARIATES #####
......
196 203
               "y_var ~ s(lat,lon,elev_s)",
197 204
               "y_var ~ s(lat,lon) + s(elev_s) + s(N_w,E_w) + s(LST)", 
198 205
               "y_var ~ s(lat,lon) + s(elev_s) + s(N_w,E_w) + s(LST) + s(LC2)",
199
               "y_var ~ s(lat,lon) + s(elev_s) + s(N_w,E_w) + s(LST) + s(LC6)", 
200
               "y_var ~ s(lat,lon) + s(elev_s) + s(N_w,E_w) + s(LST) + s(DISTOC)")
206
               "y_var ~ s(lat,lon) + s(elev_s) + s(N_w,E_w) + s(LST) + s(LC6)")
207
#               "y_var ~ s(lat,lon) + s(elev_s) + s(N_w,E_w) + s(LST) + s(DISTOC)")
201 208

  
202 209
#Choose interpolation method...
203 210
#interpolation_method<-c("gam_fusion","gam_CAI") #other otpions to be added later
204 211
interpolation_method<-c("gam_CAI") #other otpions to be added later
205

  
212
#interpolation_method<-c("gam_fusion") #other otpions to be added later
206 213

  
207 214
#Default name of LST avg to be matched               
208 215
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")  
209
#in_path<-"/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/input_data"
210
#Create on the fly output folder...
211
#out_path<-"/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/output_data"
212
#script_path<-"/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/"
213

  
214 216

  
215 217
#Collect all parameters in a list
216 218
list_param_raster_prediction<-list(list_param_data_prep,
......
226 228

  
227 229
raster_prediction_obj <-raster_prediction_fun(list_param_raster_prediction)
228 230

  
229

  
230 231
############## STAGE 5: OUTPUT ANALYSES ##################
231 232

  
232
date_selected<-c("20100101") ##This is for year 2000!!!
233
date_selected_results<-c("20100101") ##This is for year 2000!!!
233 234
#raster_prediction_obj<-load_obj("raster_prediction_obj_dailyTmin_365d_GAM_fus5_all_lstd_03292013.RData")
234 235
#raster_prediction_obj<-load_obj("raster_prediction_obj_gam_CAI_dailyTmax_365d_GAM_CAI_all_lst_04162013.RData")
235 236
#raster_prediciton_obj<-load_obj(paste("raster_prediction_obj","_","interpolation_method,
236 237
#                                y_var_name,out_prefix,sep="")
237
list_param_results_analyses<-list(in_path,out_path,script_path,raster_prediction_obj,interpolation_method,infile_covar,covar_names,date_selected,var,out_prefix)
238
list_param_results_analyses<-list(in_path,out_path,script_path,raster_prediction_obj,interpolation_method,
239
                                  infile_covariates,covar_names,date_selected_results,var,out_prefix)
238 240
names(list_param_results_analyses)<-c("in_path","out_path","script_path","raster_prediction_obj","interpolation_method",
239
                     "infile_covar","covar_names","date_selected","var","out_prefix")
241
                     "infile_covariates","covar_names","date_selected_results","var","out_prefix")
240 242
#plots_assessment_by_date<-function(j,list_param){
241

  
242
plots_assessment_by_date(1,list_param_results_analyses)
243
#source(file.path(script_path,"results_interpolation_date_output_analyses_04302013.R"))
244
#Call as function...
245

  
243
if (stages_to_run[5]==5){
244
  #source(file.path(script_path,"results_interpolation_date_output_analyses_05062013.R"))
245
  plots_assessment_by_date(1,list_param_results_analyses)
246
  #Call as function...
247
}
248
  
246 249
###############   END OF SCRIPT   ###################
247 250
#####################################################
248 251

  

Also available in: Unified diff