Advertisement
DangoMelon0701

grid_modis.pro

Nov 16th, 2016
2,598
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
IDL 1.98 KB | None | 0 0
  1. PRO GRID_MODIS
  2.  
  3. COMPILE_OPT IDL2
  4.  
  5. ;- Obtener la lista de todos los archivos de entrada
  6. list = file_search('G:/AOD MODIS/AQUA/out/MYD04_L2.*.dat')
  7. help, list
  8.  
  9. ;- Crear una grilla de igual ángulo
  10. ;- (la esquina inferior izquierda es a 180W, 90S; en efecto, -180.0 y -90.0)
  11. resolution = 1.0
  12. ncol = long(360.0 / resolution)
  13. nrow = long(180.0 / resolution)
  14. grid = fltarr(ncol, nrow)
  15.  
  16. ;- Bucle sobre los archivos de entrada
  17. for index = 0, n_elements(list) - 1 do begin
  18.  
  19.   ;- Abrir cada archivo de entrada y obtener un numero de filas
  20.   input_file = list[index]
  21.   print, input_file
  22.   openr, lun, input_file, /get_lun
  23.   result = fstat(lun)
  24.   nrows = result.size / (4 * 3)
  25.  
  26.   ;- Leer la tabla de datos
  27.   table = fltarr(3, nrows)
  28.   readu, lun, table
  29.   free_lun, lun
  30.  
  31.   ;- Extraer, lat, lon y data
  32.   lat = table[0, *]
  33.   lon = table[1, *]
  34.   data = table[2, *]
  35.   help, lat, lon, data
  36.  
  37.   ;- Obtener la lista de indices de grillado
  38.   lonlat_to_index, lon, lat, resolution, grid_index
  39.  
  40.   ;- Resetear la matriz de grillado
  41.   grid[*] = -999.9
  42.  
  43.   ;- Bucle sobre las celdas de grillado
  44.   for cell_index = 0, n_elements(grid) - 1 do begin
  45.    
  46.     ;- Encontrar los data points dentro de esta celda de grillado
  47.     loc = where(grid_index eq cell_index, count)
  48.    
  49.     ;- Guardar el promedio para esta celda  
  50.     if (count gt 0) then begin
  51.       mean = total(data[loc]) / count
  52.       grid[cell_index] = mean
  53.       print, cell_index, mean
  54.     endif
  55.  
  56.   endfor
  57.  
  58.   ;- Mostrar el grillado
  59.   map_set, -10, -90, /orthographic, /isotropic, title=input_file
  60.   image = map_image(grid, x0, y0, compress=1)
  61.   loadct, 39, /silent
  62.   tv, bytscl(image, min=0.0, max=5.0), x0, y0
  63.   map_continents
  64.  
  65.   ;- Guargar el grillado de salida
  66.   date_name = strmid(basename(input_file), 10, 12)
  67.   output_file =  'G:/AOD MODIS/AQUA/grid/' + date_name + '.grd'
  68.   print, 'Escribiendo ' + output_file
  69.   openw, lun, output_file, /get_lun
  70.   writeu, lun, grid
  71.   free_lun, lun
  72.  
  73. endfor
  74.  
  75. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement