<p><b>mhoffman@lanl.gov</b> 2012-06-08 22:04:52 -0600 (Fri, 08 Jun 2012)</p><p>BRANCH COMMIT -- land ice<br>
<br>
Fixing a bug in the script to copy data from CISM to MPAS grid that resulted in incorrect data for fields coming from  the CISM staggered grid (beta).<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        2012-06-08 19:46:18 UTC (rev 1975)
+++ branches/land_ice_projects/grid_tools/copy_CISM_grid_to_MPAS_grid.py        2012-06-09 04:04:52 UTC (rev 1976)
@@ -45,10 +45,10 @@
     ValueCell = numpy.zeros(xCell.shape)
     for i in range(len(xCell)):
        # Calculate the CISM grid cell indices (these are the lower index)
-       xgrid = math.floor( xCell[i] / dx )
+       xgrid = math.floor( (xCell[i]-x[0]) / dx )
        if xgrid &gt;= len(x) - 1:
           xgrid = len(x) - 2
-       ygrid = math.floor( yCell[i] / dy )
+       ygrid = math.floor( (yCell[i]-y[0]) / dy )
        if ygrid &gt;= len(y) - 1:
           ygrid = len(y) - 2
        #print xgrid, ygrid
@@ -56,7 +56,6 @@
                  Value[ygrid+1,xgrid] * (x[xgrid+1] - xCell[i]) * (yCell[i] - y[ygrid]) / (dx * dy) + \
                  Value[ygrid,xgrid+1] * (xCell[i] - x[xgrid]) * (y[ygrid+1] - yCell[i]) / (dx * dy) + \
                  Value[ygrid+1,xgrid+1] * (xCell[i] - x[xgrid]) * (yCell[i] - y[ygrid]) / (dx * dy) 
-    #print ValueCell.max(), ValueCell.min()
   except:
      'error in BilinearInterp'
   return  ValueCell
@@ -160,6 +159,7 @@
     thickness = outfile.variables['thickness']
     print '</font>
<font color="gray">thk min/max', thk[:].min()*sf, thk[:].max()*sf
     thickness[timelevout,:] = BilinearInterp(x1, y1, thk[timelev,:,:] * sf, xCell, yCell)
+    print 'interim thickness min/max', thickness[:].min(), thickness[:].max()
     # Don't let there be negative thickness
     thickness[:] = thickness[:] * (thickness[:]&gt;=0.0)
     print 'new thickness min/max', thickness[:].min(), thickness[:].max()
@@ -179,7 +179,7 @@
     bedTopography = outfile.variables['bedTopography']
     print '</font>
<font color="red">topg min/max', topg[:].min()*sf, topg[:].max()*sf
     bedTopography[timelevout,:] = BilinearInterp(x1, y1, topg[timelev,:,:]*sf, xCell, yCell)
-    print 'new bedTopography min/max', bedTopography[:].min(), bedTopography[timelevout,:].max()
+    print 'new bedTopography min/max', bedTopography[:].min(), bedTopography[:].max()
     del topg, bedTopography
 except:
     print '</font>
<font color="black">problem with topg field (e.g. not found in input file), skipping...</font>
<font color="gray">'
@@ -196,7 +196,7 @@
     beta = outfile.variables['betaTimeSeries']
     print '</font>
<font color="gray">input beta min/max', inbeta[:].min()*sf, inbeta[:].max()*sf
     #beta[timelevout,:] = BilinearInterp(x0, y0, inbeta[timelev,:,:]*sf, xCell, yCell)
-    beta[:,0] = BilinearInterp(x0, y0, inbeta[timelev,:,:]*sf, xCell, yCell)
+    beta[:,timelevout] = BilinearInterp(x0, y0, inbeta[timelev,:,:]*sf, xCell, yCell)
     print 'interim beta min/max', beta[:].min(), beta[:].max()
     # Make all beta be positive values
     b = beta[:]
@@ -223,10 +223,15 @@
       for i in range(1,stagwbndlevel-1):
         print 'Copying level ', i+1, ' of ', stagwbndlevel , 'CISM staggered levels (ignoring CISM b.c. temp levels)'
         temperature[timelevout,:,i-1] = BilinearInterp(x1, y1, tempstag[timelev,i,:,:]*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
+    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="black">'
 

</font>
</pre>