Project

General

Profile

« Previous | Next » 

Revision e84c3d48

Added by Jim Regetz over 12 years ago

tucked misc procedural code into a main function

View differences:

climate/extra/aggregate-daily-lst.py
196 196
    return lstname
197 197

  
198 198

  
199
#--------------------------------------------
200
# test procedures mostly for timing purposes
201
#--------------------------------------------
199
def main():
200
    #--------------------------------------------
201
    # test procedures mostly for timing purposes
202
    #--------------------------------------------
202 203

  
203
# TODO: set up a (temporary?) GRASS database to use for processing? code
204
# currently assumes it's being run within an existing GRASS session
205
# using an appropriately configured LOCATION...
206
#
207
# note the following trick to fix datum for modis sinu;
208
# TODO: check that this works properly...compare to MRT output?
209
# gs.run_command('g.proj', flags='c',
210
#     proj4='+proj=sinu +a=6371007.181 +b=6371007.181 +ellps=sphere')
211
##    proj4='+proj=sinu +R=6371007.181 +nadgrids=@null +wktext')
212

  
213
# (1) download then aggregate for one month
214

  
215
tile = 'h09v04'
216
year = 2005
217
month = 1
218
hdfdir = '.'
219

  
220
# determine range of doys for the specified month
221
start_doy, end_doy = get_doy_range(year, month)
222
# download data
223
### [atlas 17-May-2012] Wall time: 111.62 s
224
hdfs = download_mod11a1(hdfdir, tile, start_doy, end_doy, year)
225
# generate monthly pixelwise mean & count of high-quality daytime LST
226
### [atlas 17-May-2012] Wall time: 53.79 s
227
gs.os.environ['GRASS_OVERWRITE'] = '1'
228
LST = [load_qc_adjusted_lst(hdf) for hdf in hdfs]
229
clims = calc_clim(LST, 'LST_%s_%d_%02d' % (tile, year, month))
230
# clean up
231
gs.run_command('g.remove', rast=','.join(LST))
232
gs.os.environ['GRASS_OVERWRITE'] = '0'
233

  
234

  
235
# (2) aggregate all 12 months in one year, using local data
236

  
237
tile = 'h09v04'
238
year = 2005
239
hdfdir = '/home/layers/data/climate/MOD11A1.004-OR-orig'
240

  
241
### [atlas 17-May-2012] Wall time: 802.86 s
242
gs.os.environ['GRASS_OVERWRITE'] = '1'
243
for month in range(1, 12+1):
204
    # TODO: set up a (temporary?) GRASS database to use for processing? code
205
    # currently assumes it's being run within an existing GRASS session
206
    # using an appropriately configured LOCATION...
207
    #
208
    # note the following trick to fix datum for modis sinu;
209
    # TODO: check that this works properly...compare to MRT output?
210
    # gs.run_command('g.proj', flags='c',
211
    #     proj4='+proj=sinu +a=6371007.181 +b=6371007.181 +ellps=sphere')
212
    ##    proj4='+proj=sinu +R=6371007.181 +nadgrids=@null +wktext')
213

  
214
    # (1) download then aggregate for one month
215

  
216
    tile = 'h09v04'
217
    year = 2005
218
    month = 1
219
    hdfdir = '.'
220

  
221
    # determine range of doys for the specified month
222
    start_doy, end_doy = get_doy_range(year, month)
223
    # download data
224
    ### [atlas 17-May-2012] Wall time: 111.62 s
225
    hdfs = download_mod11a1(hdfdir, tile, start_doy, end_doy, year)
226
    # generate monthly pixelwise mean & count of high-quality daytime LST
227
    ### [atlas 17-May-2012] Wall time: 53.79 s
228
    gs.os.environ['GRASS_OVERWRITE'] = '1'
229
    LST = [load_qc_adjusted_lst(hdf) for hdf in hdfs]
230
    clims = calc_clim(LST, 'LST_%s_%d_%02d' % (tile, year, month))
231
    # clean up
232
    gs.run_command('g.remove', rast=','.join(LST))
233
    gs.os.environ['GRASS_OVERWRITE'] = '0'
234

  
235

  
236
    # (2) aggregate all 12 months in one year, using local data
237

  
238
    tile = 'h09v04'
239
    year = 2005
240
    hdfdir = '/home/layers/data/climate/MOD11A1.004-OR-orig'
241

  
242
    ### [atlas 17-May-2012] Wall time: 802.86 s
243
    gs.os.environ['GRASS_OVERWRITE'] = '1'
244
    for month in range(1, 12+1):
245
        start_doy, end_doy = get_doy_range(year, month)
246
        hdfs = get_hdf_paths(hdfdir, tile, start_doy, end_doy, year)
247
        LST = [load_qc_adjusted_lst(hdf) for hdf in hdfs]
248
        clims = calc_clim(LST, 'LST_%s_%d_%02d' % (tile, year, month))
249
        gs.run_command('g.remove', rast=','.join(LST))
250
    gs.os.environ['GRASS_OVERWRITE'] = '0'
251

  
252
    # (3) download then aggregate for one month, tile h21v09
253

  
254
    tile = 'h21v09'
255
    year = 2005
256
    month = 1
257
    hdfdir = '.'
258

  
259
    # determine range of doys for the specified month
244 260
    start_doy, end_doy = get_doy_range(year, month)
245
    hdfs = get_hdf_paths(hdfdir, tile, start_doy, end_doy, year)
261
    # download data
262
    ### [atlas 17-May-2012] Wall time: 118.41 s
263
    hdfs = download_mod11a1(hdfdir, tile, start_doy, end_doy, year)
264
    # generate monthly pixelwise mean & count of high-quality daytime LST
265
    gs.os.environ['GRASS_OVERWRITE'] = '1'
266
    ### [atlas 17-May-2012] Wall time: 33.28 s
246 267
    LST = [load_qc_adjusted_lst(hdf) for hdf in hdfs]
268
    ### [atlas 17-May-2012] Wall time: 15.09 s
247 269
    clims = calc_clim(LST, 'LST_%s_%d_%02d' % (tile, year, month))
270
    # clean up
248 271
    gs.run_command('g.remove', rast=','.join(LST))
249
gs.os.environ['GRASS_OVERWRITE'] = '0'
272
    gs.os.environ['GRASS_OVERWRITE'] = '0'
273

  
274
    return None

Also available in: Unified diff