def makeTimeComposite(variable, avgvariable, minvalue, maxvalue): """ Make a time composite of grid supplied(variable) between min max ranges of a 1d avg variable supplied. """ from visad import FunctionType from visad import FieldImpl from visad import RealType from visad import Gridded1DDoubleSet from visad import VisADException from ucar.unidata.util.Misc import getAverage timeSet = GridUtil.getTimeSet(avgvariable) newTimeIndexList = java.util.ArrayList() newTimeValues = [] for i in range(timeSet.getLength()): avg = getAverage(avgvariable.getSample(i).getFloats()[0]) if minvalue < avg <= maxvalue: newTimeIndexList.add(Integer(i)) newTimeValues.append(timeSet[i].getValue()) print(len(newTimeIndexList)) if (len(newTimeIndexList) < 1): raise VisADException("No Matches found to make a time composite") newTimes = Gridded1DDoubleSet(RealType.Time, [newTimeValues], len(newTimeValues), None, timeSet.getSetUnits(), None) compvariable = FieldImpl( FunctionType(RealType.Time, variable.getSample(0).getType()), newTimes) for i in range(len(newTimeValues)): compvariable.setSample(i, variable[newTimeIndexList[i]]) return compvariable
def makeTimeComposite(variable,avgvariable,minvalue,maxvalue): """ Make a time composite of grid supplied(variable) between min max ranges of a 1d avg variable supplied. """ from visad import FunctionType from visad import FieldImpl from visad import RealType from visad import Gridded1DDoubleSet from visad import VisADException from ucar.unidata.util.Misc import getAverage timeSet = GridUtil.getTimeSet(avgvariable) newTimeIndexList = java.util.ArrayList(); newTimeValues= [] for i in range(timeSet.getLength()): avg=getAverage(avgvariable.getSample(i).getFloats()[0]) if minvalue < avg <=maxvalue: newTimeIndexList.add(Integer(i)) newTimeValues.append(timeSet[i].getValue()) print(len(newTimeIndexList)) if (len(newTimeIndexList) < 1): raise VisADException("No Matches found to make a time composite") newTimes=Gridded1DDoubleSet(RealType.Time,[newTimeValues],len(newTimeValues),None,timeSet.getSetUnits(),None) compvariable = FieldImpl(FunctionType(RealType.Time, variable.getSample(0).getType()), newTimes) for i in range(len(newTimeValues)): compvariable.setSample(i,variable[newTimeIndexList[i]]) return compvariable
def setValuestoGridAverage(variable, avgvariable): """ Set all values at each grid in a grid by spatial average, currently the average is not area weighted """ from ucar.unidata.util.Misc import getAverage ts = GridUtil.getTimeSet(variable) newGrid = variable.clone() for i in range(ts.getLength()): avg = getAverage(avgvariable.getSample(i).getFloats()[0]) newGrid.setSample(i, replace(variable.getSample(i), avg)) return newGrid
def setValuestoGridAverage(variable,avgvariable): """ Set all values at each grid in a grid by spatial average, currently the average is not area weighted """ from ucar.unidata.util.Misc import getAverage ts=GridUtil.getTimeSet(variable) newGrid=variable.clone() for i in range(ts.getLength()): avg=getAverage(avgvariable.getSample(i).getFloats()[0]) newGrid.setSample(i,replace(variable.getSample(i),avg)) return newGrid