[ncl-talk] Subsetting a circle of data

Alan Brammer abrammer at albany.edu
Mon Aug 14 09:58:59 MDT 2017


Hi Jake, 

From that square, which should fully encompass your circle. You could then pass the latitude and longitudes of the grid points to gc_inout <https://www.ncl.ucar.edu/Document/Functions/Built-in/gc_inout.shtml> to find which grid points are actually within your circle. 

e.g.  (not tested, always test and double check)

;; Make lat and lon a 2d grid 
lat2d = conform(  newTRMMyearly,newTRMMyearly&lat, 0)   ; coord names may not be correct 
lon2d = conform(  newTRMMyearly,newTRMMyearly&lon, 1)

in_circle = gc_inout( lat2d, lon2d, clat, clon)
newTRMMyearly = where( in_circle, newTRMMyearly, newTRMMyearly at _FillValue) ; mask points out of circle


set gsnAddCyclic = False and you should be able to plot the grid on a map. 

Good luck,
 
	Alan


> On Aug 13, 2017, at 2:43 PM, Jake Huff <jake.huff at stonybrook.edu> wrote:
> 
> Hello,
> 
> I am working on reading in precipitation data that corresponds to a radius of a 500km around a tropical cyclone. I have a variable that contains precipitation over the Eastern US and into the Atlantic Ocean. Below is some of my code. 
> 
> ;Snippet of code 
> 
> obtracks = addfile("Allstorms.ibtracs_wmo.v03r05.nc <http://allstorms.ibtracs_wmo.v03r05.nc/>","r") ;Read in IBTrACS
> lat_wmo = short2flt(obtracks->lat_wmo) ;(storm,time)
> lon_wmo = short2flt(obtracks->lon_wmo) ;(storm,time)
> 
> 
> ; Read in Precipitation Files
> 
> precipfile = addfile("TRMMdata.nc","r")
> AvgYearlyTRMM = precipfile->AvgYearlyTRMM   ;(time,lat,lon)
> 
> clat = new(61,float)
> clon = new(61,float)
> radius = 5.0
> 
> lat_location = lat_wmo(0,0) ; location for 1st TC and time step
> lon_location = lon_wmo(0,0) ; location for 1st TC and time step
> nggcog(lat_location,lon_location,radius,clat,clon) ;calculate circle
> 
> min_lat = min(clat)
> max_lat = max(clat)
> min_lon = min(clon)
> max_lon = max(clon)
> 
> 
> newTRMMyearly = AvgYearlyTRMM(0,{min_lat:max_lat},{min_lon:max_lon}) ;reads in square of data
> 
> So the above reads in the data correctly but gives me a square of data instead of the circle that I create with the nggcog function above since I'm using the min/max of the circle.
> 
> 
> I was wanting to know if anyone knows of a way to read in the clat/clon from my AvgYearlyTRMM dataset. I have attempted some indexing of the clat/clon varibles to put the index into AvgYearlyTRMM, but then the lat/lon arrays are no longer monotonic so trying to use gsn_csm_contour_map doesn't work. 
> 
> 
> Thanks for any help.
> Jake
> 
>  
> _______________________________________________
> 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/20170814/c71e6e7a/attachment.html 


More information about the ncl-talk mailing list