Project

General

Profile

« Previous | Next » 

Revision f37cc8b7

Added by Benoit Parmentier almost 12 years ago

LST clim averages calc,testing parallel call to python scripts

View differences:

climate/research/oregon/interpolation/download_and_produce_MODIS_LST_climatology.R
7 7
# This R script calls python scripts. 
8 8
#
9 9
#AUTHORS: Benoit Parmentier    
10
#         based on modified earlier python scripts from J. Regetz
11
#DATE: 05/29/2013                                                                                 
12

  
10
#         Using python scripts started by J. Regetz and modified by B.Parmentier.
11
#DATE: 05/30/2013                                                                                 
12
#To Do:
13
#-collect list of LST files created
14
#-solve issue realted to parallelization of python script: GRASS problem?
13 15
#PROJECT: NCEAS INPLANT: Environment and Organisms --TASK#???--   
14 16

  
15 17
##################################################################################################
......
18 20
  
19 21
  ###Function to download and calculate LST climatology from MODIS tiles
20 22
  #AUTHOR: Benoit Parmentier                                                                       
21
  #DATE: 05/29/2013                                                                                 
23
  #DATE: 05/30/2013                                                                                 
22 24
  #PROJECT: NCEAS INPLANT: Environment and Organisms --TASK#363--   
23 25
  
24 26
  #1) var 
......
53 55
  #j to be used later...parallelization??
54 56
  
55 57
  #Additional parameters
56
  #list_tiles_modis <- unlist(strsplit(list_tiles_modis,","))  # transform string into separate element in char vector
57
  #list_tiles_modis <- list_tiles_modis[j]
58
  list_tiles_modis <- unlist(strsplit(list_tiles_modis,","))  # transform string into separate element in char vector
59
  list_tiles_modis <- list_tiles_modis[j]
58 60
  end_month= "12"
59 61
  start_month= "1"
60 62
  
......
84 86
  
85 87
  #command_str<-"python /home/parmentier/Data/test5.py h01v05,h02v05 2001 2005 12 1 /benoit 1 test_out 1"
86 88
  #paste(toString(list_param_python_script),collapse=",",sep=" ")
89
  command_download_str <- paste("python",modis_download_script, list_param_python_script_str,sep=" ")
90
  command_clim_str <- paste("python",clim_script, list_param_python_script_str,sep=" ") #preparing shell command
87 91
  
88 92
  ##Downownload files if necessary...
89 93
  if (download==1){
90
    command_download_str <- paste("python",modis_download_script, list_param_python_script_str,sep=" ")
91
    #command_str <- paste("python","/home/parmentier/Data/benoit_test/test5.py", list_param_python_script_str,sep=" ")
92 94
    system(command_download_str)
93 95
  }
94 96
  
95 97
  if (clim_calc==1){
96 98
    ##Now run climatology: Can add other climatology scripts or method to produce climatology later on...
97
    source(grass_setting_script) #Setting to access GRASS (current setting valid for Atlas at nceas)
98
    command_clim_str <- paste("python",clim_script, list_param_python_script_str,sep=" ") #preparing shell command
99
    source(grass_setting_script) #Setting to access GRASS (current setting valid for Atlas at nceas)  
99 100
    system(command_clim_str)
100
    #/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/climatology_05132013.py
101
  }
102
  
103
  ## return list of files???, may be modified later to return clim list and list of downloaded files + missing.
104
  if (clim_calc==1){
105
    list_output_obj <-list(command_download_str,command_clim_str)
106
    names(list_output_obj) <- c("command_download_str", "command_clim_str")
107
  } else{
108
    list_output_obj <-list(command_download_str)
109
    names(list_output_obj) <- c("command_download_str")
110 101
  }
111
    #Add function to list files created or modify in python...
112 102
  
103
#   ## return list of files???, may be modified later to return clim list and list of downloaded files + missing.
104
#   if (clim_calc==1){
105
#     list_output_obj <-list(command_download_str,command_clim_str)
106
#     names(list_output_obj) <- c("command_download_str", "command_clim_str")
107
#   } else{
108
#     list_output_obj <-list(command_download_str)
109
#     names(list_output_obj) <- c("command_download_str")
110
#   }
111
  #Add function to list files created or modify in python...
112
  
113
  list_output_obj <-list(command_download_str,command_clim_str)
114
  names(list_output_obj) <- c("command_download_str", "command_clim_str")
113 115
  return(list_output_obj)
