Level 2 Visualization Using Python Pyresample Library (1)

Level 2 Visualization Using Python Pyresample Library (1)

Postby yiboj » Sun Oct 23, 2016 3:10 pm

Pyresample is a Python package for resampling (reprojection) of earth observing satellite data. Pyresample handles both resampling of gridded data (e.g. geostationary satellites) and swath data (polar orbiting satellites). Pyresample can use multiple processor cores for resampling. Pyresample supports masked arrays.

Here is the plot and code using VIIRS Level 2 dataset:

viirs_l2.png (568.1 KiB) Viewed 5975 times

Code: Select all
import numpy as np
import matplotlib.pyplot as plt
import pyresample as pr
from pyresample import image, geometry
from netCDF4 import Dataset
import glob
import os

dirname = 'Your Data Directory'

k = 0
for filename in glob.glob(dirname+'/20160901*.nc'):
  fname = os.path.basename(filename)

  #Read data
  ncin = Dataset(filename, 'r')
  lons = ncin.variables['lon'][:]
  lats = ncin.variables['lat'][:]
  sst = ncin.variables['sea_surface_temperature'][:]

  alat = np.average(lats)
  alon = np.average(lons)

  idx = np.where((sst<=-1000.0))
  sst[idx] = np.nan

  area_def = pr.utils.load_area('areas.cfg', 'pc_world')

  bmap = pr.plot.area_def2basemap(area_def)
  bmng = bmap.bluemarble()

  swath_def2 = pr.geometry.SwathDefinition(lons, lats)

  if k == 0:
    sst_cat  = sst
    sst1  = sst
    swath_def = swath_def2
    swath_def1 = swath_def2
    swath_def = swath_def1.concatenate(swath_def2)
    swath_def1 = swath_def
    sst_cat = np.concatenate((sst1, sst), axis=1)
    sst1 = sst_cat

  result = pr.kd_tree.resample_nearest(swath_def, sst_cat, area_def, radius_of_influence=20000, fill_value=None)
  col = bmap.imshow(result, origin='upper', vmin=250, vmax=310)
  plt.title('MODIS L2 VIIRS SST')

  plt.savefig("modis_l2_globe_{0}".format(str(k).rjust(4, "0")), num_meridians=10, num_parallels=10, bbox_inches='tight')

  k = k + 1

Please refer to the following link for more detail information:
Posts: 130
Joined: Mon Mar 30, 2015 11:22 am

Return to Visualization