Page 1 of 1

get a small region of my data

Posted: Fri May 12, 2017 6:33 pm
by jconrado
Hi,

With the support of the MCIDAS Forum I have succeeded in reading and plotting my data. I've always used IDL and now I'm starting to use PYTHON. My data is on a grid point for the whole globe. What I would like to know is how do I get a given region of the globe, [lon1: lon2, lat1: lat2]. For example I would like to take the region of South America.

Thanks,

Conrado

Re: get a small region of my data

Posted: Tue May 16, 2017 4:46 pm
by jayh
Hi Conrado-

I talked to my colleagues and we had a couple questions for clarification.

1. What type of data are you working with? Gridded data or imagery or something else. We wanted to clarify this because we wanted to choose the correct functions to use.

2. For your output, are you asking for how to set the display region? Or are you requesting just a certain domain of data to be displayed in a lat/lon bounded box?

3. Are you asking how to format the output data? (For example, netCDF files or csv files?)

Thanks, Jay

small region of my data

Posted: Thu May 18, 2017 1:47 pm
by jconrado
Hi Jay,

My data is gridded and the limit of my data is latitude [-70,70] and longitude [-180,180]. I would like to get a region small region of this data. For example latitude [-70,70] and longitude [-110,-10]. And I would like to visualize this region using Stereographic Projection. Finally I would like to export this data to the Netcdf format.


Thanks,

Conrado

Re: get a small region of my data

Posted: Thu May 18, 2017 8:41 pm
by jayh
Hi Conrado-

My colleague put together a sample script that should do what you need. I tested it in 1.6 and a recent nightly and it works in both versions. You will just need to substitute your local file names, directories, parameters, etc. that you wish to use.

Code: Select all

# The below script loads in a full disk data source,
# displays a lat/lon subset of the data, and exports
# this lat/lon subset to a netCDF file.  This works
# for a single timestep in a file, by default, only
# displaying and writing a netCDF file of the earliest
# time in the file, position 0.

# specifying variables
dataDir = "C:/Users/rcarp/Data/NetCDF/"
dataFile = "GFS_2p5deg_global.nc"

# dictionary for loadGrid
# latLonBounds = UL lat, UL lon, LR lat, LR lon
dataParms = dict(
    filename = dataDir+dataFile,
    field = "Pressure_reduced_to_MSL_msl",
    latLonBounds = (70, -110, -70, -10)
    )

# create a data object with loadGrid
data = loadGrid(**dataParms)

# build a window, display the data, and set the display
# to a stereographic projection, in this case, "North Pole"
panel = buildWindow()
layer = panel[0].createLayer("Color-Filled Contour Plan View", data)
panel[0].setProjection("North Pole")

# export the data object created from loadGrid to a netCDF file
exportGridToNetcdf(data, dataDir+"OutputFile.nc")


I hope this helps you get started.

Thanks, Jay