<p><b>mhoffman@lanl.gov</b> 2012-05-24 11:10:51 -0600 (Thu, 24 May 2012)</p><p>BRANCH COMMIT -- land ice<br>
Modified script to work with netCDF4 python module (Jaguar).<br>
Also modified it to only work with the CISM variable tempstag (which is on the same vertical coordinate system as MPAS).<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-05-23 21:10:10 UTC (rev 1934)
+++ branches/land_ice_projects/grid_tools/copy_CISM_grid_to_MPAS_grid.py        2012-05-24 17:10:51 UTC (rev 1935)
@@ -76,6 +76,14 @@
except:
print 'Input file is missing the dimension level. Might not be a problem.'
+ try:
+ if netCDF_module == 'Scientific.IO.NetCDF':
+ level = infile.dimensions['stagwbndlevel']
+ else:
+ level = len(infile.dimensions['stagwbndlevel'])
+ except:
+ print 'Input file is missing the dimension stagwbndlevel. Might not be a problem.'
+
# try:
# x1 = infile.dimensions['x1']
# y1 = infile.dimensions['y1']
@@ -147,6 +155,8 @@
sf = thk.scale_factor
except:
sf = 1.0
+ if netCDF_module == 'netCDF4':
+ sf = 1.0 # netCDF4 should autoscale!
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)
@@ -162,6 +172,8 @@
sf = topg.scale_factor
except:
sf = 1.0
+ if netCDF_module == 'netCDF4':
+ sf = 1.0 # netCDF4 should autoscale!
bedTopography = outfile.variables['bedTopography']
print '</font>
<font color="gray">topg min/max', topg[:].min()*sf, topg[:].max()*sf
bedTopography[timelevout,:] = BilinearInterp(x1, y1, topg[timelev,:,:]*sf, xCell, yCell)
@@ -177,6 +189,8 @@
sf = inbeta.scale_factor
except:
sf = 1.0
+ if netCDF_module == 'netCDF4':
+ sf = 1.0 # netCDF4 should autoscale!
beta = outfile.variables['beta']
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)
@@ -188,18 +202,20 @@
try:
- temp = infile.variables['temp']
+ tempstag = infile.variables['tempstag']
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="red">input temp min/max', temp[:].min()*sf, temp[:].max()*sf
- if level == nVertLevels + 2: # CISM includes the upper and lower boundaries as levels, MPAS does not.
+ print '</font>
<font color="gray">input tempstag min/max', tempstag[:].min()*sf, tempstag[:].max()*sf
+ if stagwbndlevel == nVertLevels + 2: # CISM includes the upper and lower boundaries as levels, MPAS does not.
#print range(1,level-1)
- for i in range(1,level-1):
- print 'Copying level ', i+1, ' of ', level , 'CISM levels (ignoring CISM b.c. temp levels)'
- temperature[timelevout,:,i-1] = BilinearInterp(x1, y1, temp[timelev,i,:,:]*sf, xCell, yCell)
+ 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 'new temperature min/max', temperature[:].min(), temperature[:].max()
else:
raise Exception
@@ -237,6 +253,7 @@
#except:
# print 'problem with thk field (e.g. not found in input file), skipping...'
+print '</font>
<font color="black">This script is still experimental. Make sure the in/out min/max values make sense before using the grid.'
infile.close()
outfile.close()
</font>
</pre>