""" READ.PY is a python read code for the COAPS Simplified Scatterometer Daily files. That shows the user how to read the NetCDF variables into memory. Input: file_name = string value containing the relative or absolute path of the netcdf file Output: time A one dimensional LONG array containing the mean time of the observations. Given as the seconds since 1990-01-01 00:00:00. Each value in the array corresponds to one row of observations: all times in across track (perpendicular to the satellite track) are equal. The index corresponds to the along track time and position. lat A two dimensional FLOAT array containing the latitude of the wind vectors. The first index corresponds to the along track position, and the second index corresponds to the cross track position. lon A two dimensional FLOAT array containing the longitude of the wind vectors. The first index corresponds to the along track position, and the second index corresponds to the cross track position. eastward_wind Zonal equivalent neutral wind vector component. Positive values indicate an eastward movement. The first index corresponds to the along track position, and the second index corresponds to the cross track position. northward_wind Meridional equivalent neutral wind vector component. Positive values indicate northward movement. The first index corresponds to the along track position and the second index corresponds to the cross track position wind_to_direction A two dimensional FLOAT array containing the direction of the wind vector (oceonographic convention). The first index corresponds to the along track position, and the second index corresponds to the cross track position. wind_speed A two dimensional FLOAT array containing the equivalent neutral wind speed. The first index corresponds to the track position, and the second index corresponds to the cross track position. simplified_wvc_quality_flag A two dimensional INTEGER array with two values, 0 or 1. This flag is a summary of the product developer's non-rain flag, with 0 indicating good data, and 1 indicating highly suspect or bad data. See the metadata for this variable to see flags that are combined to produce this summary flag. rain_impact A two dimensional FLOAT array that attempts to indicate the impact of rain on a zero to 100 scale. At this time, the interpretation of these numbers is poorly described for Ku band, and not provided for C band. We anticipate this changing in the future; however, at this time JPL recommends most data users to avoid using the rain_impact variable. The only exception to this rule is for users who are trying to do very specific studies that are highly adversely impacted by rain. """ import numpy as np from netCDF4 import Dataset import sys def read(file_name): """Read time, lat, lon, and wind speed""" ncdf_file = Dataset(file_name, 'r') source = str(ncdf_file.source) if ("QuikSCAT" in source) or ("Rapidscat" in source): grid_spacing = str(ncdf_file.cross_track_resolution) else: grid_spacing = str(ncdf_file.pixel_size_on_horizontal) ncdf_attributes = ncdf_file.ncattrs() #List of attributes ncdf_vars = ncdf_file.variables # List of variables variable_dict = dict() #Will hold the variable name as the key and its data as the value print "\n" print "Source:", source print "Grid Spacing:", grid_spacing print "Variables:" for var in ncdf_vars: print "\t", var print "\t", "-"*len(var) if var not in variable_dict: variable_dict[var]= ncdf_file.variables[var][:] #Loads the NetCDF array into a numpy array print variable_dict[var] print "\n" if __name__ == '__main__': args = sys.argv if len(args) != 2: print "ERROR" print "USAGE: python read.py [PATH OF NETCDF FILE]" sys.exit() file_name = args[1] read(file_name)