Page 1 of 1
loadGrid 'dimensions' access
Posted: Fri May 20, 2016 2:37 pm
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
Re: loadGrid 'dimensions' access
Posted: Fri May 20, 2016 4:21 pm
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
Re: loadGrid 'dimensions' access
Posted: Fri May 20, 2016 5:40 pm
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
Re: loadGrid 'dimensions' access
Posted: Mon May 23, 2016 4:35 pm
by joleenf
Thanks Bob, this does provide what I need.
Joleen
Re: loadGrid 'dimensions' access
Posted: Wed May 25, 2016 3:22 pm
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
Re: loadGrid 'dimensions' access
Posted: Sat May 06, 2017 2:43 pm
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 ... 35bb4c6870are tied together.
Joleen