Revision e9283712
Added by Benoit Parmentier over 11 years ago
climate/research/oregon/interpolation/master_script_temp.R | ||
---|---|---|
10 | 10 |
#STAGE 5: Output analyses: assessment of results for specific dates... |
11 | 11 |
# |
12 | 12 |
#AUTHOR: Benoit Parmentier |
13 |
#DATE: 06/11/2013
|
|
13 |
#DATE: 06/19/2013
|
|
14 | 14 |
|
15 | 15 |
#PROJECT: NCEAS INPLANT: Environment and Organisms --TASK#363, TASK$568-- |
16 | 16 |
|
17 | 17 |
## TODO: |
18 |
# Modify code for stage 1 and call python script from R |
|
19 |
# Modify code for stage 2, make it a function and fully automated (distoc var) |
|
18 |
# Modify code for stage 1 and call python script from R in parallel |
|
20 | 19 |
# Add options to run only specific stage + additional out_suffix? |
21 | 20 |
# Make master script a function? |
22 | 21 |
# Add log file for master script,add function to collect inputs and outputs |
23 |
# Comments for run: |
|
24 |
#Testing full code for 5 stages (no downloading) for Oregon region. |
|
25 | 22 |
################################################################################################## |
26 | 23 |
|
27 | 24 |
###Loading R library and packages |
... | ... | |
56 | 53 |
clim_script <- file.path(script_path,"climatology_05312013.py") # LST climatology python script |
57 | 54 |
grass_setting_script <- file.path(script_path,"grass-setup.R") #Set up system shell environment for python+GRASS |
58 | 55 |
source(file.path(script_path,"download_and_produce_MODIS_LST_climatology_05302013.R")) |
59 |
source(file.path(script_path,"covariates_production_temperatures_06072013.R"))
|
|
56 |
source(file.path(script_path,"covariates_production_temperatures_06192013.R"))
|
|
60 | 57 |
source(file.path(script_path,"Database_stations_covariates_processing_function_05212013.R")) |
61 | 58 |
source(file.path(script_path,"GAM_fusion_analysis_raster_prediction_multisampling_06082013.R")) |
62 | 59 |
source(file.path(script_path,"results_interpolation_date_output_analyses_06102013.R")) |
... | ... | |
73 | 70 |
stages_to_run<-c(0,2,3,4,5) #May decide on antoher strategy later on... |
74 | 71 |
|
75 | 72 |
var<-"TMAX" # variable being interpolated |
76 |
#out_prefix<-"_365d_kriging_day_lst_06072013" #User defined output prefix |
|
77 |
out_prefix<-"_365d_GAM_fus_all_lst_06112013" #User defined output prefix |
|
78 |
out_suffix<-"_QE_06112013" |
|
79 |
#out_suffix_modis <-"_05302013" #use tiles produce previously |
|
80 |
out_suffix_modis <-"_05242013" #use tiles produce previously |
|
73 |
out_prefix<-"_365d_gwr_day_lst_06192013" #User defined output prefix |
|
74 |
out_suffix<-"_OR_06192013" |
|
75 |
out_suffix_modis <-"_05302013" #use tiles produce previously |
|
81 | 76 |
|
82 | 77 |
#interpolation_method<-c("gam_fusion","gam_CAI","gam_daily") #other otpions to be added later |
83 | 78 |
#interpolation_method<-c("gam_CAI") #other otpions to be added later |
84 |
interpolation_method<-c("gam_fusion") #other otpions to be added later |
|
79 |
#interpolation_method<-c("gam_fusion") #other otpions to be added later
|
|
85 | 80 |
#interpolation_method<-c("gam_daily") #other otpions to be added later |
86 | 81 |
#interpolation_method<-c("kriging_daily") #other otpions to be added later |
87 |
#interpolation_method<-c("gwr_daily") #other otpions to be added later
|
|
82 |
interpolation_method<-c("gwr_daily") #other otpions to be added later |
|
88 | 83 |
|
89 | 84 |
#out_path <- paste("/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/output_data", |
90 | 85 |
# out_prefix,"/",sep="") |
91 |
#out_path<-"/home/parmentier/Data/IPLANT_project/Oregon_interpolation/Oregon_03142013/output_data" |
|
92 |
out_path<-"/home/parmentier/Data/IPLANT_project/Queensland_interpolation/output_data" |
|
93 |
|
|
86 |
out_path<-"/home/parmentier/Data/IPLANT_project/Oregon_interpolation/Oregon_03142013/output_data" |
|
94 | 87 |
out_path <-paste(out_path,out_prefix,sep="") |
95 | 88 |
|
96 | 89 |
if (!file.exists(out_path)){ |
... | ... | |
108 | 101 |
#infile_reg_outline<- "/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/outline_venezuela_region__VE_01292013.shp" |
109 | 102 |
#infile_covariates<-"/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/covariates__venezuela_region_TMIN__VE_03192013.tif" #covariates stack for TMIN |
110 | 103 |
#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 |
111 |
infile_reg_outline="" #input region outline defined by polygon: none for Venezuela |
|
104 |
#infile_reg_outline="" #input region outline defined by polygon: none for Venezuela
|
|
112 | 105 |
#This is the shape file of outline of the study area #It is an input/output of the covariate script |
113 |
#infile_reg_outline <- "/home/parmentier/Data/IPLANT_project/Oregon_interpolation/Oregon_03142013/OR83M_state_outline.shp" #input region outline defined by polygon: Oregon
|
|
106 |
infile_reg_outline <- "/home/parmentier/Data/IPLANT_project/Oregon_interpolation/Oregon_03142013/OR83M_state_outline.shp" #input region outline defined by polygon: Oregon |
|
114 | 107 |
#infile_reg_outline <-"OR83M_state_outline.shp" #remove this parameter!!! |
115 |
ref_rast_name<-"" #local raster name defining resolution, exent, local projection--. set on the fly?? |
|
108 |
#ref_rast_name<-"" #local raster name defining resolution, exent, local projection--. set on the fly??
|
|
116 | 109 |
#this may be redundant with infile_reg_outline |
117 |
#ref_rast_name<-"/home/parmentier/Data/IPLANT_project/Oregon_interpolation/Oregon_03142013/mean_day244_rescaled.rst" #local raster name defining resolution, exent: oregon
|
|
110 |
ref_rast_name<-"/home/parmentier/Data/IPLANT_project/Oregon_interpolation/Oregon_03142013/mean_day244_rescaled.rst" #local raster name defining resolution, exent: oregon |
|
118 | 111 |
|
119 | 112 |
#covar_names see stage 2 |
120 | 113 |
|
121 | 114 |
#list_tiles_modis <- c("h11v08,h11v07,h12v07,h12v08,h10v07,h10v08") #tile for Venezuela and surrounding area |
122 |
#list_tiles_modis <- c("h08v04,h09v04") #tiles for Oregon |
|
123 |
list_tiles_modis <-c("h30v10,h31v10,h32v10,h30v11,h31v11") #list("Queensland") |
|
124 |
|
|
125 |
|
|
126 |
CRS_interp<-"+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181 +b=6371007.181 +units=m +no_defs"; |
|
127 |
#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"; |
|
115 |
list_tiles_modis <- c("h08v04,h09v04") #tiles for Oregon |
|
116 |
|
|
117 |
#CRS_interp<-"+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181 +b=6371007.181 +units=m +no_defs"; |
|
118 |
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"; |
|
128 | 119 |
#"+proj=lcc +lat_1=43 +lat_2=45.5 +lat_0=41.75 +lon_0=-120.5 +x_0=400000 +y_0=0 +datum=NAD83 +units=m +no_defs +ellps=GRS80" |
129 | 120 |
CRS_locs_WGS84<-CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +towgs84=0,0,0") #Station coords WGS84 |
130 | 121 |
#out_region_name<-"_venezuela_region" #generated on the fly |
131 |
out_region_name<-"_queensland_region" #generated on the fly
|
|
122 |
out_region_name<-"_oregon_region" #generated on the fly
|
|
132 | 123 |
|
133 | 124 |
#The names of covariates can be changed...these names should be output/input from covar script!!! |
134 | 125 |
rnames<-c("x","y","lon","lat","N","E","N_w","E_w","elev_s","slope","aspect","CANHEIGHT","DISTOC") |
... | ... | |
139 | 130 |
"nobs_09","nobs_10","nobs_11","nobs_12") |
140 | 131 |
covar_names<-c(rnames,lc_names,lst_names) |
141 | 132 |
|
133 |
list_val_range <-c("lon,180,180","lat,-90,90","N,-1,1","E,-1,1","N_w,-1,1","E_w,-1,1","elev_s,0,6000","slope,0,90", |
|
134 |
"aspect,0,360","DISTOC,-0,10000000","CANHEIGHT,0,255","LC1,0,100","LC3,0,100","mm_01,-15,50", |
|
135 |
"mm_02,-15,50","mm_03,-15,50","mm_04,-15,50","mm_05,-15,50","mm_06,-15,50","mm_07,-15,50", |
|
136 |
"mm_08,-15,50","mm_09,-15,50","mm_10,-15,50","mm_11,-15,50","mm_12,-15,50") |
|
137 |
|
|
142 | 138 |
############ STAGE 1: LST Climatology ############### |
143 | 139 |
|
144 | 140 |
#Parameters,Inputs from R to Python?? |
... | ... | |
170 | 166 |
#list of 17 parameters |
171 | 167 |
list_param_covar_production<-list(var,out_path,lc_path,infile_modis_grid,infile_elev,infile_canheight, |
172 | 168 |
infile_distoc,list_tiles_modis,infile_reg_outline,CRS_interp,CRS_locs_WGS84,out_region_name, |
173 |
out_suffix,out_suffix_modis,ref_rast_name,hdfdir,covar_names) |
|
169 |
list_val_range,out_suffix,out_suffix_modis,ref_rast_name,hdfdir,covar_names)
|
|
174 | 170 |
|
175 | 171 |
names(list_param_covar_production)<-c("var","out_path","lc_path","infile_modis_grid","infile_elev","infile_canheight", |
176 | 172 |
"infile_distoc","list_tiles_modis","infile_reg_outline","CRS_interp","CRS_locs_WGS84","out_region_name", |
177 |
"out_suffix","out_suffix_modis","ref_rast_name","hdfdir","covar_names") |
|
173 |
"list_val_range","out_suffix","out_suffix_modis","ref_rast_name","hdfdir","covar_names")
|
|
178 | 174 |
|
179 | 175 |
## Modify to store infile_covar_brick in output folder!!! |
180 | 176 |
if (stages_to_run[2]==2){ |
181 | 177 |
covar_obj <- covariates_production_temperature(list_param_covar_production) |
182 | 178 |
infile_covariates <- covar_obj$infile_covariates |
183 | 179 |
infile_reg_outline <- covar_obj$infile_reg_outline |
180 |
covar_names<- covar_obj$covar_names |
|
184 | 181 |
} |
185 | 182 |
|
186 | 183 |
#Note that if stages_to_run[2]!=2, then use values defined at the beginning of the script for infile_covariates and infile_reg_outline |
... | ... | |
194 | 191 |
range_years_clim<-c("2000","2011") #right bound not included in the range!! |
195 | 192 |
infile_ghncd_data <-"/home/layers/data/climate/ghcn/v2.92-upd-2012052822/ghcnd-stations.txt" #This is the textfile of station locations from GHCND |
196 | 193 |
#qc_flags_stations<-c("0","S") #flags allowed for screening after the query from the GHCND?? |
197 |
#qc_flags_stations<-c("0") #flags allowed for screening after the query from the GHCND?? |
|
198 |
qc_flags_stations<-c("0","a") #flags allowed for screening after the query from the GHCND?? |
|
194 |
qc_flags_stations<-c("0") #flags allowed for screening after the query from the GHCND?? |
|
199 | 195 |
|
200 | 196 |
#infile_covariates and infile_reg_outline defined in stage 2 or at the start of script... |
201 | 197 |
|
... | ... | |
237 | 233 |
|
238 | 234 |
#Models to run...this can be change for each run |
239 | 235 |
|
240 |
list_models<-c("y_var ~ s(elev_s)", |
|
241 |
"y_var ~ s(LST)", |
|
242 |
"y_var ~ s(elev_s,LST)") |
|
243 |
# "y_var ~ s(lat) + s(lon)+ s(elev_s)", |
|
244 |
# "y_var ~ s(lat,lon,elev_s)", |
|
245 |
# "y_var ~ s(lat,lon) + s(elev_s) + s(N_w,E_w) + s(LST)", |
|
246 |
# "y_var ~ s(lat,lon) + s(elev_s) + s(N_w,E_w) + s(LST) + s(LC2)", |
|
247 |
# "y_var ~ s(lat,lon) + s(elev_s) + s(N_w,E_w) + s(LST) + s(LC6)", |
|
248 |
# "y_var ~ s(lat,lon) + s(elev_s) + s(N_w,E_w) + s(LST) + s(DISTOC)") |
|
236 |
list_models<-c("y_var ~ elev_s", |
|
237 |
"y_var ~ LST", |
|
238 |
"y_var ~ elev_s*LST") |
|
239 |
# "y_var ~ lat + lon + elev_s", |
|
240 |
# "y_var ~ lat*lon*elev_s", |
|
241 |
# "y_var ~ lat*lon + elev_s + N_w*E_w + LST", |
|
242 |
# "y_var ~ lat*lon + elev_s + N_w*E_w + LST + LC2", |
|
243 |
# "y_var ~ lat*lon + elev_s + N_w*E_w + LST + LC6", |
|
244 |
# "y_var ~ lat*lon + elev_s + N_w*E_w + LST + DISTOC") |
|
245 |
|
|
249 | 246 |
#list_models<-c("y_var~ lat + lon + elev_", |
250 | 247 |
# "y_var~ I(lat*lon) + elev_s", |
251 | 248 |
# "y_var~ lat + lon + elev_s + N + E + DISTOC", |
Also available in: Unified diff
master script adding arguments to screen covariates