loadGrid 'dimensions' access

Post any questions, ideas, or topics related to Jython and Python scripting.
Post Reply
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

loadGrid 'dimensions' access

Post by joleenf »

Hi,

Is there a way to get the header dimensions from a netCDF file using loadGrid? I did not find any indication in the documentation that this was possible. I thought it would be possible to read in the full disk data of a ABI file and then use getDomainSizes() to extract the original shape of the data. However, I have found this can be taxing on memory. The goal is to allow one of my colleagues to set swath sizes based on width rather than specific start,end points so that he can display a series of swaths in one animation.

For now, I am using the following approach:

Code: Select all

filename='DR_ABI-L2-CMIPC-M3C01_G16_s20152322000151_e20152322002542_c20152322002596.nc'
stride=100
parms = dict(
                    field='CMI',
                    stride=stride
                    )
qd=loadGrid(filename, **parms)


shp= getDomainSizes(qd)

x=shp[0]*stride
y=shp[1]*stride

print x,y



Joleen
User avatar
bobc
Posts: 988
Joined: Mon Nov 15, 2010 5:57 pm

Re: loadGrid 'dimensions' access

Post by bobc »

Hi Joleen -

I've found other ways to get the sizes, such as:

Code: Select all

xLength = qd.getDomainSet().getX().getLengthX()
yLength = qd.getDomainSet().getY().getLengthX()

... but the method you are using looks cleaner.

Were you looking for a way to get the size information without having to pass your 'qd' data object through any functions?

Thanks -
Bob
User avatar
bobc
Posts: 988
Joined: Mon Nov 15, 2010 5:57 pm

Re: loadGrid 'dimensions' access

Post by bobc »

Hi Joleen -

Here's another alternative where you can list out the x and y dimensions without even having to use loadGrid:

Code: Select all

abiDir = 'C:/Users/rcarp/Data/abi/'
abiFile = 'DR_ABI-L2-CMIPC-M3C05_G16_s20152322000151_e20152322002542_c20152322002598.nc'
fullPath = abiDir + abiFile

# ncdumpToString() returns a unicode object that lists out values
# 0 through 4999, along with some other information
xVals = ncdumpToString(fullPath,vars='x')

# change this unicode object to a string, and then use split()
# to change the string to a list
xList = str(xVals).split()

# the second to last position is the final number, so use -2
# attached to the number is a '}' character that is removed
# by translating '}' to 'None'
xNum = xList[-2].translate(None,'}')

# this list is 0-based, so to get the final number, add 1
xNum = int(xNum)+1

# do the same process as above to get the y values
yVals = ncdumpToString(fullPath,vars='y')
yList = str(yVals).split()
yNum = yList[-2].translate(None,'}')
yNum = int(yNum)+1

print xNum, yNum

This code works in the nightly but the line where the '}' character is removed from the string errors in 1.5. This looks to be a pretty easy fix though. You just need to change

Code: Select all

xNum = xList[-2].translate(None,'}')

to:

Code: Select all

import string
xNum = xList[-2].translate(string.maketrans('', ''), '}')

... and a similar change for the step with the 'y' dimension.

Please let me know if this doesn't give you what you are looking for.

Thanks -
Bob
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: loadGrid 'dimensions' access

Post by joleenf »

Thanks Bob, this does provide what I need.

Joleen
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: loadGrid 'dimensions' access

Post by joleenf »

Hi Bob,

Just to follow up, using the ncDumpToString seems to be the safer way to proceed. Using the loadGrid with a stride I created a dimension that was actually larger than the grid size.

Joleen
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: loadGrid 'dimensions' access

Post by joleenf »

Bob,

I think that your alternative solution posted on 20 May 2016, 17:40 is the best solution currently. I am currently using a full disk file, which does not have row and columns sizes evenly divisible by 100, and my method overestimates the size of the arrays.

Also, this post and http://mcidasv.ssec.wisc.edu/forums/vie ... 35bb4c6870
are tied together.

Joleen
Post Reply