114 116
}
115 117

  
116 118
## Run function:
117 119

  
118 120
#list_tiles_modis <- c("h10v04,h11v04,h12v04,h13v04,h14v04,h07v06") #tiles for Northenr America, Northern US...
119
list_tiles_modis <- c("h12v04,h13v04,h14v04,h07v06") #tiles for Northenr America, Northern US...
121
#list_tiles_modis <- c("h12v04,h13v04,h14v04,h07v06") #tiles for Northenr America, Northern US...
120 122
#list_tiles_modis <- c("h11v08,h11v07,h12v07,h12v08,h10v07,h10v08") #tile for Venezuela and surrounding area
121 123
#list_tiles_modis <- c("h08v04,h09v04") #tiles for Oregon #defined above...
124
#list_tiles_modis <- c("h09v04,h09v04") #tiles for Oregon #defined above...
122 125

  
123 126
#list_tiles_modis <- c("h09v04,h09v04") #tiles for Oregon #defined above...
124 127
#list_tiles_modis <- c("h09v08,h09v07,h08v07,h0706,h08v06,h09v06,h10v06,h08v05,h09v05,h10v05,h11v05,h12v05") #tiles for Central America and Mexico Southern US...
125 128
#list_tiles_modis <- c("h09v09,h10v09,h11v09,h12v09,h13v09,h14v09")
126 129
#list_tiles_modis <-c("h30v10,h31v10,h32v10,h30v11,h31v11") #list("Queensland")
127 130

  
128
script_path<-"/home/parmentier/Data/IPLANT_project/env_layers_scripts/"
129
modis_download_script <- file.path(script_path,"modis_download_05142013.py") # LST modis download python script
130
clim_script <- file.path(script_path,"climatology_05142013.py") # LST climatology python script
131
grass_setting_script <- file.path(script_path,"grass-setup.R")
132
var="TMAX"
133
start_year = "2001"
134
end_year = "2010"
131
#script_path<-"/home/parmentier/Data/IPLANT_project/env_layers_scripts/"
132
#modis_download_script <- file.path(script_path,"modis_download_05142013.py") # LST modis download python script
133
#clim_script <- file.path(script_path,"climatology_05142013.py") # LST climatology python script
134
#grass_setting_script <- file.path(script_path,"grass-setup.R")
135
#var="TMAX"
136
#start_year = "2001"
137
#end_year = "2010"
138
#end_year = "2002"
139

  
135 140
#path on Jupiter
136 141

  
137
hdfdir =  '/data/project/layers/commons/modis/MOD11A1_tiles' #destination file where hdf files are stored locally after download.
142
#hdfdir =  '/data/project/layers/commons/modis/MOD11A1_tiles' #destination file where hdf files are stored locally after download.
138 143
#hdfdir =  '/home/parmentier/Data/IPLANT_project/MOD11A1_tiles'
139
download=1
140
clim_calc=0
141
out_suffix_modis="_05292013"
144
#download=0
145
#clim_calc=1
146
#out_suffix_modis="_05302013"
142 147

  
143
list_param_download_clim_LST_script <- list(list_tiles_modis,start_year,end_year,hdfdir,
144
                                 var,grass_setting_script,modis_download_script, clim_script,
145
                                 download,clim_calc,out_suffix_modis)
146
names(list_param_download_clim_LST_script)<-c("list_tiles_modis","start_year","end_year","hdfdir",
147
                                   "var","grass_setting_script","modis_download_script","clim_script",
148
                                   "download","clim_calc","out_suffix_modis")
148
#list_param_download_clim_LST_script <- list(list_tiles_modis,start_year,end_year,hdfdir,
149
#                                 var,grass_setting_script,modis_download_script, clim_script,
150
#                                 download,clim_calc,out_suffix_modis)
151
#names(list_param_download_clim_LST_script)<-c("list_tiles_modis","start_year","end_year","hdfdir",
152
#                                   "var","grass_setting_script","modis_download_script","clim_script",
153
#                                   "download","clim_calc","out_suffix_modis")
149 154
#debug(download_calculate_MODIS_LST_climatology)
150 155
#clim_production_obj <-mclapply(1:2, list_param=list_param_download_clim_LST_script, download_calculate_MODIS_LST_climatology,mc.preschedule=FALSE,mc.cores = 2) #This is the end bracket from mclapply(...) statement
156
#clim_production_obj <-lapply(1:2, list_param=list_param_download_clim_LST_script, download_calculate_MODIS_LST_climatology) #,mc.preschedule=FALSE,mc.cores = 2) #This is the end bracket from mclapply(...) statement
151 157

  
152
download_calculate_MODIS_LST_climatology(1,list_param_download_clim_LST_script)
153

  
158
#download_calculate_MODIS_LST_climatology(1,list_param_download_clim_LST_script)
159
#source(file.path(script_path,"covariates_production_temperatures_05302013.R"))
154 160
### END OF SCRIPT

Also available in: Unified diff