[SciPy-User] netCDF output error

Ryan May rmay31 at gmail.com
Wed Oct 27 21:47:35 EDT 2010


On Wed, Oct 27, 2010 at 7:58 PM, Neil Berg <nberg at atmos.ucla.edu> wrote:
> 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()
> _______________________________________________________

Where's the code where you create the dimensions
('time','latitude','longitude',)? My first gut guess is that the shape
of the variable as written doesn't match the array.

Ryan

-- 
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma



More information about the SciPy-User mailing list