Commit e89fd7e3 authored by Ralf Mueller's avatar Ralf Mueller
Browse files

Completed table.py for textual output

parent dfb4d0a4
......@@ -73,19 +73,20 @@ int main() {
}
else
std::cout << "no grid bounds available" << std::endl;
{
std::cout << "#===============================" << std::endl;
printf("Stream:%d\n" , var.streamID);
printf("Taxis (unit):%d\n" , var.taxis.unit);
printf("Taxis (ntsteps):%d\n", var.taxis.ntsteps);
printf("Taxis (type):%d\n" , var.taxis.type);
printf("Zaxis (unit):%d\n" , var.taxis.unit);
printf("Zaxis (levels):%d\n" , var.zaxis.size);
printf("Zaxis (type):%d\n" , var.zaxis.type);
printf("Zaxis (ltype):%d\n" , var.zaxis.ltype);
printf("Zaxis (prec):%d\n" , var.zaxis.prec);
printf("Zaxis (levels): varno:%f -1:%f\n", var.zaxis.levels[varno], var.zaxis.levels[var.zaxis.size-1]);
std::cout << "#===============================" << std::endl;
printf("Stream:%d\n" , var.streamID);
printf("Taxis (unit):%d\n" , var.taxis.unit);
printf("Taxis (ntsteps):%d\n", var.taxis.ntsteps);
printf("Taxis (type):%d\n" , var.taxis.type);
printf("Zaxis (unit):%d\n" , var.taxis.unit);
printf("Zaxis (levels):%d\n" , var.zaxis.size);
printf("Zaxis (type):%d\n" , var.zaxis.type);
printf("Zaxis (ltype):%d\n" , var.zaxis.ltype);
printf("Zaxis (prec):%d\n" , var.zaxis.prec);
printf("Zaxis (levels): varno:%f -1:%f\n", var.zaxis.levels[varno], var.zaxis.levels[var.zaxis.size-1]);
}
std::cout << "# field values ================" << std::endl;
var.getValues();
std::cout << "values[0] = " << var.values[0] << std::endl;
......
......@@ -87,6 +87,7 @@ void CdiGrid::getValues()
std::cout << "grid " << gridID << " has no YValues" << std::endl;
}
}
void CdiGrid::getBounds()
{
double *xbnds, *ybnds;
......@@ -292,6 +293,7 @@ CdiVariable::getValuesWithLevelAsPointer(int tsID)
streamReadVarSlice(streamID, varID, levelID, field, &nmiss);
fieldWithLevel[levelID] = field;
}
free(field);
return fieldWithLevel;
}
......@@ -301,6 +303,7 @@ CdiVariable::getValues()
double *field = getValuesAsPointer();
values.resize(grid.size);
std::copy(field, field + grid.size, values.begin());
free(field);
}
void
......@@ -313,6 +316,7 @@ CdiVariable::getValuesWithLevel(int tsID) {
valuesWithLevel[levelID].resize(grid.size);
std::copy(fieldWithLevel[levelID], fieldWithLevel[levelID] + grid.size, valuesWithLevel[levelID].begin());
}
free(fieldWithLevel);
}
vector<float>
......
......@@ -604,36 +604,15 @@ class CdiGrid(_object):
__swig_setmethods__["ncorner"] = _CdiObj.CdiGrid_ncorner_set
__swig_getmethods__["ncorner"] = _CdiObj.CdiGrid_ncorner_get
if _newclass:ncorner = _swig_property(_CdiObj.CdiGrid_ncorner_get, _CdiObj.CdiGrid_ncorner_set)
__swig_setmethods__["hasXYValues"] = _CdiObj.CdiGrid_hasXYValues_set
__swig_getmethods__["hasXYValues"] = _CdiObj.CdiGrid_hasXYValues_get
if _newclass:hasXYValues = _swig_property(_CdiObj.CdiGrid_hasXYValues_get, _CdiObj.CdiGrid_hasXYValues_set)
__swig_setmethods__["hasXValues"] = _CdiObj.CdiGrid_hasXValues_set
__swig_getmethods__["hasXValues"] = _CdiObj.CdiGrid_hasXValues_get
if _newclass:hasXValues = _swig_property(_CdiObj.CdiGrid_hasXValues_get, _CdiObj.CdiGrid_hasXValues_set)
__swig_setmethods__["hasYValues"] = _CdiObj.CdiGrid_hasYValues_set
__swig_getmethods__["hasYValues"] = _CdiObj.CdiGrid_hasYValues_get
if _newclass:hasYValues = _swig_property(_CdiObj.CdiGrid_hasYValues_get, _CdiObj.CdiGrid_hasYValues_set)
__swig_setmethods__["hasBounds"] = _CdiObj.CdiGrid_hasBounds_set
__swig_getmethods__["hasBounds"] = _CdiObj.CdiGrid_hasBounds_get
if _newclass:hasBounds = _swig_property(_CdiObj.CdiGrid_hasBounds_get, _CdiObj.CdiGrid_hasBounds_set)
__swig_setmethods__["xvals"] = _CdiObj.CdiGrid_xvals_set
__swig_getmethods__["xvals"] = _CdiObj.CdiGrid_xvals_get
if _newclass:xvals = _swig_property(_CdiObj.CdiGrid_xvals_get, _CdiObj.CdiGrid_xvals_set)
__swig_setmethods__["yvals"] = _CdiObj.CdiGrid_yvals_set
__swig_getmethods__["yvals"] = _CdiObj.CdiGrid_yvals_get
if _newclass:yvals = _swig_property(_CdiObj.CdiGrid_yvals_get, _CdiObj.CdiGrid_yvals_set)
__swig_setmethods__["xbnds"] = _CdiObj.CdiGrid_xbnds_set
__swig_getmethods__["xbnds"] = _CdiObj.CdiGrid_xbnds_get
if _newclass:xbnds = _swig_property(_CdiObj.CdiGrid_xbnds_get, _CdiObj.CdiGrid_xbnds_set)
__swig_setmethods__["ybnds"] = _CdiObj.CdiGrid_ybnds_set
__swig_getmethods__["ybnds"] = _CdiObj.CdiGrid_ybnds_get
if _newclass:ybnds = _swig_property(_CdiObj.CdiGrid_ybnds_get, _CdiObj.CdiGrid_ybnds_set)
__swig_setmethods__["xvalsF"] = _CdiObj.CdiGrid_xvalsF_set
__swig_getmethods__["xvalsF"] = _CdiObj.CdiGrid_xvalsF_get
if _newclass:xvalsF = _swig_property(_CdiObj.CdiGrid_xvalsF_get, _CdiObj.CdiGrid_xvalsF_set)
__swig_setmethods__["yvalsF"] = _CdiObj.CdiGrid_yvalsF_set
__swig_getmethods__["yvalsF"] = _CdiObj.CdiGrid_yvalsF_get
if _newclass:yvalsF = _swig_property(_CdiObj.CdiGrid_yvalsF_get, _CdiObj.CdiGrid_yvalsF_set)
__swig_setmethods__["xbndsF"] = _CdiObj.CdiGrid_xbndsF_set
__swig_getmethods__["xbndsF"] = _CdiObj.CdiGrid_xbndsF_get
if _newclass:xbndsF = _swig_property(_CdiObj.CdiGrid_xbndsF_get, _CdiObj.CdiGrid_xbndsF_set)
__swig_setmethods__["ybndsF"] = _CdiObj.CdiGrid_ybndsF_set
__swig_getmethods__["ybndsF"] = _CdiObj.CdiGrid_ybndsF_get
if _newclass:ybndsF = _swig_property(_CdiObj.CdiGrid_ybndsF_get, _CdiObj.CdiGrid_ybndsF_set)
__swig_setmethods__["xvalues"] = _CdiObj.CdiGrid_xvalues_set
__swig_getmethods__["xvalues"] = _CdiObj.CdiGrid_xvalues_get
if _newclass:xvalues = _swig_property(_CdiObj.CdiGrid_xvalues_get, _CdiObj.CdiGrid_xvalues_set)
......@@ -673,8 +652,12 @@ class CdiGrid(_object):
__swig_setmethods__["name"] = _CdiObj.CdiGrid_name_set
__swig_getmethods__["name"] = _CdiObj.CdiGrid_name_get
if _newclass:name = _swig_property(_CdiObj.CdiGrid_name_get, _CdiObj.CdiGrid_name_set)
def readFloatBounds(self): return _CdiObj.CdiGrid_readFloatBounds(self)
def readFloatVals(self): return _CdiObj.CdiGrid_readFloatVals(self)
def getValues(self): return _CdiObj.CdiGrid_getValues(self)
def getBounds(self): return _CdiObj.CdiGrid_getBounds(self)
def getValuesAsPointer(self, *args): return _CdiObj.CdiGrid_getValuesAsPointer(self, *args)
def getBoundsAsPointer(self, *args): return _CdiObj.CdiGrid_getBoundsAsPointer(self, *args)
def getFloatVals(self, *args): return _CdiObj.CdiGrid_getFloatVals(self, *args)
def getFloatBounds(self, *args): return _CdiObj.CdiGrid_getFloatBounds(self, *args)
CdiGrid_swigregister = _CdiObj.CdiGrid_swigregister
CdiGrid_swigregister(CdiGrid)
......
This diff is collapsed.
import os
import os, numpy
import CdiObj
sourcefile = "BOT.grb"
......@@ -13,13 +13,27 @@ os.popen(cmd).read()
cdi = CdiObj.Cdi(zonalfile)
# get all codes and names
myCodes = [176, 96]
for code in cdi.codes:
# display gridvalues
#var = cdi.varByCode[176]
#print "VAR: ", var.name, ' size:' ,var.size
#g = var.grid
#print var.xvalues.first
#print '#============================================#'
#print var.yvalues
#print '#============================================#'
# display gridvalues
var = cdi.varByCode[code]
#print '# GRID info ===========================================#'
#g = var.grid
#for v in g.xvalues:
#print v
#for v in g.yvalues:
#print v
print "VAR: ", var.name, ' size:' ,var.size
var.getValues()
#for v in var.values:
#print v
# convert to numpy
vals = numpy.array(var.values)
lats = numpy.array(var.grid.yvalues)
northInd = numpy.where(lats >= 0)
southInd = numpy.where(lats < 0)
print 'Global Mean: ',vals.mean()
print 'Global Max|Min: ',vals.max(),'|',vals.min()
print 'North Mean: ',vals[northInd].mean()
print 'South Mean: ',vals[southInd].mean()
print '#============================================#'
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment