Revision 55408bb4
Added by Benoit Parmentier over 11 years ago
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/14/2013
|
|
13 |
#DATE: 05/17/2013
|
|
14 | 14 |
|
15 | 15 |
#PROJECT: NCEAS INPLANT: Environment and Organisms --TASK#363, TASK$568-- |
16 | 16 |
|
... | ... | |
44 | 44 |
### Need to add documentation ### |
45 | 45 |
|
46 | 46 |
script_path<-"/home/parmentier/Data/IPLANT_project/env_layers_scripts/" |
47 |
#script_path<-"/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/" |
|
48 |
#list_script_files<- |
|
49 | 47 |
|
50 |
##SCRIPT USED FOR THE PREDICTIONS: Source all scripts here to avoid confusion on versions being run!!!! |
|
48 |
##SCRIPT USED FOR THE PREDICTIONS: Source or list all scripts here to avoid confusion on versions being run!!!!
|
|
51 | 49 |
|
52 |
#source(file.path(script_path,"master_script_temp_05132013.R")) #Master script can be run directly...
|
|
50 |
#source(file.path(script_path,"master_script_temp_05162013.R")) #Master script can be run directly...
|
|
53 | 51 |
|
54 | 52 |
#CALLED FROM MASTER SCRIPT: |
55 |
#modis_download_script <- file.path(script_path,"modis_download_05132013.py") # LST modis download python script |
|
53 |
|
|
56 | 54 |
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") |
|
55 |
clim_script <- file.path(script_path,"climatology_05142013.py") # LST climatology python script |
|
56 |
grass_setting_script <- file.path(script_path,"grass-setup.R") #Set up system shell environment for python+GRASS |
|
57 |
source(file.path(script_path,"download_and_produce_MODIS_LST_climatology_05162013.R")) |
|
59 | 58 |
source(file.path(script_path,"covariates_production_temperatures_05132013.R")) |
60 | 59 |
source(file.path(script_path,"Database_stations_covariates_processing_function_05062013.R")) |
61 | 60 |
source(file.path(script_path,"GAM_fusion_analysis_raster_prediction_multisampling_05062013.R")) |
... | ... | |
72 | 71 |
stages_to_run<-c(0,0,3,4,5) #May decide on antoher strategy later on... |
73 | 72 |
|
74 | 73 |
var<-"TMAX" # variable being interpolated |
75 |
out_prefix<-"_365d_GAM_CAI_all_lst_05132013" #User defined output prefix
|
|
74 |
out_prefix<-"_365d_GAM_CAI_all_lst_05172013" #User defined output prefix
|
|
76 | 75 |
#interpolation_method<-c("gam_fusion","gam_CAI") #other otpions to be added later |
77 | 76 |
interpolation_method<-c("gam_CAI") #other otpions to be added later |
78 | 77 |
#interpolation_method<-c("gam_fusion") #other otpions to be added later |
... | ... | |
89 | 88 |
} |
90 | 89 |
|
91 | 90 |
lc_path<-"/home/layers/data/land-cover/lc-consensus-global" |
92 |
infile_modis_grid<-"modis_sinusoidal_grid_world.shp" #Give path!!! NEED TO CHANGE THIS... |
|
91 |
infile_modis_grid<-"/home/layers/commons/modis/modis_sinusoidal/modis_sinusoidal_grid_world.shp" #Give path!!! NEED TO CHANGE THIS...
|
|
93 | 92 |
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 |
94 | 93 |
infile_canheight<-"/home/layers/data/land-cover/treeheight-simard2011/Simard_Pinto_3DGlobalVeg_JGR.tif" #Canopy height |
95 | 94 |
list_tiles_modis <- c("h11v08,h11v07,h12v07,h12v08,h10v07,h10v08") #tile for Venezuela and surrounding area |
... | ... | |
102 | 101 |
#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"; |
103 | 102 |
CRS_locs_WGS84<-CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +towgs84=0,0,0") #Station coords WGS84 |
104 | 103 |
out_region_name<-"_venezuela_region" #generated on the fly |
105 |
out_suffix<-"_VE_05092013"
|
|
104 |
out_suffix<-"_VE_05172013"
|
|
106 | 105 |
ref_rast_name<-"" #local raster name defining resolution, exent, local projection--. set on the fly?? |
107 | 106 |
#ref_rast_name<-"mean_day244_rescaled.rst" #local raster name defining resolution, exent: oregon |
108 | 107 |
|
... | ... | |
115 | 114 |
"nobs_09","nobs_10","nobs_11","nobs_12") |
116 | 115 |
covar_names<-c(rnames,lc_names,lst_names) |
117 | 116 |
|
118 |
list_param_covar_production<-list(var,in_path,out_path,lc_path,infile_modis_grid,infile_elev,infile_canheight, |
|
119 |
list_tiles_modis,infile_reg_outline,CRS_interp,CRS_locs_WGS84,out_region_name, |
|
120 |
out_suffix,ref_rast_name,covar_names) |
|
121 |
|
|
122 |
names(list_param_covar_production)<-c("var","in_path","out_path","lc_path","infile_modis_grid","infile_elev","infile_canheight", |
|
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 | 117 |
############ STAGE 1: LST Climatology ############### |
127 | 118 |
|
128 | 119 |
#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 | 120 |
#list_tiles_modis <- c("h08v04,h09v04") #tiles for Oregon #defined above... |
132 | 121 |
start_year = "2001" |
133 | 122 |
end_year = "2010" |
134 | 123 |
#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 |
|
124 |
#hdfdir = '/home/layers/commons/modis/MOD11A1_tiles' #destination file where hdf files are stored locally after download. |
|
125 |
hdfdir = '/home/parmentier/Data/IPLANT_project/MOD11A1_tiles' |
|
126 |
download=1 |
|
127 |
clim_calc=0 |
|
150 | 128 |
out_suffix_modis="_05132013" |
129 |
#end_month= "12" |
|
130 |
#start_month= "1" |
|
151 | 131 |
|
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=" ") |
|
132 |
list_param_download_clim_LST_script <- list(list_tiles_modis,start_year,end_year,hdfdir, |
|
133 |
var,grass_setting_script,modis_download_script, clim_script, |
|
134 |
download,clim_calc,out_suffix_modis) |
|
135 |
names(list_param_download_clim_LST_script)<-c("list_tiles_modis","start_year","end_year","hdfdir", |
|
136 |
"var","grass_setting_script","modis_download_script","clim_script", |
|
137 |
"download","clim_calc","out_suffix_modis") |
|
159 | 138 |
|
160 | 139 |
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 |
|
140 |
|
|
141 |
download_calculate_MODIS_LST_climatology(1,list_param_download_clim_LST_script) |
|
142 |
|
|
172 | 143 |
} |
144 |
#Collect LST climatology list as output??? |
|
173 | 145 |
|
174 | 146 |
############ STAGE 2: Covariate production ################ |
175 | 147 |
|
148 |
list_param_covar_production<-list(var,in_path,out_path,lc_path,infile_modis_grid,infile_elev,infile_canheight, |
|
149 |
list_tiles_modis,infile_reg_outline,CRS_interp,CRS_locs_WGS84,out_region_name, |
|
150 |
out_suffix,ref_rast_name,hdfdir,covar_names) |
|
151 |
|
|
152 |
names(list_param_covar_production)<-c("var","in_path","out_path","lc_path","infile_modis_grid","infile_elev","infile_canheight", |
|
153 |
"list_tiles_modis","infile_reg_outline","CRS_interp","CRS_locs_WGS84","out_region_name", |
|
154 |
"out_suffix","ref_rast_name","hdfdir","covar_names") |
|
176 | 155 |
|
177 | 156 |
## Modify to store infile_covar_brick in output folder!!! |
178 | 157 |
if (stages_to_run[2]==2){ |
Also available in: Unified diff
master script, calling python scripts from R function