Beispiel #1
0
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
Beispiel #2
0
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