I can't find a way to extract the unit consistently from the data object in McIDAS-V.
I have used:
1.) flatField.getRangeUnits()[0][0]
I have used:
1.) flatField.getRangeUnits()[0][0]
- <class '__main__._MappedAreaImageFlatField'> original unit, correct result
- noUnit(<class '__main__._MappedAreaImageFlatField'>) universal unit, incorrect result
- <class '__main__._MappedGeoGridFlatField'> correct result
- <type 'ucar.visad.data.GeoGridFlatField'> correct result (for ADDE or Grids loaded through choosers)
- <type 'visad.FieldImpl'> doesn't work, but did not expect this to work since the Impl can be an array of data fields.
2.) getRangeType(gdata)
- <class '__main__._MappedAreaImageFlatField'> incorrect result
- noUnit(<class '__main__._MappedAreaImageFlatField'>) correct result
- <class '__main__._MappedGeoGridFlatField'> different path needed
- <type 'ucar.visad.data.GeoGridFlatField'> unit is in result, but result is not a unit
(for ADDE or Grids loaded through choosers)
- <type 'visad.FieldImpl'> unit is in result, but result is not a unit
3.) GridUtil.getParamUnits(flatField)[0] does not always report the correct unit
- <class '__main__._MappedAreaImageFlatField'> correct result
- noUnit(<class '__main__._MappedAreaImageFlatField'>) incorrect result
- <class '__main__._MappedGeoGridFlatField'> correct result
- <type 'ucar.visad.data.GeoGridFlatField'> correct result (for ADDE or Grids loaded through choosers)
- <type 'visad.FieldImpl'> correct
4.) whatType always reports corrects units as far as I can tell, but how can the units be extracted?
Code: Select all
parmsList=dict(
#accounting = ('YOU',9999), #accounting information required
#if ADDE dataset is not registered
#in ADDE Manager
server='dcarchivex.ssec.wisc.edu',
dataset='GREX',
descriptor='FD',
band=1,
day='2016277',
time=('16:04', '16:09'),
position='ALL'
)
dateTimes=listADDEImageTimes(**parmsList)
if (len(dateTimes) >= 1):
#panel=buildWindow(height=900,width=900)[0]
for dateTime in dateTimes[::2]:
index=1
parms=dict(
#accounting = ('YOU',9999), #accounting information required
#if ADDE dataset is not registered
#in ADDE Manager
server=parmsList['server'],
dataset=parmsList['dataset'],
descriptor='FD',
day=dateTime['day'],
time=dateTime['time'],
unit='ALB',
location=(0.1,-98.4),
coordinateSystem=LATLON,
place=ULEFT,
mag=(1,1)
)
gdata=loadADDEImage(band=3, size=(4,4), **parms)
print 'gdata is {}'.format(type(gdata))
print '\n(CORRECT) gdata.getRangeUnits()[0][0]: {}'.format((gdata.getRangeUnits()[0][0]))
print '(WRONG) getRangeType(gdata) will not work in this case {}'.format(getRangeType(gdata))
print '(CORRECT) GridUtil.getParamUnits: {}\n'.format(GridUtil.getParamUnits(gdata)[0])
print 'Apply noUnit\n\n'
newGreen=noUnit(gdata)
print 'newGreen is {}'.format(type(newGreen))
print '(CORRECT) getRangeType(newGreen): {}\n'.format(getRangeType(newGreen))
print '(WRONG) As reported above, this fails on the original object, try getRangeType(gdata): {}'.format(getRangeType(gdata))
thisNewUnit=newGreen.getRangeUnits()[0][0]
print '(WRONG) newGreen.getRangeUnits()[0][0]: noUnit has been applied and the unit is still being reported as {}'.format(thisNewUnit)
print '(CORRECT) Try using whatType(newGreen)....This should report the Units correctly as UniversalUnit'
print whatType(newGreen)
print '(WRONG) GridUtil.getParamUnits(newGreen)[0]: {}\n'.format(GridUtil.getParamUnits(newGreen)[0])
print 'The result for flatFields loaded via loadGrid is different'
filename='/Users/joleenf/data/goesr/DOE-4/CONUS/OR_ABI-L2-CMIPC-M3C07_G16_s20162231442163_e20162231444535_c20162231444592.nc'
thisData=loadGrid(filename=filename,field='CMI',stride=50)
print 'thisData is {}'.format(type(thisData))
print '(CORRECT) thisData.getRangeUnits()[0][0]: {}'.format(thisData.getRangeUnits()[0][0])
print '(DIFFERENT PATH) getRangeType(thisData): {}\n'.format(getRangeType(thisData))
print 'Getting the unit is via a different method getRangeType(thisData).range.defaultUnit.toString(): {}\n'.format(getRangeType(thisData).defaultUnit.toString())
print '(CORRECT): GridUtil.getParamUnits(thisData): {}\n'.format(GridUtil.getParamUnits(thisData)[0])
a=selectData('Stage same grid as before via grid chooser')
print 'a is {}'.format(type(a))
print 'For netCDF grid data loaded via the gui selection and then accessed via select data, getRangeType produces a different answer\n'
print '(NOT QUITE A UNIT) Try getRangeType(a): {}'.format(getRangeType(a))
print '(CORRECT BUT DIFFERENT PATH) longer path provides the unit getRangeType(a).range.defaultUnit: {}'.format(getRangeType(a).range.defaultUnit)
print '(CORRECT) GridUtil.getParamUnits(a): {}\n'.format(GridUtil.getParamUnits(a)[0])
print 'a[0] is {}'.format(type(a[0]))
print '(CORRECT) a[0].getRangeUnits()[0][0]: {}\n'.format(a[0].getRangeUnits()[0][0])
print '(NOT QUITE A UNIT) Try getRangeType(a[0]): {}. Is there a path to get the unit from this?'.format(getRangeType(a[0]))
print '(CORRECT) GridUtil.getParamUnits(a[0]): {}\n'.format(GridUtil.getParamUnits(a[0])[0])
print 'Try an ADDE image'
b=selectData('Use ADDE Chooser')
print 'b[0] is {}'.format(type(a[0]))
print '(CORRECT) b[0].getRangeUnits()[0][0]: {}\n'.format(b[0].getRangeUnits()[0][0])
print '(NOT QUITE A UNIT) Try getRangeType(b[0]): {}. Is there a path to get the unit from this?'.format(getRangeType(b[0]))
print '(CORRECT) GridUtil.getParamUnits(b[0]): {}\n'.format(GridUtil.getParamUnits(b[0])[0])
print 'whatType is consistent with expected units, but need to extract units'
print whatType(gdata)
print whatType(newGreen)
print whatType(thisData)
print whatType(a)
print whatType(b)
print whatType(a[0])
print whatType(b[0])
Thanks,
Joleen