<p><b>mhoffman@lanl.gov</b> 2012-03-06 16:17:36 -0700 (Tue, 06 Mar 2012)</p><p>BRANCH COMMIT -- land_ice<br>
<br>
Fixed the Time dimension in add_land_ice_variables_to_mpas_grid.py to have a value of 1.  Previously it had a value of 0 which caused problems when trying to assign values to variables that use that dimension.<br>
Also, fixed a typo in the name of the convert script.<br>
</p><hr noshade><pre><font color="gray">Modified: branches/land_ice_projects/grid_tools/add_land_ice_variables_to_mpas_grid.py
===================================================================
--- branches/land_ice_projects/grid_tools/add_land_ice_variables_to_mpas_grid.py        2012-03-06 23:13:46 UTC (rev 1599)
+++ branches/land_ice_projects/grid_tools/add_land_ice_variables_to_mpas_grid.py        2012-03-06 23:17:36 UTC (rev 1600)
@@ -31,10 +31,18 @@
 #       It may be better to list them explicitly as I do for the grid variables, 
 #       but this way ensures they all get included and is easier.
 for dim in filein.dimensions.keys():
-    fileout.createDimension(dim, filein.dimensions[dim])
+    if dim == 'Time':
+    # Note that for some reason getting the current value of the UNLIMITED dimension does not work with this method.  The value returned in this case is &quot;None&quot;.  However, you can always get the current value of any variable dimension via the shape attribute.
+    # This is a limitation of Scientific.IO.NetCDF and may not be an issue with other netcdf python modules.
+    # This workaround should be fine for the time being since there is no need to have the I.C. file have UNLIMITED time dimension.
+        fileout.createDimension('Time', 1)
+    else:    
+        fileout.createDimension(dim, filein.dimensions[dim])
 # Create nVertLevelsPlus2 dimension
 fileout.createDimension('nVertLevelsPlus2', filein.dimensions['nVertLevels'] + 2)
 
+
+
 # Copy over all of the required grid variables to the new file
 vars2copy = ('latCell', 'lonCell', 'xCell', 'yCell', 'zCell', 'indexToCellID', 'latEdge', 'lonEdge', 'xEdge', 'yEdge', 'zEdge', 'indexToEdgeID', 'latVertex', 'lonVertex', 'xVertex', 'yVertex', 'zVertex', 'indexToVertexID', 'cellsOnEdge', 'nEdgesOnCell', 'nEdgesOnEdge', 'edgesOnCell', 'edgesOnEdge', 'weightsOnEdge', 'dvEdge', 'dcEdge', 'angleEdge', 'areaCell', 'areaTriangle', 'cellsOnCell', 'verticesOnCell', 'verticesOnEdge', 'edgesOnVertex', 'cellsOnVertex', 'kiteAreasOnVertex')
 for varname in vars2copy:

Copied: branches/land_ice_projects/grid_tools/convert_mpas_grid_to_regular_grid_netcdf.py (from rev 1595, branches/land_ice_projects/grid_tools/covert_mpas_grid_to_regular_grid_netcdf.py)
===================================================================
--- branches/land_ice_projects/grid_tools/convert_mpas_grid_to_regular_grid_netcdf.py                                (rev 0)
+++ branches/land_ice_projects/grid_tools/convert_mpas_grid_to_regular_grid_netcdf.py        2012-03-06 23:17:36 UTC (rev 1600)
@@ -0,0 +1,82 @@
+#!/usr/bin/python
+# Script to convert selected variables from an MPAS run and create a new netCDF file
+# that has those variables on a rectangular grid.  The resulting gridded data appears 
+# distorted but is adequate for quickly checking output.  This is likely to only work 
+# with grids created with periodic_hex where the order of cells in each 1d array (e.g. 'nCells')
+# is row by row (or is it column by column).  This is a workaround to allow visualization 
+# in, e.g. ncview since Paraview has some limitations as to which variables can be read in.
+# Currently, the script is setup to regrid any 2d and 3d variables that have dimensions of both Time
+# and nCells.  The output file has the name 'converted.nc'.  The output file is a little quirky, 
+# but does work with ncview.
+
+import sys, os, glob, shutil, numpy
+from Scientific.IO.NetCDF import *
+# from NetCDF import *
+from optparse import OptionParser
+
+parser = OptionParser()
+parser.add_option(&quot;-f&quot;, &quot;--file&quot;, dest=&quot;filename&quot;, help=&quot;file to convert&quot;, metavar=&quot;FILE&quot;)
+options, args = parser.parse_args()
+if not options.filename:
+        parser.error(&quot;Filename is a required input.&quot;)
+
+# Get some information about the input file
+filein = NetCDFFile(options.filename,'r')
+# These need to be specified!!!!  Perhaps these should be supplied as arguments on the command line
+nx = 30
+ny = 35
+times = filein.variables['xtime']
+time_length = times.shape[0]
+vert_levs = filein.dimensions['nVertLevels']
+
+# Define the new file to be output - this should be made a variant of the input file name
+fileout = NetCDFFile(&quot;converted.nc&quot;,&quot;w&quot;)
+# Create the new x,y dimensions for the new file
+fileout.createDimension('nx',nx)
+fileout.createDimension('ny',ny)
+# Copy over all the dimensions to the new file
+for dim in filein.dimensions.keys():
+    # print 'DIMENSION: ', dim
+    # print 'HAS VALUE: ', filein.dimensions[dim]
+    fileout.createDimension(dim, filein.dimensions[dim])
+
+# Loop over all variables in file and find the ones we want to convert
+for var in filein.variables.keys():
+   # print var
+   thevar = filein.variables[var]
+   dimflag = 0
+   # Look for variables that have these two dimensions
+   for dim in thevar.dimensions:
+       if dim == 'nCells':
+           # print '  has', dim
+           dimflag += 1
+       if dim == 'Time':
+           # print '  has', dim
+           dimflag += 1
+   if dimflag == 2:
+       # print '       HAS BOTH'
+       # Convert this variable
+       dims2use = ()
+       lastdim = 0
+       for dim in thevar.dimensions:
+           if dim == 'nCells':
+              dims2use = dims2use + ('ny', 'nx')
+           else:
+              dims2use = dims2use + (dim,)
+           if dim == 'nVertLevels':
+              lastdim = vert_levs
+           elif dim == 'nVertLevelsPlus2':
+              lastdim = vert_levs + 2
+       # print dims2use
+       # print thevar.typecode()
+       newVar = fileout.createVariable(var,thevar.typecode(),dims2use)
+       originalvalue = thevar[:]
+       # Determine how to reshape
+       if lastdim == 0:
+          newVar[:] = originalvalue.reshape(time_length,ny,nx)
+       else:
+          newVar[:] = originalvalue.reshape(time_length,ny,nx,lastdim)
+
+
+filein.close()
+fileout.close()

