[ncl-talk] Extracting Output Results from Specific Grid Cells
Mary Haley
haley at ucar.edu
Thu May 3 13:11:11 MDT 2018
Stuart,
One procedure that I know Dennis likes (and I should use more) is
stat_dispersion
<http://www.ncl.ucar.edu/Document/Functions/Contributed/stat_dispersion.shtml>.
It calculates robust statistics on your data, including how it is
distributed:
opt = True
opt at PrintStat = True
stat_var = stat_dispersion(Tair_f_tavg,opt)
Otherwise, using printMinMax and printVarSummary are the two main ways we
tell people to look at data. I only use the "num" and "ismissing" functions
if I suspect something is wrong with the data itself, or the lat/lon values.
Personally, I like to plot the data to get a better look at it. If I
suspect that the lat/lon values are questionable, then I'll also add a
gsn_coordinates all to plot the lat/lon locations on the contour plot to
see what the grid looks like.
I've included a basic NCL script that loops through your 2D variables and
creates a simple contour plot over a map, and then adds lat/lon points at
locations where your 2D lat/lon are not missing. I attached one of the PNG
images, which is the plot of Tair_f_tavg.
--Mary
On Thu, May 3, 2018 at 6:21 AM, Smith, Stuart <smit1770 at purdue.edu> wrote:
> Mary,
>
>
>
> Thank you for your assistance. I had no idea so much information was
> missing. I have been looking at the dimensions and sizes (ex. [ncl_join |
> 4017] x [north_south | 29] x [east_west | 45]) along with the total size
> values (Total Size: 20968740 bytes; 5242185 values) as a method to confirm
> that my model was simulating the correct extent and that it was outputting
> data, but this was not sufficient.
>
>
>
> Thank you so much for teaching me another method to confirm how many valid
> values I have, and how many I am missing. This tells me that there is a
> wrong input in my model simulation. If you have any other preliminary data
> checks that you would recommend please let me know. Thank you for yours and
> Dennis’s time.
>
>
>
> Regards,
>
>
>
> -Stuart
>
> *From:* Mary Haley <haley at ucar.edu>
> *Sent:* Wednesday, May 2, 2018 10:19 AM
> *To:* Smith, Stuart <smit1770 at purdue.edu>
> *Cc:* Ncl-talk <ncl-talk at ucar.edu>
> *Subject:* Re: [ncl-talk] Extracting Output Results from Specific Grid
> Cells
>
>
>
> Stuart,
>
>
>
> Sorry for the delay.
>
>
>
> The answer follows, but I want to point out that almost half of your
> lat/lon values on the file are missing. I'll discuss this in a little bit.
>
>
>
> If you look at one of your data files using ncl_filedump, you will see
> that the lat/lon arrays are two-dimensional (I edited the output for
> clarity):
>
>
>
> Variable: lat
>
> Type: float
>
> Number of Dimensions: 2
>
> Dimensions and sizes: [ 29 <north_south> x 45 <east_west> ]
>
> Coordinates:
>
> Number of Attributes: 9
>
> units : degree_north
>
> standard_name : latitude
>
> long_name : latitude
>
>
>
>
>
> Variable: lon
>
> Type: float
>
> Number of Dimensions: 2
>
> Dimensions and sizes: [ 29 <north_south> x 45 <east_west> ]
>
> Coordinates:
>
> Number of Attributes: 9
>
> units : degree_east
>
> standard_name : longitude
>
> long_name : longitude
>
>
>
> Data that is defined by two-dimensional lat/lon arrays is said to be on a
> "curvilinear" grid. In order to sub-select regions from curvilinear data,
> you need to use either getind_latlon2d or region_ind.
>
>
>
> Also, you don't want to use the [:] syntax to read the lat/lon arrays off
> the file, because then you will get back 2 x 29 x 45 arrays, which is
> unnecessary if your lat/lon arrays don't change with each time step.
>
>
>
> Instead, simply read off one timestep of the lat / lon using [0]:
>
>
>
> a = addfiles(fils,"r")
>
> ListSetType (a, "join")
>
> data = a[:]->Tair_f_tavg
>
> data at time = a[:]->time
>
> lon2d = a[0]->lon
>
> lat2d = a[0]->lat
>
>
>
> You can then get the index locations into lat2d and lon2d that are equal
> to LAT and LON as follows:
>
>
>
> LAT = (/ 48.5625/)
>
> LON = (/-98.9375/)
>
>
>
> nm = getind_latlon2d (lat2d,lon2d, LAT, LON)
>
> n = nm(0,0)
>
> m = nm(0,1)
>
> print("==================================================")
>
> print("Original lat/lon : " + LAT +" "+LON)
>
> print("Actual lat/lon : " + lat2d(n,m)+" "+lon2d(n,m))
>
> print("==================================================")
>
>
>
> To slice the data at that particular location:
>
>
>
>
> data_slice = data(:,n,m)
>
> printVarSummary(data)
>
> printVarSummary(data_slice)
>
> printMinMax(data_slice,0)
>
>
>
>
>
> We have some examples of using these functions. Please see:
>
>
>
> http://www.ncl.ucar.edu/Applications/latlon_subset.shtml
>
>
>
> These examples show the difference between region_ind and getind_latlon2d,
> which is important if you want to grab a sub-region of data, rather than
> just a single slice.
>
>
>
> Back to the lat/lon values being missing. It's always incredibly important
> to look at your data and understand it before you start doing calculations
> on it, or try to plot it. Dennis Shea mentioned to me offline that your
> lat/lon arrays had a high number of missing values, so I simply added the
> following two lines to check this:
>
>
>
> print("==================================================")
>
> print("# of valid latitude values = " + num(.not.ismissing(lat2d)))
>
> print("# of missing latitude values = " + num(ismissing(lat2d)))
>
> print("==================================================")
>
> print("# of valid longitude values = " + num(.not.ismissing(lon2d)))
>
> print("# of missing longitude values = " + num(ismissing(lon2d)))
>
> print("==================================================")
>
>
>
> which gave me the following output:
>
>
>
> ==================================================
>
> # of valid latitude values = 703
>
> # of missing latitude values = 602
>
> ==================================================
>
> # of valid longitude values = 703
>
> # of missing longitude values = 602
>
> ==================================================
>
>
>
> It's likely that the lat/lon arrays have missing values in the same
> location.
>
>
>
> Now maybe this is perfectly valid for your data, but it's something we
> wanted to be sure you were aware of. It's somewhat unusual to see this many
> missing values in lat / lon arrays.
>
>
>
> --Mary
>
>
>
>
>
>
>
>
>
>
>
> On Sat, Apr 28, 2018 at 12:32 PM, Smith, Stuart <smit1770 at purdue.edu>
> wrote:
>
> Hello,
>
>
>
> Attached is a NCL script I have been using to output model simulation
> results. My goal is to enhance this script to plot outputs from specific
> grid cells.
>
>
>
> The plotting script was originally designed to read in netCDF files, which
> were outputted from the model simulation in a daily time step as a netCDF
> file (ex. 200903180000.d01.nc). In order to create a timeseries, the
> script joins the files into an array and plots the total average data. I
> would like to enhance the NCL script to plot a time series of the raw
> outputted data from a defined grid cell.
>
>
>
> I have been able to do this successfully looking at individual files, but
> when I try joining the data into an array for time series analysis of the
> grid cell I get the following error “fatal:Dimension (east_west) of (data)
> does not have an associated coordinate variable fatal" on line 28. Could I
> please have assistance on understanding the error and correcting this
> issue? Attached are example output results from a model simulation as well.
> Thank you for your time.
>
>
>
> Regards,
>
>
>
> -Stuart
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180503/0309cf03/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: plot_lis_hist.ncl
Type: application/octet-stream
Size: 2397 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180503/0309cf03/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lis_hist.000021.png
Type: image/png
Size: 173249 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180503/0309cf03/attachment.png>
More information about the ncl-talk
mailing list