Exemplo n.º 1
0
 def wrapper(*args, **kwargs):
     wrappedArgs = []
     returnFlatField = False
     for i, arg in enumerate(args):
         # print '%s: %s' % (i, arg)
         if isinstance(arg, FlatField):
             returnFlatField = True
             arg = makeFlatFieldSequence([arg])
         wrappedArgs.append(arg)
     # print [type(a) for a in wrappedArgs]
     wrappedKwargs = {}
     for keyword in kwargs:
         keywordValue = kwargs[keyword]
         if isinstance(keywordValue, FlatField):
             returnFlatField = True  # ??? not sure about kwarg case
             keywordValue = makeFlatFieldSequence([keywordValue])
         wrappedKwargs[keyword] = keywordValue
     # print [type(wrappedKwargs[a]) for a in wrappedKwargs]
     result = func(*wrappedArgs, **wrappedKwargs)
     # print 'result type=%s' % (type(result))
     if GridUtil.isTimeSequence(result) and len(
             result) == 1 and returnFlatField:
         # print 'attempting conversion...'
         result = result.getSample(0)
     # else:
     # print 'not a time sequence! isseq=%s seqtype=%s' % (GridUtil.isSequence(result), GridUtil.getSequenceType(result))
     # print 'returning type=%s' % (type(result))
     return result
Exemplo n.º 2
0
 def wrapper(*args, **kwargs):
     wrappedArgs = []
     returnFlatField = False
     for i, arg in enumerate(args):
         # print '%s: %s' % (i, arg)
         if isinstance(arg, FlatField):
             returnFlatField = True
             arg = makeFlatFieldSequence([arg])
         wrappedArgs.append(arg)
     # print [type(a) for a in wrappedArgs]
     wrappedKwargs = {}
     for keyword in kwargs:
         keywordValue = kwargs[keyword]
         if isinstance(keywordValue, FlatField):
             returnFlatField = True # ??? not sure about kwarg case
             keywordValue = makeFlatFieldSequence([keywordValue])
         wrappedKwargs[keyword] = keywordValue
     # print [type(wrappedKwargs[a]) for a in wrappedKwargs]
     result = func(*wrappedArgs, **wrappedKwargs)
     # print 'result type=%s' % (type(result))
     if GridUtil.isTimeSequence(result) and len(result) == 1 and returnFlatField:
         # print 'attempting conversion...'
         result = result.getSample(0)
     # else:
         # print 'not a time sequence! isseq=%s seqtype=%s' % (GridUtil.isSequence(result), GridUtil.getSequenceType(result))
     # print 'returning type=%s' % (type(result))
     return result
Exemplo n.º 3
0
def unpackage(fieldImpl):
    """ Return the first FlatField contained by this FieldImpl.
  
    Args:  
      fieldImpl: the original argument to the VIIRS formula being called

    Returns:  FlatField suitable for sending into MultiSpectralDataSource methods
    """
    if GridUtil.isTimeSequence(fieldImpl):
        return fieldImpl.getSample(0)
    else:
        return fieldImpl
Exemplo n.º 4
0
def applyToRange(function, data):
    """ Apply the function name to each timestep of the data """
    newData = data.clone()
    f = function + '(rangeValue)'
    if (GridUtil.isTimeSequence(newData)):
        for t in range(newData.getDomainSet().getLength()):
            rangeValue = newData.getSample(t)
            result = eval(f)
            newData.setSample(t, result, 0)
    else:
        rangeValue = newData
        newData = eval(f)
    return newData
Exemplo n.º 5
0
def applyToRange(function,data):
    """ Apply the function name to each timestep of the data """
    newData = data.clone()
    f = function +'(rangeValue)'
    if (GridUtil.isTimeSequence(newData)):
        for t in range(newData.getDomainSet().getLength()):
            rangeValue = newData.getSample(t)
            result = eval(f)
            newData.setSample(t,result,0)
    else:
        rangeValue = newData
        newData = eval(f)
    return newData
Exemplo n.º 6
0
 def wrapper(*args):
     wrappedArgs = []
     for i, arg in enumerate(args):
         # print '%s: %s' % (i, arg)
         if isinstance(arg, SingleBandedImage):
             arg = ImageSequenceImpl([arg])
         wrappedArgs.append(arg)
     # print [type(a) for a in wrappedArgs]
     result = func(*wrappedArgs)
     # print 'result type=%s' % (type(result))
     if GridUtil.isTimeSequence(result) and len(result) == 1:
         # print 'attempting conversion...'
         result = result.getImage(0)
     # else:
         # print 'not a time sequence! isseq=%s seqtype=%s' % (GridUtil.isSequence(result), GridUtil.getSequenceType(result))
     # print 'returning type=%s' % (type(result))
     return result
