PyNIO: Assigning data to 3-d NetCDF variable

From: Gregory Deemer <gjdeemer_at_nyahnyahspammersnyahnyah>
Date: Mon Nov 18 2013 - 14:05:26 MST

Hello,

I'm wanting to assign values to a 3-D variable consisting of time, y, x.
The time dimension is unlimited but is assigned 366 values. I have seen
some examples of how to approach this problem with other scripting
languages where a loop is applied to write the 2-D slice per timestep, and
that is the approach I have taken here, but I am receiving the error
message:

NIOError: type or dimensional mismatch writing to variable (hi)

 For reference, the shapes of pertinent variables in the code snippet to
follow are:

Clime_hi.shape = (366, 120, 360)

time_dat.shape = (366,) # values spanning 0 - 365

lat_datR.shape = (120, 360)

lon_datR.shape = (120, 360)

# Create new variable dimensions

f_out.create_dimension('time', None)

f_out.create_dimension('y', 120)

f_out.create_dimension('x', 360)

# TIME

f_out.create_variable('time', 'd', ('time',))

# Attributes of time

setattr(f_out.variables['time'], 'standard_name', 'Valid Time')

setattr(f_out.variables['time'], 'units', 'hours since 2001-01-01 00:00:00')

setattr(f_out.variables['time'], 'time_origin', '2001-01-01 00:00:00')

setattr(f_out.variables['time'], 'calendar', 'gregorian')

setattr(f_out.variables['time'], 'axis', 'T')

# Write values to file

f_out.variables['time'].assign_value(time_dat)

# LATITUDE

f_out.create_variable('lat', 'd', ('y','x'))

# Attributes of latitude

setattr(f_out.variables['lat'], 'standard_name', 'latitude')

setattr(f_out.variables['lat'], 'units', 'degrees_north')

setattr(f_out.variables['lat'], 'axis', 'Y')

# Write values to file

f_out.variables['lat'].assign_value(lat_datR)

# LONGITUDE

f_out.create_variable('lon', 'd', ('y', 'x'))

# Attributes of longitude

setattr(f_out.variables['lon'], 'standard_name', 'longitude')

setattr(f_out.variables['lon'], 'units', 'degrees_east')

setattr(f_out.variables['lon'], 'axis', 'X')

# Write values to file

f_out.variables['lon'].assign_value(lon_datR)

# ICE THICKNESS

f_out.create_variable('hi', 'f', ('time', 'y', 'x'))

# Create variable attributes

setattr(f_out.variables['hi'], 'standard_name', 'sea_ice_thickness')

setattr(f_out.variables['hi'], 'units', 'm')

setattr(f_out.variables['hi'], '_FillValue', _FillandMiss)

setattr(f_out.variables['hi'], 'missing_value', _FillandMiss)

# Write values to file

for i in range(0, Clime_hi.shape[0]):

    f_out.variables['hi'].assign_value(Clime_hi[i,:,:])

Again, the error message that I am given once the loop as finished its
iteration is this:

    for i in range(0, Clime_hi.shape[0]):

NIOError: type or dimensional mismatch writing to variable (hi)

Please let me know if more information is needed to solve this error.

Thank you,

Greg

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - -

Gregory J. Deemer
Graduate Research Assistant
Department of Atmospheric Sciences
University of Alaska Fairbanks
IARC 338K
Office: (907) 474-5430
Cell: (907) 750-1063

_______________________________________________
pyngl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/pyngl-talk
Received on Mon Nov 18 14:05:34 2013

This archive was generated by hypermail 2.1.8 : Fri Nov 22 2013 - 09:37:03 MST