[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

20060102: Surface Temperature under Clouds



>From: "Valentijn Venus" <address@hidden>
>Organization: ITC
>Keywords: 200601021646.k02Gko7s025501 IDV Jython

Hi Valentijn-

Happy New Year!

>I'm trying to implement a jython procedure within IDV to reconstruct
>diurnal temperature under cloudcover (replacing NaN with an estimated
>surface temperature). The few clear sky satellite surface temperature
>estimates I have are used as an input to the new algorithm (full javadoc
>attached), as a dimensionless array (time is initiated based on a
>.setResolution() and setStartTime() method:

Since I don't have your libraries to run this, I can only guess
at some possible problems.

The error is indicating that the grid that is being returned
is null, probably because some error occured in executing the
Jython procedure.  I've sprinkled some comments in the code
of my observations:

here are a couple of observations:


>By the way, how do i scale the y-axes in a timeseries probe?

Right now, there's no way to scale this manually.  It should scale
to the data range, so I'm not sure why it is showing outside the
box.

>java.lang.Object
>   org.n52.operation.cropmodeling.TemperatureModelAlgorithm
>
>
>       All Implemented Interfaces:
>       AlgorithmN
><http://adde.itc.nl/IDV/operation/doc/org/n52/math/AlgorithmN.html> ,
>AlgorithmOnValues
><http://adde.itc.nl/IDV/operation/doc/org/n52/math/AlgorithmOnValues.htm
>l> 
>
>________________________________
>
>=09
>       public class TemperatureModelAlgorithm
>       extends java.lang.Object
>       implements AlgorithmOnValues
><http://adde.itc.nl/IDV/operation/doc/org/n52/math/AlgorithmOnValues.htm
>l>
>
>Algorithm to calculate crop CO2 assimilation values
>
>The algorithm works on a timeseries temperature values; it needs
>time-temperature value pairs and the latitude of the spatial location to
>correctly perform the calculation
>
>       Author:
>       Valentijn Venus, Willem Nieuwenhuis
>
>
>The algorithm returns an array of tempratures, but i'm failing to return
>the results as you can see form the NullPointerException
>
>The error message:
>
>java.lang.NullPointerException
> at ucar.unidata.data.grid.GridUtil.isSequence(GridUtil.java:351)
> at ucar.unidata.data.grid.GridUtil.setParamType(GridUtil.java:1438)
> at
>ucar.unidata.data.grid.GridDataInstance.setParamType(GridDataInstance.ja
>va:365)
> at
>ucar.unidata.data.grid.GridDataInstance.getGrid(GridDataInstance.java:53
>7)
> at
>ucar.unidata.data.grid.GridDataInstance.getGrid(GridDataInstance.java:52
>3)
> at
>ucar.unidata.idv.control.ProbeControl.setData(ProbeControl.java:1441)
> at
>ucar.unidata.idv.control.ProbeControl.updatePosition(ProbeControl.java:1
>300)
> at
>ucar.unidata.idv.control.ProbeControl.updatePosition(ProbeControl.java:1
>215)
> at
>ucar.unidata.idv.control.ProbeControl.initDone(ProbeControl.java:306)
> at
>ucar.unidata.idv.control.DisplayControlImpl.init(DisplayControlImpl.java
>:984)
> at
>ucar.unidata.idv.ControlDescriptor.initControl(ControlDescriptor.java:79
>2)
> at ucar.unidata.idv.ControlDescriptor$1.run(ControlDescriptor.java:750)
> at ucar.unidata.util.Misc$2.run(Misc.java:806)
>
>The script:
>
>################################################################
># Temperature model
>################################################################
>
>def getTempDiurnalImageSeqN52(LST):
>
> import sys;
> sys.add_package('visad.meteorology');
> sys.add_package('GridUtil');
>
>from java.util import TimeZone
>from visad import DateTime
>from visad.meteorology import ImageSequence
>from visad.meteorology import SingleBandedImage
>
>sys.add_package('org.n52.math');
>sys.add_package('org.n52.operation');
>sys.add_package('org.n52.operation.cropmodeling');
>from org.n52.operation.cropmodeling import TemperatureModelAlgorithm
>
>def getTempDiurnalImageN52(LST):
>  domain = LST.getDomainSet()
>  cs = domain.getCoordinateSystem()
>  len =  domain.getLength()
>#Note: we want a copy of the range values so we don't pass in 0 (false)
>here
>  lineValuesLST = LST.getValues()

If LST is an ImageSequence, the getValues() will not return
the values for the image.  

  lineValuesLST = LST.getValues()

You'd need to do this for each image in the sequence.

>#Pass in 0 as false so we don't copy the values
>  samples = domain.getSamples(0)
>#Get the latlon points of the spatial domain
>  latlon = cs.toReference(samples)

There is no guarantee that the toReference and fromReference
methods return a new array.  Some CoordinateSystems will change
values in place to save on memory.  So, if you are going to run
the domain samples, you should probably make a copy to avoid
changing the original arrays.

>
>#Initialize temperature algorithm
>  tempModelAlg = TemperatureModelAlgorithm()
>  tempModelAlg.setResolution(15)
>
>#Get start time of image sequence
>  tz = TimeZone.getTimeZone("GMT");
>  if isinstance(LST, ImageSequence):
>      sbi = LST.getImage(0)
>      dateTime = sbi.getStartTime()
>  elif isinstance(LST, SingleBandedImage):
>      dateTime = LST.getStartTime()
>  year = dateTime.formattedString("yyyy", tz)
>  month = dateTime.formattedString("MM", tz)
>  day = dateTime.formattedString("dd", tz)
>  hour = float(dateTime.formattedString("H", tz))
>  minutes = float(dateTime.formattedString("mm", tz))
>
>  tempModelAlg.setStartTime(int(year), int(month), int(day), int(hour),
>int(minutes))
>  tempModelAlg.setLatitude(10.5)
>
>  newA = LST.clone()
>   
>  seq = LST.getDomainSet().getLength()
>  arr = array(seq, "d")
>  for i in xrange(seq):
>      arr[i] = LST.getSample(i)

Again, if LST is an FieldImpl/ImageSequence, your results will be different
than if it is a FlatField/SingleBandedImage.  getSample will return
a VisAD data object, not an array.

>  res = tempModelAlg.calculate(arr)
>  for i in xrange(seq):
>      lineValuesLST[0][i] = res.getSample(i)

if res is a double array, I'm not sure how you can call res.getSample(i).
Is that a jython built-in?

>      newA.setSample(i,lineValuesLST)
>  return newA

Unless I'm reading this wrong, I think you are mixing VisAD Data
objects and double arrays and that may be part of your problem.
It might help to add some printouts of the MathType of LST and
various variables in they jython to see if you aren't mixing
apples and oranges.

Don Murray
NOTE: All email exchanges with Unidata User Support are recorded in the
Unidata inquiry tracking system and then made publicly available
through the web.  If you do not want to have your interactions made
available in this way, you must let us know in each email you send to us.