Reading MODIS level 1b data in netcdf format

Here is a walkthrough of how to read metadata and data from a level1b file. I've used the the converter I downloaded from this link to produce the Aqua granule netcdf file in this download directory: http://clouds.eos.ubc.ca/~phil/Downloads/a301/MYD021KM.A2005188.0405.005.2009232180906.nc (right click to save to your local drive)

I'm going to use http://unidata.github.io/netcdf4-python/ and two new modules (modismeta.py and netcdflib.py) to read the granule


In [0]:
from __future__ import print_function
import os,site
currdir=os.getcwd()
head,tail=os.path.split(currdir)
libdir=os.path.join(head,'lib')
site.addsitedir(libdir)
from modismeta import parseMeta
from netcdflib import ncdump
import glob
from netCDF4 import Dataset

the glob function finds a file using a wildcard to save typing (google: python glob wildcard)


In [0]:
nc_filename=glob.glob('*.nc')
print("found {}".format(nc_filename))

In [0]:
nc_file=Dataset(nc_filename[0])

netcdf files have attributes


In [0]:
print(nc_file.ncattrs())

In [0]:
print(nc_file.Earth_Sun_Distance)

In [0]:
print(nc_file.HDFEOSVersion)

netcdf files have variables -- stored in a dictionary


In [0]:
print(nc_file.variables)

In [0]:
print(nc_file.variables.keys())

In [0]:
the_long=nc_file.variables['longitude']

In [0]:
help(the_long)

In [0]:
the_long.ncattrs()

In [0]:
long_data=the_long[:10,:10]

In [0]:
print(long_data)

Dump a selection of metadata


In [0]:
from modismeta import parseMeta

In [0]:
print(parseMeta(nc_file))

Dump all metdata


In [0]:
from netcdflib import ncdump

In [0]:
ncdump(nc_file)

In [0]:
import os
os.getcwd()

In [0]: