<p><b>mhoffman@lanl.gov</b> 2013-03-06 12:56:52 -0700 (Wed, 06 Mar 2013)</p><p>BRANCH COMMIT - land ice<br>
Update to script for copying CISM data to MPAS to allow copying of the 'temp' variable.  Currently it passes over the closest sigma level rather than doing vertical interpolation.<br>
</p><hr noshade><pre><font color="gray">Modified: branches/land_ice_projects/grid_tools/copy_CISM_grid_to_MPAS_grid.py
===================================================================
--- branches/land_ice_projects/grid_tools/copy_CISM_grid_to_MPAS_grid.py        2013-03-06 17:05:22 UTC (rev 2550)
+++ branches/land_ice_projects/grid_tools/copy_CISM_grid_to_MPAS_grid.py        2013-03-06 19:56:52 UTC (rev 2551)
@@ -208,6 +208,7 @@
     print '</font>
<font color="black">problem with beta field (e.g. not found in input file), skipping...</font>
<font color="gray">'
 
 
+# If tempstag is present, then copy it directly over to the MPAS grid.  This currently requires that they have the same number of vertical levels.
 try: 
     tempstag = infile.variables['tempstag']
     try:
@@ -236,7 +237,42 @@
     print '</font>
<font color="black">problem with tempstag field (e.g. not found in input file, differing number of layers), skipping...</font>
<font color="blue">'
 
 
+# If temp is present, copy over the level that is closest to the MPAS level.  Interpolation should be done, but starting with this simpler approach.  The CISM and MPAS grids need not have the same number of vertical levels.
+try: 
+    temp = infile.variables['temp']
+    try:
+      sf = temp.scale_factor
+    except:
+      sf = 1.0
+    if netCDF_module == 'netCDF4':
+      sf = 1.0   # netCDF4 should autoscale!
+    temperature = outfile.variables['temperature']
+    print '</font>
<font color="blue">input temp min/max', temp[:].min()*sf, temp[:].max()*sf
+    for i in range(nVertLevels):
+      print 'Copying level ', i+1, ' of ', nVertLevels
+      # grab the closest cism level (should interpolate)
+      if i==0:
+           icism=0
+      elif i==(nVertLevels-1):
+           icism=level-1
+      else:
+           icism=int(round( float(i+1)/float(nVertLevels) * float(level) ))-1
+      print 'Using CISM level ', icism+1
+      temperature[timelevout,:,i] = BilinearInterp(x1, y1, temp[timelev,icism,:,:]*sf, xCell, yCell)
+      print 'interim temperature min/max', temperature[:].min(), temperature[:].max()
+      # Don't let there be positive temperature
+      t = temperature[:]
+      t[t&gt;0.0] = 0.0
+      temperature[:] = t
+      print 'new temperature min/max', temperature[:].min(), temperature[:].max()
+    else: 
+      raise Exception
+    del tempstag, temperature, t
+except:
+    print '</font>
<font color="black">problem with tempstag field (e.g. not found in input file, differing number of layers), skipping...</font>
<font color="blue">'
 
+
+
 # Variables on edges...?
 #normalVelocity = outfile.variables['normalVelocity'][:]
 

</font>
</pre>