SeaWiFS chlorophyll-a

A few months ago I wanted to use the monthly average values of chlorophyll-a data available from the SeaWiFS project homepage as HDF4 files.  Because I already have netCDF4 and HDF5 installed on my computer, I had problems installing HDF4 on the same computer. After a lot of struggling to get that to work, I downloaded HDFView instead. Using HDFView I exported each of the monthly climatology HDF4 files of chlorophyll-a to ASCII format. This left me with 12 ASCII files that I wanted to convert into one netCDF4 file that I could use with my individual-based model.  I wrote a python program to facilitate that task (shown below) and I ended up with one netCDF4 file that contains monthly (January to December) climatology (1998-2008) values of SeaWiFS chlorophyll-a. The netCDF4 file is 178MB large and available here


Chlorophyll-a (format NetCDF4) (1002)

The program I used to create the file is available below: (706)

import numpy as np
import datetime as datetime
import string, sys, os
import pylab
import IOseawifs

__author__   = 'Trond Kristiansen'
__created__  = datetime.datetime(2009, 12, 3)
__modified__ = datetime.datetime(2009, 12, 19)
__version__  = "0.5.0"
__status__   = "Development"
__revisions__= "3.12.09, 16.12.2009, 19.12.2009"

===================== ===========================================

This is a script to read SeaWiFS data from files (monthly mean files). These
data was downloaded from the SeaWiFS website as HDF4 files
(, and converted
(exported) to ASCII files using the application HDFview. This was the best
solution after having had problems installing HDF4 alongside HDF5.
The data are read as one big matrix using numpys loadtxt
(np.loadtxt(ascii-file)). One matrix is read for each monthly climatology
(Jan-Dec). Each matrix is stored into a large array called chlo which has the
shape (12,2160,4320). This matrix together with the latitude, longitude
arrays are written to netCDF4 file using

The program enables you to extract time series from a
given longitude/latitude position by interpolating the values stored in
the surrounding grid points read from this file.

Uses: (and is useful together with

def createGrid(minLon,maxLon,minLat,maxLat,delta):

lat=np.zeros((2160), dtype=np.float64)
lon=np.zeros((4320), dtype=np.float64)

for k in range(2160):
if k==0:
lat[k]=minLat + delta
lat[k]=lat[k-1] + delta
for k in range(4320):
if k==0:
lon[k]=minLon + delta
lon[k]=lon[k-1] + delta

latitude, longitude= np.meshgrid(lat,lon)

return longitude, latitude

def main(files):
maxLat= 90.
maxLon= 180.
delta = 180./2160.

"""A one time creation of the longitude/latitude grid"""
longitude, latitude = createGrid(minLon,maxLon,minLat,maxLat,delta)
"""Create the matrix to save data to:"""
chlo = np.zeros((12,index[0],index[1]), dtype=np.float64)

months=[]; month=0

for file in files:
if os.path.exists(file):
print 'Opened file %s (month=%s)'%(file,month)
months.append(month + 1)
chlo[month,:,:] = np.flipud(np.fliplr(data2[:,:]))
print "File %s does not exists"%(file)

"""Now save the data for all months to a netcdf4 file"""

if __name__=="__main__":

import psyco
except ImportError:


main(files) (651)

from netCDF4 import Dataset
from netCDF4 import num2date
import numpy as np
import time
import os

def writeSeawifsFile(data, latitude, longitude, months):

if os.path.exists(outputFile): os.remove(outputFile)
print 'Output file is %s'%(outputFile)

print 'months',months
f1 = Dataset(outputFile, mode='w', format='NETCDF4')
f1.description="This is a monthly average global SEAWIFS Chlorophyll-a file"
f1.history = 'Created ' + time.ctime(time.time())
f1.type='NetCDF4 classic created'

f1.createDimension('time', len(months))
f1.createDimension('lat', 2160)
f1.createDimension('lon', 4320)

v_time = f1.createVariable('time', 'd', ('time',),zlib=True)
v_time.long_name = 'Month of the year'
v_time.units = 'month'
v_time.field = 'time, scalar, series'

v=f1.createVariable('latitude', 'd', ('lon','lat',),zlib=True)
v.long_name = "Matrix of latitude"
v.units = "degrees"

v=f1.createVariable('longitude', 'd', ('lon','lat',),zlib=True)
v.long_name = "Matrix of latitude"
v.units = "degrees"

v=f1.createVariable('Chlorophyll-a', 'f', ('time','lon','lat',),zlib=True)
v.long_name = "Monthly climatological chlorophyll-a from Seawifs"
v.units = "mg/m3"

f1.variables['time'][:]   = months

f1.variables['Chlorophyll-a'][:,:,:]  = data
f1.variables['latitude'][:,:]  = latitude
f1.variables['longitude'][:,:]  = longitude


7 thoughts on “SeaWiFS chlorophyll-a”

  1. Thank you for providing the SeaWIFS Chlorophyll climatology. I will be using this data for calculating penetrative radiation in the ocean.

  2. I want to know how are averaged SeaWifs chlorophyll-a over a month.
    Are the clouds included in this average?
    Do you give more weight to pixels with more values or not?
    If, for example, 25 out of 30 images contain lot of clouds, must I give less weight to these pixels with lot of clouds?

  3. The processing of these data were performed by the SeaWIFS project. What I did was to organize the monthly data files in HDF format to be contained in one netCDF4 file. Please read the details on the SeaWIFS website for more info on the processing and data details (click here)

  4. This website is a treasure chest of reliable and well-studied information pertaining to modeling. Thank you for sharing the information!

  5. Hi Trond,

    I’m impressed by all the work you’ve done here, and for making the code available. Perhaps you can help me – can you tell me if there are any simple, spatially explicit datafiles available for annual chlorophyll abundance? I’d like to be able to analyze and plot data collected by SeaWifs and others, but I’m having trouble locating ready-to-use data files. Something I could put in text or spreadsheet format for analyzing, or shp files for GIS programs. For instance, I found nice NPP datasets at this university website:

    Or perhaps they all must be processed with code as you have done? I’ve never used python, and I might be hoping that I don’t have to learn. Any suggestions would be most appreciated.



  6. Hi John. Thanks for your comment. I did create a Python script for converting phytoplankton data from Oregon SU into ArcGIS format a few years ago. I uploaded the script which can be used to convert monthly phytoplankton productivity data found here into a standard ArcGIS readable format. The script can be downloaded here. Please send me an email if you need more detailed help with this. Cheers, Trond

Leave a Reply

Your email address will not be published. Required fields are marked *