Re: [idvusers] Changing unit of FlatField from celsius to meter using Jython

Hi Don,

thanks a lot for the really quick help. newUnit works just fine. I'm scripting some computations with celsius data and want to display the results in a topography display, therefore the unit change.

One more quick question: I have a FieldImpl containing the data of one variable. How do I get the name of that variable? I've tried rangeType(data.getSample(0)).prettyString(), but that also gives me some additional information about the unit (e.g. 'tho[unit:Celsius]'), which I don't need (I only want to get the 'tho').

Patrick


Don Murray schrieb:
Hi Patrick-

Patrick Koethur wrote:
Is there a way of changing the unit of a FlatField from celsius to meter using Jython scripting? I've tried a lot different approaches, but haven't come up with a solution yet.

Since it's physically impossible to convert between these units the
typical approaches (like below) don't work.  There is a Jython
function:

newUnit(field, varname, unitname)

in grid.py which will replace the units with incompatible units.
Basically, it creates a new RealType using the new name and unit
and sets that for the samples of the FlatField.  Using this will
allow you to do what you want.  Just be sure to use "celsius" or
"degC" for the unit name, not "C".  "C" is for Coulomb (as the
Cookie Monster would say. ;-))

For example: ucar.visad.Util.clone(|visad.Data data, visad.MathType type|) doesn't work because the units are not convertable...

I'm really at a loss. Every little hint is much appreciated.

Try the suggestion above and let us know if it doesn't work.

Just curious, why are you changing from celsius to meter?  Is
it to display the temperatures as a height in the main display?

Don
*************************************************************
Don Murray                               UCAR Unidata Program
dmurray@xxxxxxxxxxxxxxxx                        P.O. Box 3000
(303) 497-8628                              Boulder, CO 80307
http://www.unidata.ucar.edu/staff/donm
*************************************************************