Subsetting and acessing times in Netcdf file

Post any questions, ideas, or topics related to Jython and Python scripting.
Post Reply
User avatar
carlospsneto
Posts: 68
Joined: Thu Mar 14, 2013 1:38 pm

Subsetting and acessing times in Netcdf file

Post by carlospsneto »

Hello,

How can i select a smaller region (obs. South América) and display only one time of a global netcdf file that has multiple times using script?

to access the file i use the code:

Code: Select all

inputFilename = 'dods://thredds.ucar.edu/thredds/dodsC/grib/NCEP/GFS/Global_0p5deg/files/GFS_Global_0p5deg_20140609_0600.grib2'
sourceType = 'netcdf.grid'
dataChoice = 'Temperature_tropopause'
dd = makeDataSource(inputFilename, sourceType)
source = idv.getDataManager().findDataSource(dd.getName())
choice = source.findDataChoice(dataChoice)
createDisplay('planviewcolor', choice)


this file contains multiple times and i just need the latest one displayed to South America region. Can this be done by script?

Thank you once again.
User avatar
bobc
Posts: 990
Joined: Mon Nov 15, 2010 5:57 pm

Re: Subsetting and acessing times in Netcdf file

Post by bobc »

Hello -

This seems like the perfect case for a new function that we are in the process of developing called loadFile. This function has a variety of parameters that include:

    filename - String specifying the full path to NetCDF/HDF/Grib files on disk.
    time - Interger specifying the time index desired, or a full date/time string e.g. '2000-01-24 18:00:00 UTC'
    level - String specifying the level and units of a 3D field e.g. '500 hPa'
    field - String for the shortname of the field to display (macro that appears when you mouse over a field in the Field Selector
    xRange and yRange - Like a region subset - values are just indicies into the grid
    xStride and yStride - Sets a stride/skip in the horizontal
    latLonBounds - specify a rectangle for subsetting the part of the grid you want to display, specified as (UL Lat, UL Lon, LR Lat, LR Lon)

An example script that uses loadFile to specify one time and a geographical subset of South America would be:

Code: Select all

# dictionary to pass through loadFile
params = dict(
    filename = '/Users/rcarp/data/grib/FD/GFS_Global_2.5deg_20140609_0600.nc',
    time = '2014-06-18 06:00:00Z',
    field = 'Temperature_tropopause',
    latLonBounds=(15,-85,-60,-30),
    )
# loadFile command
tempTrop = loadFile(**params)
# build window, display data from loadFile and adjust the display
panel=buildWindow(height=800,width=1000)
layer1=panel[0].createLayer('Color-Filled Contour Plan View', tempTrop)
layer1.setEnhancement('Temperature', range=(-20,-90))
layer1.setColorScale(placement='Left', color='White', size=20, showUnit=True)
panel[0].setProjection('South America')
panel[0].setWireframe(False)

This is currently available in the McIDAS-V nightly build. Note that the nightly is not fully tested and has all programming changes from the previous day. I'll send you an email with the url and logon information to access the 1.5beta1 nightly build.

Thanks -
Bob Carp
McIDAS Help Desk
User avatar
carlospsneto
Posts: 68
Joined: Thu Mar 14, 2013 1:38 pm

Re: Subsetting and acessing times in Netcdf file

Post by carlospsneto »

Thank you very much Bob,

I just downloaded and installed Mcv1.5beta.
Post Reply