Deleted: branches/land_ice_projects/grid_tools/covert_mpas_grid_to_regular_grid_netcdf.py
===================================================================
--- branches/land_ice_projects/grid_tools/covert_mpas_grid_to_regular_grid_netcdf.py        2012-03-06 23:13:46 UTC (rev 1599)
+++ branches/land_ice_projects/grid_tools/covert_mpas_grid_to_regular_grid_netcdf.py        2012-03-06 23:17:36 UTC (rev 1600)
@@ -1,82 +0,0 @@
-#!/usr/bin/python
-# Script to convert selected variables from an MPAS run and create a new netCDF file
-# that has those variables on a rectangular grid.  The resulting gridded data appears 
-# distorted but is adequate for quickly checking output.  This is likely to only work 
-# with grids created with periodic_hex where the order of cells in each 1d array (e.g. 'nCells')
-# is row by row (or is it column by column).  This is a workaround to allow visualization 
-# in, e.g. ncview since Paraview has some limitations as to which variables can be read in.
-# Currently, the script is setup to regrid any 2d and 3d variables that have dimensions of both Time
-# and nCells.  The output file has the name 'converted.nc'.  The output file is a little quirky, 
-# but does work with ncview.
-
-import sys, os, glob, shutil, numpy
-from Scientific.IO.NetCDF import *
-# from NetCDF import *
-from optparse import OptionParser
-
-parser = OptionParser()
-parser.add_option(&quot;-f&quot;, &quot;--file&quot;, dest=&quot;filename&quot;, help=&quot;file to convert&quot;, metavar=&quot;FILE&quot;)
-options, args = parser.parse_args()
-if not options.filename:
-        parser.error(&quot;Filename is a required input.&quot;)
-
-# Get some information about the input file
-filein = NetCDFFile(options.filename,'r')
-# These need to be specified!!!!  Perhaps these should be supplied as arguments on the command line
-nx = 30
-ny = 35
-times = filein.variables['xtime']
-time_length = times.shape[0]
-vert_levs = filein.dimensions['nVertLevels']
-
-# Define the new file to be output - this should be made a variant of the input file name
-fileout = NetCDFFile(&quot;converted.nc&quot;,&quot;w&quot;)
-# Create the new x,y dimensions for the new file
-fileout.createDimension('nx',nx)
-fileout.createDimension('ny',ny)
-# Copy over all the dimensions to the new file
-for dim in filein.dimensions.keys():
-    # print 'DIMENSION: ', dim
-    # print 'HAS VALUE: ', filein.dimensions[dim]
-    fileout.createDimension(dim, filein.dimensions[dim])
-
-# Loop over all variables in file and find the ones we want to convert
-for var in filein.variables.keys():
-   # print var
-   thevar = filein.variables[var]
-   dimflag = 0
-   # Look for variables that have these two dimensions
-   for dim in thevar.dimensions:
-       if dim == 'nCells':
-           # print '  has', dim
-           dimflag += 1
-       if dim == 'Time':
-           # print '  has', dim
-           dimflag += 1
-   if dimflag == 2:
-       # print '       HAS BOTH'
-       # Convert this variable
-       dims2use = ()
-       lastdim = 0
-       for dim in thevar.dimensions:
-           if dim == 'nCells':
-              dims2use = dims2use + ('ny', 'nx')
-           else:
-              dims2use = dims2use + (dim,)
-           if dim == 'nVertLevels':
-              lastdim = vert_levs
-           elif dim == 'nVertLevelsPlus2':
-              lastdim = vert_levs + 2
-       # print dims2use
-       # print thevar.typecode()
-       newVar = fileout.createVariable(var,thevar.typecode(),dims2use)
-       originalvalue = thevar[:]
-       # Determine how to reshape
-       if lastdim == 0:
-          newVar[:] = originalvalue.reshape(time_length,ny,nx)
-       else:
-          newVar[:] = originalvalue.reshape(time_length,ny,nx,lastdim)
-
-
-filein.close()
-fileout.close()

</font>
</pre>