def noUnit(field): """ remove the units from a grid """ import visad from visad import CommonUnit newunit = CommonUnit.promiscuous rt = GridUtil.getParamType(field).getRealComponents()[0] newType = Util.makeRealType(rt.getName(), visad.CommonUnit.promiscuous) return GridUtil.setParamType(field, newType, 0)
def noUnit(field): """ remove the units from a grid """ import visad from visad import CommonUnit newunit = CommonUnit.promiscuous rt = GridUtil.getParamType(field).getRealComponents()[0] newType = Util.makeRealType(rt.getName(), visad.CommonUnit.promiscuous) return GridUtil.setParamType(field, newType,0)
def centerDisplay(viewId, useProjection=False): control = findDisplayControl(id) if not control: raise IllegalArgumentException('Could not find display: %s' % (id)) mcv = McIDASV.getStaticMcv() if mcv: viewManagers = getViewManagers(viewId) if useProjection and control.getDataProjection(): mapProjection = control.getDataProjection() mcv.getVMManager().center(mapProjection, viewManagers) elif control.getDisplayCenter(): centerPoint = Util.makeEarthLocation(control.getDisplayCenter()) mcv.getVMManager().center(centerPoint, viewManagers)
def getSliceAtAltitude(fieldimpl, alt, unit="m"): """ Extract a 2D horizontal slice from a 3D grid at the given altitude; level is a real number; if unit is supplied, it must be compatible with meters (ft, fathoms, etc) param fieldimpl is a grid which may have one or more time steps. """ #import methods from from visad import RealType from visad import Real alt = float(alt) unit = Util.parseUnit(unit) altitude = Real(RealType.Altitude, alt, unit) ff = GridUtil.sliceAtLevel(fieldimpl, altitude) return ff
def getSliceAtAltitude(fieldimpl, alt, unit="m") : """ Extract a 2D horizontal slice from a 3D grid at the given altitude; level is a real number; if unit is supplied, it must be compatible with meters (ft, fathoms, etc) param fieldimpl is a grid which may have one or more time steps. """ #import methods from from visad import RealType from visad import Real alt = float(alt) unit = Util.parseUnit(unit) altitude = Real(RealType.Altitude, alt, unit) ff = GridUtil.sliceAtLevel(fieldimpl, altitude) return ff
def makeFlatFieldSequence(sequence): """Turn list of _MappedGeoGridFlatField's into a FieldImpl with time domain that is suitable for displaying. This will work if the flatfield's have a time associated with them via getMetadataMap, but if that doesn't work we're out of luck because a plain old FlatField doesn't have any timestamp. How do handle we that case? Do we put in fake timestamps so the data can at least get displayed still? """ from ucar.unidata.data import DataUtil from ucar.visad import Util from visad import FunctionType from visad import RealType from visad import DateTime dateTimes = [] try: for ff in sequence: if ff.geogrid.getCoordinateSystem().hasTimeAxis1D(): timeAxis = ff.geogrid.getCoordinateSystem().getTimeAxis1D() dateTimes.append(DataUtil.makeDateTimes(timeAxis)[0]) else: # fix for ABI data / data with no time coord: just return plain FF # this will allow data to get displayed, but w/o time info return ff except AttributeError: # no geogrid ... try to read from getMetadataMap if sequence[0].getMetadataMap().get('times'): # this was a _MappedGeoGridFlatField for ff in sequence: # should be a visad.DateTime: timeStr = ff.getMetadataMap().get('times')[0].toString() dateTimes.append(DateTime.createDateTime(timeStr)) elif sequence[0].getMetadataMap().get('nominal-time'): # this was a _MappedAreaImageFlatField for ff in sequence: time = ff.getMetadataMap().get('nominal-time') dateTimes.append(time) timeSet = Util.makeTimeSet(dateTimes) ftype = FunctionType(RealType.Time, ff.getType()) fi = FieldImpl(ftype, timeSet) for i, ff in enumerate(sequence): fi.setSample(i, ff) return fi
def oldaverageOverTime(field, makeTimes=0): """@deprecated Average the values in each time step If makeTimes is true (1) then we return a field mapping all of the times to the average. Else we just return the average """ if (GridUtil.isTimeSequence(field) == 0): return field cnt = 0 domainSet = field.getDomainSet() current = None for t in range(domainSet.getLength()): cnt = cnt + 1 rangeValue = field.getSample(t) if (current is None): current = rangeValue.clone() else: current = current + rangeValue if (cnt == 0): return None current = current / cnt if (makeTimes): return Util.makeTimeField(current, GridUtil.getDateTimeList(field)) return current
def oldaverageOverTime(field,makeTimes = 0): """@deprecated Average the values in each time step If makeTimes is true (1) then we return a field mapping all of the times to the average. Else we just return the average """ if (GridUtil.isTimeSequence(field)==0): return field; cnt = 0; domainSet = field.getDomainSet() current = None; for t in range(domainSet.getLength()): cnt=cnt+1 rangeValue = field.getSample(t) if(current is None): current = rangeValue.clone(); else: current = current+rangeValue; if(cnt == 0): return None; current = current/cnt; if(makeTimes): return Util.makeTimeField(current, GridUtil.getDateTimeList(field)) return current
def centerOnLatLon(latitude, longitude): mcv = McIDASV.getStaticMcv() if mcv: viewManagers = getViewManagers() earthLoc = Util.makeEarthLocation(latitude, longitude) mcv.getVMManager().center(earthLoc, viewManagers)
def newUnit(field, varname, unitname): """ set the name and unit on a grid """ newunit = Util.parseUnit(unitname) newType = Util.makeRealType(varname, newunit) return GridUtil.setParamType(field, newType, 0)
def newUnit(field, varname, unitname): """ set the name and unit on a grid """ newunit = Util.parseUnit(unitname) newType = Util.makeRealType(varname, newunit) return GridUtil.setParamType(field, newType,0)