Revision 86216d9e
Added by Benoit Parmentier over 11 years ago
climate/research/oregon/interpolation/master_script_temp.R | ||
---|---|---|
1 | 1 |
################## Master script for temperature predictions ####################################### |
2 | 2 |
############################ TMIN AND TMAX predictions ########################################## |
3 | 3 |
# |
4 |
##This script produces intperpolated surface of TMIN and TMAX for specified processing region given sets |
|
4 |
##This script produces intperpolated surface of TMIN and TMAX for specified processing region(s) given sets
|
|
5 | 5 |
#of inputs and parameters. |
6 | 6 |
#STAGE 1: LST climatology calculation |
7 | 7 |
#STAGE 2: Covariates preparation: aspect, land cover, distance to coast etc. |
... | ... | |
10 | 10 |
#STAGE 5: Output analyses-visualization of results for specific dates... |
11 | 11 |
# |
12 | 12 |
#AUTHOR: Benoit Parmentier |
13 |
#DATE: 05/09/2013
|
|
13 |
#DATE: 05/14/2013
|
|
14 | 14 |
|
15 | 15 |
#PROJECT: NCEAS INPLANT: Environment and Organisms --TASK#363, TASK$568-- |
16 | 16 |
|
... | ... | |
20 | 20 |
# Add options to run only specific stage + additional out_suffix? |
21 | 21 |
# Make master script a function? |
22 | 22 |
# Add log file for master script,add function to collect inputs and outputs |
23 |
# |
|
23 | 24 |
################################################################################################## |
24 | 25 |
|
25 | 26 |
###Loading R library and packages |
... | ... | |
39 | 40 |
library(reshape) |
40 | 41 |
library(plotrix) |
41 | 42 |
|
42 |
### Parameters and arguments |
|
43 |
######## PARAMETERS FOR WORK FLOW ######################### |
|
44 |
### Need to add documentation ### |
|
45 |
|
|
43 | 46 |
script_path<-"/home/parmentier/Data/IPLANT_project/env_layers_scripts/" |
44 | 47 |
#script_path<-"/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/" |
45 | 48 |
#list_script_files<- |
46 |
#stages_to_run<-c(1,2,3,4,5) #May decide on antoher strategy later on... |
|
47 |
stages_to_run<-c(0,0,3,4,5) #May decide on antoher strategy later on... |
|
48 | 49 |
|
49 |
#####SCRIPT USED FOR THE PREDICTIONS: Source all scripts here to avoid confusion on versions being run!!!!
|
|
50 |
##SCRIPT USED FOR THE PREDICTIONS: Source all scripts here to avoid confusion on versions being run!!!! |
|
50 | 51 |
|
51 |
#source(file.path(script_path,"master_script_temp_05062013.R")) #Master script can be run directly...
|
|
52 |
#source(file.path(script_path,"master_script_temp_05132013.R")) #Master script can be run directly...
|
|
52 | 53 |
|
53 | 54 |
#CALLED FROM MASTER SCRIPT: |
54 |
|
|
55 |
#/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/climatology_03192013.py |
|
56 |
source(file.path(script_path,"covariates_production_temperatures_03212013.R")) |
|
55 |
#modis_download_script <- file.path(script_path,"modis_download_05132013.py") # LST modis download python script |
|
56 |
modis_download_script <- file.path(script_path,"modis_download_05142013.py") # LST modis download python script |
|
57 |
clim_script <- file.path(script_path,"climatology_05132013.py") # LST climatology python script |
|
58 |
grass_setting_script <- file.path(script_path,"grass-setup.R") |
|
59 |
source(file.path(script_path,"covariates_production_temperatures_05132013.R")) |
|
57 | 60 |
source(file.path(script_path,"Database_stations_covariates_processing_function_05062013.R")) |
58 | 61 |
source(file.path(script_path,"GAM_fusion_analysis_raster_prediction_multisampling_05062013.R")) |
59 | 62 |
source(file.path(script_path,"results_interpolation_date_output_analyses_05062013.R")) |
... | ... | |
65 | 68 |
source(file.path(script_path,"GAM_fusion_function_multisampling_05062013.R")) #Include GAM_CAI |
66 | 69 |
source(file.path(script_path,"GAM_fusion_function_multisampling_validation_metrics_05062013.R")) |
67 | 70 |
|
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_03182013.py |
|
73 |
} |
|
74 |
|
|
75 |
############ STAGE 2: Covariate production ################ |
|
71 |
#stages_to_run<-c(1,2,3,4,5) #May decide on antoher strategy later on... |
|
72 |
stages_to_run<-c(0,0,3,4,5) #May decide on antoher strategy later on... |
|
76 | 73 |
|
77 |
##Paths to inputs and output |
|
78 |
var<-"TMAX" |
|
79 |
out_prefix<-"_365d_GAM_CAI_all_lst_05092013" #User defined output prefix |
|
74 |
var<-"TMAX" # variable being interpolated |
|
75 |
out_prefix<-"_365d_GAM_CAI_all_lst_05132013" #User defined output prefix |
|
76 |
#interpolation_method<-c("gam_fusion","gam_CAI") #other otpions to be added later |
|
77 |
interpolation_method<-c("gam_CAI") #other otpions to be added later |
|
78 |
#interpolation_method<-c("gam_fusion") #other otpions to be added later |
|
80 | 79 |
|
81 | 80 |
#Change input path?? for LST stage ?? |
82 | 81 |
in_path <- "/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/input_data/" |
83 |
#in_path <-"/home/parmentier/Data/IPLANT_project/Oregon_interpolation/Oregon_03142013/input" |
|
84 | 82 |
#in_path <- out_path |
85 | 83 |
out_path <- paste("/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/output_data", |
86 | 84 |
out_prefix,"/",sep="") |
87 | 85 |
if (!file.exists(out_path)){ |
88 | 86 |
dir.create(out_path) |
89 |
#} else{ |
|
90 |
# out_path <-paste(out_path..) |
|
91 |
#}
|
|
92 |
|
|
87 |
#} else{
|
|
88 |
# out_path <-paste(out_path..)
|
|
89 |
} |
|
90 |
|
|
93 | 91 |
lc_path<-"/home/layers/data/land-cover/lc-consensus-global" |
94 | 92 |
infile_modis_grid<-"modis_sinusoidal_grid_world.shp" #Give path!!! NEED TO CHANGE THIS... |
95 | 93 |
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 |
96 | 94 |
infile_canheight<-"/home/layers/data/land-cover/treeheight-simard2011/Simard_Pinto_3DGlobalVeg_JGR.tif" #Canopy height |
97 |
list_tiles_modis <- c('h11v08','h11v07','h12v07','h12v08','h10v07','h10v08') #tile for Venezuel and surrounding area
|
|
95 |
list_tiles_modis <- c("h11v08,h11v07,h12v07,h12v08,h10v07,h10v08") #tile for Venezuela and surrounding area
|
|
98 | 96 |
#list_tiles_modis <- c("h08v04","h09v04") #tiles for Oregon |
99 |
|
|
97 |
|
|
100 | 98 |
infile_reg_outline="" #input region outline defined by polygon: none for Venezuel |
101 | 99 |
#infile_reg_outline <- "OR83M_state_outline.shp" #input region outline defined by polygon: Oregon |
102 |
|
|
100 |
|
|
103 | 101 |
CRS_interp<-"+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181 +b=6371007.181 +units=m +no_defs"; |
104 | 102 |
#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"; |
105 | 103 |
CRS_locs_WGS84<-CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +towgs84=0,0,0") #Station coords WGS84 |
... | ... | |
107 | 105 |
out_suffix<-"_VE_05092013" |
108 | 106 |
ref_rast_name<-"" #local raster name defining resolution, exent, local projection--. set on the fly?? |
109 | 107 |
#ref_rast_name<-"mean_day244_rescaled.rst" #local raster name defining resolution, exent: oregon |
110 |
|
|
108 |
|
|
111 | 109 |
#The names of covariates can be changed...these names should be output/input from covar script!!! |
112 | 110 |
rnames<-c("x","y","lon","lat","N","E","N_w","E_w","elev_s","slope","aspect","CANHEIGHT","DISTOC") |
113 | 111 |
lc_names<-c("LC1","LC2","LC3","LC4","LC5","LC6","LC7","LC8","LC9","LC10","LC11","LC12") |
114 | 112 |
#lc_names<-c("LC1","LC2","LC3","LC4","LC5","LC6","LC7","LC8","LC9","LC10") #use older version for continuity check to be changed |
115 | 113 |
lst_names<-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", |
116 |
"nobs_01","nobs_02","nobs_03","nobs_04","nobs_05","nobs_06","nobs_07","nobs_08", |
|
117 |
"nobs_09","nobs_10","nobs_11","nobs_12") |
|
114 |
"nobs_01","nobs_02","nobs_03","nobs_04","nobs_05","nobs_06","nobs_07","nobs_08",
|
|
115 |
"nobs_09","nobs_10","nobs_11","nobs_12")
|
|
118 | 116 |
covar_names<-c(rnames,lc_names,lst_names) |
119 |
|
|
117 |
|
|
120 | 118 |
list_param_covar_production<-list(var,in_path,out_path,lc_path,infile_modis_grid,infile_elev,infile_canheight, |
121 |
list_tiles_modis,infile_reg_outline,CRS_interp,CRS_locs_WGS84,out_region_name, |
|
122 |
out_suffix,ref_rast_name,covar_names) |
|
123 |
|
|
119 |
list_tiles_modis,infile_reg_outline,CRS_interp,CRS_locs_WGS84,out_region_name,
|
|
120 |
out_suffix,ref_rast_name,covar_names)
|
|
121 |
|
|
124 | 122 |
names(list_param_covar_production)<-c("var","in_path","out_path","lc_path","infile_modis_grid","infile_elev","infile_canheight", |
125 |
"list_tiles_modis","infile_reg_outline","CRS_interp","CRS_locs_WGS84","out_region_name", |
|
126 |
"out_suffix","ref_rast_name","covar_names") |
|
123 |
"list_tiles_modis","infile_reg_outline","CRS_interp","CRS_locs_WGS84","out_region_name", |
|
124 |
"out_suffix","ref_rast_name","covar_names") |
|
125 |
|
|
126 |
############ STAGE 1: LST Climatology ############### |
|
127 |
|
|
128 |
#Parameters,Inputs from R to Python?? |
|
129 |
#tiles = ['h11v08','h11v07','h12v07','h12v08','h10v07','h10v08'] #These tiles correspond to Venezuela. |
|
130 |
list_tiles_modis <- c("h11v08,h11v07,h12v07,h12v08,h10v07,h10v08") #tile for Venezuel and surrounding area |
|
131 |
#list_tiles_modis <- c("h08v04,h09v04") #tiles for Oregon #defined above... |
|
132 |
start_year = "2001" |
|
133 |
end_year = "2010" |
|
134 |
#end_year = "2002" #for testing (year included?) |
|
135 |
end_month= "12" |
|
136 |
start_month= "1" |
|
137 |
hdfdir = '/home/layers/commons/modis/MOD11A1_tiles' #destination file where hdf files are stored locally after download. |
|
138 |
|
|
139 |
if (!file.exists(hdfdir)){ |
|
140 |
dir.create(hdfdir) |
|
141 |
#} else{ |
|
142 |
# out_path <-paste(out_path..) |
|
143 |
} |
|
144 |
if (var=="TMIN") { |
|
145 |
night="1" # if 1 then produce night climatology |
|
146 |
} else{ |
|
147 |
night="0" # if 0 then produce day climatology |
|
148 |
} |
|
149 |
download="1" # if 1 then download modis files before calculating averages |
|
150 |
out_suffix_modis="_05132013" |
|
151 |
|
|
152 |
list_param_python_script <- list(list_tiles_modis,start_year,end_year,start_month,end_month,hdfdir, |
|
153 |
night,download,out_suffix_modis) |
|
154 |
names(list_param_python_script)<-c("list_tiles_modis","start_year","end_year","start_month","end_month","hdfdir", |
|
155 |
"night","download","out_suffix_modis") |
|
156 |
list_param_python_script_str <- paste(unlist(list_param_python_script), collapse=" ") |
|
157 |
#command_str<-"python /home/parmentier/Data/test5.py h01v05,h02v05 2001 2005 12 1 /benoit 1 test_out 1" |
|
158 |
#paste(toString(list_param_python_script),collapse=",",sep=" ") |
|
159 |
|
|
160 |
if (stages_to_run[1]==1){ |
|
161 |
##Run download if necessary |
|
162 |
if (download==1){ |
|
163 |
command_str <- paste("python",modis_download_script, list_param_python_script_str,sep=" ") |
|
164 |
#command_str <- paste("python","/home/parmentier/Data/benoit_test/test5.py", list_param_python_script_str,sep=" ") |
|
165 |
system(command_str) |
|
166 |
} |
|
167 |
##Now run climatology |
|
168 |
source(grass_setting_script) |
|
169 |
command_str <- paste("python",clim_script, list_param_python_script_str,sep=" ") |
|
170 |
system(command_str) |
|
171 |
#/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/climatology_05132013.py |
|
172 |
} |
|
173 |
|
|
174 |
############ STAGE 2: Covariate production ################ |
|
175 |
|
|
127 | 176 |
|
128 | 177 |
## Modify to store infile_covar_brick in output folder!!! |
129 | 178 |
if (stages_to_run[2]==2){ |
... | ... | |
139 | 188 |
|
140 | 189 |
############# STAGE 3: Data preparation ############### |
141 | 190 |
|
142 |
#Setting up input argurments for script function... |
|
143 |
#set up earlier |
|
144 |
#var <- "TMIN" # name of the variables to keep: TMIN, TMAX or PRCP --already set up earlier |
|
145 |
|
|
146 |
#CRS_locs_WGS84<-CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +towgs84=0,0,0") #Station coords WGS84: same as earlier |
|
147 | 191 |
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 |
148 | 192 |
#infile_reg_outline <- "OR83M_state_outline.shp" #input region outline defined by polygon: Oregon |
149 | 193 |
#infile1 <-"OR83M_state_outline.shp" #remove this parameter!!! |
... | ... | |
154 | 198 |
range_years<-c("2010","2011") #right bound not included in the range!! |
155 | 199 |
range_years_clim<-c("2000","2011") #right bound not included in the range!! |
156 | 200 |
infile2<-"/home/layers/data/climate/ghcn/v2.92-upd-2012052822/ghcnd-stations.txt" #This is the textfile of station locations from GHCND |
157 |
#in_path <- "/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/input_data/" |
|
158 |
#out_prefix<-"_365d_GAM_CAI_all_lst_04162013" #User defined output prefix |
|
159 | 201 |
qc_flags_stations<-c("0","S") #flags allowed for screening after the query from the GHCND?? |
160 |
#qc_flags_stations<-c("0") #flags allowed for screening after the query from the GHCND?? |
|
161 | 202 |
|
162 | 203 |
#list of 12 parameters for input in the function... |
163 | 204 |
|
... | ... | |
206 | 247 |
"y_var ~ s(lat,lon) + s(elev_s) + s(N_w,E_w) + s(LST) + s(LC6)") |
207 | 248 |
# "y_var ~ s(lat,lon) + s(elev_s) + s(N_w,E_w) + s(LST) + s(DISTOC)") |
208 | 249 |
|
209 |
#Choose interpolation method... |
|
210 |
#interpolation_method<-c("gam_fusion","gam_CAI") #other otpions to be added later |
|
211 |
interpolation_method<-c("gam_CAI") #other otpions to be added later |
|
212 |
#interpolation_method<-c("gam_fusion") #other otpions to be added later |
|
213 | 250 |
|
214 | 251 |
#Default name of LST avg to be matched |
215 | 252 |
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") |
... | ... | |
219 | 256 |
seed_number,nb_sample,step,constant,prop_minmax,dates_selected, |
220 | 257 |
list_models,lst_avg,in_path,out_path,script_path, |
221 | 258 |
interpolation_method) |
222 |
|
|
223 | 259 |
names(list_param_raster_prediction)<-c("list_param_data_prep", |
224 | 260 |
"seed_number","nb_sample","step","constant","prop_minmax","dates_selected", |
225 | 261 |
"list_models","lst_avg","in_path","out_path","script_path", |
226 | 262 |
"interpolation_method") |
227 | 263 |
|
228 |
|
|
229 | 264 |
raster_prediction_obj <-raster_prediction_fun(list_param_raster_prediction) |
230 | 265 |
|
231 | 266 |
############## STAGE 5: OUTPUT ANALYSES ################## |
232 | 267 |
|
233 | 268 |
date_selected_results<-c("20100101") ##This is for year 2000!!! |
234 |
#raster_prediction_obj<-load_obj("raster_prediction_obj_dailyTmin_365d_GAM_fus5_all_lstd_03292013.RData") |
|
235 |
#raster_prediction_obj<-load_obj("raster_prediction_obj_gam_CAI_dailyTmax_365d_GAM_CAI_all_lst_04162013.RData") |
|
236 | 269 |
#raster_prediciton_obj<-load_obj(paste("raster_prediction_obj","_","interpolation_method, |
237 | 270 |
# y_var_name,out_prefix,sep="") |
238 | 271 |
list_param_results_analyses<-list(in_path,out_path,script_path,raster_prediction_obj,interpolation_method, |
Also available in: Unified diff
master script, adding call to python scripts