Page 1 of 1

newUnit

Posted: Mon Jul 06, 2015 4:52 pm
by joleenf
Hi,

I am loading local adde goes data from the May 20, 2014 srso. I want to change the unit of the band4 temperature from Kelvin to C.

Code: Select all

   imgIR = loadADDEImage(time=(imgTime,imgTime),day=imgDay,**parmsIR)

   test=newUnit(imgIR,'182_Band4_Temp','C')


fails, but does not raise an error. When I try displaying "test," a null pointer exception is raised. I tried using "TEMP" within the newUnit command as well, that did not work either.

Joleen

Re: newUnit

Posted: Mon Jul 06, 2015 5:13 pm
by tomw
You might try "degC". I believe that "C" is "Coulomb".

Re: newUnit

Posted: Mon Jul 06, 2015 6:33 pm
by jayh
Hi Joleen-

I tried your newUnit() on some local band4 GOES data and I'm seeing a null pointer exception as well.

Tom... I tried 'degC' and still received the NPE. I've pinged Mike and Jon to see if they have an idea.

Thanks, Jay

Re: newUnit

Posted: Mon Jul 06, 2015 7:33 pm
by jayh
Hi Joleen-

I received this information from MikeH, and he thinks there are 2 issues going on here:

(1) Joleen's NPE is caused by the startTime field not getting initialized after the call to newUnit. I have seen this type of bug before in the early days of the scripting API, and it should be a straightforward fix (probably needs an inquiry?). For the moment, you can fix the NPE in Joleen's script by adding a line after newUnit:

test = newUnit(irData, '182_Band4_Temp','degC')
test.startTime = irData.startTime

(2) the newUnit formula isn't really working as expected through scripting due to issues related to parameter defaults. You'll get a "degC" label but the probe values will still be in Kelvin. See Inquiry 1875 for more details.


I have written the startTime initialization bug up in Inquiry 2100. Also, these problems are occurring with the noUnit() formula.

I did confirm Mike's #2 issue, I was able to get a display that was labeled "degC" but the values were in K.

Thanks for reporting this!

-Jay

Re: newUnit

Posted: Tue Jul 07, 2015 6:06 pm
by joleenf
Hi Jay,

Thanks, after using degC in newUnit and assigning the startTime again, I was able to display the data.

Unfortunately, I was going to use the values of Celsius for a color bar label, since this is what a certain scientist usually prefers instead of Kelvin. I will stick with Kelvin for now and not worry until someone complains.

Joleen

Re: newUnit

Posted: Tue Jul 07, 2015 8:29 pm
by tomw
Naive question: could you not just change the "display units" in the "Edit->Change Display Unit" menu? Or, if you always want degC, change the display defaults?

Re: newUnit

Posted: Wed Jul 08, 2015 3:14 pm
by joleenf
I did not consider setting the color scale unit in the parameter defaults. That should work for this.

The reason I would not want to change by using the 'Edit->Change Display Unit' feature is that I am running on SRSO images. That would involve too much clicking.

Joleen

Re: newUnit

Posted: Wed Sep 13, 2017 3:51 pm
by joleenf
Post

Hi,

I ran into this problem again with the current problem: unit looks to be changed from kelvin to celsius, but the values are not. I was wondering if this is fixed, or am I writing this code incorrectly. If it is still broken within McV, could it be fixed or temporarily issue a warning message to the user so that they are reminded that newUnit is not working correctly. Below are two pathways I tried, neither worked. In the end, I chose to convert the unit using irTemp - 273.15, and not change the unit officially. In that case, I also chose to leave the unit label off the color table.

Joleen

Code: Select all

panel=buildWindow(height=480, width=854)
panel[0].setUseProjectionFromData(True)
day='2017/09/08'

time1='17:00'
time2='17:00:30'
descriptor='M1'

listADDE=dict(
   server='satbuf1.ssec.wisc.edu',
   dataset='GOES16A',
   descriptor=descriptor,
   time=(time1,time2),
   day=day,
   band=14,
   position='ALL'
)

imageList=listADDEImageTimes(**listADDE)

loadADDE=dict(
   server=listADDE['server'],
   dataset=listADDE['dataset'],
   descriptor=listADDE['descriptor'],
   size='ALL'
   )
for i,dateTime in enumerate(imageList):
    loadADDE['day']=dateTime['day']
    loadADDE['time']=dateTime['time']

    ir=loadADDEImage(band=14,unit='Temperature',**loadADDE)
   
    thisField=getRangeType(ir)
    newIR =newUnit(ir,thisField.toString(),'degC')

    print whatType(ir)
    print whatType(newIR)

    irLayer1=panel[0].createLayer('Image Display', newIR)
    irLayer2=panel[0].createLayer('Image Display', ir)


In fact, newUnit seems to adjust back to some kelvin values?
ir=loadADDEImage(band=14,unit='Temperature',**loadADDE)

thisField=getRangeType(ir)
newIR=ir.clone()
newIR = newIR - 273.15

newIR2 =newUnit(newIR,thisField.toString(),'degC')

l1=activeDisplay().createLayer('Image Display', ir)
l2=activeDisplay().createLayer('Image Display', newIR)
l3=activeDisplay().createLayer('Image Display', newIR2)

l1.setLegendLabel('IR')
l2.setLegendLabel('newIR')

l3.setLegendLabel('newIR2')


Thanks,
Joleen

Re: newUnit

Posted: Wed Sep 13, 2017 5:25 pm
by bobc
Hi Joleen -

You are correct that newUnit has problems converting temperature values. This is written up as Inquiry 1875. I'll add a note to this inquiry that you ran into this problem again and send it to the programmers for comment.

Thanks -
Bob

Re: newUnit

Posted: Thu Sep 14, 2017 7:08 pm
by bobc
Hi Joleen -

The programmers looked at this yesterday, and it doesn't appear that newUnit will work through scripting due to a conflict with parameter defaults.

However, they added a couple new functions that add the ability to change the unit once the display has been created. You can return the unit of the displayed layer by running:

Code: Select all

layer.getDisplayUnit()

For satellite imagery data, this (by default) will return K. If you want to change to Celsius, you can use setDisplayUnit():

Code: Select all

layer.setDisplayUnit('C')

Which will change the display unit to Celsius.

I'll add these functions to the documentation, and mention that users should use these functions to change display units instead of using newUnit.

I've tested this on Windows 7 so far with no issues. These new functions are included in the 09/14 nightly. If you give it a try and run into any problems, please let me know.

Thanks -
Bob