[ncl-talk] Plotting netCDF

Smith, Stuart smit1770 at purdue.edu
Fri Mar 16 12:25:33 MDT 2018


Dave,

 

Thank you very much for your help, and taking the time to walk me through the steps.

 

Regards,

 

-Stuart 

 

From: Dave Allured - NOAA Affiliate [mailto:dave.allured at noaa.gov] 
Sent: Thursday, March 15, 2018 4:09 PM
To: Smith, Stuart <smit1770 at purdue.edu>
Cc: Ncl-talk <ncl-talk at ucar.edu>
Subject: Re: [ncl-talk] Plotting netCDF

 

Stuart,

When reading the whole array, subscripts are not needed.  Just use whole array syntax:

    x = f->ppt

You did not fix the mismatched _FillVallue problem that I mentioned before.  You will need to either fix the file, or else add this kludge to make NCL properly recognize the missing values after they are read in:

    x at _FillValue := todouble (x at missing_value)

With that fix, it looks like your ppt.nc <http://ppt.nc>  data file is pre-masked for a predetermined spatial area.  To calculate a simple spatial average time series for all grid points within that predetermined area, just use a simple unweighted array averaging function:

    dim_select = (/ 1, 2 /)        ; select lat and lon dims to average over
    spatial_aves = dim_avg_n_Wrap (x, dim_select)     ; makes a 1-D time series

Please read the function documentation for dim_avg_n and dim_avg_n_Wrap, for more details.

If you need latitude weighting, or you need to select a smaller spatial area within the existing domain, then more code will be needed.

 

--Dave

 

 

On Wed, Mar 14, 2018 at 8:06 AM, Smith, Stuart <smit1770 at purdue.edu <mailto:smit1770 at purdue.edu> > wrote:

Dave,

 

Thanks for the feedback. I was able to get more data. The runoff data didn’t look useful, so I have attached another variable (precipitation) which had more data over the spatial area, but still missing data (-9999). The variables are:

 

0)      PPT=Precipitation

1)      T = Time

2)      X= Longitude

3)      Y = Latitude

 

In order to calculate spatial averages over time would I read in all dimensions, similar to what you have described below and calculate the average using a function? Thank you for your time.

 

    x = f->runoff(:,:,:)        ; x will be read as a 3-D array

 

Regards,

 

-Stuart

 

 

 

From: Dave Allured - NOAA Affiliate [mailto:dave.allured at noaa.gov <mailto:dave.allured at noaa.gov> ] 
Sent: Tuesday, March 13, 2018 5:12 PM
To: Smith, Stuart <smit1770 at purdue.edu <mailto:smit1770 at purdue.edu> >
Cc: Ncl-talk <ncl-talk at ucar.edu <mailto:ncl-talk at ucar.edu> >
Subject: Re: [ncl-talk] Plotting netCDF

 

Stuart,

 

That is a strange Netcdf file.  It is a time series of 45 x 29 grids, but all grid points are missing values, except for one corner point at (*,0,0).  You can extract the corner point as a 1-D time series, and make a line plot and other 1-D analysis.

 

    x = f->runoff(:,0,0)        ; x will be read as a 1-D array

 

However, you requested how to calculate spatial averages.  That does not make sense if you do not have valid data over multiple grid points.  So either you can just do 1-D plots and analysis, or you need to go back to your data source and get a file with valid data over your desired spatial area.

 

If you get another data file, also please ask the provider to make the _FillValue match the array data type, which is "double" in this case.

 

--Dave

 

 

On Tue, Mar 13, 2018 at 2:20 PM, Smith, Stuart <smit1770 at purdue.edu <mailto:smit1770 at purdue.edu> > wrote:

Good afternoon,

 

I received a netCDF file that has a format I am unfamiliar with and wanted guidance on calculating spatial averages over time. Attached is a copy of the .nc file. The variables are:

0)      Runoff 

1)      T=Time

2)      X= Longitude

3)      Y = Latitude

When defining variables for runoff (ex. Var = fi->runoff ), the output format is the following:

(0,0,0)    0

(0,0,1) -9999

(0,0,2) -9999

(0,0,3) -9999

(0,0,4) -9999

……..

(1,0,0)    0

(1,0,1) -9999

(1,0,2) -9999

 

The next value will not appear until (1,0,0). I wanted to ask how I would plot such data, and calculate averages over the area with the given format?  Thank you for your time.

 

Regards,

 

-Stuart

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180316/ce02fdb2/attachment.html>


More information about the ncl-talk mailing list