Exemplo n.º 7
0
 def wrapper(*args):
     wrappedArgs = []
     for i, arg in enumerate(args):
         # print '%s: %s' % (i, arg)
         if isinstance(arg, SingleBandedImage):
             arg = ImageSequenceImpl([arg])
         wrappedArgs.append(arg)
     # print [type(a) for a in wrappedArgs]
     result = func(*wrappedArgs)
     # print 'result type=%s' % (type(result))
     if GridUtil.isTimeSequence(result) and len(result) == 1:
         # print 'attempting conversion...'
         result = result.getImage(0)
     # else:
     # print 'not a time sequence! isseq=%s seqtype=%s' % (GridUtil.isSequence(result), GridUtil.getSequenceType(result))
     # print 'returning type=%s' % (type(result))
     return result
Exemplo n.º 8
0
def applyToRangeValues(function, data):
    """ Apply the function name to each value in each timestep of the data """
    newData = data.clone()
    f = function + '(values,step=step,rangeObject=rangeObject,field=field)'
    step = 0
    if (GridUtil.isTimeSequence(newData)):
        for t in range(newData.getDomainSet().getLength()):
            rangeObject = newData.getSample(t)
            values = rangeObject.getFloats(0)
            values = eval(f)
            rangeObject.setSamples(values, 1)
            step = step + 1
    else:
        rangeObject = newData
        values = rangeObject.getFloats(0)
        values = eval(f)
        rangeObject.setSamples(values, 1)
    return newData
Exemplo n.º 9
0
def applyToRangeValues(function,data):
    """ Apply the function name to each value in each timestep of the data """
    newData = data.clone()
    f = function +'(values,step=step,rangeObject=rangeObject,field=field)'
    step=0
    if (GridUtil.isTimeSequence(newData)):
        for t in range(newData.getDomainSet().getLength()):
            rangeObject = newData.getSample(t)
            values = rangeObject.getFloats(0)
            values = eval(f)
            rangeObject.setSamples(values,1)
            step= step+1
    else:
        rangeObject = newData
        values = rangeObject.getFloats(0)
        values = eval(f)
        rangeObject.setSamples(values,1)
    return newData
Exemplo n.º 10
0
def substitute(data, low, high, newValue):
    """change values in data  between low/high to newvalue """
    newData = data.clone()
    if (GridUtil.isTimeSequence(newData)):
        for t in range(newData.getDomainSet().getLength()):
            rangeObject = newData.getSample(t)
            values = rangeObject.getFloats(0)
            for i in range(len(values)):
                for j in range(len(values[0])):
                    if values[i][j] >= low:
                        if values[i][j] <= high: values[i][j] = newValue
            rangeObject.setSamples(values, 1)
    else:
        rangeObject = newData
        values = rangeObject.getFloats(0)
        for i in range(len(values)):
            for j in range(len(values[0])):
                if values[i][j] >= low:
                    if values[i][j] <= high: values[0][i] = newValue
        rangeObject.setSamples(values, 1)
    return newData
Exemplo n.º 11
0
def substitute(data, low, high, newValue):
    """change values in data  between low/high to newvalue """
    newData = data.clone();
    if (GridUtil.isTimeSequence(newData)):
        for t in range(newData.getDomainSet().getLength()):
            rangeObject = newData.getSample(t)
            values = rangeObject.getFloats(0);
            for i in range(len(values)):
               for j in range(len(values[0])):
		           if values[i][j]>=low:
		             if values[i][j]<=high:  values[i][j] = newValue;
            rangeObject.setSamples(values,1);
    else:
        rangeObject = newData;
        values = rangeObject.getFloats(0);
        for i in range(len(values)):
          for j in range(len(values[0])):
             if values[i][j]>=low:
                if values[i][j]<=high: values[0][i] = newValue;
        rangeObject.setSamples(values,1);
    return newData;
Exemplo n.º 12
0
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
Exemplo n.º 13
0
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
Exemplo n.º 14
0
def package(original, result):
    """ Put 'result' back into a FieldImpl using the time domain from 'original'.

    Args:
      original: the original argument to the VIIRS formula being called
      result: the result of the MultiSpectralDataSource methods called by
            the current VIIRS formula

    Returns: FieldImpl with proper time domain (so that e.g. IDV's %timestamp% macro
             will work properly)
    """
    from visad import FunctionType
    from visad import FieldImpl
    from visad import RealType

    if GridUtil.isTimeSequence(original):
        ftype = FunctionType(RealType.Time, result.getType())
        fieldimpl = FieldImpl(ftype, original.getDomainSet())
        fieldimpl.setSample(0, result)
        return fieldimpl
    else:
        # just return the plain flatfield if original wasn't a fieldimpl
        # (needed to make loadJPSSImage work)
        return result