[SciPy-User] netCDF output error

Neil Berg nberg@atmos.ucla....
Wed Oct 27 19:58:48 CDT 2010


Hi all,

The piece of code below is used to linearly interpolate 80-meter wind speeds at each grid point per hour using previously determined wind speeds at heights above and below 80m.  The interpolated values are correct, however, when those values get outputted to a netCDF file, there is an issue.  The issue is that for all "ntim" greater than 0, the variable ws80 is not being recorded correctly for longitude 0 and 1, leading to a 2-longitude shift between the calculated value and the outputted value, as seen below. 

Calculated ws80 values for ntim = 1(these values are correct):

time = 1 lat = 0 lon = 0 ws80 = 3.53356
time = 1 lat = 0 lon = 1 ws80 = 3.44833
time = 1 lat = 0 lon = 2 ws80 = 3.35811
time = 1 lat = 0 lon = 3 ws80 = 3.26005
time = 1 lat = 0 lon = 4 ws80 = 3.15432
time = 1 lat = 0 lon = 5 ws80 = 3.04073
time = 1 lat = 0 lon = 6 ws80 = 2.91952
time = 1 lat = 0 lon = 7 ws80 = 2.7913
time = 1 lat = 0 lon = 8 ws80 = 2.65674
time = 1 lat = 0 lon = 9 ws80 = 2.51895
time = 1 lat = 0 lon = 10 ws80 = 2.37965

And here is what the netCDF output looks like for the same sample:

time[1] latitude[0] longitude[0] ws80[5184]=1.4013e-45 m s-1
time[1] latitude[0] longitude[1] ws80[5185]=0 m s-1
time[1] latitude[0] longitude[2] ws80[5186]=3.53356 m s-1
time[1] latitude[0] longitude[3] ws80[5187]=3.44833 m s-1
time[1] latitude[0] longitude[4] ws80[5188]=3.35811 m s-1
time[1] latitude[0] longitude[5] ws80[5189]=3.26005 m s-1
time[1] latitude[0] longitude[6] ws80[5190]=3.15432 m s-1
time[1] latitude[0] longitude[7] ws80[5191]=3.04073 m s-1
time[1] latitude[0] longitude[8] ws80[5192]=2.91952 m s-1
time[1] latitude[0] longitude[9] ws80[5193]=2.7913 m s-1
time[1] latitude[0] longitude[10] ws80[5194]=2.65674 m s-1

--------------------------------------------------------------------------------------------
Mac OS X 10.6.4
Python 2.6.1 
-------------------------------------------------------------------------------------------- 
from scipy.io.netcdf import netcdf_file as Dataset
from scipy.interpolate import interp1d
.....
ws80 = zeros([ntim,nlat,nlon],'float32')
for tim_idx in range(0,ntim): # loops from hour 0 to hour 744, which covers entire month of January 
            z_arr = (za1[tim_idx],za2[tim_idx])     # nearest heights below 80 meters (za1) and above 80 meter (za2)
            ws_arr = (wspd1[tim_idx],wspd2[tim_idx]) # wind speeds at za1 and za2
            f = interp1d(z_arr,ws_arr, kind='linear')
            ws80[tim_idx,lat_idx,lon_idx] = f(80) # interpolated wind speed at 80 meters 
            print "time =",tim_idx,"lat =",lat_idx,"lon =",lon_idx,"ws80 =",ws80[tim_idx,lat_idx,lon_idx]
....
ncfile_out = Dataset('output_file','w')
data = ncfile_out.createVariable('ws80',dtype('float32').char,('time','latitude','longitude',))
data.units = "m s-1"
data[:,:,:] = ws80[:,:,:]
ncfile_out.close()
_______________________________________________________ 

I thank you in advance for any suggestions on why the first two longitudes are not being outputted in the netCDF correctly, leading to the rest of the output being incorrectly shifted.

Neil Berg  




More information about the SciPy-User mailing list