Weird problem with interpolation

Hi all,

I'm trying to do what I thought was a fairly straightforward field.evaluate(blah) call, and ended up with some NullPointerExceptions. It's a tool under development, so I *might* be giving bad samples or something like that, but I'll post various bits of code and stack trace, and you can make up your own minds. I looked at the VisAD source to try to see what was going on. The datestamp on my visad.jar is July 14th, and the source I'm working from is out of the visad_src.jar with the same timestamp. I included a lot of code / traces, so hopefully what you need is here. Let me know if I've made a dumb error....

My code is :

.....

double[][] timeSet = animationControl.getSet().getDoubles(false); Real timeSample = new Real(RealType.Time, timeSet[0][animationControl.getCurrent()]); FieldImpl distanceField = (FieldImpl)field.evaluate(timeSample);
               System.out.println(distanceField.getType().toString());
RealTuple domainSample = new RealTuple(LEVEL_DISTANCE_TYPE, new double[] { dDistance, dHeight });
               System.out.println(domainSample.toString());
               Data intensityData = distanceField.evaluate(domainSample);
               RealTuple intensityTuple = (RealTuple) intensityData;
               double[] intensityValues = intensityTuple.getValues();
.....

with the error occurring on the line that reads
               Data intensityData = distanceField.evaluate(domainSample);

The mathType of the FieldImpl is :
((LevelXS, VerticalDistanceXS) -> XSGASPMIX)

The RealType I'm trying to evaluate has the samples :
(224.13154940119756, 205.24017467248817)

Both those numbers are valid numbers to ask for, for either level _or_ distance, so it's not a silly specified-the-samples-wrong problem.

The stack trace is :
java.lang.NullPointerException
at visad.Gridded2DDoubleSet.valueToInterp(Gridded2DDoubleSet.java:256)
       at visad.FieldImpl.resample(FieldImpl.java:2762)
       at visad.FunctionImpl.evaluate(FunctionImpl.java:169)
       at visad.FunctionImpl.evaluate(FunctionImpl.java:146)
at au.gov.bom.aifs.dv.xsection.CrossSectionDialog.displayData(CrossSectionDialog.java:787) at au.gov.bom.aifs.dv.xsection.CrossSectionDialog.access$900(CrossSectionDialog.java:57) at au.gov.bom.aifs.dv.xsection.CrossSectionDialog$MouseMovedListener.mouseMoved(CrossSectionDialog.java:811) at java.awt.AWTEventMulticaster.mouseMoved(AWTEventMulticaster.java:271)
       at java.awt.Component.processMouseMotionEvent(Component.java:5145)
       at java.awt.Component.processEvent(Component.java:4901)
       at java.awt.Component.dispatchEventImpl(Component.java:3615)
       at java.awt.Component.dispatchEvent(Component.java:3477)
       at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
       at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

Gridded2DDoubleSet.valueToInterp reads :

 /** for each of an array of values in R^DomainDimension, compute an array
     of 1-D indices and an array of weights, to be used for interpolation;
     indices[i] and weights[i] are null if i-th value is outside grid
     (i.e., if no interpolation is possible) */
 public void valueToInterp(float[][] value, int[][] indices,
   float[][] weights) throws VisADException
 {
   int len = weights.length;
   double[][] w = new double[len][];
   for (int i=0; i<len; i++) w[i] = new double[weights[i].length];
   doubleToInterp(Set.floatToDouble(value), indices, w);
   for (int i=0; i<len; i++) {
     System.arraycopy(w[i], 0, weights[i], 0, w.length);
   }
 }

With the problematic line being :
   for (int i=0; i<len; i++) w[i] = new double[weights[i].length];

Looking at at visad.FieldImpl.resample(FieldImpl.java:2762), which is the calling line shows :

     int[][] indices = new int[length][];
     float[][] coefs = new float[length][];
((GriddedSet) DomainSet).valueToInterp(vals, indices, coefs); <-- this is the calling line

So the weights[][] array in interp is this coefs array. The line " for (int i=0; i<len; i++) w[i] = new double[weights[i].length];" doesn't seem like it will ever work, because it's always a new double[length][], i.e. null for all i.

Cheers,
-Tennessee

  • 2004 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the visad archives: